152 lines
5.4 KiB
GDScript
152 lines
5.4 KiB
GDScript
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
|
|
signal new_game_requested(options)
|
|
signal shop_open_requested(options)
|
|
signal deckmanager_open_requested(options)
|
|
signal map_open_requested(options)
|
|
@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 gameMenuScreen = get_node("/root/Board/GameMenuScreen")
|
|
|
|
@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")
|
|
if gameMenuScreen:
|
|
gameMenuScreen.setup(self)
|
|
gameMenuScreen.connect("shop_open_requested", Callable(self, "_on_shop_open_requested"))
|
|
gameMenuScreen.connect("deckmanager_open_requested", Callable(self, "_on_deckmanager_open_requested"))
|
|
gameMenuScreen.connect("map_open_requested", Callable(self, "_on_map_open_requested"))
|
|
gameMenuScreen.connect("new_game_requested", Callable(self, "_on_start_game_pressed"))
|
|
gameMenuScreen.visible = false
|
|
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, showing game menu")
|
|
self.visible = false
|
|
if gameMenuScreen:
|
|
gameMenuScreen.visible = true
|
|
# self.visible = false
|
|
|
|
# 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
|
|
|
|
# Game Menu Screen Signals
|
|
func _on_shop_open_requested(options):
|
|
print("Shop requested with options:", options)
|
|
emit_signal("shop_open_requested", options)
|
|
|
|
func _on_deckmanager_open_requested(options):
|
|
print("Deck Manager requested with options:", options)
|
|
emit_signal("deckmanager_open_requested", options)
|
|
|
|
func _on_map_open_requested(options):
|
|
print("Map requested with options:", options)
|
|
emit_signal("map_open_requested", options)
|
|
|
|
func _on_start_game_pressed(options):
|
|
print("Starting game with options:", options)
|
|
|
|
# Find the ChessGame instance
|
|
# 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 with options
|
|
emit_signal("new_game_requested", options)
|
|
|
|
|
|
# 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
|
|
if gameMenuScreen:
|
|
gameMenuScreen.visible = false
|