######################## ステートをアイコンで表示する ######################## # # # 現在かかっているステートをアイコンにして横に並べます。 # # 戦闘中は横幅の問題もあり、数の制約をつけないといけませんが、 # # メニューから開く場合は数の制約無く、全てのアイコンを並べることも可能です。 # # デフォルトの表示幅が120しかないので、その辺りは各自で調整しましょう。 # # # # なお、かなりの範囲で根本から書き換えています。 # # ステート名を表示するトコで他所のスクリプトを使っている場合は # # それなりの覚悟、もとい知識が必要です。 # # まぁ、そもそも「ステート表示周りのスクリプトを二つ以上入れる」状況が # # 作者には想像できないので、そんなに問題視していませんが。 # # # # アイコンの幅はどうでも良いですが、高さは32pixel以下にしてください。 # # 下にはみ出ることになります。 # # 横幅も大きすぎると、アイコンが一つも表示されない状況になるかもしれません。 # # # ############################################################################## # ココから設定 module Annex STATE_ICON_IGNORE_KEY = "!" # ステート名にこれが含まれる場合アイコン化しない STATE_ICON_NORMAL = "正常" # 正常時のアイコンの名前(""でアイコンなし) STATE_ICON_ENEMY_SET = true # 敵のステートもアイコン表示するかどうか。 end # ココまで設定 module RPG #============================================================================ # □ RPG::Cache #============================================================================ module Cache def self.States(filename) # ステートアイコンを格納するフォルダの指定 # たとえばGraphicsフォルダの中のStatesフォルダにアイコンを入れるなら # self.load_bitmap("Graphics/States/", filename)とする。 # ちなみにこのフォルダを作成していない場合エラーになるので気をつけよう。 self.load_bitmap("Graphics/States/", filename) end end end # ココまで設定 #============================================================================== # ■ Window_Base #============================================================================== class Window_Base < Window #-------------------------------------------------------------------------- # ● 描画用のステート文字列作成 (再定義) # actor : アクター # width : 描画先の幅 # need_normal : [正常] が必要かどうか (true / false) #-------------------------------------------------------------------------- def make_battler_state_text(battler, width, need_normal) # ☆ココから変更 # ステートを格納する配列を作成 temp_states = [] for i in battler.states # レーティングが1以上+ステート名前にSTATE_ICON_IGNORE_KEYを含まない場合 if $data_states[i].rating >= 1 and $data_states[i].name !~ /#{Annex::STATE_ICON_IGNORE_KEY}/ # ステート配列に現在のステートを追加 temp_states.push($data_states[i]) end end # ステート配列をレーティングの大きい順にソート temp_states.sort!{ |a, b| b.rating<=>a.rating } # ステート配列を名前だけの配列に変更 temp_states.map!{ |a| a.name } # 重複している名前の削除 temp_states.uniq! # アイコンの横幅を取得していき、widthよりも大きくなる前までstatesにpush total_width = 0 states = [] for i in temp_states bitmap = RPG::Cache.States(i) break if (bitmap.width + total_width) > width states.push(i) total_width += bitmap.width + 1 end # ステート名の文字列が空の場合は "[正常]" にする if states == [] and need_normal and Annex::STATE_ICON_NORMAL != "" states.push(Annex::STATE_ICON_NORMAL) end # 完成した文字列を返す return states # ☆ココまで変更 end #-------------------------------------------------------------------------- # ● ステートの描画 (再定義) # actor : アクター # x : 描画先 X 座標 # y : 描画先 Y 座標 # width : 描画先の幅 #-------------------------------------------------------------------------- def draw_actor_state(actor, x, y, width = 120) # アイコン名配列を取得 icons = make_battler_state_text(actor, width, true) # ☆ココから変更 # アイコン描写 draw_state_icon(icons, x, y) # ☆ココまで変更 end #-------------------------------------------------------------------------- # ◎ 追加:ステートアイコンの描画 # icons : ステートアイコンの配列 # x : 描画先 X 座標 # y : 描画先 Y 座標 #-------------------------------------------------------------------------- def draw_state_icon(icons, x = 0, y = 0) width = 0 for i in icons bitmap = RPG::Cache.States(i) # 描画開始 rect = Rect.new(0, 0, bitmap.width, bitmap.height) # 真ん中にアイコンが来るように変更 ty = y + (32 - bitmap.height) / 2 self.contents.blt(x + width, ty, bitmap, rect, self.opacity) width += bitmap.width + 1 end end #-------------------------------------------------------------------------- # ◎ 追加:ステートアイコンの幅取得 # icons : ステートアイコンの配列 #-------------------------------------------------------------------------- def get_state_icon_width(icons) width = 0 for i in icons bitmap = RPG::Cache.States(i) width += bitmap.width + 1 end return width - 1 end end #============================================================================== # ■ Window_Help #============================================================================== class Window_Help < Window_Base #-------------------------------------------------------------------------- # ● エネミー設定 # enemy : 名前とステートを表示するエネミー #-------------------------------------------------------------------------- def set_enemy(enemy) text = enemy.name state_text = make_battler_state_text(enemy, 112, false) # ☆ココから変更 if state_text != [] # ステート名文字で表示する場合、一番最初のヤツを表示する。 if Annex::STATE_ICON_ENEMY_SET == false state_text = state_text[0] text += " " + state_text set_text(text, 1) # ステート名をアイコンで表示する場合、専用のメソッドを呼び出す else # 描画幅の取得 text_width = self.contents.text_size(text + " ").width total_width = text_width + get_state_icon_width(state_text) # 敵の名前を表示 draw_enemy_text(text, state_text, total_width) end else # ステートが空の場合素直にset_text set_text(text, 1) end # ☆ココまで変更 end #-------------------------------------------------------------------------- # ◎ 追加:敵の名前を描画 # name : 敵の名前 # state_icon : アイコンの名前が格納されてる配列 # width : 描画幅 #-------------------------------------------------------------------------- def draw_enemy_text(name, state_icon, total_width) # 名前が前回と違う場合 (確認用にステートを文字列に変換しておく) if (name + state_icon.join(',')) != @text # テキストを再描画 self.contents.clear self.contents.font.color = normal_color # x 座標を設定 x = (self.width - total_width - 32) / 2 text_width = self.contents.text_size(name + " ").width self.contents.draw_text(x, 0, text_width, 32, name + " ") x += text_width # ステート描画 draw_state_icon(state_icon, x, 0) # @textなどを変更しておく。 @text = name + state_icon.join(',') # align は、まぁ、真ん中に表示なのでとりあえず1にしておく。 @align = 1 @actor = nil end self.visible = true end end