Im wondering, is there a way I can add Icons to my command names?
Like most things with scripting/plugins, the answer in this case is "yes", but you will have to put in a bit of effort. More than normal.
Let me explain: In RMMV (and VX/Ace and probably MZ), the "quick" and "simple" way to draw icons in a Window is to use the "drawTextEx()" function. This function parses whatever string that it is fed and detects text codes like "\I[123]" or "\V[456]" - the sort you put into your Show Text event commands to show icons or variable values in your text - and prints the relevant values in their place. So if you had a string like "\I[1] Bree" then "drawTextEx()" would print icon #1 from the iconset onto the screen followed by "Bree".
However, Window_Command does not use "drawTextEx()" when it prints the command names. It uses the basic "drawText()" instead, which does not look for any text codes.
The way it works is that Window_Command's "addCommand()" pushes its arguments, including the name string of the command added, into an Array called "_list" (as in 'command list') and then bulk prints all the command names there on the list using one single function called "drawAllItems()", which is inherited from its parent class, Window_Selectable (which is called in Window_Command's "refresh()" method when it calls Window_Selectable's version of "refresh()").
For each and every command to be printed, "drawAllItems()" then calls the function "drawItem()", adjusting the x/y argument for each time it calls "drawItem()" so that the next command isn't drawn over the previous one on screen. And "drawItem()" itself then calls "drawText()" to actually draw the text.
So you might be thinking: "Well, in that case, why can't I just modify Window_Command's "drawItem()" to use drawTextEx() instead of drawText()"?
You can, but you shouldn't. The reason is because -
"drawTextEx()" does not support text alignment. The basic "drawText()" allows you to specify aligning text to left/right/center but "drawTextEx()" has no functionality for that.
Window_Command has a property/function called "itemTextAlign()" that you are meant to be able to use/change in order to set the text alignment of your command names. If you just tried to replace how it uses "drawText()" with "drawTextEx()",
you would break that functionality.
So the "simple" way is out.
You can't just use "drawTextEx()" to draw your icons without nasty side effects.
That means you have to do it the "long" way.
You will have to modify Window_Command's "drawItem()" to manually draw the icons. And also shift the x-position fed into "drawText()" so it draws the command name text next to your icon instead of ontop of it.
The function you need to call to draw icons is called "drawIcon()".
"drawIcon()" is what every Window ends up using to display icons on the screen, "drawTextEx()" itself ends up calling "drawIcon()" when it detects a text code to draw an icon. You can check the code for it in Window_Base, it takes 3 arguments (iconIndex, x and y) and reads the iconset image file for the specified icon at the index and print it at the coordinates given.
But you say: "Hey wait, but then how will "drawIcon()" know which icon index you want to use for the command it's drawing? It can't read text codes in the name string, after all and "addCommand()" doesn't pass any icon index data to it."
No, no it doesn't. Not by default. You will have to feed in that data somehow.
Fortunately, Window_Command already provides some infrastructure for including additional information with each command in "addCommand()".
Because the "addCommand()" function actually takes 4 arguments, not 2. The first two are the name and function to call upon selection. The last 2 are "enabled" (true/false value to determine whether or not it is greyed out and unselectable, defaults to being true if nothing is specified) and "ext" (which means "extra data", I think only used in "Window_SkillList" to feed in skill type, defaults to null if nothing is specified).
The "ext" argument will end up being pushed into the "_list" alongside the name and other 2 arguments, allowing you to retrieve the data later.
So you can adjust your "addCommand()"s to look something like this:
JavaScript:
addCommand("Bree", "command1", true, 111)
And then modify "drawItem()" to look something like this:
JavaScript:
Window_CustomHorzCommand.prototype.drawItem = function(index) {
...
...
this.drawIcon(this._list[index].ext, rect.x, rect.y);
this.drawText(this.commandName(index), rect.x + 36, rect.y, rect.width, align);
}
And it should draw icon 111 and then "Bree".