Adding Main Tabs

Started by Ady, August 31, 2016, 04:35:06 PM

Previous topic - Next topic

Ady

Evening folks,
My eyes hurt from looking at this all day so I thought I'd better ask.

I thought I'd have a go at adding a new tab to the menu bar, like the extra Help tab in the CCL.  I copied and renamed the MainTab_HelpMenuDef and MainTabWindow_ModHelp classes and put them in their own namespace, though the Window class is basically empty.  I copied the MainTabs.xml and edited it to include my changes and put the namespace in along with the class names.  The project builds without incident, the mod appears in the menu and is activated (listed below CCL of course ;) ) and the debug log says it loaded the mod and there are no errors, but no shiny new tab appears.

I have some basic familiarity with writing small, amateurish programs, but it has been a long time since I last did it and I never really got into any object oriented languages so I may be making unwarranted assumptions or just screwing up basic things.  I can follow basic C# but jumping between the CCL source, the decompiled assemblies, core XML and my own stuff and trying to trace the problem when I don't even know that it could work is probably too much for someone with my level of experience, but I'd like to understand.

Please be gentle with me.   :-*  8)

Oh, and please excuse the coarse language, I wasn't expecting anyone else to see it.

<?xml version="1.0" encoding="utf-8" ?>
<MainTabDefs>
    <MainTabDef Class="AdyMenuFuckabout.MainTab_AMFADef">
        <defName>AMFADef</defName>
        <label>kabout</label>
        <description>kin about... with menus</description>
        <windowClass>AdyMenuFuckabout.MainTabWindow_AMFA</windowClass>
        <order>7</order>
<windowSize>(700,500)</windowSize>
        <listWidth>200</listWidth>
        <pauseGame>false</pauseGame>
    </MainTabDef>
</MainTabDefs>


using RimWorld;
using UnityEngine;


namespace AdyMenuFuckabout
{
    public class MainTab_AMFADef : MainTabDef
    {
        public Vector2 windowSize = new Vector2(200f, 600f);
        public float listWidth = 200f;
        public bool pauseGame = false;
       
    }
}


using RimWorld;
using UnityEngine;
using Verse;

namespace AdyMenuFuckabout
{
    public class MainTabWindow_AMFA : MainTabWindow {
        public override Vector2 RequestedTabSize {
            get {
                return new Vector2(100f, 600f);
            }
        }

        public override MainTabWindowAnchor Anchor {
            get {
                return MainTabWindowAnchor.Right;
            }
        }

        private MainTab_AMFADef TabDef {
            get {
                return def as MainTab_AMFADef;
            }
        }

        public MainTabWindow_AMFA() {
            layer = WindowLayer.GameUI;
            closeOnEscapeKey = true;
            forcePause = true;
        }

        //public override void PreOpen()
        //{
        //    base.PreOpen();
        //}

        //public override void ExtraOnGUI()
        //{
        //    base.ExtraOnGUI();
        //}

        //public override void DoWindowContents(Rect rect)
        //{
        //    base.DoWindowContents(rect);
        //}
    }
}

1000101

You don't need to define a new class like CCL does.  We do it because we set default values in xml so people can override them if they want to.

Look at the core MainTabs and how they work, they are a much better example then CCLs as we are doing some magic under the hood with regards to our default values.

As to your window being empty...It will be until you write your DoWindowContents method to draw stuff. :P
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

Ady

You have to be kidding. 

Usually in these situations it's a case of finding something that does what you want and copying it... CCL was the only thing I'd come across that implements new tabs so I just assumed it wasn't possible to add one through Core XML   :o
QuoteAs to your window being empty...It will be until you write your DoWindowContents method to draw stuff.
Yeah that's kinda what I meant, I left it empty until I knew I could get the tab working.

QuoteYou don't need to define a new class like CCL does.  We do it because we set default values in xml so people can override them if they want to.
Just out of curiosity, do you know why it didn't work when I copied what CCL did?

Anyway, thanks a lot for the help, I just tried messing around with MainTabs and it worked straight away.  If you're thinking about doing some documentation and you need some (relatively unskilled) help, I'd be happy to pitch in.  It feels like some of this stuff could be easier to find.

Ady

OK, I thought I had it but I realised that the first time I edited MainTabs.xml in Core, which is no good right?  The small test I did worked fine in Core, but if I move it out to a separate mod it won't work, the game seems to ignore whatever I do.

Lockdown

Have you forgotten to activate your new mod, perhaps?  :P

I just tried defining a new tab in one of my mods like this, and it showed up:

<?xml version="1.0" encoding="utf-8" ?>
<MainTabDefs>

  <MainTabDef>
    <defName>ResearchDUPLICATE</defName>
    <label>test research tab</label>
    <description>Examine and decide on research projects.</description>
    <windowClass>MainTabWindow_Research</windowClass>
    <order>100</order>
  </MainTabDef>

</MainTabDefs>

Ady

#5
QuoteHave you forgotten to activate your new mod, perhaps?

It was something pretty stupid in the end.  I managed to spell "Defs" incorrectly in the folder structure, so they weren't being loaded.