basic main menu

This commit is contained in:
Antti Hakkarainen 2023-02-16 22:48:26 +02:00
parent 523f7888da
commit 8b437f6598
16 changed files with 370 additions and 128 deletions

View file

@ -16,6 +16,8 @@ extends Node2D
signal worldgen_ready
signal set_camera_position(pos:Vector2)
var start_new_game_pressed:bool = false
# The idea is for the user to be able to choose the map from GUI later
var map_filenames:Array = [
"res://maps/tampere_10x10km_1000px.png",
@ -24,20 +26,19 @@ var map_filenames:Array = [
"res://maps/tampere_256px.png",
"res://maps/tampere_10x10km_4096px.png"
]
var map_filename:String = map_filenames[1]
var map_filename:String = map_filenames[3]
var _world_generator:WorldGenerator
func _init():
func _init():
# DisplayServer.window_set_size(
# #Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES)
# Vector2i(3800,2000)
# )
Globals.CAMERA_POSITION = Vector2(16*256/2, 16*256/2)
# Called when the node enters the scene tree for the first time.
func _ready():
func start_new_game():
# create a new world with worldgenerator
_world_generator = WorldGenerator.new()
if !_world_generator.generate_world(map_filename):
@ -45,9 +46,14 @@ func _ready():
quit_game()
# connections are made from GUI
# tell other classes they can start working after loading is done
emit_signal("worldgen_ready")
emit_signal("worldgen_ready")
self.find_child("MainMenu").hide()
self.find_child("Game").show()
self.find_child("UILayer").show()
# center camera to world map
emit_signal(
"set_camera_position",
@ -55,6 +61,39 @@ func _ready():
Globals.map_size / 2.0 * Globals.TILE_SIZE_Y)
)
func _on_mainmenu_button_pressed(button:int):
match button:
0: # new game
start_new_game()
self.find_child("Menu_NewGame").disabled = true
self.find_child("Menu_ResumeGame").disabled = false
1: # load game:
pass
2: # 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()
_:
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
self.find_child("Game").process_mode = PROCESS_MODE_DISABLED
func quit_game():
get_tree().get_root().propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)