How to Open New Form On Action/Condition to Pick a Profession Task

Post Reply
nw_sony
Advanced Member
Advanced Member
Posts: 33
Joined: Tue Jun 21, 2016 6:21 am

How to Open New Form On Action/Condition to Pick a Profession Task

Post by nw_sony »

Hey!

I'm running into some trouble when I want to pick a Profession Task within an action or condition using the Astral.Professions.Forms.TasksEditor. In the existing action "StartATask" you can pick a task by clicking the three dots next to the "Task" row and bringing up the form. I can't replicate this for my own actions and conditions. How is this done?

Regards!
michaelprog
Contributor
Contributor
Posts: 534
Joined: Wed Aug 31, 2016 7:32 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by michaelprog »

nw_sony wrote: Sat Sep 11, 2021 4:17 pm Hey!

I'm running into some trouble when I want to pick a Profession Task within an action or condition using the Astral.Professions.Forms.TasksEditor. In the existing action "StartATask" you can pick a task by clicking the three dots next to the "Task" row and bringing up the form. I can't replicate this for my own actions and conditions. How is this done?

Regards!
You have to add attribute "Editor" to the property of your action/condition. Like this

code: Select all

[Editor(typeof(TaskEditor), typeof(UITypeEditor))]
public Task Task { get; set; }
nw_sony
Advanced Member
Advanced Member
Posts: 33
Joined: Tue Jun 21, 2016 6:21 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by nw_sony »

michaelprog wrote: Sat Sep 11, 2021 8:39 pm
nw_sony wrote: Sat Sep 11, 2021 4:17 pm Hey!

I'm running into some trouble when I want to pick a Profession Task within an action or condition using the Astral.Professions.Forms.TasksEditor. In the existing action "StartATask" you can pick a task by clicking the three dots next to the "Task" row and bringing up the form. I can't replicate this for my own actions and conditions. How is this done?

Regards!
You have to add attribute "Editor" to the property of your action/condition. Like this

code: Select all

[Editor(typeof(TaskEditor), typeof(UITypeEditor))]
public Task Task { get; set; }
Thanks!

I tried to follow your solution, but it didn't quite work just yet. Now my Property Value is completely black when I add the Condition to an Action:

Image

My Code:

code: Select all

using System.ComponentModel;
using Astral.Professions.Forms;
using Astral.Professions.Classes;
using System.Drawing.Design;

public class MyCondition : Astral.Quester.Classes.Condition
{
	// ...
	[Editor(typeof(TasksEditor), typeof(UITypeEditor))]
	public Task Task { get; set; }
	// ...
}
michaelprog
Contributor
Contributor
Posts: 534
Joined: Wed Aug 31, 2016 7:32 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by michaelprog »

nw_sony wrote: Sun Sep 12, 2021 3:58 am I tried to follow your solution, but it didn't quite work just yet. Now my Property Value is completely black when I add the Condition to an Action:
Do you initialize the Task object ?
Try to initialize it in constructor

code: Select all

Task = new Task();
nw_sony
Advanced Member
Advanced Member
Posts: 33
Joined: Tue Jun 21, 2016 6:21 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by nw_sony »

michaelprog wrote: Sun Sep 12, 2021 4:00 pm
nw_sony wrote: Sun Sep 12, 2021 3:58 am I tried to follow your solution, but it didn't quite work just yet. Now my Property Value is completely black when I add the Condition to an Action:
Do you initialize the Task object ?
Try to initialize it in constructor

code: Select all

Task = new Task();
Still no luck unfortunately, but appreciate your help on the topic!

My only guess is that TasksEditor doesn't come with a constructor and can't be initialized correctly? Maybe @Jarod can help here? I worked around the issue by bringing up the TasksEditor in the constructor (Condition) or GatherInfos (Action) and set the Tasks there. It works, because you can obviously just set the task once and have to re-insert the condition or action whenever the task changes.
michaelprog
Contributor
Contributor
Posts: 534
Joined: Wed Aug 31, 2016 7:32 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by michaelprog »

Still no luck unfortunately, but appreciate your help on the topic!

My only guess is that TasksEditor doesn't come with a constructor and can't be initialized correctly? Maybe @Jarod can help here? I worked around the issue by bringing up the TasksEditor in the constructor (Condition) or GatherInfos (Action) and set the Tasks there. It works, because you can obviously just set the task once and have to re-insert the condition or action whenever the task changes.
This is strange.
Can you show me all code of your class?
nw_sony
Advanced Member
Advanced Member
Posts: 33
Joined: Tue Jun 21, 2016 6:21 am

Re: How to Open New Form On Action/Condition to Pick a Profession Task

Post by nw_sony »

michaelprog wrote: Tue Sep 14, 2021 10:29 am
Still no luck unfortunately, but appreciate your help on the topic!

My only guess is that TasksEditor doesn't come with a constructor and can't be initialized correctly? Maybe @Jarod can help here? I worked around the issue by bringing up the TasksEditor in the constructor (Condition) or GatherInfos (Action) and set the Tasks there. It works, because you can obviously just set the task once and have to re-insert the condition or action whenever the task changes.
This is strange.
Can you show me all code of your class?

code: Select all

using Astral.Logic.Classes.Map;
using MyNW.Classes;
using System.ComponentModel;
using System.Drawing.Design;
using Astral.Professions.Forms;

namespace MyPlugin.Actions
{
    public class RushTask : Astral.Quester.Classes.Action
    {
        public RushTask() {
            var task = new Astral.Professions.Classes.Task();
            Task = task;
        }

        [Editor(typeof(TasksEditor), typeof(UITypeEditor))]
        public Astral.Professions.Classes.Task Task { get; set; }

        public override string ActionLabel => "RushTask: " + Task.DisplayName;

        public override string Category => "Tasks";

        public override bool NeedToRun => true;

        public override string InternalDisplayName => "RushTask";

        public override bool UseHotSpots => false;

        protected override bool IntenalConditions => true;

        protected override Vector3 InternalDestination => MyNW.Classes.Vector3.Empty;

        protected override ActionValidity InternalValidity => new Astral.Quester.Classes.Action.ActionValidity();

        public override void GatherInfos()
        {
            Task = Astral.Professions.Forms.TasksEditor.Show();
        }

        public override void InternalReset()
        {
        }

        public override void OnMapDraw(GraphicsNW graph)
        {
        }

        public override ActionResult Run()
        {
            foreach (var Assignment in Astral.Logic.NW.Professions2.CurrentOrders)
            {
                if (Assignment.Def.InternalName == Task.InternalName) {
                    MyNW.Internals.GameCommands.Execute("Itemassignmentscompletenowbyid " + Assignment.ID);
                }
            }

            return Astral.Quester.Classes.Action.ActionResult.Completed;
        }
    }
}
I also tried changing UITypeEditor to DevExpress.XtraEditors.XtraForm, but no luck. Have to say I don't quite understand yet what "Base" is supposed to be in the EditorAttribute class. But tried different things and nothing worked...
Post Reply