Hex Color Codes in Messages
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script allows you to enter a six-character hex value when using the "\c" control code in messages, while still allowing you to use the numbered reference colors (\c[0[ - \c[7]) by default). To do this, use the \c control code as normal, but within the brackets, put the character "x" followed by the hex code. For instance, the syntax for red would be \c[xFF0000]. Be careful, though. If you enter a hex string that isn't six characters long, white text will be used. If you enter a malformed string, such as \c[D49], then reference color 0 will be used. Note that letters for hex values A-F must be capital letters.
To use this script, replace the parts of Window_Message shown in the first spoiler (the first part replaces a single statement and the second part replaces a block, as shown in the comments). Then, add the second part (in the second spoiler) that adds the hex_color and hex_convert methods into Window_Base. This script will work with my Custom Text Command script.
Script
Hex Code (part 1)
This part requires a manual edit of your message system:
Code:
#==============================================================================
# ** Window_Message
#------------------------------------------------------------------------------
# This message window is used to display text.
#==============================================================================
class Window_Message < Window_Selectable
[...]
# Replace text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } in the
# refresh method with the following statement. Use the Find feature
# to find it.
#
text.gsub!(/\\[Cc]\[([0123456789ABCDEFx]+)\]/) { "\001[#{$1}]" }
[...]
# Replace the entire if c == "\001" block with
# this one.
if c == "\001"
# Change text color (hex code)
text.sub!(/\[([0123456789ABCDEFx]+)\]/, "")
temp_color = $1
color = temp_color.to_i
leading_x = temp_color.to_s.slice!(/./m)
if leading_x == "x"
self.contents.font.color = hex_color(temp_color)
next
end
if color >= 0 and color <= 7
self.contents.font.color = text_color(color)
end
# go to next text
next
end
Hex Code (part 2)
Just paste this in with your custom scripts BELOW Scene_Debug or ABOVE Main
Code:
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Hex Color
# string : string
#--------------------------------------------------------------------------
def hex_color(string)
red = 0
green = 0
blue = 0
if string.size != 6
print("Hex strings must be six characters long.")
print("White text will be used.")
return Color.new(255, 255, 255, 255)
end
for i in 1..6
s = string.slice!(/./m)
if s == "x"
print("Hex color string may not contain the \"x\" character.")
print("White text will be used.")
return Color.new(255, 255, 255, 255)
end
value = hex_convert(s)
if value == -1
print("Error converting hex value.")
print("White text will be used.")
return Color.new(255, 255, 255, 255)
end
case i
when 1
red += value * 16
when 2
red += value
when 3
green += value * 16
when 4
green += value
when 5
blue += value * 16
when 6
blue += value
end
end
return Color.new(red, green, blue, 255)
end
#--------------------------------------------------------------------------
# * Hexadecimal Conversion
# character : character
#--------------------------------------------------------------------------
def hex_convert(character)
case character
when "0"
return 0
when "1"
return 1
when "2"
return 2
when "3"
return 3
when "4"
return 4
when "5"
return 5
when "6"
return 6
when "7"
return 7
when "8"
return 8
when "9"
return 9
when "A"
return 10
when "B"
return 11
when "C"
return 12
when "D"
return 13
when "E"
return 14
when "F"
return 15
end
return -1
end
end