diff --git a/msu/systems/mod_settings/abstract_setting.nut b/msu/systems/mod_settings/abstract_setting.nut index 1ce4551ce..f812f9ce6 100644 --- a/msu/systems/mod_settings/abstract_setting.nut +++ b/msu/systems/mod_settings/abstract_setting.nut @@ -3,8 +3,7 @@ static Type = "Abstract"; Value = null; BaseValue = null; - Locked = null; - LockReason = null; + Locks = null; BeforeChangeCallbacks = null; AfterChangeCallbacks = null; Persistence = null; //if it should print change to log for further manipulation @@ -14,8 +13,7 @@ base.constructor(_id, _name, _description) this.Value = _value; this.BaseValue = _value; - this.Locked = false; - this.LockReason = ""; + this.Locks = {}; this.Persistence = true; this.BeforeChangeCallbacks = []; this.AfterChangeCallbacks = []; @@ -84,7 +82,7 @@ function set( _newValue, _updateJS = true, _updatePersistence = true, _updateBeforeChangeCallback = true, _force = false, _updateAfterChangeCallback = true) { - if (this.Locked) + if (this.isLocked()) { ::logError("Setting \'" + this.Name + "\'' is locked and its value cannot be changed. Lock reason: " + this.getLockReason()); return false; @@ -141,24 +139,40 @@ function isLocked() { - return this.Locked; + return this.Locks.len() != 0; } function getLockReason() { - return this.LockReason == "" ? "" : this.LockReason.slice(0, -5); + local ret = ""; + foreach (lockReason in this.Locks) + { + ret += lockReason + " +++ "; + } + return ret == "" ? "" : ret.slice(0, -5); } + // Deprecated - use addLock instead function lock( _lockReason = "" ) { - this.Locked = true; - if (_lockReason != "") this.LockReason += _lockReason + " +++ "; + // "MSU_LegacyLock" is for legacy support for the days when settings used to have + // a this.Locked Boolean which could be set/unset using lock() and unlock() + this.Locks["MSU_LegacyLock" + this.Locks.len()] <- _lockReason; + } + + function addLock( _lockID, _lockReason ) + { + this.Locks[_lockID] <- _lockReason; + } + + function removeLock( _lockID ) + { + if (_lockID in this.Locks) delete this.Locks[_lockID]; } function unlock() { - this.Locked = false; - this.LockReason = ""; + this.Locks.clear(); } function getUIData(_flags = []) diff --git a/msu/systems/mod_settings/mod_settings_mod_addon.nut b/msu/systems/mod_settings/mod_settings_mod_addon.nut index ef99e5619..c005c762a 100644 --- a/msu/systems/mod_settings/mod_settings_mod_addon.nut +++ b/msu/systems/mod_settings/mod_settings_mod_addon.nut @@ -64,10 +64,19 @@ return true; } - function lockSetting( _setting, _lockReason ) + function addLock( _setting, _lockID, _lockReason ) { if (typeof _setting == "string") _setting = this.getSetting(_setting); - _setting.lock(_lockReason + format(" (%s (%s))", this.getMod().getID(), this.getMod().getName())); + _lockID = this.getMod().getID() + "." + _lockID; + _setting.addLock(_lockID, _lockReason); + } + + function removeLock( _setting, _lockID ) + { + if (typeof _setting == "string") _setting = this.getSetting(_setting); + + _lockID = this.getMod().getID() + "." + _lockID; + _setting.removeLock(_lockID); } }