AssignOwner UI box?

Started by DrMrEd, October 12, 2017, 08:43:45 AM

Previous topic - Next topic

DrMrEd

Greetings modders. Newb modder here, but worked through a few basic mods and learned a lot, but now I'm stuck.

In my current project, I would like to use the AssignOwner button in the UI for my new object. I've been all through the Bed and Grave source code and Defs, but can't see where this is configured. I feel like I've missed something obvious regarding the UI buttons. Can anyone point me in the right direction?

My custom ThingClass implements IAssignableBuilding, but that doesn't take care of this bit of magic. I actually have all the code to claim/unclaim written and working through a cool bit of C# using Extensions to add new methods to the Pawn_Ownership class. I can test this by manually calling up the Dialog_AssignBuildingOwner from the ctor() in my ThingClass, which is interesting, but useless in-game.

Kiame

#1
The method you're looking for is Building_Bed.getGizmos which is where the buttons at the bottom are created

It's compiled gibberish in ilSpy though. You could consider postfix'ing the method with Harmony and printing each gizmo's attributes to the Log to see how the assign button is built - at least to get the Assign button's image that's used.

To see how to create a gizmo and/or how you use harmony here's an example from one of my mods. Specifically the Main constructor (the first two lines) and class Patch_ZoneStockpile_GetGizmos

https://github.com/KiameV/rimworld-recolorzones/blob/master/Source/Main.cs

DrMrEd

Thank you for the leads!

I'll dig into GetGizmos() later today when I get back to this project. It's probably the same gibberish we see everywhere with compiler generated types, which I've avoided really trying to understand thus far. But knowing the Command Buttons are "Gizmos" will help a lot.

I also have yet to dig into Harmony. I though I'd need it for my Pawn_Ownership hack, but the extensions stuff is actually really powerful.

Learn as you go ;)

Kiame

Just to make sure i'm being clear... you won't have to use harmony to add the gizmo as your Building_ class you can just override the getgizmo. Harmony more for being able to tell which icon to use if you want to use the same gizmo as the bed's Assign  :)

DrMrEd

Gotcha, thanks. Anxious to look into this, but running out of time today already to play around with this.

DrMrEd

Finally getting back to this, and I have some working code. I've got this for the GetGizmos() method:


        public override IEnumerable<Gizmo> GetGizmos()
        {
            foreach (Gizmo baseGizmo in base.GetGizmos())
            {
                yield return baseGizmo;
            }
            yield return new Command_Action
            {
                defaultLabel = "CommandBedSetOwnerLabel".Translate(),
                icon = ContentFinder<UnityEngine.Texture2D>.Get("UI/Commands/AssignOwner", true),
                defaultDesc = "CommandBedSetOwnerDesc".Translate(),
                action = delegate
                {
                    Find.WindowStack.Add(new Dialog_AssignBuildingOwner(this));
                },
                hotKey = KeyBindingDefOf.Misc3
            };
        }


And it's working in so far as the SetOwner command box now appears. However, I've still got some code issues in that multiple owners can be assigned (so I'm not checking ownership properly somewhere). The bigger issue is that even though this is "owned" by a named Pawn, any other Pawn in game still uses it.

Thanks to the help above from Kiame, I've passed one hurdle just to find two more :) Hopefully this code will help others in the future.

If/when I figure the rest out, I'll be sure to post it. However, the ownership here is a small incremental feature of the mod I'm working on, so if it gets to be too much, I may just drop this bit after all.