Add addons
This commit is contained in:
parent
2c862b2235
commit
3367bad24f
527 changed files with 36197 additions and 0 deletions
126
Sprout/addons/dialogic/Events/Condition/event_condition.gd
Normal file
126
Sprout/addons/dialogic/Events/Condition/event_condition.gd
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
@tool
|
||||
class_name DialogicConditionEvent
|
||||
extends DialogicEvent
|
||||
|
||||
## Event that allows branching a timeline based on a condition.
|
||||
|
||||
enum ConditionTypes {If, Elif, Else}
|
||||
|
||||
### Settings
|
||||
## condition type (see [ConditionTypes]). Defaults to if.
|
||||
var condition_type := ConditionTypes.If
|
||||
## The condition as a string. Will be executed as an Expression.
|
||||
var condition: String = ""
|
||||
|
||||
|
||||
################################################################################
|
||||
## EXECUTE
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
if condition_type == ConditionTypes.Else:
|
||||
finish()
|
||||
return
|
||||
|
||||
if condition.is_empty(): condition = "true"
|
||||
|
||||
var result = dialogic.execute_condition(condition)
|
||||
if not result:
|
||||
var idx = dialogic.current_event_idx
|
||||
var ignore = 1
|
||||
while true:
|
||||
idx += 1
|
||||
if not dialogic.current_timeline.get_event(idx):
|
||||
break
|
||||
if ignore == 0 and dialogic.current_timeline.get_event(idx) is DialogicConditionEvent:
|
||||
break
|
||||
if dialogic.current_timeline.get_event(idx).can_contain_events:
|
||||
ignore += 1
|
||||
elif dialogic.current_timeline.get_event(idx) is DialogicEndBranchEvent:
|
||||
ignore -= 1
|
||||
elif ignore == 0:
|
||||
break
|
||||
|
||||
dialogic.current_event_idx = idx-1
|
||||
finish()
|
||||
|
||||
## only called if the previous event was an end-branch event
|
||||
## return true if this event should be executed if the previous event was an end-branch event
|
||||
func should_execute_this_branch() -> bool:
|
||||
return condition_type == ConditionTypes.If
|
||||
|
||||
|
||||
################################################################################
|
||||
## INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Condition"
|
||||
set_default_color('Color3')
|
||||
event_category = Category.Logic
|
||||
event_sorting_index = 0
|
||||
can_contain_events = true
|
||||
continue_at_end = true
|
||||
|
||||
|
||||
# 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_condition_end.tscn')).instantiate()
|
||||
|
||||
################################################################################
|
||||
## SAVING/LOADING
|
||||
################################################################################
|
||||
|
||||
func to_text() -> String:
|
||||
var result_string := ""
|
||||
|
||||
match condition_type:
|
||||
ConditionTypes.If:
|
||||
result_string = 'if '+condition+':'
|
||||
ConditionTypes.Elif:
|
||||
result_string = 'elif '+condition+':'
|
||||
ConditionTypes.Else:
|
||||
result_string = 'else:'
|
||||
|
||||
return result_string
|
||||
|
||||
|
||||
func from_text(string:String) -> void:
|
||||
if string.strip_edges().begins_with('if'):
|
||||
condition = string.strip_edges().trim_prefix('if ').trim_suffix(':').strip_edges()
|
||||
condition_type = ConditionTypes.If
|
||||
elif string.strip_edges().begins_with('elif'):
|
||||
condition = string.strip_edges().trim_prefix('elif ').trim_suffix(':').strip_edges()
|
||||
condition_type = ConditionTypes.Elif
|
||||
elif string.strip_edges().begins_with('else'):
|
||||
condition = ""
|
||||
condition_type = ConditionTypes.Else
|
||||
|
||||
|
||||
func is_valid_event(string:String) -> bool:
|
||||
if (string.strip_edges().begins_with('if ') or string.strip_edges().begins_with('elif ') or string.strip_edges().begins_with('else')) and string.strip_edges().ends_with(':'):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
################################################################################
|
||||
## EDITOR REPRESENTATION
|
||||
################################################################################
|
||||
|
||||
func build_event_editor():
|
||||
add_header_edit('condition_type', ValueType.FixedOptionSelector, '', '', {
|
||||
'selector_options': [
|
||||
{
|
||||
'label': 'IF',
|
||||
'value': ConditionTypes.If,
|
||||
},
|
||||
{
|
||||
'label': 'ELIF',
|
||||
'value': ConditionTypes.Elif,
|
||||
},
|
||||
{
|
||||
'label': 'ELSE',
|
||||
'value': ConditionTypes.Else,
|
||||
}
|
||||
], 'disabled':true})
|
||||
add_header_edit('condition', ValueType.Condition, '', '', {}, 'condition_type != %s'%ConditionTypes.Else)
|
||||
BIN
Sprout/addons/dialogic/Events/Condition/icon.png
Normal file
BIN
Sprout/addons/dialogic/Events/Condition/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 637 B |
34
Sprout/addons/dialogic/Events/Condition/icon.png.import
Normal file
34
Sprout/addons/dialogic/Events/Condition/icon.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b6bevon73e8mo"
|
||||
path="res://.godot/imported/icon.png-e7bc292be22002b6dc9192913250e17f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/dialogic/Events/Condition/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-e7bc292be22002b6dc9192913250e17f.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
|
||||
6
Sprout/addons/dialogic/Events/Condition/index.gd
Normal file
6
Sprout/addons/dialogic/Events/Condition/index.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
@tool
|
||||
extends DialogicIndexer
|
||||
|
||||
|
||||
func _get_events() -> Array:
|
||||
return [this_folder.path_join('event_condition.gd')]
|
||||
45
Sprout/addons/dialogic/Events/Condition/ui_condition_end.gd
Normal file
45
Sprout/addons/dialogic/Events/Condition/ui_condition_end.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
@tool
|
||||
extends HBoxContainer
|
||||
|
||||
var parent_resource = null
|
||||
|
||||
func _ready():
|
||||
$AddElif.button_up.connect(add_elif)
|
||||
$AddElse.button_up.connect(add_else)
|
||||
|
||||
func refresh():
|
||||
if parent_resource is DialogicConditionEvent:
|
||||
# hide add elif and add else button on ELSE event
|
||||
$AddElif.visible = parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.Else
|
||||
$AddElse.visible = parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.Else
|
||||
$Label.text = "End of "+["IF", "ELIF", "ELSE"][parent_resource.condition_type]+" ("+parent_resource.condition+")"
|
||||
|
||||
# hide add add else button if followed by ELIF or ELSE event
|
||||
var timeline_editor = find_parent('VisualEditor')
|
||||
if timeline_editor:
|
||||
var next_event = null
|
||||
if timeline_editor.get_block_below(get_parent()):
|
||||
next_event = timeline_editor.get_block_below(get_parent()).resource
|
||||
if next_event is DialogicConditionEvent:
|
||||
if next_event.condition_type != DialogicConditionEvent.ConditionTypes.If:
|
||||
$AddElse.hide()
|
||||
if parent_resource.condition_type == DialogicConditionEvent.ConditionTypes.Else:
|
||||
$Label.text = "End of ELSE"
|
||||
else:
|
||||
hide()
|
||||
|
||||
func add_elif():
|
||||
var timeline = find_parent('VisualEditor')
|
||||
if timeline:
|
||||
var resource = DialogicConditionEvent.new()
|
||||
resource.condition_type = DialogicConditionEvent.ConditionTypes.Elif
|
||||
timeline.add_event_with_end_branch(resource, get_parent().get_index()+1)
|
||||
timeline.indent_events()
|
||||
|
||||
func add_else():
|
||||
var timeline = find_parent('VisualEditor')
|
||||
if timeline:
|
||||
var resource = DialogicConditionEvent.new()
|
||||
resource.condition_type = DialogicConditionEvent.ConditionTypes.Else
|
||||
timeline.add_event_with_end_branch(resource, get_parent().get_index()+1)
|
||||
timeline.indent_events()
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/dialogic/Events/Condition/ui_condition_end.gd" id="1_sh52m"]
|
||||
|
||||
[node name="Condition_End" type="HBoxContainer"]
|
||||
offset_right = 90.0
|
||||
offset_bottom = 23.0
|
||||
script = ExtResource("1_sh52m")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_top = 2.0
|
||||
offset_right = 141.0
|
||||
offset_bottom = 28.0
|
||||
text = "End of condition X"
|
||||
|
||||
[node name="AddElif" type="Button" parent="."]
|
||||
offset_left = 145.0
|
||||
offset_right = 212.0
|
||||
offset_bottom = 31.0
|
||||
text = "Add Elif"
|
||||
|
||||
[node name="AddElse" type="Button" parent="."]
|
||||
offset_left = 216.0
|
||||
offset_right = 290.0
|
||||
offset_bottom = 31.0
|
||||
text = "Add Else"
|
||||
Loading…
Add table
Add a link
Reference in a new issue