Adding new Architect tabs [solved]

Started by jamieg, April 25, 2014, 06:51:43 PM

Previous topic - Next topic

jamieg

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.
YES! Its true! im updating The BIG BANG mod pack check it out here: https://www.youtube.com/watch?v=orzLZbECR20&list=UUr1sEPUEhFqy01q16zGisIg

WorldOfIllusion

I am looking forward to this so much.

Come on June!
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

Cala13er

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.

Architect

Callum's right, if it isn't in the changelog here, I'm pretty sure it is meant to be private knowledge.
Check out BetterPower+ and all its derivatives by clicking the picture below.

It adds many new methods of power generation and uses for it, as well as other things such as incidents.


jamieg

#4
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 ;)
YES! Its true! im updating The BIG BANG mod pack check it out here: https://www.youtube.com/watch?v=orzLZbECR20&list=UUr1sEPUEhFqy01q16zGisIg

Tynan

It's okay, I asked him to share the info. Maybe inadvisably since this isn't in A3... :P
Tynan Sylvester - @TynanSylvester - Tynan's Blog

WorldOfIllusion

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).
Artistically challenged modder seeking artistically talented texturer's help. Please, please, PM me :)

Cala13er

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.

Vendan

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]

Architect

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.


Check out BetterPower+ and all its derivatives by clicking the picture below.

It adds many new methods of power generation and uses for it, as well as other things such as incidents.


pawnstorm

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());
        }
    }