From 40e47d36d054622f9aee29df22d3fad19828d784 Mon Sep 17 00:00:00 2001 From: Malcolm Roberts Date: Fri, 12 Jan 2024 09:24:26 -0600 Subject: [PATCH] Start of quest writer --- auto_quest/npc_dialog_ui.json | 97 ++++++++++++++++++ auto_quest/writer.iss | 178 +++++++++++++++++++++++++++------- auto_quest/writer.json | 150 +++------------------------- 3 files changed, 254 insertions(+), 171 deletions(-) create mode 100644 auto_quest/npc_dialog_ui.json diff --git a/auto_quest/npc_dialog_ui.json b/auto_quest/npc_dialog_ui.json new file mode 100644 index 0000000..d2dd9b6 --- /dev/null +++ b/auto_quest/npc_dialog_ui.json @@ -0,0 +1,97 @@ +{ + "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json", + "type": "stackpanel", + "name": "mr.quest_writer.npc_dialog_properties", + "_dock": "bottom", + "borderBrush": { + "color": "#f4f3ee" + }, + "borderThickness": [0, 2, 0, 0], + "header": "test", + "children": [ + { + "type": "panel", + "borderBrush": { + "color": "#f4f3ee" + }, + "borderThickness": [0, 0, 0, 1], + "margin": [0, 0, 0, 15], + "children": [ + { + "type": "textblock", + "text": "NPC Dialog Properties", + "font": { + "bold": true, + "heightFactor": 1.2 + }, + "horizontalAlignment": "center", + "widthFactor": 1 + } + ] + }, + { + "type": "textblock", + "text": "NPC Name:", + "widthFactor": 1, + "horizontalAlignment": "left", + "font": { + "heightFactor": 0.9 + } + }, + { + "type": "stackpanel", + "orientation": "horizontal", + "children": [ + { + "type": "button", + "content": "◎", + "tooltip": "Set the NPC name to the currently targeted NPC.", + "horizontalAlignment": "left", + "eventHandlers": { + "onRelease": [ + "method", + "MRNPCDialogPropertiesController", + "OnSetNPCNameButtonClick" + ] + } + }, + { + "type": "textblock", + "horizontalAlignment": "left", + "widthFactor": 1, + "text": "${MRNPCDialogPropertiesController.CurrentNPCName}" + } + ] + }, + { + "type": "stackpanel", + "orientation": "vertical", + "children": [ + { + "type": "textblock", + "text": "Dialog Options:", + "horizontalAlignment": "left", + "widthFactor": 1, + "font": { + "heightFactor": 0.9 + } + }, + { + "type": "textbox", + "name": "mr.quest_writer.npc_dialog_dialog_options", + "horizontalAlignment": "left", + "widthFactor": 1, + "tooltip": "A comma separated list of the\nnumber of the dialog option to\npick tomake the quest dialog appear.\n\ne.g. 1,2,1,1,2", + "textBinding": { + "pullFormat": "${MRNPCDialogPropertiesController.CurrentDialogOptions}", + "pullReplaceNull": "", + "pushFormat": [ + "MRNPCDialogPropertiesController.CurrentDialogOptions:Set[\"", + "\"]" + ] + } + } + ] + } + ] +} diff --git a/auto_quest/writer.iss b/auto_quest/writer.iss index 1e44009..c0abee5 100644 --- a/auto_quest/writer.iss +++ b/auto_quest/writer.iss @@ -1,9 +1,145 @@ +objectdef NPCDialogPropertiesController +{ + variable string CurrentDialogOptions + variable string CurrentNPCName + variable jsonvalue ui ="{}" + variable string StepType = "npc_dialog" + + member:jsonvalueref GetUI() + { + return ui + } + + member:jsonvalueref GetDialogOptions() + { + variable jsonvalue dialogOptions + + dialogOptions:SetValue[$$>"{ + "type": "${This.StepType}", + "params": { + "npc_name": ${This.CurrentNPCName.AsJSON~}, + "dialog_options": ${This.CurrentDialogOptions.AsJSON~} + } + }"<$$] + + return dialogOptions + } + + member:jsonvalueref GetDisplayForProperties(jsonvalueref step) + { + variable jsonvalue stepItem + variable string options + variable string npcName + + options:Set["${step.Get["params","dialog_options"]}"] + npcName:Set["${step.Get["params","npc_name"]}"] + + stepItem:SetValue[$$>"{ + "type": "stackpanel", + "orientation": "vertical", + "children": [ + { + "type": "textblock", + "horizontalAlignment": "stretch", + "font": { + "bold": true, + "heightFactor": 1.1 + }, + "text": "NPC Dialog" + }, + { + "type": "stackpanel", + "orientation": "horizontal", + "horizontalAlignment": "stretch", + "padding": [5, 0, 0, 0], + "children": [ + { + "type": "textblock", + "text": "NPC Name:", + "margin": [0, 0, 5, 0] + }, + { + "type": "textblock", + "text": ${npcName.AsJSON~} + } + ] + }, + { + "type": "stackpanel", + "orientation": "horizontal", + "horizontalAlignment": "stretch", + "padding": [5, 0, 0, 0], + "children": [ + { + "type": "textblock", + "text": "Options:", + "margin": [0, 0, 5, 0] + }, + { + "type": "textblock", + "text": ${options.AsJSON~} + } + ] + } + ] + }"<$$] + + return stepItem + } + + method Initialize() + { + ui:ParseFile["npc_dialog_ui.json"] + } + + method OnSetNPCNameButtonClick() + { + This.CurrentNPCName:Set["${Me.Target.Name}"] + } +} + +variable(global) NPCDialogPropertiesController MRNPCDialogPropertiesController + objectdef QuestWriterController { - variable string CurrentNPCName variable string CurrentStepType - variable string CurrentDialogOptions + variable weakref CurrentStepProperties + variable jsonvalue QuestSteps = [] + + member:jsonvalueref FormatPropertiesForDisplay(jsonvalue step) + { + variable jsonvalue stepItem + if ${step.Get["type"].Equal["${MRNPCDialogPropertiesController.StepType}"]} + { + stepItem:SetValue["${MRNPCDialogPropertiesController.GetDisplayForProperties[step].AsJSON~}"] + return stepItem + } + else + { + return null + } + } + + member:string GetQuestStepsForDisplay() + { + variable jsoniterator stepIterator + This.QuestSteps:GetIterator[stepIterator] + + if ${stepIterator:First(exists)} + { + variable jsonvalue listItems = "[]" + variable jsonvalue stepItem + + do + { + listItems:Add["${This.FormatPropertiesForDisplay["${stepIterator.Value.AsJSON~}"].AsJSON~}"] + } + while ${stepIterator:Next(exists)} + } + return ${listItems.AsJSON~} + } + method Initialize() { @@ -22,43 +158,14 @@ objectdef QuestWriterController method OnNPCDialogButtonClick() { - CurrentStepType:Set["ncp_dialog"] - LGUI2.Element["mr.quest_writer.npc_dialog_properties"]:SetVisibility["visible"] - } - - method OnSetNPCNameButtonClick() - { - echo "Setting NPC Name to ${Me.Target.Name}" - This.CurrentNPCName:Set["${Me.Target.Name}"] + CurrentStepProperties:SetReference[MRNPCDialogPropertiesController] + LGUI2.Element["mr.quest_writer.properties_panel"]:AddChild[MRNPCDialogPropertiesController.GetUI] } method OnAddStepButtonClick() { - variable jsonvalue newStep - - newStep:SetValue[$$>"{ - "type": ${This.CurrentStepType.AsJSON~}, - "params": { - "npc_name": ${This.CurrentNPCName.AsJSON~}, - "dialog_options": ${This.CurrentDialogOptions.AsJSON~} - } - }"<$$] - This.QuestSteps:Add["${newStep.AsJSON~}"] - - echo "Current Steps ${This.QuestSteps.AsJSON~}" - } - - member:jsonvalueref CurrentSteps() - { - variable jsonvalue questList - - questList:SetValue[$$>"[ - "Step 1", - "Step 2", - "Step 3", - ]"<$$] - - return questList + This.QuestSteps:Add["${This.CurrentStepProperties.GetDialogOptions.AsJSON~}"] + LGUI2.Element[MRQuestWriterController.events]:FireEventHandler[onNewStepAdded] } } @@ -67,7 +174,6 @@ variable(global) QuestWriterController MRQuestWriterController function main() { - echo "${MRQuestWriterController.CurrentSteps.AsJSON~}" while 1 { wait 1 diff --git a/auto_quest/writer.json b/auto_quest/writer.json index b49b987..fd80bdb 100644 --- a/auto_quest/writer.json +++ b/auto_quest/writer.json @@ -8,41 +8,6 @@ } }, "templates": { - "mr.quest_writer.quest_steps.list_entry": { - "jsontemplate": "listboxitem", - "padding": 2, - "borderBrush": { - "color": "#f4f3ee" - }, - "borderThickness": [0, 0, 0, 1], - "content": { - "type": "stackpanel", - "orientation": "vertical", - "-contentContainer": { - "jsonTemplate": "listbox.contentContainerFitWidth" - }, - "children": [ - { - "type": "textblock", - "horizontalAlignment": "stretch", - "font": { - "bold": true, - "heightFactor": 1.1 - }, - "textBinding": { - "pullFormat": "${_CONTEXTITEMDATA_.Get[type]}" - } - }, - { - "type": "textblock", - "horizontalAlignment": "stretch", - "textBinding": { - "pullFormat": "${_CONTEXTITEMDATA_.Get[params].AsJSON[multiline]}" - } - } - ] - } - }, "window.title": { "verticalAlignment": "center", "margin": [2, 0, 0, 0] @@ -100,6 +65,11 @@ "heightFactor": 1, "orientation": "horizontal", "children": [ + { + "type": "panel", + "visibility": "hidden", + "name": "MRQuestWriterController.events" + } { "type": "dockpanel", "widthFactor": 0.2, @@ -188,101 +158,11 @@ ] }, { - "type": "stackpanel", - "name": "mr.quest_writer.npc_dialog_properties", - "visibility": "hidden", + "type": "panel", + "widthFactor": 1, "_dock": "bottom", - "borderBrush": { - "color": "#f4f3ee" - }, - "borderThickness": [0, 2, 0, 0], - "header": "test", - "children": [ - { - "type": "panel", - "borderBrush": { - "color": "#f4f3ee" - }, - "borderThickness": [0, 0, 0, 1], - "margin": [0, 0, 0, 15], - "children": [ - { - "type": "textblock", - "text": "NPC Dialog Properties", - "font": { - "bold": true, - "heightFactor": 1.2 - }, - "horizontalAlignment": "center", - "widthFactor": 1 - } - ] - }, - { - "type": "textblock", - "text": "NPC Name:", - "widthFactor": 1, - "horizontalAlignment": "left", - "font": { - "heightFactor": 0.9 - } - }, - { - "type": "stackpanel", - "orientation": "horizontal", - "children": [ - { - "type": "button", - "content": "◎", - "tooltip": "Set the NPC name to the currently targeted NPC.", - "horizontalAlignment": "left", - "eventHandlers": { - "onRelease": [ - "method", - "MRQuestWriterController", - "OnSetNPCNameButtonClick" - ] - } - }, - { - "type": "textblock", - "horizontalAlignment": "left", - "widthFactor": 1, - "text": "${MRQuestWriterController.CurrentNPCName}" - } - ] - }, - { - "type": "stackpanel", - "orientation": "vertical", - "children": [ - { - "type": "textblock", - "text": "Dialog Options:", - "horizontalAlignment": "left", - "widthFactor": 1, - "font": { - "heightFactor": 0.9 - } - }, - { - "type": "textbox", - "name": "mr.quest_writer.npc_dialog_dialog_options", - "horizontalAlignment": "left", - "widthFactor": 1, - "tooltip": "A comma separated list of the\nnumber of the dialog option to\npick tomake the quest dialog appear.\n\ne.g. 1,2,1,1,2", - "textBinding": { - "pullFormat": "${MRQuestWriterController.CurrentDialogOptions}", - "pullReplaceNull": "", - "pushFormat": [ - "MRQuestWriterController.CurrentDialogOptions:Set[\"", - "\"]" - ] - } - } - ] - } - ] + "name": "mr.quest_writer.properties_panel", + "children": [] } ] }, @@ -302,12 +182,12 @@ "heightFactor": 1, "widthFactor": 1, "itemsBinding": { - "pullFormat": "${MRQuestWriterController.QuestSteps}" - }, - "itemViewGenerators": { - "default": { - "type": "template", - "template": "mr.quest_writer.quest_steps.list_entry" + "pullFormat": "${MRQuestWriterController.GetQuestStepsForDisplay}", + "autoPull": false, + "pullHook": { + "elementName": "MRQuestWriterController.events", + "flags": "global", + "event": "onNewStepAdded" } } }