basic main menu
This commit is contained in:
parent
523f7888da
commit
8b437f6598
16 changed files with 370 additions and 128 deletions
|
@ -39,20 +39,18 @@ func _init() -> void:
|
|||
|
||||
|
||||
func _on_main_worldgen_ready():
|
||||
thread.start(start_chunkgen, Thread.PRIORITY_NORMAL)
|
||||
clean_up_chunks()
|
||||
if !thread.is_started():
|
||||
thread.start(start_chunkgen, Thread.PRIORITY_NORMAL)
|
||||
clean_up_chunks()
|
||||
|
||||
|
||||
#func _process(_delta):
|
||||
# update_chunks()
|
||||
|
||||
|
||||
func _ready():
|
||||
mutex = Mutex.new()
|
||||
semaphore = Semaphore.new()
|
||||
exit_thread = false
|
||||
|
||||
thread = Thread.new()
|
||||
if !thread:
|
||||
thread = Thread.new()
|
||||
|
||||
process_delay_chunks()
|
||||
process_delay_stats()
|
||||
|
|
|
@ -8,6 +8,8 @@ signal button_pressed(button_name)
|
|||
|
||||
var amount_of_chunks:int = 0
|
||||
var size_of_chunk_removal_queue:int = 0
|
||||
var update_debug_info:bool = false
|
||||
|
||||
|
||||
# name, position
|
||||
var buttons = {
|
||||
|
@ -20,6 +22,45 @@ var buttons = {
|
|||
"button_social": [Vector2(150,50), "So"],
|
||||
}
|
||||
|
||||
func _on_chunk_handler_chunk_stats(chunks, removal_queue):
|
||||
self.amount_of_chunks = chunks
|
||||
self.size_of_chunk_removal_queue = removal_queue
|
||||
|
||||
|
||||
# sends signals which View catches and places selected type of buildings
|
||||
func _on_button_residental_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_RESIDENTIAL)
|
||||
|
||||
|
||||
func _on_button_commercial_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_COMMERCIAL)
|
||||
|
||||
|
||||
func _on_button_industrial_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_INDUSTRIAL)
|
||||
|
||||
|
||||
func _on_button_roads_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_ROADS)
|
||||
|
||||
|
||||
func _on_button_demolish_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_DEMOLISH)
|
||||
|
||||
|
||||
func _on_button_services_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_SERVICES)
|
||||
|
||||
|
||||
func _on_button_social_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_SOCIAL)
|
||||
|
||||
|
||||
func _on_main_worldgen_ready():
|
||||
self.set_process(true)
|
||||
update_debug_info = true
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
create_buttons()
|
||||
|
@ -28,15 +69,9 @@ func _ready():
|
|||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta):
|
||||
debug_info.set_text(
|
||||
str(get_viewport().get_mouse_position()) +"\n" +
|
||||
"FPS " + str(Engine.get_frames_per_second()) + "\n" +
|
||||
"Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + "\n" +
|
||||
"Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" +
|
||||
"Camera pos: " + str(Globals.camera_marker.position) + "\n" +
|
||||
"Chunks: " + str(self.amount_of_chunks) + "\n" +
|
||||
"Chunk del: " + str(self.size_of_chunk_removal_queue),
|
||||
)
|
||||
if update_debug_info:
|
||||
update_debug_info_func()
|
||||
|
||||
|
||||
# defines construction toolbar buttons
|
||||
func create_buttons():
|
||||
|
@ -53,31 +88,16 @@ func create_buttons():
|
|||
node_path.set_anchor(SIDE_TOP, anchor_top)
|
||||
node_path.set_text(values[1])
|
||||
node_path.show()
|
||||
|
||||
func update_debug_info_func():
|
||||
debug_info.set_text(
|
||||
str(get_viewport().get_mouse_position()) +"\n" +
|
||||
"FPS " + str(Engine.get_frames_per_second()) + "\n" +
|
||||
"Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + "\n" +
|
||||
"Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" +
|
||||
"Camera pos: " + str(Globals.camera_marker.position) + "\n" +
|
||||
"Chunks: " + str(self.amount_of_chunks) + "\n" +
|
||||
"Chunk del: " + str(self.size_of_chunk_removal_queue),
|
||||
)
|
||||
|
||||
|
||||
# sends signals which View catches and places selected type of buildings
|
||||
func _on_button_residental_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_RESIDENTIAL)
|
||||
|
||||
func _on_button_commercial_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_COMMERCIAL)
|
||||
|
||||
func _on_button_industrial_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_INDUSTRIAL)
|
||||
|
||||
func _on_button_roads_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_ROADS)
|
||||
|
||||
func _on_button_demolish_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_DEMOLISH)
|
||||
|
||||
func _on_button_services_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_SERVICES)
|
||||
|
||||
func _on_button_social_pressed():
|
||||
emit_signal("button_pressed", Globals.TYPE_SOCIAL)
|
||||
|
||||
|
||||
func _on_chunk_handler_chunk_stats(chunks, removal_queue):
|
||||
self.amount_of_chunks = chunks
|
||||
self.size_of_chunk_removal_queue = removal_queue
|
||||
|
|
|
@ -87,6 +87,7 @@ const GUI_BUILD_BUTTON_SIZE_Y: int = 50
|
|||
const GUI_BUILD_BUTTON_SIZE: Vector2i = Vector2i(GUI_BUILD_BUTTON_SIZE_X,GUI_BUILD_BUTTON_SIZE_Y)
|
||||
|
||||
# maybe should use int for these instead for faster matching?
|
||||
# ^ yes TODO switch to enum
|
||||
const TYPE_RESIDENTIAL:String = "residential"
|
||||
const TYPE_COMMERCIAL:String = "commercial"
|
||||
const TYPE_INDUSTRIAL:String = "industrial"
|
||||
|
@ -96,6 +97,16 @@ const TYPE_POWERPLANT:String = "powerplant"
|
|||
const TYPE_ROADS:String = "roads"
|
||||
const TYPE_DEMOLISH:String = "demolish"
|
||||
|
||||
# Main menu buttons
|
||||
enum {
|
||||
MAINMENU_NEW_GAME,
|
||||
MAINMENU_LOAD_GAME,
|
||||
MAINMENU_RESUME_GAME,
|
||||
MAINMENU_OPTIONS,
|
||||
MAINMENU_CREDITS,
|
||||
MAINMENU_QUIT_GAME,
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
# WORLD GENERATION SETTINGS #
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
33
scripts/MainMenuBar.gd
Normal file
33
scripts/MainMenuBar.gd
Normal file
|
@ -0,0 +1,33 @@
|
|||
extends GridContainer
|
||||
|
||||
signal button_pressed(button_name)
|
||||
|
||||
# Connect main menu to Main game
|
||||
func _ready():
|
||||
self.connect("button_pressed", self.find_parent("Main")._on_mainmenu_button_pressed, CONNECT_PERSIST)
|
||||
self.find_child("Menu_ResumeGame").disabled = true
|
||||
|
||||
|
||||
func _on_menu_new_game_pressed():
|
||||
emit_signal("button_pressed", Globals.MAINMENU_NEW_GAME)
|
||||
|
||||
|
||||
func _on_menu_load_game_pressed():
|
||||
emit_signal("button_pressed", Globals.MAINMENU_LOAD_GAME)
|
||||
|
||||
|
||||
func _on_menu_resume_game_pressed():
|
||||
emit_signal("button_pressed", Globals.MAINMENU_RESUME_GAME)
|
||||
|
||||
|
||||
func _on_menu_options_pressed():
|
||||
emit_signal("button_pressed", Globals.MAINMENU_OPTIONS)
|
||||
|
||||
|
||||
func _on_menu_credits_pressed():
|
||||
emit_signal("button_pressed", Globals.MAINMENU_CREDITS)
|
||||
|
||||
|
||||
func _on_menu_exit_game_pressed():
|
||||
#emit_signal("button_pressed", Globals.MAINMENU_QUIT_GAME)
|
||||
get_tree().quit()
|
|
@ -9,6 +9,7 @@ signal set_map_background_texture(texture)
|
|||
@onready var is_mouse_inside_minimap:bool = false
|
||||
@onready var position_multiplier:float
|
||||
@onready var area_size:Vector2
|
||||
var observe_mouse_inside_minimap:bool = false
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
@ -22,7 +23,7 @@ func _draw():
|
|||
|
||||
|
||||
func _process(_delta):
|
||||
if !is_mouse_inside_minimap:
|
||||
if !is_mouse_inside_minimap and observe_mouse_inside_minimap:
|
||||
Globals.camera_marker.position = Vector2(
|
||||
Globals.CAMERA_POSITION.x / position_multiplier,
|
||||
Globals.CAMERA_POSITION.y / position_multiplier,
|
||||
|
@ -31,6 +32,8 @@ func _process(_delta):
|
|||
|
||||
func _on_main_worldgen_ready():
|
||||
# Assuming the area has a child CollisionShape2D with a RectangleShape resource
|
||||
self.set_process(true)
|
||||
observe_mouse_inside_minimap = true
|
||||
area_size = self.get_rect().size
|
||||
|
||||
position_multiplier = Globals.map_size / 32
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue