Changed choice lists to allow text formatting

This commit is contained in:
Maruno17
2024-11-01 23:56:04 +00:00
parent 210cfc654f
commit ae80d9dcd4
4 changed files with 43 additions and 21 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) { "<c2=" + $1 + ">" }
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)

View File

@@ -893,5 +893,5 @@ MultipleForms.register(:QUILAVA, {
MultipleForms.copy(:QUILAVA,
:DEWOTT, :PETILILL, :RUFFLET, :GOOMY, :BERGMITE, :DARTRIX)
# Paldean forms
# Paldean forms.
# None!