[VX to XP Conversion] Item Quality Colors

Started by mroedesigns, January 08, 2011, 06:34:28 am

Previous topic - Next topic

mroedesigns

I found a VX script that I used use that I really, really like. Problem is that it's written for VX (It uses the 'Notes' section in the database to configure quality), and I'm nowhere near skilled enough to re-write or convert it. I looked for an XP version, or if the author had anything like that but I turned up nothing. It's a short script though, so I wouldn't think it'd be too difficult.

Also, since XP obviously doesn't have the Notes section, it could either be configured in the script or some other way, it's up to whoever decides to help me out.

Here's the original post on RPGRevolution
http://www.rpgrevolution.com/forums/index.php?showtopic=42543

And here's the script itself, written by Leongon

module IQC_Configs
################################################################################
#                  Basic Item Quality Colors of Awesome VX v1.1                #
################################################################################
# Author: Leongon                                                              #
# Contact: carlos_gon47@hotmail.com       (or PM leongon on the board below)   #
# Licence: Free for commercial and non-commercial proyects, just credit.       #
# Share: Exclusive for www.rpgrevolution.com                                   #
#        If you want to share it outside, give a link only, please.            #
################################################################################
# This is a really tiny one. Item Quality let you set "quality" by colors,     #
# like in Diablo II: green for sets, yellow for epics, etc. and lot of other   #
# games around that colorizes the item, weapon and armor's names. And also can #
# be used on skills if you want to colourize them by element or something.     #
################################################################################

################################################################################
# Instructions #                                                               #
################                                                               #
#                                                                              #
# Setting an Item Quality. --------------------------------------------------- #
#                                                                              #
# Insert this tag in the item, weapon, armor or skill's notefields:            #
# <IQC quality>                                                                #
#                                                                              #
# Being "quality" the name you set for that quality, like rare, epic or uber.  #
#                                                                              #
# Asigning a color to a Item Quality. ---------------------------------------- #
#                                                                              #
# Below, in the configuration area, you can find the color list from 0 to 31.  #
# There insert the proper quality name at the color you want to be linked.     #
#                                                                              #
# If there are no tag found, the name will appear at normal text color: white  #
# in default RTP Window.png                                                    #
#                                                                              #
# I defaulted according to WoW quality colors: poor, rare, epic and legendary, #
# but you must take in consideration that I used the default RTP Window.png    #
# So if you have a custom one you can have different colors, so change the     #
# list at your will to match your needs.                                       #
#                                                                              #
################################################################################
# Configuration Area #
######################
                     #
  IQC_quality =      # Don't touch this line.
  {                  # Don't touch this line.
  0 => "",           #
  1 => "",           #
  2 => "",           #
  3 => "",           #
  4 => "",           #
  5 => "",           #
  6 => "",           #
  7 => "",           #
  8 => "poor",       #
  9 => "rare",       #
  10 => "",          #
  11 => "",          #
  12 => "",          #
  13 => "",          #
  14 => "",          #
  15 => "",          #
  16 => "",          #
  17 => "",          #
  18 => "",          #
  19 => "",          #
  20 => "legendary", #
  21 => "",          #
  22 => "",          #
  23 => "",          #
  24 => "uncommon",  #
  25 => "",          #
  26 => "",          #
  27 => "",          #
  28 => "",          #
  29 => "",          #
  30 => "epic",      #
  31 => ""           #
  }                  # Don't touch this line.
                     #
######################
#  Config Area End   #
######################
end





#------------------------------------------------------------------------------#
# Don't cross this line unless your country is at the top of the group table   #
# on South Africa's 2010 soccer world cup.                                     #
#------------------------------------------------------------------------------#
module LNR
  def get_single_for(note_field,tag_name)
    lines = note_field.split("\n")
    for line in lines
      if line[0,1].eql?("<")
        line2=line.split(/[<> ]/)
        if line2[1].eql?(tag_name)
          return line2[2]
        end
      end
    end
  end
end
#------------------------------------------------------------------------------#
class Window_Base < Window
  include LNR
  include IQC_Configs
  def draw_item_name(item, x, y, enabled = true)
    if item != nil
      draw_icon(item.icon_index, x, y, enabled)
      self.contents.font.color = normal_color
      if item.note.include?("<IQC ")
        quality = get_single_for(item.note,"IQC")
        self.contents.font.color = text_color(IQC_quality.index(quality).to_i)
      end
      self.contents.font.color.alpha = enabled ? 255 : 128
      self.contents.draw_text(x + 24, y, 172, WLH, item.name)
      self.contents.font.color = normal_color
    end
  end
end

G_G

January 14, 2011, 12:05:02 am #1 Last Edit: January 14, 2011, 12:31:50 am by game_guy
Would something like this be okay?

Setup in the script:

 Quality['common'] = Color.new(255, 255, 255) # r, g, b
 Quality['rare'] = Color.new(120, 20, 0)
 Quality['epic'] = Color.new(0, 255, 0)


Database Setup:
In item name you type in \qty["quality"]
Based from VX script except this allows for more customization and more colors.

EDIT: Also because this is XP, there is no method that gets called to draw the item. So if you are using a custom item screen let me know so I can make it work with that.

mroedesigns

Quote from: game_guy on January 14, 2011, 12:05:02 am
Would something like this be okay?

Setup in the script:

 Quality['common'] = Color.new(255, 255, 255) # r, g, b
 Quality['rare'] = Color.new(120, 20, 0)
 Quality['epic'] = Color.new(0, 255, 0)


Database Setup:
In item name you type in \qty["quality"]
Based from VX script except this allows for more customization and more colors.

EDIT: Also because this is XP, there is no method that gets called to draw the item. So if you are using a custom item screen let me know so I can make it work with that.


That would be perfect! And right now I'm using the default menu, though I am looking to either find a different Scene_Item or write a new one at some point, but for now I'm using the defualt.

G_G

January 14, 2011, 12:39:42 pm #3 Last Edit: January 14, 2011, 12:41:53 pm by game_guy
Here you go fine sir!

#===============================================================================
# Item Quality Colors
# Author game_guy
# Version 1.0
#-------------------------------------------------------------------------------
# Intro:
# Changes the color of the items name according to the items quality.
# e.g. rare, common, etc.
#
# Features:
# Unlimited Qualities
# Any Color You Want
#
# Instructions:
# Everything you need to configure for the script is below.
# -Setting the Items Quality:
#  Go into the database, click the items, weapons, or armors tab. Type this into
#  the name box after the name.
#  \qty[quality name]
#  e.g.
#  You have a quality like so
#  Quality['common'] = Color.new(255, 255, 0)
#  You type \qty[common] in the items name
#
# Compatibility:
# Takes a few more seconds to load game up as its editing the items.
# Not tested with SDK.
# Most likely will not work with custom menu systems/custom item systems.
# -IF you do use a CMS/CIS
#  -PM me at http://forum.chaos-project.com/index.php?action=profile;u=220
#  -Message me at http://youtube.com/GameGuysProjects
#  -Email me at gameguysprojects@hotmail.com (LAST RESORT, DON'T CHECK OFTEN)
# -Then let me know which custom script you're using and send a copy of it
#  and I'll whip up a compatibility patch if I have the time.
#
# Credits:
# game_guy ~ Creator of the script.
# mroedesigns ~ Requesting.
# Leongon ~ Original VX version.
#===============================================================================
module GG_QualityColors
 Quality = {}
 #================================================
 # Color used for all other items without a
 # quality or when a quality level does not exist
 #================================================
 Default_Color = Color.new(255, 255, 255)
 #================================================
 # Add a new line under the qualities already
 # given and type
 # Quality['quality name'] = Color.new(r, g, b)
 #  quality name - name of quality in quotes
 #  r - amount of red
 #  g - amount of green
 #  b - amount of blue
 # Examples below.
 #================================================
 Quality['common'] = Color.new(255, 255, 0)
 Quality['rare'] = Color.new(120, 20, 0)
 Quality['epic'] = Color.new(0, 255, 0)
end
module RPG
 class Item
   attr_accessor :quality
   alias gg_init_qual_colors_itm_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 class Armor
   attr_accessor :quality
   alias gg_init_qual_colors_arm_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 class Weapon
   attr_accessor :quality
   alias gg_init_qual_colors_wpn_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 def self.get_item_quality
   data = ["Data/Weapons.rxdata", "Data/Armors.rxdata", "Data/Items.rxdata"]
   data.each {|d|
   items = load_data(d)
   items.each {|i|
   Graphics.update
   if i != nil
     text = i.name
     text.gsub!(/\\[Qq][Tt][Yy]\[([0-9A-Za-z_]+)\]/) do
       i.quality = $1.to_s
       ""
     end
     if !GG_QualityColors::Quality.include?(i.quality)
       i.quality = nil
     end
     if i.quality == nil
       i.quality = 'gg_def'
     end
   end}
   save_data(items, d)}
 end
end
RPG.get_item_quality
class Window_Item < Window_Selectable
 def draw_item(index)
   use = false
   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)
     use = true
   end
   if item.quality == 'gg_def'
     self.contents.font.color = GG_QualityColors::Default_Color
   else
     self.contents.font.color = GG_QualityColors::Quality[item.quality]
   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 = use == true ? 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
end


EDIT: I take that back. There is a draw_item_name method. However it doesn't get used in the Window_Item. Also this won't work with the Equip Scene but I can make it if you need.

mroedesigns

Awesome, thank you very much! :D I would love if it worked with scene_equip as well, if it's not too much trouble.

Also, how much modification will this take to work with a custom scene_item/scene_equip? Because as I said, I'm using the default at the moment but I am looking to have someone help me with writing custom scenes for those sometime in the near future. If it's simple stuff I'm sure I'll be able to figure it out, but I'm not that good with advanced scripting.

Again, thank you! Level up of course

G_G

January 14, 2011, 06:59:11 pm #5 Last Edit: January 14, 2011, 07:02:42 pm by game_guy
For the modifications, in your scene when you get one, look for the draw_item method under Window_Item. Take a look at the original method for draw_item, then take a look at mine. If you can spot the differences then you should be able to place my modifications into yours. If you can't figure it out I can do it for you. ^_^

Original
Spoiler: ShowHide
  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


Mine
Spoiler: ShowHide
  def draw_item(index)
   use = false
   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)
     use = true
   end
   if item.quality == 'gg_def'
     self.contents.font.color = GG_QualityColors::Default_Color
   else
     self.contents.font.color = GG_QualityColors::Quality[item.quality]
   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 = use == true ? 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


Also heres the version that works with equip now.
Spoiler: ShowHide
#===============================================================================
# Item Quality Colors
# Author game_guy
# Version 1.1
#-------------------------------------------------------------------------------
# Intro:
# Changes the color of the items name according to the items quality.
# e.g. rare, common, etc.
#
# Features:
# Unlimited Qualities
# Any Color You Want
#
# Instructions:
# Everything you need to configure for the script is below.
# -Setting the Items Quality:
#  Go into the database, click the items, weapons, or armors tab. Type this into
#  the name box after the name.
#  \qty[quality name]
#  e.g.
#  You have a quality like so
#  Quality['common'] = Color.new(255, 255, 0)
#  You type \qty[common] in the items name
#
# Compatibility:
# Takes a few more seconds to load game up as its editing the items.
# Not tested with SDK.
# Most likely will not work with custom menu systems/custom item systems.
# -IF you do use a CMS/CIS
#  -PM me at http://forum.chaos-project.com/index.php?action=profile;u=220
#  -Message me at http://youtube.com/GameGuysProjects
#  -Email me at gameguysprojects@hotmail.com (LAST RESORT, DON'T CHECK OFTEN)
# -Then let me know which custom script you're using and send a copy of it
#  and I'll whip up a compatibility patch if I have the time.
#
# Credits:
# game_guy ~ Creator of the script.
# mroedesigns ~ Requesting.
# Leongon ~ Original VX version.
#===============================================================================
module GG_QualityColors
 Quality = {}
 #================================================
 # Color used for all other items without a
 # quality or when a quality level does not exist
 #================================================
 Default_Color = Color.new(255, 255, 255)
 #================================================
 # Add a new line under the qualities already
 # given and type
 # Quality['quality name'] = Color.new(r, g, b)
 #  quality name - name of quality in quotes
 #  r - amount of red
 #  g - amount of green
 #  b - amount of blue
 # Examples below.
 #================================================
 Quality['common'] = Color.new(255, 255, 0)
 Quality['rare'] = Color.new(120, 20, 0)
 Quality['epic'] = Color.new(0, 255, 0)
end
module RPG
 class Item
   attr_accessor :quality
   alias gg_init_qual_colors_itm_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 class Armor
   attr_accessor :quality
   alias gg_init_qual_colors_arm_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 class Weapon
   attr_accessor :quality
   alias gg_init_qual_colors_wpn_lat initialize
   def initialize
     @quality = ""
     gg_init_qual_colors_lat
   end
 end
 def self.get_item_quality
   data = ["Data/Weapons.rxdata", "Data/Armors.rxdata", "Data/Items.rxdata"]
   data.each {|d|
   items = load_data(d)
   items.each {|i|
   Graphics.update
   if i != nil
     text = i.name
     text.gsub!(/\\[Qq][Tt][Yy]\[([0-9A-Za-z_]+)\]/) do
       i.quality = $1.to_s
       ""
     end
     if !GG_QualityColors::Quality.include?(i.quality)
       i.quality = nil
     end
     if i.quality == nil
       i.quality = 'gg_def'
     end
   end}
   save_data(items, d)}
 end
end
RPG.get_item_quality
class Window_Item < Window_Selectable
 def draw_item(index)
   use = false
   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)
     use = true
   end
   if item.quality == 'gg_def'
     self.contents.font.color = GG_QualityColors::Default_Color
   else
     self.contents.font.color = GG_QualityColors::Quality[item.quality]
   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 = use == true ? 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
end
class Window_Base < Window
 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.quality == 'gg_def'
     self.contents.font.color = GG_QualityColors::Default_Color
   else
     self.contents.font.color = GG_QualityColors::Quality[item.quality]
   end
   self.contents.draw_text(x + 28, y, 212, 32, item.name)
 end
end


Let me know if theres anything else :)

EDIT: In fact, just to make it a little more easier.
I added use = false directly under def draw_item.  I replaced these lines
    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

With
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      use = true
    end

Added this directly under the above code.
    if item.quality == 'gg_def'
      self.contents.font.color = GG_QualityColors::Default_Color
    else
      self.contents.font.color = GG_QualityColors::Quality[item.quality]
    end

Then replaced this line
opacity = self.contents.font.color == normal_color ? 255 : 128

With
opacity = use == true ? 255 : 128


That should be it. ^_^

LiTTleDRAgo

January 14, 2011, 09:22:20 pm #6 Last Edit: January 14, 2011, 09:41:12 pm by game_guy
it's really epic script  :haha:

Quote from: game_guy on January 14, 2011, 06:59:11 pm
For the modifications, in your scene when you get one, look for the draw_item method under Window_Item. Take a look at the original method for draw_item, then take a look at mine. If you can spot the differences then you should be able to place my modifications into yours. If you can't figure it out I can do it for you. ^_^


unfortunately I did'nt find that at STCMS....

Code too large. Removed. Please link to script instead. ~ G_G

G_G

January 14, 2011, 09:42:38 pm #7 Last Edit: January 14, 2011, 09:45:00 pm by game_guy
STCMS uses a different class. Look for Window_CMSItem.

EDIT: Here. Should work.
class Window_CMSItem < Window_Selectable
  def draw_item(i)
    use = false
   number = case @data[i]
   when RPG::Item then $game_party.item_number(@data[i].id)
   when RPG::Weapon then $game_party.weapon_number(@data[i].id)
   when RPG::Armor then $game_party.armor_number(@data[i].id)
   end
   if @data[i].is_a?(RPG::Item) && $game_party.item_can_use?(@data[i].id) ||
       @mode == nil
     use = true
   end
    if @data[i].quality == 'gg_def'
      self.contents.font.color = GG_QualityColors::Default_Color
    else
      self.contents.font.color = GG_QualityColors::Quality[@data[i].quality]
    end
   self.contents.fill_rect(4, i*32, 352, 32, Color.new(0, 0, 0, 0))
   bitmap = RPG::Cache.icon(@data[i].icon_name)
   opacity = use == true ? 255 : 128
   self.contents.blt(4, i*32 + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
   self.contents.draw_text(32, i*32, 212, 32, @data[i].name, 0)
   self.contents.draw_text(308, i*32, 16, 32, ':', 1)
   self.contents.draw_text(324, i*32, 24, 32, number.to_s, 2)
 end
end


Not tested. Place below CMS.

G_G

Legal double post.

Use the newer version here.
http://forum.chaos-project.com/index.php/topic,8276.msg131167.html#new

Its updated. Changes the way to gets item quality instead of loading items then saving them. Much faster and safer.