Project1
标题: [已解决]从自定义的子菜单返回时如何固定光标位置 [打印本页]
作者: 饿啊 时间: 2024-10-6 13:07
标题: [已解决]从自定义的子菜单返回时如何固定光标位置
本帖最后由 饿啊 于 2024-10-10 11:49 编辑
闲来无事搓了如下的“更多功能”子菜单小脚本:
class Window_ExtraMenuCommand < Window_MenuCommand #"更多功能"子菜单
def make_command_list
add_command("任务/书籍",:book,true)
add_command("自主合成",:itemsynthesis,$game_system.i_rcp_sw.size > 0)
unless TMMEDAL::HIDE_COMMAND && !medal_enabled
add_command(TMMEDAL::COMMAND_MEDAL, :medal, medal_enabled)
end
add_command("返回上级",:originmenu,true)
end
end
#==============================================================================
#“更多功能”窗口的Scene_ExtraMenu扩展
#==============================================================================
class Scene_ExtraMenu < Scene_Menu
#--------------------------------------------------------------------------
# ● 菜单条目生成
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_ExtraMenuCommand.new
@command_window.set_handler(:medal, method(:command_medal))
@command_window.set_handler(:book, method(:command_book))
@command_window.set_handler(:itemsynthesis, method(:command_itemsynthesis))
@command_window.set_handler(:originmenu, method(:return_scene))
@command_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# 窗口调用
#--------------------------------------------------------------------------
def command_medal
SceneManager.call(Scene_Medal)
end
def command_book
SceneManager.call(Scene_Book)
end
def command_itemsynthesis
SceneManager.call(Scene_ItemSynthesis)
end
end
class Window_ExtraMenuCommand < Window_MenuCommand #"更多功能"子菜单
def make_command_list
add_command("任务/书籍",:book,true)
add_command("自主合成",:itemsynthesis,$game_system.i_rcp_sw.size > 0)
unless TMMEDAL::HIDE_COMMAND && !medal_enabled
add_command(TMMEDAL::COMMAND_MEDAL, :medal, medal_enabled)
end
add_command("返回上级",:originmenu,true)
end
end
#==============================================================================
#“更多功能”窗口的Scene_ExtraMenu扩展
#==============================================================================
class Scene_ExtraMenu < Scene_Menu
#--------------------------------------------------------------------------
# ● 菜单条目生成
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_ExtraMenuCommand.new
@command_window.set_handler(:medal, method(:command_medal))
@command_window.set_handler(:book, method(:command_book))
@command_window.set_handler(:itemsynthesis, method(:command_itemsynthesis))
@command_window.set_handler(:originmenu, method(:return_scene))
@command_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# 窗口调用
#--------------------------------------------------------------------------
def command_medal
SceneManager.call(Scene_Medal)
end
def command_book
SceneManager.call(Scene_Book)
end
def command_itemsynthesis
SceneManager.call(Scene_ItemSynthesis)
end
end
随后在Scene_Menu中做了如下处理,以使得能在主菜单中出现“更多功能”的选项
@command_window.set_handler(:moreoptions, method(:command_moreoptions)) #位于"生成指令窗口"处
def command_moreoptions
#@command_window.dispose
#@command_window = Window_ExtraMenuCommand.new
SceneManager.call(Scene_ExtraMenu)
end #新增于各种指令处
@command_window.set_handler(:moreoptions, method(:command_moreoptions)) #位于"生成指令窗口"处
def command_moreoptions
#@command_window.dispose
#@command_window = Window_ExtraMenuCommand.new
SceneManager.call(Scene_ExtraMenu)
end #新增于各种指令处
运行虽然比较完美,但有一个小问题:如果直接按ESC还好,但只要我在子菜单中对任意选项进行“确认”操作后,返回主菜单时光标都会停在最上面一条。我想把光标固定在主菜单的“更多功能”上,请问我该如何进一步改写?
作者: 喵呜喵5 时间: 2024-10-8 13:51
打开菜单时的选项位置是 Window_MenuCommand 的 @@last_command_symbol 在控制的,你的 “子菜单中对任意选项进行“确认”操作” 是不是改了这个?
作者: 喵呜喵5 时间: 2024-10-9 13:53
你自己内部界面里的选项窗口,不要作为 Window_MenuCommand 的子类,而是直接作为 Window_Command 的子类就没这问题了
作者: 饿啊 时间: 2024-10-10 11:18
本帖最后由 饿啊 于 2024-10-10 11:45 编辑
感谢提点,另对父类修改后还需要对一楼中脚本主体的第19行做出如下改动:@command_window = Window_ExtraMenuCommand.new(0,0)
@command_window = Window_ExtraMenuCommand.new(0,0)
以及如果有后来的兄弟想引入这个脚本,还是用如下的改良版好些,(请务必配合一楼中对于Scene_Manager的改动)起码不会报错:
#=================================================================
#"更多功能"子菜单
#=================================================================
class Window_ExtraMenuCommand < Window_Command
def make_command_list
#~ add_command("任务/书籍",:book,true)
#~ add_command("自主合成",:itemsynthesis,$game_system.i_rcp_sw.size > 0)
#~ unless TMMEDAL::HIDE_COMMAND && !medal_enabled
#~ add_command(TMMEDAL::COMMAND_MEDAL, :medal, medal_enabled)
#~ end
add_command("返回上级",:originmenu,true)
#此处仅保留"返回上级",以适配其他工程
end
end
#==============================================================================
#MenuCommand扩展
#==============================================================================
class Window_MenuCommand
alias saren_extramenu_add_original_commands add_original_commands
def add_original_commands
saren_extramenu_add_original_commands
add_command("更多功能",:moreoptions,true)
end
end
#==============================================================================
#“更多功能”窗口的Scene_ExtraMenu扩展
#==============================================================================
class Scene_ExtraMenu < Scene_Menu
#--------------------------------------------------------------------------
# ● 菜单条目生成
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_ExtraMenuCommand.new(0,0)
#~ @command_window.set_handler(:medal, method(:command_medal))
#~ @command_window.set_handler(:book, method(:command_book))
#~ @command_window.set_handler(:itemsynthesis, method(:command_itemsynthesis))
@command_window.set_handler(:originmenu, method(:return_scene))
@command_window.set_handler(:cancel, method(:return_scene))
#此处仅保留"返回上级",以适配其他工程
end
#--------------------------------------------------------------------------
# 窗口调用
#--------------------------------------------------------------------------
#~ def command_medal
#~ SceneManager.call(Scene_Medal)
#~ end
end
#=================================================================
#"更多功能"子菜单
#=================================================================
class Window_ExtraMenuCommand < Window_Command
def make_command_list
#~ add_command("任务/书籍",:book,true)
#~ add_command("自主合成",:itemsynthesis,$game_system.i_rcp_sw.size > 0)
#~ unless TMMEDAL::HIDE_COMMAND && !medal_enabled
#~ add_command(TMMEDAL::COMMAND_MEDAL, :medal, medal_enabled)
#~ end
add_command("返回上级",:originmenu,true)
#此处仅保留"返回上级",以适配其他工程
end
end
#==============================================================================
#MenuCommand扩展
#==============================================================================
class Window_MenuCommand
alias saren_extramenu_add_original_commands add_original_commands
def add_original_commands
saren_extramenu_add_original_commands
add_command("更多功能",:moreoptions,true)
end
end
#==============================================================================
#“更多功能”窗口的Scene_ExtraMenu扩展
#==============================================================================
class Scene_ExtraMenu < Scene_Menu
#--------------------------------------------------------------------------
# ● 菜单条目生成
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_ExtraMenuCommand.new(0,0)
#~ @command_window.set_handler(:medal, method(:command_medal))
#~ @command_window.set_handler(:book, method(:command_book))
#~ @command_window.set_handler(:itemsynthesis, method(:command_itemsynthesis))
@command_window.set_handler(:originmenu, method(:return_scene))
@command_window.set_handler(:cancel, method(:return_scene))
#此处仅保留"返回上级",以适配其他工程
end
#--------------------------------------------------------------------------
# 窗口调用
#--------------------------------------------------------------------------
#~ def command_medal
#~ SceneManager.call(Scene_Medal)
#~ end
end
如果还有其他使用上的疑问,烦请告知我。
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |