#============================================================================== # ○自動改行テキスト Ver1.00 # for RGSS2 # 西瓜 / Space not far # http://muspell.raindrop.jp/ # 自動的に改行してくれるdraw_textです。 #============================================================================== # ■更新履歴 # Ver1.00 # ・公開 #============================================================================== # 多少ご自身でスクリプト改造を行う人向けの素材です。 # Window_Baseクラスにdraw_autoreturn_text(x, y, w, h, t, line_h) # という関数を追加します。 # 長い文章を表示したいが、行数だけdraw_textを書くのは面倒臭い、 # という方におすすめです。 # x, y:draw_textと同じ始点座標です。 # w:横幅です。これより右に文字が出そうな場合改行されます。 # h:縦幅です。これより下に文字が来そうな場合、関数を中断します。 # t:テキストです。 # line_h:行間です。入力を省略した場合は20ピクセルとなります。 # おまけで制御文字に対応しています。 # \c[n],\v[n],\n[n],\rが使えます。\rは改行です。 module SNF_AUTORETURN HEAD_HYP = "ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎ。、!?・‐゠–~,)]}、〕〉》」』】〙〗〟’”⦆»" # 行頭にこれらの文字が来そうな場合、その1文字前で改行します。 HEAD_C = " " # 手動改行後、先頭に挿入する文字です。 end class Window_Base < Window def draw_autoreturn_text(x, y, w, h, t, line_h = 20) i = 0 align = 1 spacing = self.contents.font.size c_x = x c_y = y c_height = line_h + 0 text = (SNF_AUTORETURN::HEAD_C + t.clone) text = convert_autoreturn_text(text) loop do c = text.slice!(/./m) # 次の文字を取得 break if c_y >= h case c when nil break when "\x00" # 改行 c_x = x c_y += line_h text = SNF_AUTORETURN::HEAD_C + text next when "\x01" # \C[n] (文字色変更) text.sub!(/\[([0-9]+)\]/, "") contents.font.color = text_color($1.to_i) next else c_width = contents.text_size(c).width next_c_x = c_x + c_width # 行頭禁則処理判定 next_c = text.slice(/./m) if next_c != nil if SNF_AUTORETURN::HEAD_HYP.include?(next_c) and next_c_x > w # 改行 c_x = x c_y += line_h end end # 描画 self.contents.draw_text(c_x, c_y, c_width, c_height, c, align) c_x += c_width # 自動改行 if c_x > w c_x = x c_y += line_h end end end end # 特殊文字の変換 def convert_autoreturn_text(text) text.gsub!(/\\R/i) { "\x00" } text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name } text.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" } text.gsub!(/\\\\/) { "\\" } return text end end # 禁則処理はいい加減なのでうまく動かないかもしれません。ご了承ください。