You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
5.3 KiB
164 lines
5.3 KiB
@tool
|
|
extends DialogicEvent
|
|
class_name DialogicQuestConditionEvent
|
|
|
|
## 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 := ""
|
|
var quest_resource: String
|
|
var compare_status: QuestEventUtils.QuestStatusOrActive
|
|
|
|
################################################################################
|
|
## EXECUTE
|
|
################################################################################
|
|
|
|
func _execute() -> void:
|
|
var resource = ResourceLoader.load(quest_resource)
|
|
|
|
var result: bool
|
|
if compare_status == QuestEventUtils.QuestStatusOrActive.ACTIVE:
|
|
result = QuestManager.GetActiveQuest() == resource
|
|
elif compare_status == QuestEventUtils.QuestStatusOrActive.NOT_ACTIVE:
|
|
result = QuestManager.GetActiveQuest() != resource
|
|
else:
|
|
result = QuestManager.GetQuestStatus(resource).status == compare_status
|
|
|
|
if not result:
|
|
var idx: int = dialogic.current_event_idx
|
|
var ignore := 1
|
|
while true:
|
|
idx += 1
|
|
if not dialogic.current_timeline.get_event(idx) or ignore == 0:
|
|
break
|
|
elif dialogic.current_timeline.get_event(idx).can_contain_events:
|
|
ignore += 1
|
|
elif dialogic.current_timeline.get_event(idx) is DialogicEndBranchEvent:
|
|
ignore -= 1
|
|
|
|
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 true
|
|
|
|
|
|
################################################################################
|
|
## INITIALIZE
|
|
################################################################################
|
|
|
|
func _init() -> void:
|
|
event_name = "Quest Condition"
|
|
set_default_color('Color3')
|
|
event_category = "Quest"
|
|
event_sorting_index = 1
|
|
can_contain_events = 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_quest_condition_end.tscn')).instantiate()
|
|
|
|
################################################################################
|
|
## SAVING/LOADING
|
|
################################################################################
|
|
|
|
func to_text() -> String:
|
|
return 'ifquest ' + quest_resource + ', ' + str(compare_status) + ':'
|
|
|
|
|
|
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
|
|
var strings:Array[String]
|
|
strings.assign(string.strip_edges().trim_prefix('ifquest ').trim_suffix(':').strip_edges().split(','))
|
|
quest_resource = strings[0].strip_edges()
|
|
var compare_string: String = strings[1].strip_edges()
|
|
if compare_string.is_valid_int():
|
|
compare_status = compare_string.to_int()
|
|
else:
|
|
compare_status = QuestEventUtils.QuestStatusOrActive.get(compare_string)
|
|
|
|
|
|
func is_valid_event(string:String) -> bool:
|
|
if string.strip_edges().begins_with('ifquest '):
|
|
return true
|
|
return false
|
|
|
|
|
|
################################################################################
|
|
## EDITOR REPRESENTATION
|
|
################################################################################
|
|
|
|
func build_event_editor() -> void:
|
|
add_header_label("IF")
|
|
add_header_edit(
|
|
"quest_resource",
|
|
ValueType.DYNAMIC_OPTIONS,
|
|
{
|
|
"mode":2,
|
|
"suggestions_func":QuestEventUtils.quest_resource_suggestrions
|
|
})
|
|
add_header_label("IS")
|
|
add_header_edit("compare_status",ValueType.FIXED_OPTIONS,{
|
|
'options': [
|
|
{
|
|
'label': 'HIDDEN',
|
|
'value': QuestEventUtils.QuestStatusOrActive.HIDDEN,
|
|
},
|
|
{
|
|
'label': 'AVAILABLE',
|
|
'value': QuestEventUtils.QuestStatusOrActive.AVAILABLE,
|
|
},
|
|
{
|
|
'label': 'DONE',
|
|
'value': QuestEventUtils.QuestStatusOrActive.DONE,
|
|
},
|
|
{
|
|
'label': 'CANCLED',
|
|
'value': QuestEventUtils.QuestStatusOrActive.CANCLED,
|
|
},
|
|
{
|
|
'label': 'ACTIVE',
|
|
'value': QuestEventUtils.QuestStatusOrActive.ACTIVE,
|
|
},
|
|
{
|
|
'label': 'NOT_ACTIVE',
|
|
'value': QuestEventUtils.QuestStatusOrActive.NOT_ACTIVE,
|
|
}
|
|
]})
|
|
|
|
func _get_icon() -> Resource:
|
|
return load("res://addons/dialogic/Modules/Condition/icon.svg")
|
|
|
|
####################### CODE COMPLETION ########################################
|
|
################################################################################
|
|
|
|
func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:String, _word:String, symbol:String) -> void:
|
|
pass
|
|
|
|
|
|
func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
|
|
TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'ifquest', 'ifquest ', TextNode.syntax_highlighter.code_flow_color)
|
|
|
|
|
|
#################### SYNTAX HIGHLIGHTING #######################################
|
|
################################################################################
|
|
|
|
|
|
func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
|
|
var word := line.get_slice(' ', 0)
|
|
dict[line.find(word)] = {"color":Highlighter.code_flow_color}
|
|
dict[line.find(word)+len(word)] = {"color":Highlighter.normal_color}
|
|
dict = Highlighter.color_condition(dict, line)
|
|
return dict
|