Skip to content

Instantly share code, notes, and snippets.

@cacao-soft
Created January 3, 2021 19:18
Show Gist options
  • Save cacao-soft/ba529a961fc3d9fb159b3bee37dde16b to your computer and use it in GitHub Desktop.
Save cacao-soft/ba529a961fc3d9fb159b3bee37dde16b to your computer and use it in GitHub Desktop.
# 変数[n]の値が 1 なら中央、2 なら左、それ以外なら左
Window_ScrollText::VID_SCROLL_ALIGN = 1
class Window_ScrollText < Window_Base
#--------------------------------------------------------------------------
# ● 制御文字つきテキストの描画
#--------------------------------------------------------------------------
def draw_text_ex(x, y, text)
reset_font_settings
text = convert_escape_characters(text)
pos = {:x => x, :y => y, :new_x => x}
text.lines do |line|
case $game_variables[VID_SCROLL_ALIGN]
when 1
pos[:x] = (contents_width - calc_line_width(line)) / 2
when 2
pos[:x] = (contents_width - calc_line_width(line)) - x
end
pos[:height] = calc_line_height(line)
process_character(line.slice!(0, 1), line, pos) until line.empty?
end
end
#--------------------------------------------------------------------------
# ● 行の幅を計算
# restore_font_size : 計算後にフォントサイズを元に戻す
#--------------------------------------------------------------------------
def calc_line_width(text, restore_font_size = true)
result = 0
last_font_size = contents.font.size
text = text.clone
until text.empty?
c = text.slice!(0, 1)
case c
when "\n" # 改行
break
when "\e" # 制御文字
case obtain_escape_code(text).upcase
when 'C'
obtain_escape_param(text)
when 'I'
obtain_escape_param(text)
result += 24
when '{'
make_font_bigger
when '}'
make_font_smaller
end
else # 普通の文字
result += text_size(c).width
end
end
contents.font.size = last_font_size if restore_font_size
return result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment