赞 | 2 |
VIP | 0 |
好人卡 | 0 |
积分 | 42 |
经验 | 13328 |
最后登录 | 2024-8-10 |
在线时间 | 258 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 4169
- 在线时间
- 258 小时
- 注册时间
- 2013-10-13
- 帖子
- 815
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
class Scene_Ck
def main
# 生成帮助窗口、物品窗口
@help_window = Window_Help.new
@ck_item_window = Ck_Window_Item.new
@ch_item_window = Ch_Window_Item.new
# 关联帮助窗口
@ck_item_window.help_window = @help_window
# 生成命令窗口
s1 = "取出"
s2 = "存入"
s3 = "取消"
@command_window = Window_Command.new(192, [s1,s2,s3])
@command_window.x = 0
@command_window.y = 480-128
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面被切换就中断循环
if $scene != self
break
end
end
# 装备过渡
Graphics.freeze
@ck_item_window.dispose
@ch_item_window.dispose
@help_window.dispose
@command_window.dispose
end
def update
@command_window.update
@ck_item_window.update
@ch_item_window.update
if @command_window.active #命令窗口界面
command_update
return
end
if @ck_item_window.active #仓库界面
ck_update
return
end
if @ch_item_window.active #角色背包界面
ch_update
return
end
end
def command_update
@ck_item_window.active=false
@ch_item_window.active=false
if Input.trigger?(Input::B)
$scene=Scene_Map.new
end
if Input.trigger?(Input::C)
case @command_window.index
when 0
@command_window.active=false
@ch_item_window.active=false
@ck_item_window.active=true
return
when 1
@command_window.active=false
@ch_item_window.active=true
@ck_item_window.active=false
return
when 2
$scene=Scene_Map.new
return
end
end
end
def ck_update
if Input.trigger?(Input::B)
@command_window.active=true
@ch_item_window.active=false
@ck_item_window.active=false
return
end
if Input.trigger?(Input::C)
@tmp=@ck_item_window.item.id
if $game_party.item_number(@ck_item_window.item.id)>0
#p $game_party
$game_party.lose_item(@ck_item_window.item.id,1)
#p $game_party
#p @ck_item_window.item.id
@ck_item_window.refresh
#p @ck_item_window.item.id
else
return
end
$game_party.gain_item_1(@tmp,1)
@ch_item_window.refresh
end
end
def ch_update
if Input.trigger?(Input::B)
@command_window.active=true
@ch_item_window.active=false
@ck_item_window.active=false
return
end
if Input.trigger?(Input::C)
@tmp_1=@ch_item_window.item.id
if $game_party.item_number_1(@ch_item_window.item.id)>0
$game_party.lose_item_1(@ch_item_window.item.id,1)
@ch_item_window.refresh
else
return
end
$game_party.gain_item(@tmp_1,1)
@ck_item_window.refresh
end
end
end
class Ch_Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(320, 64, 320, 416-64)
@column_max = 1
refresh
self.index = 0
# 战斗中的情况下将窗口移至中央并将其半透明化
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# 添加物品
for i in 1...$data_items.size
if $game_party.item_number_1(i) > 0
@data.push($data_items[i])
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_1(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
y = index * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 更新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽度
cursor_width = self.width / (@column_max*2) - 32
# 计算光标坐标
x = @index % @column_max * (cursor_width/2 + 32)
y = @index / @column_max * 32 - self.oy
# 更新光标矩形
self.cursor_rect.set(x, y, cursor_width/2, 32)
end
end
class Ck_Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
super(0, 64, 320, 416-64)
@column_max = 1
refresh
self.index = 0
# 战斗中的情况下将窗口移至中央并将其半透明化
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# 添加物品
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
#p $game_party
@data.push($data_items[i])
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
y = index * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 刷新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
#--------------------------------------------------------------------------
# ● 更新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽度
cursor_width = self.width / (@column_max*2) - 32
# 计算光标坐标
x = @index % @column_max * (cursor_width/2 + 32)
y = @index / @column_max * 32 - self.oy
# 更新光标矩形
self.cursor_rect.set(x, y, cursor_width/2, 32)
end
end
class Game_Party
alias initialize_old initialize
def initialize
initialize_old
@items_1={}
end
#--------------------------------------------------------------------------
# ● 获取物品的所持数
# item_id : 物品 ID
#--------------------------------------------------------------------------
def item_number_1(item_id)
# 如果 hash 个数数值不存在就返回 0
return @items_1.include?(item_id) ? @items_1[item_id] : 0
end
#--------------------------------------------------------------------------
# ● 减少物品
# item_id : 物品 ID
# n : 个数
#--------------------------------------------------------------------------
def lose_item_1(item_id, n)
# 调用 gain_item 的数值逆转
gain_item_1(item_id, -n)
end
#--------------------------------------------------------------------------
# ● 增加物品 (减少)
# item_id : 物品 ID
# n : 个数
#--------------------------------------------------------------------------
def gain_item_1(item_id, n)
# 更新 hash 的个数数据
if item_id > 0
@items_1[item_id] = [[item_number_1(item_id) + n, 0].max, 99].min
end
end
end
描述:
在地图上设置一个事件用脚本:
$game_party.gain_item(1,10)
$game_party.gain_item(4,10)
$scene=Scene_Ck.new
我的仓库脚本只能作到取出物品和存入物品,但是在物品数目0的时候显示不了,请高手帮我改一下脚本,做到能显示0数目的物品数目。
|
|