gd,refacto: added state chart addon and namespace cleanup
This commit is contained in:
6
godot_state_charts_examples/cooldown/LICENSE.md
Normal file
6
godot_state_charts_examples/cooldown/LICENSE.md
Normal file
@ -0,0 +1,6 @@
|
||||
The icons in this demo are used under CC BY 3.0 DEED license
|
||||
(https://creativecommons.org/licenses/by/3.0/).
|
||||
|
||||
Original author:
|
||||
|
||||
J. W. Bjerk (eleazzaar) -- www.jwbjerk.com/art -- find this and other open art at: http://opengameart.org
|
140
godot_state_charts_examples/cooldown/cooldown_demo.tscn
Normal file
140
godot_state_charts_examples/cooldown/cooldown_demo.tscn
Normal file
@ -0,0 +1,140 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://cnqh7qot0estd"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bcwkugn6v3oy7" path="res://addons/godot_state_charts/utilities/state_chart_debugger.tscn" id="1_oec6f"]
|
||||
[ext_resource type="PackedScene" uid="uid://ch1pukkyc07qo" path="res://godot_state_charts_examples/cooldown/skill_button/skill_button.tscn" id="2_aahy2"]
|
||||
[ext_resource type="Texture2D" uid="uid://bphe0g2d306fe" path="res://godot_state_charts_examples/cooldown/icons/enchant-red-3.png" id="3_a8h0q"]
|
||||
[ext_resource type="Texture2D" uid="uid://bjmc4abduaxww" path="res://godot_state_charts_examples/cooldown/icons/fireball-eerie-2.png" id="4_jhd8u"]
|
||||
[ext_resource type="Texture2D" uid="uid://b87nmomi1l48x" path="res://godot_state_charts_examples/cooldown/icons/heal-jade-2.png" id="5_xxunm"]
|
||||
[ext_resource type="Script" path="res://addons/godot_state_charts/state_chart.gd" id="6_d3pqh"]
|
||||
[ext_resource type="Script" path="res://addons/godot_state_charts/parallel_state.gd" id="7_l6ahs"]
|
||||
[ext_resource type="Script" path="res://addons/godot_state_charts/compound_state.gd" id="8_pvst5"]
|
||||
[ext_resource type="Script" path="res://addons/godot_state_charts/atomic_state.gd" id="9_h41ei"]
|
||||
[ext_resource type="Script" path="res://addons/godot_state_charts/transition.gd" id="10_5fig4"]
|
||||
|
||||
[node name="Cooldown Example" type="Node2D"]
|
||||
|
||||
[node name="StateChartDebugger" parent="." instance=ExtResource("1_oec6f")]
|
||||
offset_left = 290.0
|
||||
offset_top = 16.0
|
||||
offset_right = 629.0
|
||||
offset_bottom = 466.0
|
||||
initial_node_to_watch = NodePath("../StateChart")
|
||||
|
||||
[node name="InfoLabel" type="Label" parent="."]
|
||||
offset_left = 10.0
|
||||
offset_top = 24.0
|
||||
offset_right = 277.0
|
||||
offset_bottom = 128.0
|
||||
text = "This example shows how to connect delayed transitions with game UI to model skill buttons that have cooldowns. Click the buttons to try it."
|
||||
autowrap_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
offset_left = 18.0
|
||||
offset_top = 164.0
|
||||
offset_right = 278.0
|
||||
offset_bottom = 435.0
|
||||
theme_override_constants/separation = 15
|
||||
|
||||
[node name="AttackSkillButton" parent="VBoxContainer" instance=ExtResource("2_aahy2")]
|
||||
editor_description = "This is the attack skill button. When you press it, it will send the \"attack\" event to the state chart."
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = ExtResource("3_a8h0q")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="MagicSkillButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_aahy2")]
|
||||
editor_description = "This is the magic skill button. When you press it, it will send the \"magic\" event to the state chart."
|
||||
layout_mode = 2
|
||||
texture = ExtResource("4_jhd8u")
|
||||
|
||||
[node name="HealSkillButton" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_aahy2")]
|
||||
editor_description = "This is the heal skill button. When you press it, it will send the \"heal\" event to the state chart."
|
||||
layout_mode = 2
|
||||
texture = ExtResource("5_xxunm")
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("6_d3pqh")
|
||||
track_in_editor = true
|
||||
|
||||
[node name="Root" type="Node" parent="StateChart"]
|
||||
editor_description = "Since all three skills can be used independently of each other we use a parallel state as the root here."
|
||||
script = ExtResource("7_l6ahs")
|
||||
|
||||
[node name="AttackSkill" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("8_pvst5")
|
||||
initial_state = NodePath("Available")
|
||||
|
||||
[node name="Available" type="Node" parent="StateChart/Root/AttackSkill"]
|
||||
editor_description = "State indicating that attack is available. Entering this state will reset the cooldown on the attack skill button."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="On Attack To Cooldown" type="Node" parent="StateChart/Root/AttackSkill/Available"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Cooldown")
|
||||
event = &"attack"
|
||||
|
||||
[node name="Cooldown" type="Node" parent="StateChart/Root/AttackSkill"]
|
||||
editor_description = "Cooldown state for the attack skill. While the delayed transition is pending, this state will send status updates on the pending transition to the attack skill button. The attack skill button will then update itself and show the remaining cooldown."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="Back to Available" type="Node" parent="StateChart/Root/AttackSkill/Cooldown"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Available")
|
||||
delay_seconds = 1.0
|
||||
|
||||
[node name="MagicSkill" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("8_pvst5")
|
||||
initial_state = NodePath("Available")
|
||||
|
||||
[node name="Available" type="Node" parent="StateChart/Root/MagicSkill"]
|
||||
editor_description = "State indicating that the magic skill is available. Entering this state will reset the cooldown on the magic skill button."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="On Magic To Cooldown" type="Node" parent="StateChart/Root/MagicSkill/Available"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Cooldown")
|
||||
event = &"magic"
|
||||
|
||||
[node name="Cooldown" type="Node" parent="StateChart/Root/MagicSkill"]
|
||||
editor_description = "Cooldown state for the magic skill. While the delayed transition is pending, this state will send status updates on the pending transition to the magic skill button. The magic skill button will then update itself and show the remaining cooldown."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="Back to Available" type="Node" parent="StateChart/Root/MagicSkill/Cooldown"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Available")
|
||||
delay_seconds = 3.0
|
||||
|
||||
[node name="HealSkill" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("8_pvst5")
|
||||
initial_state = NodePath("Available")
|
||||
|
||||
[node name="Available" type="Node" parent="StateChart/Root/HealSkill"]
|
||||
editor_description = "State indicating that the heal skill is available. Entering this state will reset the cooldown on the heal skill button."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="On Heal To Cooldown" type="Node" parent="StateChart/Root/HealSkill/Available"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Cooldown")
|
||||
event = &"heal"
|
||||
|
||||
[node name="Cooldown" type="Node" parent="StateChart/Root/HealSkill"]
|
||||
editor_description = "Cooldown state for the heal skill. While the delayed transition is pending, this state will send status updates on the pending transition to the heal skill button. The heal skill button will then update itself and show the remaining cooldown."
|
||||
script = ExtResource("9_h41ei")
|
||||
|
||||
[node name="Back to Available" type="Node" parent="StateChart/Root/HealSkill/Cooldown"]
|
||||
script = ExtResource("10_5fig4")
|
||||
to = NodePath("../../Available")
|
||||
delay_seconds = 10.0
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/AttackSkillButton" to="StateChart" method="send_event" binds= ["attack"]]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/MagicSkillButton" to="StateChart" method="send_event" binds= ["magic"]]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/HealSkillButton" to="StateChart" method="send_event" binds= ["heal"]]
|
||||
[connection signal="state_entered" from="StateChart/Root/AttackSkill/Available" to="VBoxContainer/AttackSkillButton" method="clear_cooldown"]
|
||||
[connection signal="transition_pending" from="StateChart/Root/AttackSkill/Cooldown" to="VBoxContainer/AttackSkillButton" method="set_cooldown"]
|
||||
[connection signal="state_entered" from="StateChart/Root/MagicSkill/Available" to="VBoxContainer/HBoxContainer/MagicSkillButton" method="clear_cooldown"]
|
||||
[connection signal="transition_pending" from="StateChart/Root/MagicSkill/Cooldown" to="VBoxContainer/HBoxContainer/MagicSkillButton" method="set_cooldown"]
|
||||
[connection signal="state_entered" from="StateChart/Root/HealSkill/Available" to="VBoxContainer/HBoxContainer/HealSkillButton" method="clear_cooldown"]
|
||||
[connection signal="transition_pending" from="StateChart/Root/HealSkill/Cooldown" to="VBoxContainer/HBoxContainer/HealSkillButton" method="set_cooldown"]
|
BIN
godot_state_charts_examples/cooldown/icons/cooldown_overlay.png
Normal file
BIN
godot_state_charts_examples/cooldown/icons/cooldown_overlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 318 B |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://tgsnqiq40n41"
|
||||
path="res://.godot/imported/cooldown_overlay.png-5594f471c10cac21fce498b609075490.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://godot_state_charts_examples/cooldown/icons/cooldown_overlay.png"
|
||||
dest_files=["res://.godot/imported/cooldown_overlay.png-5594f471c10cac21fce498b609075490.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
|
BIN
godot_state_charts_examples/cooldown/icons/enchant-red-3.png
Normal file
BIN
godot_state_charts_examples/cooldown/icons/enchant-red-3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bphe0g2d306fe"
|
||||
path="res://.godot/imported/enchant-red-3.png-1df2c19bbfe03c22227b3db03bc16eee.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://godot_state_charts_examples/cooldown/icons/enchant-red-3.png"
|
||||
dest_files=["res://.godot/imported/enchant-red-3.png-1df2c19bbfe03c22227b3db03bc16eee.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
|
BIN
godot_state_charts_examples/cooldown/icons/fireball-eerie-2.png
Normal file
BIN
godot_state_charts_examples/cooldown/icons/fireball-eerie-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bjmc4abduaxww"
|
||||
path="res://.godot/imported/fireball-eerie-2.png-a420ae5d8f4f4f86ea5ef03eeea7f3c6.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://godot_state_charts_examples/cooldown/icons/fireball-eerie-2.png"
|
||||
dest_files=["res://.godot/imported/fireball-eerie-2.png-a420ae5d8f4f4f86ea5ef03eeea7f3c6.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
|
BIN
godot_state_charts_examples/cooldown/icons/heal-jade-2.png
Normal file
BIN
godot_state_charts_examples/cooldown/icons/heal-jade-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b87nmomi1l48x"
|
||||
path="res://.godot/imported/heal-jade-2.png-5317fa8cf716c70c254fee8762a0dfda.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://godot_state_charts_examples/cooldown/icons/heal-jade-2.png"
|
||||
dest_files=["res://.godot/imported/heal-jade-2.png-5317fa8cf716c70c254fee8762a0dfda.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
|
@ -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