From ae80d9dcd4c59cffd0227f876a3262061a9d9148 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Fri, 1 Nov 2024 23:56:04 +0000 Subject: [PATCH] Changed choice lists to allow text formatting --- .../005_SpriteWindow_text.rb | 29 ++++++++++++++----- .../007_Objects and windows/010_DrawText.rb | 25 +++++++++++----- .../007_Objects and windows/011_Messages.rb | 8 ++--- .../001_Pokemon-related/001_FormHandlers.rb | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) 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 f1d201e76..75df4c0b9 100644 --- a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb +++ b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb @@ -1326,15 +1326,28 @@ class Window_AdvancedCommandPokemon < Window_DrawableCommand windowheight += self.borderY if !width || width < 0 width = 0 - tmpbitmap = Bitmap.new(1, 1) - pbSetSystemFont(tmpbitmap) - commands.each do |i| - txt = toUnformattedText(i).gsub(/\n/, "") - width = [width, tmpbitmap.text_size(txt).width].max + tmp_bitmap = Bitmap.new(1, 1) + pbSetSystemFont(tmp_bitmap) + commands.each do |cmd| + txt = toUnformattedText(cmd).gsub(/\n/, "") + txt_width = tmp_bitmap.text_size(txt).width + check_text = cmd + while check_text[FORMATREGEXP] + if $~[2].downcase == "icon" && $~[3] + check_text = $~.post_match + filename = $~[4].sub(/\s+$/, "") + temp_graphic = Bitmap.new("Graphics/Icons/#{filename}") + txt_width += temp_graphic.width + temp_graphic.dispose + else + check_text = $~.post_match + end + end + width = [width, txt_width].max end # one 16 to allow cursor width += 16 + 16 + SpriteWindow_Base::TEXT_PADDING - tmpbitmap.dispose + tmp_bitmap.dispose end # Store suggested width and height of window dims[0] = [self.borderX + 1, @@ -1347,7 +1360,7 @@ class Window_AdvancedCommandPokemon < Window_DrawableCommand dims = [] getAutoDims(commands, dims, width) self.width = dims[0] - self.height = dims[1] - 6 + self.height = dims[1] end def itemCount @@ -1363,7 +1376,7 @@ class Window_AdvancedCommandPokemon < Window_DrawableCommand rect.width, rect.height, @commands[index], self.baseColor, self.shadowColor) else chars = getFormattedText(self.contents, rect.x, rect.y + (self.contents.text_offset_y || 0) + 2, # TEXT OFFSET - rect.width, rect.height, @commands[index], rect.height, true, true) + rect.width, rect.height, @commands[index], rect.height, true, true, false, self) drawFormattedChars(self.contents, chars) end end diff --git a/Data/Scripts/007_Objects and windows/010_DrawText.rb b/Data/Scripts/007_Objects and windows/010_DrawText.rb index d4a5dc569..6724a224a 100644 --- a/Data/Scripts/007_Objects and windows/010_DrawText.rb +++ b/Data/Scripts/007_Objects and windows/010_DrawText.rb @@ -66,7 +66,9 @@ def fmtReplaceEscapes(text) end def toUnformattedText(text) - text2 = text.gsub(FORMATREGEXP, "") + text2 = text.clone + pbReplaceMessageText(text2, nil) + text2 = text2.gsub(FORMATREGEXP, "") fmtReplaceEscapes(text2) return text2 end @@ -314,7 +316,7 @@ end #=============================================================================== def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = 32, newlineBreaks = true, explicitBreaksOnly = false, - collapseAlignments = false) + collapseAlignments = false, msg_window = nil) dummybitmap = nil if !bitmap || bitmap.disposed? # allows function to be called with nil bitmap dummybitmap = Bitmap.new(1, 1) @@ -327,6 +329,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = textchunks = [] controls = [] # oldtext = text + pbReplaceMessageText(text, msg_window) while text[FORMATREGEXP] textchunks.push($~.pre_match) if $~[3] @@ -376,7 +379,11 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = fontsize = defaultfontsize fontnamestack = [] fontsizestack = [] - defaultcolors = [oldfont.color.clone, nil] + if msg_window + defaultcolors = [msg_window.baseColor, msg_window.shadowColor] + else + defaultcolors = [oldfont.color.clone, nil] + end if defaultfontname.is_a?(Array) defaultfontname = defaultfontname.find { |i| Font.exist?(i) } || "Arial" elsif !Font.exist?(defaultfontname) @@ -917,17 +924,18 @@ def drawSingleFormattedChar(bitmap, ch) if ch[5] # If a graphic graphic = Bitmap.new(ch[0]) graphicRect = ch[15] - bitmap.blt(ch[1], ch[2], graphic, graphicRect, ch[8].alpha) + bitmap.blt(ch[1], ch[2] - (bitmap.text_offset_y || 0), graphic, graphicRect, ch[8].alpha) graphic.dispose return end bitmap.font.size = ch[13] if bitmap.font.size != ch[13] if ch[9] # shadow if ch[10] # underline - bitmap.fill_rect(ch[1], ch[2] + ch[4] - [(ch[4] - bitmap.font.size) / 2, 0].max - 2, ch[3], 4, ch[9]) + bitmap.fill_rect(ch[1], ch[2] + ch[4] - [(ch[4] - bitmap.font.size) / 2, 0].max - 2 - (bitmap.text_offset_y || 0), + ch[3], 4, ch[9]) end if ch[11] # strikeout - bitmap.fill_rect(ch[1], ch[2] + 2 + (ch[4] / 2), ch[3], 4, ch[9]) + bitmap.fill_rect(ch[1], ch[2] + 2 + (ch[4] / 2) - (bitmap.text_offset_y || 0), ch[3], 4, ch[9]) end end if ch[0] == "\n" || ch[0] == "\r" || ch[0] == " " || isWaitChar(ch[0]) @@ -969,10 +977,11 @@ def drawSingleFormattedChar(bitmap, ch) bitmap.draw_text(ch[1] + offset, ch[2] + offset, ch[3], ch[4], ch[0]) end if ch[10] # underline - bitmap.fill_rect(ch[1], ch[2] + ch[4] - [(ch[4] - bitmap.font.size) / 2, 0].max - 2, ch[3] - 2, 2, ch[8]) + bitmap.fill_rect(ch[1], ch[2] + ch[4] - [(ch[4] - bitmap.font.size) / 2, 0].max - 2 - (bitmap.text_offset_y || 0), + ch[3] - 2, 2, ch[8]) end if ch[11] # strikeout - bitmap.fill_rect(ch[1], ch[2] + 2 + (ch[4] / 2), ch[3] - 2, 2, ch[8]) + bitmap.fill_rect(ch[1], ch[2] + 2 + (ch[4] / 2) - (bitmap.text_offset_y || 0), ch[3] - 2, 2, ch[8]) end end diff --git a/Data/Scripts/007_Objects and windows/011_Messages.rb b/Data/Scripts/007_Objects and windows/011_Messages.rb index 60bff8edb..3a42e0621 100644 --- a/Data/Scripts/007_Objects and windows/011_Messages.rb +++ b/Data/Scripts/007_Objects and windows/011_Messages.rb @@ -336,9 +336,9 @@ def pbReplaceMessageText(text, msg_window) text.gsub!(/\\r/i, female_text_tag) # Other text colors text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "" } - isDarkSkin = isDarkWindowskin(msg_window.windowskin) + isDarkSkin = msg_window && isDarkWindowskin(msg_window.windowskin) text.gsub!(/\\c\[([0-9]+)\]/i) do - main_color, shadow_color = get_text_colors_for_windowskin(msg_window.windowskin, $1.to_i, isDarkSkin) + main_color, shadow_color = get_text_colors_for_windowskin(msg_window&.windowskin, $1.to_i, isDarkSkin) next shadowc3tag(main_color, shadow_color) end end @@ -732,7 +732,7 @@ end def pbShowCommands(msgwindow, commands = nil, cmdIfCancel = 0, defaultCmd = 0) return 0 if !commands - cmdwindow = Window_CommandPokemonEx.new(commands) + cmdwindow = Window_AdvancedCommandPokemon.new(commands) cmdwindow.z = 99999 cmdwindow.visible = true cmdwindow.resizeToFit(cmdwindow.commands) @@ -772,7 +772,7 @@ def pbShowCommandsWithHelp(msgwindow, commands, help, cmdIfCancel = 0, defaultCm oldlbl = msgwin.letterbyletter msgwin.letterbyletter = false if commands - cmdwindow = Window_CommandPokemonEx.new(commands) + cmdwindow = Window_AdvancedCommandPokemon.new(commands) cmdwindow.z = 99999 cmdwindow.visible = true cmdwindow.resizeToFit(cmdwindow.commands) diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb index 084ae0ad8..e0ab0b878 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb @@ -893,5 +893,5 @@ MultipleForms.register(:QUILAVA, { MultipleForms.copy(:QUILAVA, :DEWOTT, :PETILILL, :RUFFLET, :GOOMY, :BERGMITE, :DARTRIX) -# Paldean forms +# Paldean forms. # None!