#encoding:utf-8
#==============================================================================
# ■ Scene_Shop
#------------------------------------------------------------------------------
# 商店画面
#==============================================================================
class Scene_Shop < Scene_MenuBase
#↓ =================== ↓#
TALK_SWITCH = 84
# 开关编号,根据此开关在事件中设置是显示对话还是直接跳出循环。参考范例中的【开关1】
ALL_Tr = false
# 全体窗口透明开关,true为全部透明,方便自己制作合适的背景。
# 在事件中调用脚本,内容为:
# ---------------------------------
# $TALK_TITLE = "请问您需要什么?"
# $TALK_BACK = "shopback_001"
# ---------------------------------
# $TALK_TITLE——进入商店界面后显示的文字,通过全局变量传递。
# $TALK_BACK ——进入商店界面后显示的背景立绘图。
#↑ =================== ↑#
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_help_window
create_gold_window
create_command_window
create_dummy_window
create_number_window
create_status_window
create_buy_window
create_category_window
create_sell_window
transparent_all if ALL_Tr
@help_window.y = Graphics.height - @help_window.height
@help_window.set_text($TALK_TITLE)
@back_sprite = Sprite.new(@viewport)
@back_sprite.bitmap = Cache.picture($TALK_BACK)
end
#--------------------------------------------------------------------------
# ● 使所有窗口透明
#--------------------------------------------------------------------------
def transparent_all
instance_variables.each do |varname|
ivar = instance_variable_get(varname)
ivar.opacity = 0 if ivar.is_a?(Window)
end
end
#--------------------------------------------------------------------------
# ● 释放所有窗口
#--------------------------------------------------------------------------
def dispose_all_windows
super
@back_sprite.bitmap.dispose
@back_sprite.dispose
end
#--------------------------------------------------------------------------
# ● 生成金钱窗口
#--------------------------------------------------------------------------
def create_gold_window
@gold_window = Window_Gold.new
@gold_window.viewport = @viewport
end
#--------------------------------------------------------------------------
# ● 生成指令窗口
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_ShopCommand.new(Graphics.width - @gold_window.width, @purchase_only)
@command_window.viewport = @viewport
@command_window.x = @gold_window.width
@command_window.set_handler(:buy, method(:command_buy))
@command_window.set_handler(:sell, method(:command_sell))
@command_window.set_handler(:talk, method(:command_talk))
@command_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# ● 生成填充窗口
#--------------------------------------------------------------------------
def create_dummy_window
wy = @command_window.y + @command_window.height
wh = Graphics.height - wy - @help_window.height
@dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
@dummy_window.viewport = @viewport
@dummy_window.hide
end
#--------------------------------------------------------------------------
# ● 生成数值输入窗口
#--------------------------------------------------------------------------
def create_number_window
wy = @dummy_window.y
wh = @dummy_window.height
@number_window = Window_ShopNumber.new(0, wy, wh)
@number_window.viewport = @viewport
@number_window.hide
@number_window.set_handler(:ok, method(:on_number_ok))
@number_window.set_handler(:cancel, method(:on_number_cancel))
end
#--------------------------------------------------------------------------
# ● 生成卖出窗口
#--------------------------------------------------------------------------
def create_sell_window
wy = @category_window.y + @category_window.height
wh = Graphics.height - wy - @help_window.height
@sell_window = Window_ShopSell.new(0, wy, Graphics.width, wh)
@sell_window.viewport = @viewport
@sell_window.help_window = @help_window
@sell_window.hide
@sell_window.set_handler(:ok, method(:on_sell_ok))
@sell_window.set_handler(:cancel, method(:on_sell_cancel))
@category_window.item_window = @sell_window
end
#--------------------------------------------------------------------------
# ● 指令“交谈”
#--------------------------------------------------------------------------
def command_talk
$game_switches[TALK_SWITCH] = true
$game_map.need_refresh = true
return_scene
end
#--------------------------------------------------------------------------
# ● 买入“取消”
#--------------------------------------------------------------------------
def on_buy_cancel
@command_window.activate
@buy_window.hide
@status_window.hide
@status_window.item = nil
@help_window.clear
@help_window.set_text($TALK_TITLE)
end
#--------------------------------------------------------------------------
# ● 分类“取消”
#--------------------------------------------------------------------------
def on_category_cancel
@command_window.activate
@category_window.hide
@sell_window.hide
@help_window.set_text($TALK_TITLE)
end
end