gd,refacto: added state chart addon and namespace cleanup
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
## This is tool so we can show the selected texture immediately in the editor.
|
||||
@tool
|
||||
extends MarginContainer
|
||||
|
||||
signal pressed()
|
||||
|
||||
@export var texture:Texture2D:
|
||||
set(value):
|
||||
texture = value
|
||||
_apply_settings()
|
||||
|
||||
## The progressbar we control
|
||||
@onready var _texture_progress_bar:TextureProgressBar = %TextureProgressBar
|
||||
|
||||
## The label showing the cooldown in seconds
|
||||
@onready var _label:Label = %Label
|
||||
|
||||
## The button that can be pressed
|
||||
@onready var _button:Button = %Button
|
||||
|
||||
func _ready():
|
||||
_apply_settings()
|
||||
|
||||
|
||||
func _apply_settings():
|
||||
if _texture_progress_bar != null:
|
||||
_texture_progress_bar.texture_under = texture
|
||||
|
||||
## Called while cooldown transitions run. Will update the state of the
|
||||
## cooldown in the UI elements and disable the button until clear_cooldown
|
||||
## is called.
|
||||
func set_cooldown(total:float, current:float):
|
||||
_label.visible = true
|
||||
_button.disabled = true
|
||||
_texture_progress_bar.max_value = total
|
||||
_texture_progress_bar.value = current
|
||||
_label.text = "%.1f" % current
|
||||
|
||||
|
||||
## Called to clear the cooldown. Will enable the button and clear all cooldown
|
||||
## indicators.
|
||||
func clear_cooldown():
|
||||
_label.visible = false
|
||||
_button.disabled = false
|
||||
_texture_progress_bar.value = 0
|
||||
|
||||
_texture_progress_bar.max_value = 100
|
||||
|
||||
## Signal relay for the inner button.
|
||||
func _on_button_pressed():
|
||||
pressed.emit()
|
@ -0,0 +1 @@
|
||||
uid://cjlrmcmit4jhm
|
@ -0,0 +1,34 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://ch1pukkyc07qo"]
|
||||
|
||||
[ext_resource type="Script" path="res://godot_state_charts_examples/cooldown/skill_button/skill_button.gd" id="1_r0ivs"]
|
||||
[ext_resource type="Texture2D" uid="uid://tgsnqiq40n41" path="res://godot_state_charts_examples/cooldown/icons/cooldown_overlay.png" id="3_pgrfi"]
|
||||
|
||||
[node name="SkillButton" type="MarginContainer"]
|
||||
offset_right = 32.0
|
||||
offset_bottom = 32.0
|
||||
script = ExtResource("1_r0ivs")
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TextureProgressBar" type="TextureProgressBar" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
step = 0.0
|
||||
fill_mode = 4
|
||||
texture_progress = ExtResource("3_pgrfi")
|
||||
tint_progress = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 8
|
||||
theme_override_font_sizes/font_size = 48
|
||||
text = "10"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
Reference in New Issue
Block a user