Simple menu
This commit is contained in:
parent
d22aa7c962
commit
6797935834
19 changed files with 588 additions and 14 deletions
4
Assets/Themes/SimpleMenuText.tres
Normal file
4
Assets/Themes/SimpleMenuText.tres
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[gd_resource type="Theme" format=3 uid="uid://btgbiqdc4kf15"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
default_font_size = 49
|
||||||
4
Assets/Themes/Title.tres
Normal file
4
Assets/Themes/Title.tres
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[gd_resource type="Theme" format=3 uid="uid://cuq0xndnachqb"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
default_font_size = 71
|
||||||
BIN
Assets/main_menu/characters.png
Normal file
BIN
Assets/main_menu/characters.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
34
Assets/main_menu/characters.png.import
Normal file
34
Assets/main_menu/characters.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bexpni52h8527"
|
||||||
|
path="res://.godot/imported/characters.png-aa4b087f4ba916c3768cf8d9d020e5a0.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/main_menu/characters.png"
|
||||||
|
dest_files=["res://.godot/imported/characters.png-aa4b087f4ba916c3768cf8d9d020e5a0.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
Assets/main_menu/icon.png
Normal file
BIN
Assets/main_menu/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
34
Assets/main_menu/icon.png.import
Normal file
34
Assets/main_menu/icon.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bdb3grojgjtaq"
|
||||||
|
path="res://.godot/imported/icon.png-a1f010172d24ada42d71428b39fa8e05.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/main_menu/icon.png"
|
||||||
|
dest_files=["res://.godot/imported/icon.png-a1f010172d24ada42d71428b39fa8e05.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
Assets/main_menu/label_continue.png
Normal file
BIN
Assets/main_menu/label_continue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
34
Assets/main_menu/label_continue.png.import
Normal file
34
Assets/main_menu/label_continue.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bn0offg4w11w4"
|
||||||
|
path="res://.godot/imported/label_continue.png-73ecf71c03ce72f5729846d86d279818.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/main_menu/label_continue.png"
|
||||||
|
dest_files=["res://.godot/imported/label_continue.png-73ecf71c03ce72f5729846d86d279818.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
Assets/main_menu/label_options.png
Normal file
BIN
Assets/main_menu/label_options.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
34
Assets/main_menu/label_options.png.import
Normal file
34
Assets/main_menu/label_options.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b8khh5b1iwic1"
|
||||||
|
path="res://.godot/imported/label_options.png-19b15ef319e033f5146c10542dd5f109.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Assets/main_menu/label_options.png"
|
||||||
|
dest_files=["res://.godot/imported/label_options.png-19b15ef319e033f5146c10542dd5f109.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
6
Game.json
Normal file
6
Game.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"title": "ChessBuilder",
|
||||||
|
"developer": "Comet Studios",
|
||||||
|
"release_date": "2025-01-15"
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ const StockfishController = preload("res://Systems/FairyStockfish/StockfishClien
|
||||||
signal tile_pressed(location: String)
|
signal tile_pressed(location: String)
|
||||||
signal send_location(location: String)
|
signal send_location(location: String)
|
||||||
signal turn_changed
|
signal turn_changed
|
||||||
|
signal game_initialized
|
||||||
|
|
||||||
# Game state variables
|
# Game state variables
|
||||||
var currentPlayer: String = WHITE
|
var currentPlayer: String = WHITE
|
||||||
|
|
@ -39,6 +40,7 @@ var lightStyle = null
|
||||||
var darkStyle = null
|
var darkStyle = null
|
||||||
var highlightStyle = null
|
var highlightStyle = null
|
||||||
var cpuElo = 1500
|
var cpuElo = 1500
|
||||||
|
var is_initialized: bool = false
|
||||||
|
|
||||||
# Node references
|
# Node references
|
||||||
@onready var turnIndicator: ColorRect = $TurnIndicator
|
@onready var turnIndicator: ColorRect = $TurnIndicator
|
||||||
|
|
@ -51,6 +53,8 @@ var cpuElo = 1500
|
||||||
@onready var cardPreview: CardPreview
|
@onready var cardPreview: CardPreview
|
||||||
@onready var boardContainer: FlowContainer = $Flow
|
@onready var boardContainer: FlowContainer = $Flow
|
||||||
@onready var stateMachine: StateMachine = $StateMachine
|
@onready var stateMachine: StateMachine = $StateMachine
|
||||||
|
@onready var menuContainer = get_node_or_null("/root/Board/MenuContainer")
|
||||||
|
|
||||||
|
|
||||||
# Export parameters
|
# Export parameters
|
||||||
@export var boardXSize = 12
|
@export var boardXSize = 12
|
||||||
|
|
@ -68,31 +72,66 @@ var cpuElo = 1500
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
print("Initialize Local Stockfish")
|
print("ChessGame _ready() called")
|
||||||
# Set up the stockfish path based on OS
|
# Only set up paths and window size initially
|
||||||
if OS.get_name() == "Windows":
|
if OS.get_name() == "Windows":
|
||||||
stockfishPath = "res://Assets/ChessEngines/stockfish/stockfish.exe"
|
stockfishPath = "res://Assets/ChessEngines/stockfish/stockfish.exe"
|
||||||
else:
|
else:
|
||||||
stockfishPath = ProjectSettings.globalize_path("res://Assets/ChessEngines/Fairy-Stockfish/src/stockfish")
|
stockfishPath = ProjectSettings.globalize_path("res://Assets/ChessEngines/Fairy-Stockfish/src/stockfish")
|
||||||
|
|
||||||
add_to_group("ChessGame")
|
add_to_group("ChessGame")
|
||||||
currentFen = FEN
|
currentFen = FEN
|
||||||
DisplayServer.window_set_size(Vector2i(windowXSize, windowYSize))
|
DisplayServer.window_set_size(Vector2i(windowXSize, windowYSize))
|
||||||
|
|
||||||
|
# Set up the menu signal connection
|
||||||
|
if menuContainer:
|
||||||
|
print("Found MenuContainer, connecting signal")
|
||||||
|
if !menuContainer.is_connected("new_game_requested", Callable(self, "_on_new_game_requested")):
|
||||||
|
print("Signal Connected")
|
||||||
|
menuContainer.connect("new_game_requested", Callable(self, "_on_new_game_requested"))
|
||||||
|
else:
|
||||||
|
print("MenuContainer not found, will initialize game now")
|
||||||
|
call_deferred("initialize_game_system")
|
||||||
|
turnIndicator.visible = false
|
||||||
|
|
||||||
|
func _on_new_game_requested():
|
||||||
|
print("ChessGame received new_game_requested signal ", is_initialized)
|
||||||
|
turnIndicator.visible = true
|
||||||
|
if is_initialized:
|
||||||
|
resetBoard()
|
||||||
|
else:
|
||||||
|
initialize_game_system()
|
||||||
|
|
||||||
|
func initialize_game_system():
|
||||||
|
print("Initializing game system")
|
||||||
|
# Set up basic styles first
|
||||||
|
setupStyles()
|
||||||
|
|
||||||
# Initialize the game components
|
# Initialize the game components
|
||||||
initializeGame()
|
initializeGame()
|
||||||
initializeTiles()
|
initializeTiles()
|
||||||
# Start the state machine
|
|
||||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
|
||||||
# Initialize Stockfish controller
|
# Initialize Stockfish controller
|
||||||
stockfishController = StockfishController.new()
|
stockfishController = StockfishController.new()
|
||||||
add_child(stockfishController)
|
add_child(stockfishController)
|
||||||
stockfishController.connect_to_engine(stockfishPath, self)
|
stockfishController.connect_to_engine(stockfishPath, self)
|
||||||
# if stockfishController.connect_to_engine(stockfishPath):
|
|
||||||
# stockfishController.limit_strength_to(cpuElo)
|
# Start the state machine
|
||||||
|
if stateMachine:
|
||||||
|
stateMachine.start()
|
||||||
|
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||||
|
|
||||||
|
# Mark as initialized
|
||||||
|
is_initialized = true
|
||||||
|
|
||||||
|
# Emit signal that game is initialized
|
||||||
|
emit_signal("game_initialized")
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
# Clean up the Stockfish controller when exiting
|
# Clean up the Stockfish controller when exiting
|
||||||
stockfishController.disconnect_engine()
|
if stockfishController:
|
||||||
|
stockfishController.disconnect_engine()
|
||||||
|
|
||||||
|
|
||||||
func initializeGame() -> void:
|
func initializeGame() -> void:
|
||||||
|
|
@ -242,7 +281,7 @@ func createBoard() -> void:
|
||||||
var numberX = 0
|
var numberX = 0
|
||||||
var numberY = 0
|
var numberY = 0
|
||||||
var isWhite = true
|
var isWhite = true
|
||||||
|
print("CREATING BOARD X " + str(boardXSize) + " Y " + str(boardYSize))
|
||||||
while numberY != boardYSize:
|
while numberY != boardYSize:
|
||||||
boardContainer.size.y += tileYSize + 5
|
boardContainer.size.y += tileYSize + 5
|
||||||
boardContainer.size.x += tileXSize + 5
|
boardContainer.size.x += tileXSize + 5
|
||||||
|
|
@ -261,7 +300,7 @@ func createTile(x: int, y: int, isWhite: bool) -> void:
|
||||||
var tile = PieceContainer.new(str(x) + "-" + str(y))
|
var tile = PieceContainer.new(str(x) + "-" + str(y))
|
||||||
tile.set_custom_minimum_size(Vector2(tileXSize, tileYSize))
|
tile.set_custom_minimum_size(Vector2(tileXSize, tileYSize))
|
||||||
tile.add_theme_stylebox_override("normal", lightStyle if isWhite else darkStyle)
|
tile.add_theme_stylebox_override("normal", lightStyle if isWhite else darkStyle)
|
||||||
|
print(" Create Tile " + str(x) + "-" + str(y) )
|
||||||
tile.set_name(str(x) + "-" + str(y))
|
tile.set_name(str(x) + "-" + str(y))
|
||||||
# tile.pressed.connect(func(): handleTileSelection(tile.name))
|
# tile.pressed.connect(func(): handleTileSelection(tile.name))
|
||||||
tile.pressed.connect(func():
|
tile.pressed.connect(func():
|
||||||
|
|
@ -327,6 +366,7 @@ func setupTilesFromFEN() -> void:
|
||||||
x += 1
|
x += 1
|
||||||
|
|
||||||
func placePiece(position: String, pieceName: String, color: int) -> void:
|
func placePiece(position: String, pieceName: String, color: int) -> void:
|
||||||
|
print("Placing Piece")
|
||||||
var piece = summonPiece(pieceName, color)
|
var piece = summonPiece(pieceName, color)
|
||||||
var container = boardContainer.get_node(position) as PieceContainer
|
var container = boardContainer.get_node(position) as PieceContainer
|
||||||
await container.set_piece(piece, false)
|
await container.set_piece(piece, false)
|
||||||
|
|
@ -533,7 +573,8 @@ func clearSelection() :
|
||||||
# Clear the current selection
|
# Clear the current selection
|
||||||
resetHighlights()
|
resetHighlights()
|
||||||
selectedNode = ""
|
selectedNode = ""
|
||||||
cardPreview.hide_preview()
|
if cardPreview:
|
||||||
|
cardPreview.hide_preview()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -830,4 +871,3 @@ func updateHalfMoveClock(fromIdx: int, toIdx: int) -> void:
|
||||||
halfMoveClock = 0
|
halfMoveClock = 0
|
||||||
else:
|
else:
|
||||||
halfMoveClock += 1
|
halfMoveClock += 1
|
||||||
|
|
||||||
|
|
|
||||||
64
Systems/Game/Game.gd
Normal file
64
Systems/Game/Game.gd
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
class_name Game extends Node
|
||||||
|
|
||||||
|
# This script can be attached to your main Game node that contains both
|
||||||
|
# the menu and the chess game components
|
||||||
|
|
||||||
|
@onready var menuContainer = $MenuContainer
|
||||||
|
@onready var chessGame = $ChessGame
|
||||||
|
@onready var stateMachine = $StateMachine
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Show menu on startup
|
||||||
|
if menuContainer:
|
||||||
|
menuContainer.visible = true
|
||||||
|
|
||||||
|
# Hide chess game initially
|
||||||
|
if chessGame:
|
||||||
|
chessGame.visible = false
|
||||||
|
|
||||||
|
# Connect menu signals
|
||||||
|
if menuContainer and menuContainer.has_signal("new_game_requested"):
|
||||||
|
menuContainer.connect("new_game_requested", Callable(self, "_on_new_game_started"))
|
||||||
|
|
||||||
|
func _on_new_game_started():
|
||||||
|
print("Starting new game...")
|
||||||
|
|
||||||
|
# Show chess game
|
||||||
|
if chessGame:
|
||||||
|
chessGame.visible = true
|
||||||
|
|
||||||
|
# You can add additional game initialization logic here if needed
|
||||||
|
# For example, configuring game options based on menu selections
|
||||||
|
|
||||||
|
# Ensure the chess game is properly initialized
|
||||||
|
if !chessGame.is_inside_tree():
|
||||||
|
await chessGame.ready
|
||||||
|
|
||||||
|
# Start game logic
|
||||||
|
_start_game_logic()
|
||||||
|
|
||||||
|
func _start_game_logic():
|
||||||
|
# If StateMachine is already initialized in the Chess game, this may not be needed
|
||||||
|
if stateMachine and stateMachine.has_method("transitionToNextState"):
|
||||||
|
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||||
|
|
||||||
|
# Add any additional game start logic here
|
||||||
|
|
||||||
|
# If you need to open a specific scene or create nodes dynamically:
|
||||||
|
# var chess_scene = load("res://Scenes/ChessGame.tscn").instantiate()
|
||||||
|
# add_child(chess_scene)
|
||||||
|
|
||||||
|
# Handle escape key to show menu during game
|
||||||
|
func _unhandled_input(event):
|
||||||
|
if event is InputEventKey:
|
||||||
|
if event.pressed and event.keycode == KEY_ESCAPE:
|
||||||
|
_toggle_menu()
|
||||||
|
|
||||||
|
func _toggle_menu():
|
||||||
|
if menuContainer:
|
||||||
|
menuContainer.visible = !menuContainer.visible
|
||||||
|
|
||||||
|
# Optional: Pause game when menu is visible
|
||||||
|
if menuContainer.visible and chessGame:
|
||||||
|
# You might want to pause the game or disable input
|
||||||
|
pass
|
||||||
119
Systems/Game/Menu/MenuContainer.gd
Normal file
119
Systems/Game/Menu/MenuContainer.gd
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
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
|
||||||
39
Systems/Game/Menu/MenuOption.gd
Normal file
39
Systems/Game/Menu/MenuOption.gd
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
extends TextureRect
|
||||||
|
class_name MenuOption
|
||||||
|
|
||||||
|
signal pressed
|
||||||
|
|
||||||
|
# Original modulate to return to after hover
|
||||||
|
var _original_modulate: Color
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Make this texture rect clickable
|
||||||
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
|
||||||
|
# Save original modulate color
|
||||||
|
_original_modulate = modulate
|
||||||
|
|
||||||
|
# Connect the gui_input signal to our own handler
|
||||||
|
connect("gui_input", Callable(self, "_on_gui_input"))
|
||||||
|
|
||||||
|
# Connect hover signals for better user experience
|
||||||
|
connect("mouse_entered", Callable(self, "_on_mouse_entered"))
|
||||||
|
connect("mouse_exited", Callable(self, "_on_mouse_exited"))
|
||||||
|
|
||||||
|
func _on_gui_input(event):
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||||
|
emit_signal("pressed")
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
|
func _on_mouse_entered():
|
||||||
|
# Change appearance when mouse hovers
|
||||||
|
modulate = Color(1.2, 1.2, 0.8) # Slight yellowish tint and brightening
|
||||||
|
|
||||||
|
# Optional: Add a hover sound effect
|
||||||
|
# if has_node("/root/SoundManager"):
|
||||||
|
# get_node("/root/SoundManager").play_hover_sound()
|
||||||
|
|
||||||
|
func _on_mouse_exited():
|
||||||
|
# Restore original appearance
|
||||||
|
modulate = _original_modulate
|
||||||
50
Systems/Game/Menu/MenuTextOption.gd
Normal file
50
Systems/Game/Menu/MenuTextOption.gd
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
extends RichTextLabel
|
||||||
|
class_name MenuTextOption
|
||||||
|
|
||||||
|
signal pressed
|
||||||
|
|
||||||
|
# Style properties
|
||||||
|
var normal_color: Color = Color(1, 1, 1, 1) # White
|
||||||
|
var hover_color: Color = Color(1, 1, 0, 1) # Yellow
|
||||||
|
var font_size: int = 24
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Make this label clickable
|
||||||
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
|
||||||
|
# Set up base styling
|
||||||
|
add_theme_font_size_override("normal_font_size", font_size)
|
||||||
|
add_theme_color_override("default_color", normal_color)
|
||||||
|
|
||||||
|
# Make text bold
|
||||||
|
bbcode_enabled = true
|
||||||
|
text = "[b]" + text + "[/b]"
|
||||||
|
|
||||||
|
# Connect the gui_input signal to our own handler
|
||||||
|
connect("gui_input", Callable(self, "_on_gui_input"))
|
||||||
|
|
||||||
|
# Connect hover signals for better user experience
|
||||||
|
connect("mouse_entered", Callable(self, "_on_mouse_entered"))
|
||||||
|
connect("mouse_exited", Callable(self, "_on_mouse_exited"))
|
||||||
|
|
||||||
|
func _on_gui_input(event):
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||||
|
emit_signal("pressed")
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
|
func _on_mouse_entered():
|
||||||
|
# Change appearance when mouse hovers
|
||||||
|
add_theme_color_override("default_color", hover_color)
|
||||||
|
|
||||||
|
# Scale up slightly on hover (optional)
|
||||||
|
var tween = create_tween()
|
||||||
|
tween.tween_property(self, "scale", Vector2(1.05, 1.05), 0.1)
|
||||||
|
|
||||||
|
func _on_mouse_exited():
|
||||||
|
# Restore original appearance
|
||||||
|
add_theme_color_override("default_color", normal_color)
|
||||||
|
|
||||||
|
# Scale back to normal (optional)
|
||||||
|
var tween = create_tween()
|
||||||
|
tween.tween_property(self, "scale", Vector2(1.0, 1.0), 0.1)
|
||||||
|
|
@ -6,4 +6,4 @@ func enter(_previous: String, _data := {}) -> void:
|
||||||
game.deckManager.drawCard()
|
game.deckManager.drawCard()
|
||||||
finished.emit(Constants.PERSISTENT_EFFECTS)
|
finished.emit(Constants.PERSISTENT_EFFECTS)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ var previouseState = null
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
print("Ready Statemachine")
|
||||||
|
|
||||||
|
func start() -> void:
|
||||||
for stateNode: ChessGameState in find_children("*", "ChessGameState"):
|
for stateNode: ChessGameState in find_children("*", "ChessGameState"):
|
||||||
stateNode.game = owner
|
stateNode.game = owner
|
||||||
stateNode.finished.connect(transitionToNextState)
|
stateNode.finished.connect(transitionToNextState)
|
||||||
|
|
@ -19,7 +22,6 @@ func _ready() -> void:
|
||||||
await owner.ready
|
await owner.ready
|
||||||
state.enter("")
|
state.enter("")
|
||||||
|
|
||||||
|
|
||||||
func unhandledInput(event: InputEvent) -> void:
|
func unhandledInput(event: InputEvent) -> void:
|
||||||
# print("StateMachine received input:", event)
|
# print("StateMachine received input:", event)
|
||||||
state.handleInput(event)
|
state.handleInput(event)
|
||||||
|
|
|
||||||
112
board.tscn
112
board.tscn
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=18 format=3 uid="uid://d0qyk6v20uief"]
|
[gd_scene load_steps=26 format=3 uid="uid://d0qyk6v20uief"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Systems/Game/ChessGame.gd" id="1_fkb2r"]
|
[ext_resource type="Script" path="res://Systems/Game/ChessGame.gd" id="1_fkb2r"]
|
||||||
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/WhiteTurn.gd" id="3_276ip"]
|
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/WhiteTurn.gd" id="3_276ip"]
|
||||||
|
|
@ -17,6 +17,14 @@
|
||||||
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/CleanupPhase.gd" id="15_m58r8"]
|
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/CleanupPhase.gd" id="15_m58r8"]
|
||||||
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/RoundEnd.gd" id="16_8h5do"]
|
[ext_resource type="Script" path="res://Systems/StateMachine/GameStates/RoundEnd.gd" id="16_8h5do"]
|
||||||
[ext_resource type="Script" path="res://Systems/Game/CameraController.gd" id="17_1epdx"]
|
[ext_resource type="Script" path="res://Systems/Game/CameraController.gd" id="17_1epdx"]
|
||||||
|
[ext_resource type="Script" path="res://Systems/Game/Menu/MenuContainer.gd" id="18_c1y73"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bn0offg4w11w4" path="res://Assets/main_menu/label_continue.png" id="18_yr4pt"]
|
||||||
|
[ext_resource type="Theme" uid="uid://cuq0xndnachqb" path="res://Assets/Themes/Title.tres" id="19_enj45"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b8khh5b1iwic1" path="res://Assets/main_menu/label_options.png" id="20_necaf"]
|
||||||
|
[ext_resource type="Script" path="res://Systems/Game/Menu/MenuOption.gd" id="20_qqo7d"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bexpni52h8527" path="res://Assets/main_menu/characters.png" id="23_vmvai"]
|
||||||
|
[ext_resource type="Theme" uid="uid://btgbiqdc4kf15" path="res://Assets/Themes/SimpleMenuText.tres" id="24_4y4dr"]
|
||||||
|
[ext_resource type="Script" path="res://Systems/Game/Menu/MenuTextOption.gd" id="24_aslgu"]
|
||||||
|
|
||||||
[node name="Board" type="Control"]
|
[node name="Board" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|
@ -155,3 +163,105 @@ game = NodePath("../..")
|
||||||
|
|
||||||
[node name="CameraController" type="Node2D" parent="."]
|
[node name="CameraController" type="Node2D" parent="."]
|
||||||
script = ExtResource("17_1epdx")
|
script = ExtResource("17_1epdx")
|
||||||
|
|
||||||
|
[node name="MenuContainer" type="MarginContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_constants/margin_left = 120
|
||||||
|
theme_override_constants/margin_top = 80
|
||||||
|
theme_override_constants/margin_right = 120
|
||||||
|
theme_override_constants/margin_bottom = 80
|
||||||
|
script = ExtResource("18_c1y73")
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="MenuContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="MenuContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TitleText" type="RichTextLabel" parent="MenuContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
clip_contents = false
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_stretch_ratio = 0.0
|
||||||
|
theme = ExtResource("19_enj45")
|
||||||
|
text = "ChessBuilder"
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
tab_size = 1
|
||||||
|
shortcut_keys_enabled = false
|
||||||
|
deselect_on_focus_loss_enabled = false
|
||||||
|
drag_and_drop_selection_enabled = false
|
||||||
|
script = ExtResource("24_aslgu")
|
||||||
|
|
||||||
|
[node name="MenuOptions" type="VBoxContainer" parent="MenuContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
theme_override_constants/separation = 30
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="Continue" type="TextureRect" parent="MenuContainer/HBoxContainer/VBoxContainer/MenuOptions"]
|
||||||
|
layout_mode = 2
|
||||||
|
texture = ExtResource("18_yr4pt")
|
||||||
|
stretch_mode = 2
|
||||||
|
script = ExtResource("20_qqo7d")
|
||||||
|
|
||||||
|
[node name="NewGameText" type="RichTextLabel" parent="MenuContainer/HBoxContainer/VBoxContainer/MenuOptions"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme = ExtResource("24_4y4dr")
|
||||||
|
text = "New Game"
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
tab_size = 1
|
||||||
|
shortcut_keys_enabled = false
|
||||||
|
deselect_on_focus_loss_enabled = false
|
||||||
|
drag_and_drop_selection_enabled = false
|
||||||
|
script = ExtResource("24_aslgu")
|
||||||
|
|
||||||
|
[node name="Options" type="TextureRect" parent="MenuContainer/HBoxContainer/VBoxContainer/MenuOptions"]
|
||||||
|
layout_mode = 2
|
||||||
|
texture = ExtResource("20_necaf")
|
||||||
|
stretch_mode = 2
|
||||||
|
script = ExtResource("20_qqo7d")
|
||||||
|
|
||||||
|
[node name="VersionText" type="RichTextLabel" parent="MenuContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
clip_contents = false
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_stretch_ratio = 0.0
|
||||||
|
theme = ExtResource("24_4y4dr")
|
||||||
|
text = "v."
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
tab_size = 1
|
||||||
|
shortcut_keys_enabled = false
|
||||||
|
deselect_on_focus_loss_enabled = false
|
||||||
|
drag_and_drop_selection_enabled = false
|
||||||
|
script = ExtResource("24_aslgu")
|
||||||
|
|
||||||
|
[node name="DeveloperText" type="RichTextLabel" parent="MenuContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
clip_contents = false
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_stretch_ratio = 0.0
|
||||||
|
theme = ExtResource("24_4y4dr")
|
||||||
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
tab_size = 1
|
||||||
|
shortcut_keys_enabled = false
|
||||||
|
deselect_on_focus_loss_enabled = false
|
||||||
|
drag_and_drop_selection_enabled = false
|
||||||
|
script = ExtResource("24_aslgu")
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="MenuContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="GameImage" type="TextureRect" parent="MenuContainer/HBoxContainer/CenterContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
texture = ExtResource("23_vmvai")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue