Ludeon Forums

RimWorld => Mods => Help => Topic started by: jamieg on April 25, 2014, 06:51:43 PM

Title: Adding new Architect tabs [solved]
Post by: jamieg on April 25, 2014, 06:51:43 PM
I asked Ty for some help today in how to add new tabs to the architect menu as i couldnt find the answer and he helped me out so here it is incase anyone else as wondering

-It's easy in A4, impossible in A3. If you're modding towards A4 just use the test version and add a DesignationCategoryDef.
Title: Re: Adding new Architect tabs
Post by: WorldOfIllusion on April 25, 2014, 08:24:18 PM
I am looking forward to this so much.

Come on June!
Title: Re: Adding new Architect tabs
Post by: Cala13er on April 26, 2014, 04:40:48 AM
Quote from: jamieg on April 25, 2014, 06:51:43 PM
I asked Ty for some help today in how to add new tabs to the architect menu as i couldnt find the answer and he helped me out so here it is incase anyone else as wondering

-It's easy in A4, impossible in A3. If you're modding towards A4 just use the test version and add a DesignationCategoryDef.

I'll say this again, I've read a while ago in the tester forum that we should not be leaking information about test releases or upcoming alpha's.  Probably best you remove this jamie.
Title: Re: Adding new Architect tabs
Post by: Architect on April 26, 2014, 06:39:27 AM
Callum's right, if it isn't in the changelog here (https://docs.google.com/document/d/1_rCdGYp3nbSUXFG4Ky96RZW1cJGt9g_6ANZZPOHyNsg/pub), I'm pretty sure it is meant to be private knowledge.
Title: Re: Adding new Architect tabs
Post by: jamieg on April 26, 2014, 07:01:23 AM
The part of the reply from Ty that i didnt show was him asking me to put this in the public mod help forum incase anyone else wondered...... so im sure it fine ;)
Title: Re: Adding new Architect tabs
Post by: Tynan on April 26, 2014, 10:51:57 AM
It's okay, I asked him to share the info. Maybe inadvisably since this isn't in A3... :P
Title: Re: Adding new Architect tabs
Post by: WorldOfIllusion on April 26, 2014, 11:27:33 AM
drumming up the anticipation for us non-tester modders (and for all the mod users who don't want their screens to be entirely filled up I guess).
Title: Re: Adding new Architect tabs
Post by: Cala13er on April 26, 2014, 11:29:19 AM
Quote from: Tynan on April 26, 2014, 10:51:57 AM
It's okay, I asked him to share the info. Maybe inadvisably since this isn't in A3... :P

Fair play :). I withdraw my case :P.
Title: Re: Adding new Architect tabs
Post by: Vendan on April 28, 2014, 12:06:43 PM
Quote from: jamieg on April 25, 2014, 06:51:43 PM
I asked Ty for some help today in how to add new tabs to the architect menu as i couldnt find the answer and he helped me out so here it is incase anyone else as wondering

-It's easy in A4, impossible in A3. If you're modding towards A4 just use the test version and add a DesignationCategoryDef.

THE IMPOSSIBLE IS NEVER IMPOSSIBLE

though it is a severe kludge, and adding categories through xml is probably like 5000% easier.


[attachment deleted by admin: too old]
Title: Re: Adding new Architect tabs
Post by: Architect on April 28, 2014, 01:18:13 PM
Quote from: Vendan on April 28, 2014, 12:06:43 PM
Quote from: jamieg on April 25, 2014, 06:51:43 PM
I asked Ty for some help today in how to add new tabs to the architect menu as i couldnt find the answer and he helped me out so here it is incase anyone else as wondering

-It's easy in A4, impossible in A3. If you're modding towards A4 just use the test version and add a DesignationCategoryDef.

THE IMPOSSIBLE IS NEVER IMPOSSIBLE

though it is a severe kludge, and adding categories through xml is probably like 5000% easier.


(http://www.thefilmleague.com/wp-content/uploads/2011/09/the_matrix-11347.jpeg)
Title: Re: Adding new Architect tabs [solved]
Post by: pawnstorm on May 23, 2014, 06:46:18 AM
In case somebody finds it useful, I thought I'd share some code here. Aside from extending the TabArchitect class and replacing Find.MainTabsRoot.tabArchitect with it in the incidentmakerclasses like I did in Architect+ (Architect+ comes with source btw, unlike Vanilla+), I found another easy way to add stuff to the interface. It's the same method that's also used in Joretap0's awesome Inventory Panel mod.

This is achieved by adding a custom Layer extended class to the layerstack, adding it is simple: Find.Layers.Add(YourLayer). You can draw any GUI stuff you want in a layer, buttons, icons, dialogs, labels...

The problem is finding some way to trigger adding the layer at the right time. The solution I came up with is adding a dummy sound to get an early trigger through the constructor of the custom sound class (which is always triggered after mods are loaded), and then creating a custom mapgenner for when a new game is started and a custom postloadinitter for when a game is loaded. I've also added a destructor that ensures a new instance is added to the mapgenners/postloadinitters if needed when it is removed. Hacky method, but it works :P.

First you need to create a dummy sound def in Defs\SoundDefs. Use a different def name to avoid compatibility issues:

<?xml version="1.0" encoding="utf-8"?>
<SoundDefPackage>
<SoundDef>
<defName>SubSoundDummy</defName>
<subSounds>
<li Class="YourMod.SubSoundDummy, YourMod">
</li>
</subSounds>
</SoundDef>
</SoundDefPackage>


And these are the classes you need to trigger adding your Layer at the appropriate time:

    public class SubSoundDummy : SubSoundDef
    {
        public SubSoundDummy()
        {
            if (!Genner_YourMod.active)
            {
                Genner_YourMod genner = new Genner_YourMod();
                foreach (MapGeneratorDef def in DefDatabase<MapGeneratorDef>.AllDefs)
                    def.genners.Add(genner);
            }
            if (!Initter_YourMod.active)
            {
                Initter_YourMod init = new Initter_YourMod();
                PostLoadInitter.RegisterForPostLoadInit(init);
            }
        }
    }


    public class Genner_YourMod : Genner
    {
        public static bool active = false;

        public Genner_YourMod()
        {
            active = true;
        }

        ~Genner_YourMod()
        {
            if (!PlayDataMaster.loaded && ModsConfig.IsActive("YourMod"))
            {
                Genner_YourMod genner = new Genner_YourMod();
                foreach (MapGeneratorDef def in DefDatabase<MapGeneratorDef>.AllDefs)
                    def.genners.Add(genner);
            }
            else
            {
                active = false;
            }
        }

        public override void Generate()
        {
            if (ModsConfig.IsActive("YourMod"))
                Find.Layers.Add(new YourLayer());
        }   
    }


    public class Initter_YourMod : Saveable
    {
        public static bool active = false;

        public Initter_YourMod()
        {
            active = true;
        }
       
        ~Initter_YourMod()
        {
            if (Scribe.mode == LoadSaveMode.PostLoadInit && ModsConfig.IsActive("YourMod"))
            {
                Initter_YourMod init = new Initter_YourMod();
                PostLoadInitter.RegisterForPostLoadInit(init);
            }
            else
            {
                active = false;
            }
        }

        public void ExposeData()
        {
            if (ModsConfig.IsActive("YourMod"))
                Find.Layers.Add(new YourLayer());
        }
    }