mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-22 23:06:18 +00:00
Added in \l and \r to credits
For left-justified and right-justified text
This commit is contained in:
parent
88d9690737
commit
7c97b71824
1 changed files with 24 additions and 1 deletions
|
|
@ -70,6 +70,7 @@ class Credits_Message
|
||||||
text = ''
|
text = ''
|
||||||
y = -1
|
y = -1
|
||||||
widths = []
|
widths = []
|
||||||
|
right_widths = []
|
||||||
|
|
||||||
# Pre-process text
|
# Pre-process text
|
||||||
text_raw = $game_temp.message_credits_text.to_str
|
text_raw = $game_temp.message_credits_text.to_str
|
||||||
|
|
@ -83,6 +84,8 @@ class Credits_Message
|
||||||
end
|
end
|
||||||
text_raw.gsub!("\\p", $game_oneshot.player_name)
|
text_raw.gsub!("\\p", $game_oneshot.player_name)
|
||||||
text_raw.gsub!("\\n", "\n")
|
text_raw.gsub!("\\n", "\n")
|
||||||
|
text_raw.gsub!("\\l", "\005")
|
||||||
|
text_raw.gsub!("\\r", "\006")
|
||||||
# Handle text-rendering escape sequences
|
# Handle text-rendering escape sequences
|
||||||
text_raw.gsub!(/\\c\[([0-9]+)\]/, "\000[\\1]")
|
text_raw.gsub!(/\\c\[([0-9]+)\]/, "\000[\\1]")
|
||||||
# Finally convert the backslash back
|
# Finally convert the backslash back
|
||||||
|
|
@ -92,6 +95,7 @@ class Credits_Message
|
||||||
|
|
||||||
# Now split text into lines by measuring text metrics
|
# Now split text into lines by measuring text metrics
|
||||||
x = y = 0
|
x = y = 0
|
||||||
|
right_x = 0
|
||||||
maxwidth = @contents.width - 8
|
maxwidth = @contents.width - 8
|
||||||
spacesize = @contents.text_size(' ')
|
spacesize = @contents.text_size(' ')
|
||||||
for i in text_raw.split(/ /)
|
for i in text_raw.split(/ /)
|
||||||
|
|
@ -102,19 +106,28 @@ class Credits_Message
|
||||||
if newline
|
if newline
|
||||||
text << "\n"
|
text << "\n"
|
||||||
widths << x
|
widths << x
|
||||||
|
right_widths << right_x
|
||||||
x = 0
|
x = 0
|
||||||
|
right_x = 0
|
||||||
y += 1
|
y += 1
|
||||||
@contents.font.size = 24
|
@contents.font.size = 24
|
||||||
else
|
else
|
||||||
newline = true
|
newline = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if j.start_with?("\006")
|
||||||
|
right_x = 0
|
||||||
|
x = 0
|
||||||
|
end
|
||||||
|
|
||||||
# Get width of this word and see if it goes out of bounds
|
# Get width of this word and see if it goes out of bounds
|
||||||
width = @contents.text_size(j.gsub(/\000\[[0-9]+\]/, '')).width
|
width = @contents.text_size(j.gsub(/\000\[[0-9]+\]/, '').gsub( "\005","").gsub( "\006","")).width
|
||||||
if x + width > maxwidth
|
if x + width > maxwidth
|
||||||
text << "\n"
|
text << "\n"
|
||||||
widths << x
|
widths << x
|
||||||
|
right_widths << right_x
|
||||||
x = 0
|
x = 0
|
||||||
|
right_x = 0
|
||||||
y += 1
|
y += 1
|
||||||
@contents.font.size = 24
|
@contents.font.size = 24
|
||||||
end
|
end
|
||||||
|
|
@ -126,9 +139,11 @@ class Credits_Message
|
||||||
text << ' ' << j
|
text << ' ' << j
|
||||||
end
|
end
|
||||||
x += width + spacesize.width
|
x += width + spacesize.width
|
||||||
|
right_x += width
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
widths << x
|
widths << x
|
||||||
|
right_widths << right_x
|
||||||
|
|
||||||
# Prepare renderer
|
# Prepare renderer
|
||||||
@contents.clear
|
@contents.clear
|
||||||
|
|
@ -165,6 +180,14 @@ class Credits_Message
|
||||||
# go to next text
|
# go to next text
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
if c == "\005"
|
||||||
|
x = 16
|
||||||
|
next
|
||||||
|
end
|
||||||
|
if c == "\006"
|
||||||
|
x = 320 - (right_widths[y] + 16)
|
||||||
|
next
|
||||||
|
end
|
||||||
# Draw text
|
# Draw text
|
||||||
@contents.draw_text(x, y_top + (y * 24), 40, 18, c)
|
@contents.draw_text(x, y_top + (y * 24), 40, 18, c)
|
||||||
# Add x to drawn text width
|
# Add x to drawn text width
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue