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

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