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.

How to Change Font Color of a COMMAND ACTIVE?

Zup guys. I just want to know if someone can teach me how to make a command change its color when the cursor is on top of that command ( it is the active command )?

e.g.

- When the blinking cursor is on top of ITEM command then the Font color of that command will become Yellow or crisis_color.

thanks in advance..
 

Mac

Member

You could probably accomplish this with an if statement...something like:-

if selected
selected colour
else
normal colour
end

Obviously thats not the right coding but its an example.
 
search for this method:
Code:
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
change it to this:
Code:
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if (self.index == index)
      self.contents.font.color = crysis_color
    end
    self.contents.draw_text(rect, @commands[index])
  end
 
Freakboy;194291 said:
search for this method:
Code:
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
change it to this:
Code:
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if (self.index == index)
      self.contents.font.color = crysis_color
    end
    self.contents.draw_text(rect, @commands[index])
  end

Sorry bro.. But it doesnt work.. I even corrected the "crisis_color" you mispelled but nothing happens..

to MAC: the "If statement" could work. but how?
to Landarma: Im not actually looking for a command window script.. I only need just the code so that I could study it.
 
The method itself works, but I forgat to refresh the contents, and also needs to be refreshed when the index changes.

I've just tested it and it works, paste it above main :)
Code:
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================

class Window_Command < Window_Selectable
  #--------------------------------------------------------------------------
  # * Alias
  #--------------------------------------------------------------------------
  alias :freakboy_active_command_color_update :update
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if (@index == index)
      self.contents.font.color = crisis_color
    end
    self.contents.draw_text(rect, @commands[index])
  end
  #--------------------------------------------------------------------------
  # * Update (Alias)
  #--------------------------------------------------------------------------
  def update
    if (@active_command_index != @index)
      @active_command_index = @index
      refresh
    end
    freakboy_active_command_color_update
  end
end
No credit needed :P

@mac,
using else in a if-statement isn't always needed
It has actually the same effect, but shorter.
Code:
a = 1
if b == 2
  a = 2
end
is the same as doing:
Code:
if b == 2
  a = 2
else 
  a = 1
end
according to my script, 'a' can be compared with font color and b with index.
 
Freakboy: Yep thanks for that one bro... it now works great.. problem solved..
Im actually not gonna use it with the default so I just gonna study it and learn how its done and try to merge it with selwyn command window script...
 
if you want, i'll merge it for you ^_^

--edit--
In my script, replace def draw_item with this one ^_^
Code:
  def draw_item(index, color)
    sprite = @sprites[index]
    sprite.bitmap.clear
    sprite.bitmap.font.color = color
    if (@index == index)
      sprite.bitmap.font.color = crisis_color
    end
    sprite.bitmap.draw_text(4, 0, self.width - 32, 32, @commands[index])
  end
 

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