From 494e646fd5859c195936d119e5194af83572c356 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Mon, 1 Apr 2024 23:41:54 +0100 Subject: [PATCH] Fixed replacement battler being invisible if its predecessor fainted and used the same sprite, refactoring --- .../002_MessageConfig.rb | 89 +++++++++---------- .../005_SpriteWindow_text.rb | 36 ++------ .../007_Objects and windows/011_Messages.rb | 9 +- .../007_Objects and windows/012_TextEntry.rb | 8 +- .../004_Scene/004_Scene_PlayAnimations.rb | 2 + Data/Scripts/016_UI/025_UI_TextEntry.rb | 4 +- 6 files changed, 64 insertions(+), 84 deletions(-) diff --git a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb index 47813fd34..c223fcfa0 100644 --- a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb +++ b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb @@ -330,58 +330,52 @@ end #=============================================================================== # Determine which text colours to use based on the darkness of the background #=============================================================================== -def getSkinColor(windowskin, color, isDarkSkin) - if !windowskin || windowskin.disposed? || - windowskin.width != 128 || windowskin.height != 128 - # Base color, shadow color (these are reversed on dark windowskins) - # Values in arrays are RGB numbers - textcolors = [ - [ 0, 112, 248], [120, 184, 232], # 1 Blue - [232, 32, 16], [248, 168, 184], # 2 Red - [ 96, 176, 72], [174, 208, 144], # 3 Green - [ 72, 216, 216], [168, 224, 224], # 4 Cyan - [208, 56, 184], [232, 160, 224], # 5 Magenta - [232, 208, 32], [248, 232, 136], # 6 Yellow - [160, 160, 168], [208, 208, 216], # 7 Gray - [240, 240, 248], [200, 200, 208], # 8 White - [114, 64, 232], [184, 168, 224], # 9 Purple - [248, 152, 24], [248, 200, 152], # 10 Orange - MessageConfig::DARK_TEXT_MAIN_COLOR, - MessageConfig::DARK_TEXT_SHADOW_COLOR, # 11 Dark default - MessageConfig::LIGHT_TEXT_MAIN_COLOR, - MessageConfig::LIGHT_TEXT_SHADOW_COLOR # 12 Light default - ] - if color == 0 || color > textcolors.length / 2 # No special colour, use default - if isDarkSkin # Dark background, light text - return shadowc3tag(MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR) - end - # Light background, dark text - return shadowc3tag(MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR) - end - # Special colour as listed above - if isDarkSkin && color != 12 # Dark background, light text - return shadowc3tag(textcolors[(2 * (color - 1)) + 1], textcolors[2 * (color - 1)]) - end - # Light background, dark text - return shadowc3tag(textcolors[2 * (color - 1)], textcolors[(2 * (color - 1)) + 1]) - else # VX windowskin +def get_text_colors_for_windowskin(windowskin, color, isDarkSkin) + # VX windowskin + if windowskin && !windowskin.disposed? && windowskin.width == 128 && windowskin.height == 128 color = 0 if color >= 32 x = 64 + ((color % 8) * 8) y = 96 + ((color / 8) * 8) pixel = windowskin.get_pixel(x, y) - return shadowc3tag(pixel, pixel.get_contrast_color) + return pixel, pixel.get_contrast_color end + # No windowskin or not a VX windowskin + # Base color, shadow color (these are reversed on dark windowskins) + # Values in arrays are RGB numbers + textcolors = [ + [ 0, 112, 248], [120, 184, 232], # 1 Blue + [232, 32, 16], [248, 168, 184], # 2 Red + [ 96, 176, 72], [174, 208, 144], # 3 Green + [ 72, 216, 216], [168, 224, 224], # 4 Cyan + [208, 56, 184], [232, 160, 224], # 5 Magenta + [232, 208, 32], [248, 232, 136], # 6 Yellow + [160, 160, 168], [208, 208, 216], # 7 Gray + [240, 240, 248], [200, 200, 208], # 8 White + [114, 64, 232], [184, 168, 224], # 9 Purple + [248, 152, 24], [248, 200, 152], # 10 Orange + MessageConfig::DARK_TEXT_MAIN_COLOR, + MessageConfig::DARK_TEXT_SHADOW_COLOR, # 11 Dark default + MessageConfig::LIGHT_TEXT_MAIN_COLOR, + MessageConfig::LIGHT_TEXT_SHADOW_COLOR # 12 Light default + ] + if color == 0 || color > textcolors.length / 2 # No special colour, use default + if isDarkSkin # Dark background, light text + return MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR + end + # Light background, dark text + return MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR + end + # Special colour as listed above + if isDarkSkin && color != 12 # Dark background, light text + return Color.new(*textcolors[(2 * (color - 1)) + 1]), Color.new(*textcolors[2 * (color - 1)]) + end + # Light background, dark text + return Color.new(*textcolors[2 * (color - 1)]), Color.new(*textcolors[(2 * (color - 1)) + 1]) end def getDefaultTextColors(windowskin) - if !windowskin || windowskin.disposed? || - windowskin.width != 128 || windowskin.height != 128 - if isDarkWindowskin(windowskin) - return [MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR] # White - else - return [MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR] # Dark gray - end - else # VX windowskin + # VX windowskin + if windowskin && !windowskin.disposed? && windowskin.width == 128 && windowskin.height == 128 color = windowskin.get_pixel(64, 96) shadow = nil isDark = (color.red + color.green + color.blue) / 3 < 128 @@ -390,8 +384,13 @@ def getDefaultTextColors(windowskin) else shadow = Color.new(color.red - 64, color.green - 64, color.blue - 64) end - return [color, shadow] + return color, shadow end + # No windowskin or not a VX windowskin + if isDarkWindowskin(windowskin) + return MessageConfig::LIGHT_TEXT_MAIN_COLOR, MessageConfig::LIGHT_TEXT_SHADOW_COLOR # White + end + return MessageConfig::DARK_TEXT_MAIN_COLOR, MessageConfig::DARK_TEXT_SHADOW_COLOR # Dark gray end #=============================================================================== diff --git a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb index e8be64d69..bb50e0e82 100644 --- a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb +++ b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb @@ -30,9 +30,7 @@ class Window_UnformattedTextPokemon < SpriteWindow_Base pbSetSystemFont(self.contents) @text = text @letterbyletter = false # Not supported in this class - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) resizeToFit(text) end @@ -88,9 +86,7 @@ class Window_UnformattedTextPokemon < SpriteWindow_Base oldshadowg = @shadowColor.green oldshadowb = @shadowColor.blue oldshadowa = @shadowColor.alpha - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) if oldbaser != @baseColor.red || oldbaseg != @baseColor.green || oldbaseb != @baseColor.blue || oldbasea != @baseColor.alpha || oldshadowr != @shadowColor.red || oldshadowg != @shadowColor.green || @@ -142,9 +138,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base self.contents = Bitmap.new(1, 1) pbSetSystemFont(self.contents) self.resizeToFit(text, Graphics.width) - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) self.text = text @starting = false end @@ -266,9 +260,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base oldshadowg = @shadowColor.green oldshadowb = @shadowColor.blue oldshadowa = @shadowColor.alpha - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) if redrawText && (oldbaser != @baseColor.red || oldbaseg != @baseColor.green || oldbaseb != @baseColor.blue || oldbasea != @baseColor.alpha || @@ -634,9 +626,7 @@ class Window_InputNumberPokemon < SpriteWindow_Base super(0, 0, 32, 32) self.width = (digits_max * 24) + 8 + self.borderX self.height = 32 + self.borderY - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) @index = digits_max - 1 self.active = true refresh @@ -1068,9 +1058,7 @@ class Window_DrawableCommand < SpriteWindow_SelectableEx RPG::Cache.retain("Graphics/UI/sel_arrow") end @index = 0 - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) refresh end @@ -1118,9 +1106,7 @@ class Window_DrawableCommand < SpriteWindow_SelectableEx def setSkin(skin) super(skin) privRefresh(true) - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) end def drawCursor(index, rect) @@ -1173,9 +1159,7 @@ class Window_CommandPokemon < Window_DrawableCommand self.height = dims[1] @commands = commands self.active = true - colors = getDefaultTextColors(self.windowskin) - self.baseColor = colors[0] - self.shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) refresh @starting = false end @@ -1282,9 +1266,7 @@ class Window_AdvancedCommandPokemon < Window_DrawableCommand self.height = dims[1] @commands = commands self.active = true - colors = getDefaultTextColors(self.windowskin) - self.baseColor = colors[0] - self.shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) refresh @starting = false end diff --git a/Data/Scripts/007_Objects and windows/011_Messages.rb b/Data/Scripts/007_Objects and windows/011_Messages.rb index 91c985bd0..bbba3a466 100644 --- a/Data/Scripts/007_Objects and windows/011_Messages.rb +++ b/Data/Scripts/007_Objects and windows/011_Messages.rb @@ -452,7 +452,8 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni end isDarkSkin = isDarkWindowskin(msgwindow.windowskin) text.gsub!(/\\c\[([0-9]+)\]/i) do - next getSkinColor(msgwindow.windowskin, $1.to_i, isDarkSkin) + main_color, shadow_color = get_text_colors_for_windowskin(msgwindow.windowskin, $1.to_i, isDarkSkin) + next shadowc3tag(main_color, shadow_color) end loop do last_text = text.clone @@ -469,9 +470,11 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni end colortag = "" if $game_system && $game_system.message_frame != 0 - colortag = getSkinColor(msgwindow.windowskin, 0, true) + main_color, shadow_color = get_text_colors_for_windowskin(msgwindow.windowskin, 0, true) + colortag = shadowc3tag(main_color, shadow_color) else - colortag = getSkinColor(msgwindow.windowskin, 0, isDarkSkin) + main_color, shadow_color = get_text_colors_for_windowskin(msgwindow.windowskin, 0, isDarkSkin) + colortag = shadowc3tag(main_color, shadow_color) end text = colortag + text ### Controls diff --git a/Data/Scripts/007_Objects and windows/012_TextEntry.rb b/Data/Scripts/007_Objects and windows/012_TextEntry.rb index 4258af660..98e9fad9c 100644 --- a/Data/Scripts/007_Objects and windows/012_TextEntry.rb +++ b/Data/Scripts/007_Objects and windows/012_TextEntry.rb @@ -85,9 +85,7 @@ end class Window_TextEntry < SpriteWindow_Base def initialize(text, x, y, width, height, heading = nil, usedarkercolor = false) super(x, y, width, height) - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) if usedarkercolor @baseColor = Color.new(16, 24, 32) @shadowColor = Color.new(168, 184, 184) @@ -264,9 +262,7 @@ end class Window_MultilineTextEntry < SpriteWindow_Base def initialize(text, x, y, width, height) super(x, y, width, height) - colors = getDefaultTextColors(self.windowskin) - @baseColor = colors[0] - @shadowColor = colors[1] + @baseColor, @shadowColor = getDefaultTextColors(self.windowskin) @helper = CharacterEntryHelper.new(text) @firstline = 0 @cursorLine = 0 diff --git a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb index 5df4c2c08..0910e7f92 100644 --- a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb +++ b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb @@ -312,6 +312,7 @@ class Battle::Scene #============================================================================= def pbFaintBattler(battler) @briefMessage = false + old_height = @sprites["pokemon_#{battler.index}"].src_rect.height # Pokémon plays cry and drops down, data box disappears faintAnim = Animation::BattlerFaint.new(@sprites, @viewport, battler.index, @battle) dataBoxAnim = Animation::DataBoxDisappear.new(@sprites, @viewport, battler.index) @@ -323,6 +324,7 @@ class Battle::Scene end faintAnim.dispose dataBoxAnim.dispose + @sprites["pokemon_#{battler.index}"].src_rect.height = old_height end #============================================================================= diff --git a/Data/Scripts/016_UI/025_UI_TextEntry.rb b/Data/Scripts/016_UI/025_UI_TextEntry.rb index 687878a54..88e615097 100644 --- a/Data/Scripts/016_UI/025_UI_TextEntry.rb +++ b/Data/Scripts/016_UI/025_UI_TextEntry.rb @@ -10,9 +10,7 @@ class Window_CharacterEntry < Window_DrawableCommand @charset = charset @othercharset = "" super(0, 96, 480, 192) - colors = getDefaultTextColors(self.windowskin) - self.baseColor = colors[0] - self.shadowColor = colors[1] + self.baseColor, self.shadowColor = getDefaultTextColors(self.windowskin) self.columns = XSIZE refresh end