Co-authored-by: Dennis Ploeger <develop@dieploegers.de> Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
67
game/ui/commons/dialogs/text_dialog_choice.gd
Normal file
67
game/ui/commons/dialogs/text_dialog_choice.gd
Normal file
@@ -0,0 +1,67 @@
|
||||
extends ESCDialogOptionsChooser
|
||||
|
||||
export(Color, RGB) var color_normal = Color(1.0,1.0,1.0,1.0)
|
||||
export(Color, RGB) var color_hover = Color(165.0,42.0,42.0, 1.0)
|
||||
export(Font) var font
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
hide_chooser()
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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:
|
||||
var _option_node = Button.new()
|
||||
_option_node.text = (option as ESCDialogOption).option
|
||||
_option_node.flat = true
|
||||
_option_node.add_color_override("font_color", color_normal)
|
||||
_option_node.add_color_override("font_color_hover", color_hover)
|
||||
_option_node.add_font_override("font", font)
|
||||
_vbox.add_child(_option_node)
|
||||
_option_node.connect("pressed", self, "_on_answer_selected", [option])
|
||||
|
||||
if self.dialog.avatar != "-":
|
||||
$AvatarContainer.add_child(
|
||||
ResourceLoader.load(self.dialog.avatar).instance()
|
||||
)
|
||||
|
||||
$MarginContainer.show()
|
||||
|
||||
if self.dialog.timeout > 0:
|
||||
$Timer.start(self.dialog.timeout)
|
||||
|
||||
|
||||
func hide_chooser():
|
||||
$MarginContainer.hide()
|
||||
|
||||
|
||||
func _option_chosen(option: ESCDialogOption):
|
||||
_remove_avatar()
|
||||
$TimerProgress.value = 0
|
||||
emit_signal("option_chosen", option)
|
||||
|
||||
|
||||
func _on_answer_selected(option: ESCDialogOption):
|
||||
_option_chosen(option)
|
||||
|
||||
|
||||
func _on_Timer_timeout() -> void:
|
||||
_option_chosen(self.dialog.options[self.dialog.timeout_option - 1])
|
||||
|
||||
|
||||
func _remove_avatar():
|
||||
if $AvatarContainer.get_child_count() > 0:
|
||||
$AvatarContainer.remove_child($AvatarContainer.get_child(0))
|
||||
@@ -1,34 +1,64 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/template_scenes/dialog_scenes/dialog_choosers/text_dialog_choice.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/game/assets/fonts/efmi/efmi_font.tres" type="DynamicFont" id=2]
|
||||
|
||||
[node name="text_dialog_choice" type="MarginContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
custom_constants/margin_top = 20
|
||||
custom_constants/margin_left = 20
|
||||
[sub_resource type="Gradient" id=1]
|
||||
colors = PoolColorArray( 1, 0, 0, 1, 1, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="GradientTexture" id=2]
|
||||
gradient = SubResource( 1 )
|
||||
|
||||
[node name="text_dialog_choice" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
color_hover = Color( 0.647059, 0.164706, 0.164706, 1 )
|
||||
font = ExtResource( 2 )
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="."]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = 1280.0
|
||||
margin_bottom = 900.0
|
||||
mouse_filter = 2
|
||||
custom_constants/margin_top = 20
|
||||
custom_constants/margin_left = 20
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer"]
|
||||
margin_left = 20.0
|
||||
margin_top = 20.0
|
||||
margin_right = 1260.0
|
||||
margin_bottom = 880.0
|
||||
scroll_horizontal_enabled = false
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
|
||||
margin_right = 1260.0
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/ScrollContainer"]
|
||||
margin_right = 1240.0
|
||||
margin_bottom = 860.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_constants/separation = 20
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="TimerProgress" type="TextureProgress" parent="."]
|
||||
anchor_right = 1.0
|
||||
rect_min_size = Vector2( 0, 20 )
|
||||
texture_progress = SubResource( 2 )
|
||||
nine_patch_stretch = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="AvatarContainer" type="Node2D" parent="."]
|
||||
position = Vector2( 29.1458, 120.012 )
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
||||
|
||||
Reference in New Issue
Block a user