#◆◇◆◇◆ ルビ描写スクリプト ver 1・00 ◇◆◇◆◇ # 全マスタースクリプト共通スクリプト # サポート掲示板 http://www2.ezbbs.net/21/minto-aaa/ # by みんと =begin 説明 特定の文字列にルビ(振り仮名)を描写します。 ルビは文字列が設定した文字列と等しい場合に表示されます。 例えば 試験(テスト)とする場合、 文字列が 試験 なら表示されますが、 試験2 の場合は表示されません。 あくまで完全に等しい場合に表示します。 設定した文字列であれば、アクター名や武器などを問わず描写します。 ただし、ルビを描写する場合、 ルビの描写スペースを確保するために、文章が多少小さくなります。 =end #============================================================================== # ☆ MINTO #------------------------------------------------------------------------------ # 様々なフラグを扱うメインモジュールです。 #============================================================================== module MINTO # ルビ描写スクリプトを有効化 ( true で有効 / false で無効 ) RGSS["ルビ描写スクリプト"] = true end if MINTO::RGSS["ルビ描写スクリプト"] == true then #============================================================================== # ☆ カスタマイズ #------------------------------------------------------------------------------ # 機能のカスタマイズを行うモジュールです。 #============================================================================== module MINTO # ルビを管理するハッシュ(変更しない) @ruby_text = {} # ルビを表示したい文字列(文字列が設定した文字列と等しい場合に表示されます) # 例 : @ruby_text["ルビを振りたい本文"] = "ルビ" @ruby_text["試験君"] = "でばっぐくん" @ruby_text["戦闘開始"] = "たたかう" @ruby_text["戦略的後退"] = "にげる" #-------------------------------------------------------------------------- # ● ルビを管理するハッシュの取得 #-------------------------------------------------------------------------- def self.ruby_text return @ruby_text end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ #  ゲーム中のビットマップの表示を管理する組み込みクラスです #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● テキスト描画 #-------------------------------------------------------------------------- # 多重エイリアスでない場合 if not method_defined?("ruby_MINTO_draw_text") then # エイリアスを実行 alias :ruby_MINTO_draw_text :draw_text end def draw_text(x, y, width = 0, height = 0, text = "", align = 0) # ルビを表示フラグをオフ ruby_on = false # 最初の引数が Rect の場合 if x.is_a?(Rect) == true then # 文字列がルビを表示すべき文字の場合 if MINTO.ruby_text.key?(y) == true then # 各データを取得 x2 = x.x y2 = x.y width2 = x.width height2 = x.height text2 = y.dup align2 = width # ルビを取得 ruby = MINTO.ruby_text[text2] # ルビを表示フラグをオン ruby_on = true # それ以外の文章の場合 else # 元の処理を実行 ruby_MINTO_draw_text(x, y, width) end # 通常の引数の場合 else # 文字列がルビを表示すべき文字の場合 if MINTO.ruby_text.key?(text) == true then # 各データを取得 x2 = x y2 = y width2 = width height2 = height text2 = text.dup align2 = align # ルビを取得 ruby = MINTO.ruby_text[text2] # ルビを表示フラグをオン ruby_on = true # それ以外の文章の場合 else # 元の処理を実行 ruby_MINTO_draw_text(x, y, width, height, text, align) end end # ルビ表示フラグがオンの場合 if ruby_on == true then # 文字サイズを保存 text_size = self.font.size # 文字サイズを調節 self.font.size = [self.font.size, height2 / 2 + 2].min # 文章の長さを測る text_width = self.text_size(text2).width # 文章の高さを測る text_height = self.text_size(text2).height # 求められたルビを一文字ずつ配列にする ruby_array = ruby.to_s.split(//) # ルビの1文字辺りの描写幅を取得 ruby_width = text_width / ruby_array.size # 文章のY座標を調節 text_y = y2 + ((height2 - text_height) / 2) # 求められた文章を描写 ruby_MINTO_draw_text(x2, text_y, width2, height2, text2, align2) # 文字を小さくする self.font.size = self.font.size / 2 # ルビの高さを測る ruby_height = self.text_size(ruby).height # ループ処理 (0...ruby_array.size).each do |i| # アライメントに応じて分岐 case align2 # 左寄せ when 0 # 描写座標を計算して取得 ruby_x = x2 + (i * ruby_width) # 中央寄せ when 1 # 描写座標を計算して取得 ruby_x = x2 + ((width2 - text_width) / 2) + (i * ruby_width) # 右寄せ when 2 # 描写座標を計算して取得 ruby_x = x2 + (width2 - text_width) + (i * ruby_width) end # ルビを取得 r = ruby_array[i] # ルビを描写 ruby_MINTO_draw_text(ruby_x, y2 + 2, ruby_width, ruby_height, r, 1) end # 文字サイズを戻す self.font.size = text_size end end #-------------------------------------------------------------------------- # ● ルビ付き文字描写 # x : 文章の X 座標 # y : 文章の Y 座標 # width : 文章の描写範囲(横幅) # height : 文章の描写範囲(高さ) # text : 文章 # ruby : 振り仮名 # align : アラインメント (0..左揃え、1..中央揃え、2..右揃え) #-------------------------------------------------------------------------- def draw_ruby(x, y, width, height, text, ruby, align = 0) # 文字サイズを保存 text_size = self.font.size # 文字サイズを調節 self.font.size = [self.font.size, 18].min # 文章の長さを測る text_width = self.text_size(text).width # 文章の高さを測る text_height = self.text_size(text).height # 求められたルビを一文字ずつ配列にする ruby_array = ruby.to_s.split(//) # ルビの1文字辺りの描写幅を取得 ruby_width = text_width / ruby_array.size # 文章のY座標を調節 text_y = y + ((height - text_height) / 2) # 求められた文章を描写 draw_text(x, text_y, width, height, text, align) # 文字を小さくする self.font.size = self.font.size / 2 # ルビの高さを測る ruby_height = self.text_size(ruby).height # ループ処理 (0...ruby_array.size).each do |i| # アライメントに応じて分岐 case align # 左寄せ when 0 # 描写座標を計算して取得 ruby_x = x + (i * ruby_width) # 中央寄せ when 1 # 描写座標を計算して取得 ruby_x = x + ((width - text_width) / 2) + (i * ruby_width) # 右寄せ when 2 # 描写座標を計算して取得 ruby_x = x + (width - text_width) + (i * ruby_width) end # ルビを取得 r = ruby_array[i] # ルビを描写 draw_text(ruby_x, y + 2, ruby_width, ruby_height, r, 1) end # 文字サイズを戻す self.font.size = text_size end end end