# # 文章の自動センタリング処理(RGSS3) #  (C)2011 TYPE74RX-T # module Kernel #-------------------------------------------------------------------------- # ★ センタリングフラグ # (顔グラ設定がなく、イベントでセンタリング指定がされているか) #-------------------------------------------------------------------------- def rx3_message_centering? $game_message.face_name.empty? and $game_temp.rx_message_centering end end #============================================================================== # ■ Game_Temp #------------------------------------------------------------------------------ #  セーブデータに含まれない、一時的なデータを扱うクラスです。このクラスのイン # スタンスは $game_temp で参照されます。 #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :rx_message_centering # 文章のセンタリング表示フラグ #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias rx3_111216_initialize initialize def initialize rx3_111216_initialize # メソッド呼び戻し @rx_message_centering = false end end #============================================================================== # ■ Game_Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、 # Game_Troop クラス、Game_Event クラスの内部で使用されます。 #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ★ センタリングフラグをオン #-------------------------------------------------------------------------- def rxmsg_ctr $game_temp.rx_message_centering = true end #-------------------------------------------------------------------------- # ★ センタリングフラグをオフ #-------------------------------------------------------------------------- def rxmsg $game_temp.rx_message_centering = false end end #============================================================================== # ■ Window_Base #------------------------------------------------------------------------------ #  ゲーム中の全てのウィンドウのスーパークラスです。 #============================================================================== class Window_Base < Window #-------------------------------------------------------------------------- # ★ 各行ごとの X 座標を設定(センタリング用) #-------------------------------------------------------------------------- def rx_set_text_xpos(text) # メッセージを配列化して rx_textspl に入れる rx_texts = text.sub("\n", " ") rx_textspl = rx_texts.split(/\s+/) @rx_text_count = 0 @rx_txt_widths = [] # 各行ごとの最終的な X 座標を配列に入れる (0...rx_textspl.size).each do |i| xps = (Graphics.width - 32 - contents.text_size(rx_textspl[i]).width) / 2 @rx_txt_widths.push(xps) end end #-------------------------------------------------------------------------- # ● 改行文字の処理 #-------------------------------------------------------------------------- alias rx3_111216_process_new_line process_new_line def process_new_line(text, pos) # ★ センタリングフラグが立っていたら表示行数をカウント if rx3_message_centering? @rx_text_count += 1 return if @rx_text_count == @rx_txt_widths.size end rx3_111216_process_new_line(text, pos) # メソッド呼び戻し # ★ 改行後の X 座標をセンタリング pos[:x] = @rx_txt_widths[@rx_text_count] if rx3_message_centering? end end #============================================================================== # ■ Window_Message #------------------------------------------------------------------------------ #  文章表示に使うメッセージウィンドウです。 #============================================================================== class Window_Message < Window_Base #-------------------------------------------------------------------------- # ★ 各行ごとの X 座標を設定(センタリング用) #-------------------------------------------------------------------------- def rx_set_text_xpos(text) super(text) end #-------------------------------------------------------------------------- # ● 全テキストの処理 #-------------------------------------------------------------------------- alias rx3_111216_process_all_text process_all_text def process_all_text # ★ センタリングフラグが立っていたら各行ごとの X 座標を設定 rx_set_text_xpos(convert_escape_characters($game_message.all_text)) if rx3_message_centering? rx3_111216_process_all_text # メソッド呼び戻し end #-------------------------------------------------------------------------- # ● 改行位置の取得 #-------------------------------------------------------------------------- alias rx3_111216_new_line_x new_line_x def new_line_x # センタリングフラグが立っていたらセンタリング return @rx_txt_widths[@rx_text_count] if rx3_message_centering? rx3_111216_new_line_x # メソッド呼び戻し end end