UnlimitedHugs / RimworldHugsLib

A lightweight shared library for Rimworld modding.
Other
244 stars 59 forks source link

Suggestion: visually update a handle's value when ResetToDefault() is called. #74

Closed jptrrs closed 3 years ago

jptrrs commented 3 years ago

Hi! Recently I had to write this custom validation for a group of related SettingHandle<bool> which called for a ResetToDefault() on one of them. Unfortunately, the user would never get the feedback for what was happening because the red X would never turn into a green tick unless the settings window was closed and re-opened. I realized it would require an update to the dialog's handleControlInfo so I resorted to the reflection and invocation of the dilaog's ResetHandleControlInfo method. It works just fine, but looks so janky! Wouldn't it be better if this reset was automatically triggered when calling ResetToDefault()?

public void ValidateTechPoolSettings(bool value)
{
    if (!value && !TechPoolIncludesStarting.Value && !TechPoolIncludesTechLevel.Value && !TechPoolIncludesBackground && !TechPoolIncludesScenario)
    {
        Messages.Message("TechPoolMinimumDefaultMsg".Translate(), MessageTypeDefOf.CautionInput);
        TechPoolIncludesStarting.ResetToDefault();
        MethodInfo ResetHandleControlInfo = AccessTools.Method("HugsLib.Settings.Dialog_ModSettings:ResetHandleControlInfo");
        ResetHandleControlInfo.Invoke(Find.WindowStack.currentlyDrawnWindow, new object[] { TechPoolIncludesStarting } );
    }
}
UnlimitedHugs commented 3 years ago

Quite true. Currently I am planning to add an OnChanged event that will deprecate OnValueChanged, which is a plain delegate. The settings window will subscribe to the event on all handles, and update their view when a value changes. That should cover all use cases, I think. Good job on the reflection approach- that should work for the time being.

jptrrs commented 3 years ago

Sounds good!

UnlimitedHugs commented 3 years ago

Implemented in 9.0.0. See ValueChanged for details.