Jump to content

not obvious code in an old mods


Recommended Posts

this code originally was in the KCT, I updated it, and now it is almost work with VesselSpawnDialog (LaunchPad/Runway GUI)

https://github.com/.../KVASS.cs#L158

"Almost" because of one thing - the launchsites radiobuttons.
It works when I launch using little launch button (per launchsite), the code is the same, the launchsitename is gotten from the GUI, 
it works when I launch with GreenLaunchButton to the default LaunchPad/Runway,
but if I change a launchsite using a radiobutton, and then use the GreenLaunchButton, I can't get sitename,
because KCT use launchSite = EditorLogic.fetch.launchSiteName which will not work for the KSC scene (VesselSpawnDialog).

  • A small question is how to solve that problem?
    (get selected radiobutton's launchsitename or at least completely disable radiobuttons and leave only GreenLaunchButton and smallLaunchButtons ),
  • and a large question is how this code was born in the first place?
    I found in the KSP API UILaunchsiteController but it hasn't any mentions of launchPadItems and other objects used there.
    Most likely I can at least disable radiobuttons in the same way as littlelaunchbutton was got there:
    site.GetType().GetPublicValue<UnityEngine.UI.Button>("buttonLaunch", site);
    but where I need to find the PublicValue for that, if not in the KSP API?

 

if (settingsGame.AllowOtherLaunchSites)
{
    UILaunchsiteController controller = UnityEngine.Object.FindObjectOfType<UILaunchsiteController>();
    if (controller == null) return;

    object items = controller.GetType()?.GetPrivateMemberValue("launchPadItems", controller, 4);
    if (items == null) return;

    IEnumerable list = items as IEnumerable;

    foreach (object site in list)
    {
        UnityEngine.UI.Button button = site.GetType().GetPublicValue<UnityEngine.UI.Button>("buttonLaunch", site);
        if (button != null)
        {
            button.onClick.RemoveAllListeners();
            string siteName = site.GetType().GetPublicValue<string>("siteName", site);
            button.onClick.AddListener(() => { LaunchClickListenerBoth(vesselSpawnInfo, siteName); });
        }
    }
}

 

 

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