mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-01-22 14:26:01 +00:00
Refactored some code relating to colours, trivially simplified some calculations
This commit is contained in:
@@ -67,7 +67,7 @@ module RPG
|
||||
ret.addRef
|
||||
else
|
||||
ret = BitmapWrapper.new(32 * width, 32 * height)
|
||||
x = (tile_id - 384) % 8 * 32
|
||||
x = ((tile_id - 384) % 8) * 32
|
||||
y = (((tile_id - 384) / 8) - height + 1) * 32
|
||||
tileset = yield(filename)
|
||||
ret.blt(0, 0, tileset, Rect.new(x, y, 32 * width, 32 * height))
|
||||
|
||||
@@ -342,10 +342,10 @@ def getSkinColor(windowskin, color, isDarkSkin)
|
||||
"F0F0F8", "C8C8D0", # 8 White
|
||||
"9040E8", "B8A8E0", # 9 Purple
|
||||
"F89818", "F8C898", # 10 Orange
|
||||
colorToRgb32(MessageConfig::DARK_TEXT_MAIN_COLOR),
|
||||
colorToRgb32(MessageConfig::DARK_TEXT_SHADOW_COLOR), # 11 Dark default
|
||||
colorToRgb32(MessageConfig::LIGHT_TEXT_MAIN_COLOR),
|
||||
colorToRgb32(MessageConfig::LIGHT_TEXT_SHADOW_COLOR) # 12 Light default
|
||||
MessageConfig::DARK_TEXT_MAIN_COLOR.to_rgb24,
|
||||
MessageConfig::DARK_TEXT_SHADOW_COLOR.to_rgb24, # 11 Dark default
|
||||
MessageConfig::LIGHT_TEXT_MAIN_COLOR.to_rgb24,
|
||||
MessageConfig::LIGHT_TEXT_SHADOW_COLOR.to_rgb24 # 12 Light default
|
||||
]
|
||||
if color == 0 || color > textcolors.length / 2 # No special colour, use default
|
||||
if isDarkSkin # Dark background, light text
|
||||
@@ -365,7 +365,7 @@ def getSkinColor(windowskin, color, isDarkSkin)
|
||||
x = 64 + ((color % 8) * 8)
|
||||
y = 96 + ((color / 8) * 8)
|
||||
pixel = windowskin.get_pixel(x, y)
|
||||
return shadowctagFromColor(pixel)
|
||||
return shadowc3tag(pixel, pixel.get_contrast_color)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -447,13 +447,13 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base
|
||||
when 1 # Lower right
|
||||
pauseWidth = @pausesprite.bitmap ? @pausesprite.framewidth : 16
|
||||
pauseHeight = @pausesprite.bitmap ? @pausesprite.frameheight : 16
|
||||
@pausesprite.x = self.x + self.width - (20 * 2) + (pauseWidth / 2)
|
||||
@pausesprite.y = self.y + self.height - (30 * 2) + (pauseHeight / 2)
|
||||
@pausesprite.x = self.x + self.width - 40 + (pauseWidth / 2)
|
||||
@pausesprite.y = self.y + self.height - 60 + (pauseHeight / 2)
|
||||
when 2 # Lower middle
|
||||
pauseWidth = @pausesprite.bitmap ? @pausesprite.framewidth : 16
|
||||
pauseHeight = @pausesprite.bitmap ? @pausesprite.frameheight : 16
|
||||
@pausesprite.x = self.x + (self.width / 2) - (pauseWidth / 2)
|
||||
@pausesprite.y = self.y + self.height - (18 * 2) + (pauseHeight / 2)
|
||||
@pausesprite.y = self.y + self.height - 36 + (pauseHeight / 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,118 +1,57 @@
|
||||
#===============================================================================
|
||||
# Text colours
|
||||
#===============================================================================
|
||||
# TODO: Unused.
|
||||
def ctag(color)
|
||||
ret = (color.red.to_i << 24)
|
||||
ret |= ((color.green.to_i) << 16)
|
||||
ret |= ((color.blue.to_i) << 8)
|
||||
ret |= ((color.alpha.to_i))
|
||||
return sprintf("<c=%08X>", ret)
|
||||
return sprintf("<c=%s>", color.to_rgb32(true))
|
||||
end
|
||||
|
||||
def shadowctag(base, shadow)
|
||||
return sprintf("<c2=%s%s>", colorToRgb16(base), colorToRgb16(shadow))
|
||||
return sprintf("<c2=%s%s>", base.to_rgb15, shadow.to_rgb15)
|
||||
end
|
||||
|
||||
def shadowc3tag(base, shadow)
|
||||
return sprintf("<c3=%s,%s>", colorToRgb32(base), colorToRgb32(shadow))
|
||||
return sprintf("<c3=%s,%s>", base.to_rgb32, shadow.to_rgb32)
|
||||
end
|
||||
|
||||
# TODO: Unused.
|
||||
def shadowctagFromColor(color)
|
||||
return shadowc3tag(color, getContrastColor(color))
|
||||
return shadowc3tag(color, color.get_contrast_color)
|
||||
end
|
||||
|
||||
# TODO: Unused.
|
||||
def shadowctagFromRgb(param)
|
||||
return shadowctagFromColor(rgbToColor(param))
|
||||
return shadowctagFromColor(Color.new_from_rgb(param))
|
||||
end
|
||||
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def colorToRgb32(color)
|
||||
return "" if !color
|
||||
if color.alpha.to_i == 255
|
||||
return sprintf("%02X%02X%02X", color.red.to_i, color.green.to_i, color.blue.to_i)
|
||||
else
|
||||
return sprintf("%02X%02X%02X%02X",
|
||||
color.red.to_i, color.green.to_i, color.blue.to_i, color.alpha.to_i)
|
||||
end
|
||||
Deprecation.warn_method("colorToRgb32", "v22", "color.to_rgb32")
|
||||
return color.to_rgb32
|
||||
end
|
||||
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def colorToRgb16(color)
|
||||
ret = (color.red.to_i >> 3)
|
||||
ret |= ((color.green.to_i >> 3) << 5)
|
||||
ret |= ((color.blue.to_i >> 3) << 10)
|
||||
return sprintf("%04X", ret)
|
||||
Deprecation.warn_method("colorToRgb16", "v22", "color.to_rgb15")
|
||||
return color.to_rgb15
|
||||
end
|
||||
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def rgbToColor(param)
|
||||
return Font.default_color if !param
|
||||
baseint = param.to_i(16)
|
||||
case param.length
|
||||
when 8 # 32-bit hex
|
||||
return Color.new(
|
||||
(baseint >> 24) & 0xFF,
|
||||
(baseint >> 16) & 0xFF,
|
||||
(baseint >> 8) & 0xFF,
|
||||
(baseint) & 0xFF
|
||||
)
|
||||
when 6 # 24-bit hex
|
||||
return Color.new(
|
||||
(baseint >> 16) & 0xFF,
|
||||
(baseint >> 8) & 0xFF,
|
||||
(baseint) & 0xFF
|
||||
)
|
||||
when 4 # 16-bit hex
|
||||
return Color.new(
|
||||
((baseint) & 0x1F) << 3,
|
||||
((baseint >> 5) & 0x1F) << 3,
|
||||
((baseint >> 10) & 0x1F) << 3
|
||||
)
|
||||
when 1 # Color number
|
||||
i = param.to_i
|
||||
return Font.default_color if i >= 8
|
||||
return [
|
||||
Color.new(255, 255, 255, 255),
|
||||
Color.new(128, 128, 255, 255),
|
||||
Color.new(255, 128, 128, 255),
|
||||
Color.new(128, 255, 128, 255),
|
||||
Color.new(128, 255, 255, 255),
|
||||
Color.new(255, 128, 255, 255),
|
||||
Color.new(255, 255, 128, 255),
|
||||
Color.new(192, 192, 192, 255)
|
||||
][i]
|
||||
else
|
||||
return Font.default_color
|
||||
end
|
||||
Deprecation.warn_method("rgbToColor", "v22", "Color.new_from_rgb(param)")
|
||||
return Color.new_from_rgb(param)
|
||||
end
|
||||
|
||||
def Rgb16ToColor(param)
|
||||
baseint = param.to_i(16)
|
||||
return Color.new(
|
||||
((baseint) & 0x1F) << 3,
|
||||
((baseint >> 5) & 0x1F) << 3,
|
||||
((baseint >> 10) & 0x1F) << 3
|
||||
)
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def rgb15ToColor(param)
|
||||
Deprecation.warn_method("rgb15ToColor", "v22", "Color.new_from_rgb(param)")
|
||||
return Color.new_from_rgb(param)
|
||||
end
|
||||
|
||||
# @deprecated This method is slated to be removed in v22.
|
||||
def getContrastColor(color)
|
||||
raise "No color given" if !color
|
||||
r = color.red
|
||||
g = color.green
|
||||
b = color.blue
|
||||
yuv = [
|
||||
(r * 0.299) + (g * 0.587) + (b * 0.114),
|
||||
(r * -0.1687) + (g * -0.3313) + (b * 0.500) + 0.5,
|
||||
(r * 0.500) + (g * -0.4187) + (b * -0.0813) + 0.5
|
||||
]
|
||||
if yuv[0] < 127.5
|
||||
yuv[0] += (255 - yuv[0]) / 2
|
||||
else
|
||||
yuv[0] = yuv[0] / 2
|
||||
end
|
||||
return Color.new(
|
||||
yuv[0] + (1.4075 * (yuv[2] - 0.5)),
|
||||
yuv[0] - (0.3455 * (yuv[1] - 0.5)) - (0.7169 * (yuv[2] - 0.5)),
|
||||
yuv[0] + (1.7790 * (yuv[1] - 0.5)),
|
||||
color.alpha
|
||||
)
|
||||
Deprecation.warn_method("getContrastColor", "v22", "color.get_contrast_color")
|
||||
return color.get_contrast_color
|
||||
end
|
||||
|
||||
|
||||
@@ -151,8 +90,8 @@ def itemIconTag(item)
|
||||
if item.respond_to?("icon_name")
|
||||
return sprintf("<icon=%s>", item.icon_name)
|
||||
else
|
||||
ix = item.icon_index % 16 * 24
|
||||
iy = item.icon_index / 16 * 24
|
||||
ix = (item.icon_index % 16) * 24
|
||||
iy = (item.icon_index / 16) * 24
|
||||
return sprintf("<img=Graphics/System/Iconset|%d|%d|24|24>", ix, iy)
|
||||
end
|
||||
end
|
||||
@@ -481,15 +420,15 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
if endtag
|
||||
colorstack.pop
|
||||
else
|
||||
color = rgbToColor(param)
|
||||
color = Color.new_from_rgb(param)
|
||||
colorstack.push([color, nil])
|
||||
end
|
||||
when "c2"
|
||||
if endtag
|
||||
colorstack.pop
|
||||
else
|
||||
base = Rgb16ToColor(param[0, 4])
|
||||
shadow = Rgb16ToColor(param[4, 4])
|
||||
base = Color.new_from_rgb(param[0, 4])
|
||||
shadow = Color.new_from_rgb(param[4, 4])
|
||||
colorstack.push([base, shadow])
|
||||
end
|
||||
when "c3"
|
||||
@@ -499,8 +438,8 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
param = param.split(",")
|
||||
# get pure colors unaffected by opacity
|
||||
oldColors = getLastParam(colorstack, defaultcolors)
|
||||
base = (param[0] && param[0] != "") ? rgbToColor(param[0]) : oldColors[0]
|
||||
shadow = (param[1] && param[1] != "") ? rgbToColor(param[1]) : oldColors[1]
|
||||
base = (param[0] && param[0] != "") ? Color.new_from_rgb(param[0]) : oldColors[0]
|
||||
shadow = (param[1] && param[1] != "") ? Color.new_from_rgb(param[1]) : oldColors[1]
|
||||
colorstack.push([base, shadow])
|
||||
end
|
||||
when "o"
|
||||
@@ -921,7 +860,7 @@ def getLineBrokenChunks(bitmap, value, width, dims, plain = false)
|
||||
end
|
||||
textcols = []
|
||||
if ccheck[/</] && !plain
|
||||
ccheck.scan(re) { textcols.push(rgbToColor($1)) }
|
||||
ccheck.scan(re) { textcols.push(Color.new_from_rgb($1)) }
|
||||
words = ccheck.split(reNoMatch) # must have no matches because split can include match
|
||||
else
|
||||
words = [ccheck]
|
||||
@@ -1086,7 +1025,7 @@ end
|
||||
def drawFormattedTextEx(bitmap, x, y, width, text, baseColor = nil, shadowColor = nil, lineheight = 32)
|
||||
base = baseColor ? baseColor.clone : Color.new(96, 96, 96)
|
||||
shadow = shadowColor ? shadowColor.clone : Color.new(208, 208, 200)
|
||||
text = "<c2=" + colorToRgb16(base) + colorToRgb16(shadow) + ">" + text
|
||||
text = shadowctag(base, shadow) + text
|
||||
chars = getFormattedText(bitmap, x, y, width, -1, text, lineheight)
|
||||
drawFormattedChars(bitmap, chars)
|
||||
end
|
||||
|
||||
@@ -507,7 +507,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
bitmap.clear
|
||||
getTextChars
|
||||
height = self.height - self.borderY
|
||||
cursorcolor = Color.new(0, 0, 0)
|
||||
cursorcolor = Color.black
|
||||
textchars = getTextChars
|
||||
startY = getLineY(@firstline)
|
||||
textchars.each do |text|
|
||||
|
||||
Reference in New Issue
Block a user