Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

window dont' show all the items

S0L0

Member

Hi there, I never bottered much about this because I was planing make game only have 5 skills for each kind of spellbook, but now I re-organized it better so need to show several types of skills.

My idea is, make the window like a normal window of one single columm
, showing the the skill picture/name/sp cost, and when I move down the cursor moves aswell showing the actual skill i'm "selecting"

Now heres comes problem, with this current code i'm using, I only can see the skill picture/name/sp cost, on the first 5 skills (wich are the ones "inside" the window box, and when I move down I can't see the actual cursor, but I can stil choose them, I mean is, I keep moving down as if I were using a HUGE window box that doesn't fit on screen and the screen isn't updated with the current cursor location for show the info.

I hope I have explained this clear enought, since was kinda hard for me explain it :P

Anyways heres the actual code i'm using:

Code:
#==============================================================================
# Window_SpellBook_Light
#==============================================================================

class Window_SpellBook_Light < Window_Selectable

  def initialize(actor)
    super(0, 45, 456, 545)
    @actor = actor
    @column_max = 1
    self.z = 9999
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.x =135
      self.y = 100
      self.height = 330
      self.width = 530
      self.back_opacity = 160
    end
  end
  
  def skill
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_skills.size
      for x in 0...$light_skills_ids.size
        if i == $light_skills_ids[x]
          @data.push($data_skills[i])
        end
      end
    end 
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 70)#32)
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  
  def draw_item(index)
    skill = @data[index]
    x = 4
    y = index / @column_max * 60
    self.contents = Bitmap.new(width - 32, row_max * 60)
    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, 48, 48), opacity)
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = shadow_color
      self.contents.draw_text(x + 50, y + 2, 214, 48, skill.name, 0)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 48, y, 214, 48, skill.name, 0)
      self.contents.font.color = shadow_color
      self.contents.draw_text(x + 374, y + 2, 48, 48, skill.sp_cost.to_s, 2)
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 372, y, 48, 48, skill.sp_cost.to_s, 2)
    else
      self.contents.font.color = shadow_color
      self.contents.draw_text(x + 50, y + 2, 214, 48, skill.name, 0)
      self.contents.font.color = disabled_color
      self.contents.draw_text(x + 48, y, 214, 48, skill.name, 0)
      self.contents.font.color = shadow_color
      self.contents.draw_text(x + 374, y + 2, 48, 48, skill.sp_cost.to_s, 2)
      self.contents.font.color = disabled_color
      self.contents.draw_text(x + 372, y, 48, 48, skill.sp_cost.to_s, 2)
    end
  end
   
  def update_help
    @help_window.set_text(self.skill == nil ? "" : self.skill.description)
    if $game_temp.in_battle
      @help_window.x = 0
      @help_window.y = 0
      @help_window.height = 64
      @help_window.width = 800
      @help_window.opacity = 160
    end
  end
  
   def update_cursor_rect
     self.cursor_rect.set(-1, (index * 60) + 1, 500, 54)
   end
end

Thank you
 
Ok. Let's just start from the beggining.

Code:
    super(0, 45, 456, 545)

    if $game_temp.in_battle
      self.x =135
      self.y = 100
      self.height = 330
      self.width = 530
    end

Not necessary, but I have found it to make everything look nicer if you make all your window and sprite dimensions something divisible by 8, 16, 32, etc. Everything in the default scripts does this, so unless you plan on modifing everything, I recommend using similar sizes. Everything just lines up and looks neater.

--------------------------

Code:
    @column_max = 1
    self.z = 9999

I don't think either line is nessessary. Making the z 9999 is very bad formatting. You only need a +1 or -1 z when comparing to other windows and such. It is fine to leave a little room, but 9999 is excessive.

--------------------------

Code:
    for i in 1...$data_skills.size
      for x in 0...$light_skills_ids.size
        if i == $light_skills_ids[x]
          @data.push($data_skills[i])
        end
      end
    end

Instead, you can use the .include? method. Makes everything process faster.

Code:
    for i in 1...$data_skills.size
      if $light_skills_ids.include?(i)
        @data.push($data_skills[i])
      end
    end

--------------------------

Code:
      self.contents = Bitmap.new(width - 32, row_max * 70)#32)

The y is all off. It should be:
Code:
      self.contents = Bitmap.new(width - 32, row_max * 32)

--------------------------

Code:
    y = index / @column_max * 60
    self.contents = Bitmap.new(width - 32, row_max * 60)

Ouch! This is way off. Remember, self.contents is a specialized bitmap for windows. You are constant recreating it, which is your problem. This should just be (just remove the other line)
Code:
    y = index * 32

--------------------------

Code:
   def update_cursor_rect
     self.cursor_rect.set(-1, (index * 60) + 1, 500, 54)
   end

You should be able to remove all of this. The cursor_rect is just fine how it is in Window_Selectable. You shouldn't modify this method unless you know what you are doing.



Let me know if you need help with anything.
 

S0L0

Member

A reply from SephirothSpawn himself, nice :D, thanks for you reply me but:

SephirothSpawn;163655":2zxbbb8v said:
Code:
    @column_max = 1
    self.z = 9999
I don't think either line is nessessary. Making the z 9999 is very bad formatting. You only need a +1 or -1 z when comparing to other windows and such. It is fine to leave a little room, but 9999 is excessive.

Well, I use the z as HUGE value (wich I also know is a stupid value) but is just for temporary, soon I fix all the displayed windows on the menu on the proper ways, I will fix the z value for something more reasonable, as for exemple: self.z = 101 or something, but as is stil under testing I''ll leave the 9999 for now :)

SephirothSpawn;163655":2zxbbb8v said:
Code:
    y = index / @column_max * 60
    self.contents = Bitmap.new(width - 32, row_max * 60)
Ouch! This is way off. Remember, self.contents is a specialized bitmap for windows. You are constant recreating it, which is your problem. This should just be (just remove the other line)
Code:
    y = index * 32

I'm sorry, but the y has to be 60, because i changed ALL menus to use the icons as 48x48 so I need a lil 12px border, so the best Y value I found was 60

SephirothSpawn;163655":2zxbbb8v said:
Code:
   def update_cursor_rect
     self.cursor_rect.set(-1, (index * 60) + 1, 500, 54)
   end
You should be able to remove all of this. The cursor_rect is just fine how it is in Window_Selectable. You shouldn't modify this method unless you know what you are doing.

Hehehe nice said :P, unfortenly I'm not very sure what I'm doing but I know what I want do, and soon I disabled this, this got "fixed" but problem BUT the items got listed in 32x by 32x while the icons themselfs are 48x48, I want the cursor be of heigh 60 size, so I tried make a small modification using it as 60 and all worked great, since all my Menus don't have excessive items, this update_cursor_rect code I've been using so far worked great, but now for scrollable windows it don't work...

so could you please help me modifing the update_cursor_rect for fit better on this window??, because I changed values for fit better, for exemple:
- 1 = the X for the cursor so it apears "pop up" over the item a little back from item, make a better effect
index * 60 + 1= his index is multiplied by 60 (wich is where each bitmap is suposed be listed in) and added 1 for the box apear outside of the item bitmap, as said make a beter effect
500 = the width of the cursor "box"
54 = the height of the cursor "box"

For all I understood I changed this correctly (from my point of view...) but I somehow messed with some kind of variable so the cursor keep moving down and up without never scroll the bitmaps ...


I truely hope have explained this properly. Thanks
 

S0L0

Member

Ok, I explain you my idea, what I want is to make a Skills Window for the battle, wich this window just show the specific skills wich are inside a variable

I mean is, the skills avaliable are the ones wich are set on the:
$light_skills_ids = [ID, ID, ID, ID, ID, etc]

And I want the skills be listed with the icons size of 48x48, showing skill name and SP cost, and I want it to be listed with 60px distance (already counting with the 48px of the icon size)


And ALL this is already done :P, the only problem is the update_cursor_rect wich isn't working, if you could help me out with just the update_cursor_rect code would be great, because then I could see where I made the mess and could then fix all the other update_cursor codes I have in my entire game lol :P

And i been searching arround and I saw the 'original' update_cursor_rect code is:

Code:
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index / @column_max
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = self.width / @column_max - 32
    # Calculate cursor coordinates
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * 32 - self.oy
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, 32)
  end


and from this code, I'm sure the last cursor_rect.sets value (the 32) has to be 50 because will be the height size of the cursor "box", and the code part of "y = @index / @column_max * 32 - self.oy" is the code I need to change, since this is the code for the up/down move of the cursor, and so I assume it has to be 60 (same as the draw_item code y value) but if I change this value this become complete messed out again, making the cursor window y position just move up/down without "scroll" the contents ...


as you see, I prefer LEARN what I'm doing wrong for know, then just ask a script request :), but if you need know ANY info of command or whateva just say and I tell you, but for the few knowledge I think I have :P I can even bet all this mess has to do with y value of the update_cursor code ...



BIG EDIT:

After several tests, I managed to find the problem and fix it, the problem of all this was the original code from Windows_Selectable wich were set for make the cursor rows as 32 and incluidg the max "rows" per page, so I had to create a new windows_selectable script, heres the one I used and BLUE BOLD the lines I had to change for make it compatible:

Code:
class Window_SkillSelectable < Window_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :index                    # cursor position
  attr_reader   :help_window              # help window
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @item_max = 1
    @column_max = 1
    @index = -1
  end
  #--------------------------------------------------------------------------
  # * Set Cursor Position
  #     index : new cursor position
  #--------------------------------------------------------------------------
  def index=(index)
    @index = index
    # Update Help Text (update_help is defined by the subclasses)
    if self.active and @help_window != nil
      update_help
    end
    # Update cursor rectangle
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # * Get Row Count
  #--------------------------------------------------------------------------
  def row_max
    # Compute rows from number of items and columns
    return (@item_max + @column_max - 1) / @column_max
  end
  #--------------------------------------------------------------------------
  # * Get Top Row
  #--------------------------------------------------------------------------
  def top_row
    # Divide y-coordinate of window contents transfer origin by 1 row
    # height of 32
    [COLOR=RoyalBlue][B]return self.oy / 60[/B][/COLOR]
  end
  #--------------------------------------------------------------------------
  # * Set Top Row
  #     row : row shown on top
  #--------------------------------------------------------------------------
  def top_row=(row)
    # If row is less than 0, change it to 0
    if row < 0
      row = 0
    end
    # If row exceeds row_max - 1, change it to row_max - 1
    if row > row_max - 1
      row = row_max - 1
    end
    # Multiply 1 row height by 32 for y-coordinate of window contents
    # transfer origin
    [COLOR=RoyalBlue][B]self.oy = row * 60[/B][/COLOR]
  end
  #--------------------------------------------------------------------------
  # * Get Number of Rows Displayable on 1 Page
  #--------------------------------------------------------------------------
  def page_row_max
    # Subtract a frame height of 32 from the window height, and divide it by
    # 1 row height of 32
    # I want to just show 5 items per page right now
    [COLOR=RoyalBlue][B]return 5#(self.height - 32) / 32[/B][/COLOR]
  end
  #--------------------------------------------------------------------------
  # * Get Number of Items Displayable on 1 Page
  #--------------------------------------------------------------------------
  def page_item_max
    # Multiply row count (page_row_max) times column count (@column_max)
    return page_row_max * @column_max
  end
  #--------------------------------------------------------------------------
  # * Set Help Window
  #     help_window : new help window
  #--------------------------------------------------------------------------
  def help_window=(help_window)
    @help_window = help_window
    # Update help text (update_help is defined by the subclasses)
    if self.active and @help_window != nil
      update_help
    end
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # If cursor position is less than 0
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # Get current row
    row = @index / @column_max
    # If current row is before top row
    if row < self.top_row
      # Scroll so that current row becomes top row
      self.top_row = row
    end
    # If current row is more to back than back row
    if row > self.top_row + (self.page_row_max - 1)
      # Scroll so that current row becomes back row
      self.top_row = row - (self.page_row_max - 1)
    end
    # Calculate cursor width
    cursor_width = self.width / @column_max - 32
    # Calculate cursor coordinates
    x = @index % @column_max * (cursor_width + 32)
    [COLOR=RoyalBlue][B]y = @index / @column_max * 60 - self.oy[/B][/COLOR]
    # Update cursor rectangle
 [COLOR=RoyalBlue][B]   self.cursor_rect.set(x, y, cursor_width, 60)[/B][/COLOR]
  end
    
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If cursor is movable
    if self.active and @item_max > 0 and @index >= 0
      # If pressing down on the directional buttons
      if Input.repeat?(Input::DOWN)
        # If column count is 1 and directional button was pressed down with no
        # repeat, or if cursor position is more to the front than
        # (item count - column count)
        if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
           @index < @item_max - @column_max
          # Move cursor down
          $game_system.se_play($data_system.cursor_se)
          @index = (@index + @column_max) % @item_max
        end
      end
      # If the up directional button was pressed
      if Input.repeat?(Input::UP)
        # If column count is 1 and directional button was pressed up with no
        # repeat, or if cursor position is more to the back than column count
        if (@column_max == 1 and Input.trigger?(Input::UP)) or
           @index >= @column_max
          # Move cursor up
          $game_system.se_play($data_system.cursor_se)
          @index = (@index - @column_max + @item_max) % @item_max
        end
      end
      # If the right directional button was pressed
      if Input.repeat?(Input::RIGHT)
        # If column count is 2 or more, and cursor position is closer to front
        # than (item count -1)
        if @column_max >= 2 and @index < @item_max - 1
          # Move cursor right
          $game_system.se_play($data_system.cursor_se)
          @index += 1
        end
      end
      # If the left directional button was pressed
      if Input.repeat?(Input::LEFT)
        # If column count is 2 or more, and cursor position is more back than 0
        if @column_max >= 2 and @index > 0
          # Move cursor left
          $game_system.se_play($data_system.cursor_se)
          @index -= 1
        end
      end
      # If R button was pressed
      if Input.repeat?(Input::R)
        # If bottom row being displayed is more to front than bottom data row
        if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
          # Move cursor 1 page back
          $game_system.se_play($data_system.cursor_se)
          @index = [@index + self.page_item_max, @item_max - 1].min
          self.top_row += self.page_row_max
        end
      end
      # If L button was pressed
      if Input.repeat?(Input::L)
        # If top row being displayed is more to back than 0
        if self.top_row > 0
          # Move cursor 1 page forward
          $game_system.se_play($data_system.cursor_se)
          @index = [@index - self.page_item_max, 0].max
          self.top_row -= self.page_row_max
        end
      end
    end
    # Update help text (update_help is defined by the subclasses)
    if self.active and @help_window != nil
      update_help
    end
    # Update cursor rectangle
    update_cursor_rect
  end
end

This is the "sollution" i found for my own problem, so I decided post it here for case someone ever get a simillar problem and use search button may find something helpful :P

Thanks

PS: if just depend of me, you are free for close topic
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top