function for toggling main menu visibility
This commit is contained in:
parent
8b437f6598
commit
8189a16fee
3 changed files with 31 additions and 20 deletions
|
@ -16,6 +16,7 @@ script = ExtResource("1_ysxum")
|
|||
[node name="MainMenu" parent="." instance=ExtResource("2_wfpe2")]
|
||||
|
||||
[node name="Game" type="Node2D" parent="."]
|
||||
process_mode = 1
|
||||
visible = false
|
||||
|
||||
[node name="ChunkHandler" type="Node2D" parent="Game"]
|
||||
|
|
|
@ -63,39 +63,49 @@ func start_new_game():
|
|||
|
||||
func _on_mainmenu_button_pressed(button:int):
|
||||
match button:
|
||||
0: # new game
|
||||
Globals.MAINMENU_NEW_GAME:
|
||||
start_new_game()
|
||||
self.find_child("Menu_NewGame").disabled = true
|
||||
self.find_child("Menu_ResumeGame").disabled = false
|
||||
1: # load game:
|
||||
Globals.MAINMENU_LOAD_GAME:
|
||||
pass
|
||||
2: # resume game
|
||||
Globals.MAINMENU_RESUME_GAME:
|
||||
# TODO save camera position before opening menu, restore camera position when closing menu
|
||||
self.find_child("Game").process_mode = PROCESS_MODE_INHERIT
|
||||
self.find_child("Game").show()
|
||||
self.find_child("UILayer").show()
|
||||
self.find_child("MainMenu").hide()
|
||||
toggle_main_menu_visibility()
|
||||
Globals.MAINMENU_QUIT_GAME:
|
||||
quit_game()
|
||||
_:
|
||||
push_error("Error: Main: unknown signal at _on_mainmenu_button_pressed: ", button)
|
||||
|
||||
func _unhandled_input(event) -> void:
|
||||
if event.is_action_pressed("open_main_menu"):
|
||||
emit_signal(
|
||||
"set_camera_position",
|
||||
Vector2(
|
||||
DisplayServer.window_get_size(0).x/2,
|
||||
DisplayServer.window_get_size(0).y/2
|
||||
)
|
||||
)
|
||||
self.find_child("Game").hide()
|
||||
self.find_child("UILayer").hide()
|
||||
self.find_child("MainMenu").show()
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
# move mainmenu to current game camera position
|
||||
var mainmenu_pos = Globals.CAMERA_POSITION
|
||||
mainmenu_pos.x -= DisplayServer.window_get_size(0).x/2
|
||||
mainmenu_pos.y -= DisplayServer.window_get_size(0).y/2
|
||||
self.find_child("MainMenu").position = mainmenu_pos
|
||||
|
||||
# show the menu
|
||||
toggle_main_menu_visibility()
|
||||
#await get_tree().create_timer(0.2).timeout
|
||||
self.find_child("Game").process_mode = PROCESS_MODE_DISABLED
|
||||
|
||||
|
||||
|
||||
func toggle_main_menu_visibility():
|
||||
var items = [find_child("Game"), find_child("UILayer"), find_child("MainMenu")]
|
||||
|
||||
for item in items:
|
||||
if !item:
|
||||
push_error("Error: While toggling main menu visibility. Missing UI element " + item)
|
||||
if item.visible:
|
||||
item.hide()
|
||||
continue
|
||||
item.show()
|
||||
|
||||
func quit_game():
|
||||
get_tree().get_root().propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,5 +29,5 @@ func _on_menu_credits_pressed():
|
|||
|
||||
|
||||
func _on_menu_exit_game_pressed():
|
||||
#emit_signal("button_pressed", Globals.MAINMENU_QUIT_GAME)
|
||||
get_tree().quit()
|
||||
emit_signal("button_pressed", Globals.MAINMENU_QUIT_GAME)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue