online multiplayer chess game (note server currently down)
add go back button for local multiplayer
bendn 2022-09-16
parent 97a56fe · commit dbb7597
-rw-r--r--project.godot6
-rw-r--r--ui/board/BackButton.gd1
-rw-r--r--ui/board/Game.gd3
-rw-r--r--ui/menus/local_multiplayer/LocalMultiplayer.gd13
-rw-r--r--ui/menus/sidebarright/SidebarRight.tscn19
-rw-r--r--ui/menus/sidebarright/backbutton.gd5
6 files changed, 36 insertions, 11 deletions
diff --git a/project.godot b/project.godot
index 21a425c..b296c59 100644
--- a/project.godot
+++ b/project.godot
@@ -14,11 +14,6 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://addons/gdcli/Arg.gd"
}, {
-"base": "CenterContainer",
-"class": "BackButton",
-"language": "GDScript",
-"path": "res://ui/board/BackButton.gd"
-}, {
"base": "ColorRect",
"class": "BackgroundSquare",
"language": "GDScript",
@@ -261,7 +256,6 @@ _global_script_classes=[ {
} ]
_global_script_class_icons={
"Arg": "",
-"BackButton": "",
"BackgroundSquare": "",
"BarTextureButton": "",
"Chat": "",
diff --git a/ui/board/BackButton.gd b/ui/board/BackButton.gd
index 0bd014f..f91b25b 100644
--- a/ui/board/BackButton.gd
+++ b/ui/board/BackButton.gd
@@ -1,5 +1,4 @@
extends CenterContainer
-class_name BackButton
var button := Button.new()
diff --git a/ui/board/Game.gd b/ui/board/Game.gd
index 367c044..f6d7e42 100644
--- a/ui/board/Game.gd
+++ b/ui/board/Game.gd
@@ -15,11 +15,14 @@ func _ready() -> void:
Events.connect("game_over", self, "_game_over")
if Globals.local:
get_tree().call_group("freeinlocalmultiplayer", "queue_free")
+ get_tree().call_group("showiflocalmultiplayer", "show")
func _game_over(_why: String) -> void:
get_tree().call_group("showongameover", "show")
get_tree().call_group("hideongameover", "hide")
+ if not Globals.local:
+ get_tree().call_group("hideongameoverifnolocalmultiplayer", "hide")
func set_status(text: String, length := 5) -> void:
diff --git a/ui/menus/local_multiplayer/LocalMultiplayer.gd b/ui/menus/local_multiplayer/LocalMultiplayer.gd
index c7596ec..bc498df 100644
--- a/ui/menus/local_multiplayer/LocalMultiplayer.gd
+++ b/ui/menus/local_multiplayer/LocalMultiplayer.gd
@@ -39,6 +39,7 @@ func create(moves: PoolStringArray, player1_color: bool, players: PoolIntArray,
b.load_pgn(moves.join(" ")) # load_pgn emits Events.turn_over
b.auto_flip()
Globals.chat.hide()
+ in_game = true
func assign_mode(players: PoolIntArray) -> void:
@@ -59,7 +60,17 @@ func _pressed():
func _input(_event):
- if Input.is_action_pressed("ui_cancel") and Globals.local == true:
+ if Input.is_action_pressed("ui_cancel") and Globals.local == true and in_game:
+ Events.emit_signal("go_back", "", true)
+
+
+func _init() -> void:
+ Events.connect("go_back", self, "go_back")
+
+
+func go_back(_reason: String, _isok: bool) -> void:
+ if in_game:
+ in_game = false
if board_engine_bridge:
board_engine_bridge.kill()
board_engine_bridge = null
diff --git a/ui/menus/sidebarright/SidebarRight.tscn b/ui/menus/sidebarright/SidebarRight.tscn
index 94ad2b7..ab75114 100644
--- a/ui/menus/sidebarright/SidebarRight.tscn
+++ b/ui/menus/sidebarright/SidebarRight.tscn
@@ -1,8 +1,9 @@
-[gd_scene load_steps=21 format=2]
+[gd_scene load_steps=22 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/backbutton.gd" type="Script" id=4]
[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]
@@ -155,7 +156,19 @@ text = "īŠŒ"
script = ExtResource( 18 )
confirm_text = "Your opponent requests a undo"
-[node name="RematchButton" type="Button" parent="V" groups=["showongameover"]]
+[node name="BackButton" type="Button" parent="V/buttonbarholder/buttonbar" groups=["showiflocalmultiplayer"]]
+visible = false
+margin_left = 1121.0
+margin_right = 1402.0
+margin_bottom = 50.0
+rect_min_size = Vector2( 0, 50 )
+hint_tooltip = "exit"
+mouse_default_cursor_shape = 2
+size_flags_horizontal = 3
+text = "īœ…"
+script = ExtResource( 4 )
+
+[node name="RematchButton" type="Button" parent="V" groups=["freeinlocalmultiplayer", "showongameover"]]
visible = false
margin_top = 207.0
margin_right = 1402.0
@@ -167,7 +180,7 @@ text = "â €ī€ž"
script = ExtResource( 9 )
confirm_text = "Would you like to play again?"
-[node name="SanDisplay" parent="V" groups=["hideongameover"] instance=ExtResource( 21 )]
+[node name="SanDisplay" parent="V" groups=["hideongameoverifnolocalmultiplayer"] instance=ExtResource( 21 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 320.0
diff --git a/ui/menus/sidebarright/backbutton.gd b/ui/menus/sidebarright/backbutton.gd
new file mode 100644
index 0000000..db0ffe6
--- /dev/null
+++ b/ui/menus/sidebarright/backbutton.gd
@@ -0,0 +1,5 @@
+extends Button
+
+
+func _ready():
+ connect("pressed", Events, "emit_signal", ["go_back", "", true])