diff --git a/DrawInfo.gd b/DrawInfo.gd new file mode 100644 index 0000000..c96e560 --- /dev/null +++ b/DrawInfo.gd @@ -0,0 +1,32 @@ +extends Control + +@onready var offer_received = $PanelContainer/MarginContainer/OfferReceived +@onready var offer_sent = $PanelContainer/MarginContainer/OfferSent + + +# Called when the node enters the scene tree for the first time. +func _ready(): + GameEvents.draw_offer_sent.connect(_on_draw_offer_sent) + GameEvents.draw_offer_received.connect(_on_draw_offer_received) + GameEvents.draw_answer_received.connect(_on_draw_answer_received) + +func _on_draw_answer_received(accepted: bool) -> void: + visible = false + +func _on_draw_offer_sent() -> void: + offer_received.visible = false + offer_sent.visible = true + visible = true + +func _on_draw_offer_received() -> void: + offer_received.visible = true + offer_sent.visible = false + visible = true + +func _on_yes_button_pressed(): + GameEvents.draw_answer_sent.emit(true) + visible = false + +func _on_no_button_pressed(): + GameEvents.draw_answer_sent.emit(false) + visible = false diff --git a/Game.tscn b/Game.tscn index 37833ae..5ae99d4 100644 --- a/Game.tscn +++ b/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=28 format=3 uid="uid://bx0bbrwdr0h40"] +[gd_scene load_steps=30 format=3 uid="uid://bx0bbrwdr0h40"] [ext_resource type="Script" path="res://Game.gd" id="1_dgt1j"] [ext_resource type="Script" path="res://CameraPivot.gd" id="2_71xp1"] @@ -17,6 +17,7 @@ [ext_resource type="Script" path="res://addons/awesome_input_icons/classes/InputIconTextureRect.gd" id="13_mbmni"] [ext_resource type="Texture2D" uid="uid://20wqrthwoqr0" path="res://addons/awesome_input_icons/assets/keyboard and mouse vector/mouse_move.svg" id="14_t8b21"] [ext_resource type="Script" path="res://UI/ActionMoveMenu.gd" id="15_gc6p8"] +[ext_resource type="Script" path="res://DrawInfo.gd" id="16_enu5g"] [ext_resource type="Script" path="res://UI/GameSettings.gd" id="16_uww8u"] [sub_resource type="PlaneMesh" id="PlaneMesh_cu5ir"] @@ -59,6 +60,9 @@ texture = SubResource("GradientTexture2D_tjcjh") axis_stretch_vertical = 2 modulate_color = Color(1, 1, 1, 0.639216) +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_74vw4"] +bg_color = Color(0, 0, 0, 0.341176) + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_51vcp"] bg_color = Color(0.345098, 0.345098, 0.345098, 1) @@ -242,73 +246,6 @@ size_flags_horizontal = 4 size_flags_vertical = 0 mouse_filter = 2 -[node name="MenuButtons" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 0 -offset_right = 40.0 -offset_bottom = 40.0 -script = ExtResource("11_urihv") - -[node name="VBoxContainer" type="VBoxContainer" parent="MenuButtons"] -layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 - -[node name="MenuButton" type="Button" parent="MenuButtons/VBoxContainer"] -layout_mode = 2 -text = "Menu" - -[node name="PassRoundButton" type="Button" parent="MenuButtons/VBoxContainer"] -layout_mode = 2 -text = "Pass" - -[node name="SurrenderButton" type="Button" parent="MenuButtons/VBoxContainer"] -layout_mode = 2 -text = "Surrender" - -[node name="OfferDrawButton" type="Button" parent="MenuButtons/VBoxContainer"] -layout_mode = 2 -disabled = true -text = "Offer Draw" - -[node name="RulesButton" type="Button" parent="MenuButtons/VBoxContainer"] -layout_mode = 2 -text = "Rules" - -[node name="GameOverMenu" type="CanvasLayer" parent="."] -visible = false -script = ExtResource("11_ffmss") - -[node name="Control" type="Control" parent="GameOverMenu"] -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="PanelContainer" type="PanelContainer" parent="GameOverMenu/Control"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="VBoxContainer" type="VBoxContainer" parent="GameOverMenu/Control/PanelContainer"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 - -[node name="Label" type="Label" parent="GameOverMenu/Control/PanelContainer/VBoxContainer"] -layout_mode = 2 -text = "#WINNER#" -horizontal_alignment = 1 - -[node name="Button" type="Button" parent="GameOverMenu/Control/PanelContainer/VBoxContainer"] -layout_mode = 2 -text = "Back to menu" - [node name="InputInfo" type="Control" parent="."] layout_mode = 3 anchors_preset = 1 @@ -487,6 +424,162 @@ theme_override_font_sizes/font_size = 20 text = "Show/Hide controls" horizontal_alignment = 2 +[node name="MenuButtons" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 +script = ExtResource("11_urihv") + +[node name="VBoxContainer" type="VBoxContainer" parent="MenuButtons"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="MenuButton" type="Button" parent="MenuButtons/VBoxContainer"] +layout_mode = 2 +text = "Menu" + +[node name="PassRoundButton" type="Button" parent="MenuButtons/VBoxContainer"] +layout_mode = 2 +text = "Pass" + +[node name="SurrenderButton" type="Button" parent="MenuButtons/VBoxContainer"] +layout_mode = 2 +text = "Surrender" + +[node name="OfferDrawButton" type="Button" parent="MenuButtons/VBoxContainer"] +layout_mode = 2 +text = "Offer Draw" + +[node name="RulesButton" type="Button" parent="MenuButtons/VBoxContainer"] +layout_mode = 2 +text = "Rules" + +[node name="DrawInfo" type="Control" parent="."] +visible = false +layout_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("16_enu5g") + +[node name="PanelContainer2" type="PanelContainer" parent="DrawInfo"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -620.0 +offset_top = -340.0 +offset_right = 620.0 +offset_bottom = 340.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_74vw4") + +[node name="PanelContainer" type="PanelContainer" parent="DrawInfo"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="DrawInfo/PanelContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +theme_override_constants/margin_left = 15 +theme_override_constants/margin_top = 15 +theme_override_constants/margin_right = 15 +theme_override_constants/margin_bottom = 15 + +[node name="OfferReceived" type="VBoxContainer" parent="DrawInfo/PanelContainer/MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 + +[node name="Label" type="Label" parent="DrawInfo/PanelContainer/MarginContainer/OfferReceived"] +layout_mode = 2 +text = "Your opponent wants to +call the game a draw. + +Accept? + +" + +[node name="HBoxContainer" type="HBoxContainer" parent="DrawInfo/PanelContainer/MarginContainer/OfferReceived"] +layout_mode = 2 + +[node name="YesButton" type="Button" parent="DrawInfo/PanelContainer/MarginContainer/OfferReceived/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "YES" + +[node name="NoButton" type="Button" parent="DrawInfo/PanelContainer/MarginContainer/OfferReceived/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "NO" + +[node name="OfferSent" type="VBoxContainer" parent="DrawInfo/PanelContainer/MarginContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="DrawInfo/PanelContainer/MarginContainer/OfferSent"] +layout_mode = 2 +text = "Draw offer sent. + +Waiting for opponents decision..." + +[node name="GameOverMenu" type="CanvasLayer" parent="."] +visible = false +script = ExtResource("11_ffmss") + +[node name="Control" type="Control" parent="GameOverMenu"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PanelContainer" type="PanelContainer" parent="GameOverMenu/Control"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="GameOverMenu/Control/PanelContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 + +[node name="Label" type="Label" parent="GameOverMenu/Control/PanelContainer/VBoxContainer"] +layout_mode = 2 +text = "#WINNER#" +horizontal_alignment = 1 + +[node name="Button" type="Button" parent="GameOverMenu/Control/PanelContainer/VBoxContainer"] +layout_mode = 2 +text = "Back to menu" + [node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="ActionMoveMenu" type="Control" parent="CanvasLayer"] @@ -625,8 +718,10 @@ text = "Start" [connection signal="pressed" from="MenuButtons/VBoxContainer/MenuButton" to="MenuButtons" method="_on_menu_button_pressed"] [connection signal="pressed" from="MenuButtons/VBoxContainer/PassRoundButton" to="MenuButtons" method="_on_pass_round_button_pressed"] [connection signal="pressed" from="MenuButtons/VBoxContainer/SurrenderButton" to="MenuButtons" method="_on_surrender_button_pressed"] -[connection signal="pressed" from="MenuButtons/VBoxContainer/OfferDrawButton" to="MenuButtons" method="_on_menu_button_pressed"] +[connection signal="pressed" from="MenuButtons/VBoxContainer/OfferDrawButton" to="MenuButtons" method="_on_offer_draw_button_pressed"] [connection signal="pressed" from="MenuButtons/VBoxContainer/RulesButton" to="MenuButtons" method="_on_rules_button_pressed"] +[connection signal="pressed" from="DrawInfo/PanelContainer/MarginContainer/OfferReceived/HBoxContainer/YesButton" to="DrawInfo" method="_on_yes_button_pressed"] +[connection signal="pressed" from="DrawInfo/PanelContainer/MarginContainer/OfferReceived/HBoxContainer/NoButton" to="DrawInfo" method="_on_no_button_pressed"] [connection signal="pressed" from="GameOverMenu/Control/PanelContainer/VBoxContainer/Button" to="GameOverMenu" method="_on_button_pressed"] [connection signal="pressed" from="CanvasLayer/ActionMoveMenu/PanelContainer/MarginContainer/VBoxContainer/MoveButton" to="CanvasLayer/ActionMoveMenu" method="_on_move_button_pressed"] [connection signal="pressed" from="CanvasLayer/ActionMoveMenu/PanelContainer/MarginContainer/VBoxContainer/ActionButton" to="CanvasLayer/ActionMoveMenu" method="_on_action_button_pressed"] diff --git a/Globals/GameEvents.gd b/Globals/GameEvents.gd index 8fe8b39..65d019a 100644 --- a/Globals/GameEvents.gd +++ b/Globals/GameEvents.gd @@ -21,6 +21,12 @@ signal insect_tile_action_started(tile) signal show_move_error(error) +signal draw_offer_sent() +signal draw_offer_received() + +signal draw_answer_sent(accepted) +signal draw_answer_received(accepted) + # Turn started could work implicitly? We'll see... signal pass_round signal turn_started(turn_num, map, is_blacks_turn) diff --git a/MenuButtons.gd b/MenuButtons.gd index a442532..2aedbe5 100644 --- a/MenuButtons.gd +++ b/MenuButtons.gd @@ -5,22 +5,24 @@ const RULES = preload("res://UI/Rules/Rules.tscn") @onready var surrender_button = $VBoxContainer/SurrenderButton @onready var pass_round_button = $VBoxContainer/PassRoundButton +@onready var offer_draw_button = $VBoxContainer/OfferDrawButton var is_blacks_turn: bool = false # Called when the node enters the scene tree for the first time. func _ready(): + GameEvents.draw_answer_sent.connect(_on_draw_answer_sent) + GameEvents.turn_started.connect(_on_turn_started) + if GameData.is_hot_seat: + offer_draw_button.disabled = true + offer_draw_button.visible = false + func _on_turn_started(round_num: int, map: HexGrid, _is_blacks_turn: bool) -> void: is_blacks_turn = _is_blacks_turn surrender_button.disabled = GameData.is_player_black != _is_blacks_turn and not GameData.is_hot_seat pass_round_button.disabled = GameData.is_player_black != _is_blacks_turn and not GameData.is_hot_seat - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass - func _on_rules_button_pressed(): var rules = RULES.instantiate() @@ -48,3 +50,35 @@ func _on_surrender_button_pressed(): func _on_pass_round_button_pressed(): GameEvents.pass_round.emit() + + +@rpc("any_peer", "call_remote") +func receive_draw_offer() -> void: + offer_draw_button.disabled = true + GameEvents.draw_offer_received.emit() + # other player wants to draw the game, show yes/no popup + pass + +@rpc("any_peer", "call_remote") +func receive_draw_answer(accepted: bool) -> void: + GameEvents.draw_answer_received.emit(accepted) + offer_draw_button.disabled = false + pass + +@rpc("any_peer", "call_local") +func _end_game() -> void: + GameEvents.game_over.emit(true, true) + pass + +func _on_draw_answer_sent(accepted: bool) -> void: + receive_draw_answer.rpc(accepted) + + if accepted: + _end_game.rpc() + else: + offer_draw_button.disabled = false + +func _on_offer_draw_button_pressed(): + offer_draw_button.disabled = true + GameEvents.draw_offer_sent.emit() + receive_draw_offer.rpc()