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]Ultimate Item Indication With Text Color

Culex

Member

I know I've seen the text slice method somewhere (assuming that's the right method), so I'm wondering if I can make any item name with an asterisk (*) preceding it have the crisis_color font rather than the normal_color font. I am trying to integrate this into draw_item_name under Window_Base.
 
Code:
def draw_item_name(item, x, y)
    if item == nil
      return
    end
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    if item.name.include?('*')
       self.contents.font.color = crisis_color
    else
       self.contents.font.color = normal_color
    end
    self.contents.draw_text(x + 28, y, 212, 32, item.name)
  end
Or if you want it so it HAS to be at the end of the string,
Code:
if item.name[-1] == '*'
 

Culex

Member

I forgot to add that I was hoping it could be configured to exclude the ( * ) during gameplay. For example:

In the database, the name of the weapon is Sword*

But when you're in the menu, no matter the Scene, it will show up as Sword,
obviously with the change in text color.

I've seen it done somewhere with something else, but it was at .net and I don't remember how to do it, and I've been looking at multiple sites with multiple searches.
 
Code:
def draw_item_name(item, x, y)
    if item == nil
      return
    end
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    if item.name[-1] == '*'
       self.contents.font.color = crisis_color
       self.contents.draw_text(x + 28, y, 212, 32, item.name.chop)
    else
       self.contents.font.color = normal_color
       self.contents.draw_text(x + 28, y, 212, 32, item.name)
    end
  end
 

Culex

Member

It loses the asterisk when the item is equipped, but in the item menus (Window_Item, Window_EquipItem) it retains the asterisk. I used your previous method:

Code:
if item.name.include?('*')
 
Oh, the extra info helped.
Code:
def draw_item_name(item, x, y)
    if item == nil
      return
    end
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    if item.name.include?('*')
       self.contents.font.color = crisis_color
       self.contents.draw_text(x + 28, y, 212, 32, item.name.delete('*'))
    else
       self.contents.font.color = normal_color
       self.contents.draw_text(x + 28, y, 212, 32, item.name)
    end
  end
And if the other Window_'s use a different method you'll need to modify that too.
 

Culex

Member

Okay, I added this in Window_Item:

Code:
    if item.name.include?('*')
      self.contents.draw_text(x + 28, y, 212, 32, item.name.delete('*'))
    else
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    end
    self.contents.draw_text(x + 138, y, 24, 32, number.to_s, 2)

above this:

Code:
self.contents.draw_text(x + 138, y, 24, 32, number.to_s, 2)

...and it worked!

I figured out the disabled_color problem I was having too:

In Window_Base I created a disabled form of crisis_color:

Code:
def unusable_color
  return Color.new(255, 255, 64, 128)
end

...and then I edited Window_Item to look like this:
Code:
 [...]
    [B]if item.name.include?('*')
      opacity = self.contents.font.color == unusable_color ? 255 : 128
      self.contents.font.color = unusable_color
      self.contents.draw_text(x + 28, y, 212, 32, item.name.delete('*'))
    else
      opacity = self.contents.font.color == normal_color ? 255 : 128
      self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    end[/B]    
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 138, y, 24, 32, number.to_s, 2)
 
You can just say.. new_color = Color.new(r, g, b, a) (red green blue alpha), and to use all of the colors from crisis_color just more transparent, use
Code:
self.contents.font.color = Color.new(crisis_color.red, crisis_color.green, crisis_color.blue, 150)
Or you can just find red green blue values and put those in. Change 150 to whatever transparency you want (out of 255).

EDIT: Oh you got it :D, PM me if you need any more help.
 

Culex

Member

I may try your method if for some reason mine goes awry, but everything is working great right now.

Thank you so much, verballydecapitating! I'll make sure you get credit!

This topic is [ RESOLVED ].
 

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