- 累计送礼:
- 0 个
- 累计收礼:
- 0 个
TA的每日心情 | 开心 昨天 18:01 |
---|
签到天数: 114 天 连续签到: 4 天 [LV.6]常住居民II

管理员
  
- VIP
- 6
- 卡币
- 10632
- OK点
- 16
- 推广点
- 0
- 同能卷
- 0
- 积分
- 13401


|
是LZ一个游戏制作途中用到的小功能。
具体是这样的的,NPC会送给玩家一些纪念性的小礼物,放在道具栏里和其他道具混在一起不方便,就做了个礼物盒的功能。放在玩家的房间里,玩家可以在那里查看收集到的小礼物。
Window_gift里预留了物品ID50~100为礼物
Window_Item里设置物品ID1~49、101以上为普通道具(具体请看注释)
可以按照需要自行更改
主角的道具栏顿时清净了有木有!{:2_268:}
使用方法:
将下面三个脚本依次插入Main上
在事件中调用脚本:$scene=Scene_Gift_Box.new 呼出礼物盒界面即可
默认是物品ID在50~100的物品为礼物,不会出现在玩家的道具列表里,只出现在礼物盒里。
效果预览:
事件:
物品设置:
RUBY 代码 - #==============================================================================
- # ■ Window_Item
- #------------------------------------------------------------------------------
- # 物品画面、战斗画面、显示浏览物品的窗口。
- #==============================================================================
- class Window_Item < Window_Selectable
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- super(0, 64, 640, 416)
- @column_max = 2
- 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
- ifself.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @data = []
- # 添加物品
- for i in1...49#ID1~49为普通道具
- if$game_party.item_number(i) > 0
- @data.push($data_items[i])
- end
- end
- for i in101...$data_items.size#ID101以上为普通道具
- if$game_party.item_number(i) > 0
- @data.push($data_items[i])
- end
- end
- # 在战斗中以外添加武器、防具
- unless$game_temp.in_battle
- for i in1...$data_weapons.size
- if$game_party.weapon_number(i) > 0
- @data.push($data_weapons[i])
- end
- end
- for i in1...$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 in0...@item_max
- draw_item(i)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- case item
- whenRPG::Item
- number = $game_party.item_number(item.id)
- whenRPG::Weapon
- number = $game_party.weapon_number(item.id)
- whenRPG::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 * (288 + 32)
- 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 + 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
- end
复制代码
RUBY 代码 - #==============================================================================
- # ■ Window_gift
- #------------------------------------------------------------------------------
- # 物品画面、战斗画面、显示浏览物品的窗口。
- #==============================================================================
- class Window_gift < Window_Selectable
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- super(0, 200, 640, 416)
- @column_max = 2
- refresh
- self.index = 0
- self.y = 64
- self.height = 200
- self.back_opacity = 160
- # 战斗中的情况下将窗口移至中央并将其半透明化
- 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
- ifself.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @data = []
- for i in50...100# 添加礼物——预留物品ID50~ID100的物品为“礼物”,可自行修改
- if$game_party.item_number(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 in0...@item_max
- draw_item(i)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- case item
- whenRPG::Item
- number = $game_party.item_number(item.id)
- whenRPG::Weapon
- number = $game_party.weapon_number(item.id)
- whenRPG::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 * (288 + 32)
- 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 + 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
- end
复制代码
RUBY 代码 - #==============================================================================
- # ■ Scene_Gift_Box
- #------------------------------------------------------------------------------
- # 处理礼物(不可使用)画面的类。
- #==============================================================================
- class Scene_Gift_Box
- #--------------------------------------------------------------------------
- # ● 主处理
- #--------------------------------------------------------------------------
- def main
- @sprite =Spriteset_Map.new
- # 生成帮助窗口、物品窗口
- @help_window = Window_Help.new
- @item_window = Window_gift.new
- # 关联帮助窗口
- @item_window.help_window = @help_window
- # 生成目标窗口 (设置为不可见・不活动)
- @target_window = Window_Target.new
- @target_window.visible = false
- @target_window.active = false
- # 执行过度
- Graphics.transition
- # 主循环
- loopdo
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果画面切换就中断循环
- if$scene != self
- break
- end
- end
- # 装备过渡
- Graphics.freeze
- # 释放窗口
- @sprite.dispose
- @help_window.dispose
- @item_window.dispose
- @target_window.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 刷新窗口
- @help_window.update
- @item_window.update
- @target_window.update
- # 物品窗口被激活的情况下: 调用 update_item
- if@item_window.active
- update_item
- return
- end
- # 目标窗口被激活的情况下: 调用 update_target
- if@target_window.active
- update_target
- return
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面 (物品窗口被激活的情况下)
- #--------------------------------------------------------------------------
- def update_item
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换到菜单画面
- $scene = Scene_Map.new
- return
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面 (目标窗口被激活的情况下)
- #--------------------------------------------------------------------------
- def update_target
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换到菜单画面
- $scene = Scene_Map.new
- return
- end
- end
- end
复制代码
本帖来自P1论坛作者小徐,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=344849 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|