Project1
标题:
物品分类
[打印本页]
作者:
scgjgj999
时间:
2014-7-20 10:24
标题:
物品分类
本帖最后由 RyanBern 于 2014-7-20 15:11 编辑
最近在做物品分类时出现了一个问题,就是想把防具和装饰品分开,但怎么做都做不出来,大侠麻烦来帮个忙。
附脚本:
#==============================================================================
# ■ Window_ItemTitle
#------------------------------------------------------------------------------
# 选择类别
#==============================================================================
class Window_ItemTitle < Window_Base #"使用物品"四个字的窗口
def initialize
super(0, 0, 160, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.clear
self.contents.font.color = Color.new(189, 183, 103, 200)
self.contents.draw_text(4, 0, 120, 32, $data_system.words.item, 1)
end
end
class Window_ItemCommand < Window_Selectable
#———— 初始化 ————
def initialize
super(0, 64, 160, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 5
@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
case self.index
when 0
@text = @commands[0]
when 1
@text = @commands[1]
when 2
@text = @commands[2]
when 3
@text = @commands[3]
when 4
@text = @commands[4]
end
@help_window.set_text(@text)
end
end # Window_ItemCommand的
#==============================================================================
# ■ Window_ItemCommand
#------------------------------------------------------------------------------
# 选择类别
#==============================================================================
#==============================================================================
# ■ Window_ItemList
#------------------------------------------------------------------------------
# 物品窗口。 item.variance是物品的"分散度",借来用做分类
#==============================================================================
class Window_ItemList < Window_Selectable
#———— 初始化 ————
def initialize
super(160, 0, 480, 416)
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 #恢复类,分散度为0
for i in 1...$data_items.size
if ($data_items[i].variance == 0 and $game_party.item_number(i) > 0)
@data.push($data_items[i])
end
end
when 1 #武器类:
for i in 1...$game_party.weapons.size
if $game_party.weapons[i] != nil
@data.push($game_party.weapons[i]) if ! $game_party.weapons[i].equiping
end
end
when 2 #防具辅助类
for i in 1...$game_party.armors.size
if $game_party.armors[i] != nil
@data.push($game_party.armors[i]) if ! $game_party.armors[i].equiping
end
end
when 3 #材料
for i in 1...$data_items.size
if ($data_items[i].variance == 6 and $game_party.item_number(i) > 0)
@data.push($data_items[i])
end
end
when 4 #不明物品类:分散度为5
for i in 1...$data_items.size
if ($data_items[i].variance == 5 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) and $game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = Color.new(153, 153, 153, 220)
end
#—— 描绘物体图标、物体名、数量 ——
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 + 400, y, 16, 32, ":", 1)
self.contents.draw_text(x + 416, y, 24, 32, number.to_s, 2)
end
#——— 更新帮助窗口 ————
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end #—— Window_ItemList 的 ——
复制代码
我试过用 .kind 进行分解,但是分解开以后不报错,分类里也显示不出任何防具和装饰品,试了好几种方法,结果都是无法显示出防具和饰品,有点晕了,求大侠出来帮忙解释下,谢谢了~~~~~~~~
作者:
恐惧剑刃
时间:
2014-7-20 10:37
本帖最后由 恐惧剑刃 于 2014-7-20 11:19 编辑
现在试试呢?
推荐看看癫狂侠客的录像
#==============================================================================
# ■ Window_ItemTitle
#------------------------------------------------------------------------------
# 选择类别
#==============================================================================
class Window_ItemTitle < Window_Base #"使用物品"四个字的窗口
def initialize
super(0, 0, 160, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.clear
self.contents.font.color = Color.new(189, 183, 103, 200)
self.contents.draw_text(4, 0, 120, 32, "使用"<<$data_system.words.item, 1) # 改
end
end
class Window_ItemCommand < Window_Selectable
#———— 初始化 ————
def initialize
super(0, 64, 160, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 5
@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 # Window_ItemCommand的
#==============================================================================
# ■ Window_ItemCommand
#------------------------------------------------------------------------------
# 选择类别
#==============================================================================
#==============================================================================
# ■ Window_ItemList
#------------------------------------------------------------------------------
# 物品窗口。 item.variance是物品的"分散度",借来用做分类
#==============================================================================
class Window_ItemList < Window_Selectable
#———— 初始化 ————
def initialize
super(160, 0, 480, 416)
refresh
self.index = -1 # 改
self.active = false # 改
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 #恢复类,分散度为0 改
for i in 1...$data_items.size
if ($data_items[i].variance == 0 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])# if ! $game_party.weapons.equiping
end
end
when 2 #防具辅助类 改
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
# 这样分歧
case $data_armors[i].kind
when 2
when 3
end
@data.push($data_armors[i])# if ! $game_party.armors.equiping
end
end
when 3 #材料 改
for i in 1...$data_items.size
if ($data_items[i].variance == 6 and $game_party.item_number(i) > 0)
@data.push($data_items[i])
end
end
when 4 #不明物品类:分散度为5 改
for i in 1...$data_items.size
if ($data_items[i].variance == 5 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) and $game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = Color.new(153, 153, 153, 220)
end
#—— 描绘物体图标、物体名、数量 ——
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 + 400, y, 16, 32, ":", 1)
self.contents.draw_text(x + 416, y, 24, 32, number.to_s, 2)
end
#——— 更新帮助窗口 ———— 改
def update_help
@help_window.set_text(@data[self.index] == nil ? "" : @data[self.index].description)
end
end #—— Window_ItemList 的 ——
复制代码
作者:
芯☆淡茹水
时间:
2014-7-20 15:07
#多增加一个分歧,分别添加 防具 和 饰品 。
when 2 #防具类
for i in 1...$game_party.armors.size
armor = $game_party.armors[i]
if armor != nil
unless armor.equiping
@data.push(armor) if [0,1,2].include?(armor.kind)
end
end
end
when 3 #饰品类
for i in 1...$game_party.armors.size
armor = $game_party.armors[i]
if armor != nil
unless armor.equiping
@data.push(armor) if armor.kind == 3
end
end
end
# 下面的就依次: when 4 when 5 ,,,,,,,,
复制代码
作者:
scgjgj999
时间:
2014-7-20 17:07
好的,下次我注意,谢谢提醒~{:2_282:}
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1