From 1cda0fca3d928aea7bd39da931252e236bffb8b3 Mon Sep 17 00:00:00 2001 From: Malcolm Roberts Date: Fri, 12 Jan 2024 14:53:12 -0600 Subject: [PATCH] Implemented npc_dialog step --- auto_quest/actions/actions.iss | 15 ++ auto_quest/actions/npc_dialog_action.iss | 10 ++ .../npc_dialog_properties.iss | 100 ++++++++++++ .../npc_dialog_properties.json} | 0 .../property_editors/property_editors.iss | 21 +++ auto_quest/writer.iss | 143 ++++++------------ auto_quest/writer.json | 59 ++++++++ utilities/NpcHelpers.iss | 56 +++---- 8 files changed, 272 insertions(+), 132 deletions(-) create mode 100644 auto_quest/actions/actions.iss create mode 100644 auto_quest/actions/npc_dialog_action.iss create mode 100644 auto_quest/property_editors/npc_dialog_properties.iss rename auto_quest/{npc_dialog_ui.json => property_editors/npc_dialog_properties.json} (100%) create mode 100644 auto_quest/property_editors/property_editors.iss diff --git a/auto_quest/actions/actions.iss b/auto_quest/actions/actions.iss new file mode 100644 index 0000000..3966a43 --- /dev/null +++ b/auto_quest/actions/actions.iss @@ -0,0 +1,15 @@ +#ifndef _mr_auto_quest_actions_ +#define _mr_auto_quest_actions_ + +#include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/actions/npc_dialog_action.iss" + +function RunAction(string actionType, jsonvalue params) +{ + echo "RunAction: ${actionType}, ${params}" + if ${actionType.Equal["npc_dialog"]} + { + call npc_dialog_action params + } +} + +#endif \ No newline at end of file diff --git a/auto_quest/actions/npc_dialog_action.iss b/auto_quest/actions/npc_dialog_action.iss new file mode 100644 index 0000000..6086adb --- /dev/null +++ b/auto_quest/actions/npc_dialog_action.iss @@ -0,0 +1,10 @@ +#includeoptional "${LavishScript.HomeDirectory}/Scripts/mr/utilities/NpcHelpers.iss" + +function npc_dialog_action(jsonvalueref params) +{ + variable NpcHelpers npcHelpers + + echo "npc_dialog_action::params ${params.AsJSON~}" + + call npcHelpers.GetQuestFromNpc "${params.Get["npc_name"]}" "${params.Get["dialog_options"]}" +} \ No newline at end of file diff --git a/auto_quest/property_editors/npc_dialog_properties.iss b/auto_quest/property_editors/npc_dialog_properties.iss new file mode 100644 index 0000000..5a1eca1 --- /dev/null +++ b/auto_quest/property_editors/npc_dialog_properties.iss @@ -0,0 +1,100 @@ +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", + "horizontalAlignment": "left", + "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["${Script.CurrentDirectory}/property_editors/npc_dialog_properties.json"] + } + + method OnSetNPCNameButtonClick() + { + This.CurrentNPCName:Set["${Me.Target.Name}"] + } +} \ No newline at end of file diff --git a/auto_quest/npc_dialog_ui.json b/auto_quest/property_editors/npc_dialog_properties.json similarity index 100% rename from auto_quest/npc_dialog_ui.json rename to auto_quest/property_editors/npc_dialog_properties.json diff --git a/auto_quest/property_editors/property_editors.iss b/auto_quest/property_editors/property_editors.iss new file mode 100644 index 0000000..d83c4c7 --- /dev/null +++ b/auto_quest/property_editors/property_editors.iss @@ -0,0 +1,21 @@ +#ifndef _mr_property_editors_ +#define _mr_property_editors_ + +#includeoptional "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/property_editors/npc_dialog_properties.iss" + +variable(global) NPCDialogPropertiesController MRNPCDialogPropertiesController + +objectdef PropertyEditors +{ + static method GetPropertyEditor( string stepType ) + { + switch ( stepType ) + { + case MRNPCDialogPropertiesController.StepType: + return MRNPCDialogPropertiesController; + } + return null; + } +} + +#endif \ No newline at end of file diff --git a/auto_quest/writer.iss b/auto_quest/writer.iss index c0abee5..bbfa4ca 100644 --- a/auto_quest/writer.iss +++ b/auto_quest/writer.iss @@ -1,104 +1,7 @@ -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 +#include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/property_editors/property_editors.iss" +#include "${LavishScript.HomeDirectory}/Scripts/mr/auto_quest/actions/actions.iss" objectdef QuestWriterController { @@ -130,10 +33,40 @@ objectdef QuestWriterController { variable jsonvalue listItems = "[]" variable jsonvalue stepItem + variable jsonvalue listItem do { - listItems:Add["${This.FormatPropertiesForDisplay["${stepIterator.Value.AsJSON~}"].AsJSON~}"] + stepItem:SetValue["${This.FormatPropertiesForDisplay["${stepIterator.Value.AsJSON~}"].AsJSON~}"] + stepItem:Set["_dock", "\"left\""] + stepItem:Set["widthFactor", "0.8"] + + + listItem:SetValue[$$>"{ + "type": "dockpanel", + "widthFactor": .18, + "children": [ + ${stepItem.AsJSON~}, + { + "type": "button", + "content": "Test", + "_dock": "right", + "verticalAlignment": "center", + + "_step": ${stepIterator.Value.AsJSON~} + "eventHandlers": { + "onRelease": { + "type": "method", + "object": "MRQuestWriterController", + "method": "OnTestStepButtonClick", + } + } + } + ] + }"<$$] + + listItems:Add["${listItem.AsJSON~}"] + } while ${stepIterator:Next(exists)} } @@ -162,6 +95,15 @@ objectdef QuestWriterController LGUI2.Element["mr.quest_writer.properties_panel"]:AddChild[MRNPCDialogPropertiesController.GetUI] } + method OnTestStepButtonClick() + { + variable jsonvalue step + step:SetValue["${Context.Source.Metadata.Get["step"].AsJSON~}"] + echo "${step.AsJSON~}" + QueueCommand call RunAction ${step.Get["type"]} "${step.Get["params"].AsJSON~}" + + } + method OnAddStepButtonClick() { This.QuestSteps:Add["${This.CurrentStepProperties.GetDialogOptions.AsJSON~}"] @@ -176,6 +118,7 @@ function main() { while 1 { + ExecuteQueued wait 1 } } \ No newline at end of file diff --git a/auto_quest/writer.json b/auto_quest/writer.json index fd80bdb..062ee34 100644 --- a/auto_quest/writer.json +++ b/auto_quest/writer.json @@ -32,9 +32,64 @@ "height": 16 } }, + "listbox.contentContainer": { + "jsonTemplate": "scrollviewer", + "type": "scrollviewer", + "acceptsMouseFocus": false, + "contentContainer": { + "type": "border", + "horizontalContentAlignment": "stretch", + "verticalContentAlignment": "stretch" + } + }, "listbox.contentContainerFitWidth": { "jsonTemplate": "listbox.contentContainer", "horizontalScroll": "fit" + }, + "listbox.content": { + "type": "stackpanel", + "uniform": true, + "backgroundBrush": "listbox.backgroundBrush" + }, + "listbox": { + "defaultItemViewTemplate": "listboxitem", + "acceptsKeyboardFocus": true, + "padding": [ 1, 1, 1, 1 ], + "borderThickness": 1, + "borderBrush": "listbox.borderBrush", + "contentContainer": { + "jsonTemplate": "listbox.contentContainer" + }, + "content": { + "jsonTemplate": "listbox.content" + } + }, + "itemview": { + "type": "itemview", + "acceptsKeyboardFocus": false, + "contentContainer": { + "type": "border", + "horizontalContentAlignment": "stretch", + "verticalContentAlignment": "stretch" + }, + "padding": [ 2, 2, 2, 2 ], + "margin": [ 1, 1, 1, 1 ], + "backgroundBrush": "itemview.backgroundBrush", + "eventHandlers": { + "onMouseButtonMove": { + "type": "forward", + "elementType": "itemlist", + "event": "onItemMouseButtonMove" + } + }, + "styles": { + "onSelected": { + "backgroundBrush": "itemview.selectedBackgroundBrush" + }, + "onDeselected": { + "backgroundBrush": "itemview.backgroundBrush" + } + } } } }, @@ -169,6 +224,7 @@ { "type": "stackpanel", "heightFactor": 1, + "widthFactor": 1, "children": [ { "type": "textblock", @@ -181,6 +237,9 @@ "name": "mr.quest_writer.quest_steps", "heightFactor": 1, "widthFactor": 1, + "-contentContainer":{ + "jsonTemplate":"listbox.contentContainerFitWidth" + }, "itemsBinding": { "pullFormat": "${MRQuestWriterController.GetQuestStepsForDisplay}", "autoPull": false, diff --git a/utilities/NpcHelpers.iss b/utilities/NpcHelpers.iss index 26a7c3c..5ca2b21 100644 --- a/utilities/NpcHelpers.iss +++ b/utilities/NpcHelpers.iss @@ -1,3 +1,5 @@ +#ifndef _mr_npc_helpers_ +#define _mr_npc_helpers_ objectdef QuestHelpers { member:bool IsQuestPending() @@ -13,23 +15,35 @@ objectdef QuestHelpers objectdef NpcHelpers { variable QuestHelpers QuestHelper - function GetQuestFromNpc(... params) + function GetQuestFromNpc(string npcName, string choices) { - if ${params.Size} < 1 + echo "NpcHelpers::GetQuestFromNpc[\"${npcName}\", \"${choices}\"]" + if ${npcName.Length} < 1 { - echo "Usage: GetQuestFromNpc [...Dialog Choices(optional)]" + echo "Usage: GetQuestFromNpc [comma separted string of dialog choices(optional)]" return } - variable string npcName = ${params[1]}; Actor[Query, Name =- "${npcName}"]:DoubleClick - if ${params.Size} > 1 + wait 5 + + variable int numChoices = 0 + if ${choices.Length} > 0 + { + numChoices:Set[${choices.Count[","]}] + numChoices:Inc + } + + if ${numChoices} > 0 { variable int idx - for (idx:Set[2]; ${idx} <= ${params.Size}; idx:Inc) + for (idx:Set[1]; ${idx} <= ${numChoices}; idx:Inc) { - variable string choice = ${params[i]}; - EQ2UIPage[ProxyActor,Conversation].Child[composite,replies].Child[button,choice]:LeftClick + variable string choice + choice:Set[${choices.Token[${idx}, ","]}] + echo "choice: ${choice}" + EQ2UIPage[ProxyActor,Conversation].Child[composite,replies]:SpewProperties + EQ2UIPage[ProxyActor,Conversation].Child[composite,replies].Child[${choice}]:LeftClick wait 5 } } @@ -38,6 +52,7 @@ objectdef NpcHelpers variable int dialogOptionsTaken = 0; do { + echo "Clicking dialog option 1 for loop #${dialogOptionsTaken}" dialogOptionsTaken:Inc EQ2UIPage[ProxyActor,Conversation].Child[composite,replies].Child[button,1]:LeftClick wait 5 @@ -59,27 +74,4 @@ objectdef NpcHelpers } } - - -atom atexit() -{ - echo "Exiting..." -} - -function main() -{ - ; variable NpcHelpers NpcHelper - ; variable NavHelpers NavHelper - ; echo "Starting test" - - ; /* - ; 910.060730,12.070809,239.235611 - ; 913.628540,10.217931,170.337494 - ; 907.632385,10.002500,152.857849 - ; 897.398376,10.180861,146.060623 - ; */ - ; ; wait 5 - ; ; call NpcHelper.GetQuestFromNpc "Germa" - ; call NavHelper.FollowPath() - ; return -} \ No newline at end of file +#endif \ No newline at end of file