Window : Command Icons

Window : Command Icons
Version: 3.5
By: Kain Nobel

Introduction

Easily allows you to put icons in your command windows, without having to go through and edit other scripts.

Features

  • Will put icons in any Window_Command (or Window_HorizCommand)
  • No need to edit other scripts to achieve this effect
  • Easy to use

Screenshots

Some Examples Spoiler
The Title...
Image
The Menu...
Image
The Battle (Party Command)...
Image
The Battle (Actor Command)...
Image


Script

Window : Command Icons Spoiler
  1. #===============================================================================
  2. # ** Window : Command Icons
  3. #===============================================================================
  4. #-------------------------------------------------------------------------------
  5. # * SDK Log
  6. #-------------------------------------------------------------------------------
  7. SDK.log('Window.CommandIcons', 'Kain Nobel ©', 3.5, '2009.06.17')
  8. #-------------------------------------------------------------------------------
  9. # * SDK Enabled Test : Begin
  10. #-------------------------------------------------------------------------------
  11. if SDK.enabled?('Window.CommandIcons')
  12.  
  13. #===============================================================================
  14. # ** Window_Base
  15. #===============================================================================
  16.  
  17. class Window_Base < Window
  18.   #-----------------------------------------------------------------------------
  19.   # * Included Modules
  20.   #-----------------------------------------------------------------------------
  21.   include SDK::Vocab
  22.   #-----------------------------------------------------------------------------
  23.   # * Icons
  24.   #-----------------------------------------------------------------------------
  25.   Icons                         = Hash.new  # Don't tamper with
  26.   Icons.default                 = Hash.new  # Don't tamper with
  27.   Icons.default.default         = Hash.new  # Don't tamper with
  28.   Icons.default.default.default = Hash.new  # Don't tamper with
  29.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  30.   # ** Scene_Title  : @command_window                                          #
  31.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  32.   s, w = 'Scene_Title', '@command_window'
  33.   Icons[s][w][Scene_Title::New_Game] = '050-Skill07'
  34.   Icons[s][w][Scene_Title::Continue] = '039-Item08'
  35.   Icons[s][w][Scene_Title::Shutdown] = '046-Skill03'
  36.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  37.   # ** Scene_Menu   : @command_window                                          #
  38.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  39.   s, w = 'Scene_Menu', '@command_window'
  40.   Icons[s][w][Scene_Menu::Item]      = '032-Item01'
  41.   Icons[s][w][Scene_Menu::Skill]     = '044-Skill01'
  42.   Icons[s][w][Scene_Menu::Equip]     = '001-Weapon01'
  43.   Icons[s][w][Scene_Menu::Status]    = '050-Skill07'
  44.   Icons[s][w][Scene_Menu::Save]      = '037-Item06'
  45.   Icons[s][w][Scene_Menu::End_Game]  = '046-Skill03'
  46.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  47.   # ** Scene_Batte  : @actor_command_window                                    #
  48.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  49.   s, w = 'Scene_Battle', '@actor_command_window'
  50.   Icons[s][w][Scene_Battle::Attack]  = '001-Weapon01'
  51.   Icons[s][w][Scene_Battle::Skill]   = '044-Skill01'
  52.   Icons[s][w][Scene_Battle::Guard]   = '009-Shield01'
  53.   Icons[s][w][Scene_Battle::Item]    = '032-Item01'
  54.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  55.   # ** Scene_Battle : @party_command_window                                    #
  56.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  57.   s, w = 'Scene_Battle', '@party_command_window'
  58.   Icons[s][w][Scene_Battle::Fight]   = '001-Weapon01'
  59.   Icons[s][w][Scene_Battle::Escape]  = '020-Accessory05'
  60.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  61.   # ** Scene_End    : @command_window
  62.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  63.   s, w = 'Scene_End', '@command_window'
  64.   #-----------------------------------------------------------------------------
  65.   # * Icon Settings
  66.   #-----------------------------------------------------------------------------
  67.   def icon_settings
  68.     if @icon_settings.nil?
  69.       scene_key       = "#{$scene.class}"
  70.       window_key      = get_scene_instance
  71.       @icon_settings  = Icons[scene_key][window_key]
  72.     end
  73.     @icon_settings
  74.   end
  75.   #-----------------------------------------------------------------------------
  76.   # * Icon At?
  77.   #-----------------------------------------------------------------------------
  78.   def icon_at?(index)
  79.     settings = icon_settings
  80.     settings[@commands[index]]
  81.   end
  82.   #-----------------------------------------------------------------------------
  83.   # * Command Has Icon Key?
  84.   #-----------------------------------------------------------------------------
  85.   def command_icon_key?(index)
  86.     icon_settings.has_key?(@commands[index])
  87.   end
  88.   #-----------------------------------------------------------------------------
  89.   # * Command Has Icon Value?
  90.   #-----------------------------------------------------------------------------
  91.   def command_icon_value?(index)
  92.     icon_settings[@command[index]].is_a?(String)
  93.   end
  94.   #-----------------------------------------------------------------------------
  95.   # * Command Has Icon?
  96.   #-----------------------------------------------------------------------------
  97.   def command_icon?(index)
  98.     icon_settings.has_key?(@commands[index])
  99.   end
  100.   #-----------------------------------------------------------------------------
  101.   # * Command Icon
  102.   #-----------------------------------------------------------------------------
  103.   def command_icon(index)
  104.     RPG::Cache.icon(icon_at?(index))
  105.   end
  106.   #-----------------------------------------------------------------------------
  107.   # * Get Scene Instance
  108.   #-----------------------------------------------------------------------------
  109.   def get_scene_instance
  110.     $scene.instance_variables.each do |object_name|
  111.       object = $scene.instance_variable_get(object_name)
  112.       return object_name if object == self
  113.     end
  114.   end
  115. end
  116.  
  117. #===============================================================================
  118. # ** Window_Command
  119. #===============================================================================
  120.  
  121. class Window_Command < Window_Selectable
  122.   #-----------------------------------------------------------------------------
  123.   # * Alias Listings
  124.   #-----------------------------------------------------------------------------
  125.   alias_method :commandicons_wincommand_drawitem, :draw_item
  126.   #-----------------------------------------------------------------------------
  127.   # * Draw Item
  128.   #-----------------------------------------------------------------------------
  129.   def draw_item(index, color)
  130.     unless command_icon?(index)
  131.       commandicons_wincommand_drawitem(index, color)
  132.       return
  133.     end
  134.     icon = command_icon(index)
  135.     op = (color == disabled_color ? 160 : 255)
  136.     self.contents.blt(0, 32 * index + 4, icon, icon.rect, op)
  137.     self.contents.font.color = color
  138.     rect = Rect.new(28, 32 * index, self.contents.width - 28, 32)
  139.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  140.     self.contents.draw_text(rect, @commands[index])
  141.   end
  142. end
  143.  
  144. #===============================================================================
  145. # ** Window_HorizCommand
  146. #===============================================================================
  147.  
  148. class Window_HorizCommand < Window_Selectable
  149.   #-----------------------------------------------------------------------------
  150.   # * Alias Listings
  151.   #-----------------------------------------------------------------------------
  152.   alias_method :commandicons_winhcommand_drawitem, :draw_item
  153.   #-----------------------------------------------------------------------------
  154.   # * Draw Item
  155.   #-----------------------------------------------------------------------------
  156.   def draw_item(index, color)
  157.     unless command_icon?(index)
  158.       commandicons_winhcommand_drawitem(index, color)
  159.       return
  160.     end
  161.     icon = command_icon(index)
  162.     op = (color == disabled_color ? 160 : 255)
  163.     x = index * @c_spacing + 4
  164.     self.contents.blt(x, 4, icon, icon.rect, op)
  165.     command = commands[index]
  166.     x += 28
  167.     self.contents.font.color = color
  168.     self.contents.draw_text(x, 0, @c_spacing - 8, 32, command, @alignment)
  169.   end
  170. end
  171.  
  172. #-------------------------------------------------------------------------------
  173. # * SDK Enabled Test : End
  174. #-------------------------------------------------------------------------------
  175. end
Expand to see the code.

Window : Command Icons (Take 2!) Spoiler
  1. #===============================================================================
  2. # ** Window : Command Icons
  3. #===============================================================================
  4. #-------------------------------------------------------------------------------
  5. # * SDK Log
  6. #-------------------------------------------------------------------------------
  7. SDK.log('Window.CommandIcons', 'Kain Nobel ©', 3.5, '2009.06.17')
  8. #-------------------------------------------------------------------------------
  9. # * SDK Enabled Test : Begin
  10. #-------------------------------------------------------------------------------
  11. if SDK.enabled?('Window.CommandIcons')
  12.  
  13. #===============================================================================
  14. # ** Window_Base
  15. #===============================================================================
  16.  
  17. class Window_Base < Window
  18.   #-----------------------------------------------------------------------------
  19.   # * Included Modules
  20.   #-----------------------------------------------------------------------------
  21.   include SDK::Vocab
  22.   #-----------------------------------------------------------------------------
  23.   # * Icons
  24.   #-----------------------------------------------------------------------------
  25.   Icons = Hash.new  # Don't tamper with
  26.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  27.   # ** Scene_Title  : @command_window                                          #
  28.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  29.   s, w = 'Scene_Title', '@command_window'
  30.   Icons[s] ||= Hash.new
  31.   Icons[s][w] = Hash.new
  32.   Icons[s][w][Scene_Title::New_Game] = '050-Skill07'
  33.   Icons[s][w][Scene_Title::Continue] = '039-Item08'
  34.   Icons[s][w][Scene_Title::Shutdown] = '046-Skill03'
  35.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  36.   # ** Scene_Menu   : @command_window                                          #
  37.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  38.   s, w = 'Scene_Menu', '@command_window'
  39.   Icons[s] ||= Hash.new
  40.   Icons[s][w] = Hash.new
  41.   Icons[s][w][Scene_Menu::Item]      = '032-Item01'
  42.   Icons[s][w][Scene_Menu::Skill]     = '044-Skill01'
  43.   Icons[s][w][Scene_Menu::Equip]     = '001-Weapon01'
  44.   Icons[s][w][Scene_Menu::Status]    = '050-Skill07'
  45.   Icons[s][w][Scene_Menu::Save]      = '037-Item06'
  46.   Icons[s][w][Scene_Menu::End_Game]  = '046-Skill03'
  47.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  48.   # ** Scene_Batte  : @actor_command_window                                    #
  49.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  50.   s, w = 'Scene_Battle', '@actor_command_window'
  51.   Icons[s] ||= Hash.new
  52.   Icons[s][w] = Hash.new
  53.   Icons[s][w][Scene_Battle::Attack]  = '001-Weapon01'
  54.   Icons[s][w][Scene_Battle::Skill]   = '044-Skill01'
  55.   Icons[s][w][Scene_Battle::Guard]   = '009-Shield01'
  56.   Icons[s][w][Scene_Battle::Item]    = '032-Item01'
  57.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  58.   # ** Scene_Battle : @party_command_window                                    #
  59.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  60.   s, w = 'Scene_Battle', '@party_command_window'
  61.   Icons[s] ||= Hash.new
  62.   Icons[s][w] = Hash.new
  63.   Icons[s][w][Scene_Battle::Fight]   = '001-Weapon01'
  64.   Icons[s][w][Scene_Battle::Escape]  = '020-Accessory05'
  65.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  66.   # ** Scene_End    : @command_window                                          #
  67.   #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
  68.   s, w = 'Scene_End', '@command_window'
  69.   Icons[s] ||= Hash.new
  70.   Icons[s][w] = Hash.new
  71.   Icons[s][w][Scene_End::To_Title]   = '001-Weapon01'
  72.   Icons[s][w][Scene_End::Shutdown]   = '001-Weapon01'
  73.   Icons[s][w][Scene_End::Cancel]     = '001-Weapon01'
  74.   #-----------------------------------------------------------------------------
  75.   # * Update
  76.   #-----------------------------------------------------------------------------
  77.   alias_method :commandicons_winbase_update, :update
  78.   def update
  79.     commandicons_winbase_update
  80.     if self.respond_to?(:refresh) && self.respond_to?(:commands) && !@icons_set
  81.       self.refresh
  82.       @icons_set = true
  83.     end
  84.   end
  85.   #-----------------------------------------------------------------------------
  86.   # * Icon Settings
  87.   #-----------------------------------------------------------------------------
  88.   def icon_settings
  89.     scene_key       = "#{$scene.class}"
  90.     window_key      = get_scene_instance
  91.     if Icons.has_key?(scene_key) && Icons[scene_key].has_key?(window_key)
  92.       return Icons[scene_key][window_key]
  93.     end
  94.   end
  95.   #-----------------------------------------------------------------------------
  96.   # * Icon At?
  97.   #-----------------------------------------------------------------------------
  98.   def icon_at?(index)
  99.     settings = icon_settings
  100.     settings[@commands[index]]
  101.   end
  102.   #-----------------------------------------------------------------------------
  103.   # * Command Icon?
  104.   #-----------------------------------------------------------------------------
  105.   def command_icon?(index)
  106.     return false unless icon_settings.is_a?(Hash)
  107.     icons = icon_settings
  108.     icons.has_key?(@commands[index]) && icons[@commands[index]].is_a?(String)
  109.   end
  110.   #-----------------------------------------------------------------------------
  111.   # * Command Icon
  112.   #-----------------------------------------------------------------------------
  113.   def command_icon(index)
  114.     RPG::Cache.icon(icon_at?(index))
  115.   end
  116.   #-----------------------------------------------------------------------------
  117.   # * Get Scene Instance
  118.   #-----------------------------------------------------------------------------
  119.   def get_scene_instance
  120.     $scene.instance_variables.each do |object_name|
  121.       object = $scene.instance_variable_get(object_name)
  122.       next unless object.kind_of?(Window)
  123.       next unless object.respond_to?(:commands)
  124.       return object_name if object == self
  125.     end
  126.   end
  127. end
  128.  
  129. #===============================================================================
  130. # ** Window_Command
  131. #===============================================================================
  132.  
  133. class Window_Command < Window_Selectable
  134.   #-----------------------------------------------------------------------------
  135.   # * Alias Listings
  136.   #-----------------------------------------------------------------------------
  137.   alias_method :commandicons_wincommand_drawitem, :draw_item
  138.   #-----------------------------------------------------------------------------
  139.   # * Draw Item
  140.   #-----------------------------------------------------------------------------
  141.   def draw_item(index, color)
  142.     unless command_icon?(index)
  143.       commandicons_wincommand_drawitem(index, color)
  144.       return
  145.     end
  146.     icon = command_icon(index)
  147.     op = (color == disabled_color ? 160 : 255)
  148.     self.contents.blt(0, 32 * index + 4, icon, icon.rect, op)
  149.     self.contents.font.color = color
  150.     rect = Rect.new(28, 32 * index, self.contents.width - 28, 32)
  151.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  152.     self.contents.draw_text(rect, @commands[index])
  153.   end
  154. end
  155.  
  156. #===============================================================================
  157. # ** Window_HorizCommand
  158. #===============================================================================
  159.  
  160. class Window_HorizCommand < Window_Selectable
  161.   #-----------------------------------------------------------------------------
  162.   # * Alias Listings
  163.   #-----------------------------------------------------------------------------
  164.   alias_method :commandicons_winhcommand_drawitem, :draw_item
  165.   #-----------------------------------------------------------------------------
  166.   # * Draw Item
  167.   #-----------------------------------------------------------------------------
  168.   def draw_item(index, color)
  169.     unless command_icon?(index)
  170.       commandicons_winhcommand_drawitem(index, color)
  171.       return
  172.     end
  173.     icon = command_icon(index)
  174.     op = (color == disabled_color ? 160 : 255)
  175.     x = index * @c_spacing + 4
  176.     self.contents.blt(x, 4, icon, icon.rect, op)
  177.     command = commands[index]
  178.     x += 28
  179.     self.contents.font.color = color
  180.     self.contents.draw_text(x, 0, @c_spacing - 8, 32, command, @alignment)
  181.   end
  182. end
  183.  
  184. #-------------------------------------------------------------------------------
  185. # * SDK Enabled Test : End
  186. #-------------------------------------------------------------------------------
  187. end
Expand to see the code.

Instructions

Place Above Main and Below SDK, this script is already set up for Title, Menu and Battle and End Game scenes. Just follow the example of how I set it up and it should be easy enough to understand. I would suggest having this script at the bottom of your scripts, just one up from Main.

FAQ

Example of setting icons Spoiler
First thing you need to do is set your keys for Scene and Window, where s is the name of the $scene the window will be in, and w is the name of the instance variable which represents the window. Basically, an example would be...

s, w = 'Scene_Menu', '@command_window'

Then, you have to create a new hash within Icons constant for it...

Icons[s] ||= Hash.new # This will create a new hash for the scene, only if it isn't defined
Icons[s][w] = Hash.new # This will create a new hash for the window

Then you set all your icons like so...

Icons[s][w]["Command Name"] = "icon filename"

The end result should look like...

  1. s, w = 'Scene_Menu', '@command_window'
  2. Icons[s] ||= Hash.new
  3. Icons[s][w] = Hash.new
  4. Icons[s][w]['My Command'] = 'My Icon'
Expand to see the code.


...and thats basically how it works...


Compatibility

This script does use SDK, but with some editing you can make it non-SDK. If I have some time I'll make a non-SDK version, but really I expect you to be responsible enough to be able to figure that out on your own :P

Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, but credit is required!
Nice work Kain! :thumb:

I started making a Non-SDK version, but I ran into a bit of a problem.

'Shutdown' has the icon, no matter what scene. Is that supposed to happen? Because other than that, it's done and Non-SDK.
I have a more simple script that do exaclty the same thing.

The icon file name is based on the command name (so it's the command name + '_icon') and the commands without icon are shown normally.
@Kain: Another great script. Just one question; Could we add/remove icons by adding/removing the following?
  1.   s, w = 'Scene_Battle', '@party_command_window'
  2.    Icons[s][w][Scene_Battle::Fight]   = '001-Weapon01'
  3.    Icons[s][w][Scene_Battle::Escape]  = '020-Accessory05'
Expand to see the code.
for example...
  1.   s, w = 'Scene_Login', '@login_command_window'
  2.    Icons[s][w][Scene_Login::Login]   = 'ICON-NAME'
  3.    Icons[s][w][Scene_Login::Register]  = 'ICON-NAME'
  4.    Icons[s][w][Scene_Login::Quit]  = 'ICON-NAME'
Expand to see the code.
??? That's what I got out of it... Please correct me if I'm wrong...
Also, will this conflict with command windows that don't have icons (aren't listed?)

@Atoa: Care to link, or release if you haven't already?
@TehSeph
Well most of my scripts aren't on english and i'm really busy to translate them.

And let's stick on the topic xD
I'd still like to know why the commands have the same icons regardless of the scene and window, Kain. Of course there is the Icons[scene][window][command], but it does pretty much nothing, the command is the only key that changes anything.
@TehSeph : Yeah, thats basically how it works! And yes, if there is no icon assigned to a certain command it'll just display normally, no error occurs or anything.

@Atoa : You can share yours here if you'd like or PM me with it so I can look it over, maybe I'll learn something new ;)

@Ulqiorra : That is an interesting find, I didn't think it would do that but now I see what you're talking about, thanks for pointing that out. I have a theory of what might be causing that, so I'll look into it tonight and see if I can fix it.
Which version of SDK does this need? 2.4 or 2.3?

EDIT: Nevermind. Though i notice quite an interesting problem if anyone is using a simple menu edit script like i am. (By kRECKER) using more commands than the default ones.

It does work with it though you won't see any icons with it unless there's a way to add them. I'll show you an example.

Image

This is the script i'm using.
viewtopic.php?t=18863
@XP Learner : You need to add the icon into the script, it doesn't automatically define the icons for ya and it only works for command windows...

Just an example... Spoiler
  1. s, w = 'Scene_Menu', '@command_window'
  2. Icons[s][w]['Spirit']  = 'my icon name'
Expand to see the code.


If you look in the screenshots for Battle, you'll see that the Gambit command has its own icon, I set it up just like that :P

@Everyone else : I've been trying to fix the weird issue where it ignores the scene and window, just sets icons based on command... I'm glad it was pointed out, and I'm having alot of trouble trying to get it to work.

If anybody else is able to figure it out, the method you need to look at is Window_Base#get_scene_instance. After a couple hours of testing and tweaking it, all that happens is it'll return an array of all the $scene's instance variables always excluding the window in question...

Example Scene_Title's instances Spoiler
  1. ["@continue_enabled", "@previous_scene"]
Expand to see the code.


...What this means is that when a window is initialized, ie @command_window = Window_Command.new(160, commands), that the instance of @command_window isn't yet created when the method is ran, until after everything has already initialized and ran once.

So... now we have an idea of the problem, but I still haven't figured out a solution. What intrigues me is how it'll still set the correct icons for most of the windows reguardless of the window key, instead of raising some kind of game crashing error or just not setting anything.

So when you set...

Icons['Scene_Menu']['@command_window']

...The key that Window_Base#get_scene_instance returns...

Icons['Scene_Menu'][['@menu_index', '@previous_scene']]

...meaning the window hasn't registered to the instance of '@command_window' yet...

One solution could be to, after the very first update, create a new bitmap with just the icons and then blt self.contents onto it with x + 28 or something (since the instance will then be registered within the scene), but again I'm not sure if that'll be the most effecient fix, or if that'll even work like I think it will and I can already tell that won't work the same for HorizCommand as it would for regular Window_Command windows (or maybe it will, who knows... too tired to think at this point).

If anybody who knows their stuff has any tips or advice I'll definately take it, but I'm gonna try a couple things tomorrow and see if I can get this working correctly, only if I can get some free time that is.
Yeah basically, an object doesn't "exist" until its initialize method hasn't finished to run.

if i follow the process of instructions,

scne -> create_window -> my_window.new -> initialize -> refresh -> draw_item ( with your stuff in it ) , initialize runs refresh before it has ended, and refresh execute draw_item, where is the code that kain added. Therefore by the times it runs, the instance variable isn't yet defined. (just in the process of being it)

basically a solution would be to have a my_window.refresh right after the my_window.new so that we go again through draw_item.

sadly, i've been looking for a way of getting the receiver name, from its instance ( like each time you do foo = thing.new, the thing instance knows the variable is called "foo" ) but nothing at all.
Here is the code.

He is really simple. a added a line to get the command name and add the icon based on it.
If the icon doesn't exist, it would return a "no file" erro, but i added an rescue to prevent that, so if the icon doesn't exist, the rescue call the old draw item method.

It's not SDK compilant, but it would be easy to make it, since it would only change the "draw_item" method of the "Window_HorizCommand"
  1. #==============================================================================
  2. # Icon Command
  3. # by Atoa
  4. #==============================================================================
  5. =begin
  6. This script allow you to add icons for any command created with "Window_Command"
  7. class.
  8. This also works for "Window_ShopCommand" and "Window_PartyCommand" classes
  9.  
  10. To add the icon, just add an graphic with the command name + "_ic" to the Icon folder.
  11. So if you want the "Attack" command to have an icon, the icon must be named
  12. "Attack_ic"
  13.  
  14. Commands without icons are shown normally
  15. =end
  16. #==============================================================================
  17. # Window_Command
  18. #==============================================================================
  19. class Window_Command < Window_Selectable
  20.   #--------------------------------------------------------------------------
  21.   alias draw_item_window_command_ic draw_item
  22.   def draw_item(index, color)
  23.     begin
  24.       bitmap = RPG::Cache.icon(@commands[index] + "_ic")
  25.       opacity = color == normal_color ? 255 : 128
  26.       self.contents.blt(4, 32 * index + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  27.       self.contents.font.color = color
  28.       rect = Rect.new(32, 32 * index, self.contents.width - 32, 32)
  29.       self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  30.       self.contents.draw_text(rect, @commands[index])
  31.     rescue
  32.       draw_item_window_command_ic(index, color)
  33.     end
  34.   end
  35. end
  36.  
  37. #==============================================================================
  38. # Window_ShopCommand
  39. #==============================================================================
  40. class Window_ShopCommand < Window_Selectable
  41.   #--------------------------------------------------------------------------
  42.   alias draw_item_window_shopcommand_ic draw_item
  43.   def draw_item(index)
  44.     begin
  45.       bitmap = RPG::Cache.icon(@commands[index] + "_ic")
  46.       x = 32 + index * 160
  47.       self.contents.blt(x - 28, 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  48.       self.contents.draw_text(x, 0, 128, 32, @commands[index])
  49.     rescue
  50.       draw_item_window_shopcommand_ic(index)
  51.     end
  52.   end
  53. end
  54.  
  55. #==============================================================================
  56. # Window_PartyCommand
  57. #==============================================================================
  58. class Window_PartyCommand < Window_Selectable
  59.   #--------------------------------------------------------------------------
  60.   alias draw_item_window_partycommand_ic draw_item
  61.   def draw_item(index, color)
  62.     begin
  63.       bitmap = RPG::Cache.icon(@commands[index] + "_ic")
  64.       self.contents.blt(184 + index * 160 + 4 , 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  65.       self.contents.font.color = color
  66.       rect = Rect.new(184 + index * 160 + 32, 0, 118, 32)
  67.       self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  68.       self.contents.draw_text(rect, @commands[index], 0)
  69.     rescue
  70.       draw_item_window_partycommand_ic(index, color)
  71.     end
  72.   end
  73. end
  74.  
Expand to see the code.
Could you post a non-SDK version?
When I get some free time I'll try and get a non-SDK version up, but before I do that I'm trying to fix some issues in the origional version first, if you can wait.

Okay, slight update please visit the top post and try out Command Icons (Take 2!)^^

Whats different in that version, I fixed the Icons hash and got rid of the default and default.default setting, since I noticed apparently when defining icons for a new window it'll all stack in the same hash, rather than a window having it's own hash, when the default is defined as a hash too (sorry if I made you crosseyed with that statement...)

In lamens terms, this means that the icons set properly when different between windows and command names, (ie "Shutdown" for Scene_Title#@command_window will be different than "Shutdown" for Scene_End#@command_window, if you give them different icons.)

It is improved in that sense, but on the other hand there was also a problem where the instance of @command_window (or w/e) isn't set until after the command window initializes, meaning the script itself was giving the wrong key in most cases, you can read more about that in my previous post. THAT issue has been fixed too, the only quirk is in certain scenes it'll show the command window normally with no icons, then a split second later the icons will appear, it needs to do that so the instance of it is registered when looking for the window key.

That shouldn't be a BIG deal (or maybe it will be to some) but, with the way this script works, it might be the only solution if you're wanting to use different command icons between windows. Alternatively, I could throw out the Icons[scene][window] key altogether, and just use an Icons[scene] key without the window being used, and that'll get rid of the re-refresh I have to do once the instance has been created. Only case where the scene => window => command_icons keys would matter is if you have two command windows, with some of the same command names, but you're wanting different icons between the two...

Its up to you guys how you'd like me to do it, so please give me some input so I know what would be mostly perferred. Throw out the Icons[scene][window] key and just use Icons[scene] key, or keep the window key and deal with the 1 second update? Any alternative suggestions I'll take into account too, just give me some feedback on it.
Kain Nobel wrote:
When I get some free time I'll try and get a non-SDK version up, but before I do that I'm trying to fix some issues in the origional version first, if you can wait.


Aaaawwww!
@MCsephiroth13
I don't think you noticed, but mine script is non-SDK.
It's works a bit different from the Kain Nobel's but the result is the same.
Kain Nobel wrote:
@TehSeph : Yeah, thats basically how it works! And yes, if there is no icon assigned to a certain command it'll just display normally, no error occurs or anything.

Ahh I see. Another question. Any way to tweak this to remove the text and just place an icon? I'm thinking of modifying this script to use pictures instead, then making pictures for each of the commands.
Now it doesn't add any icons.
Thats odd, it shows icons in my project and I put it in a new project with just SDK and its working just fine, maybe its another script conflicting with it? o.O

I'll try and post a non-SDK version tomorrow for those of you who need it.
Been 6 days since you said that...

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