extends Control class_name MenuContainer # Path to the game scene or initialization script const ChessGame = preload("res://Systems/Game/ChessGame.gd") const VERSION_FILE_PATH = "res://Game.json" # Signal to notify parent when a new game is requested signal new_game_requested @onready var newGameButton = $HBoxContainer/VBoxContainer/MenuOptions/NewGameText @onready var continueButton = $HBoxContainer/VBoxContainer/MenuOptions/Continue @onready var optionsButton = $HBoxContainer/VBoxContainer/MenuOptions/Options @onready var versionText = $HBoxContainer/VBoxContainer/VersionText @onready var titleText = $HBoxContainer/VBoxContainer/TitleText @onready var developerText = $HBoxContainer/VBoxContainer/DeveloperText @onready var stateMachine = get_node("/root/Board/StateMachine") func _ready(): # Connect menu option signals _connect_button(newGameButton, "_on_new_game_pressed") _connect_button(continueButton, "_on_continue_pressed") _connect_button(optionsButton, "_on_options_pressed") load_version() func load_version(): var version = "v.0.0.0" var title = "ChessBuilder" var developer = "" var file = FileAccess.open(VERSION_FILE_PATH, FileAccess.READ) if file: var json_text = file.get_as_text() file.close() # Parse the JSON var json = JSON.new() var error = json.parse(json_text) if error == OK: var data = json.get_data() if data and typeof(data) == TYPE_DICTIONARY and data.has("version"): version = "v " + str(data.version) if data and typeof(data) == TYPE_DICTIONARY and data.has("title"): title = str(data.title) if data and typeof(data) == TYPE_DICTIONARY and data.has("developer"): developer = str(data.developer) else: print("JSON Parse Error: ", json.get_error_message()) if versionText: versionText.text = version if titleText: titleText.text = title if developerText: developerText.text = developer # Connect a button signal to a method func _connect_button(button, method_name): if button and button.has_signal("pressed"): if !button.is_connected("pressed", Callable(self, method_name)): button.connect("pressed", Callable(self, method_name)) # Handle New Game button press func _on_new_game_pressed(): print("New Game pressed, initializing game...") # Hide the menu container self.visible = false # # Find the ChessGame instance or create one if needed # var chess_game = _find_chess_game() # if chess_game: # # Reset the game board if it exists # chess_game.resetBoard() # # Start state machine # if stateMachine: # stateMachine.transitionToNextState(Constants.WHITE_TURN) # else: # print("Warning: StateMachine not found") # else: # print("Error: ChessGame not found") # Emit signal for parent to handle emit_signal("new_game_requested") # Handle Continue button press func _on_continue_pressed(): print("Continue pressed") # Implement continue game logic here # self.visible = false # You can add logic to load a saved game if needed # Handle Options button press func _on_options_pressed(): print("Options pressed") # Implement options menu logic here # You could show an options panel or switch to an options menu # Find the ChessGame node func _find_chess_game(): # Try to find existing ChessGame node var chess_game = get_node_or_null("/root/Game/ChessGame") # If not found, check if we're a child of ChessGame if not chess_game: var parent = get_parent() while parent and not chess_game: if parent.get_class() == "ChessGame" or parent is ChessGame: chess_game = parent parent = parent.get_parent() return chess_game # Public method to show the menu func show_menu(): self.visible = true