[1.5] HugsLib (11.0.3) Lightweight modding library

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

Previous topic - Next topic

UnlimitedHugs

Quote from: scuba156 on June 01, 2017, 08:20:18 AM
I ended up getting a bit carried away... complete with an OnClick event, and even animation to make it scroll up from the bottom of the screen, wait for a few seconds and then scroll back down.

That looks pretty cool! I did wonder if achievements should give points- what would one unlock with them, though? Perhaps the the mods that make use of them could also provide some cosmetic unlocks, or something- like golden icons, reskinned things, cheat options, and the like.
A window that lists all achievements could also be used to unlock and toggle the rewards.

Quote from: Love on June 01, 2017, 09:34:31 AM
I suggest incorporating this function into HugsLib
https://github.com/cuproPanda/STN/blob/master/Source/CuprosStones/PatchOperationFindMod.cs

Could be useful, but I wouldn't rely on mod names too much- the author might add a version to the name, or something. It's generally more reliable to reflect the main class of the mod you're checking for, like so:
if(GenTypes.GetTypeInAnyAssembly("ModNamespace.ModController")!=null)
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

#226
Quote from: UnlimitedHugs on June 01, 2017, 10:06:54 AM
That looks pretty cool! I did wonder if achievements should give points- what would one unlock with them, though? Perhaps the the mods that make use of them could also provide some cosmetic unlocks, or something- like golden icons, reskinned things, cheat options, and the like.
A window that lists all achievements could also be used to unlock and toggle the rewards.
I attached a gif of the popup animating, hopefully it works.
Rewards would be pretty cool, maybe have point tiers that when reached would display a different coloured badge to show off (like bronze, silver, gold, diamond etc)

Edit: I've added an achievement def, here's an example, the test achievement can be triggered with       
Instance.Achievements.Trigger_AchievementEarned("Test");

[attachment deleted by admin due to age]

scuba156

I know you said we were just tossing around ideas but I've still being working on it. So far I've done:

  • Harmony patch to allow the main menu to draw when an achievement popup is visible
  • A notification controller for the popups
  • Managed list of unlocked achievements with unlock date
  • unlocked achievements xml saving/loading
The popup notification controller queues all notifications and only allows X amount of popups to be drawn at a time. The next queued popup will start to draw when another closes. Each popup is drawn at the first free position available vertically (if there are were 8 popups total, and the first 4 have closed, it will draw the next popup in place of the first closed popup instead of above the the popup). A popup will scroll all the way off screen before it closes. Its a bit buggy with drawing some popups on top of each other at the moment but it basically works.

The controller could be adapted to host a toast notification system if you like? It could allow mods to queue toast messages of their own, display messages/images/progress bars/buttons (anything a Window can draw) with an OnClick event and multiple styles like fade in/out or scroll in/out from any screen side. Sounds like it could be really useful, and most of the code is already there.

UnlimitedHugs

Quote from: scuba156 on June 02, 2017, 04:43:59 PM
- snip -

Sounds like you're really getting into it :)
I probably won't be adding your version to the library, though, since I'm looking forward to working on it myself when the time comes. I'm still debating wether achievements should be part of the library in the first place- might be a better fit for a standalone library.
In any case, variety and options are always nice- so I hope my plans don't deter your enthusiasm. After all, it's about the process, not the result :P
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

Quote from: UnlimitedHugs on June 02, 2017, 05:00:02 PM
Sounds like you're really getting into it :)
I probably won't be adding your version to the library, though, since I'm looking forward to working on it myself when the time comes. I'm still debating wether achievements should be part of the library in the first place- might be a better fit for a standalone library.
In any case, variety and options are always nice- so I hope my plans don't deter your enthusiasm. After all, it's about the process, not the result :P
It does deter me from continuing with achievements as I don't think 2 different standards would be healthy but its not a bad thing at all, as there is now a code reference and I've learnt a lot (I now know how to write harmony transpilers which I'll need for the steam downloads) and I've decided to continue with the Toast Message controller in a seperate mod. You can always use the toast messages to display achievements. I do think that achievements should be in a separate mod

UnlimitedHugs

Quote from: scuba156 on June 03, 2017, 02:58:18 AM
It does deter me from continuing with achievements as I don't think 2 different standards would be healthy but its not a bad thing at all, as there is now a code reference and I've learnt a lot (I now know how to write harmony transpilers which I'll need for the steam downloads) and I've decided to continue with the Toast Message controller in a seperate mod. You can always use the toast messages to display achievements. I do think that achievements should be in a separate mod

I see. Well, whatever you enjoy working on most- at least that's how I pick my battles.
As for the separate mod, my idea was to make it a Harmony-style library: include your own copy, but only the most recent version will do the GUI work. This wouldn't fly for HugsLib, as it's way too complex, but with a small feature set it's quite viable.
Also, yay for transpiler. Those things are so much fun!
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

ChairmanPoo

Hello, I'm getting this bug at worldgen. I'm seeing mentions to Harmony in it. I assume it's related?


Exception from asynchronous event: System.TypeInitializationException: An exception was thrown by the type initializer for CompVehicle.HarmonyCompPilotable ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: key
  at System.Collections.Generic.Dictionary`2[System.Reflection.MethodBase,System.Byte[]].TryGetValue (System.Reflection.MethodBase key, System.Byte[]& value) [0x00000] in <filename unknown>:0
  at Harmony.GeneralExtensions.GetValueSafe[MethodBase,Byte[]] (System.Collections.Generic.Dictionary`2 dictionary, System.Reflection.MethodBase key) [0x00000] in <filename unknown>:0
  at Harmony.HarmonySharedState.GetPatchInfo (System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0
  at Harmony.PatchProcessor.Patch () [0x00000] in <filename unknown>:0
  at Harmony.HarmonyInstance.Patch (System.Reflection.MethodBase original, Harmony.HarmonyMethod prefix, Harmony.HarmonyMethod postfix, Harmony.HarmonyMethod transpiler) [0x00000] in <filename unknown>:0
  at CompVehicle.HarmonyCompPilotable..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (intptr)
  at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (RuntimeTypeHandle type) [0x00000] in <filename unknown>:0
  at Verse.StaticConstructorOnStartupUtility.CallAll () [0x00000] in <filename unknown>:0
  at Verse.PlayDataLoader.<DoPlayLoad>m__80F () [0x00000] in <filename unknown>:0
  at Verse.LongEventHandler.ExecuteToExecuteWhenFinished () [0x00000] in <filename unknown>:0
Verse.Log:Error(String)
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__84C()


UnlimitedHugs

Quote from: ChairmanPoo on June 03, 2017, 03:20:16 PM
Hello, I'm getting this bug at worldgen. I'm seeing mentions to Harmony in it. I assume it's related?

Heyo. I think this is caused by Jec's tools. Seems the author has already been notified.
This comment thread will probably be updated once a fix is out.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Nqshou

Hello,

Is HugsLib updated for A17b?

Many thanks.

Stormfox

Btw, I get a harmony.log.txt on my desktop every time I start rimworld. I guess for some reason harmony cannot find the correct directory to place that logfile in? I reinstalled the newest HugsLib, did not help. Its only a minor annoyance, but it would be nifty if this disappeared sometime in the future.

UnlimitedHugs

Quote from: Nqshou on June 04, 2017, 07:53:14 AM
Hello, Is HugsLib updated for A17b?
Many thanks.

I've seen no conflicts or other problems since the update.
You should be fine using the same version of HugsLib.

Quote from: Stormfox on June 04, 2017, 10:23:04 AM
Btw, I get a harmony.log.txt on my desktop every time I start rimworld. I guess for some reason harmony cannot find the correct directory to place that logfile in? I reinstalled the newest HugsLib, did not help. Its only a minor annoyance, but it would be nifty if this disappeared sometime in the future.

It should be on the desktop- one of your mods forgot to turn off debug mode for Harmony. No easy way to find out which one, though.
I'll poke pardeike to add the id of the mod to the log file, but for now looks like you're on recycle bin duty.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

Hello again.
I would to save something I similar to World data storage object but I want it to be persistent, like mod settings.

I can easily save those settings by using ExposeData() but SettingHandleConvertible does not provide such a feature.
I want to save a list of objects that have their ExposeData() method.
Perhaps I could convert them to a string (and then use SettingHandleConvertible) but that does not seem to be the best way I think.

(those objects are food policies, similar to drug policies).

Do you recommend something ?

UnlimitedHugs

Quote from: Wishmaster on June 04, 2017, 04:15:56 PM
Do you recommend something ?

I would probably store them in a SettingHandleConvertible and pack/unpack them using DirectXmlSaver and DirectXmlToObject.
Since your objects need to be IExposable, I assume they are also stored in the save file- in which case I would just store their ids and resolve the references at load time. This may or may not be applicable in your case, though.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

Quote from: UnlimitedHugs on June 05, 2017, 10:19:33 AM
Quote from: Wishmaster on June 04, 2017, 04:15:56 PM
Do you recommend something ?

I would probably store them in a SettingHandleConvertible and pack/unpack them using DirectXmlSaver and DirectXmlToObject.
Since your objects need to be IExposable, I assume they are also stored in the save file- in which case I would just store their ids and resolve the references at load time. This may or may not be applicable in your case, though.

I wanted to store something persistent like settings but do it easily using IExpose.
But know I guess I have to do direct xml conversion.

scuba156

Hey I haven't forgotten about hugslib or the the active mod checker, I've had a few other mods to work on for a bit, still have a few more in progress :-X
But I've been thinking of the best way to check for active/missing mods might be to do something similar to HugsLibChecker, a replacement basically.  It would be a completely separate mod without a hugslib dependency.

A mod can add a dependencies.xml file similar to version.xml which lists any other mods by name/steam id (might even be able to do a steam lookup) that it depends on. It would harmony patch the mod loading and/or saved game loading sequence, check for any missing dependencies, compile a list of whats not active/installed and display a prompt similar to HugsLibChecker with the list of links for missing mods and an activate/restart button.

I'm thinking this way because I have mods that have dependencies on another core mod of mine, and I need to make sure it is active, so it would be better to have something universal rather than a library per dependency. By patching both the mod loading and save game loading, it should suit the purpose of checking mods with the quickstarter but also checking mod dependencies all in one swift kick.