Add addons
This commit is contained in:
parent
2c862b2235
commit
3367bad24f
527 changed files with 36197 additions and 0 deletions
153
Sprout/addons/dialogic/Events/Choice/event_choice.gd
Normal file
153
Sprout/addons/dialogic/Events/Choice/event_choice.gd
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
@tool
|
||||
class_name DialogicChoiceEvent
|
||||
extends DialogicEvent
|
||||
|
||||
## Event that allows adding choices. Needs to go after a text event (or another choices EndBranch).
|
||||
|
||||
enum ElseActions {Hide, Disable, Default}
|
||||
|
||||
|
||||
### Settings
|
||||
## The text that is displayed on the choice button.
|
||||
var text :String = ""
|
||||
## If not empty this condition will determine if this choice is active.
|
||||
var condition: String = ""
|
||||
## Determines what happens if [condition] is false. Default will use the action set in the settings.
|
||||
var else_action: = ElseActions.Default
|
||||
## The text that is displayed if [condition] is false and [else_action] is Disable.
|
||||
## If empty [text] will be used for disabled button as well.
|
||||
var disabled_text: String = ""
|
||||
|
||||
|
||||
################################################################################
|
||||
## EXECUTION
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
# This event is basically a placeholder only used to indicate a position.
|
||||
# It is never really reached. Instead the Subsystem_Choices queries the events
|
||||
# to find the choices that belong to the question.
|
||||
finish()
|
||||
|
||||
|
||||
################################################################################
|
||||
## INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Choice"
|
||||
set_default_color('Color3')
|
||||
event_category = Category.Logic
|
||||
event_sorting_index = 0
|
||||
can_contain_events = true
|
||||
needs_parent_event = true
|
||||
expand_by_default = false
|
||||
|
||||
|
||||
# if needs_parent_event is true, this needs to return true if the event is that event
|
||||
func is_expected_parent_event(event:DialogicEvent) -> bool:
|
||||
return event is DialogicTextEvent
|
||||
|
||||
|
||||
# return a control node that should show on the END BRANCH node
|
||||
func get_end_branch_control() -> Control:
|
||||
return load(get_script().resource_path.get_base_dir().path_join('ui_choice_end.tscn')).instantiate()
|
||||
|
||||
################################################################################
|
||||
## SAVING/LOADING
|
||||
################################################################################
|
||||
|
||||
func to_text() -> String:
|
||||
var result_string := ""
|
||||
|
||||
result_string = "- "+text.strip_edges()
|
||||
if condition:
|
||||
result_string += " [if "+condition+"]"
|
||||
|
||||
|
||||
var shortcode = '['
|
||||
if else_action == ElseActions.Hide:
|
||||
shortcode += 'else="hide"'
|
||||
elif else_action == ElseActions.Disable:
|
||||
shortcode += 'else="disable"'
|
||||
|
||||
if disabled_text:
|
||||
shortcode += " alt_text="+'"'+disabled_text+'"'
|
||||
|
||||
if len(shortcode) > 1:
|
||||
result_string += shortcode + "]"
|
||||
return result_string
|
||||
|
||||
|
||||
func from_text(string:String) -> void:
|
||||
var regex = RegEx.new()
|
||||
regex.compile('- (?<text>[^\\[]*)(\\[if (?<condition>[^\\]]+)])?\\s?(\\s*\\[(?<shortcode>.*)\\])?')
|
||||
var result = regex.search(string.strip_edges())
|
||||
if result == null:
|
||||
return
|
||||
text = result.get_string('text')
|
||||
condition = result.get_string('condition')
|
||||
if result.get_string('shortcode'):
|
||||
var shortcode_params = parse_shortcode_parameters(result.get_string('shortcode'))
|
||||
else_action = {
|
||||
'default':ElseActions.Default,
|
||||
'hide':ElseActions.Hide,
|
||||
'disable':ElseActions.Disable}.get(shortcode_params.get('else', ''), ElseActions.Default)
|
||||
|
||||
disabled_text = shortcode_params.get('alt_text', '')
|
||||
|
||||
|
||||
func is_valid_event(string:String) -> bool:
|
||||
if string.strip_edges().begins_with("-"):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
################################################################################
|
||||
## TRANSLATIONS
|
||||
################################################################################
|
||||
|
||||
func _get_translatable_properties() -> Array:
|
||||
return ['text', 'disabled_text']
|
||||
|
||||
|
||||
func _get_property_original_translation(property:String) -> String:
|
||||
match property:
|
||||
'text':
|
||||
return text
|
||||
'disabled_text':
|
||||
return disabled_text
|
||||
return ''
|
||||
|
||||
|
||||
################################################################################
|
||||
## EDITOR REPRESENTATION
|
||||
################################################################################
|
||||
|
||||
func build_event_editor() -> void:
|
||||
add_header_edit("text", ValueType.SinglelineText)
|
||||
add_body_edit("condition", ValueType.Condition, 'if ')
|
||||
add_body_edit("else_action", ValueType.FixedOptionSelector, 'else ', '', {
|
||||
'selector_options': [
|
||||
{
|
||||
'label': 'Default',
|
||||
'value': ElseActions.Default,
|
||||
},
|
||||
{
|
||||
'label': 'Hide',
|
||||
'value': ElseActions.Hide,
|
||||
},
|
||||
{
|
||||
'label': 'Disable',
|
||||
'value': ElseActions.Disable,
|
||||
}
|
||||
]}, '!condition.is_empty()')
|
||||
add_body_edit("disabled_text", ValueType.SinglelineText, 'Disabled text:', '',
|
||||
{'placeholder':'(Empty for same)'}, 'allow_alt_text()')
|
||||
|
||||
|
||||
func allow_alt_text() -> bool:
|
||||
return condition and (
|
||||
else_action == ElseActions.Disable or
|
||||
(else_action == ElseActions.Default and
|
||||
DialogicUtil.get_project_setting("dialogic/choices/def_false_behaviour", 0) == 1))
|
||||
BIN
Sprout/addons/dialogic/Events/Choice/icon.png
Normal file
BIN
Sprout/addons/dialogic/Events/Choice/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 621 B |
34
Sprout/addons/dialogic/Events/Choice/icon.png.import
Normal file
34
Sprout/addons/dialogic/Events/Choice/icon.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d0p5oj7m0vp15"
|
||||
path="res://.godot/imported/icon.png-5b61c4d2ebb9ccd2a839f9719c30446b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/dialogic/Events/Choice/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-5b61c4d2ebb9ccd2a839f9719c30446b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/bptc_ldr=0
|
||||
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
|
||||
14
Sprout/addons/dialogic/Events/Choice/index.gd
Normal file
14
Sprout/addons/dialogic/Events/Choice/index.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
@tool
|
||||
extends DialogicIndexer
|
||||
|
||||
|
||||
func _get_events() -> Array:
|
||||
return [this_folder.path_join('event_choice.gd')]
|
||||
|
||||
|
||||
func _get_subsystems() -> Array:
|
||||
return [{'name':'Choices', 'script':this_folder.path_join('subsystem_choices.gd')}]
|
||||
|
||||
|
||||
func _get_settings_pages() -> Array:
|
||||
return [this_folder.path_join('settings_choices.tscn')]
|
||||
52
Sprout/addons/dialogic/Events/Choice/node_button_sound.gd
Normal file
52
Sprout/addons/dialogic/Events/Choice/node_button_sound.gd
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
class_name DialogicNode_ButtonSound
|
||||
extends AudioStreamPlayer
|
||||
|
||||
## Node that is used for playing sound effects on hover/focus/press of sibling DialogicNode_ChoiceButtons.
|
||||
|
||||
## Sound to be played if one of the sibling ChoiceButtons is pressed.
|
||||
## If sibling ChoiceButton has a sound_pressed set, that is prioritized.
|
||||
@export var sound_pressed:AudioStream
|
||||
## Sound to be played on hover. See [sound_pressed] for more.
|
||||
@export var sound_hover:AudioStream
|
||||
## Sound to be played on focus. See [sound_pressed] for more.
|
||||
@export var sound_focus:AudioStream
|
||||
|
||||
func _ready():
|
||||
add_to_group('dialogic_button_sound')
|
||||
_connect_all_buttons()
|
||||
|
||||
#basic play sound
|
||||
func play_sound(sound) -> void:
|
||||
if sound != null:
|
||||
stream = sound
|
||||
play()
|
||||
|
||||
func _connect_all_buttons():
|
||||
for child in get_parent().get_children():
|
||||
if child is DialogicNode_ChoiceButton:
|
||||
child.button_up.connect(_on_pressed.bind(child.sound_pressed))
|
||||
child.mouse_entered.connect(_on_hover.bind(child.sound_hover))
|
||||
child.focus_entered.connect(_on_focus.bind(child.sound_focus))
|
||||
|
||||
|
||||
#the custom_sound argument comes from the specifec button and get used
|
||||
#if none are found, it uses the above sounds
|
||||
|
||||
func _on_pressed(custom_sound) -> void:
|
||||
if custom_sound != null:
|
||||
play_sound(custom_sound)
|
||||
else:
|
||||
play_sound(sound_pressed)
|
||||
|
||||
func _on_hover(custom_sound) -> void:
|
||||
if custom_sound != null:
|
||||
play_sound(custom_sound)
|
||||
else:
|
||||
play_sound(sound_hover)
|
||||
|
||||
func _on_focus(custom_sound) -> void:
|
||||
if custom_sound != null:
|
||||
play_sound(custom_sound)
|
||||
else:
|
||||
play_sound(sound_focus)
|
||||
|
||||
20
Sprout/addons/dialogic/Events/Choice/node_choice_button.gd
Normal file
20
Sprout/addons/dialogic/Events/Choice/node_choice_button.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class_name DialogicNode_ChoiceButton
|
||||
extends Button
|
||||
|
||||
## Dialogic Node that displays choices.
|
||||
|
||||
## Used to identify what choices to put on. If you leave it at -1, choices will be distributed automatically.
|
||||
@export var choice_index:int = -1
|
||||
|
||||
## Can be set to play this sound when pressed. Requires a sibling DialogicNode_ButtonSound node.
|
||||
@export var sound_pressed: AudioStream
|
||||
## Can be set to play this sound when hovered. Requires a sibling DialogicNode_ButtonSound node.
|
||||
@export var sound_hover: AudioStream
|
||||
## Can be set to play this sound when focused. Requires a sibling DialogicNode_ButtonSound node.
|
||||
@export var sound_focus: AudioStream
|
||||
|
||||
|
||||
func _ready():
|
||||
add_to_group('dialogic_choice_button')
|
||||
shortcut_in_tooltip = false
|
||||
hide()
|
||||
29
Sprout/addons/dialogic/Events/Choice/settings_choices.gd
Normal file
29
Sprout/addons/dialogic/Events/Choice/settings_choices.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
func refresh() -> void:
|
||||
%Autofocus.button_pressed = DialogicUtil.get_project_setting('dialogic/choices/autofocus_first', true)
|
||||
var delay_value:float = DialogicUtil.get_project_setting('dialogic/choices/delay', 0.2)
|
||||
%Delay.value = delay_value
|
||||
%FalseBehaviour.select(DialogicUtil.get_project_setting('dialogic/choices/def_false_behaviour', 0))
|
||||
%HotkeyType.select(DialogicUtil.get_project_setting('dialogic/choices/hotkey_behaviour', 0))
|
||||
|
||||
|
||||
func _on_Autofocus_toggled(button_pressed: bool) -> void:
|
||||
ProjectSettings.set_setting('dialogic/choices/autofocus_first', button_pressed)
|
||||
ProjectSettings.save()
|
||||
|
||||
|
||||
func _on_FalseBehaviour_item_selected(index) -> void:
|
||||
ProjectSettings.set_setting('dialogic/choices/def_false_behaviour', index)
|
||||
ProjectSettings.save()
|
||||
|
||||
|
||||
func _on_HotkeyType_item_selected(index) -> void:
|
||||
ProjectSettings.set_setting('dialogic/choices/hotkey_behaviour', index)
|
||||
ProjectSettings.save()
|
||||
|
||||
|
||||
func _on_Delay_value_changed(value) -> void:
|
||||
ProjectSettings.set_setting('dialogic/choices/delay', value)
|
||||
ProjectSettings.save()
|
||||
157
Sprout/addons/dialogic/Events/Choice/settings_choices.tscn
Normal file
157
Sprout/addons/dialogic/Events/Choice/settings_choices.tscn
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
[gd_scene load_steps=4 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/dialogic/Events/Choice/settings_choices.gd" id="2"]
|
||||
[ext_resource type="StyleBox" uid="uid://dmsjhgv22dns8" path="res://addons/dialogic/Editor/Common/TitleBgStylebox.tres" id="2_cg22x"]
|
||||
[ext_resource type="Script" path="res://addons/dialogic/Editor/Settings/HintLabelStylingScript.gd" id="3_mpugv"]
|
||||
|
||||
[node name="Choices" type="HBoxContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource("2")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
offset_right = 570.0
|
||||
offset_bottom = 648.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Title" type="Label" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
offset_right = 570.0
|
||||
offset_bottom = 36.0
|
||||
theme_override_styles/normal = ExtResource("2_cg22x")
|
||||
text = "Choice Settings"
|
||||
|
||||
[node name="Autofocus" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
offset_top = 40.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 66.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/Autofocus"]
|
||||
layout_mode = 2
|
||||
offset_right = 542.0
|
||||
offset_bottom = 26.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Autofocus first choice"
|
||||
|
||||
[node name="Autofocus" type="CheckBox" parent="VBoxContainer/Autofocus"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 546.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 26.0
|
||||
|
||||
[node name="Delay" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
offset_top = 70.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 101.0
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer/Delay"]
|
||||
layout_mode = 2
|
||||
offset_top = 2.0
|
||||
offset_right = 483.0
|
||||
offset_bottom = 28.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Delay before choices can be pressed"
|
||||
|
||||
[node name="Delay" type="SpinBox" parent="VBoxContainer/Delay"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 487.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 31.0
|
||||
step = 0.01
|
||||
|
||||
[node name="DefaultFalseBehaviour" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
offset_top = 105.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 136.0
|
||||
|
||||
[node name="Label3" type="Label" parent="VBoxContainer/DefaultFalseBehaviour"]
|
||||
layout_mode = 2
|
||||
offset_top = 2.0
|
||||
offset_right = 466.0
|
||||
offset_bottom = 28.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Default behaviour for false choices"
|
||||
|
||||
[node name="FalseBehaviour" type="OptionButton" parent="VBoxContainer/DefaultFalseBehaviour"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 470.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 31.0
|
||||
item_count = 2
|
||||
selected = 0
|
||||
popup/item_0/text = "Hide"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Disable"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="VSeparator" type="VSeparator" parent="."]
|
||||
layout_mode = 2
|
||||
offset_left = 574.0
|
||||
offset_right = 578.0
|
||||
offset_bottom = 648.0
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
offset_left = 582.0
|
||||
offset_right = 1152.0
|
||||
offset_bottom = 648.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Title2" type="Label" parent="VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
offset_right = 570.0
|
||||
offset_bottom = 36.0
|
||||
theme_override_styles/normal = ExtResource("2_cg22x")
|
||||
text = "Choice Hotkeys"
|
||||
|
||||
[node name="HotkeySelection" type="HBoxContainer" parent="VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
offset_top = 40.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 71.0
|
||||
|
||||
[node name="Label4" type="Label" parent="VBoxContainer2/HotkeySelection"]
|
||||
layout_mode = 2
|
||||
offset_top = 2.0
|
||||
offset_right = 428.0
|
||||
offset_bottom = 28.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Hotkey type"
|
||||
|
||||
[node name="HotkeyType" type="OptionButton" parent="VBoxContainer2/HotkeySelection"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_left = 432.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 31.0
|
||||
item_count = 2
|
||||
selected = 0
|
||||
popup/item_0/text = "No Hotkeys"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Default (1-9)"
|
||||
popup/item_1/id = 1
|
||||
|
||||
[node name="Info" type="Label" parent="VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
offset_top = 75.0
|
||||
offset_right = 570.0
|
||||
offset_bottom = 127.0
|
||||
size_flags_horizontal = 3
|
||||
text = "You can add more complex hotkeys by editing the \"shortcut\" property of a ChoiceButton. "
|
||||
autowrap_mode = 3
|
||||
script = ExtResource("3_mpugv")
|
||||
|
||||
[connection signal="toggled" from="VBoxContainer/Autofocus/Autofocus" to="." method="_on_Autofocus_toggled"]
|
||||
[connection signal="value_changed" from="VBoxContainer/Delay/Delay" to="." method="_on_Delay_value_changed"]
|
||||
[connection signal="item_selected" from="VBoxContainer/DefaultFalseBehaviour/FalseBehaviour" to="." method="_on_FalseBehaviour_item_selected"]
|
||||
[connection signal="item_selected" from="VBoxContainer2/HotkeySelection/HotkeyType" to="." method="_on_HotkeyType_item_selected"]
|
||||
132
Sprout/addons/dialogic/Events/Choice/subsystem_choices.gd
Normal file
132
Sprout/addons/dialogic/Events/Choice/subsystem_choices.gd
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
extends DialogicSubsystem
|
||||
|
||||
## Subsystem that manages showing and activating of choices.
|
||||
|
||||
## Used to block choices from being clicked for a couple of seconds (if delay is set in settings).
|
||||
var choice_blocker = Timer.new()
|
||||
|
||||
func _ready():
|
||||
choice_blocker.one_shot = true
|
||||
DialogicUtil.update_timer_process_callback(choice_blocker)
|
||||
add_child(choice_blocker)
|
||||
|
||||
|
||||
####################################################################################################
|
||||
## STATE
|
||||
####################################################################################################
|
||||
|
||||
func clear_game_state():
|
||||
hide_all_choices()
|
||||
|
||||
|
||||
####################################################################################################
|
||||
## MAIN METHODS
|
||||
####################################################################################################
|
||||
|
||||
## Hides all choice buttons.
|
||||
func hide_all_choices() -> void:
|
||||
for node in get_tree().get_nodes_in_group('dialogic_choice_button'):
|
||||
node.hide()
|
||||
if node.is_connected('button_up', self.choice_selected):
|
||||
node.disconnect('button_up', self.choice_selected)
|
||||
|
||||
|
||||
## Lists all current choices and shows buttons.
|
||||
func show_current_choices() -> void:
|
||||
hide_all_choices()
|
||||
var button_idx = 1
|
||||
for choice_index in get_current_choice_indexes():
|
||||
var choice_event = dialogic.current_timeline_events[choice_index]
|
||||
# check if condition is false
|
||||
if not choice_event.condition.is_empty() and not dialogic.execute_condition(choice_event.condition):
|
||||
if choice_event.else_action == DialogicChoiceEvent.ElseActions.Default:
|
||||
choice_event.else_action = DialogicUtil.get_project_setting('dialogic/choices/def_false_behaviour', 0)
|
||||
|
||||
# check what to do in this case
|
||||
if choice_event.else_action == DialogicChoiceEvent.ElseActions.Disable:
|
||||
if !choice_event.disabled_text.is_empty():
|
||||
show_choice(button_idx, choice_event.get_property_translated('disabled_text'), false, choice_index)
|
||||
else:
|
||||
show_choice(button_idx, choice_event.get_property_translated('text'), false, choice_index)
|
||||
button_idx += 1
|
||||
# else just show it
|
||||
else:
|
||||
show_choice(button_idx, choice_event.get_property_translated('text'), true, choice_index)
|
||||
button_idx += 1
|
||||
|
||||
if typeof(DialogicUtil.get_project_setting('dialogic/choices/delay')) != TYPE_FLOAT:
|
||||
choice_blocker.start(DialogicUtil.get_project_setting('dialogic/choices/delay', 0.2).to_float())
|
||||
else:
|
||||
choice_blocker.start(DialogicUtil.get_project_setting('dialogic/choices/delay', 0.2))
|
||||
|
||||
|
||||
## Adds a button with the given text that leads to the given event.
|
||||
func show_choice(button_index:int, text:String, enabled:bool, event_index:int) -> void:
|
||||
var idx = 1
|
||||
for node in get_tree().get_nodes_in_group('dialogic_choice_button'):
|
||||
if !node.get_parent().is_visible_in_tree():
|
||||
continue
|
||||
if (node.choice_index == button_index) or (idx == button_index and node.choice_index == -1):
|
||||
node.show()
|
||||
if dialogic.has_subsystem('VAR'):
|
||||
node.text = dialogic.VAR.parse_variables(text)
|
||||
else:
|
||||
node.text = text
|
||||
|
||||
if idx == 1 and DialogicUtil.get_project_setting('dialogic/choices/autofocus_first', true):
|
||||
node.grab_focus()
|
||||
|
||||
if DialogicUtil.get_project_setting('dialogic/choices/hotkey_behaviour', 0) == 1 and idx < 10:
|
||||
var shortcut = Shortcut.new()
|
||||
var input_key = InputEventKey.new()
|
||||
input_key.scancode = OS.find_keycode_from_string(str(idx))
|
||||
shortcut.shortcut = input_key
|
||||
node.shortcut = shortcut
|
||||
|
||||
node.disabled = not enabled
|
||||
node.button_up.connect(choice_selected.bind(event_index))
|
||||
|
||||
if node.choice_index > 0:
|
||||
idx = node.choice_index
|
||||
idx += 1
|
||||
|
||||
####################################################################################################
|
||||
## HELPERS
|
||||
####################################################################################################
|
||||
func choice_selected(event_index:int) -> void:
|
||||
if Dialogic.paused or not choice_blocker.is_stopped():
|
||||
return
|
||||
hide_all_choices()
|
||||
dialogic.current_state = dialogic.states.IDLE
|
||||
dialogic.handle_event(event_index)
|
||||
|
||||
## QUESTION/CHOICES
|
||||
func is_question(index:int) -> bool:
|
||||
if dialogic.current_timeline_events[index] is DialogicTextEvent:
|
||||
if len(dialogic.current_timeline_events)-1 != index:
|
||||
if dialogic.current_timeline_events[index+1] is DialogicChoiceEvent:
|
||||
return true
|
||||
return false
|
||||
|
||||
func get_current_choice_indexes() -> Array:
|
||||
var choices = []
|
||||
var evt_idx = dialogic.current_event_idx
|
||||
var ignore = 0
|
||||
while true:
|
||||
|
||||
evt_idx += 1
|
||||
if evt_idx >= len(dialogic.current_timeline_events):
|
||||
break
|
||||
if dialogic.current_timeline_events[evt_idx] is DialogicChoiceEvent:
|
||||
if ignore == 0:
|
||||
choices.append(evt_idx)
|
||||
ignore += 1
|
||||
elif dialogic.current_timeline_events[evt_idx].can_contain_events:
|
||||
ignore += 1
|
||||
else:
|
||||
if ignore == 0:
|
||||
break
|
||||
|
||||
if dialogic.current_timeline_events[evt_idx] is DialogicEndBranchEvent:
|
||||
ignore -= 1
|
||||
return choices
|
||||
11
Sprout/addons/dialogic/Events/Choice/ui_choice_end.gd
Normal file
11
Sprout/addons/dialogic/Events/Choice/ui_choice_end.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
var parent_resource: DialogicChoiceEvent = null
|
||||
|
||||
func refresh():
|
||||
if parent_resource is DialogicChoiceEvent:
|
||||
show()
|
||||
$Label.text = "End of choice ("+parent_resource.text+")"
|
||||
else:
|
||||
hide()
|
||||
13
Sprout/addons/dialogic/Events/Choice/ui_choice_end.tscn
Normal file
13
Sprout/addons/dialogic/Events/Choice/ui_choice_end.tscn
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/dialogic/Events/Choice/ui_choice_end.gd" id="1_7qd85"]
|
||||
|
||||
[node name="Choice_End" type="HBoxContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource("1_7qd85")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_top = 288.0
|
||||
offset_right = 1.0
|
||||
offset_bottom = 311.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue