Implemented npc_dialog step

This commit is contained in:
Malcolm Roberts 2024-01-12 14:53:12 -06:00
parent 55e1001b43
commit 1cda0fca3d
8 changed files with 272 additions and 132 deletions

View File

@ -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

View File

@ -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"]}"
}

View File

@ -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}"]
}
}

View File

@ -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

View File

@ -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
}
}

View File

@ -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,

View File

@ -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 <NPC Name> [...Dialog Choices(optional)]"
echo "Usage: GetQuestFromNpc <NPC Name> [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
}
#endif