Jump to content

I cannot figure out how to use the application launcher


Superfluous J

Recommended Posts

Can someone explain to me - in simple term with examples - exactly how to get a button on the toolbar that I can click and "do something"?

For a concrete example, I'm trying to code a very simple first-step version of a mod that, when you click a button in the toolbar in map mode, it drops a maneuver node 5 minutes into the future. I've got the "drop a maneuver node 5 minutes into the future" function written, but I'm running out of hair to pull out trying to even get a button to show up on the application launcher.

Please assume I am a complete moron when answering my questions. Do not assume though that I don't know how to search. Don't point me at a web page with the API. It confuses me. Don't tell me to look at other people's source code. I have. I've even copied it and pasted it into my mod. I can't get it to work. I will accept that I'm too dumb to figure it out myself but I will not accept that I haven't tried hard enough.

Link to comment
Share on other sites

Maybe the code I have would help (did I mention I'm dumb?). Here's the entire cs file. It's not that big and hopefully I'm just missing something simple. It complies fine, and I'm not seeing anything in the output_log.txt implying an error, but I don't know exactly where to look. If it matters, I'm trying to do this in 1.2

using KSP.UI.Screens; // Unsure if needed
using System;
using System.Collections; // Unsure if needed
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace DropAManeuverNode
{
	public class DAMN_Basic : MonoBehaviour
    {
        ApplicationLauncherButton ToolbarButton;
        public void Start()
        {
            GameEvents.onGUIApplicationLauncherReady.Add(OnGUIApplicationLauncherReady);
        }

        public void DropAManeuverNode_5Min()
        {
            FlightGlobals.ActiveVessel.patchedConicSolver.AddManeuverNode(Planetarium.GetUniversalTime() + (5.0 * 60.0));
        }

        private void OnGUIApplicationLauncherReady()
        {
            if (ToolbarButton == null)
            {
                ToolbarButton = ApplicationLauncher.Instance.AddModApplication(DropAManeuverNode_5Min, null, null, null, null, null, ApplicationLauncher.AppScenes.MAPVIEW, GameDatabase.Instance.GetTexture("DropAManeuverNode/Toolbar", false));
            }
        }
    }
}

 

Link to comment
Share on other sites

Try adding

    [KSPAddon(KSPAddon.Startup.Flight, false)]

before your class declaration... at the moment your Addon is never being started, because your not telling KSP to.

Also: don't know if this is a hard and fast rule, but I usually find event listeners work better in Awake() not Start().

Edited by severedsolo
Link to comment
Share on other sites

17 minutes ago, severedsolo said:

Try adding

    [KSPAddon(KSPAddon.Startup.Flight, false)]

before your class declaration... at the moment your Addon is never being started, because your not telling KSP to.

That worked! Thank you. So I actually had the toolbar stuff correct. Who'd'a'thunk't

17 minutes ago, severedsolo said:

Also: don't know if this is a hard and fast rule, but I usually find event listeners work better in Awake() not Start().

It doesn't seem to matter which one it's in, they both work. So I'll leave it in Awake() for now.

The "Like" button on the forum isn't enough to express my thanks.

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