just reorganised files thats it
This commit is contained in:
124
UI/EnergyBar/energy_bar.gd
Normal file
124
UI/EnergyBar/energy_bar.gd
Normal file
@@ -0,0 +1,124 @@
|
||||
class_name EnergyBar
|
||||
extends Control
|
||||
|
||||
@export var cell_icon_tex: Texture
|
||||
@export var bar_overlay: TextureRect
|
||||
@export var progress_bar: ProgressBar
|
||||
@export var big_progress_bar: ProgressBar
|
||||
@export var secondary_progress_bar: ProgressBar
|
||||
@export var bg: TextureRect
|
||||
var cell_icons: Array[TextureRect]
|
||||
var energy: float = 0
|
||||
var secondary_energy: float = 0 :
|
||||
get():
|
||||
return secondary_energy
|
||||
set(value):
|
||||
secondary_energy = value
|
||||
secondary_progress_bar.value = secondary_energy
|
||||
var prev_energy_int: int = 0
|
||||
var max_energy: float = 0 :
|
||||
get():
|
||||
return max_energy
|
||||
set(value):
|
||||
max_energy = value
|
||||
energy = max_energy
|
||||
var secondary_max_energy: float = 0:
|
||||
get():
|
||||
return secondary_max_energy
|
||||
set(value):
|
||||
secondary_max_energy = value
|
||||
secondary_energy = secondary_max_energy
|
||||
secondary_progress_bar.visible = true
|
||||
secondary_progress_bar.max_value = secondary_max_energy
|
||||
|
||||
|
||||
#TODO: we can just create all 12 of these not even in a script, just create them
|
||||
#and use the bar overlay to hide the unused ones, we just need to change the algorithm
|
||||
#for setting the used ones invisible to account for the ones that are there but hidden
|
||||
func create_discrete_icons(new_energy: int) -> void:
|
||||
bg.visible = true
|
||||
progress_bar.visible = true
|
||||
big_progress_bar.visible = false
|
||||
for icon: TextureRect in cell_icons:
|
||||
icon.queue_free()
|
||||
if new_energy < 12:
|
||||
bar_overlay.visible = true
|
||||
bar_overlay.texture.region = Rect2(117.0 * (-new_energy + 11), 0.0, 117.0, 442.0)
|
||||
#progress_bar.position = Vector2(-101.0, -430.0 + ((-new_energy + 12.0) * 27.0))
|
||||
#progress_bar.size = Vector2(60.0, 316.0 - ((-new_energy + 12.0) * 27.0))
|
||||
else:
|
||||
bar_overlay.visible = false
|
||||
#progress_bar.position = Vector2(-101.0, -430.0)
|
||||
#progress_bar.size = Vector2(60.0, 316.0)
|
||||
progress_bar.position = Vector2(-101.0, -430.0 + ((-new_energy + 12.0) * 27.0))
|
||||
progress_bar.size = Vector2(60.0, 316.0 - ((-new_energy + 12.0) * 27.0))
|
||||
cell_icons = []
|
||||
energy = new_energy
|
||||
for x: int in energy:
|
||||
var new_icon: TextureRect = TextureRect.new()
|
||||
new_icon.texture = cell_icon_tex
|
||||
#new_icon.expand_mode = TextureRect.EXPAND_FIT_HEIGHT_PROPORTIONAL
|
||||
#new_icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
new_icon.size = Vector2(42.0, 35.0)
|
||||
new_icon.position = Vector2(-92, -150 + (-27 * x))
|
||||
cell_icons.append(new_icon)
|
||||
add_child(new_icon)
|
||||
progress_bar.max_value = max_energy
|
||||
progress_bar.value = max_energy
|
||||
|
||||
|
||||
func enable_progress_bar() -> void:
|
||||
for icon: TextureRect in cell_icons:
|
||||
icon.queue_free()
|
||||
cell_icons = []
|
||||
progress_bar.visible = true
|
||||
big_progress_bar.visible = true
|
||||
bar_overlay.visible = false
|
||||
bg.visible = false
|
||||
progress_bar.max_value = max_energy
|
||||
progress_bar.value = max_energy
|
||||
big_progress_bar.max_value = max_energy
|
||||
big_progress_bar.value = max_energy
|
||||
|
||||
|
||||
func blank() -> void:
|
||||
progress_bar.visible = false
|
||||
bar_overlay.visible = false
|
||||
for icon: TextureRect in cell_icons:
|
||||
icon.queue_free()
|
||||
cell_icons = []
|
||||
|
||||
|
||||
func gain_secondary_energy(energy_gained: float, _energy_type: Data.EnergyType = Data.EnergyType.DISCRETE) -> void:
|
||||
if secondary_energy >= secondary_max_energy:
|
||||
return
|
||||
secondary_energy += energy_gained
|
||||
|
||||
|
||||
func disable_secondary_energy() -> void:
|
||||
secondary_progress_bar.visible = false
|
||||
|
||||
|
||||
func use_energy(energy_used: float, energy_type: Data.EnergyType = Data.EnergyType.DISCRETE) -> void:
|
||||
if energy <= 0:
|
||||
return
|
||||
if energy_type == Data.EnergyType.DISCRETE:
|
||||
for x: int in int(energy_used):
|
||||
energy -= 1
|
||||
cell_icons[energy].visible = false
|
||||
energy = floorf(energy)
|
||||
else:
|
||||
energy -= energy_used
|
||||
progress_bar.value = energy
|
||||
big_progress_bar.value = energy
|
||||
|
||||
|
||||
func gain_energy(energy_gained: float, energy_type: Data.EnergyType = Data.EnergyType.DISCRETE) -> void:
|
||||
if energy >= max_energy:
|
||||
return
|
||||
energy += energy_gained
|
||||
progress_bar.value = energy
|
||||
big_progress_bar.value = energy
|
||||
if energy_type == Data.EnergyType.DISCRETE and int(energy) > prev_energy_int:
|
||||
cell_icons[int(energy) - 1].visible = true
|
||||
prev_energy_int = int(energy)
|
||||
1
UI/EnergyBar/energy_bar.gd.uid
Normal file
1
UI/EnergyBar/energy_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://gjcl34fan741
|
||||
141
UI/EnergyBar/energy_bar.tscn
Normal file
141
UI/EnergyBar/energy_bar.tscn
Normal file
@@ -0,0 +1,141 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://c2id8hjico4w8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://gjcl34fan741" path="res://UI/EnergyBar/energy_bar.gd" id="1_rdnti"]
|
||||
[ext_resource type="Texture2D" uid="uid://bm13bgpre6ubr" path="res://Assets/Textures/energy_cell.png" id="2_q48n7"]
|
||||
[ext_resource type="Texture2D" uid="uid://b1y1d1ge4fl8p" path="res://Assets/Textures/energy_bar.png" id="3_d65ol"]
|
||||
[ext_resource type="Texture2D" uid="uid://c0kwkv021p7gl" path="res://Assets/Textures/energy_bar_bg3.png" id="3_efdny"]
|
||||
[ext_resource type="Texture2D" uid="uid://3vqulb1vpy7h" path="res://Assets/Textures/energy_bar_bg.png" id="3_wymtn"]
|
||||
[ext_resource type="Texture2D" uid="uid://cxh488oh3jtr7" path="res://Assets/Textures/energy_bar_overlay.png" id="4_77ucw"]
|
||||
[ext_resource type="Texture2D" uid="uid://0ru2mv88fn4i" path="res://Assets/Textures/energy_bar_bg2.png" id="4_eh880"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8eabt"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_77ucw"]
|
||||
bg_color = Color(0, 0.667, 0.87, 1)
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_x1ntx"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_efdny"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wymtn"]
|
||||
atlas = ExtResource("4_77ucw")
|
||||
region = Rect2(0, 0, 117, 442)
|
||||
|
||||
[node name="EnergyBar" type="Control" node_paths=PackedStringArray("bar_overlay", "progress_bar", "big_progress_bar", "secondary_progress_bar", "bg")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
script = ExtResource("1_rdnti")
|
||||
cell_icon_tex = ExtResource("2_q48n7")
|
||||
bar_overlay = NodePath("Foreground/LimitOverlay")
|
||||
progress_bar = NodePath("ProgressBar")
|
||||
big_progress_bar = NodePath("ProgressBar2")
|
||||
secondary_progress_bar = NodePath("Background2/ProgressBar2")
|
||||
bg = NodePath("Background")
|
||||
|
||||
[node name="Background4" type="TextureRect" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = -142.0
|
||||
offset_top = -461.0
|
||||
offset_right = -25.0
|
||||
offset_bottom = -19.0
|
||||
texture = ExtResource("3_wymtn")
|
||||
|
||||
[node name="Background3" type="TextureRect" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = -142.0
|
||||
offset_top = -461.0
|
||||
offset_right = -25.0
|
||||
offset_bottom = -19.0
|
||||
texture = ExtResource("3_efdny")
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="."]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -101.0
|
||||
offset_top = -430.0
|
||||
offset_right = -41.0
|
||||
offset_bottom = -114.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxEmpty_8eabt")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_77ucw")
|
||||
value = 100.0
|
||||
fill_mode = 3
|
||||
show_percentage = false
|
||||
|
||||
[node name="ProgressBar2" type="ProgressBar" parent="."]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -95.0
|
||||
offset_top = -448.0
|
||||
offset_right = -47.0
|
||||
offset_bottom = -114.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxEmpty_x1ntx")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_77ucw")
|
||||
value = 100.0
|
||||
fill_mode = 3
|
||||
show_percentage = false
|
||||
|
||||
[node name="Background" type="TextureRect" parent="."]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
offset_left = -142.0
|
||||
offset_top = -461.0
|
||||
offset_right = -25.0
|
||||
offset_bottom = -19.0
|
||||
texture = ExtResource("3_wymtn")
|
||||
|
||||
[node name="Background2" type="TextureRect" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = -142.0
|
||||
offset_top = -461.0
|
||||
offset_right = -25.0
|
||||
offset_bottom = -19.0
|
||||
texture = ExtResource("4_eh880")
|
||||
|
||||
[node name="ProgressBar2" type="ProgressBar" parent="Background2"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 13.0
|
||||
offset_top = 72.0
|
||||
offset_right = -86.0
|
||||
offset_bottom = -84.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxEmpty_efdny")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_77ucw")
|
||||
fill_mode = 3
|
||||
show_percentage = false
|
||||
|
||||
[node name="Foreground" type="TextureRect" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = -142.0
|
||||
offset_top = -461.0
|
||||
offset_right = -25.0
|
||||
offset_bottom = -19.0
|
||||
texture = ExtResource("3_d65ol")
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="LimitOverlay" type="TextureRect" parent="Foreground"]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
offset_right = 117.0
|
||||
offset_bottom = 442.0
|
||||
texture = SubResource("AtlasTexture_wymtn")
|
||||
Reference in New Issue
Block a user