Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: LadyGodiva on April 14, 2012, 06:44:51 pm

Title: [RESOLVED] [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 14, 2012, 06:44:51 pm
I'm having a little trouble editing the item window. I want to make it so the in-battle item menu is only one column and the items are listed only vertically, with the window itself shrunk to fit. However, I've been toying with it for a while and can't seem to make it work just right. I usually get one of two problems.

Either a) the items won't list in just one column and you can see a little of the next column (but it's cut off)

Screenshot:
Spoiler: ShowHide

(http://i225.photobucket.com/albums/dd196/collier_ladygodiva/ProblemA.png)


or b) only half of the items the party has will display and the descriptions don't match.

Screenshot:
Spoiler: ShowHide

(http://i225.photobucket.com/albums/dd196/collier_ladygodiva/ProblemB.png)


Here's the script I'm using. It's just the standard Window_Item script with my own edits on lines 100-112.

Spoiler: ShowHide

#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays items in possession on the item and battle screens.
#==============================================================================

class Window_Item < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 64, 640, 416)
   @column_max = 2
   refresh
   self.index = 0
   # If in battle, move window to center of screen
   # and make it semi-transparent
   if $game_temp.in_battle
   @column_max = 1
   refresh
     self.y = 64
     self.height = 256
     self.width = 400
     self.back_opacity = 255 #160
   end
 end
 #--------------------------------------------------------------------------
 # * Get Item
 #--------------------------------------------------------------------------
 def item
   return @data[self.index]
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   if self.contents != nil
     self.contents.dispose
     self.contents = nil
   end
   @data = []
   # Add item
   for i in 1...$data_items.size
     if $game_party.item_number(i) > 0
       @data.push($data_items[i])
     end
   end
   # Also add weapons and items if outside of battle
   unless $game_temp.in_battle
     for i in 1...$data_weapons.size
       if $game_party.weapon_number(i) > 0
         @data.push($data_weapons[i])
       end
     end
     for i in 1...$data_armors.size
       if $game_party.armor_number(i) > 0
         @data.push($data_armors[i])
       end
     end
   end
   # If item count is not 0, make a bit map and draw all items
   @item_max = @data.size
   if @item_max > 0
     self.contents = Bitmap.new(width - 32, row_max * 32)
     for i in 0...@item_max
       draw_item(i)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Item
 #     index : item number
 #--------------------------------------------------------------------------
 def draw_item(index)
   item = @data[index]
   case item
   when RPG::Item
     number = $game_party.item_number(item.id)
   when RPG::Weapon
     number = $game_party.weapon_number(item.id)
   when RPG::Armor
     number = $game_party.armor_number(item.id)
   end
   if item.is_a?(RPG::Item) and
      $game_party.item_can_use?(item.id)
     self.contents.font.color = normal_color
   else
     self.contents.font.color = disabled_color
   end
   x = 4 + index % 2 * (288 + 32)
   y = index / 2 * 32
   rect = Rect.new(x, y, self.width / @column_max - 32, 32)
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   bitmap = RPG::Cache.icon(item.icon_name)
   opacity = self.contents.font.color == normal_color ? 255 : 128
   self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
   self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
   self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
   self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
#My Own Attempt
   if $game_temp.in_battle
   x = 4
   y = index * 32    
   rect = Rect.new(x, y, self.width / @column_max - 32, 32)
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   bitmap = RPG::Cache.icon(item.icon_name)
   opacity = self.contents.font.color == normal_color ? 255 : 128
   self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
   self.contents.draw_text(x+35, y, 212, 32, item.name, 0)
   self.contents.draw_text(x+315, y, 16, 32, ":", 1)
   self.contents.draw_text(x+325, y, 24, 32, number.to_s, 2)
#End My Own Attempt
 end
end
 #--------------------------------------------------------------------------
 # * Help Text Update
 #--------------------------------------------------------------------------
 def update_help
   @help_window.set_text(self.item == nil ? "" : self.item.description)
 end
end




Below is how I would like it, ideally. That is, if all of the items were displayed and the descriptions matched.

Screenshot:
Spoiler: ShowHide

(http://i225.photobucket.com/albums/dd196/collier_ladygodiva/HowIWantIt.png)


Thanks to anyone who can help and/or fix this!!

(Also, sorry if there is someone who has done this already. I checked the forum and couldn't find anything. Sorry if I over-looked it.)
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: nathmatt on April 14, 2012, 06:58:28 pm
change the column_max
@column_max = 1
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 14, 2012, 07:12:15 pm
I did in lines 16-19.


16 # If in battle, move window to center of screen
17 # and make it semi-transparent
18 if $game_temp.in_battle
19 @column_max = 1
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: ForeverZer0 on April 14, 2012, 08:14:43 pm
Spoiler: ShowHide
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays items in possession on the item and battle screens.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    if $game_temp.in_battle
      super(0, 64, 400, 256)
      @column_max = 1
    else
      super(0, 64, 640, 416)
      @column_max = 2
    end
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Add item
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    # Also add weapons and items if outside of battle
    unless $game_temp.in_battle
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0
          @data.push($data_weapons[i])
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors[i])
        end
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    if $game_temp.in_battle
      x = 4
      y = index * 32   
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(item.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x+35, y, 212, 32, item.name, 0)
      self.contents.draw_text(x+315, y, 16, 32, ":", 1)
      self.contents.draw_text(x+325, y, 24, 32, number.to_s, 2)
    else
      x = 4 + index % 2 * (288 + 32)
      y = index / 2 * 32
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(item.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
      self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
      self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
    end
   
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 15, 2012, 05:22:20 pm
Thank you thank you thank you Forever Zer0!!! It works wonderfully. Would there be any chance that you could alter Window_Skill to work the same way??? Pretty please?? :D


#==============================================================================
# ** Window_Skill
#------------------------------------------------------------------------------
#  This window displays usable skills on the skill and battle screens.
#==============================================================================

class Window_Skill < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor : actor
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 128, 640, 352)
    @actor = actor
    @column_max = 2
    refresh
    self.index = 0
    # If in battle, move window to center of screen
    # and make it semi-transparent
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  # * Acquiring Skill
  #--------------------------------------------------------------------------
  def skill
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@actor.skills.size
      skill = $data_skills[@actor.skills[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
    self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  end
end
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: ForeverZer0 on April 15, 2012, 07:32:37 pm
Sure.

Spoiler: ShowHide
#==============================================================================
# ** Window_Skill
#------------------------------------------------------------------------------
#  This window displays usable skills on the skill and battle screens.
#==============================================================================

class Window_Skill < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor)
    @actor = actor
    if $game_temp.in_battle
      super(0, 64, 400, 256)
      @column_max = 1
    else
      super(0, 64, 640, 416)
      @column_max = 2
    end
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    if $game_temp.in_battle
      x = 4
      y = index * 32   
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(skill.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x+35, y, 212, 32, skill.name, 0)
      self.contents.draw_text(x+312, y, 48, 32, skill.sp_cost.to_s, 2)
    else
      x = 4 + index % 2 * (288 + 32)
      y = index / 2 * 32
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(skill.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
      self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
    end
  end
end
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 15, 2012, 08:04:14 pm
Hmm... I keep getting this error screen whenever I try to access the Skills menu, in or out of battle.

Spoiler: ShowHide
(http://i225.photobucket.com/albums/dd196/collier_ladygodiva/ErrorMessage1.png)
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: ForeverZer0 on April 15, 2012, 08:11:05 pm
I'm sorry, I should have said.
You don't overwrite the Window_Skill with this one, just put it in a new script slot in the editor anywhere below Window_Skill.
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 15, 2012, 09:05:36 pm
No worries! It works perfectly in battle, but when I access the Skills screen from the Main Menu, the first two skills and the HP/SP meters overlap one another. I'm assuming an adjustment to the y value should fix that right up?

Spoiler: ShowHide
(http://i225.photobucket.com/albums/dd196/collier_ladygodiva/ErrorMessage2.png)
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: ForeverZer0 on April 15, 2012, 09:24:39 pm
Oops. I must have changed the wrong part. I'll update in a sec.

EDIT:

I accidentally used the "super" call from Window_Item instead of Window_Skill for the menu version. :P
All better now.

Spoiler: ShowHide
#==============================================================================
# ** Window_Skill
#------------------------------------------------------------------------------
#  This window displays usable skills on the skill and battle screens.
#==============================================================================

class Window_Skill < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor)
    @actor = actor
    if $game_temp.in_battle
      super(0, 64, 400, 256)
      @column_max = 1
    else
      super(0, 128, 640, 352)
      @column_max = 2
    end
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    if $game_temp.in_battle
      x = 4
      y = index * 32   
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(skill.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x+35, y, 212, 32, skill.name, 0)
      self.contents.draw_text(x+312, y, 48, 32, skill.sp_cost.to_s, 2)
    else
      x = 4 + index % 2 * (288 + 32)
      y = index / 2 * 32
      rect = Rect.new(x, y, self.width / @column_max - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      bitmap = RPG::Cache.icon(skill.icon_name)
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
      self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
      self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
    end
  end
end
Title: Re: [XP] Item Window Edit Help (for battle)
Post by: LadyGodiva on April 15, 2012, 11:16:48 pm
Ahh, yes, it works perfectly now! Thanks much!