online multiplayer chess game (note server currently down)
local multiplayer
bendn 2022-08-26
parent 4a0e9b2 · commit 5e0fa24
-rw-r--r--Square.gd18
-rw-r--r--networking/PacketHandler.gd15
-rw-r--r--piece/Piece.gd30
-rw-r--r--ui/board/Board.gd39
-rw-r--r--ui/board/Game.gd6
-rw-r--r--ui/board/Game.tscn2
-rw-r--r--ui/chat/Chat.gd2
-rw-r--r--ui/menus/LocalMultiplayer.gd43
-rw-r--r--ui/menus/LocalMultiplayer.tscn35
-rw-r--r--ui/menus/lobby/GameConfig.gd20
-rw-r--r--ui/menus/lobby/Lobby.gd20
-rw-r--r--ui/menus/lobby/Lobby.tscn34
-rw-r--r--ui/menus/sidebarright/SidebarRight.tscn6
-rw-r--r--ui/menus/sidebarright/UserPanel.gd5
-rw-r--r--ui/menus/sidebarright/UserPanel.tscn2
-rw-r--r--ui/menus/sidebarright/buttonbar.gd7
-rw-r--r--ui/menus/sidebarright/drawbutton.gd2
-rw-r--r--ui/menus/sidebarright/resignbutton.gd4
-rw-r--r--ui/menus/sidebarright/undobutton.gd6
-rw-r--r--ui/menus/startmenu/StartMenu.tscn20
20 files changed, 230 insertions, 86 deletions
diff --git a/Square.gd b/Square.gd
index f0edd80..754ec0a 100644
--- a/Square.gd
+++ b/Square.gd
@@ -12,20 +12,22 @@ onready var circle: TextureRect = $Circle
onready var move_indicator: ColorRect = $MoveIndicator
onready var premove_indicator: ColorRect = $PremoveIndicator
+var b
+
func _ready() -> void:
- move_indicator.color = Globals.grid.last_move_indicator_color
- premove_indicator.color = Globals.grid.premove_color
- mouse_default_cursor_shape = CURSOR_FORBIDDEN if Globals.spectating else CURSOR_POINTING_HAND
+ move_indicator.color = b.last_move_indicator_color
+ premove_indicator.color = b.premove_color
+ mouse_default_cursor_shape = CURSOR_FORBIDDEN if b.spectating else CURSOR_POINTING_HAND
Events.connect("turn_over", self, "clear_move_indicators")
func check_piece_above() -> bool:
- return is_instance_valid(Globals.grid.get_piece(square))
+ return is_instance_valid(b.get_piece(square))
func _gui_input(event: InputEvent):
- if !Globals.spectating and event is InputEventMouseButton and event.pressed:
+ if !b.spectating and event is InputEventMouseButton and event.pressed:
emit_signal("clicked" if event.button_index == BUTTON_LEFT else "right_clicked")
get_tree().set_input_as_handled()
@@ -36,7 +38,7 @@ func _focus_exited():
func clear_move_indicators():
if check_piece_above():
- Globals.grid.get_piece(square).background.hide()
+ b.get_piece(square).background.hide()
for m in move_indicators:
if is_instance_valid(m):
m.hide()
@@ -45,7 +47,6 @@ func clear_move_indicators():
func show_move_indicators():
clear_move_indicators()
- var b = Globals.grid
var p = b.get_piece(square)
p.background.show()
var movs = b.chess.__generate_moves({"square": square})
@@ -57,10 +58,9 @@ func show_move_indicators():
func show_premove_indicators():
clear_move_indicators()
- var b = Globals.grid
var p = b.get_piece(square)
p.background.show()
- var movs = b.chess.piece_moves(square, p.type, Globals.team, false)
+ var movs = b.chess.piece_moves(square, p.type, b.team, false)
for m in movs:
var _p = b.board[m.to]
var i = b.background_array[m.to].circle
diff --git a/networking/PacketHandler.gd b/networking/PacketHandler.gd
index 47a122e..a3f71d2 100644
--- a/networking/PacketHandler.gd
+++ b/networking/PacketHandler.gd
@@ -171,16 +171,21 @@ func go_back(error: String, isok: bool) -> void:
func _start_game() -> void:
set_hosting(false)
- var board: Control = load("res://ui/board/Game.tscn").instance()
- get_tree().get_root().add_child(board)
+ Log.debug("Created board")
+ var ui: Control = load("res://ui/board/Game.tscn").instance()
+ var b: Grid = ui.get_board()
+ b.team = Globals.team
+ Log.debug("Set board team to %s" % Utils.expand_color(b.team))
+ get_tree().get_root().add_child(ui)
+ b.spectating = Globals.spectating
lobby.toggle(false)
emit_signal("start_game")
lobby.set_buttons(false)
SoundFx.play("Victory")
- yield(get_tree(), "idle_frame")
- Log.debug("Flipping board" if Globals.team == Chess.BLACK else "Not flipping board")
+
if Globals.team == Chess.BLACK:
- board.get_board().flip_board()
+ yield(get_tree(), "idle_frame")
+ b.flip_board()
func rejoin(tries := 5, interval := 2) -> int: # on disconnect, try to rejoin
diff --git a/piece/Piece.gd b/piece/Piece.gd
index 3196b7c..92fee38 100644
--- a/piece/Piece.gd
+++ b/piece/Piece.gd
@@ -15,18 +15,20 @@ onready var rotate = $RotatePlayer
# for pawn promotion
signal promotion_decided(promote_to)
+var b
+
func size() -> void: # size the control
- rect_size = Globals.grid.piece_size
+ rect_size = b.piece_size
rect_pivot_offset = rect_size / 2
- rect_position = Chess.algebraic2vec(position) * Globals.grid.piece_size
- sprite.flip_v = Globals.grid.flipped
- sprite.flip_h = Globals.grid.flipped
+ rect_position = Chess.algebraic2vec(position) * b.piece_size
+ sprite.flip_v = b.flipped
+ sprite.flip_h = b.flipped
func _ready():
load_texture()
- background.color = Globals.grid.overlay_color
+ background.color = b.overlay_color
if type == Chess.KING:
Events.connect("turn_over", self, "check_in_check")
@@ -36,14 +38,14 @@ func _ready():
func turn_over():
- if Globals.grid.chess.turn == Globals.team:
- background.color = Globals.grid.overlay_color
+ if b.is_my_turn():
+ background.color = b.overlay_color
else:
- background.color = Globals.grid.premove_color
+ background.color = b.premove_color
func check_in_check():
- check.visible = Globals.grid.chess.__king_attacked(color)
+ check.visible = b.chess.__king_attacked(color)
func _pressed(p: String) -> void:
@@ -72,7 +74,7 @@ func open_promotion_previews(darken: ColorRect):
newsprite.connect("pressed", self, "_pressed", [p])
previews.add_child(newsprite)
- var rect = Rect2(rect_global_position, Vector2(Globals.grid.piece_size.x, Globals.grid.piece_size.y * 4))
+ var rect = Rect2(rect_global_position, Vector2(b.piece_size.x, b.piece_size.y * 4))
popup.popup(rect)
yield(self, "promotion_decided")
darken.hide()
@@ -93,8 +95,8 @@ func move(to: String, synchronized := false) -> Piece:
yield(get_tree(), "idle_frame")
name = "%s-%s" % [type, to]
- Globals.grid.set_piece(position, null)
- Globals.grid.set_piece(to, self)
+ b.set_piece(position, null)
+ b.set_piece(to, self)
var go_to = Chess.algebraic2vec(to)
var signresult := int(sign(Chess.algebraic2vec(position).x - go_to.x))
@@ -105,13 +107,13 @@ func move(to: String, synchronized := false) -> Piece:
anim.play("Move")
position = to
var tween = create_tween().set_trans(Tween.TRANS_BACK)
- tween.tween_property(self, @"rect_position", go_to * Globals.grid.piece_size, 0.3)
+ tween.tween_property(self, @"rect_position", go_to * b.piece_size, 0.3)
if synchronized:
yield(tween, "finished")
return self
func took() -> void:
- Globals.grid.set_piece(position, null)
+ b.set_piece(position, null)
frame.hide()
anim.play("Took")
diff --git a/ui/board/Board.gd b/ui/board/Board.gd
index 3a3c336..e1b94d4 100644
--- a/ui/board/Board.gd
+++ b/ui/board/Board.gd
@@ -52,6 +52,9 @@ onready var pieces := $Pieces
onready var arrows := $"%Arrows"
var chess := Chess.new()
+var local := false
+var spectating := false
+var team: String
func _init():
@@ -65,7 +68,7 @@ func _exit_tree():
func _process(_delta):
rect_rotation = rot
foreground.rect_rotation = rot
- if Input.is_action_just_pressed("debug"):
+ if Input.is_action_just_pressed("debug") and Debug.debug:
print(chess.ascii())
@@ -96,6 +99,9 @@ func set_take_move_circle_color(
func _ready():
+ if !team:
+ team = "w"
+ local = true
set_take_move_circle_color()
_resized()
Events.connect("turn_over", self, "_on_turn_over")
@@ -103,6 +109,7 @@ func _ready():
create_pieces()
create_squares()
create_labels()
+ Log.debug("board: ready")
func resize_board():
@@ -115,6 +122,7 @@ func create_squares() -> void: # create the board
var alg := Chess.algebraic(i)
var square := Square.instance() # create a square
square.name = alg
+ square.b = self
square.square = alg
square.hint_tooltip = alg
square.color = (Globals.board_color1 if Chess.square_color(alg) == "light" else Globals.board_color2) # set the color
@@ -211,6 +219,7 @@ func create_pieces():
func make_piece(algebraic: String, piece_type: String, color := "w") -> void: # make peace
var piece := PieceScene.instance() # create a piece
piece.name = "%s-%s" % [piece_type, algebraic]
+ piece.b = self
piece.position = algebraic
piece.type = piece_type
piece.color = color
@@ -239,21 +248,26 @@ func flip_board() -> void:
rot = 0 if rot == 180 else 180
flipped = rot == 180
Log.debug(["Flipped the board, now", "flipped" if flipped else "not flipped"])
- sidebar.flip_panels()
+ if sidebar:
+ sidebar.flip_panels()
flip_pieces()
flip_labels()
+func is_my_turn() -> bool:
+ return team == chess.turn
+
+
func square_clicked(clicked_square: BackgroundSquare) -> void:
if Globals.spectating:
return
var p := get_piece(clicked_square.square)
- if chess.turn != Globals.team and is_instance_valid(last_clicked):
+ if not is_my_turn() and is_instance_valid(last_clicked):
# PREMOVE AREA
var p_sq: int = Chess.SQUARE_MAP[clicked_square.square]
- for m in chess.piece_moves(last_clicked.position, last_clicked.type, Globals.team):
+ for m in chess.piece_moves(last_clicked.position, last_clicked.type, team):
if m.to == p_sq && m.from == Chess.SQUARE_MAP[last_clicked.position]:
if "from" in premove and "to" in premove:
background_array[premove.from].premove_indicator.hide() # hide premove indicators
@@ -271,7 +285,7 @@ func square_clicked(clicked_square: BackgroundSquare) -> void:
Log.debug("Selected premove: %s" % premove)
clear_last_clicked()
return
- elif (!p or p.color != Globals.team) and is_instance_valid(last_clicked):
+ elif (!p or p.color != team) and is_instance_valid(last_clicked):
# Attempt to make the move (NORMAL MOVE AREA)
for m in chess.moves({square = last_clicked.position, verbose = true}):
if m.to == clicked_square.square && m.from == last_clicked.position:
@@ -279,8 +293,8 @@ func square_clicked(clicked_square: BackgroundSquare) -> void:
clear_last_clicked()
return
- if p and p.color == Globals.team:
- if chess.turn != Globals.team:
+ if p and p.color == team:
+ if chess.turn != team:
clicked_square.show_premove_indicators()
else:
clicked_square.show_move_indicators()
@@ -324,7 +338,7 @@ func move(san: String, send := true, create_promotion_input := true) -> void:
sound_handled = true
else: # not promotion: from **always** moves to `to`
var _p = board[move_0x88.from].move(Chess.algebraic(move_0x88.to))
- if send:
+ if send && !local:
PacketHandler.send_mov(san)
if !sound_handled:
SoundFx.play("Move")
@@ -374,10 +388,11 @@ func undo(two: bool = false) -> void:
func _on_turn_over():
- if get_parent() == get_viewport(): # for testing
- Globals.team = chess.turn
+ if local: # for testing
+ team = chess.turn
+ flip_board()
- if Globals.grid.chess.turn == Globals.team:
+ if is_my_turn():
set_take_move_circle_color()
# use the premove if possible
if premove:
@@ -405,7 +420,7 @@ func _on_turn_over():
func check_game_over():
if chess.in_checkmate():
# they won if its my turn, i won if its their turn.
- win(Globals.team if Globals.team != chess.turn else Chess.__swap_color(Globals.team), "checkmate")
+ win(team if is_my_turn() else Chess.__swap_color(team), "checkmate")
elif chess.half_moves >= 50:
draw("fifty move rule")
elif chess.in_stalemate():
diff --git a/ui/board/Game.gd b/ui/board/Game.gd
index c614e75..b46229b 100644
--- a/ui/board/Game.gd
+++ b/ui/board/Game.gd
@@ -18,8 +18,8 @@ func set_status(text: String, length := 5) -> void:
status.set_text(text, length)
-func get_board() -> Node:
- return $Holder/middle/Board
+func get_board() -> AspectRatioContainer:
+ return $Holder/middle/Board as AspectRatioContainer
func _spectate_info(info: Dictionary) -> void:
@@ -28,7 +28,7 @@ func _spectate_info(info: Dictionary) -> void:
func _on_info(info: Dictionary) -> void:
- var enemy_int := int(Globals.team == "w")
+ var enemy_int := int(Globals.grid.team == "w")
set_panel(panels[enemy_int], info.name, info.country) # enemy panel
set_panel(panels[abs(enemy_int - 1)], Creds.get("name"), Creds.get("country")) # own panel
diff --git a/ui/board/Game.tscn b/ui/board/Game.tscn
index 29dd5d6..cfc3281 100644
--- a/ui/board/Game.tscn
+++ b/ui/board/Game.tscn
@@ -56,7 +56,7 @@ margin_right = 700.0
margin_bottom = 800.0
rect_min_size = Vector2( 700, 700 )
-[node name="BackButton" type="CenterContainer" parent="Holder/middle"]
+[node name="BackButton" type="CenterContainer" parent="Holder/middle" groups=["backbutton"]]
visible = false
margin_top = 720.0
margin_right = 700.0
diff --git a/ui/chat/Chat.gd b/ui/chat/Chat.gd
index e0cec0c..be4b119 100644
--- a/ui/chat/Chat.gd
+++ b/ui/chat/Chat.gd
@@ -46,7 +46,7 @@ func add_label_with(data: Dictionary) -> void:
func send(t: String) -> void:
t = md2bb(t)
var name = Creds.get("name") if Creds.get("name") else "Anonymous"
- name += "(%s)" % ("Spectator" if Globals.spectating else Globals.team)
+ name += "(%s)" % ("Spectator" if Globals.spectating else Globals.grid.team)
if PacketHandler.is_open_connection():
PacketHandler.relay_signal({"text": t, "who": name}, PacketHandler.RELAYHEADERS.chat)
else:
diff --git a/ui/menus/LocalMultiplayer.gd b/ui/menus/LocalMultiplayer.gd
new file mode 100644
index 0000000..e124ca1
--- /dev/null
+++ b/ui/menus/LocalMultiplayer.gd
@@ -0,0 +1,43 @@
+extends Control
+
+onready var gameconfig = $"%GameConfig"
+
+var in_game := false
+
+
+func _ready():
+ gameconfig.connect("done", self, "create")
+
+
+func create(moves: PoolStringArray) -> void:
+ var ui: Control = load("res://ui/board/Game.tscn").instance()
+ var b: Grid = ui.get_board()
+ Log.debug("Set board team to %s" % Utils.expand_color(b.team))
+ get_tree().get_root().add_child(ui)
+ PacketHandler.lobby.toggle(false)
+ yield(get_tree(), "idle_frame")
+ b.load_pgn(moves.join(" "))
+ Globals.chat.hide()
+ in_game = true
+ b.team = b.chess.turn
+ if b.flipped and b.team == Chess.WHITE:
+ b.flip_board()
+ get_tree().call_group("userpanel", "hide_children")
+ get_tree().call_group("backbutton", "queue_free")
+
+
+func _pressed():
+ if gameconfig.visible:
+ create(gameconfig.moves)
+ else:
+ gameconfig.show()
+
+
+func _input(_event):
+ if Input.is_action_pressed("ui_cancel") and in_game:
+ in_game = false
+ PacketHandler.go_back("", true)
+ get_node("/root/Game").queue_free()
+ PacketHandler.lobby.toggle(true)
+ Globals.reset_vars()
+ get_parent().current_tab = get_parent().get_children().find(self)
diff --git a/ui/menus/LocalMultiplayer.tscn b/ui/menus/LocalMultiplayer.tscn
new file mode 100644
index 0000000..9aa4dd4
--- /dev/null
+++ b/ui/menus/LocalMultiplayer.tscn
@@ -0,0 +1,35 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://ui/menus/LocalMultiplayer.gd" type="Script" id=1]
+[ext_resource path="res://ui/menus/lobby/GameConfig.tscn" type="PackedScene" id=2]
+
+[sub_resource type="ButtonGroup" id=1]
+
+[node name="LocalMultiplayer" type="CenterContainer"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+script = ExtResource( 1 )
+
+[node name="V" type="VBoxContainer" parent="."]
+margin_left = 671.0
+margin_top = 373.0
+margin_right = 751.0
+margin_bottom = 427.0
+
+[node name="GameConfig" parent="V" instance=ExtResource( 2 )]
+unique_name_in_owner = true
+visible = false
+anchor_right = 0.0
+anchor_bottom = 0.0
+margin_right = 351.0
+margin_bottom = 268.0
+color_config = false
+button_group = SubResource( 1 )
+
+[node name="PlayButton" type="Button" parent="V"]
+margin_right = 80.0
+margin_bottom = 54.0
+size_flags_horizontal = 4
+text = "play"
+
+[connection signal="pressed" from="V/PlayButton" to="." method="_pressed"]
diff --git a/ui/menus/lobby/GameConfig.gd b/ui/menus/lobby/GameConfig.gd
index 5f8646c..f1ab473 100644
--- a/ui/menus/lobby/GameConfig.gd
+++ b/ui/menus/lobby/GameConfig.gd
@@ -2,12 +2,18 @@ extends TabContainer
var moves := PoolStringArray()
var color := true
-var lobby: Lobby
+
+export(bool) var color_config := true
+
+signal back
+signal done(color, moves)
export(ButtonGroup) var button_group: ButtonGroup
func _ready():
+ if not color_config:
+ $"".queue_free()
button_group.connect("pressed", self, "_button_pressed")
@@ -16,17 +22,15 @@ func _button_pressed(button: BarTextureButton) -> void:
func _on_Continue_pressed():
- PacketHandler.host_game(PacketHandler.game_code, color, moves)
+ if color_config:
+ emit_signal("done", color, moves)
+ else:
+ emit_signal("done", moves)
reset()
-func open(_lobby: Lobby):
- show()
- lobby = _lobby
-
-
func _on_Stop_pressed():
- lobby.set_buttons(true)
+ emit_signal("back")
reset()
diff --git a/ui/menus/lobby/Lobby.gd b/ui/menus/lobby/Lobby.gd
index 6c04c27..b6dd488 100644
--- a/ui/menus/lobby/Lobby.gd
+++ b/ui/menus/lobby/Lobby.gd
@@ -2,20 +2,23 @@ extends Control
class_name Lobby
onready var address: LineEdit = $"%Address"
-onready var buttons := find_node("buttons")
+onready var buttons := $"%buttons"
onready var status_ok := $"%StatusOK"
onready var status_fail := $"%StatusFail"
-onready var hostbutton = $"%HostButton"
+onready var hostbutton := $"%HostButton"
+onready var gameconfig := $"%GameConfig"
func toggle(onoff: bool) -> void:
- get_parent().visible = onoff
+ get_parent().get_parent().visible = onoff
func _ready() -> void:
PacketHandler.lobby = self
PacketHandler.connect("hosting", $"%stophost", "set_visible")
PacketHandler.connect("connection_established", self, "reset")
+ gameconfig.connect("back", self, "reset")
+ gameconfig.connect("done", self, "host")
if !Utils.internet:
set_status("no internet", false)
set_buttons(false)
@@ -26,6 +29,10 @@ func reset():
set_buttons(true)
+func host(color: bool, moves: PoolStringArray) -> void:
+ PacketHandler.host_game(PacketHandler.game_code, color, moves)
+
+
func focus():
get_parent().current_tab = get_parent().get_children().find(self)
@@ -56,10 +63,13 @@ func _on_join_pressed() -> void:
func _on_HostButton_pressed() -> void:
+ if gameconfig.visible:
+ gameconfig.hide()
+ host(gameconfig.color, gameconfig.moves)
+ return
if validate_text():
set_buttons(false)
- $Center/VBox/GameConfig.open(self)
- hostbutton.disabled = true
+ gameconfig.show()
else:
set_status("Invalid address", false)
diff --git a/ui/menus/lobby/Lobby.tscn b/ui/menus/lobby/Lobby.tscn
index 0b9049e..859f8e8 100644
--- a/ui/menus/lobby/Lobby.tscn
+++ b/ui/menus/lobby/Lobby.tscn
@@ -12,17 +12,14 @@ anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )
-[node name="Center" type="CenterContainer" parent="."]
+[node name="VBox" type="VBoxContainer" parent="."]
margin_left = 536.0
margin_top = 341.0
margin_right = 886.0
margin_bottom = 459.0
-[node name="VBox" type="VBoxContainer" parent="Center"]
-margin_right = 350.0
-margin_bottom = 118.0
-
-[node name="GameConfig" parent="Center/VBox" instance=ExtResource( 5 )]
+[node name="GameConfig" parent="VBox" instance=ExtResource( 5 )]
+unique_name_in_owner = true
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
@@ -30,7 +27,7 @@ margin_right = 727.0
margin_bottom = 450.0
button_group = SubResource( 1 )
-[node name="stophost" type="Button" parent="Center/VBox"]
+[node name="stophost" type="Button" parent="VBox"]
unique_name_in_owner = true
visible = false
margin_right = 296.0
@@ -39,11 +36,12 @@ focus_mode = 0
size_flags_horizontal = 4
text = "stop hosting"
-[node name="buttons" type="HBoxContainer" parent="Center/VBox"]
+[node name="buttons" type="HBoxContainer" parent="VBox"]
+unique_name_in_owner = true
margin_right = 350.0
margin_bottom = 54.0
-[node name="SpectateButton" type="Button" parent="Center/VBox/buttons"]
+[node name="SpectateButton" type="Button" parent="VBox/buttons"]
margin_right = 110.0
margin_bottom = 54.0
rect_min_size = Vector2( 110, 0 )
@@ -54,7 +52,7 @@ size_flags_vertical = 3
disabled = true
text = "watch"
-[node name="JoinButton" type="Button" parent="Center/VBox/buttons"]
+[node name="JoinButton" type="Button" parent="VBox/buttons"]
margin_left = 120.0
margin_right = 230.0
margin_bottom = 54.0
@@ -65,7 +63,7 @@ size_flags_horizontal = 7
disabled = true
text = "join"
-[node name="HostButton" type="Button" parent="Center/VBox/buttons"]
+[node name="HostButton" type="Button" parent="VBox/buttons"]
unique_name_in_owner = true
margin_left = 240.0
margin_right = 350.0
@@ -77,7 +75,7 @@ size_flags_horizontal = 7
disabled = true
text = "host"
-[node name="Address" type="LineEdit" parent="Center/VBox"]
+[node name="Address" type="LineEdit" parent="VBox"]
unique_name_in_owner = true
margin_top = 64.0
margin_right = 350.0
@@ -92,7 +90,7 @@ placeholder_text = "game_name"
caret_blink = true
caret_blink_speed = 0.5
-[node name="StatusOK" type="Label" parent="Center/VBox"]
+[node name="StatusOK" type="Label" parent="VBox"]
unique_name_in_owner = true
visible = false
margin_top = 242.0
@@ -100,7 +98,7 @@ margin_right = 350.0
margin_bottom = 292.0
autowrap = true
-[node name="StatusFail" type="Label" parent="Center/VBox"]
+[node name="StatusFail" type="Label" parent="VBox"]
unique_name_in_owner = true
visible = false
margin_top = 242.0
@@ -109,7 +107,7 @@ margin_bottom = 292.0
custom_colors/font_color = Color( 0.862745, 0.196078, 0.184314, 1 )
autowrap = true
-[connection signal="pressed" from="Center/VBox/stophost" to="." method="_on_stophost_pressed"]
-[connection signal="pressed" from="Center/VBox/buttons/SpectateButton" to="." method="_on_spectate_pressed"]
-[connection signal="pressed" from="Center/VBox/buttons/JoinButton" to="." method="_on_join_pressed"]
-[connection signal="pressed" from="Center/VBox/buttons/HostButton" to="." method="_on_HostButton_pressed"]
+[connection signal="pressed" from="VBox/stophost" to="." method="_on_stophost_pressed"]
+[connection signal="pressed" from="VBox/buttons/SpectateButton" to="." method="_on_spectate_pressed"]
+[connection signal="pressed" from="VBox/buttons/JoinButton" to="." method="_on_join_pressed"]
+[connection signal="pressed" from="VBox/buttons/HostButton" to="." method="_on_HostButton_pressed"]
diff --git a/ui/menus/sidebarright/SidebarRight.tscn b/ui/menus/sidebarright/SidebarRight.tscn
index 6b06dfe..b8940a7 100644
--- a/ui/menus/sidebarright/SidebarRight.tscn
+++ b/ui/menus/sidebarright/SidebarRight.tscn
@@ -1,8 +1,9 @@
-[gd_scene load_steps=22 format=2]
+[gd_scene load_steps=23 format=2]
[ext_resource path="res://ui/menus/sidebarright/drawbutton.gd" type="Script" id=1]
[ext_resource path="res://ui/menus/sidebarright/resignbutton.gd" type="Script" id=2]
[ext_resource path="res://ui/Status.gd" type="Script" id=3]
+[ext_resource path="res://ui/menus/sidebarright/buttonbar.gd" type="Script" id=4]
[ext_resource path="res://ui/barbutton/default_highlight.tres" type="StyleBox" id=5]
[ext_resource path="res://ui/barbutton/default_pressed.tres" type="StyleBox" id=6]
[ext_resource path="res://ui/barbutton/default.tres" type="StyleBox" id=7]
@@ -83,7 +84,9 @@ visible = false
margin_top = 176.0
margin_right = 1402.0
margin_bottom = 199.0
+rect_min_size = Vector2( 0, 25 )
custom_fonts/font = ExtResource( 8 )
+valign = 1
script = ExtResource( 10 )
[node name="BlackPanel" parent="V" instance=ExtResource( 22 )]
@@ -116,6 +119,7 @@ margin_bottom = 50.0
theme = SubResource( 24 )
custom_constants/separation = 0
alignment = 1
+script = ExtResource( 4 )
[node name="FlipButton" type="Button" parent="V/buttonbarholder/buttonbar"]
margin_right = 350.0
diff --git a/ui/menus/sidebarright/UserPanel.gd b/ui/menus/sidebarright/UserPanel.gd
index 0911332..0967e53 100644
--- a/ui/menus/sidebarright/UserPanel.gd
+++ b/ui/menus/sidebarright/UserPanel.gd
@@ -16,3 +16,8 @@ func set_flag(newflag: String):
func set_name(newname: String):
_name = newname
name_display.text = _name
+
+
+func hide_children():
+ flag_display.hide()
+ name_display.hide()
diff --git a/ui/menus/sidebarright/UserPanel.tscn b/ui/menus/sidebarright/UserPanel.tscn
index c02e0c0..d2d5f76 100644
--- a/ui/menus/sidebarright/UserPanel.tscn
+++ b/ui/menus/sidebarright/UserPanel.tscn
@@ -5,7 +5,7 @@
[ext_resource path="res://ui/theme/main.theme" type="Theme" id=3]
[ext_resource path="res://ui/menus/sidebarright/UserPanel.gd" type="Script" id=4]
-[node name="UserPanel" type="MarginContainer"]
+[node name="UserPanel" type="MarginContainer" groups=["userpanel"]]
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 0, 40 )
diff --git a/ui/menus/sidebarright/buttonbar.gd b/ui/menus/sidebarright/buttonbar.gd
new file mode 100644
index 0000000..39cf3b3
--- /dev/null
+++ b/ui/menus/sidebarright/buttonbar.gd
@@ -0,0 +1,7 @@
+extends Control
+
+
+func _ready():
+ if Globals.grid.local:
+ for c in [$FlipButton, $DrawButton, $ResignButton]:
+ c.queue_free()
diff --git a/ui/menus/sidebarright/drawbutton.gd b/ui/menus/sidebarright/drawbutton.gd
index 948506c..197939f 100644
--- a/ui/menus/sidebarright/drawbutton.gd
+++ b/ui/menus/sidebarright/drawbutton.gd
@@ -30,7 +30,7 @@ func _pressed() -> void:
_confirmed(true)
else:
set_disabled(true)
- var msg = draw_request_message % Utils.expand_color(Globals.team)
+ var msg = draw_request_message % Utils.expand_color(Globals.grid.team)
PacketHandler.signal({question = msg}, PacketHandler.SIGNALHEADERS.draw)
Globals.chat.server(msg)
diff --git a/ui/menus/sidebarright/resignbutton.gd b/ui/menus/sidebarright/resignbutton.gd
index e84f46e..326a373 100644
--- a/ui/menus/sidebarright/resignbutton.gd
+++ b/ui/menus/sidebarright/resignbutton.gd
@@ -4,7 +4,7 @@ class_name ResignButton
func _signal_recieved(what: Dictionary) -> void:
if what.type == PacketHandler.SIGNALHEADERS.resign:
- Globals.grid.win(Globals.team, "resignation")
+ Globals.grid.win(Globals.grid.team, "resignation")
func _pressed() -> void:
@@ -18,5 +18,5 @@ func _pressed() -> void:
func after_confirmed():
PacketHandler.signal({}, PacketHandler.SIGNALHEADERS.resign)
- Globals.grid.win("w" if Globals.team == "b" else "b", "resignation")
+ Globals.grid.win("w" if Globals.grid.team == "b" else "b", "resignation")
disabled = true
diff --git a/ui/menus/sidebarright/undobutton.gd b/ui/menus/sidebarright/undobutton.gd
index 483005a..ebfceaf 100644
--- a/ui/menus/sidebarright/undobutton.gd
+++ b/ui/menus/sidebarright/undobutton.gd
@@ -16,12 +16,12 @@ func _pressed() -> void:
if waiting_on_answer:
_confirmed(true)
else:
- var two_undos = true if Globals.grid.chess.turn == Globals.team else false
+ var two_undos = true if Globals.grid.chess.turn == Globals.grid.team else false
var completed_moves = Globals.grid.chess.history().size()
if completed_moves == 0 or (two_undos && completed_moves == 1):
status.set_text("No moves to undo!")
return
- var msg = undo_request_message % Utils.expand_color(Globals.team)
+ var msg = undo_request_message % Utils.expand_color(Globals.grid.team)
var pckt = {gamecode = PacketHandler.game_code, question = msg, two = two_undos}
status.set_text("")
PacketHandler.send_packet(pckt, PacketHandler.HEADERS.undo)
@@ -44,7 +44,7 @@ func undo_signal_recieved(sig: Dictionary) -> void:
func _confirmed(what: bool) -> void:
._confirmed(what)
- var two_undos = false if Globals.grid.chess.turn == Globals.team else true
+ var two_undos = not Globals.grid.is_my_turn() # not my turn
var pckt = {gamecode = PacketHandler.game_code, accepted = what, two = two_undos}
PacketHandler.send_packet(pckt, PacketHandler.HEADERS.undo)
if what:
diff --git a/ui/menus/startmenu/StartMenu.tscn b/ui/menus/startmenu/StartMenu.tscn
index c6ffc88..3333b6e 100644
--- a/ui/menus/startmenu/StartMenu.tscn
+++ b/ui/menus/startmenu/StartMenu.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=11 format=2]
+[gd_scene load_steps=12 format=2]
[ext_resource path="res://assets/fonts/ubuntu/ubuntu-bold.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://ui/theme/main.theme" type="Theme" id=2]
@@ -9,6 +9,7 @@
[ext_resource path="res://ui/menus/settings/Settings.tscn" type="PackedScene" id=7]
[ext_resource path="res://ui/menus/account/Account.tscn" type="PackedScene" id=8]
[ext_resource path="res://ui/menus/startmenu/VersionLabel.gd" type="Script" id=9]
+[ext_resource path="res://ui/menus/LocalMultiplayer.tscn" type="PackedScene" id=10]
[sub_resource type="DynamicFont" id=1]
size = 400
@@ -39,7 +40,22 @@ size_flags_vertical = 0
drag_to_rearrange_enabled = true
use_hidden_tabs_for_min_size = true
-[node name="" parent="CenterContainer/tabs" instance=ExtResource( 5 )]
+[node name="" type="TabContainer" parent="CenterContainer/tabs"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+margin_left = 25.0
+margin_top = 79.0
+margin_right = -25.0
+margin_bottom = -25.0
+
+[node name="local" parent="CenterContainer/tabs/" instance=ExtResource( 10 )]
+margin_left = 25.0
+margin_top = 79.0
+margin_right = -25.0
+margin_bottom = -25.0
+
+[node name="multiplayer" parent="CenterContainer/tabs/" instance=ExtResource( 5 )]
+visible = false
margin_left = 25.0
margin_top = 79.0
margin_right = -25.0