#============================================================================== # ■ Window_ShopStatus #------------------------------------------------------------------------------ #  ショップ画面で、アイテムの所持数やアクターの装備を表示するウィンドウです。 #============================================================================== class Window_ShopStatus < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(x, y, width, height) super(x, y, width, height) @item = nil @page_index = 0 refresh end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh contents.clear draw_possession(4, 0) draw_equip_info(4, line_height * 2) if @item.is_a?(RPG::EquipItem) end #-------------------------------------------------------------------------- # ● アイテムの設定 #-------------------------------------------------------------------------- def item=(item) @item = item refresh end #-------------------------------------------------------------------------- # ● 所持数の描画 #-------------------------------------------------------------------------- def draw_possession(x, y) rect = Rect.new(x, y, contents.width - 4 - x, line_height) change_color(system_color) draw_text(rect, Vocab::Possession) change_color(normal_color) draw_text(rect, $game_party.item_number(@item), 2) end #-------------------------------------------------------------------------- # ● 装備情報の描画 #-------------------------------------------------------------------------- def draw_equip_info(x, y) status_members.each_with_index do |actor, i| draw_actor_equip_info(x, y + line_height * (i * 2.4), actor) end end #-------------------------------------------------------------------------- # ● 装備情報を描画するアクターの配列 #-------------------------------------------------------------------------- def status_members $game_party.members[@page_index * page_size, page_size] end #-------------------------------------------------------------------------- # ● 一度に表示できるアクターの人数 #-------------------------------------------------------------------------- def page_size return 4 end #-------------------------------------------------------------------------- # ● 最大ページ数の取得 #-------------------------------------------------------------------------- def page_max ($game_party.members.size + page_size - 1) / page_size end #-------------------------------------------------------------------------- # ● アクターの装備情報を描画 #-------------------------------------------------------------------------- def draw_actor_equip_info(x, y, actor) enabled = actor.equippable?(@item) change_color(normal_color, enabled) draw_text(x, y, 112, line_height, actor.name) item1 = current_equipped_item(actor, @item.etype_id) draw_actor_param_change(x, y, actor, item1) if enabled draw_item_name(item1, x, y + line_height, enabled) end #-------------------------------------------------------------------------- # ● アクターの能力値変化を描画 #-------------------------------------------------------------------------- def draw_actor_param_change(x, y, actor, item1) rect = Rect.new(x, y, contents.width - 4 - x, line_height) change = @item.params[param_id] - (item1 ? item1.params[param_id] : 0) change_color(param_change_color(change)) draw_text(rect, sprintf("%+d", change), 2) end #-------------------------------------------------------------------------- # ● 選択中のアイテムに対応する能力値 ID の取得 # デフォルトでは武器なら攻撃力、防具なら防御力とする。 #-------------------------------------------------------------------------- def param_id @item.is_a?(RPG::Weapon) ? 2 : 3 end #-------------------------------------------------------------------------- # ● 現在の装備品を取得 # 二刀流など、同じ種類の装備が複数ある場合は弱い方を返す。 #-------------------------------------------------------------------------- def current_equipped_item(actor, etype_id) list = [] actor.equip_slots.each_with_index do |slot_etype_id, i| list.push(actor.equips[i]) if slot_etype_id == etype_id end list.min_by {|item| item ? item.params[param_id] : 0 } end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super update_page end #-------------------------------------------------------------------------- # ● ページの更新 #-------------------------------------------------------------------------- def update_page if visible && Input.trigger?(:A) && page_max > 1 @page_index = (@page_index + 1) % page_max refresh end end end