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.

[Resolved] [VX] Highlighted Text changes color

ikos

Member

Heya, all.

I had this idea where, if you highlight an option (menu or otherwise), you'd have the highlighter of course. But I thought it would be pretty cool if, as well as the highlighter, the text highlighted would change color. So something like this.

  Text
  Text
>Text
  Text
  Text

The regular text will be Font color ID: 000, while the highlighted Font will be Font color ID: 006 As always, any and all help is appreciated.

~Ikos out :thumb:
 

khmp

Sponsor

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

class Window_Command < Window_Selectable
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  FOCUS_COLOR = 6
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias ikos_highlight_window_command_initialize initialize
  alias ikos_highlight_window_command_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Object Initialization                                           !ALIAS!
  #     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)
    @disabled = []
    @old_index = 0
    ikos_highlight_window_command_initialize(width, commands, column_max,
      row_max, spacing)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @old_index = @index if cursor_movable?
    super
    if cursor_movable?
      draw_focus_item if @old_index != @index
    end
  end
  #--------------------------------------------------------------------------
  # * Set Cursor Position
  #     index : new cursor position
  #--------------------------------------------------------------------------
  def index=(index)
    @old_index = @index
    super
    draw_focus_item
  end
  #--------------------------------------------------------------------------
  # * Draw Focused Item
  #--------------------------------------------------------------------------
  def draw_focus_item
    unless @old_index == -1
      rect = item_rect(@old_index)
      rect.x += 4
      rect.width -= 8
      self.contents.clear_rect(rect)
      self.contents.font.color = normal_color
      self.contents.font.color.alpha = @disabled.include?(@old_index) ? 
        128 : 255
      self.contents.draw_text(rect, @commands[@old_index])
    end
    
    # Draw the new item.
    rect = item_rect(@index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = text_color(FOCUS_COLOR)
    self.contents.font.color.alpha = @disabled.include?(@index) ? 
      128 : 255
    self.contents.draw_text(rect, @commands[@index])
  end
  #--------------------------------------------------------------------------
  # * Draw Item                                                       !ALIAS!
  #     index   : item number
  #     enabled : enabled flag. When false, draw semi-transparently.
  #--------------------------------------------------------------------------
  def draw_item(index, enabled = true)
    @disabled << index if !enabled && !@disabled.include?(index)
    ikos_highlight_window_command_draw_item(index, enabled)
  end
end

Color number 6 on the default window skin is yellow but you can play around with it if you want. It's the constant near the top "FOCUS_COLOR". Hope that's what you meant.
 

ikos

Member

khmp":2wg0k8v2 said:
Code:
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================

class Window_Command < Window_Selectable
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  FOCUS_COLOR = 6
  #--------------------------------------------------------------------------
  # * Alias Methods
  #--------------------------------------------------------------------------
  alias ikos_highlight_window_command_initialize initialize
  alias ikos_highlight_window_command_draw_item draw_item
  #--------------------------------------------------------------------------
  # * Object Initialization                                           !ALIAS!
  #     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)
    @disabled = []
    @old_index = 0
    ikos_highlight_window_command_initialize(width, commands, column_max,
      row_max, spacing)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @old_index = @index if cursor_movable?
    super
    if cursor_movable?
      draw_focus_item if @old_index != @index
    end
  end
  #--------------------------------------------------------------------------
  # * Set Cursor Position
  #     index : new cursor position
  #--------------------------------------------------------------------------
  def index=(index)
    @old_index = @index
    super
    draw_focus_item
  end
  #--------------------------------------------------------------------------
  # * Draw Focused Item
  #--------------------------------------------------------------------------
  def draw_focus_item
    unless @old_index == -1
      rect = item_rect(@old_index)
      rect.x += 4
      rect.width -= 8
      self.contents.clear_rect(rect)
      self.contents.font.color = normal_color
      self.contents.font.color.alpha = @disabled.include?(@old_index) ? 
        128 : 255
      self.contents.draw_text(rect, @commands[@old_index])
    end
    
    # Draw the new item.
    rect = item_rect(@index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = text_color(FOCUS_COLOR)
    self.contents.font.color.alpha = @disabled.include?(@index) ? 
      128 : 255
    self.contents.draw_text(rect, @commands[@index])
  end
  #--------------------------------------------------------------------------
  # * Draw Item                                                       !ALIAS!
  #     index   : item number
  #     enabled : enabled flag. When false, draw semi-transparently.
  #--------------------------------------------------------------------------
  def draw_item(index, enabled = true)
    @disabled << index if !enabled && !@disabled.include?(index)
    ikos_highlight_window_command_draw_item(index, enabled)
  end
end

Color number 6 on the default window skin is yellow but you can play around with it if you want. It's the constant near the top "FOCUS_COLOR". Hope that's what you meant.

Oh, this is amazing, KH. Much love, mate.
 

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