summaryrefslogtreecommitdiff
path: root/addons/escoria-dialog-simple/chooser
diff options
context:
space:
mode:
Diffstat (limited to 'addons/escoria-dialog-simple/chooser')
-rw-r--r--addons/escoria-dialog-simple/chooser/simple.gd99
-rw-r--r--addons/escoria-dialog-simple/chooser/simple.gd.uid1
-rw-r--r--addons/escoria-dialog-simple/chooser/simple.tscn52
3 files changed, 152 insertions, 0 deletions
diff --git a/addons/escoria-dialog-simple/chooser/simple.gd b/addons/escoria-dialog-simple/chooser/simple.gd
new file mode 100644
index 0000000..d7c0297
--- /dev/null
+++ b/addons/escoria-dialog-simple/chooser/simple.gd
@@ -0,0 +1,99 @@
+# A simple dialog chooser that shows selectable lines of text
+# Supports timeout and avatar display
+extends ESCDialogOptionsChooser
+
+
+@export var color_normal = Color(1.0,1.0,1.0,1.0) # (Color, RGB)
+@export var color_hover = Color(165.0,42.0,42.0, 1.0) # (Color, RGB)
+
+
+var _no_more_options: bool = false
+
+
+# Hide the chooser at the start just to be safe
+func _ready() -> void:
+ hide_chooser()
+ process_mode = PROCESS_MODE_PAUSABLE
+
+
+# Process the timeout display
+func _process(delta: float) -> void:
+ if $MarginContainer.visible and self.dialog and self.dialog.timeout > 0:
+ $TimerProgress.value = (
+ self.dialog.timeout - $Timer.time_left
+ ) / self.dialog.timeout * 100
+
+
+# Show the chooser
+func show_chooser():
+ var _vbox = $MarginContainer/ScrollContainer/VBoxContainer
+ for option_node in _vbox.get_children():
+ _vbox.remove_child(option_node)
+
+ _remove_avatar()
+
+ for option in self.dialog.options:
+ if option.is_valid():
+ var _option_node = Button.new()
+ _option_node.text = (option as ESCDialogOption).option
+ _option_node.flat = true
+ _option_node.add_theme_color_override("font_color", color_normal)
+ _option_node.add_theme_color_override("font_color_hover", color_hover)
+ _vbox.add_child(_option_node)
+
+ _option_node.pressed.connect(_on_answer_selected.bind(option))
+
+ # If we've no options left, signify as much and start the timer with a
+ # very short interval so the appropriate signal can be fired. Note that
+ # we have to fire the signal AFTER this method returns as the caller
+ # is almost certainly yielding after this method returns.
+ if _vbox.get_child_count() == 0:
+ _no_more_options = true
+ $Timer.start(0.05)
+ return
+
+ if self.dialog.avatar != "-":
+ $AvatarContainer.add_child(
+ ResourceLoader.load(self.dialog.avatar).instantiate()
+ )
+
+ $MarginContainer.show()
+
+ if self.dialog.timeout > 0:
+ $Timer.start(self.dialog.timeout)
+
+
+# Hide the chooser
+func hide_chooser():
+ $MarginContainer.hide()
+
+
+# An option was choosen, emit the option
+#
+# #### Parameters
+# - option: Option that was chosen
+func _option_chosen(option: ESCDialogOption):
+ _remove_avatar()
+ $TimerProgress.value = 0
+ option_chosen.emit(option)
+
+
+# An option was chosen directly from the list
+#
+# #### Parameters
+# - option: Option that was chosen
+func _on_answer_selected(option: ESCDialogOption):
+ _option_chosen(option)
+
+
+# The timeout came and a option was selected
+func _on_Timer_timeout() -> void:
+ var option_chosen = null if _no_more_options else self.dialog.options[self.dialog.timeout_option - 1]
+ _no_more_options = false
+ _option_chosen(option_chosen)
+
+
+# Remove the avatar
+func _remove_avatar():
+ if $AvatarContainer.get_child_count() > 0:
+ $AvatarContainer.remove_child($AvatarContainer.get_child(0))
diff --git a/addons/escoria-dialog-simple/chooser/simple.gd.uid b/addons/escoria-dialog-simple/chooser/simple.gd.uid
new file mode 100644
index 0000000..05b63ec
--- /dev/null
+++ b/addons/escoria-dialog-simple/chooser/simple.gd.uid
@@ -0,0 +1 @@
+uid://bfwgvr8mfsqvb
diff --git a/addons/escoria-dialog-simple/chooser/simple.tscn b/addons/escoria-dialog-simple/chooser/simple.tscn
new file mode 100644
index 0000000..0dcab9f
--- /dev/null
+++ b/addons/escoria-dialog-simple/chooser/simple.tscn
@@ -0,0 +1,52 @@
+[gd_scene load_steps=4 format=3 uid="uid://bkygfxo5vhqsy"]
+
+[ext_resource type="Script" uid="uid://bfwgvr8mfsqvb" path="res://addons/escoria-dialog-simple/chooser/simple.gd" id="1"]
+
+[sub_resource type="Gradient" id="1"]
+colors = PackedColorArray(1, 0, 0, 1, 1, 0, 0, 1)
+
+[sub_resource type="GradientTexture2D" id="2"]
+gradient = SubResource("1")
+
+[node name="text_dialog_choice" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1")
+
+[node name="MarginContainer" type="MarginContainer" parent="."]
+layout_mode = 0
+offset_left = 20.0
+offset_top = 20.0
+offset_right = 1280.0
+offset_bottom = 900.0
+mouse_filter = 2
+theme_override_constants/margin_left = 20
+theme_override_constants/margin_top = 20
+
+[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer"]
+layout_mode = 2
+
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/ScrollContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 3
+theme_override_constants/separation = 20
+
+[node name="Timer" type="Timer" parent="."]
+one_shot = true
+
+[node name="TimerProgress" type="TextureProgressBar" parent="."]
+custom_minimum_size = Vector2(0, 20)
+layout_mode = 0
+anchor_right = 1.0
+nine_patch_stretch = true
+texture_progress = SubResource("2")
+
+[node name="AvatarContainer" type="Node2D" parent="."]
+position = Vector2(94, 68)
+
+[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]