Changing text color based on select box

Would there be a way for me to change the text color based on what item the selection box is over? I've been trying to do this but I keep getting errors.
What kind of window are you working with here? There isn't a general way to achieve this with the default scripts, if that's what you're asking. It'll take some work, and probably a complete overhaul/restructuring of the window classes.
I'm hoping there's a way to do this only in the Window_Selectable class, since I noticed all the windows that have choices inherit from Window_Selectable. Maybe I could make it so I have something that stores the current item/option's text properties. And make it so that it temporarily creates a text with the same properties as the one at whatever index it's over, I'd most likely do this in update_cursor_rect.

An alternative I was thinking of was just going in any of the window classes with selectable that I want to change color and make it so that whatever item the current selection index is on changes that text's font color.

I have no idea how to go about doing this, and barely have any idea what I'm talking about.
The issue though is that Window_Selectable is not the one in charge of drawing text to the window, so there's no real one-solution-fixes-all here. You will have to modify each subclass's draw_item (or whatever is the equivalent name) method.

For example, with Window_Item:
Code:
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
You see that the self.contents.font.color is being assigned here. You will need to add some condition for when the item is being highlighted, perhaps when its index matches the window's @index:
Code:
    if index == @index
      self.contents.font.color = Color.new(255,0,0)
    elsif item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
draw_item method is only called when refresh is. I agree with updating update_cursor_rect as that ensures the @index has updated.
Code:
class Window_Selectable < Window_Base
  alias redraw_item_if_highlighted update_cursor_rect
  def update_cursor_rect
    refresh
    redraw_item_if_highlighted
  end
end
Though redrawing everything each time the cursor moves might be too intensive (especially as the item list gets longer). If it becomes too slow, you'll need to look into only calling draw_item for the selected index, which will require much more work.
Thank you, I'll go test multiple items and see how the performance goes.

Edit:
I don't want to spam post so i'll just add this here. I noticed with only 16 items it went down by 1-2 FPS. I plan on maybe only using a total of 24 in the game. Surprisingly the FPS dropped more from this then it did from nearly covering a room in parallel events and move routes 🙂 I wish there was an easier way to avoid any big FPS drop, but this overall works and only drops the FPS on that specific scene.
On laptops and lower-end PCs it noticably dropped down to 20 FPS at 16+. I'm probably going to try to go for the draw_item method, but will probably take forever to figure it out. Thx for the help though

Ok instead of coloring the text, how about an arrow that just points to the selected item. That shouldn't be too hard right and seems doable in Window_Selectable. I already managed to get an arrow icon to draw next to the text, but it's not moving even though I put it in update_cursor_rect, how would I go about making the arrow move where the cursor normally would?
im about to scream i just almost finished making my own terribly inefficient version of that, but using a text "<" instead of an image. Thank you so much though, i feel stupid

Edit:
This is the final result, I really like it more than the box. I tried doing coloring in draw_text but it only colored one item so rip, but the arrow is neat
pMPXXxZ.png

Original thread: https://forums.rpgmakerweb.com/threads/changing-text-color-based-on-select-box.132581/