Advanced Command Window

Advanced Command Window
Version: 2.11

Introduction
This is both a scripting tool and a script. It's a scripting because it
will allow scripters to manage his command windows easily, and is a script
because will allow non-scripters to easily manage his menus.

Features
# 1. Shows icons in command windows
# 2. Changes text alignment in command windows
# 3. Allows multiples columns in command windows
# 4. Allows to use arrows in selectable windows or removing the cursor rect
# 5. Allows adding items to default menu system or changing order
Screenshots
Featuring my CMS, Trickster's RTAB, a multi-layer title screen with Naramura battlers and Inquisitor tileset (at background).
http://img66.imageshack.us/img66/1913/cmdwin01vo0.th.png[/IMG] http://img401.imageshack.us/img401/2842/cmdwin02eg3.th.png[/IMG] http://img338.imageshack.us/img338/6582/cmdwin03eh4.th.png[/IMG] http://img398.imageshack.us/img398/184/cmdwin04uq0.th.png[/IMG]
Script
script Spoiler
#============================================================================
# ** Advanced Command Window
#----------------------------------------------------------------------------
# Tibuda
# 2.11
# 04.11.2007
#----------------------------------------------------------------------------
# * Version History :
# 01.17.2007 - Version 1.00 - Plug'n'Play Menu
# 04.05.2007 - Version 2.00 - Advanced Command Window
#   - Added: Icons, text alignment, cursor arrow, custom fonts
# 04.07.2007 - Version 2.10
#   - Remove: Window sprites dependancy
#   - Added: Custom icon alignment
# 04.11.2007 - Version 2.11
#   - Bugfix: Stupid bug I've forgotten when removing window sprites dependancy
#   - Changed: Increased compatibility with SDK part IV
#============================================================================
# This is both a scripting tool and a script. It's a scripting because it
# will allow scripters to manage his command windows easily, and is a script
# because will allow non-scripters to easily manage his menus.
#----------------------------------------------------------------------------
# * Features
#  1. Shows icons in command windows
#  2. Changes text alignment in command windows
#  3. Allows multiples columns in command windows
#  4. Allows to use arrows in selectable windows or removing the cursor rect
#  5. Allows adding items to default menu system or changing order
#============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Adv Command Window', 'tibuda', 2.10, '04.07.2007')

#--------------------------------------------------------------------------
# SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2, [1])

#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Adv Command Window')

#==========================================================================
class Data_Command
  #--------------------------------------------------------------------------
  attr_accessor :call_proc
  attr_accessor :enabled_proc
  attr_accessor :help
  attr_accessor :icon_name
  attr_accessor :name
  #--------------------------------------------------------------------------
  def initialize(name, icon_name = '', call_proc = nil, enabled_proc = nil, help = '')
    @call_proc           = call_proc
    @enabled_proc        = enabled_proc
    @help                = help
    @icon_name           = icon_name
    @name                = name
  end
  #--------------------------------------------------------------------------
  def enabled?
    return true if @enabled_proc.nil?
    case @enabled_proc
    when Proc
      return @enabled_proc.call
    when String
      return eval(@enabled_proc)
    end
    return @enabled_proc
  end
  #--------------------------------------------------------------------------
  def check_enabled
    unless enabled?
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return false
    end
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    return true
  end
  #--------------------------------------------------------------------------
  def call(*args)
    return unless check_enabled
    return if @call_proc.nil?
    case @call_proc
    when Proc
      return @call_proc.call(*args)
    when String
      return eval(@call_proc)
    end
    return nil
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
class Window_Base
  #--------------------------------------------------------------------------
  attr_accessor :normal_font, :disabled_font, :selected_font
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_base_init, :initialize
  def initialize(*args)
    tibuda_cmdwin_win_base_init(*args)
    @normal_font = Font.new
    @normal_font.color = normal_color
    @disabled_font = Font.new
    @disabled_font.color = disabled_color
    @selected_font = Font.new
    @selected_font.color = normal_color
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
class Window_Selectable
  #--------------------------------------------------------------------------
  attr_reader :column_max
  attr_accessor :show_arrow
  attr_accessor :show_cursor_rect
  attr_accessor :arrow_align
  attr_reader :text_align
  attr_reader :icon_align
  attr_reader :icon_opacity
  #--------------------------------------------------------------------------
  def text_align=(value)
    @text_align = value
    refresh
  end
  #--------------------------------------------------------------------------
  def icon_align=(value)
    @icon_align = value
    refresh
  end
  #--------------------------------------------------------------------------
  def icon_opacity=(value)
    @icon_opacity = value
    refresh
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_sel_init, :initialize
  def initialize(*args)
    tibuda_cmdwin_win_sel_init(*args)
    @show_arrow       = false
    @show_cursor_rect = true
    @arrow_align      = 1
    @arrow            = Arrow_Base.new(self.viewport)
    @arrow.visible    = @show_arrow
    @icon_opacity     = 255
    @icon_align       = 0
    @text_align       = self.is_a?(Window_HorizCommand) ? 1 : 0
    @disabled_commands = []
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_sel_update_cursor_rect, :update_cursor_rect
  def update_cursor_rect
    tibuda_cmdwin_win_sel_update_cursor_rect
    @arrow.y = @arrow_align == 1 ? self.cursor_rect.y : 0
    @arrow.y += self.y + 96 + 16
    case @arrow_align
    when 0
      @arrow.x = self.cursor_rect.x
    when 1
      @arrow.x = self.cursor_rect.x + self.cursor_rect.width / 2
    when 2
      @arrow.x = self.cursor_rect.x + self.cursor_rect.width
    end
    @arrow.x += self.x - self.ox + 16
    @arrow.visible = @show_arrow && self.active
    self.cursor_rect.empty unless @show_cursor_rect
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_sel_update, :update
  def update
    tibuda_cmdwin_win_sel_update
    @arrow.update if @arrow.visible
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_sel_dispose, :dispose
  def dispose
    tibuda_cmdwin_win_sel_dispose
    @arrow.dispose
  end
  #--------------------------------------------------------------------------
  def contents_opacity=(value)
    super(value)
    @arrow.opacity = value
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
module TibudaWinCommand
  #--------------------------------------------------------------------------
  def draw_command_item(index, enabled = nil)
    enabled = true if enabled == nil
    if self.is_a?(Window_Command)
      rect = Rect.new(index % @column_max * (self.width / @column_max),
                      index / @column_max * oh,
                      self.width / @column_max - 32,
                      oh)
    elsif self.is_a?(Window_HorizCommand)
      rect = Rect.new(index * @c_spacing, 0, @c_spacing, self.height - 32)
    end
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    item = @commands[index]
    case item
    when String
      text = item
      icon = ''
      align = 0
    when Bitmap
     
      return
    when Data_Command
      text = item.name
      icon = item.icon_name
      enabled = item.enabled?
    end
    opacity = (enabled && @icon_align == 0) ? @icon_opacity : @icon_opacity/2
    x = 4
    unless icon == ''
      icon = RPG::Cache.icon(icon)
      unless icon.nil?
        case @icon_align
        when 0
          icon_x = rect.x + 4
        when 1
          icon_x = rect.x + (rect.width - 32) / 2
        when 2
          icon_x = rect.x + rect.width - 32
        end
        self.contents.blt(icon_x, rect.y + 4, icon, Rect.new(0, 0, 24, 24), opacity)
        if @icon_align == 0 && opacity == 255
          rect.x += 28
          rect.width -= 28
        end
      end
    end
    unless @text == ''
      rect.x += 4
      rect.width -= 8
      if !enabled
        self.contents.font = @disabled_font
      elsif self.index == index
        self.contents.font = @selected_font
      else
        self.contents.font = @normal_font
      end
      self.contents.draw_text(rect, text, @text_align)
    end
  end
  #--------------------------------------------------------------------------
  def call(*args)
    if @commands[@index].is_a?(Data_Command)
      @commands[@index].call(*args)
    end
  end
  #--------------------------------------------------------------------------
  def update_help
    return unless @help_window.is_a?(Window_Help)
    if @commands[@index].is_a?(Data_Command)
      @help_window.set_text(@commands[@index].help)
    elsif @commands[@index].is_a?(String)
      @help_window.set_text(@commands[@index])
    else
      @help_window.set_text('')
    end
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
class Window_Command
  #--------------------------------------------------------------------------
  include TibudaWinCommand
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_Command, :initialize)
  def initialize(width, commands, column_max = 1)
    super(0, 0, width, 32 * commands.size / column_max + 32)
    @item_max = commands.size
    @commands = commands
    @column_max = column_max
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_Command, :refresh)
  def refresh
    if self.contents.height != @commands.size * oh / column_max
      self.contents.dispose
      @item_max = @commands.size
      self.contents = Bitmap.new(self.width - 32, @item_max * oh / column_max)
    else
      self.contents.clear
    end
    for i in 0...@item_max
      draw_item(i, nil)
    end
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_Command, :update_cursor_rect)
  def update_cursor_rect
    super
    draw_item(self.index > 0 ? self.index-1 : @item_max-1)
    draw_item(self.index < @item_max-1 ? self.index+1 : 0)
    draw_item(self.index)
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_Command, :draw_item)
  def draw_item(index, color = nil)
    draw_command_item(index)
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_Command, :disable_item)
  def disable_item(index)
    draw_command_item(index, false)
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
class Window_HorizCommand
  #--------------------------------------------------------------------------
  include TibudaWinCommand
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_HorizCommand, :refresh)
  def refresh
    if self.contents.width != @commands.size * @c_spacing
      self.contents.dispose
      @item_max = @commands.size
      self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
    else
      self.contents.clear
    end
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_win_horiz_update_cursor_rect, :update_cursor_rect
  def update_cursor_rect
    tibuda_cmdwin_win_horiz_update_cursor_rect
    draw_item(self.index > 0 ? self.index-1 : @item_max-1)
    draw_item(self.index < @item_max-1 ? self.index+1 : 0)
    draw_item(self.index)
    @arrow.y = @arrow_align == 1 ? self.cursor_rect.y : 0
    @arrow.y += self.y + 96 + 16
    case @arrow_align
    when 0
      @arrow.x = self.cursor_rect.x
    when 1
      @arrow.x = self.cursor_rect.x + self.cursor_rect.width / 2
    when 2
      @arrow.x = self.cursor_rect.x + self.cursor_rect.width
    end
    @arrow.x += self.x - self.ox + 16
    @arrow.visible = @show_arrow && self.active
    self.cursor_rect.empty unless @show_cursor_rect
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_HorizCommand, :draw_item)
  def draw_item(index, color = nil)
    draw_command_item(index)
  end
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Window_HorizCommand, :disable_item)
  def disable_item(index)
    draw_command_item(index, false)
  end
  #--------------------------------------------------------------------------
end
#==========================================================================

end
#--------------------------------------------------------------------------
# End SDK Enabled Test
#--------------------------------------------------------------------------
Expand to see the code.


Instructions
(these instructions are bad, I'll rewrite them later)
When initializing a command window, follow the syntax
window = Window_Command.new(width, commands[, column_max])
Expand to see the code.

Where width is the window width,
commands is an array of strings, bitmaps or Data_Command objects,
column_max (optional) is the window number of columns (default 1).
When you add strings to the commands array, nothing different happens, but when you add a bitmap it will draw the bitmap and not the text. You can use Data_Command objects to store items text, icons and actions. You initialize a Data_Command object with the syntax
Data_Command.new(name[, icon_name, call_proc, enabled_proc, help])
Expand to see the code.

Where name is the item text,
icon_name (optional) is the icon filename,
call_proc is a Proc to be called when the item is selected (pressing Input::C),
enabled_proc (optional) is a Proc that returns if the item is enabled,
help (optional) is the text to show in help windows when the item is selected.

Compatibility / Requirements
Requires the SDK 2.2 Part I, and SephirothSpawn Window_Selectable (below)
Window_Selectable Spoiler
#==============================================================================
# ** Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
  #-------------------------------------------------------------------------
  #   Name:      oh
  #   Info:      Used to determine row height. This is used to overwrite
  #              the top_row, top_row=, page_row_max & update_cursor_rect
  #              methods replacing the constant 32 with a variable amout.
  #   Author:    SephirothSpawn
  #   Call Info: No Arguments
  #   Returns:   Returns Command Offset Height
  #-------------------------------------------------------------------------
  def oh
    return 32
  end
  #--------------------------------------------------------------------------
  # * Get Top Row
  #--------------------------------------------------------------------------
  def top_row
    return self.oy / self.oh
  end
  #--------------------------------------------------------------------------
  # * Set Top Row
  #--------------------------------------------------------------------------
  def top_row=(row)
    self.oy = [[row, 0].max, row_max - 1].min * self.oh
  end
  #--------------------------------------------------------------------------
  # * Get Number of Rows Displayable on 1 Page
  #--------------------------------------------------------------------------
  def page_row_max
    return (self.height - 32) / self.oh
  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 * self.oh - self.oy
    # Update cursor rectangle
    self.cursor_rect.set(x, y, cursor_width, self.oh)
  end
end
Expand to see the code.


Credits and Thanks
I don't need credits.

Easy Plug-in
You can add the following script to add icons to your game menu and battle, and get a better look to your title screen. It requires SDK part IV
Content Hidden Spoiler
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Adv Command Window') && SDK::Parts.include?(4)
module SDK::Scene_Commands
  module Scene_Title
    New_Game = 'New Game'
    Continue = 'Continue'
    Shutdown = 'Shutdown'
   
    Commands = [New_Game, Continue, Shutdown]
  end

  module Scene_Menu
    Item   = Data_Command.new(DataSystem.words.item, '032-Item01')
    Skill  = Data_Command.new(DataSystem.words.skill, '044-Skill01')
    Equip  = Data_Command.new(DataSystem.words.equip, '010-Head01')
    Status = Data_Command.new('Status', '050-Skill07')
    Save   = Data_Command.new('Save', '037-Item06')
    End_Game = Data_Command.new('End Game', '020-Accessory05')
   
    Commands = [Item, Skill, Equip, Status]

    if SDK.enabled?('Exseiken\'s Party Switcher')
      Switch = Data_Command.new('Switch', '016-Accessory01',
          proc {$scene = Scene_Switch.new})
      Commands << Switch
    end
    if SDK.enabled?('Trickster\'s Bestiary')
      Bestiary = Data_Command.new('Bestiary', '046-Skill03',
          proc {$scene = Scene_Bestiary.new})
      Commands << Bestiary
    end

    Commands += [Save, End_Game]
  end
 
  module Scene_Battle
    Escape   = Data_Command.new('Escape', '020-Accessory05')
    Attack   = Data_Command.new(DataSystem.words.attack, '001-Weapon01')
    Skill    = Data_Command.new(DataSystem.words.skill, '044-Skill01')
    Guard    = Data_Command.new(DataSystem.words.guard, '009-Shield01')
    Item     = Data_Command.new(DataSystem.words.item, '032-Item01')
  end
end
#==========================================================================
class Scene_Menu
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Scene_Menu, :main_command_window)
  def main_command_window
    # Make command window
    commands = SDK::Scene_Commands::Scene_Menu::Commands.dup
    @command_window = Window_Command.new(160, commands)
    @command_window.index = $menu_index.is_a?(Numeric) ? $menu_index : 0
    @command_window.height = 7 * 32
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_scnmenu_disabled_main_command?, :disabled_main_command?
  def disabled_main_command?
    # Gets Current Command
    command = @command_window.command
    # Unless command has enabled proc
    unless command.is_a?(Data_Command) && !command.enabled?.nil?
      # Calls the aliased method
      tibuda_cmdwin_scnmenu_disabled_main_command?
    end
  end
  #--------------------------------------------------------------------------
  alias_method :tibuda_cmdwin_scnmenu_main_cmd_input, :main_command_input
  def main_command_input
    # Gets Current Command
    command = @command_window.command
    # Stores last item index
    $menu_index = @command_window.index
    # Unless command has call proc
    unless command.is_a?(Data_Command) && !command.call.nil?
      # Calls the aliased method
      tibuda_cmdwin_scnmenu_main_cmd_input
    end
  end
  #--------------------------------------------------------------------------
end
#==========================================================================
class Scene_Title
  #--------------------------------------------------------------------------
  attr_reader :continue_enabled
  #--------------------------------------------------------------------------
  SDK.log_overwrite(:Scene_Title, :main_window)
  def main_window
    super
    commands = SDK::Scene_Commands::Scene_Title::Commands.dup
    @command_window = Window_HorizCommand.new([180 * commands.size, 640].min, commands)
    @command_window.show_cursor_rect = false
    @command_window.show_arrow = true
    @command_window.opacity = 0
    @command_window.arrow_align = 1
    @command_window.text_align = 1
    @command_window.selected_font.bold = true
    @command_window.selected_font.size = 28
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 416 - @command_window.height
    @command_window.refresh
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    @command_window.index = 1 if @continue_enabled
  end
  #--------------------------------------------------------------------------
end
#==========================================================================

end
#--------------------------------------------------------------------------
# End SDK Enabled Test
#--------------------------------------------------------------------------
Expand to see the code.
Srry but can you explain a little bit more
THe explanation is very simple already. You can add items or choices in the menu. Look at the features, just reading there you can see how it works... Will this be a scripting tool?

Good job tibuda!
@ArcanaMagek
~Atlaswing~ is right it's only for adding items to the menu.
@~Atlaswing~
Yes, it's a scripting tool. Adding a new item to the menu was always a pain for me, with this script I think it requires less work.
Updated main post.
The script now is a lot better, and is using an object oriented thing to handle the items. It will allow the use of icons, arrows and some other features.
I don't know if someone is using this, but I've updated the script because I removed the window sprites dependancy (it didn't looked like I wanted to), and updated the plugin too, because it inherited a bad script from the original "Plug'n'Play Menu" before the SDK 2 was released (now it's based on SDK part IV). I've added some screenies too. The instructions are so confused, I will rewrite when I have time.
That looks sweet.
Is there a party script being used?
[QUOTE=mumerus;192691]Is there a party script being used?[/QUOTE]
Trickster once edited exeiken's party changer for SDK2.
Dude, that's awesome. I love the whole "# 4. Allows to use arrows in selectable windows or removing the cursor rect", that's sick. =D
[QUOTE=mumerus]Is there a party script being used?[/QUOTE]
You can use this with any party script, I just added native support for the one Trickster converted to SDK (just like Landarma said)
[QUOTE=Cruelty]Dude, that's awesome. I love the whole "# 4. Allows to use arrows in selectable windows or removing the cursor rect", that's sick. =D[/QUOTE]
Good you like it. That's what I'm using in my title scene.
I will write some better instructions on this script when I have some time. I'm having exams at the college, and Microeconomics is requiring much of my free time (when I'm not at the job).

Another thing: I was using in the plugin an global variable, but I'll replace it for an system variable because Yeyinde script will have some problems with it.
By the way, with this script, 'disabled' menu command is shown like 'enabled' menu command. I mean, you cannot distinguish 'disabled' command by color.
[QUOTE=Landarma;212729]By the way, with this script, 'disabled' menu command is shown like 'enabled' menu command. I mean, you cannot distinguish 'disabled' command by color.[/QUOTE]

***testing script

Yeah,you are right!!! God I have to fix it!!! Thanks for reporting that.
I have to add support for animated icons too...
i know you're not menna bring threads up etc, but i really like this menu but can't get it to run i get a wrong argurment thing,

heres a screenshot:
http://img120.imageshack.us/img120/4730/errorgm2.th.jpg[/IMG]
final7, when it's happening, and what other scripts do you have in your project?
I'm still working on this because I've managed to fix that disabled bug, but the custom selected font is not working anymore.
i can't start my game at all, as soon i i press new game i get that error.

and the scripts i have on are;

# ccoa's weather script
# Scene_Battle add ons(oh it gives a little box telling you about your level up)
# â–  ASM - advanced save menu(give you 99 save slots)
# * Universal Message System
# * v1.30
# * by Ccoa
# SDK all parts and the F12 bug fix
# ** Window_Selectable(seth's)
# ●● No F12(by trickster)
# ** Advanced Command Window(aka this menu system)
The script looks very good but I don't understand how to use it, can you put a demo or something like that please?, Thank you in advance :D

Greetings! :D
[QUOTE=Goldknight;222493]The script looks very good but I don't understand how to use it, can you put a demo or something like that please?, Thank you in advance :D

Greetings! :D[/QUOTE]

Demo in my signature
[QUOTE=final7;222342]i can't start my game at all, as soon i i press new game i get that error.

and the scripts i have on are;

# ccoa's weather script
# Scene_Battle add ons(oh it gives a little box telling you about your level up)
# â–  ASM - advanced save menu(give you 99 save slots)
# * Universal Message System
# * v1.30
# * by Ccoa
# SDK all parts and the F12 bug fix
# ** Window_Selectable(seth's)
# ●● No F12(by trickster)
# ** Advanced Command Window(aka this menu system)[/QUOTE]

SDK should be above of all custom scripts, mostly. And if you want to use ASM, it must be modified for SDK.

**By the way, on more problem: http://www.rmxp.org/forums/showthread.php?t=21703
Downloading it now.
Edit: for sure it's my script.
yea, landarma, i relaised after i thought i'd try putting the sdk parts seperate, that on the sdk page it said they need to be above all scripts and below all default ones
demo please
Hellladen, stop necro-posting please.
can i use this with dvv's limit break script

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=12892