204 lines
7 KiB
GDScript
204 lines
7 KiB
GDScript
extends Control
|
|
class_name MenuContainer
|
|
|
|
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)
|
|
signal shop_closed
|
|
signal card_purchased(card, price)
|
|
@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 deckManagerScreen = get_node("/root/Board/DeckManagerScreen")
|
|
@onready var mapScreen = get_node("/root/Board/MapScreen")
|
|
@onready var stateMachine = get_node("/root/Board/StateMachine")
|
|
@onready var shopScreen = get_node("/root/Board/ShopScreen")
|
|
|
|
var player_gold = 1000
|
|
|
|
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
|
|
|
|
if deckManagerScreen:
|
|
deckManagerScreen.connect("back_pressed", Callable(self, "_on_deck_manager_back_pressed"))
|
|
deckManagerScreen.visible = false
|
|
|
|
if mapScreen:
|
|
mapScreen.connect("back_pressed", Callable(self, "_on_map_back_pressed"))
|
|
mapScreen.connect("node_selected", Callable(self, "_on_map_node_selected"))
|
|
mapScreen.visible = false
|
|
|
|
if shopScreen:
|
|
shopScreen.connect("back_pressed", Callable(self, "_on_shop_back_pressed"))
|
|
shopScreen.connect("card_purchased", Callable(self, "_on_shop_card_purchased"))
|
|
shopScreen.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)
|
|
if gameMenuScreen:
|
|
gameMenuScreen.visible = false
|
|
|
|
if options == null:
|
|
options = {}
|
|
options["gold"] = player_gold
|
|
if shopScreen:
|
|
shopScreen.visible = true
|
|
shopScreen.initialize(options)
|
|
emit_signal("shop_open_requested", options)
|
|
|
|
func _on_shop_back_pressed():
|
|
if shopScreen:
|
|
shopScreen.visible = false
|
|
player_gold = shopScreen.player_gold
|
|
|
|
# Show game menu again
|
|
if gameMenuScreen:
|
|
gameMenuScreen.visible = true
|
|
|
|
# Emit signal that shop was closed
|
|
emit_signal("shop_closed")
|
|
|
|
func _on_shop_card_purchased(card, price):
|
|
player_gold -= price
|
|
# Forward the signal
|
|
emit_signal("card_purchased", card, price)
|
|
|
|
# Add the card to the player's bank
|
|
var board = get_node_or_null("/root/Board") as ChessGame
|
|
if board and "deckManager" in board:
|
|
var deck_manager = board.deckManager
|
|
deck_manager.bank.append(card)
|
|
print("Added purchased card to bank:", card.cardName)
|
|
|
|
func _on_deckmanager_open_requested(options):
|
|
print("Deck Manager requested with options:", options)
|
|
|
|
# Hide game menu
|
|
gameMenuScreen.visible = false
|
|
|
|
# Show and initialize deck manager
|
|
if deckManagerScreen:
|
|
deckManagerScreen.visible = true
|
|
deckManagerScreen.initialize(options)
|
|
|
|
# Also emit signal for other systems that might need to know
|
|
emit_signal("deckmanager_open_requested", options)
|
|
|
|
func _on_deck_manager_back_pressed():
|
|
# Return to game menu screen
|
|
deckManagerScreen.visible = false
|
|
gameMenuScreen.visible = true
|
|
|
|
|
|
func _on_map_open_requested(options):
|
|
print("Map requested with options:", options)
|
|
gameMenuScreen.visible = false
|
|
if mapScreen:
|
|
mapScreen.visible = true
|
|
emit_signal("map_open_requested", options)
|
|
|
|
func _on_start_game_pressed(options):
|
|
print("Starting game with options:", options)
|
|
|
|
emit_signal("new_game_requested", options)
|
|
|
|
func _on_map_back_pressed():
|
|
mapScreen.visible = false
|
|
gameMenuScreen.visible = true
|
|
|
|
# Map node selection
|
|
func _on_map_node_selected(node_data):
|
|
print("Selected map node: ", node_data)
|
|
# Implement logic for map node selection
|
|
# For example, start a battle based on the node type
|
|
|
|
# Public method to show the menu
|
|
func show_menu():
|
|
self.visible = true
|
|
if gameMenuScreen:
|
|
gameMenuScreen.visible = false
|
|
if deckManagerScreen:
|
|
deckManagerScreen.visible = false
|
|
if mapScreen:
|
|
mapScreen.visible = false
|