2023-12-05 23:18:27 +10:30
|
|
|
extends Control
|
2023-12-06 16:32:40 +10:30
|
|
|
#warning-ignore-all:return_value_discarded
|
2023-12-05 23:18:27 +10:30
|
|
|
|
2023-12-06 16:32:40 +10:30
|
|
|
const globals = preload('res://globals.gd') # Make LSP shut up about non-const
|
|
|
|
const Menu = globals.Menu
|
|
|
|
var packed_menus = {}
|
2023-12-05 23:18:27 +10:30
|
|
|
var menus = {}
|
|
|
|
var active_menu_stack = []
|
|
|
|
|
2023-12-06 16:32:40 +10:30
|
|
|
func instantiate_menu_list(menu_list) -> void:
|
|
|
|
for key in menu_list:
|
|
|
|
packed_menus[key] = load(globals.MENUS[key][0])
|
|
|
|
menus[key] = packed_menus[key].instance()
|
2024-07-15 02:31:36 +09:30
|
|
|
if menus[key].has_signal('exit'):
|
|
|
|
menus[key].connect('exit', self, 'pop_menu')
|
2023-12-06 16:32:40 +10:30
|
|
|
|
2023-12-05 23:18:27 +10:30
|
|
|
var is_rom_loaded := false
|
2023-12-06 16:32:40 +10:30
|
|
|
func _on_rom_loaded() -> void:
|
|
|
|
instantiate_menu_list(globals.POST_ROM_MENUS)
|
|
|
|
menus[Menu.DEBUG].connect('button_pressed', self, 'push_menu')
|
2023-12-05 23:18:27 +10:30
|
|
|
is_rom_loaded = true
|
|
|
|
|
2023-12-06 16:32:40 +10:30
|
|
|
var is_savefile_loaded := false
|
|
|
|
func _on_savefile_loaded(dicts) -> void:
|
|
|
|
push_menu(Menu.LOAD_SAVE)
|
|
|
|
menus[Menu.LOAD_SAVE].set_data(dicts)
|
|
|
|
menus[Menu.LOAD_SAVE].connect('slot_activated', self, '_on_saveslot_loaded')
|
|
|
|
|
|
|
|
func _on_saveslot_loaded(dict) -> void:
|
|
|
|
push_menu(Menu.PARTY)
|
|
|
|
menus[Menu.PARTY].update_labels(dict)
|
|
|
|
|
2023-12-05 23:18:27 +10:30
|
|
|
func _ready() -> void:
|
|
|
|
if OS.get_name() != 'HTML5' or !OS.has_feature('JavaScript'):
|
2023-12-08 21:29:09 +10:30
|
|
|
packed_menus[Menu.LOADER] = preload('res://widgets/FileSelect.tscn')
|
2023-12-05 23:18:27 +10:30
|
|
|
else:
|
2023-12-08 21:29:09 +10:30
|
|
|
packed_menus[Menu.LOADER] = preload('res://widgets/FileSelectWeb.tscn')
|
2023-12-06 16:32:40 +10:30
|
|
|
menus[Menu.LOADER] = packed_menus[Menu.LOADER].instance()
|
2023-12-05 23:18:27 +10:30
|
|
|
push_menu(Menu.LOADER)
|
|
|
|
|
2023-12-06 16:32:40 +10:30
|
|
|
instantiate_menu_list(globals.INITIAL_MENUS)
|
|
|
|
|
|
|
|
RomLoader.connect('rom_loaded', self, '_on_rom_loaded')
|
2023-12-08 21:39:44 +10:30
|
|
|
menus[Menu.LOADER].connect('debug_pressed', self, 'push_debug_menu')
|
2023-12-06 16:32:40 +10:30
|
|
|
menus[Menu.LOADER].connect('savefile_loaded', self, '_on_savefile_loaded')
|
2023-12-05 23:18:27 +10:30
|
|
|
Common.update_window_scale()
|
|
|
|
|
|
|
|
func push_debug_menu():
|
|
|
|
push_menu(Menu.DEBUG)
|
|
|
|
|
|
|
|
func push_menu(menu_type):
|
|
|
|
if len(active_menu_stack) > 0:
|
|
|
|
if active_menu_stack[-1] == menu_type:
|
|
|
|
return
|
|
|
|
remove_child(menus[active_menu_stack[-1]])
|
|
|
|
active_menu_stack.append(menu_type)
|
2024-07-26 22:54:05 +09:30
|
|
|
self._present_menu(menus[menu_type])
|
2023-12-05 23:18:27 +10:30
|
|
|
|
|
|
|
func pop_menu():
|
|
|
|
if len(active_menu_stack) > 0:
|
|
|
|
remove_child(menus[active_menu_stack.pop_back()])
|
|
|
|
if len(active_menu_stack) > 0:
|
2024-07-26 22:54:05 +09:30
|
|
|
self._present_menu(menus[active_menu_stack[-1]])
|
2023-12-05 23:18:27 +10:30
|
|
|
else:
|
|
|
|
push_menu(Menu.LOADER)
|
|
|
|
|
2024-07-26 22:54:05 +09:30
|
|
|
func _present_menu(menu) -> void:
|
|
|
|
add_child(menu)
|
|
|
|
if menu.has_method('_on_menu_presented'):
|
|
|
|
menu._on_menu_presented()
|
|
|
|
|
2023-12-05 23:18:27 +10:30
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
if event is InputEventKey and event.pressed:
|
|
|
|
match event.scancode:
|
|
|
|
KEY_BACKSPACE:
|
|
|
|
pop_menu()
|
|
|
|
KEY_D:
|
|
|
|
if is_rom_loaded:
|
|
|
|
push_menu(Menu.DEBUG)
|
2024-07-26 22:11:04 +09:30
|
|
|
|
|
|
|
func _notification(what) -> void:
|
|
|
|
match what:
|
|
|
|
NOTIFICATION_WM_GO_BACK_REQUEST: # Android back button/gesture
|
|
|
|
if len(active_menu_stack) < 2:
|
|
|
|
print('main received NOTIFICATION_WM_GO_BACK_REQUEST, quitting')
|
|
|
|
get_tree().call_deferred('quit')
|
|
|
|
else:
|
|
|
|
print('main received NOTIFICATION_WM_GO_BACK_REQUEST, popping menu')
|
|
|
|
call_deferred('pop_menu')
|