online multiplayer chess game (note server currently down)
add rematch/play again button
| -rw-r--r-- | networking/PacketHandler.gd | 4 | ||||
| -rw-r--r-- | project.godot | 6 | ||||
| -rw-r--r-- | ui/Status.gd | 6 | ||||
| -rw-r--r-- | ui/board/BackButton.gd | 5 | ||||
| -rw-r--r-- | ui/board/Board.gd | 13 | ||||
| -rw-r--r-- | ui/board/Game.gd | 8 | ||||
| -rw-r--r-- | ui/board/Game.tscn | 2 | ||||
| -rw-r--r-- | ui/chat/Chat.gd | 2 | ||||
| -rw-r--r-- | ui/menus/lobby/Lobby.gd | 8 | ||||
| -rw-r--r-- | ui/menus/sidebarright/OpeningLabel.gd | 4 | ||||
| -rw-r--r-- | ui/menus/sidebarright/SidebarRight.gd | 2 | ||||
| -rw-r--r-- | ui/menus/sidebarright/SidebarRight.tscn | 57 | ||||
| -rw-r--r-- | ui/menus/sidebarright/buttonbar.gd | 7 | ||||
| -rw-r--r-- | ui/menus/sidebarright/buttonbar.theme | bin | 0 -> 647 bytes | |||
| -rw-r--r-- | ui/menus/sidebarright/confirmbutton.gd | 1 | ||||
| -rw-r--r-- | ui/menus/sidebarright/rematchbutton.gd | 56 | ||||
| -rw-r--r-- | ui/menus/sidebarright/resignbutton.gd | 2 | ||||
| -rw-r--r-- | ui/menus/sidebarright/undobutton.gd | 6 |
18 files changed, 130 insertions, 59 deletions
diff --git a/networking/PacketHandler.gd b/networking/PacketHandler.gd index a3f71d2..d9760bd 100644 --- a/networking/PacketHandler.gd +++ b/networking/PacketHandler.gd @@ -11,6 +11,7 @@ signal start_game signal move_data(data) signal load_pgn(pgn) signal request_result(what) # join/host true accepted, false rejected +signal rematch_result(what) ## for accounts(mostly) signal signinresult(what) signal signupresult(what) @@ -26,6 +27,7 @@ const HEADERS := { "info": "I", "move": "M", "undo": "<", + "rematch": "r", "spectate": "0" # its a eye you see } @@ -117,6 +119,8 @@ func _data_recieved() -> void: emit_signal("signupresult", text) HEADERS.signin: emit_signal("signinresult", text) + HEADERS.rematch: + emit_signal("rematch_result", text) _: Log.err("unknown header %s" % header) diff --git a/project.godot b/project.godot index 26ac583..8133b1e 100644 --- a/project.godot +++ b/project.godot @@ -180,6 +180,11 @@ _global_script_classes=[ { "path": "res://ui/PromotionPreview.gd" }, { "base": "ConfirmButton", +"class": "RematchButton", +"language": "GDScript", +"path": "res://ui/menus/sidebarright/rematchbutton.gd" +}, { +"base": "ConfirmButton", "class": "ResignButton", "language": "GDScript", "path": "res://ui/menus/sidebarright/resignbutton.gd" @@ -269,6 +274,7 @@ _global_script_class_icons={ "Piece": "", "Preview": "", "PromotionPreview": "", +"RematchButton": "", "ResignButton": "", "Restrict": "", "SaveLoader": "", diff --git a/ui/Status.gd b/ui/Status.gd index 1cf2eb7..dd3debf 100644 --- a/ui/Status.gd +++ b/ui/Status.gd @@ -4,11 +4,15 @@ class_name StatusLabel func set_text(newtext: String, time := 7) -> void: __set_text(newtext) - if time != 0: + if time != 0 && newtext != "": yield(get_tree().create_timer(time), "timeout") __set_text("") +func clear_text(): + __set_text("") + + func __set_text(_text: String = ""): text = _text visible = text != "" diff --git a/ui/board/BackButton.gd b/ui/board/BackButton.gd index 4939232..0bd014f 100644 --- a/ui/board/BackButton.gd +++ b/ui/board/BackButton.gd @@ -6,10 +6,5 @@ var button := Button.new() func _ready(): add_child(button) - Events.connect("game_over", self, "_game_over") button.text = "go back" button.connect("pressed", Events, "emit_signal", ["go_back", "", true]) - - -func _game_over(_why: String) -> void: - show() diff --git a/ui/board/Board.gd b/ui/board/Board.gd index e1b94d4..8f33e08 100644 --- a/ui/board/Board.gd +++ b/ui/board/Board.gd @@ -388,7 +388,7 @@ func undo(two: bool = false) -> void: func _on_turn_over(): - if local: # for testing + if local: team = chess.turn flip_board() @@ -443,3 +443,14 @@ func create_last_move_indicators(): background_array[m.to].move_indicator.color = last_move_take_indicator background_array[m.to].move_indicator.show() move_indicators = [m.from, m.to] + + +func reload(): + premove = {} + chess = Chess.new() + clear_last_clicked() + clear_pieces() + create_pieces() + create_last_move_indicators() # it hides the indicators :/ + Events.emit_signal("turn_over") + emit_signal("clear_pgn") # clears the san displays diff --git a/ui/board/Game.gd b/ui/board/Game.gd index b46229b..457a2d5 100644 --- a/ui/board/Game.gd +++ b/ui/board/Game.gd @@ -12,6 +12,14 @@ onready var panels := [ func _ready() -> void: PacketHandler.connect("info_recieved", self, "_spectate_info" if Globals.spectating else "_on_info") + Events.connect("game_over", self, "_game_over") + if Globals.grid.local: + get_tree().call_group("freeinlocalmultiplayer", "queue_free") + + +func _game_over(_why: String) -> void: + get_tree().call_group("showongameover", "show") + get_tree().call_group("hideongameover", "hide") func set_status(text: String, length := 5) -> void: diff --git a/ui/board/Game.tscn b/ui/board/Game.tscn index cfc3281..bae208e 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" groups=["backbutton"]] +[node name="BackButton" type="CenterContainer" parent="Holder/middle" groups=["backbutton", "showongameover"]] visible = false margin_top = 720.0 margin_right = 700.0 diff --git a/ui/chat/Chat.gd b/ui/chat/Chat.gd index be4b119..ddb3a07 100644 --- a/ui/chat/Chat.gd +++ b/ui/chat/Chat.gd @@ -33,8 +33,6 @@ func _exit_tree(): func _ready(): PacketHandler.connect("chat", self, "add_label_with") server("Welcome!") # say hello - yield(get_tree().create_timer(.4), "timeout") - server("You can use markdown(sort of)!") # say hello again func add_label_with(data: Dictionary) -> void: diff --git a/ui/menus/lobby/Lobby.gd b/ui/menus/lobby/Lobby.gd index b6dd488..ebda154 100644 --- a/ui/menus/lobby/Lobby.gd +++ b/ui/menus/lobby/Lobby.gd @@ -39,11 +39,11 @@ func focus(): func set_status(text: String, isok: bool) -> void: # Simple way to show status. if isok: - status_ok.set_text(text) - status_fail.set_text("") + status_ok.text = text + status_fail.text = "" else: - status_ok.set_text("") - status_fail.set_text(text) + status_ok.text = ("") + status_fail.text = (text) status_ok.visible = len(status_ok.text) > 0 status_fail.visible = len(status_fail.text) > 0 diff --git a/ui/menus/sidebarright/OpeningLabel.gd b/ui/menus/sidebarright/OpeningLabel.gd index f7845e7..fb5897f 100644 --- a/ui/menus/sidebarright/OpeningLabel.gd +++ b/ui/menus/sidebarright/OpeningLabel.gd @@ -22,7 +22,7 @@ func update_opening(_var := null) -> void: if fen != Globals.grid.chess.DEFAULT_POSITION && fen != current_req: if current_req: http_request.cancel_request() - set_text("") + text = "" current_req = fen var u = url % fen.replace(" ", "_").http_escape() Log.net(["REQUEST: get opening with url:", u]) @@ -30,7 +30,7 @@ func update_opening(_var := null) -> void: func _request_completed(result, _response_code, _headers, byte_body): - set_text("") # empty text and hide self + text = "" # empty text and hide self current_req = "" if result != OK: # technically REQUEST_SUCCESS but i cant find it return diff --git a/ui/menus/sidebarright/SidebarRight.gd b/ui/menus/sidebarright/SidebarRight.gd index 39f6188..edf124d 100644 --- a/ui/menus/sidebarright/SidebarRight.gd +++ b/ui/menus/sidebarright/SidebarRight.gd @@ -2,7 +2,7 @@ extends Control onready var whitepanel = find_node("WhitePanel") onready var blackpanel = find_node("BlackPanel") -export(NodePath) onready var panel_holder = get_node(panel_holder) +onready var panel_holder = $"V" func flip_panels(): diff --git a/ui/menus/sidebarright/SidebarRight.tscn b/ui/menus/sidebarright/SidebarRight.tscn index b8940a7..94ad2b7 100644 --- a/ui/menus/sidebarright/SidebarRight.tscn +++ b/ui/menus/sidebarright/SidebarRight.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=21 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] +[ext_resource path="res://ui/menus/sidebarright/buttonbar.theme" type="Theme" id=5] +[ext_resource path="res://assets/fonts/migu.ttf" type="DynamicFontData" id=6] +[ext_resource path="res://assets/fonts/ubuntu/ubuntu-bold.ttf" type="DynamicFontData" id=7] [ext_resource path="res://ui/ubuntu-bold-regular.tres" type="DynamicFont" id=8] +[ext_resource path="res://ui/menus/sidebarright/rematchbutton.gd" type="Script" id=9] [ext_resource path="res://ui/menus/sidebarright/OpeningLabel.gd" type="Script" id=10] [ext_resource path="res://ui/menus/sidebarright/material/MaterialLabelManager.gd" type="Script" id=11] [ext_resource path="res://ui/menus/sidebarright/material/MaterialLabel.gd" type="Script" id=12] @@ -36,23 +36,10 @@ corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 [sub_resource type="DynamicFont" id=23] -size = 40 -font_data = ExtResource( 15 ) - -[sub_resource type="StyleBoxEmpty" id=11] - -[sub_resource type="Theme" id=24] -Button/colors/font_color = Color( 0.933333, 0.909804, 0.835294, 1 ) -Button/colors/font_color_disabled = Color( 0.576471, 0.631373, 0.631373, 1 ) -Button/colors/font_color_focus = Color( 0.992157, 0.964706, 0.890196, 1 ) -Button/colors/font_color_hover = Color( 0.992157, 0.964706, 0.890196, 1 ) -Button/colors/font_color_pressed = Color( 0.992157, 0.964706, 0.890196, 1 ) -Button/fonts/font = SubResource( 23 ) -Button/styles/disabled = ExtResource( 7 ) -Button/styles/focus = SubResource( 11 ) -Button/styles/hover = ExtResource( 5 ) -Button/styles/normal = ExtResource( 7 ) -Button/styles/pressed = ExtResource( 6 ) +size = 200 +font_data = ExtResource( 7 ) +fallback/0 = ExtResource( 15 ) +fallback/1 = ExtResource( 6 ) [node name="SidebarRight" type="PanelContainer"] anchor_right = 1.0 @@ -64,7 +51,6 @@ script = ExtResource( 13 ) __meta__ = { "_edit_lock_": true } -panel_holder = NodePath("V") [node name="MaterialLabelManager" type="Node" parent="."] script = ExtResource( 11 ) @@ -116,10 +102,9 @@ __meta__ = { [node name="buttonbar" type="HBoxContainer" parent="V/buttonbarholder"] margin_right = 1402.0 margin_bottom = 50.0 -theme = SubResource( 24 ) +theme = ExtResource( 5 ) custom_constants/separation = 0 alignment = 1 -script = ExtResource( 4 ) [node name="FlipButton" type="Button" parent="V/buttonbarholder/buttonbar"] margin_right = 350.0 @@ -131,7 +116,7 @@ size_flags_horizontal = 3 text = "ﮨ" script = ExtResource( 19 ) -[node name="DrawButton" type="Button" parent="V/buttonbarholder/buttonbar"] +[node name="DrawButton" type="Button" parent="V/buttonbarholder/buttonbar" groups=["freeinlocalmultiplayer", "hideongameover"]] margin_left = 350.0 margin_right = 701.0 margin_bottom = 50.0 @@ -144,7 +129,7 @@ text = "½-½" script = ExtResource( 1 ) confirm_text = "Your opponent requests a draw" -[node name="ResignButton" type="Button" parent="V/buttonbarholder/buttonbar"] +[node name="ResignButton" type="Button" parent="V/buttonbarholder/buttonbar" groups=["freeinlocalmultiplayer", "hideongameover"]] margin_left = 701.0 margin_right = 1051.0 margin_bottom = 50.0 @@ -157,7 +142,7 @@ text = "" script = ExtResource( 2 ) confirm_text = "Resign?" -[node name="UndoButton" type="Button" parent="V/buttonbarholder/buttonbar"] +[node name="UndoButton" type="Button" parent="V/buttonbarholder/buttonbar" groups=["freeinlocalmultiplayer", "hideongameover"]] margin_left = 1051.0 margin_right = 1402.0 margin_bottom = 50.0 @@ -169,9 +154,20 @@ size_flags_horizontal = 3 text = "社" script = ExtResource( 18 ) confirm_text = "Your opponent requests a undo" -status = NodePath("../../../Status") -[node name="SanDisplay" parent="V" instance=ExtResource( 21 )] +[node name="RematchButton" type="Button" parent="V" groups=["showongameover"]] +visible = false +margin_top = 207.0 +margin_right = 1402.0 +margin_bottom = 432.0 +hint_tooltip = "rematch?" +theme = ExtResource( 5 ) +custom_fonts/font = SubResource( 23 ) +text = "⠀" +script = ExtResource( 9 ) +confirm_text = "Would you like to play again?" + +[node name="SanDisplay" parent="V" groups=["hideongameover"] instance=ExtResource( 21 )] anchor_right = 0.0 anchor_bottom = 0.0 margin_top = 320.0 @@ -194,6 +190,7 @@ alignment = 2 script = ExtResource( 12 ) [node name="Status" type="Label" parent="V"] +unique_name_in_owner = true visible = false margin_top = 549.0 margin_right = 1402.0 diff --git a/ui/menus/sidebarright/buttonbar.gd b/ui/menus/sidebarright/buttonbar.gd deleted file mode 100644 index 39cf3b3..0000000 --- a/ui/menus/sidebarright/buttonbar.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends Control - - -func _ready(): - if Globals.grid.local: - for c in [$FlipButton, $DrawButton, $ResignButton]: - c.queue_free() diff --git a/ui/menus/sidebarright/buttonbar.theme b/ui/menus/sidebarright/buttonbar.theme Binary files differnew file mode 100644 index 0000000..9de4cfb --- /dev/null +++ b/ui/menus/sidebarright/buttonbar.theme diff --git a/ui/menus/sidebarright/confirmbutton.gd b/ui/menus/sidebarright/confirmbutton.gd index 9f9eea3..8aac37e 100644 --- a/ui/menus/sidebarright/confirmbutton.gd +++ b/ui/menus/sidebarright/confirmbutton.gd @@ -7,7 +7,6 @@ export(String) var confirm_text = "" func _ready() -> void: - Events.connect("game_over", self, "disable") PacketHandler.connect("signal_recieved", self, "_signal_recieved") diff --git a/ui/menus/sidebarright/rematchbutton.gd b/ui/menus/sidebarright/rematchbutton.gd new file mode 100644 index 0000000..1d85759 --- /dev/null +++ b/ui/menus/sidebarright/rematchbutton.gd @@ -0,0 +1,56 @@ +extends ConfirmButton +class_name RematchButton + +const request_message = "%s requested a rematch" +const declined_message = "rematch declined" + +onready var status := get_node("%Status") as StatusLabel + + +func _ready() -> void: + PacketHandler.connect("rematch_result", self, "signal_recieved") + + +func _pressed() -> void: + if Globals.spectating: + return + if waiting_on_answer: + _confirmed(true) + else: + var msg = request_message % Utils.expand_color(Globals.grid.team) + var pckt = {gamecode = PacketHandler.game_code, question = msg} + PacketHandler.send_packet(pckt, PacketHandler.HEADERS.rematch) + Globals.chat.server(msg) + set_disabled(true) + + +func signal_recieved(sig: Dictionary) -> void: + if "question" in sig: + Globals.chat.server(sig.question) + confirm() + else: + set_disabled(false) + if sig.accepted: + rematch() + else: + # declined signal reception + Globals.chat.server(declined_message) + + +func _confirmed(what: bool) -> void: + ._confirmed(what) + var pckt = {gamecode = PacketHandler.game_code, accepted = what} + PacketHandler.send_packet(pckt, PacketHandler.HEADERS.rematch) + if what: + rematch() + else: + # pressed no reception + Globals.chat.server(declined_message) + + +func rematch(): + Globals.chat.server("reloaded") + status.clear_text() + Globals.grid.reload() + get_tree().call_group("showongameover", "hide") # they go back to hidden now. + get_tree().call_group("hideongameover", "show") # and vice versa diff --git a/ui/menus/sidebarright/resignbutton.gd b/ui/menus/sidebarright/resignbutton.gd index 326a373..a7a54ae 100644 --- a/ui/menus/sidebarright/resignbutton.gd +++ b/ui/menus/sidebarright/resignbutton.gd @@ -19,4 +19,4 @@ func _pressed() -> void: func after_confirmed(): PacketHandler.signal({}, PacketHandler.SIGNALHEADERS.resign) Globals.grid.win("w" if Globals.grid.team == "b" else "b", "resignation") - disabled = true + hide() diff --git a/ui/menus/sidebarright/undobutton.gd b/ui/menus/sidebarright/undobutton.gd index ebfceaf..5572135 100644 --- a/ui/menus/sidebarright/undobutton.gd +++ b/ui/menus/sidebarright/undobutton.gd @@ -1,7 +1,7 @@ extends ConfirmButton class_name UndoButton -export(NodePath) onready var status = get_node(status) as StatusLabel +onready var status := get_node("%Status") as StatusLabel const undo_request_message = "%s requested a undo" const undo_declined_message = "undo declined" @@ -23,7 +23,7 @@ func _pressed() -> void: return 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("") + status.clear_text() PacketHandler.send_packet(pckt, PacketHandler.HEADERS.undo) Globals.chat.server(msg) set_disabled(true) @@ -56,4 +56,4 @@ func _confirmed(what: bool) -> void: func undo(two_undos := false): Globals.grid.undo(two_undos) - status.set_text("") + status.clear_text() |