Skip to content

[REQUEST] Allow mods to hide settings introduced by other mods #513

Description

@Darxo

Is your feature request related to a problem? Please describe.

Sometimes a feature, gated by a setting, from another mod, is not compatible with our mod.
If a user was to turn on that setting, glitches or crashes would happen.
And fixing the underlying bugs would be too complicated.

Currently our only solutions would be to:

  • warn users to not touch that setting
  • declare the mod which introduces those settings, as incompatible with ours

Describe the solution you'd like

The MSU Settings should allow a mod to remove, disable or hide the settings introduced by other mods.
Additional our mod must provide a harmless default value, that is returned by that setting at all times, so that code, accessing that setting, still works correctly.

Proof of Concept

I have already implemented such a feature in my own mod. Here is how I have done it. MSU can of course implement this feature way easier, sitting at the source and such.

local oldEnumerateFiles = ::IO.enumerateFiles;
::IO.enumerateFiles = function ( _path )
{
	// We can only change classes, if they have not been inherited from, or instantiated yet
	// That's why we do our changes to AbstractSetting directly before all of its child classes are created
	if (_path == "msu/systems/mod_settings/elements/")
	{
		::MSU.Class.AbstractSetting.HD_Hidden <- false;
		local oldGetUIData = ::MSU.Class.AbstractSetting.getUIData;
		::MSU.Class.AbstractSetting.getUIData <- function( _flags = [] )
		{
			local ret = oldGetUIData.call(this, _flags);
			if (this.HD_Hidden) ret.hidden = true;
			return ret;
		}

		::MSU.Class.AbstractSetting.HD_ValueOverwrite <- null;
		local oldGetValue = ::MSU.Class.AbstractSetting.getValue;
		::MSU.Class.AbstractSetting.getValue <- function()
		{
			if (this.HD_ValueOverwrite != null) return this.HD_ValueOverwrite;
			return oldGetValue.call(this);
		}

		::MSU.Class.AbstractSetting.HD_hide <- function( _defaultValue )
		{
			this.HD_Hidden = true;
			this.HD_ValueOverwrite = _defaultValue;
		}
	}

	return oldEnumerateFiles(_path);
}

During a later timing, after those settings have been created, we can then hide them:

::Reforged.Mod.ModSettings.getSetting("AutoNegotiateAttempts").HD_hide(0);
::Reforged.Mod.ModSettings.getSetting("SkipContractsToScreen").HD_hide(false);

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestA feature requested by the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions