From e116ac4769e5730122f8692c0a2d253b2df36235 Mon Sep 17 00:00:00 2001 From: zcembbi Date: Tue, 10 Sep 2024 16:03:27 +0300 Subject: [PATCH] Add basic top ui functionality --- Main.tscn | 9 +++- storm/storm_manager.gd | 1 + ui/UI.tscn | 105 ++++++++++++++++++++++++++++++++++++++ ui/number.gd | 13 +++++ ui/ui-elements.png | Bin 0 -> 4459 bytes ui/ui-elements.png.import | 34 ++++++++++++ 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 ui/UI.tscn create mode 100644 ui/number.gd create mode 100644 ui/ui-elements.png create mode 100644 ui/ui-elements.png.import diff --git a/Main.tscn b/Main.tscn index 336395e..15e1edb 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,9 +1,16 @@ -[gd_scene load_steps=2 format=3 uid="uid://5ske2hm55rce"] +[gd_scene load_steps=4 format=3 uid="uid://5ske2hm55rce"] +[ext_resource type="PackedScene" uid="uid://n2lpy72tkyc8" path="res://storm/StormManager.tscn" id="1_gcxt1"] +[ext_resource type="PackedScene" uid="uid://bxctpr0tfqidf" path="res://ui/UI.tscn" id="1_ve2mn"] [ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"] [node name="Main" type="Node2D"] +[node name="StormManager" parent="." instance=ExtResource("1_gcxt1")] + +[node name="UI" parent="." instance=ExtResource("1_ve2mn")] +offset_right = 640.0 + [node name="Control" type="Control" parent="."] layout_mode = 3 anchors_preset = 0 diff --git a/storm/storm_manager.gd b/storm/storm_manager.gd index e959e95..2a7d43f 100644 --- a/storm/storm_manager.gd +++ b/storm/storm_manager.gd @@ -2,6 +2,7 @@ extends Node @onready var globals = Data.data.globals + var game_time = 0 var last_flood_time = 0 var current_flood_state = 0 diff --git a/ui/UI.tscn b/ui/UI.tscn new file mode 100644 index 0000000..e0ee260 --- /dev/null +++ b/ui/UI.tscn @@ -0,0 +1,105 @@ +[gd_scene load_steps=3 format=3 uid="uid://bxctpr0tfqidf"] + +[ext_resource type="Texture2D" uid="uid://dsy18stvo2pu5" path="res://ui/ui-elements.png" id="1_cx752"] +[ext_resource type="Script" path="res://ui/number.gd" id="2_ei01o"] + +[node name="UI" type="MarginContainer"] +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 44.0 +grow_horizontal = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="LeftCounters" type="HBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="FloodLevel" type="MarginContainer" parent="HBoxContainer/LeftCounters"] +layout_mode = 2 + +[node name="Background" type="NinePatchRect" parent="HBoxContainer/LeftCounters/FloodLevel"] +custom_minimum_size = Vector2(160, 40) +layout_mode = 2 +texture = ExtResource("1_cx752") +region_rect = Rect2(779.878, 10.1175, 231.253, 25.8529) + +[node name="Title" type="Label" parent="HBoxContainer/LeftCounters/FloodLevel/Background"] +layout_mode = 2 +offset_top = 9.0 +offset_right = 112.0 +offset_bottom = 32.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "Flood Level:" +horizontal_alignment = 1 + +[node name="Number" type="Label" parent="HBoxContainer/LeftCounters/FloodLevel/Background"] +layout_mode = 2 +offset_left = 112.0 +offset_top = 9.0 +offset_right = 148.0 +offset_bottom = 32.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +horizontal_alignment = 2 +script = ExtResource("2_ei01o") + +[node name="RightCounters" type="VBoxContainer" parent="HBoxContainer"] +layout_direction = 2 +layout_mode = 2 + +[node name="Population" type="MarginContainer" parent="HBoxContainer/RightCounters"] +layout_mode = 2 + +[node name="Background" type="NinePatchRect" parent="HBoxContainer/RightCounters/Population"] +custom_minimum_size = Vector2(160, 20) +layout_mode = 2 +texture = ExtResource("1_cx752") +region_rect = Rect2(779.878, 10.1175, 231.253, 25.8529) + +[node name="Title" type="Label" parent="HBoxContainer/RightCounters/Population/Background"] +layout_mode = 2 +offset_top = -2.0 +offset_right = 112.0 +offset_bottom = 21.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "Population:" +horizontal_alignment = 1 + +[node name="Number" type="Label" parent="HBoxContainer/RightCounters/Population/Background"] +layout_mode = 2 +offset_left = 112.0 +offset_top = -1.0 +offset_right = 148.0 +offset_bottom = 22.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "10" +horizontal_alignment = 2 + +[node name="Resources" type="MarginContainer" parent="HBoxContainer/RightCounters"] +layout_mode = 2 + +[node name="Background" type="NinePatchRect" parent="HBoxContainer/RightCounters/Resources"] +custom_minimum_size = Vector2(160, 20) +layout_mode = 2 +texture = ExtResource("1_cx752") +region_rect = Rect2(779.878, 10.1175, 231.253, 25.8529) + +[node name="Title" type="Label" parent="HBoxContainer/RightCounters/Resources/Background"] +layout_mode = 2 +offset_top = -2.0 +offset_right = 112.0 +offset_bottom = 21.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "Resources:" +horizontal_alignment = 1 + +[node name="Number" type="Label" parent="HBoxContainer/RightCounters/Resources/Background"] +layout_mode = 2 +offset_left = 112.0 +offset_top = -1.0 +offset_right = 148.0 +offset_bottom = 22.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "10" +horizontal_alignment = 2 diff --git a/ui/number.gd b/ui/number.gd new file mode 100644 index 0000000..c1adeb2 --- /dev/null +++ b/ui/number.gd @@ -0,0 +1,13 @@ +extends Label + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + var floodlevel = Persister.get_value("flood_level") + if floodlevel: + set_text(str(floodlevel)) + else: + set_text(str(0)) diff --git a/ui/ui-elements.png b/ui/ui-elements.png new file mode 100644 index 0000000000000000000000000000000000000000..81312ecc62894d87faceec67747d0d8a688606f6 GIT binary patch literal 4459 zcmeHJ`&&}!7XH|xX*W?HtGJZl~uH)GLV3cYC-Rr;;(>bN$EK8{)8J9SHZpfPj#uDD+>3SR~Ol zGzEABe>!Y>*9@$KK3WH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@T*=I_!mfwTVZ?M^EL`gg{>+xbJ7FE9gr=IJm`hj}{8 k)4^~tn5V=4g$@Je+b_D!ux8IL0q}#{9vUdvw(p<+1&|#;F#rGn literal 0 HcmV?d00001 diff --git a/ui/ui-elements.png.import b/ui/ui-elements.png.import new file mode 100644 index 0000000..aa737a0 --- /dev/null +++ b/ui/ui-elements.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dsy18stvo2pu5" +path="res://.godot/imported/ui-elements.png-9343eafe24264ca7277498c1badb542f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/ui-elements.png" +dest_files=["res://.godot/imported/ui-elements.png-9343eafe24264ca7277498c1badb542f.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