# 多周目物品箱 by cupidk rays
# 需配合本工程内的跨存档变量
# 使用方法 调用脚本$scene = Scene_NGCase.new
class Game_Party; attr_accessor :items ; end
class Window_NgItem < Window_Item
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
(1...$data_items.size).each do |i|
if Ngitem_number(i) > 0
@data.push($data_items[i])
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
(0...@item_max).each do |i|
draw_item(i)
end
end
end
def Ngitem_number(id)
data = CUPIDK::NGVAR.get_data["NG_items"]
n = data.include?(id) ? data[id] : 0
end
def draw_item(index)
item = @data[index]
number = Ngitem_number(item.id)
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
end
class Window_HaveItem < Window_Item
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
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
end
class Scene_NGCase
include CUPIDK
def main
# 生成帮助窗口、物品窗口
@help_window = Window_Help.new
@item_window = Window_HaveItem.new
@item_window.y += 285
@item_window.height = 130
@item_window.help_window = @help_window
@Ngitem_window = Window_NgItem.new
@Ngitem_window.help_window = @help_window
@Ngitem_window.height = 284
if $game_party.items.empty? || !$game_party.items.any? {|k,v| v >= 1 }
@item_window.active = false
else
@Ngitem_window.active = false
end
# 执行过度
Graphics.transition
# 主循环
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
# 释放窗口
@help_window.dispose
@item_window.dispose
@Ngitem_window.dispose
end
# 画面更新
def update
@help_window.update
@item_window.update
@Ngitem_window.update
if @item_window.active
update_item
return
end
if @Ngitem_window.active
update_Ngitem
return
end
end
def Ngitems
NGVAR.get_data["NG_items"]
end
# 跨存档储存窗口
def update_Ngitem
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
@Ngitem = @Ngitem_window.item
num = 1
if NGVAR.get_data["NG_items"].include?(@Ngitem.id) && NGVAR.get_data["NG_items"][@Ngitem.id] >= num
NGVAR.get_data["NG_items"][@Ngitem.id] -= num
if $game_party.items.include?(@Ngitem.id)
$game_party.gain_item(@Ngitem.id, num)
else
$game_party.items[@Ngitem.id] = num
end
$game_system.se_play($data_system.decision_se)
name = "Data/NGdata.rxdata"
save_data(NGVAR.get_data, name)
@item_window.refresh
@Ngitem_window.refresh
else
$game_system.se_play($data_system.cancel_se)
end
end
end
# 角色物品窗口
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@Ngitem_window.active = true
@item_window.active = false
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
id = NGVAR::NGTIMES_VARID
max = $game_variables[id] * NGVAR::NGCASE_SIZE
ngmax = NGVAR.get_data["NG_items"].select do |k, v|
v > 0
end
if (NGVAR.get_data["NG_items"][@item.id].nil? || NGVAR.get_data["NG_items"][@item.id] == 0) &&
max <= ngmax.size
return $game_system.se_play($data_system.cancel_se)
end
# 演奏确定 SE
num = 1
if $game_party.items.include?(@item.id) && $game_party.item_number(@item.id) >= num
$game_party.gain_item(@item.id, -num)
if NGVAR.get_data["NG_items"][@item.id]
NGVAR.get_data["NG_items"][@item.id] += num
else
NGVAR.get_data["NG_items"][@item.id] = num
end
$game_system.se_play($data_system.decision_se)
name = "Data/NGdata.rxdata"
save_data(NGVAR.get_data, name)
@item_window.refresh
@Ngitem_window.refresh
else
$game_system.se_play($data_system.cancel_se)
end
end
end
end