84 lines
2.3 KiB
GDScript
84 lines
2.3 KiB
GDScript
extends Control
|
|
|
|
const IN_GAME_MENU = preload("res://UI/InGameMenu/InGameMenu.tscn")
|
|
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
|
|
|
|
func _on_rules_button_pressed():
|
|
var rules = RULES.instantiate()
|
|
|
|
get_tree().root.add_child(rules)
|
|
|
|
rules.show_panel()
|
|
|
|
func _on_menu_button_pressed():
|
|
var in_game_menu = IN_GAME_MENU.instantiate()
|
|
|
|
get_tree().root.add_child(in_game_menu)
|
|
|
|
in_game_menu.show_panel()
|
|
|
|
@rpc("any_peer", "call_local")
|
|
func surrender() -> void:
|
|
if is_blacks_turn:
|
|
GameEvents.game_over.emit(true, false)
|
|
else:
|
|
GameEvents.game_over.emit(false, true)
|
|
|
|
func _on_surrender_button_pressed():
|
|
surrender.rpc()
|
|
|
|
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()
|