#============================================================================== # ■ 物品手动分类 By gonglinyuan #============================================================================== #============================================================================== # 以下是用户设定区 #============================================================================== # 物品分类表;最后两个分别是武器和防具,不要动 $Item_Sort_Table = ["道具类","剧情类","武器类","防具类"] # 设定用于物品分类的第一个属性,默认是从17号属性开始 $Item_Sort_Start = 17 #============================================================================== # 物品的类别数目(不要动) $Item_Sort_Size = $Item_Sort_Table.size - 2 #============================================================================== # ■ Scene_Item #------------------------------------------------------------------------------ # 处理物品画面的类。 #============================================================================== class Scene_Item #-------------------------------------------------------------------------- # ● 主处理 #-------------------------------------------------------------------------- def main # 生成帮助窗口、物品窗口 @help_window = Window_Help.new @item_window = Window_MenuItem.new @item_window.active = false @item_window.index = -1 # 生成分类窗口 @sort_window = Window_Command.new(160,$Item_Sort_Table) @sort_window.y = 64 @sort_window.active = true # 生成金钱窗口 @gold_window = Window_Gold.new @gold_window.x = 0 @gold_window.y = 416 # 关联帮助窗口 @item_window.help_window = @help_window # 生成目标窗口 (设置为不可见・不活动) @target_window = Window_Target.new @target_window.visible = false @target_window.active = false # 执行过度 Graphics.transition # 主循环 loop do # 刷新游戏画面 Graphics.update # 刷新输入信息 Input.update # 刷新画面 update # 如果画面切换就中断循环 if $scene != self break end end # 装备过渡 Graphics.freeze # 释放窗口 @help_window.dispose @item_window.dispose @target_window.dispose @sort_window.dispose @gold_window.dispose end #-------------------------------------------------------------------------- # ● 刷新画面 #-------------------------------------------------------------------------- def update # 刷新窗口 @help_window.update @item_window.update @target_window.update @sort_window.update @gold_window.update # 分类窗口被激活的情况下: 调用 update_sort if @sort_window.active update_sort return end # 物品窗口被激活的情况下: 调用 update_item if @item_window.active update_item return end # 目标窗口被激活的情况下: 调用 update_target if @target_window.active update_target return end end #-------------------------------------------------------------------------- # ● 刷新画面 (分类窗口被激活的情况下) #-------------------------------------------------------------------------- def update_sort if Input.trigger?(Input::B) # 演奏取消 SE $game_system.se_play($data_system.cancel_se) # 切换到菜单画面 $scene = Scene_Menu.new(0) return end if Input.trigger?(Input::C) # 演奏确定 SE $game_system.se_play($data_system.decision_se) # 激活物品窗口 @sort_window.active = false @item_window.active = true @item_window.index = 0 @item_window.set_kind(@sort_window.index) @item_window.refresh end end #-------------------------------------------------------------------------- # ● 刷新画面 (物品窗口被激活的情况下) #-------------------------------------------------------------------------- def update_item # 按下 B 键的情况下 if Input.trigger?(Input::B) # 演奏取消 SE $game_system.se_play($data_system.cancel_se) # 清空物品窗口 if @item_window.contents != nil @item_window.contents.dispose @item_window.contents = nil end # 激活分类窗口 @item_window.active = false @item_window.index = -1 @item_window.set_kind(-1) @sort_window.active = true return end # 按下 C 键的情况下 if Input.trigger?(Input::C) # 获取物品窗口当前选中的物品数据 @item = @item_window.item # 不使用物品的情况下 unless @item.is_a?(RPG::Item) # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end # 不能使用的情况下 unless $game_party.item_can_use?(@item.id) # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end # 演奏确定 SE $game_system.se_play($data_system.decision_se) # 效果范围是我方的情况下 if @item.scope >= 3 # 激活目标窗口 @item_window.active = false @target_window.x = (@item_window.index + 1) % 2 * 304 @target_window.visible = true @target_window.active = true # 设置效果范围 (单体/全体) 的对应光标位置 if @item.scope == 4 || @item.scope == 6 @target_window.index = -1 else @target_window.index = 0 end # 效果在我方以外的情况下 else # 公共事件 ID 有效的情况下 if @item.common_event_id > 0 # 预约调用公共事件 $game_temp.common_event_id = @item.common_event_id # 演奏物品使用时的 SE $game_system.se_play(@item.menu_se) # 消耗品的情况下 if @item.consumable # 使用的物品数减 1 $game_party.lose_item(@item.id, 1) # 再描绘物品窗口的项目 @item_window.draw_item(@item_window.index) end # 切换到地图画面 $scene = Scene_Map.new return end end return end end end #============================================================================== # ■ Window_MenuItem #------------------------------------------------------------------------------ # 物品画面显示浏览物品的窗口。 #============================================================================== class Window_MenuItem < Window_Selectable #-------------------------------------------------------------------------- # ● 初始化对像 #-------------------------------------------------------------------------- def initialize super(160, 64, 480, 416) @column_max = 2 self.index = 0 @data = [] @kind = -1 # 0 = 物品;1 = 武器;2 = 防具 refresh end #-------------------------------------------------------------------------- # ● 设置物品种类 #-------------------------------------------------------------------------- def set_kind(item_kind) @kind = item_kind end #-------------------------------------------------------------------------- # ● 获取物品 #-------------------------------------------------------------------------- def item return @data[self.index] end #-------------------------------------------------------------------------- # ● 刷新 #-------------------------------------------------------------------------- def refresh if self.contents != nil self.contents.dispose self.contents = nil end @data = [] # 添加物品 case @kind when 0...$Item_Sort_Size for i in 1...$data_items.size if $data_items[i].element_set.include?($Item_Sort_Start + @kind) if $game_party.item_number(i) > 0 @data.push($data_items[i]) end end end when $Item_Sort_Size for i in 1...$data_weapons.size if $game_party.weapon_number(i) > 0 @data.push($data_weapons[i]) end end when $Item_Sort_Size + 1 for i in 1...$data_armors.size if $game_party.armor_number(i) > 0 @data.push($data_armors[i]) end end end # 如果项目数不是 0 就生成位图、重新描绘全部项目 @item_max = @data.size if @item_max > 0 self.contents = Bitmap.new(width - 32, row_max * 32) for i in 0...@item_max draw_item(i) end end end #-------------------------------------------------------------------------- # ● 描绘项目 # index : 项目编号 #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] case item when RPG::Item number = $game_party.item_number(item.id) when RPG::Weapon number = $game_party.weapon_number(item.id) when RPG::Armor number = $game_party.armor_number(item.id) end if item.is_a?(RPG::Item) and $game_party.item_can_use?(item.id) self.contents.font.color = normal_color else self.contents.font.color = disabled_color end x = 4 + index % 2 * 240 y = index / 2 * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 160, y, 16, 32, ":", 1) self.contents.draw_text(x + 176, y, 24, 32, number.to_s, 2) end #-------------------------------------------------------------------------- # ● 刷新帮助文本 #-------------------------------------------------------------------------- def update_help @help_window.set_text(self.item == nil ? "" : self.item.description) end end
350.99 KB, 下载次数: 149
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |