summaryrefslogtreecommitdiff
path: root/Stages/Wintermaul
diff options
context:
space:
mode:
Diffstat (limited to 'Stages/Wintermaul')
-rw-r--r--Stages/Wintermaul/HUD.gd215
-rw-r--r--Stages/Wintermaul/hud_tower.gd7
2 files changed, 83 insertions, 139 deletions
diff --git a/Stages/Wintermaul/HUD.gd b/Stages/Wintermaul/HUD.gd
index 34fc0ea..62a5abd 100644
--- a/Stages/Wintermaul/HUD.gd
+++ b/Stages/Wintermaul/HUD.gd
@@ -2,13 +2,6 @@ class_name HUD
extends CanvasLayer
-var selection_groups := {}
-var selected_group := "":
- set(value):
- redraw_multiselect(selected_group, value)
- selected_group = value
- redraw_select(selection_groups[selected_group][0])
-
@onready var time: Label = %Time
@onready var money: Label = %Money
@onready var income: Label = %Income
@@ -39,94 +32,74 @@ func _ready():
%TowerConfigurationsContainer.visible = false
)
- # multi select
+ # multi select setup
%SelectionContainer.visible = false
%MultiSelectionContainer.visible = false
- Client.placed_tower.connect(func(tower: Tower):
- if tower.owner_id == multiplayer.get_unique_id():
- tower.selected.connect(func():
- var multi_select_hud_data = TextureRect.new()
- multi_select_hud_data.name = tower.name
- multi_select_hud_data.modulate = Color(0.5, 0.5, 0.5)
- multi_select_hud_data.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
- multi_select_hud_data.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
- multi_select_hud_data.custom_minimum_size = Vector2(32, 64)
- var texture = AtlasTexture.new()
- texture.atlas = preload("res://Towers/Assets/spritesheet.png")
- texture.region = Rect2(5, 1, 62, 95)
- multi_select_hud_data.texture = texture
-
- if not tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id] = []
- selection_groups[tower.selection_group_id].append(tower)
- multi_select_hud_data.add_to_group(tower.selection_group_id)
-
- if Tower.selected_towers.size() == 1:
- %SelectionContainer.visible = true
- %MultiSelectionContainer.visible = false
-
- %MultiSelectionList.add_child(multi_select_hud_data)
- selected_group = tower.selection_group_id
- elif Tower.selected_towers.size() > 1:
- %MultiSelectionContainer.visible = true
-
- %MultiSelectionList.add_child(multi_select_hud_data)
-
- redraw_multiselect("", selected_group)
-
- redraw_select(tower)
- )
+
+ # add tower to selection
+ Client.selection.added_to_group.connect(func(nodes: Array[Node], id: String):
+ for tower: Tower in nodes:
+ var multi_select_hud_data = TextureRect.new()
+ multi_select_hud_data.modulate = Color(0.5, 0.5, 0.5)
+ multi_select_hud_data.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
+ multi_select_hud_data.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
+ multi_select_hud_data.custom_minimum_size = Vector2(32, 64)
+ var texture = AtlasTexture.new()
+ texture.atlas = preload("res://Towers/Assets/spritesheet.png")
+ texture.region = Rect2(5, 1, 62, 95)
+ multi_select_hud_data.texture = texture
+
+ multi_select_hud_data.set_meta("tower", tower)
+ tower.set_meta("multi_select_hud", multi_select_hud_data)
+
+ multi_select_hud_data.add_to_group(id)
+ %MultiSelectionList.add_child(multi_select_hud_data)
+
+ if Client.selection.node_count == 1:
+ %SelectionContainer.visible = true
+ %MultiSelectionContainer.visible = false
+
+ elif Client.selection.node_count > 1:
+ %MultiSelectionContainer.visible = true
+
+ redraw_multiselect()
+ redraw_select(tower)
+ )
+
+ # remove tower from selection
+ Client.selection.removed_from_group.connect(func(nodes: Array[Node], _id: String):
+ for tower: Tower in nodes:
+ if Client.selection.node_count == 0:
+ %SelectionContainer.visible = false
+ %MultiSelectionContainer.visible = false
+
+ elif Client.selection.node_count == 1:
+ %MultiSelectionContainer.visible = false
+ %SelectionContainer.visible = true
+
+ # catch free error for selecting in quick succcession by double click
+ if is_instance_valid(tower.get_meta("multi_select_hud")):
+ tower.get_meta("multi_select_hud").queue_free()
- tower.deselected.connect(func():
- if Tower.selected_towers.size() == 0:
- %SelectionContainer.visible = false
- %MultiSelectionContainer.visible = false
-
- for child in %MultiSelectionList.get_children():
- child.queue_free()
- elif Tower.selected_towers.size() == 1:
- %MultiSelectionContainer.visible = false
- %SelectionContainer.visible = true
-
- var node = %MultiSelectionList.get_node_or_null(NodePath(tower.name))
- if node:
- node.queue_free()
- elif Tower.selected_towers.size() > 1:
- # only remove deselected tower from list
- var node = %MultiSelectionList.get_node_or_null(NodePath(tower.name))
- if node: # when double click selecting in quick succession not found error
- node.queue_free()
-
- if tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id].erase(tower)
- if selection_groups[tower.selection_group_id].is_empty():
- selection_groups.erase(tower.selection_group_id)
- )
+ tower.remove_meta("multi_select_hud")
+ )
+
+ # move tower to new selection group
+ Client.selection.moved_to_group.connect(func(nodes: Array[Node], previous_id: String, new_id: String):
+ for tower: Tower in nodes:
+ tower.get_meta("multi_select_hud").remove_from_group(previous_id)
+ tower.get_meta("multi_select_hud").add_to_group(new_id)
- tower.selection_group_id_changed.connect(func(previous_id: String):
- #Client.selection.change_selection_group_id([tower], previous_id, tower.selection_group_id)
-
- if not tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id] = []
- selection_groups[tower.selection_group_id].append(tower)
- %MultiSelectionList.get_node(NodePath(tower.name)).add_to_group(tower.selection_group_id)
-
- selection_groups[previous_id].erase(tower)
- if selection_groups[previous_id].is_empty():
- selection_groups.erase(previous_id)
- if previous_id == selected_group:
- selected_group = tower.selection_group_id
- %MultiSelectionList.get_node(NodePath(tower.name)).remove_from_group(previous_id)
-
- if tower.name == selection_groups[tower.selection_group_id][0].name:
- redraw_select(tower)
- )
+ if Client.selection.has_node_in_group(tower, new_id):
+ redraw_select(tower)
+ redraw_multiselect(previous_id, new_id)
)
- Client.multi_select_finished.connect(func(_nodes):
- var keys = get_ordered_group_keys()
- if keys.size() > 0:
- selected_group = keys[0]
+ # redraw on selected group change
+ Client.selection.selected_group_changed.connect(func(previous_id: String, new_id: String):
+ if Client.selection.get_selected_nodes():
+ redraw_select(Client.selection.get_selected_nodes()[0])
+ redraw_multiselect(previous_id, new_id)
)
@@ -138,70 +111,44 @@ func _input(event: InputEvent):
team_bottom.visible = not team_bottom.visible
if event.is_action_pressed("selection_cycle") and %MultiSelectionContainer.visible:
- var keys = get_ordered_group_keys()
- var current_idx = keys.find(selected_group)
- selected_group = keys[(current_idx + 1) % keys.size()]
+ if Input.is_action_pressed("reverse_cycle_direction"):
+ Client.selection.go_to_previous()
+ else:
+ Client.selection.go_to_next()
func redraw_select(tower: Tower):
%TowerData.current_tower = tower
-func redraw_multiselect(previous_group: String, new_group: String):
+func redraw_multiselect(previous_group: String = "", new_group: String = Client.selection.selected_group):
var idx = 0
- for group_key in get_ordered_group_keys():
- var group = selection_groups[group_key]
- for node in group:
- var selection_node = %MultiSelectionList.get_node_or_null(NodePath(node.name))
- if selection_node: # when double click selecting in quick succession not found error
- %MultiSelectionList.move_child(selection_node, idx)
+ for id in Client.selection.get_ordered_group_ids():
+ var group = Client.selection.selection_groups[id]
+ for node: Tower in group:
+ # when double click selecting in quick succession not found error
+ if (node.has_meta("multi_select_hud") and
+ is_instance_valid(node.get_meta("multi_select_hud"))
+ ):
+ %MultiSelectionList.move_child(node.get_meta("multi_select_hud"), idx)
idx += 1
+ # wait for nodes to be in the correct groups
+ await get_tree().process_frame
+
for node in get_tree().get_nodes_in_group(previous_group):
node.modulate = Color(0.5, 0.5, 0.5)
- var tower = Client.current_stage.get_node_or_null("%Towers/" + node.name)
+ var tower = node.get_meta("tower")
if tower:
tower.is_highlighted = false
+
for node in get_tree().get_nodes_in_group(new_group):
node.modulate = Color(1.0, 1.0, 1.0)
- var tower = Client.current_stage.get_node_or_null("%Towers/" + node.name)
+ var tower = node.get_meta("tower")
if tower:
tower.is_highlighted = true
-func get_ordered_group_keys() -> Array:
- var keys = selection_groups.keys()
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
-
- return group_a.size() > group_b.size()
- )
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
- var node_a = group_a[0]
- var node_b = group_b[0]
- var level_a = 0
- var level_b = 0
-
- for component in node_a.components.values():
- level_a += component.level
- for component in node_b.components.values():
- level_b += component.level
-
- return level_a > level_b
- )
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
-
- return group_a[0].components.size() > group_b[0].components.size()
- )
-
- return keys
-
-
func _on_build_mode_button_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
if Client.state is StateDefault:
diff --git a/Stages/Wintermaul/hud_tower.gd b/Stages/Wintermaul/hud_tower.gd
index d24443b..7a7ef69 100644
--- a/Stages/Wintermaul/hud_tower.gd
+++ b/Stages/Wintermaul/hud_tower.gd
@@ -36,10 +36,7 @@ func redraw_components():
func get_selected_towers() -> Array:
- var hud: HUD = Client.current_stage.get_node("%HUD")
-
- # TODO: key not found error sometimes?
- return hud.selection_groups[hud.selected_group].duplicate()
+ return Client.selection.get_selected_nodes().duplicate()
func _on_range_gui_input(event: InputEvent) -> void:
@@ -180,7 +177,7 @@ func _on_range_level_up_pressed() -> void:
Client.current_stage.add_status_message("Not enough money to level up")
return
- for tower: Tower in towers:
+ for tower in towers:
var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Range)
tower_component.level += 1