summaryrefslogtreecommitdiff
path: root/Scripts/UI/UI.gd
blob: a86d69dc5c0db250b237412a3a2f9922a36fbd9f (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
extends CanvasLayer
class_name UI

@export var health_label : Label
@export var machette_sprite : TextureRect

@export var main_hud : Control
@export var inventory_panel : Control

@export var tool_slot_1 : PanelContainer
@export var tool_slot_2 : PanelContainer

@export var mask_slot_1 : PanelContainer
@export var mask_slot_2 : PanelContainer

@export var inventory_equip : Control
@export var inventory_secondary : Control
@export var inventory_1 : Control
@export var inventory_2 : Control
@export var inventory_3 : Control
@export var inventory_4 : Control

@export var bubble_machette_anim : AnimationPlayer
@export var bubble_mask_anim : AnimationPlayer

@export var death_animator : AnimationPlayer

@export var level_animator : AnimationPlayer
@export var level_label : Label
@export var level_label_id : Label

@export var level_names : Array[String]

var curr_tool : bool = false # false is 1, true is 2

var is_inv_open : bool = false

func _ready() -> void:
	# absolutely disgusting.
	inventory_equip.i_was_pressed.connect(_on_inventorybtn_pressed)
	inventory_secondary.i_was_pressed.connect(_on_inventorybtn_pressed)
	inventory_1.i_was_pressed.connect(_on_inventorybtn_pressed)
	inventory_2.i_was_pressed.connect(_on_inventorybtn_pressed)
	inventory_3.i_was_pressed.connect(_on_inventorybtn_pressed)
	inventory_4.i_was_pressed.connect(_on_inventorybtn_pressed)

func _input(_event: InputEvent) -> void:
	if Input.is_action_just_pressed("open_bag"):
		if !is_inv_open:
			main_hud.visible = false
			main_hud.mouse_filter = Control.MOUSE_FILTER_IGNORE
			inventory_panel.visible = true
			main_hud.mouse_filter = Control.MOUSE_FILTER_STOP
		else:
			main_hud.visible = true
			main_hud.mouse_filter = Control.MOUSE_FILTER_STOP
			inventory_panel.visible = false
			main_hud.mouse_filter = Control.MOUSE_FILTER_IGNORE
		is_inv_open = !is_inv_open
		UIConnector.is_inv_open = is_inv_open

func display_health(n : int) -> void:
	health_label.text = "♥".repeat(n)

func add_machette() -> void:
	machette_sprite.visible = true
	bubble_machette_anim.play("toast")

func remove_machette() -> void:
	machette_sprite.visible = false

func switch_tool() -> void:
	if curr_tool:
		tool_slot_1.theme_type_variation = "SlotSelected"
		tool_slot_2.theme_type_variation = "SlotDeselected"
	else:
		tool_slot_2.theme_type_variation = "SlotSelected"
		tool_slot_1.theme_type_variation = "SlotDeselected"
	
	curr_tool = !curr_tool

var names = ["Dash", "Grapple", "Minions", "Freeze"]

func update_masks(masks : Array[int]) -> void:
	# are you disgusted?
	for mname in names:
		inventory_equip.get_node(mname).visible = false
		inventory_secondary.get_node(mname).visible = false
		mask_slot_1.get_node(mname).visible = false
		mask_slot_2.get_node(mname).visible = false
		inventory_1.get_node(mname).visible = false
		inventory_2.get_node(mname).visible = false
		inventory_3.get_node(mname).visible = false
		inventory_4.get_node(mname).visible = false
	if masks[0] != -1:
		inventory_equip.get_node(names[masks[0]]).visible = true
		mask_slot_1.get_node(names[masks[0]]).visible = true
		mask_slot_1.theme_type_variation = "SlotSelected"
	if masks[1] != -1:
		inventory_secondary.get_node(names[masks[1]]).visible = true
		mask_slot_2.get_node(names[masks[1]]).visible = true
	for mname in names:
		inventory_1.get_node(mname).visible = false
	if masks[2] != -1:
		inventory_1.get_node(names[masks[2]]).visible = true
		inventory_1.mask_type = masks[2]
	if masks[3] != -1:
		inventory_2.get_node(names[masks[3]]).visible = true
		inventory_2.mask_type = masks[3]
	if masks[4] != -1:
		inventory_3.get_node(names[masks[4]]).visible = true
		inventory_3.mask_type = masks[4]
	if masks[5] != -1:
		inventory_4.get_node(names[masks[5]]).visible = true
		inventory_4.mask_type = masks[5]

func death() -> void:
	death_animator.play("death")

func death_finished() -> void:
	get_tree().get_root().get_node("Node2D").restart()

var was_selecting : bool = false
var prev_selecting_mask : int = -1
var prev_selecting_index : int = -1
var prev_selecting_btn : Button

func _on_inventorybtn_pressed(mask : int, index : int, btn : Button) -> void:
	print("pressed there")
	# i'm sorry.
	var player_inventory : PlayerInventory = get_tree().get_root().get_node("Node2D/Player/PlayerInventory")

	if !was_selecting:
		was_selecting = true
		prev_selecting_mask = mask
		prev_selecting_index = index
		prev_selecting_btn = btn
		print(prev_selecting_mask, " ", prev_selecting_index)
	else:
		was_selecting = false
		player_inventory.mask_inventory[index] = prev_selecting_mask
		player_inventory.mask_inventory[prev_selecting_index] = mask
		btn.mask_type = prev_selecting_mask
		prev_selecting_btn.mask_type = mask
		update_masks(player_inventory.mask_inventory)
		prev_selecting_mask = -1
		prev_selecting_index = -1
		prev_selecting_btn = null

func next_level(level : int) -> void:
	level_animator.play("enter")
	level_label.text = level_names[level]
	level_label_id.text = "Level " + str(level)

func show_mask_bubble() -> void:
	bubble_mask_anim.play("toast")