#==============================================================================
# ■ 物品丢弃 + 物品种类数限制 —— by 水镜风生
#------------------------------------------------------------------------------
LOSE_ITEM_SE_NAME = "Evasion" # 丢弃物品时播放的SE
$item_max = 30 # 最大物品种数
#==============================================================================
# ■ Scene_Item
#------------------------------------------------------------------------------
# 处理物品画面的类。
#==============================================================================
class Scene_Item < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_menu_background
@viewport = Viewport.new(0, 0, 544, 416)
@help_window = Window_Help.new
@help_window.viewport = @viewport
@item_window = Window_Item.new(0, 67, 544, 280)
@item_window.viewport = @viewport
@item_window.help_window = @help_window
@item_window.active = false
@target_window = Window_MenuStatus.new(0, 0)
@max_window = Window_Item_Max.new
@max_window.viewport = @viewport
@number_window = Window_LoseNumber.new(142, 156)
@number_window.viewport = @viewport
@command_window = Window_Command.new(145, [" 使用"," 丢弃"], 1, 2)
@command_window.x = 200
@command_window.y = 160
@over_window = Window_Help.new
@over_window.set_text("背包放不下了,丢弃一些没用的物品吧。")
@over_window.visible = false
hide_command_window
hide_number_window
hide_target_window
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@viewport.dispose
@help_window.dispose
@item_window.dispose
@target_window.dispose
@max_window.dispose
@command_window.dispose
@number_window.dispose
@over_window.dispose
end
#--------------------------------------------------------------------------
# ● 回到原画面
#--------------------------------------------------------------------------
def return_scene
$scene = Scene_Menu.new(0)
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@over_window.update
@help_window.update
@item_window.update
@target_window.update
@max_window.update
@command_window.update
@number_window.update
if @item_window.active
update_item_selection
elsif @target_window.active
update_target_selection
elsif @command_window.active
update_command_selection
elsif @number_window.active
update_number_selection
end
end
#--------------------------------------------------------------------------
# ● 更新物品选择
#--------------------------------------------------------------------------
def update_item_selection
if Input.trigger?(Input::B)
if $game_party.items.size > $item_max # 如果物品种类超过限制
Sound.play_buzzer
@over_window.visible = true
@item_window.help_window.visible = false
else
Sound.play_cancel
return_scene
end
elsif Input.trigger?(Input::C)
@item_window.help_window.visible = true
@over_window.visible = false
@item = @item_window.item
if @item != nil
$game_party.last_item_id = @item.id
Sound.play_decision
if $game_party.item_can_use?(@item) # 物品是否可用
@command_window.draw_item(0,true)
else @command_window.draw_item(0,false) # 不可用的话【使用】选项颜色无效
end
if @item.price == 0 # 物品价格是否为0
@command_window.draw_item(1,false) # 是的话【丢弃】选项无效
else
@command_window.draw_item(1,true)
end
show_command_window
else
Sound.play_buzzer
end
end
end
#--------------------------------------------------------------------------
# ● 更新目标选择
#--------------------------------------------------------------------------
def update_target_selection
if Input.trigger?(Input::B)
Sound.play_cancel
if $game_party.item_number(@item) == 0 # 判断物品是否耗尽
@item_window.refresh # 刷新窗口内容
@max_window.refresh # 刷新物品种类窗口
end
hide_target_window
elsif Input.trigger?(Input::C)
if not $game_party.item_can_use?(@item)
Sound.play_buzzer
else
determine_target
end
end
end
#--------------------------------------------------------------------------
# ★ 更新指令选择
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
hide_command_window
elsif Input.trigger?(Input::C)
if @command_window.index == 0
if $game_party.item_can_use?(@item)
Sound.play_decision
@command_window.active = false
@command_window.visible =false
determine_item
else
Sound.play_buzzer
end
elsif @item == nil or @item.price == 0
Sound.play_buzzer
else
Sound.play_decision
@command_window.active = false
@command_window.visible =false
max = $game_party.item_number(@item)
@number_window.set(@item, max)
show_number_window
end
end
end
#--------------------------------------------------------------------------
# ★ 更新数量输入
#--------------------------------------------------------------------------
def update_number_selection
if Input.trigger?(Input::B)
Sound.play_cancel
hide_number_window
elsif Input.trigger?(Input::C)
Audio.se_play("Audio/SE/#{LOSE_ITEM_SE_NAME}", 80, 100)
$game_party.lose_item(@item, @number_window.number)
@item_window.refresh
@max_window.refresh
hide_number_window
end
end
#--------------------------------------------------------------------------
# ★ 显示指令选择窗口
#--------------------------------------------------------------------------
def show_command_window
@command_window.index = 0
@item_window.active = false
@command_window.visible = true
@command_window.active = true
end
#--------------------------------------------------------------------------
# ★ 显示数量窗口
#--------------------------------------------------------------------------
def show_number_window
@command_window.active = false
@number_window.visible = true
@number_window.active = true
end
#--------------------------------------------------------------------------
# ★ 隐藏指令选择窗口
#--------------------------------------------------------------------------
def hide_command_window
@item_window.active = true
@command_window.visible = false
@command_window.active = false
@viewport.rect.set(0, 0, 544, 416)
@viewport.ox = 0
end
#--------------------------------------------------------------------------
# ★ 隐藏数量窗口
#--------------------------------------------------------------------------
def hide_number_window
@item_window.active = true
@number_window.visible = false
@number_window.active = false
@viewport.rect.set(0, 0, 544, 416)
@viewport.ox = 0
end
end
#==============================================================================
# ■ Window_lost_item
#------------------------------------------------------------------------------
# 显示物品丢弃数量的窗口,仿 Window_ShopNumber。
#==============================================================================
class Window_LoseNumber < Window_Base
#--------------------------------------------------------------------------
# ★ 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 260, 104)
@item = nil
@max = 1
@number = 1
end
#--------------------------------------------------------------------------
# ★ 设置物品、最大数量
#--------------------------------------------------------------------------
def set(item, max)
@item = item
@max = max
@number = 1
refresh
end
#--------------------------------------------------------------------------
# ★ 设置数量输入
#--------------------------------------------------------------------------
def number
return @number
end
#--------------------------------------------------------------------------
# ★ 刷新
#--------------------------------------------------------------------------
def refresh
y = 24
self.contents.clear
draw_item_name(@item, 0, y)
self.contents.font.color = normal_color
self.contents.draw_text(164, y, 20, WLH, "×")
self.contents.draw_text(190, y, 20, WLH, @number, 2)
self.cursor_rect.set(186, y, 28, WLH)
end
#--------------------------------------------------------------------------
# ★ 更新画面
#--------------------------------------------------------------------------
def update
super
if self.active
last_number = @number
if Input.repeat?(Input::RIGHT) and @number < @max
@number += 1
end
if Input.repeat?(Input::LEFT) and @number > 1
@number -= 1
end
if Input.repeat?(Input::UP) and @number < @max
@number = [@number + 10, @max].min
end
if Input.repeat?(Input::DOWN) and @number > 1
@number = [@number - 10, 1].max
end
if @number != last_number
Sound.play_cursor
refresh
end
end
end
end
#==============================================================================
# ■ Window_Item_Max
#-----------------------------------------------------------------------------
# 显示背包容量和当前物品数的窗口
#============================================================================
class Window_Item_Max < Window_Base
#--------------------------------------------------------------------------
# ★ 初始化对像
#--------------------------------------------------------------------------
def initialize
super(290, 360, 254, 56)
refresh
end
#--------------------------------------------------------------------------
# ★ 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_icon(144, 0, 0)
self.contents.draw_text(36, 0, 100, 24, "背包容量:")
item = $game_party.items
string = item.size.to_s
self.contents.font.color = knockout_color if item.size > $item_max
self.contents.draw_text(135, 0, 30, 24, string, 2)
self.contents.font.color = normal_color
string = "/ " + $item_max.to_s
self.contents.draw_text(173, 0, 100, 24, string )
end
end