online multiplayer chess game (note server currently down)
last move indicators
| -rw-r--r-- | Square.gd | 10 | ||||
| -rw-r--r-- | Square.tscn | 31 | ||||
| -rw-r--r-- | project.godot | 2 | ||||
| -rw-r--r-- | ui/board/Board.gd | 20 |
4 files changed, 47 insertions, 16 deletions
@@ -1,13 +1,19 @@ -extends ColorRect +extends MarginContainer class_name BackgroundSquare signal clicked signal right_clicked -onready var circle := $CircleHolder/Circle +var color: Color + +onready var circle: TextureRect = $BackgroundSquare/CircleHolder/Circle +onready var move_indicator: ColorRect = $MoveIndicator +onready var b_square: ColorRect = $BackgroundSquare func _ready() -> void: + move_indicator.color = Globals.grid.last_move_indicator_color + b_square.color = color circle.rect_min_size = Globals.grid.piece_size / 4 circle.material.set_shader_param("color", Globals.grid.overlay_color) circle.visible = false diff --git a/Square.tscn b/Square.tscn index de3771e..68bff26 100644 --- a/Square.tscn +++ b/Square.tscn @@ -26,24 +26,33 @@ shader = SubResource( 2 ) shader_param/amt = 1.0 shader_param/color = Color( 0.431373, 0.584314, 0.388235, 0.639216 ) -[node name="Square" type="ColorRect"] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_right = -1180.0 -margin_bottom = -780.0 +[node name="MarginContainer" type="MarginContainer"] +margin_right = 40.0 +margin_bottom = 40.0 script = ExtResource( 1 ) -[node name="CircleHolder" type="CenterContainer" parent="."] +[node name="BackgroundSquare" type="ColorRect" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 +mouse_filter = 2 + +[node name="CircleHolder" type="CenterContainer" parent="BackgroundSquare"] anchor_right = 1.0 anchor_bottom = 1.0 mouse_filter = 2 -[node name="Circle" type="TextureRect" parent="CircleHolder"] +[node name="Circle" type="TextureRect" parent="BackgroundSquare/CircleHolder"] material = SubResource( 3 ) -margin_left = 121.0 -margin_top = 10.0 -margin_right = 121.0 -margin_bottom = 10.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = 20.0 +margin_bottom = 20.0 mouse_filter = 2 texture = ExtResource( 2 ) expand = true + +[node name="MoveIndicator" type="ColorRect" parent="."] +visible = false +margin_right = 40.0 +margin_bottom = 40.0 +mouse_filter = 2 diff --git a/project.godot b/project.godot index 3359564..774a1af 100644 --- a/project.godot +++ b/project.godot @@ -9,7 +9,7 @@ config_version=4 _global_script_classes=[ { -"base": "ColorRect", +"base": "MarginContainer", "class": "BackgroundSquare", "language": "GDScript", "path": "res://Square.gd" diff --git a/ui/board/Board.gd b/ui/board/Board.gd index eb71113..04ea5f2 100644 --- a/ui/board/Board.gd +++ b/ui/board/Board.gd @@ -10,9 +10,12 @@ signal clear_pgn signal load_pgn(moves) signal remove_last +var move_indicators: PoolIntArray = [] + const piece_size := Vector2(80, 80) export(Color) var overlay_color := Color(0.078431, 0.333333, 0.117647, 0.498039) +export(Color) var last_move_indicator_color := Color(0.74902, 0.662745, 0.223529, 0.498039) export(Color) var clockrunning_color := Color(0.219608, 0.278431, 0.133333) export(Color) var clockrunninglow := Color(0.47451, 0.172549, 0.164706) export(Color) var clocklow := Color(0.313726, 0.156863, 0.14902) @@ -72,7 +75,7 @@ func init_board() -> void: # create the board var square := Square.instance() # create a square square.name = alg square.hint_tooltip = alg - square.color = Globals.board_color1 if Chess.square_color(alg) == "light" else Globals.board_color2 # set the color + square.color = (Globals.board_color1 if Chess.square_color(alg) == "light" else Globals.board_color2) # set the color background.add_child(square) # add the square to the background square.connect("clicked", self, "square_clicked", [alg]) # connect the clicked event background_array[i] = square # add the square to the background array @@ -283,7 +286,7 @@ func load_pgn(pgn: String) -> void: emit_signal("clear_pgn") var movs: PoolStringArray = Pgn.parse(pgn).moves emit_signal("load_pgn", movs) - check_game_over() + Events.emit_signal("turn_over") func undo(two: bool = false) -> void: @@ -295,10 +298,12 @@ func undo(two: bool = false) -> void: clear_pieces() clear_circles() create_pieces() + Events.emit_signal("turn_over") func _on_turn_over(): check_game_over() + create_last_move_indicators() func check_game_over(): @@ -313,3 +318,14 @@ func check_game_over(): draw("insufficient material") elif chess.in_threefold_repetition(): draw("threefold repetition") + + +func create_last_move_indicators(): + for i in move_indicators: + background_array[i].move_indicator.hide() + if !chess.__history: + return + var m: Dictionary = chess.__history[-1].move + background_array[m.from].move_indicator.show() + background_array[m.to].move_indicator.show() + move_indicators = [m.from, m.to] |