Need help with furniture ownership and buttons

Started by Friedmutant, February 03, 2015, 02:10:04 AM

Previous topic - Next topic

Friedmutant

Hello everyone!  This is my first post in these forums.  I'm working on a mod that adds a new piece of furniture that needs to be owned by a colonist.  I've copied most of the code from Building_Bed(), but there are some parts that don't work, like buttons and ownership.

I want to attempt 'automatic' ownership at spawn time, so I have this for SpawnSetup(), but
RoomQuery.RoomAt () always gives me null even though the building is spawned in a room with an owned bed.

                public override void SpawnSetup ()
{
base.SpawnSetup ();
Room room = RoomQuery.RoomAt (base.Position);
if (room != null) {
Pawn owner = room.RoomOwner;
if (owner != null) {
this.owner = owner;
}
}
}


I also want to have UI buttons where the player can override ownership, like with 'Set Owner' on beds.  However, Building_Bed.GetCommands() is obfuscated or otherwise doesn't decompile for me.  So I tried the very helpful tutorial code, but it is either out-of-date or using references that I can't find, like UI_DoorLocked and txtLocksUnlocksDoor.


        public override IEnumerable<Command> GetCommands()
        {
            IList<Command> list = new List<Command>();

            // Key-Binding F -
            Command_Action optF;
            optF = new Command_Action();
            optF.icon = UI_DoorLocked;
            optF.defaultDesc = txtLocksUnlocksDoor.Translate();
            optF.hotKey = KeyCode.F;
            optF.activateSound = SoundDef.Named("Click");
            optF.action = DoWorkFunction;
            optF.groupKey = 1234567; // unique number, for grouping in game
            // yield return optF;
            list.Add(optF);

            // Adding the base.GetCommands() when not empty
            IEnumerable<Command> baseList = base.GetCommands();
            if (baseList != null)
                return list.AsEnumerable<Command>().Concat(baseList);
            else
                return list.AsEnumerable<Command>();
        }


Thank you for reading!

-Friedmutant

Rikiki

Hi!

To get the room of a building, you must use the function GetRoomOrAdjacent:
Room bedRoom = this.Position.GetRoomOrAdjacent();

For the command button, look into the M&Co. AlertSpeaker mod or mrofa climatization in Clutter mod.

Haplo

That Looks like the code from my Lockable Doors in Miscellaneous. But from the Alpha 7 Version..
Did you download the newest source code from Miscellaneous?

the txtSomething is a variable holding the translation key. Just make your own or replace it with your own key/text like this
optF.defaultDesc = "key_from_Language_Folder".Translate();
optF.defaultDesc = "This is a not translated text";

UI_DoorLocked is the graphic used to be displayed on the button. This must be set in the SpawnSetup() function.

And you need to change this, because that was alpha 7 code:
optF.hotKey = KeyCode.F;

I'm unsure of the exact Name right now. something like this:
optF.hotKey = KeyBindingDefOf.Misc1;

Friedmutant


Thank you both very much!  I made significant progress this morning with your aid.