Main Menu
  • Welcome to The RPG Maker Resource Kit.

[resolved] window display problem.

Started by shintashi, April 21, 2011, 01:14:26 AM

0 Members and 1 Guest are viewing this topic.

shintashi

I must be getting senile because I've forgotten what the solution this is, but basically, I've got a window accidentally displaying the right arrow. This is something that happens when adjusting the parameters of a window vs. its background images and something to do with a 16-32 pixel border, but for the life of me I can't recall where I messed up. Here's the window code, based heavily on the Window_Skill.



class Window_Chant < Window_Selectable
   #--------------------------------------------------------------------------
  # * Object Initialization
  #     This is the Spell Book Window: It is translucent
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, 128, 640, 352)
    @actor = actor
    @column_max = 3
    refresh
    self.index = -1
    # If in battle
    if $game_temp.in_battle
      self.width = 540 #100
      self.x = 100
      self.y = 64
      self.height = 214 #256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  # * Acquiring Chant
  #--------------------------------------------------------------------------
  def chant
    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.chants.size
      chant = $data_chants[@actor.chants[i]]
      if chant != nil
        @data.push(chant)
      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)
    chant = @data[index]
    if @actor.chant_can_use?(chant.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    if $game_temp.in_battle   
      x = 6 + index % 3 * (146 + 32)
      y = index / 3 * 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(chant.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 + 24, y, 160, 32, chant.name, 0)
      self.contents.draw_text(x + 94, y, 48, 32, chant.power.to_s, 2)
    else
      x = 4 + index % 3 * (180 + 32)
      y = index / 3 * 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(chant.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, chant.name, 0)
      self.contents.draw_text(x + 124, y, 48, 32, chant.power.to_s, 2)
    end
  end
 
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.chant == nil ? "" : self.chant.description)
  end

end


ForeverZero

The window contents is larger than the window.

For example, if you have a 320x240 window, but the contents for it is 320x480, you will see arrows at the top, bottom or both, depending on the origin point of the bitmap.

Basically, just size the window contents properly and they will go away. In your case though, it looks like they should be there, at least on the vertical axis. The refresh method sizes the contents to fit the number of items, which don't all fit within the window frame, therefore you get the arrows to show that there are more items that are unseen and need to be scrolled down/up to.

shintashi

Quote from: ForeverZero on April 21, 2011, 05:07:40 AM
The window contents is larger than the window.

For example, if you have a 320x240 window, but the contents for it is 320x480, you will see arrows at the top, bottom or both, depending on the origin point of the bitmap.

Basically, just size the window contents properly and they will go away. In your case though, it looks like they should be there, at least on the vertical axis. The refresh method sizes the contents to fit the number of items, which don't all fit within the window frame, therefore you get the arrows to show that there are more items that are unseen and need to be scrolled down/up to.

Right. So any idea which variable needs to be edited? When I have no content items (no chants), the arrow does not appear, but even when I have only one item listed, with a width of merely 40, in the center, the right arrow still appears. I've been messing with this for a couple of days now with no success.

shintashi

temp solution:

I took out "if in battle" and changed my super to 100..540, instead of 0..640 width. This gets rid of the arrow because the arrow is related to the original figures in the Super, and I don't know how to re-initiate the super with different numbers during battle.

ForeverZero

Here is a little edit to your initialize method. It will have the window sized correctly for battle.

  def initialize(actor)
    if $game_temp.in_battle
      super(100, 64, 540, 100)
      self.back_opacity = 160
    else
      super(0, 128, 640, 352)
    end
    @actor = actor
    @column_max = 3
    refresh
    self.index = -1
  end


shintashi

excellent. Thanks much, I usually leave any part of code alone which I don't fully understand, and supers are something I'm not terribly familiar with.

ForeverZero

To put it simply, they call the same method that they are in, but the parent's version. You supply the same arguments that the parent method requires, and it applies them to the child class. You can call it at any point that is convenient for your code, it doesn't have to be at the beginning, but for windows, it usually will be.

If you are familiar with aliases, think of it like that, where you can kind of determine where the old method is called within the aliased method by where you write the alias name.