Jump to content

Mutually exclusive KSPActions?


Recommended Posts

I'm trying to create several KSPActions for my current plugin, to give end-users a lot of flexibility when assigning groups, like so:

sQYocj3.jpg

Internally there are just two booleans, one for if the part is "enabled" and the other is the same, except for the gimbals. It looks like this:

[KSPAction("Toggle")]
public void actTg(KSPActionParam kap) {
isActive = !isActive;
}

[KSPAction("Enable")]
public void actEn(KSPActionParam kap) {
isActive = true;
}

[KSPAction("Disable")]
public void actDs(KSPActionParam kap) {
isActive = false;
}

[KSPAction("Toggle Gimbals")]
public void actTgGm(KSPActionParam kap) {
isVectored = !isVectored;
}

[KSPAction("Enable Gimbals")]
public void actEnGm(KSPActionParam kap) {
isVectored = true;
}

[KSPAction("Disable Gimbals")]
public void actDsGm(KSPActionParam kap) {
isVectored = false;
}

The problem is, you can assign multiple actions to the same group, so you can get nonsensical action groups (e.g. a group that both "Enables" and "Disables" the part). What I want is to make "Toggle", "Enable", and "Disable" mutually exclusive within any given action group (make the other options disappear for that action group once one of them is selected), and then the same for the equivalent "Gimbal" triplet. This would make things a little more idiot-proof/misclick-proof. Anyone know a good way of doing this?

Edited by Orum
clarification
Link to comment
Share on other sites

I'm currently working with action groups myself to add more groups into the game.

However I have not come across anything that would do what you are looking for.

If it is absolutely necessary, you could check it in code.

Pseudo-code:

in ActionGroup
if both Extend and Retract present
remove Retract from ActionGroup

But that does nothing to stop the player from adding both Actions to the same action group, it just removes the Retract action as soon as it is added.

D.

Link to comment
Share on other sites

AS Diazo said you could simply do something like that:

        private void Update()
{
BaseAction toggle = Actions["actTg"], enable = Actions["actEn"], disable = Actions["actDs"];
BaseAction gimbalsToggle = Actions["actTgGm"], gimbalsEnable = Actions["actEnGm"], gimbalsDisable = Actions["actDsGm"];

if (toggle.actionGroup != KSPActionGroup.None)
{
if (enable.actionGroup == toggle.actionGroup) { enable.actionGroup = KSPActionGroup.None; }
if (disable.actionGroup == toggle.actionGroup) { disable.actionGroup = KSPActionGroup.None; }
}

if (enable.actionGroup != KSPActionGroup.None)
{
if (disable.actionGroup == enable.actionGroup) { disable.actionGroup = KSPActionGroup.None; }
}

//same with gimbal
}

Link to comment
Share on other sites

Well, I've been working on this for a bit now, and I've simplified/corrected some things, but I still have an issue. Here's what I have now:

		public void Update() {
BaseAction toggle = Actions["actTg"], enable = Actions["actEn"], disable = Actions["actDs"];
BaseAction gToggle = Actions["actTgGm"], gEnable = Actions["actEnGm"], gDisable = Actions["actDsGm"];

enable.actionGroup &= ~toggle.actionGroup;
disable.actionGroup &= ~toggle.actionGroup;
disable.actionGroup &= ~enable.actionGroup;

gEnable.actionGroup &= ~gToggle.actionGroup;
gDisable.actionGroup &= ~gToggle.actionGroup;
gDisable.actionGroup &= ~gEnable.actionGroup;
}

As the actionGroups are bit fields, it makes more sense to treat them as masks. There a still a few issues though, as "Enable" takes precedence over "Disable", and "Toggle" trumps both of them (I'd rather just take the most recent item the user chose). Also, the GUI 'lags' behind the actual settings, e.g. if I pick "Toggle" and then "Enable", both will show up in the current action group, unless I force the GUI to refresh by clicking on another action group and then clicking back on the one I was just at.

Ideally I'd love to not even show the other two options once one of them is picked, but I don't see a way to do that. Let me know if you guy have any other ideas. Thanks.

Edit: I think I can get the most recent to take precedence easily enough (by saving the previous state and comparing the current one to that), but ideally I wouldn't have to, assuming I could hide the other choices.

Edited by Orum
Link to comment
Share on other sites

Yeah, I can get it to use the "new" setting over the "old" one, but I can't figure out how to force the GUI to reflect my internal changes to the variables. So, I think I'm going to abandon it (as the state it's in right now is, in some respects, worse than having nothing) unless I can figure out how to force a refresh.

Edit: Ah, I see, if I just disable the actions I can get what I ultimately wanted. Thanks!

Edited by Orum
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...