module RB_ItemDump
# 不可丢弃的物品ID
NOT_FOR_DUMP_ITEMS = []
# 不可丢弃的武器ID
NOT_FOR_DUMP_WEAPONS = []
# 不可丢弃的防具ID
NOT_FOR_DUMP_ARMORS = []
def not_for_dump?(item)
case item
when RPG::Item
return NOT_FOR_DUMP_ITEMS.include?(item.id)
when RPG::Weapon
return NOT_FOR_DUMP_WEAPONS.include?(item.id)
when RPG::Armor
return NOT_FOR_DUMP_ARMORS.include?(item.id)
else
return true
end
end
end
class Window_ItemCommand < Window_Command
include RB_ItemDump
attr_accessor :calling_window
def initialize(width, commands)
super(width, commands)
@item = nil
@calling_window = nil
self.z = 120
self.active = false
self.visible = false
end
def item=(item)
@item = item
refresh
end
def refresh
self.contents.clear
(0...@item_max).each do |i|
draw_item(i, normal_color)
end
unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
disable_item(0)
end
if not_for_dump?(@item)
disable_item(1)
end
end
def adjust_position
if @calling_window.nil?
return
end
if @calling_window.cursor_y + 32 + self.height < 480
self.y = @calling_window.cursor_y + 32
else
self.y = @calling_window.cursor_y - self.height
end
self.x = @calling_window.cursor_x
end
end
class Window_Selectable
def cursor_x
cursor_width = self.width / @column_max - 32
x = @index % @column_max * (cursor_width + 32) + self.x + 16
return x
end
def cursor_y
y = @index / @column_max * 32 - self.oy + self.y + 16
return y
end
end
class Window_Dump < Window_Base
def initialize
super(0, 0, 176, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.x = 320 - width / 2
self.y = 240 - height / 2
self.z = 200
self.active = false
self.visible = false
@number = 1
end
def set(max)
@max = max
@number = 1
refresh
end
def number
return @number
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(0, 0, 144, 32, "输入丢弃个数")
self.contents.font.color = normal_color
self.contents.draw_text(72, 32, 32, 32, "×")
self.contents.draw_text(104, 32, 24, 32, @number.to_s, 2)
self.cursor_rect.set(100, 32, 32, 32)
end
def update
super
if self.active
# 光标右 (+1)
if Input.repeat?(Input::RIGHT) and @number < @max
$game_system.se_play($data_system.cursor_se)
@number += 1
refresh
end
# 光标左 (-1)
if Input.repeat?(Input::LEFT) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number -= 1
refresh
end
# 光标上 (+10)
if Input.repeat?(Input::UP) and @number < @max
$game_system.se_play($data_system.cursor_se)
@number = [@number + 10, @max].min
refresh
end
# 光标下 (-10)
if Input.repeat?(Input::DOWN) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number = [@number - 10, 1].max
refresh
end
end
end
end
class Scene_Item
include RB_ItemDump
alias rb_main main
def main
@dump_window = Window_Dump.new
@command_window = Window_ItemCommand.new(108, ["使用", "丢弃"])
rb_main
@dump_window.dispose
@command_window.dispose
end
def update
@command_window.calling_window = @item_window
@dump_window.update
@command_window.update
@help_window.update
@item_window.update
@target_window.update
if @item_window.active
update_item
return
end
if @target_window.active
update_target
return
end
if @command_window.active
update_command
return
end
if @dump_window.active
update_dump
return
end
end
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
if @item.nil?
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@command_window.item = @item
@command_window.adjust_position
@command_window.index = 0
@command_window.active = true
@command_window.visible = true
@item_window.active = false
return
end
end
def update_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.visible = false
@command_window.active = false
@item_window.active = true
return
end
if Input.trigger?(Input::C)
case @command_window.index
when 0
unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @item.scope >= 3
@command_window.active = false
@command_window.visible = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
else
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
$scene = Scene_Map.new
return
end
end
when 1
if not_for_dump?(@item)
$game_system.se_play($data_system.buzzer_se)
return
end
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.weapon_number(@item.id)
end
$game_system.se_play($data_system.decision_se)
@dump_window.set(number)
@dump_window.visible = true
@dump_window.active = true
@command_window.visible = false
@command_window.active = false
end
end
return
end
def update_dump
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@dump_window.visible = false
@dump_window.active = false
@command_window.active = true
@command_window.visible = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.shop_se)
number = @dump_window.number
case @item
when RPG::Item
$game_party.lose_item(@item.id, number)
when RPG::Weapon
$game_party.lose_weapon(@item.id, number)
when RPG::Armor
$game_party.lose_armor(@item.id, number)
end
@dump_window.visible = false
@dump_window.active = false
@item_window.active = true
@item_window.refresh
return
end
end
end