RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
In Need of some Window_Command & Window_Selectable Help

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 88
Menu & Battle System Guru
I'm trying to set up a (horizontal) command window where, upon pressing either left or right, the command window refreshes and draws a different picture. However, I cannot seem to get the command window to refresh upon key input.

Any help or suggestions would be MUCH appreciated. Thanks!
Window_Battle_Command
Spoiler for:
Code: [Select]
#===============================================================================
#===============================================================================
# Window_Battle_Command BEGIN ++++++++++++++++++++++++++++++++++++++++++++++++++
#===============================================================================
#===============================================================================
class Window_Battle_Command < Window_Selectable
  #--------------------------------------------------------------------------
  attr_accessor :actor
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     width    : window width
  #     commands : command text string array
  #--------------------------------------------------------------------------
  def initialize(commands)
   super(170, 330, 470, 150)
   #super(width*commands.size,  [commands[0]])
   @column_max = 5
   @item_max = 5
   @commands = commands
   self.contents = Bitmap.new(470, height - 32)
   self.z = 9988
   self.opacity=155
   self.index = 0
   refresh
  end

  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new((@item_width * index)-16, 0, @item_width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], 1)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    if index == 0
      draw_battlemenu_WeaponAttack(0, 85)
    elsif index == 1
      draw_battlemenu_WeaponSkill(0, 85)
    elsif index == 2
      draw_battlemenu_ArmOre(0, 85)
    elsif index == 3
      draw_battlemenu_RankSkill(0, 85)
    elsif index == 4
      draw_battlemenu_Rest(0, 85)
    else
      draw_battlemenu(0, 85)
    end
    for i in 0...@item_max
    self.contents.font.name = "Warlock"
    self.contents.font.bold = false
    self.contents.font.size = 24
#    draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_actor(@actor)
  end
end
#===============================================================================
#===============================================================================
# Window_Battle_Command END ++++++++++++++++++++++++++++++++++++++++++++++++++++
#===============================================================================
#===============================================================================

Window_Selectable_Battle
Spoiler for:
Code: [Select]
#==============================================================================
# ** Window_Selectable_Battle
#------------------------------------------------------------------------------
#  This window class contains cursor HORIZONTAL movement and scroll functions.
#==============================================================================
class Window_Selectable_Battle < 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
    return self.oy / 32
  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
    self.oy = row * 32
  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
    return (self.height - 32) / 32
  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)
    y = @index / @column_max * 32 - self.oy
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If cursor is movable
    if self.active and @item_max > 0 and @index >= 0
      # If the right directional button was pressed
      if Input.repeat?(Input::RIGHT)
        if (@column_max == 1 and Input.trigger?(Input::RIGHT)) 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 left directional button was pressed
      if Input.repeat?(Input::LEFT)
        if (@column_max == 1 and Input.trigger?(Input::LEFT)) 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
    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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, I would suggest making your classes subclasses of Window_Selectable or Window_Command rather than Window_Base. That way you'll have all of the methods you need and only have to change a few things. For the refresh, you might just want to keep track of the old index with a variable. Say, initialize the variable @old_index in the initialize method. Then you can use this check to see if index has changed:

Code: [Select]
if @old_index != self.index
  refresh
  @old_index = self.index
end

in the update method.