Added more quest stuff including dialogic quest condition

This commit is contained in:
Jonathan
2025-08-06 17:20:11 +02:00
parent abc33fd06c
commit 0170a53b5a
36 changed files with 540 additions and 41 deletions
@@ -8,7 +8,7 @@ var quest_resource: String
func _execute() -> void:
var resource = ResourceLoader.load(quest_resource)
QuestManager.ChangeQuestStatus(resource,QuestEventUtils.QuestStatus.ACTIVE)
QuestManager.ChangeQuestStatus(resource,QuestEventUtils.QuestStatus.AVAILABLE)
QuestManager.SetFollowQuest(resource)
finish() # called to continue with the next event
@@ -0,0 +1,163 @@
@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.GetFollowQuest() == resource
elif compare_status == QuestEventUtils.QuestStatusOrActive.NOT_ACTIVE:
result = QuestManager.GetFollowQuest() != 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
@@ -0,0 +1 @@
uid://b2ggc2f5kh61j
+11 -1
View File
@@ -1,12 +1,22 @@
@tool
class_name QuestEventUtils
enum QuestStatus{
HIDDEN = 0,
ACTIVE = 1,
AVAILABLE = 1,
DONE = 2,
CANCLED = 3
}
enum QuestStatusOrActive{
HIDDEN = 0,
AVAILABLE = 1,
DONE = 2,
CANCLED = 3,
ACTIVE = 4,
NOT_ACTIVE = 5
}
static func quest_resource_suggestrions(search_text:String) -> Dictionary:
var ret_val = {}
+2 -1
View File
@@ -4,5 +4,6 @@ extends DialogicIndexer
func _get_events() -> Array:
return [
this_folder.path_join('event_quest_activate.gd'),
this_folder.path_join('event_quest_complete.gd')
this_folder.path_join('event_quest_complete.gd'),
this_folder.path_join('event_quest_condition.gd')
]
@@ -0,0 +1,51 @@
@tool
extends HBoxContainer
var parent_resource: DialogicEvent = null
func _ready() -> void:
$AddElif.button_up.connect(add_elif)
$AddElse.button_up.connect(add_else)
func refresh() -> void:
if parent_resource is DialogicQuestConditionEvent:
# hide add elif and add else button on ELSE event
$AddElif.visible = false# parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
$AddElse.visible = true# parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
$Label.text = "End of If Quest" #"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: DialogicEvent = 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() -> void:
var timeline := find_parent('VisualEditor')
if timeline:
var resource := DialogicConditionEvent.new()
resource.condition_type = DialogicConditionEvent.ConditionTypes.ELIF
timeline.add_event_undoable(resource, get_parent().get_index()+1)
timeline.indent_events()
timeline.something_changed()
func add_else() -> void:
var timeline := find_parent('VisualEditor')
if timeline:
var resource := DialogicConditionEvent.new()
resource.condition_type = DialogicConditionEvent.ConditionTypes.ELSE
timeline.add_event_undoable(resource, get_parent().get_index()+1)
timeline.indent_events()
timeline.something_changed()
@@ -0,0 +1 @@
uid://dlrnhnnonum4o
@@ -0,0 +1,20 @@
[gd_scene load_steps=2 format=3 uid="uid://dnrpcgjkyoiau"]
[ext_resource type="Script" uid="uid://dlrnhnnonum4o" path="res://addons/dialogic_additions/Quest/ui_condition_end.gd" id="1_f3miq"]
[node name="Condition_End" type="HBoxContainer"]
offset_right = 90.0
offset_bottom = 23.0
script = ExtResource("1_f3miq")
[node name="Label" type="Label" parent="."]
layout_mode = 2
text = "End of condition X"
[node name="AddElif" type="Button" parent="."]
layout_mode = 2
text = "Add Elif"
[node name="AddElse" type="Button" parent="."]
layout_mode = 2
text = "Add Else"