Jump to content

Custom editor toolbar category not working


Recommended Posts

The plugin doesn't even load unless I comment out the following line but obviously this is needed to add the category.

PartCategorizer.AddCustomSubcategoryFilter(filter, CUSTOM_CATEGORY_NAME, icon, p => availableParts.Contains(p));

Here is the full code and a screenshot showing the plugin is not loading in

using System.Collections.Generic;
using UnityEngine;
using KSP.UI;
using KSP.UI.Screens;
using Icon = RUI.Icons.Selectable.Icon;


namespace KerBalloons
{
    [KSPAddon(KSPAddon.Startup.MainMenu, true)]
    class KerBalloonsCatagory : MonoBehaviour
    {
        private static readonly List<AvailablePart> availableParts = new List<AvailablePart>();

        private void Awake()
        {

            availableParts.Clear();
            foreach (var part in PartLoader.LoadedPartsList)
            {
                if (!part.partPrefab) continue;
                if (part.manufacturer == "KerBalloons")
                {
                    availableParts.Add(part);
                }
            }

            GameEvents.onGUIEditorToolbarReady.Add(SubCategories);
          
        }

        
        private void SubCategories()
        { 
            Debug.Log("Adding KerBalloons Catagory");
            const string FILTER_CATEGORY = "Filter by Function";
            const string CUSTOM_CATEGORY_NAME = "KerBalloons";

            

            Texture2D iconTex = GameDatabase.Instance.GetTexture("GameData/Squad/PartList/SimpleIcons/cs_main", false);

            Icon icon = new Icon("KerBalloons", iconTex, iconTex, false);

            PartCategorizer.Category filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == FILTER_CATEGORY);
            PartCategorizer.AddCustomSubcategoryFilter(filter, CUSTOM_CATEGORY_NAME, icon, p => availableParts.Contains(p));

            UIRadioButton button = filter.button.activeButton;
        }
    }
}

rIt6J3r.png  

Edited by JoePatrick1
Link to comment
Share on other sites

1 hour ago, stupid_chris said:

Are you compiling for .NET 3.5? KSP can't mess with lambda expressions if you dont.

Using 4.5.2 - surely that should work?

I'll try 3.5

edit: ok that actually worked. Thanks a lot :)

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