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.

[VX]Window_Icon Command

Window_Icon Command
This script-let is a simple edit of RPG Maker VX's Window_Command. If used correctly it draws a command window with icons at the left hand side of the text.

Setting the window up it's fairly simple. Down below is an ![tested]! example of how the script works in Scene_Title (Where the numbers are is the index of the icon beside the command) :

Code:
class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    s1 = [10,Vocab::new_game]
    s2 = [15,Vocab::continue]
    s3 = [20,Vocab::shutdown]
    @command_window = Window_IconCommand.new(172, [s1, s2, s3])
    @command_window.x = (544 - @command_window.width) / 2
    @command_window.y = 288
    if @continue_enabled                    # If continue is enabled
      @command_window.index = 1             # Move cursor over command
    else                                    # If disabled
      @command_window.draw_item(1, false)   # Make command semi-transparent
    end
    @command_window.openness = 0
    @command_window.open
  end
end

Code:
#==============================================================================
# ** Window_IconCommand
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================

class Window_IconCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :commands                 # command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     width      : window width
  #     commands   : command string array
  #     column_max : digit count (if 2 or more, horizontal selection)
  #     row_max    : row count (0: match command count)
  #     spacing    : blank space when items are arrange horizontally
  #--------------------------------------------------------------------------
  def initialize(width, commands, column_max = 1, row_max = 0, spacing = 32)
    if row_max == 0
      row_max = (commands.size + column_max - 1) / column_max
    end
    super(0, 0, width, row_max * WLH + 32, spacing)
    @commands = commands
    @item_max = commands.size
    @column_max = column_max
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index   : item number
  #     enabled : enabled flag. When false, draw semi-transparently.
  #--------------------------------------------------------------------------
  def draw_item(index, enabled = true)
    rect = item_rect(index)
    rect.x += 4 + 24
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    draw_icon(@commands[index][0], rect.x - 24, rect.y)
    self.contents.draw_text(rect, @commands[index][1])
  end
  #--------------------------------------------------------------------------
  # * Draw Item Name
  #     item    : Item (skill, weapon, armor are also possible)
  #     x       : draw spot x-coordinate
  #     y       : draw spot y-coordinate
  #     enabled : Enabled flag. When false, draw semi-transparently.
  #--------------------------------------------------------------------------
  def draw_item_name(index, x, y, enabled = true)
    draw_icon(index, x, y, enabled)
  end
end
http://img100.imageshack.us/img100/2168/testediconcommandfx7.png[/img]
 
@woratana: you said it, I make it XD

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

# ** Window_Command

#------------------------------------------------------------------------------

#  This window deals with general command choices.

#==============================================================================



class Window_Command < Window_Selectable

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :commands                 # command
  
  ENABLE_UNSELECTED_ITEM = true

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     width      : window width

  #     commands   : command string array

  #     column_max : digit count (if 2 or more, horizontal selection)

  #     row_max    : row count (0: match command count)

  #     spacing    : blank space when items are arrange horizontally

  #--------------------------------------------------------------------------

  def initialize(width, commands, column_max = 1, row_max = 0, spacing = 32)

    if row_max == 0

      row_max = (commands.size + column_max - 1) / column_max

    end

    super(0, 0, width, row_max * WLH + 32, spacing)

    @commands = commands

    @item_max = commands.size

    @column_max = column_max

    refresh

    self.index = 0

  end
  
  def icon?
  	for i in 0...@item_max

      return true if @commands[i].is_a?(Array)

    end
    return false
  end
  

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    for i in 0...@item_max

      draw_item(i)

    end

  end

  #--------------------------------------------------------------------------

  # * Draw Item

  #     index   : item number

  #     enabled : enabled flag. When false, draw semi-transparently.

  #--------------------------------------------------------------------------

  def draw_item(index, enabled = true)

    rect = item_rect(index)

    rect.x += 4 + icon? ? 24 : 0

    rect.width -= 8

    self.contents.clear_rect(rect)

    self.contents.font.color = normal_color

    self.contents.font.color.alpha = enabled ? 255 : 128
    draw_icon(@commands[index][0], rect.x - 24, rect.y, ENABLE_UNSELECTED_ITEM || enabled) if icon?

    self.contents.draw_text(rect, icon? ? @commands[index][1] : @commands[index])

  end

end

PS: this is VX only.. i work on a both version.
 
woratana":2e7u0p10 said:
@Hanmac
Well, that's diffrent from mine XD

http://www.paste-it.net/7920
^ It has feature to add Icon & Color & Align & Self-Disable to window_command with tag.

The version that added only show icon can be found from here :)
http://www.rpgrevolution.com/forums/?showtopic=11823
interesting... i make it ready for xp

PS: <ic> -> interger is not good.
if you check for string, you can also show iconfiles if draw_icon support this (i have this version)

PPS: <d> must above of all, because the alpha of icons


PPPS: we both do one thing..
dont make my scripts, but i can need hleb XD
 

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