Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Command Window
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.


First Off, Thanx RPGMAKER for helping me getting the tabed text function to work.

Features:
Rectangle Around Commands can be Drawn or not
Text Can be Centered or Not
Text Push (Whenever a command is highlighted, the text is pushed right)



Replace you old Window_Command With this one
(This will not make any of your other command_windows different)
Code:
# Class Window_Command
#Written By SephirothSpawn
#Call script Commands
#XXXXX.new(width, commands, rect_on, center, tab, select_color, unselect_color
#rect_on: True=Draw Rectangle Box  False=Doesn't Draw Rectangle Box
#center: True=Centers Text  False=Left Justify
#tab:  0=Doesn't Push Text to the Right  X: Pushes Text to the Right X pixels
#select_color:  If tab !=0, the text that is pushed color
#unselect_color:  If tab !=0, the text that isn't pushed color
class Window_Command < Window_Selectable
#-----------------------------------------------------------------
  def initialize(width, commands, rect_on=true, center=false, tab=0, select_color=normal_color, unselect_color=disabled_color)
    super(0, 0, width, commands.size*32+32, rect_on)
    @item_max = commands.size
    @commands = commands
    @center = center
    @tab = tab
    @select_color = select_color
    @unselect_color = unselect_color
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = $defaultfontsize
    refresh
    self.index = 0
  end
#-----------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      if @tab==0
        draw_item(i, @select_color)
      else
        if i == self.index
          draw_itemd(self.index, @select_color)
        else
          draw_item(i, @unselect_color)
        end
      end
    end
  end
#-----------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    self.contents.font.color = color
    text=@commands[index]
    cx = self.contents.text_size(text).width
    rect_width = self.contents.width - 8
    x=4
    if @center==true
      x= rect_width/2 - cx/2
    end
    rect = Rect.new(x, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
#-----------------------------------------------------------------
  def draw_itemd(index, color)
    self.contents.font.color = color
    text=@commands[index]
    self.contents.font.color = color
    cx = self.contents.text_size(text).width
    rect_width = self.contents.width - 8
    x=4
    if @center==true
      x= rect_width/2 - cx/2
    end
    rect = Rect.new(x+@tab, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, text)
  end
#-----------------------------------------------------------------
  def disable_item(index)
    if @tab==0
      draw_item(index, @unselect_color)
    else
      if index == self.index
        draw_itemd(self.index, @unselect_color)
      else
        draw_item(index, @unselect_color)
      end
    end
  end
#-----------------------------------------------------------------
end

And Replace Your Window_Selectable With this
Code:
class Window_Selectable < Window_Base
#-----------------------------------------------------------------
  attr_reader   :index
  attr_reader   :help_window
#-----------------------------------------------------------------
  def initialize(x, y, width, height, rect_on=true)
    super(x, y, width, height)
    @item_max = 1
    @column_max = 1
    @index = -1
    @rect_on=rect_on
  end
#-----------------------------------------------------------------
  def index=(index)
    @index = index
    if self.active and @help_window != nil
      update_help
    end
    update_cursor_rect
  end
#-----------------------------------------------------------------
  def row_max
    return (@item_max + @column_max - 1) / @column_max
  end
#-----------------------------------------------------------------
  def top_row
    return self.oy / 32
  end
#-----------------------------------------------------------------
  def top_row=(row)
    if row < 0
      row = 0
    end
    if row > row_max - 1
      row = row_max - 1
    end
    self.oy = row * 32
  end
#-----------------------------------------------------------------
  def page_row_max
    return (self.height - 32) / 32
  end
#-----------------------------------------------------------------
  def page_item_max
    return page_row_max * @column_max
  end
#-----------------------------------------------------------------
  def help_window=(help_window)
    @help_window = help_window
    if self.active and @help_window != nil
      update_help
    end
  end
#-----------------------------------------------------------------
  def update_cursor_rect
     if @index < 0
       self.cursor_rect.empty
       return
     end
     row = @index / @column_max
     if row < self.top_row
       self.top_row = row
     end
     if row > self.top_row + (self.page_row_max - 1)
       self.top_row = row - (self.page_row_max - 1)
     end
     cursor_width = self.width / @column_max - 32
     x = @index % @column_max * (cursor_width + 32)
     y = @index / @column_max * 32 - self.oy
     self.cursor_rect.set(x, y, cursor_width, 32)
     unless @rect_on
       self.cursor_rect.empty
     end
  end
#-----------------------------------------------------------------
  def update
    super
    if self.active and @item_max > 0 and @index >= 0
      if Input.repeat?(Input::DOWN)
        if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
          @index < @item_max - @column_max
          $game_system.se_play($data_system.cursor_se)
          @index = (@index + @column_max) % @item_max
        end
      end
      if Input.repeat?(Input::UP)
        if (@column_max == 1 and Input.trigger?(Input::UP)) or
           @index >= @column_max
          $game_system.se_play($data_system.cursor_se)
          @index = (@index - @column_max + @item_max) % @item_max
        end
      end
      if Input.repeat?(Input::RIGHT)
        if @column_max >= 2 and @index < @item_max - 1
          $game_system.se_play($data_system.cursor_se)
          @index += 1
        end
      end
      if Input.repeat?(Input::LEFT)
        if @column_max >= 2 and @index > 0
          $game_system.se_play($data_system.cursor_se)
          @index -= 1
        end
      end
      if Input.repeat?(Input::R)
        if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
          $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 Input.repeat?(Input::L)
        if self.top_row > 0
          $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
    if self.active and @help_window != nil
      update_help
    end
    update_cursor_rect
  end
#-----------------------------------------------------------------
end

Special Notes:

Because all the Items are redrawn in the refresh method, you have to refresh your window and update it in your update method.
Code:
@window_command.update
@window_command.refresh

Also, you must re-disable your items in the update method as well
Code:
if @continue_enabled==false
      @command_window.disable_item(1)
    end
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Display a gold window on the map Chronic_NG 0 2,734 12-04-2006, 01:00 PM
Last Post: Chronic_NG
  Description Window Caldaron 0 2,521 10-09-2006, 01:00 PM
Last Post: Caldaron
  Coordinate Window on the map Slanter 0 2,283 08-29-2006, 01:00 PM
Last Post: Slanter
  Advanced Command Windows Tsunokiette 0 2,321 07-07-2006, 01:00 PM
Last Post: Tsunokiette
  Transparent command box in title ryujijitei 0 1,896 04-29-2006, 01:00 PM
Last Post: ryujijitei
  Cursor Command Tsunokiette 0 2,115 01-07-2006, 01:00 PM
Last Post: Tsunokiette
  Horizontal Command Windows SephirothSpawn 0 2,313 11-04-2005, 01:00 PM
Last Post: SephirothSpawn
  Location Window Eccid 0 2,077 09-11-2005, 01:00 PM
Last Post: Eccid
  Different Gold Window Sheol 0 2,178 09-01-2005, 01:00 PM
Last Post: Sheol
  Custom message window dragonslayer 0 2,123 03-25-2005, 01:00 PM
Last Post: dragonslayer



Users browsing this thread: