Project1
标题:
根据装备总数让商店购买窗口装备字体变灰
[打印本页]
作者:
兔毛鹿
时间:
2015-9-19 12:59
标题:
根据装备总数让商店购买窗口装备字体变灰
本帖最后由 兔毛鹿 于 2015-9-19 13:05 编辑
在Window_ShopBuy修改了脚本,我希望:当前携带的武器和防具总数相加如果超过60件,购买窗口所有装备字体的颜色就显示为灰色,我测试买了60个铜铳,结果只有铜铳和防具的字体颜色变灰了,而其它武器的名字没有变灰,应该怎么改才能让所有的装备都变灰??
11223.JPG
(38.71 KB, 下载次数: 16)
下载附件
保存到相册
2015-9-19 12:58 上传
在Window_ShopBuy 的● 描绘项目 部分修改的脚本
def draw_item(index)
item = @data[index]
# 获取物品所持数
case item
when RPG::Item
number = $game_party.item_number(item.id)
# 价格在所持金以下、并且所持数不是 99 的情况下为普通颜色
# 除此之外的情况设置为无效文字色
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
when RPG::Weapon
number = $game_party.weapon_number(item.id)
b = 0
for j in 1..$data_armors.size
b += $game_party.armor_number(j)
end
if item.price <= $game_party.gold and number < 60 - b
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
when RPG::Armor
number = $game_party.armor_number(item.id)
a = 0
for j in 1..$data_weapons.size
a += $game_party.weapon_number(j)
end
if item.price <= $game_party.gold and number < 60 - a
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 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 == disabled_color ? 128 : 255
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 + 240, y, 88, 32, item.price.to_s, 2)
end
复制代码
作者:
cinderelmini
时间:
2015-9-19 13:44
本帖最后由 cinderelmini 于 2015-9-19 14:35 编辑
【Window_ShopBuy】改成这样(添加的东西放到了顶格,然后draw_item方法改了):
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
# 公开背包武器防具
class Game_Party
attr_accessor :weapons
attr_accessor :armors
end
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# shop_goods : 商品
#--------------------------------------------------------------------------
def initialize(shop_goods)
super(0, 128, 368, 352)
@shop_goods = shop_goods
refresh
self.index = 0
end
# 刷新背包持有数
def reset_wea_arm_number
@wea_arm_number = 0
$game_party.weapons.each_value{|value| @wea_arm_number += value}
$game_party.armors.each_value{|value| @wea_arm_number += value}
end
# 不可购买的场合
def cant_buy(item)
return (item == nil || item.price > $game_party.gold) if item.is_a?(RPG::Item)
return (item == nil || item.price > $game_party.gold || @wea_arm_number >= 60) if (item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor))
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
reset_wea_arm_number
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
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)
# 价格在所持金以下、并且所持数不是 99 的情况下为普通颜色
# 除此之外的情况设置为无效文字色
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
when RPG::Weapon
number = $game_party.weapon_number(item.id)
if item.price <= $game_party.gold && @wea_arm_number < 60
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
when RPG::Armor
number = $game_party.armor_number(item.id)
if item.price <= $game_party.gold && @wea_arm_number < 60
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 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 == disabled_color ? 128 : 255
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 + 240, y, 88, 32, item.price.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 刷新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
复制代码
然后到【Scene_Shop】里面的【update_buy】方法里面,
把按下C键的场合的第一个不能购买的分歧条件改成:
if @buy_window.cant_buy(@item)
复制代码
大概就可以了。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1