summaryrefslogtreecommitdiff
path: root/stage/hud_main.gd
blob: e265e2471099bfaece501944d1c4da5934ff5625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
extends CanvasLayer


const DICE_SELECTION_SCENE := preload("res://stage/dice_selection/dice_selection.tscn")
const DICE_THROW_SCENE := preload("res://stage/dice_throw/dice_throw.tscn")

@onready var grid_selector: GridSelector = get_tree().get_first_node_in_group("grid_selector")


func _ready() -> void:
	visible = false
	
	Network.current_player_changed.connect(func():
		set_current_player()
	)


func _input(event: InputEvent) -> void:
	if not visible:
		return
	
	if event.is_action_pressed("left_click"):
		for button: Button in $PanelContainer/VBoxContainer.get_children():
			if button.has_focus():
				button.pressed.emit()
				break
	
	if event.is_action_pressed("menu") or event.is_action_pressed("right_click"):
		visible = false
		grid_selector.process_mode = Node.PROCESS_MODE_INHERIT


func enable():
	$PanelContainer2/VBoxContainer/move.text = "Move: " + str(Network.local_player.current_move_points)
	$PanelContainer2/VBoxContainer/attack.text = "Atk: " + str(Network.local_player.current_attack_points)
	$PanelContainer2/VBoxContainer/defend.text = "Def: " + str(Network.local_player.current_defend_points)
	$PanelContainer2/VBoxContainer/ability.text = "Ablty: " + str(Network.local_player.current_ability_points)
	
	set_current_player()
	
	if Network.is_my_turn():
		$PanelContainer/VBoxContainer/Button.visible = true
		$PanelContainer/VBoxContainer/Button2.visible = true
	else:
		$PanelContainer/VBoxContainer/Button.visible = false
		$PanelContainer/VBoxContainer/Button2.visible = false
	
	visible = true
	
	$PanelContainer/VBoxContainer/Button.grab_focus()


func set_current_player() -> void:
	if Network.is_my_turn():
		$PanelContainer3/CurrentTurn.text = "Current Turn: Me"
	else:
		$PanelContainer3/CurrentTurn.text = "Current Turn: " + str(Network.current_player.id)


func _on_button_pressed() -> void:
	visible = false
	
	var dice_selection := DICE_SELECTION_SCENE.instantiate()
	Game.overlay.add_child(dice_selection)
	dice_selection.dice_selected.connect(func(selected_dice: Array[DiceConfiguration]):
		dice_selection.queue_free()
		
		if selected_dice.size() > 0:
			var dice_throw := DICE_THROW_SCENE.instantiate()
			dice_throw.dice_configurations = selected_dice
			Game.overlay.add_child(dice_throw)
			dice_throw.throw_finished.connect(func():
				dice_throw.queue_free()
				
				get_tree().current_scene.process_mode = PROCESS_MODE_INHERIT
				grid_selector.process_mode = PROCESS_MODE_INHERIT
				grid_selector.current_state = grid_selector.state_cube_placement
			)
		else:
			get_tree().current_scene.process_mode = PROCESS_MODE_INHERIT
			grid_selector.process_mode = PROCESS_MODE_INHERIT
	)
	
	get_tree().current_scene.process_mode = PROCESS_MODE_DISABLED


func _on_button_2_pressed() -> void:
	visible = false
	
	Network.set_current_player(Network.player_order[
		(Network.player_order.find(Network.current_player.id) + 1) % Network.player_order.size()
	])
	
	grid_selector.process_mode = Node.PROCESS_MODE_INHERIT