Project1
标题: 物品分类脚本的修改 [打印本页]
作者: summer依恋 时间: 2011-10-6 10:51
标题: 物品分类脚本的修改
本帖最后由 Kimu 于 2011-10-6 11:30 编辑
如下,是我使用的脚本,想扩展2个分类,自己知道要改的有
@item_max =
@commands =
还有底下的分类要求什么的
第一第二我会修改,出了点问题,就是在测试时分类的名字显示不完全,如下图,只能在右边看得见名字
是按什么要求分的我就搞不懂了,求各位帮帮忙
我是加入了装备扩展脚本的,因此新加的2个分类为“项链”和“鞋子”
话说,代码框怎么用不起了,还是偶电脑出问题了。。。。- #==============================================================================
- # 分类物品的命令窗口
- #==============================================================================
- class Window_ItemCommand < Window_Selectable
- #———— 初始化 ————
- def initialize #前两个坐标是位置,后两个是大小下
- super(555, 240, 142, 300) #扩大了
- self.contents = Bitmap.new(width - 32, height - 32 )
- @item_max = 8 #加道具类,防具3类分开(已经修改)
- @commands = ["药物类", "武器类", "盾牌类", "护身类", "头盔类","装饰类", "道具类", "特殊类"]
- refresh
- self.index = 0
- end
- #———— 刷新 ————
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i, normal_color)
- end
- end
- #—— 描绘项目 ——| index:编号,color:颜色——————
- def draw_item(index, color)
- self.contents.font.color = color
- y = index * 32
- self.contents.draw_text(4, y, 128, 32, @commands[index])
- end
- #—— 帮助部分更新 ————
- def update_help
- @help_window.set_text(@commands[self.index])
- end
- end
- #==============================================================================
- # 物品清单窗口
- #==============================================================================
- class Window_ItemList < Window_Selectable
- #———— 初始化 ————
- def initialize
- super(30, 20, 500, 450)
- # @column_max = 2
- refresh
- self.index = 0
- end
- #—— 取得现在选择的物品 ——
- def item
- return @data[self.index]
- end
- #—— 刷新 ———
- def refresh
- if self.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @data = []
- end
- #—— 设置不同类别的物品 ———
- def set_item(command)
- refresh
- #—— 根据现在的选项决定物品 ——
- case command
- when 0 #药品类
- for i in 1...$data_items.size
- if ($data_items[i].type == "药物" and $game_party.item_number(i) > 0)
- @data.push($data_items[i])
- end
- end
- when 1 #武器类
- for i in 1...$data_weapons.size
- if $game_party.weapon_number(i) > 0
- @data.push($data_weapons[i])
- end
- end
- when 2 #盾牌类
- for i in 1...$data_armors.size
- if $data_armors[i].kind == 0 and $game_party.armor_number(i) > 0
- @data.push($data_armors[i])
- end
- end
- when 3 #护身类+++++
- for i in 1...$data_armors.size
- if $data_armors[i].kind == 1 and $game_party.armor_number(i) > 0
- @data.push($data_armors[i])
- end
- end
- when 4 #头盔类++++++
- for i in 1...$data_armors.size
- if $data_armors[i].kind == 2 and $game_party.armor_number(i) > 0
- @data.push($data_armors[i])
- end
- end
- when 5 #装饰类
- for i in 1...$data_armors.size
- if $data_armors[i].kind == 3 and $game_party.armor_number(i) > 0
- @data.push($data_armors[i])
- end
- end
- when 6 #道具类(已经修改)
- for i in 1...$data_items.size
- if ($data_items[i].type == "道具" and $game_party.item_number(i) > 0)
- @data.push($data_items[i])
- end
- end
- when 7 #特殊类(已经修改)
- for i in 1...$data_items.size
- if ($data_items[i].type == "特殊" and $game_party.item_number(i) > 0)
- @data.push($data_items[i])
- end
- end
- end
- @item_max = @data.size
- if @item_max > 0
- self.contents = Bitmap.new(width - 32, row_max * 32)
- self.contents.clear
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- #——— 单类物品的个数 ————
- def item_number
- return @item_max
- end
- #——— 项目内容的描画 ————
- 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)
- if $game_party.item_can_use?(item.id)
- self.contents.font.color = normal_color
- else
- self.contents.font.color = disabled_color
- end
- else
- self.contents.font.color = normal_color
- end
-
- #—— 描绘物体图标、物体名、数量 ——
- # x = 4 + index % 2 * 173
- # y = index / 2 * 32
- x = 4
- y = index*32
- 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 + 300, y, 16, 32, "×", 1)
- self.contents.draw_text(x + 314, y, 24, 32, number.to_s, 2)
- end
- #——— 更新帮助窗口 ————
- def update_help
- @help_window.set_text(make_description(self.item))
- end
- end
- #############################################################################
- #############################################################################
- #==============================================================================
- # ■ Scene_Item
- #------------------------------------------------------------------------------
- # 处理物品画面的类。
- #==============================================================================
- #############################################################################
- #############################################################################
- class Scene_Item
- #——— 主处理 ————
- def main
- cmd = Window_Command_New.new($game_party.actors.size)
- cmd.index = 1
- cmd.active = false
- # 右边命令窗口
- @itemcommand_window = Window_ItemCommand.new
- @itemcommand_window.opacity = HS::OPACITY
- @itemcommand_window.y = 672
- @item_command_index = @itemcommand_window.index
- # 物品窗口
- @itemlist_window = Window_ItemList.new
- @itemlist_window.opacity = HS::OPACITY
- @itemlist_window.active = false
- @itemlist_window.set_item(@item_command_index)
- @itemlist_window.x = -378
- # 帮助窗口
- @item_help_window = Window_Help_New.new
- @item_help_window.x = -580
- @item_help_window.y = 516 #原先是396
- @item_help_window.opacity = HS::OPACITY
- # 关联帮助窗口
- @itemcommand_window.help_window = @item_help_window
- @itemlist_window.help_window = @item_help_window
- # 目标窗口
- @item_target_window = Window_Target.new
- @item_target_window.y = 480
- @item_target_window.opacity = HS::OPACITY
- @item_target_window.visible = false
- @item_target_window.active = false
- # 目标装备窗口
- @item_target_window_equip = Window_Target_Equip.new
- @item_target_window_equip.y = 480
- @item_target_window_equip.opacity = HS::OPACITY
- @item_target_window_equip.visible = false
- @item_target_window_equip.active = false
- #—— 主循环 ——
- Graphics.transition
- # 窗口的滑动
- for i in 1..8
- @item_help_window.x += 76
- @itemcommand_window.y -= 60
- @itemlist_window.x += 51
- if i == 8
- @item_help_window.x = 30
- @itemcommand_window.y = 190
- @itemlist_window.x = 30
- end
- Graphics.update
- end
-
- loop do
- Graphics.update
- Input.update
- # 更新item
- update_item_scene
- if $scene != self
- break
- end
- end
- #—— 释放窗口 ——
-
- # 窗口的滑动
- for i in 1..9
- @item_help_window.x -= 76
- @itemcommand_window.y += 60
- @itemlist_window.x -= 51
- Graphics.update
- end
-
- Graphics.freeze
- cmd.dispose
- @itemcommand_window.dispose
- @itemlist_window.dispose
- @item_help_window.dispose
- @item_target_window.dispose
- @item_target_window_equip.dispose
- end
- #—— update的定义 ——
- def update_item_scene
- @itemcommand_window.update
- @itemlist_window.update
- @item_help_window.update
- @item_target_window.update
- @item_target_window_equip.update
-
- if @item_command_index != @itemcommand_window.index
- @item_command_index = @itemcommand_window.index
- @itemlist_window.set_item(@item_command_index)
- end
-
- #—— 当某窗体在active的时候,更新之 ——
- if @itemcommand_window.active
- item_update_itemcommand
- return
- end
- if @itemlist_window.active
- item_update_itemlist
- return
- end
- if @item_target_window.active
- item_update_target
- return
- end
- if @item_target_window_equip.active
- item_update_target_equip
- return
- end
- end # update的
- #————具体更新定义————
- def item_update_itemcommand
-
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换到菜单画面
- $scene = Scene_Menu.new(1)
- return
- end
-
- if Input.trigger?(Input::C)
- if @itemlist_window.item_number == 0
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- $game_system.se_play($data_system.decision_se)
- @itemcommand_window.active = false
- @itemlist_window.active = true
- @itemlist_window.index = 0
- return
- end
- end
- #————具体更新定义————
- def item_update_itemlist
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @itemcommand_window.active = true
- @itemlist_window.active = false
- @itemlist_window.index = 0
- @itemcommand_window.index = @item_command_index
- return
- end
-
- if Input.trigger?(Input::C)
- @item = @itemlist_window.item
- if @item.is_a?(RPG::Item)
- unless $game_party.item_can_use?(@item.id)
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- $game_system.se_play($data_system.decision_se)
- if @item.scope >= 3
- @itemlist_window.active = false
- # 先打开目标窗口的显示,才开始滑动
- @item_target_window.visible = true
- @item_target_window.active = true
- for i in 1..8
- @item_target_window.y -= 39
- if i==8
- @item_target_window.y = 164
- end
- Graphics.update
- end
- if @item.scope == 4 || @item.scope == 6
- @item_target_window.index = -1
- else
- @item_target_window.index = 0
- end
- else
- if @item.common_event_id > 0
- $game_temp.common_event_id = @item.common_event_id
- $game_system.se_play(@item.menu_se)
- if @item.consumable
- $game_party.lose_item(@item.id, 1)
- @itemlist_window.draw_item(@itemlist_window.index)
- end
- $scene = Scene_Map.new
- return
- end
- end
- return
- else
- $game_system.se_play($data_system.decision_se)
- @itemlist_window.active = false
- @item_target_window_equip.set_item(@item)
- @item_target_window_equip.visible = true
- @item_target_window_equip.active = true
- for i in 1..8
- @item_target_window_equip.y -= 39
- if i==8
- @item_target_window_equip.y = 164
- end
- Graphics.update
- end
- @item_target_window_equip.index = 0
- return
- end
-
-
-
-
-
- end
- end
- def item_update_target_equip
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @itemlist_window.active = true
- # 目标窗口滑动,滑动结束后才关闭显示
- for i in 1..9
- @item_target_window_equip.y += 39
- Graphics.update
- end
- @item_target_window_equip.visible = false
- @item_target_window_equip.active = false
- @itemlist_window.set_item(@item_command_index)
- return
- end
- if Input.trigger?(Input::C)
- target_actor = $game_party.actors[@item_target_window_equip.index]
- if target_actor.equippable?(@item) and $game_party.item_can_equip?(target_actor,@item)
- # 演奏装备 SE
- $game_system.se_play($data_system.equip_se)
- if @item.is_a?(RPG::Weapon)
- equip_position = 0
- elsif @item.kind == 0
- equip_position = 1
- elsif @item.kind == 1
- equip_position = 2
- elsif @item.kind == 2
- equip_position = 3
- elsif @item.kind == 3
- equip_position = 4
- end
-
- # 固定装备的情况下
- if target_actor.equip_fix?(equip_position)
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
-
- target_actor.equip(equip_position,@item.id)
-
- @itemlist_window.active = true
- # 目标窗口滑动,滑动结束后才关闭显示
- for i in 1..9
- @item_target_window_equip.y += 39
- Graphics.update
- end
- @item_target_window_equip.visible = false
- @item_target_window_equip.active = false
-
- @itemlist_window.draw_item(@itemlist_window.index)
- @itemlist_window.set_item(@item_command_index)
- else
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- end
-
-
-
- end
-
- end
-
- #———— 更新target窗口————
- def item_update_target
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- unless $game_party.item_can_use?(@item.id)
- @itemlist_window.refresh
- end
- @itemlist_window.active = true
- # 目标窗口滑动,滑动结束后才关闭显示
- for i in 1..9
- @item_target_window.y += 39
- Graphics.update
- end
- @item_target_window.visible = false
- @item_target_window.active = false
- @itemlist_window.set_item(@item_command_index)
- return
- end
- if Input.trigger?(Input::C)
- if $game_party.item_number(@item.id) == 0
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- if @item_target_window.index == -1
- used = false
- for i in $game_party.actors
- used |= i.item_effect(@item)
- end
- end
- if @item_target_window.index >= 0
- target = $game_party.actors[@item_target_window.index]
- used = target.item_effect(@item)
- end
-
- if used
- $game_system.se_play(@item.menu_se)
- if @item.consumable
- $game_party.lose_item(@item.id, 1)
- @itemlist_window.draw_item(@itemlist_window.index)
- @itemlist_window.set_item(@item_command_index)
- end
- @item_target_window.refresh
- if $game_party.all_dead?
- $scene = Scene_Gameover.new
- return
- end
-
- if @item.common_event_id > 0
- $game_temp.common_event_id = @item.common_event_id
- $scene = Scene_Map.new
- return
- end
- end
-
- unless used
- $game_system.se_play($data_system.buzzer_se)
- end
- return
- end
- end
- end
复制代码