From a495681453c97578cc4a408d6919c6879524a603 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 24 Oct 2024 18:31:08 +0200 Subject: next commit --- Stages/Wintermaul/Assets/thumbnail.png | Bin 0 -> 45394 bytes Stages/Wintermaul/Assets/thumbnail.png.import | 34 +++++++ Stages/Wintermaul/HUD.gd | 129 ++++++++++++++++++++++++-- Stages/Wintermaul/HUD.tscn | 8 +- Stages/Wintermaul/Wintermaul.tscn | 1 + Stages/Wintermaul/wintermaul.gd | 6 ++ 6 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 Stages/Wintermaul/Assets/thumbnail.png create mode 100644 Stages/Wintermaul/Assets/thumbnail.png.import (limited to 'Stages') diff --git a/Stages/Wintermaul/Assets/thumbnail.png b/Stages/Wintermaul/Assets/thumbnail.png new file mode 100644 index 0000000..42f9567 Binary files /dev/null and b/Stages/Wintermaul/Assets/thumbnail.png differ diff --git a/Stages/Wintermaul/Assets/thumbnail.png.import b/Stages/Wintermaul/Assets/thumbnail.png.import new file mode 100644 index 0000000..0cef320 --- /dev/null +++ b/Stages/Wintermaul/Assets/thumbnail.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ci7qydmwbanbp" +path="res://.godot/imported/thumbnail.png-a553bc324925dcdfb3e3587d2082a340.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Stages/Wintermaul/Assets/thumbnail.png" +dest_files=["res://.godot/imported/thumbnail.png-a553bc324925dcdfb3e3587d2082a340.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Stages/Wintermaul/HUD.gd b/Stages/Wintermaul/HUD.gd index 6eeb7da..1349bda 100644 --- a/Stages/Wintermaul/HUD.gd +++ b/Stages/Wintermaul/HUD.gd @@ -2,6 +2,15 @@ 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].get_hud()) + +signal attack_value_changed(value: int) + @onready var time: Label = %Time @onready var money: Label = %Money @onready var income: Label = %Income @@ -39,25 +48,38 @@ func _ready(): Client.placed_tower.connect(func(tower: Tower): tower.selected.connect(func(): var hud_data = tower.get_hud() - hud_data.name = tower.name - var groups = {"md5:1": [], "md5_2": []} - var selected_group = "md5" + 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) + var texture = AtlasTexture.new() + texture.atlas = preload("res://core_outdoor.png") + texture.region = Rect2(400, 432, 32, 48) + 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) + # TODO: build groups from current component configurations matches. md5 of property values? # TODO: do in tower.gd at select? + # TODO: probably do here at the selected signal and add to groups var at top if Tower.selected_towers.size() == 1: %SelectionContainer.visible = true %MultiSelectionContainer.visible = false - %SelectionData.add_child(hud_data) - %MultiSelectionList.add_child(hud_data.duplicate()) + redraw_select(hud_data) + %MultiSelectionList.add_child(multi_select_hud_data) elif Tower.selected_towers.size() > 1: - %SelectionContainer.visible = false %MultiSelectionContainer.visible = true - %MultiSelectionList.add_child(hud_data) + %MultiSelectionList.add_child(multi_select_hud_data) + + redraw_multiselect("", selected_group) ) + tower.deselected.connect(func(): if Tower.selected_towers.size() == 0: %SelectionContainer.visible = false @@ -70,10 +92,43 @@ func _ready(): elif Tower.selected_towers.size() == 1: %MultiSelectionContainer.visible = false %SelectionContainer.visible = true + %MultiSelectionList.get_node(NodePath(tower.name)).queue_free() elif Tower.selected_towers.size() > 1: # only remove deselected tower from list - %MultiSelectionList.get_node(NodePath(tower.name)).queue_free() + 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.selection_group_id_changed.connect(func(previous_id: String): + 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.get_hud()) ) + + tower.attack_value_changed.connect(func(value: int): + attack_value_changed.emit(value) + ) + ) + + Client.multi_select_finished.connect(func(): + selected_group = get_ordered_group_keys()[0] ) @@ -83,6 +138,64 @@ func _input(event: InputEvent): if event.is_action_pressed("players_list_toggle"): team_top.visible = not team_top.visible team_bottom.visible = not team_bottom.visible + + if %MultiSelectionContainer.visible and event.is_action_pressed("selection_cycle"): + var keys = get_ordered_group_keys() + var current_idx = keys.find(selected_group) + selected_group = keys[(current_idx + 1) % keys.size()] + + +func redraw_select(hud_data: Control): + for node in %SelectionData.get_children(): + node.queue_free() + + %SelectionData.add_child(hud_data) + + +func redraw_multiselect(previous_group: String, new_group: String): + 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) + idx += 1 + + for node in get_tree().get_nodes_in_group(previous_group): + node.modulate = Color(0.5, 0.5, 0.5) + for node in get_tree().get_nodes_in_group(new_group): + node.modulate = Color(1.0, 1.0, 1.0) + + +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] + + return ( + (node_a.attack_range / 8) + node_a.attack_power + node_a.attack_speed + > + (node_b.attack_range / 8) + node_b.attack_power + node_b.attack_speed + ) + ) + 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: diff --git a/Stages/Wintermaul/HUD.tscn b/Stages/Wintermaul/HUD.tscn index 024910f..52dde03 100644 --- a/Stages/Wintermaul/HUD.tscn +++ b/Stages/Wintermaul/HUD.tscn @@ -40,6 +40,7 @@ action = &"spawn_unit" events = [SubResource("InputEventAction_t6x4q")] [node name="HUD" type="CanvasLayer"] +visible = false script = ExtResource("1_2bu0v") [node name="Panel" type="PanelContainer" parent="."] @@ -239,8 +240,8 @@ layout_mode = 2 unique_name_in_owner = true custom_minimum_size = Vector2(200, 0) layout_mode = 2 -size_flags_horizontal = 6 -size_flags_stretch_ratio = 2.0 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 100.0 [node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/MultiSelectionContainer"] layout_mode = 2 @@ -258,7 +259,7 @@ last_wrap_alignment = 1 unique_name_in_owner = true custom_minimum_size = Vector2(200, 0) layout_mode = 2 -size_flags_horizontal = 6 +size_flags_horizontal = 10 size_flags_stretch_ratio = 2.0 [node name="SelectionData" type="MarginContainer" parent="MarginContainer/HBoxContainer/SelectionContainer"] @@ -280,6 +281,7 @@ text = "T" unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 10 +size_flags_vertical = 8 size_flags_stretch_ratio = 0.0 [node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/SpawnBox"] diff --git a/Stages/Wintermaul/Wintermaul.tscn b/Stages/Wintermaul/Wintermaul.tscn index 6cf2d05..bebc79c 100644 --- a/Stages/Wintermaul/Wintermaul.tscn +++ b/Stages/Wintermaul/Wintermaul.tscn @@ -23,6 +23,7 @@ script = ExtResource("1_o88ua") [node name="HUD" parent="." instance=ExtResource("2_v3f6l")] unique_name_in_owner = true +visible = true [node name="Map" type="TileMapLayer" parent="."] unique_name_in_owner = true diff --git a/Stages/Wintermaul/wintermaul.gd b/Stages/Wintermaul/wintermaul.gd index b638c97..9219a29 100644 --- a/Stages/Wintermaul/wintermaul.gd +++ b/Stages/Wintermaul/wintermaul.gd @@ -67,6 +67,12 @@ func _ready(): # initialize lives display update_lives("top", 0) update_lives("bottom", 0) + + %HUD.attack_value_changed.connect(func(value: int): + Network.update_player.rpc(Client.player.id, { + "money": -(value * 10), + }) + ) func _process(_delta: float) -> void: -- cgit v1.2.3