Jump to content

[SOLVED] Remove Module AnimateGeneric Buttons


Recommended Posts

Ok, so goofing off with a plugin and AnimateGeneric.  It appears my plugin won't run the animation unless it's defined in the part as AnimateGeneric.  So, here's the question.  Is there any way to turn off that 'toggle' button you get when you right click on a part?  I want the plugin to handle all of the animations and not the user.

Thanks

Edited by Fengist
Link to comment
Share on other sites

Some config fields are available in the stock ModuleAnimateGeneric; have never tried them myself (I use a custom animation handler in my plugin code), so not precisely sure what they all do:

 

	[KSPField]
	public bool actionAvailable = true;

	[KSPField]
	public bool eventAvailableEditor = true;

	[KSPField]
	public bool eventAvailableFlight = true;

	[KSPField]
	public bool eventAvailableEVA = true;

 

It seems that those are likely intended for much what you are looking for -- disabling the right-click menu to let an external module handle the state changes.

Action generally refers to action group (so actionAvailable determines if the action group should be enabled).  Event generally refers to the right-click menu (so the eventAvailableXXX determines when the right-click button is present).

Link to comment
Share on other sites

Have you tried manually disabling the ModuleAnimateGenerics 'status' field through your custom plugin?

Basically doing:

moduleAnimateGeneric.Fields["status"].guiActive = false;
moduleAnimateGeneric.Fields["status"].guiActiveEditor = false;

for each of your controlled animation modules.  The best place to do this would probably be during the Unity Start() lifetime event/method.

I've certainly done similar for other stock modules while interfacing/interacting with my custom plugins; have not tried it on the stock MAG because I avoid where possible, but there is a chance it will work with that one as well.

Link to comment
Share on other sites

@Shadowmage

Thanks Shadow! Worked like a charm.  Plopped it in the OnStart where I force all the animations to rewind and... no more annoying GUI, in SPH or flight.

And for anyone else who finds this and needs the solution for disabling the gui for multiple animations on one part (and for when I lose this chunk of code and forget how it's done), solution below.

                List<ModuleAnimateGeneric> MAGlist = part.FindModulesImplementing<ModuleAnimateGeneric>();
                foreach (ModuleAnimateGeneric MAG in MAGlist)
                {
                    MAG.Fields["status"].guiActive = false;
                    MAG.Fields["status"].guiActiveEditor = false;
                }

One thing I didn't expect to have happen after running this code tho...  I still had to set all the flag in the .cfg.  If they're not set, it still shows them.  I guess I could have just set them in the plugin, but this works.  The user can remove them if they wanna play with the lights I guess.

Thanks again.

     MODULE
     {
		name = ModuleAnimateGeneric
		animationName = Batt Red Anim
		eventAvailableEditor=false
		eventAvailableFlight=false
		eventAvailableEVA=false
		allowManualControl=false
     }

 

Edited by Fengist
Link to comment
Share on other sites

@Fengist Do you mind if I piggy back your topic, with a sort of connected question? (If so, LMK & I'll delete my post)

I want to combine a ModuleAnimateGeneric, with a ModuleGenerator... Or I should say, I want to activate the Generator, behind the scenes, triggered by the toggling of the AnimateGeneric... Any idea how I would do that?

Heres the "Lights" module:

 

MODULE
{
	name = ModuleAnimateGeneric
	animationName = lights
	actionGUIName = Toggle Lights
	startEventGUIName =  Lights On
	endEventGUIName = Lights Off
	instantAnimInEditor = false 
}

And heres the "Power ON" module, I would like to trigger with the above "Toggle Lights" animation:

 

MODULE
{
	name = ModuleGenerator
	activateGUIName	= "Power suply ON"
	shutdownGUIName = "Power suply OFF"
	INPUT_RESOURCE
     {
     	name = ElectricCharge
		rate = 0.02
     }
	OUTPUT_RESOURCE
	{
	   name = GLight
	   rate = 0.1
	}	 		  
}

 

Link to comment
Share on other sites

@Stone Blue

No, I don't mind at all, but I'm not sure you'll get a decent answer.

I can tell you how I'd do it but you're going to need to write some C# code.

I basically did just this with the Idiot Lights I just released, the only difference is, instead of waiting for a generator to turn on or off, it checks the levels of fuels.  You'll basically need to check the status of the ModuleGenerator to see if it's turned off or on.  Off the top of my head I'm not positive how that's done. I'd have to dig to figure that out.  If that proves too difficult, you could check the part that contains the resource GLight and see if it's increasing, or decreasing.  Once you figure out if GLight is being made you can play an animation like this:

public void Play_Anim(string aname, float aspeed, float atime)
            {
                try
                {
                    Animation anim;
                    Animation[] animators = part.FindModelAnimators(aname);
                    if (animators.Length > 0)
                    {
                        anim = animators[0];
                        anim.clip = anim.GetClip(animationName);
                        anim[aname].speed = aspeed;
                        anim[aname].normalizedTime = atime;
                        anim.Play(aname);
                    }
                }
                catch (Exception ex)
                {
                    MPLog.Writelog("[Idiot Lights] Exception in Play_Anim");
                    MPLog.Writelog("[Idiot Lights]  Err: " + ex);
                }
            }

When you call that function you pass it 3 paramaters

  1. The name of the animation. In your case lights.
  2. The direction you want it to play.  This is a simple positive 1 for forward and negative 1 for reverse.
  3. The speed in seconds.

So it would look like this:

Play_Anim("lights", 1.0f, 1.0f);

So, when it turns on, you call it like above to turn the light on.  When it turns off, you play the animation in reverse:

Play_Anim("lights", -1.0f, 1.0f);

Wax on, wax off.

Hope that helps.

 

 

Ummm ooops... I just read you wanna do it backwards!....

You wanna have the user turn the lights on and then fire up the generator.

Well, that's a bit different but you'll still need some C# coding to do that.  I don't think there's any way to do it in just a .cfg file.  You're best be will probably be to create your own partmodule and put that in the .cfg file with the animation.

That way, you can check the status of the lights animation to determine if it's on or off and then, finding the part with the resource GLight, getting the id for that resource and then...

 

part.TransferResource(GetResourceID(mypart,"GLight"), amount);

public static int GetResourceID(this Part part, string resourceName)
        {
            PartResourceDefinition resource = PartResourceLibrary.Instance.GetDefinition(resourceName);
            return resource.id;
        }

But, this gets even messier because you'll need to keep track of how much resource you have & the max amount you can have.

PM me if you need help figuring it out.

Edited by Fengist
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...