[1.5] HugsLib (11.0.3) Lightweight modding library

Started by UnlimitedHugs, December 15, 2016, 02:20:14 PM

Previous topic - Next topic

Wishmaster

#165
So I managed to deal with that null default value


// one mask = one setting

  mask.settingHandle = Settings.GetHandle<PolicySetting>(settingId, settingLabel, settingDesc, null);

mask.settingHandle.CustomDrawer = PolicySetting.GetCustomDrawer(mask);


(almost) Everything seem to work know, including settings save!
However to assign a value to  settingHandle.Value I had to create an implicit conversion that looks somehow wrong to my eyes.
Am I supposed to create a new instance of PolicySetting every time I change a setting ?


  public static implicit operator PolicySetting(Policy obj)
{
    return new PolicySetting() { ActivePolicy = obj };
}


UnlimitedHugs

Quote from: Wishmaster on March 06, 2017, 03:31:39 PM
(almost) Everything seem to work know, including settings save!
However to assign a value to  settingHandle.Value I had to create an implicit conversion that looks somehow wrong to my eyes.
Am I supposed to create a new instance of PolicySetting every time I change a setting ?

Glad to hear it!
You don't need to assign a new object on each change- just when Value is null. After that, changing the fields of the existing object should allow the setting to be saved just fine.
Hard to tell without seeing the rest of it, but that conversion looks alright. Whatever works for you.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

Hello, it's me again.

I want to modify the Needs pawn inspect tab. Am I doing it right without using Hugs GUI injection, knowing that it does not inherits from Window ? (ITab_Pawn_Needs)

Also I wanted to create a Keybinding to toggle on/off a vanilla development option.
That would be really great if HugsLib provide a method to override in ModBase like OnUiUpdate() !
So far, RawCode suggested I use UnityEngine...

UnlimitedHugs

Quote from: Wishmaster on March 14, 2017, 11:40:09 AM
I want to modify the Needs pawn inspect tab. Am I doing it right without using Hugs GUI injection, knowing that it does not inherits from Window ? (ITab_Pawn_Needs)

Tabs are drawn inside an ImmediateWindow, which can be injected into- the window is drawn during InspectTabBase.DoTabGUI. The trouble is identifying which tab you are drawing into, since all tabs share the same immediate window Id.
I see two options:
1) Creating a new tab that inherits from ITab_Pawn_Needs and replace the original tab during DefsLoaded. This is, arguably, the more compatible option.
2) Detouring ITab_Pawn_Needs.FillTab. In A17 detours will have to be converted to Harmony patches, so you would have good compatibility eventually, as well.

Quote from: Wishmaster on March 14, 2017, 11:40:09 AM
Also I wanted to create a Keybinding to toggle on/off a vanilla development option.
That would be really great if HugsLib provide a method to override in ModBase like OnUiUpdate() !

You can override the OnGUI method in ModBase for this. The wiki has an example on how to listen to a key binding.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

Quote1) Creating a new tab that inherits from ITab_Pawn_Needs and replace the original tab during DefsLoaded. This is, arguably, the more compatible option.

What I've done at first. But it would required to rewrite or copy the entire tree of calls to what I want to change.
But then I tried only to detour a method that is called in the "tree" of ITab_Pawn_Needs( NeedsCardUtility.DoNeeds() ).

Hopefully, no other modder will detour this one !

QuoteYou can override the OnGUI method in ModBase for this. The wiki has an example on how to listen to a key binding.

Didn't see that... trying now.

UnlimitedHugs

As you may know, Alpha 17 is scheduled to be released in the near future.
I am doing some preliminary work on the library to prepare for the update. If you have any compatibility-breaking API changes you would like to suggest, this is a good time.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

Hello again !

I can't something with OnGUI() properly. It keeps blinking, just like I was using the wrong way to draw something (using Tick() for example).
While capturing keys works very fine, this does not.

          public override void OnGUI()
         {
             if (Find.Selector == null)
                 return;
             
             var t = Find.Selector.SingleSelectedThing;
//draws something
             if (t is Plant)
             {
                 var group = ((RimWorld.Plant)t).GroupOf();

                 if (group != null)
                 {
                     GenDraw.DrawFieldEdges(group.plants.Select(arg => arg.Position).ToList(),SimpleColor.Red.ToUnityColor());
                 }
             }
         }

UnlimitedHugs

Quote from: Wishmaster on March 29, 2017, 07:23:31 PM
I can't something with OnGUI() properly. It keeps blinking, just like I was using the wrong way to draw something (using Tick() for example).
While capturing keys works very fine, this does not.

This is due to how Unity's OnGUI works. It's not called on every frame, only when the GUI actually needs redrawing- such as when an input event occurs. I think this is because Rimworld does not use a camera, but all drawing happens directly to screen.
Anyway, if you put your code inside the Update() method instead, the outlines should draw consistently.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

CutiesDeathCab

Hello, I am asking for permission to place your mod into a database I am working on for RimWorld mod Listings. I plan on keeping it updated with the help of some others. The post will contain the following
[Version, Title, Author, Direct Topic Link, Direct Download Link (From the topic)]
Either PM me, Or reply to this message. Thank you. :)
P.S: The Database will have its own topic once I have a decent amount in the database.


UnlimitedHugs

Quote from: CutiesDeathCab on March 29, 2017, 09:41:18 PM
Hello, I am asking for permission to place your mod into a database I am working on for RimWorld mod Listings.

Of course, that's all right with me. Same goes for my other mods, should you choose to include them.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

CutiesDeathCab

Quote from: UnlimitedHugs on March 29, 2017, 10:01:19 PM
Quote from: CutiesDeathCab on March 29, 2017, 09:41:18 PM
Hello, I am asking for permission to place your mod into a database I am working on for RimWorld mod Listings.

Of course, that's all right with me. Same goes for my other mods, should you choose to include them.

Thanks ^_^ I'm still figuring out a good way of sorting them, I'll PM you when I have a better setup ready.

Craftysune

I hope it's okay to post a general question here. But could someone help this noob out & please tell me where I'm supposed to put Libhugs when I've downloaded it.  :-[ I'm dying to use it because it looks amazing. I've tried to find out independently &  I've had no joy. Any help would be greatly appreciated. Cheers. :)

Canute


UnlimitedHugs

Quote from: Craftysune on April 24, 2017, 12:22:34 PM
I hope it's okay to post a general question here. But could someone help this noob out & please tell me where I'm supposed to put Libhugs when I've downloaded it.  :-[ I'm dying to use it because it looks amazing. I've tried to find out independently &  I've had no joy. Any help would be greatly appreciated. Cheers. :)

Like all other mods, just extract the zip file to your "/Rimworld/Mods/" folder and you should be good to go.
If you're playing on Steam, you might have an easier time installing the mod from the Workshop.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam