summaryrefslogtreecommitdiff
path: root/UI
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-06 12:31:04 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-06 12:31:04 +0200
commit9fe787ed8a6d23cf9ab1767392951e6af39ea8ae (patch)
tree5bd7ff20eda0033241748e21b91033f3176bfad7 /UI
parentb069ea91b095d80667475c06e62712c1bd7b537f (diff)
next commitHEADmain
Diffstat (limited to 'UI')
-rw-r--r--UI/HUD.tscn84
-rw-r--r--UI/hud.gd49
-rw-r--r--UI/theme.tres12
3 files changed, 124 insertions, 21 deletions
diff --git a/UI/HUD.tscn b/UI/HUD.tscn
index 5ef4b02..68c330e 100644
--- a/UI/HUD.tscn
+++ b/UI/HUD.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=22 format=3 uid="uid://d0mlxe0gcctle"]
+[gd_scene load_steps=23 format=3 uid="uid://d0mlxe0gcctle"]
[ext_resource type="Script" path="res://UI/hud.gd" id="1_rpghv"]
[ext_resource type="Texture2D" uid="uid://nypt5ybs2yjf" path="res://UI/Assets/ButtonBlocker.png" id="2_6o4l1"]
@@ -49,6 +49,13 @@ shader_parameter/adjust = 0.0
shader = ExtResource("3_v2jeg")
shader_parameter/adjust = 0.0
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8x67q"]
+content_margin_left = 1.0
+content_margin_top = 1.0
+content_margin_right = 1.0
+content_margin_bottom = 1.0
+bg_color = Color(1, 1, 1, 1)
+
[node name="HUD" type="CanvasLayer"]
script = ExtResource("1_rpghv")
@@ -75,112 +82,149 @@ offset_bottom = 14.0
grow_horizontal = 0
theme = ExtResource("2_he3is")
-[node name="HBoxContainer" type="HBoxContainer" parent="."]
+[node name="HBoxContainer2" type="HBoxContainer" parent="."]
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
+offset_top = -16.0
grow_horizontal = 2
grow_vertical = 0
theme = ExtResource("2_he3is")
+
+[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 8
+size_flags_stretch_ratio = 2.0
theme_override_constants/separation = 0
-[node name="ButtonBlocker" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonBlocker" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_tsgkc")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Blocker"
mouse_default_cursor_shape = 2
texture = ExtResource("2_6o4l1")
stretch_mode = 5
-[node name="ButtonDigger" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonDigger" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_vfiay")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Digger"
mouse_default_cursor_shape = 2
texture = ExtResource("3_585t4")
stretch_mode = 5
-[node name="ButtonMiner" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonMiner" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_22xig")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Miner"
mouse_default_cursor_shape = 2
texture = ExtResource("5_5j5y4")
stretch_mode = 5
-[node name="ButtonBasher" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonBasher" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_sotrm")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Basher"
mouse_default_cursor_shape = 2
texture = ExtResource("6_p3ffi")
stretch_mode = 5
-[node name="ButtonFloater" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonFloater" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_ekuuk")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Floater (not implemented)"
mouse_default_cursor_shape = 2
texture = ExtResource("6_qnbw6")
stretch_mode = 5
-[node name="ButtonBuilder" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonBuilder" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_gowx5")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Builder (not implemented)"
mouse_default_cursor_shape = 2
texture = ExtResource("8_wjtr6")
stretch_mode = 5
-[node name="ButtonClimber" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonClimber" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_soqe0")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Climber"
mouse_default_cursor_shape = 2
texture = ExtResource("9_tcs2a")
stretch_mode = 5
-[node name="ButtonPlus" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonPlus" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_ywy56")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Speed +"
mouse_default_cursor_shape = 2
texture = ExtResource("4_dku02")
stretch_mode = 5
-[node name="ButtonMinus" type="TextureRect" parent="HBoxContainer"]
+[node name="ButtonMinus" type="TextureRect" parent="HBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
texture_filter = 1
material = SubResource("ShaderMaterial_ascmt")
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
+tooltip_text = "Speed -"
mouse_default_cursor_shape = 2
texture = ExtResource("5_ybavg")
stretch_mode = 5
-[connection signal="gui_input" from="HBoxContainer/ButtonBlocker" to="." method="_on_button_blocker_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonDigger" to="." method="_on_button_digger_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonMiner" to="." method="_on_button_miner_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonBasher" to="." method="_on_button_basher_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonFloater" to="." method="_on_button_floater_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonBuilder" to="." method="_on_button_builder_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonClimber" to="." method="_on_button_climber_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonPlus" to="." method="_on_button_plus_gui_input"]
-[connection signal="gui_input" from="HBoxContainer/ButtonMinus" to="." method="_on_button_minus_gui_input"]
+[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer2/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_override_constants/margin_left = 4
+theme_override_constants/margin_top = 2
+
+[node name="CurrentButton" type="Label" parent="HBoxContainer2/HBoxContainer/MarginContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+clip_text = true
+
+[node name="PanelContainer" type="PanelContainer" parent="HBoxContainer2"]
+layout_mode = 2
+theme_override_styles/panel = SubResource("StyleBoxFlat_8x67q")
+
+[node name="Minimap" type="TextureRect" parent="HBoxContainer2/PanelContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(64, 32)
+layout_mode = 2
+size_flags_horizontal = 8
+
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonBlocker" to="." method="_on_button_blocker_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonDigger" to="." method="_on_button_digger_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonMiner" to="." method="_on_button_miner_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonBasher" to="." method="_on_button_basher_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonFloater" to="." method="_on_button_floater_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonBuilder" to="." method="_on_button_builder_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonClimber" to="." method="_on_button_climber_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonPlus" to="." method="_on_button_plus_gui_input"]
+[connection signal="gui_input" from="HBoxContainer2/HBoxContainer/ButtonMinus" to="." method="_on_button_minus_gui_input"]
diff --git a/UI/hud.gd b/UI/hud.gd
index 21bd2bc..d886a73 100644
--- a/UI/hud.gd
+++ b/UI/hud.gd
@@ -8,6 +8,7 @@ var selected_button: TextureRect :
selected_button = value
(selected_button.material as ShaderMaterial).set_shader_parameter("adjust", -1.0)
+ %CurrentButton.text = selected_button.tooltip_text
func _ready() -> void:
@@ -18,6 +19,54 @@ func _ready() -> void:
Game.speed_changed.connect(func():
%Speed.text = str(Game.speed).pad_decimals(1) + "x"
)
+
+ create_minimap()
+
+
+func create_minimap():
+ var maps := get_tree().get_nodes_in_group("map")
+ var image := Image.create_empty(%Minimap.size.x, $"%Minimap".size.y, false, Image.FORMAT_RGB8)
+ var minimap_scale = Vector2(image.get_size()) / get_viewport().get_visible_rect().size
+
+ for map: TileMapLayer in maps:
+ for cell_coords in map.get_used_cells():
+ var tile = map.get_cell_tile_data(cell_coords)
+ var tile_scale = minimap_scale * Vector2(map.tile_set.tile_size)
+ image.fill_rect(
+ Rect2(Vector2(cell_coords) * tile_scale, (tile_scale + Vector2(1,1)).max(Vector2(1, 1))),
+ tile.get_custom_data("color")
+ )
+
+ %Minimap.texture = ImageTexture.create_from_image(image)
+
+ var markers := {}
+ var timer = Timer.new()
+ timer.wait_time = 0.5
+ timer.one_shot = false
+ timer.autostart = true
+ timer.timeout.connect(func():
+ for node in markers.keys():
+ if is_instance_valid(node):
+ markers[node].position = (
+ node.global_position * minimap_scale
+ )
+ )
+ %Minimap.add_child(timer)
+ get_tree().current_scene.child_entered_tree.connect(func(node: Node):
+ if node is Unit:
+ var texture = Image.create_empty(1, 1, false, Image.FORMAT_RGB8)
+ texture.set_pixel(0, 0, Color("#fff"))
+ var sprite = Sprite2D.new()
+ sprite.texture = ImageTexture.create_from_image(texture)
+ sprite.position = Vector2.ZERO
+ %Minimap.add_child(sprite)
+ markers[node] = sprite
+
+ node.tree_exiting.connect(func():
+ markers.erase(node)
+ sprite.queue_free()
+ )
+ )
func _on_button_blocker_gui_input(event: InputEvent) -> void:
diff --git a/UI/theme.tres b/UI/theme.tres
index 151ae16..5acc738 100644
--- a/UI/theme.tres
+++ b/UI/theme.tres
@@ -1,7 +1,17 @@
-[gd_resource type="Theme" load_steps=2 format=3 uid="uid://lpvaxe35v64b"]
+[gd_resource type="Theme" load_steps=3 format=3 uid="uid://lpvaxe35v64b"]
[ext_resource type="FontFile" uid="uid://deqwl54q7v6ss" path="res://UI/Assets/Minimal5x7.ttf" id="1_vykgj"]
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jv7v8"]
+content_margin_left = 2.0
+content_margin_top = 2.0
+content_margin_right = 2.0
+content_margin_bottom = 2.0
+bg_color = Color(0.165656, 0.165656, 0.165656, 1)
+
[resource]
Label/font_sizes/font_size = 16
Label/fonts/font = ExtResource("1_vykgj")
+TooltipLabel/font_sizes/font_size = 16
+TooltipLabel/fonts/font = ExtResource("1_vykgj")
+TooltipPanel/styles/panel = SubResource("StyleBoxFlat_jv7v8")