Thread Tools Display Modes
03-15-22, 05:19 PM   #1
muleyo
A Deviate Faerie Dragon
Join Date: Apr 2021
Posts: 12
CVars set via addon reset when entering Interface options

Hi,

I'm currently setting CVars via AddOn (nameplate-related to be specific). Unfortunately, the CVars reset whenever I go to Interface options... I tried resetting my Interface, that didn't fix the issue.

Any1 has an idea?

Edit: NamePlateVerticalScale always resets to its default value by InterfaceOptionsPanel.lua

Here's the code of InterfaceOptionsPanel.lua:

Code:
function InterfaceOptionsLargerNamePlate_OnLoad(self)
	function self:GetValue()
		if self.value then
			return self.value;
		end
		if math.abs(tonumber(GetCVar("NamePlateHorizontalScale")) - self.normalHorizontalScale) < .001 and
			math.abs(tonumber(GetCVar("NamePlateVerticalScale")) - self.normalVerticalScale) < .001 and
			math.abs(tonumber(GetCVar("NamePlateClassificationScale")) - self.normalClassificationScale) < .001 then
			return "0";
		end
		return "1";
	end

	function self.setFunc(value)
		if value == "1" then
			SetCVar("NamePlateHorizontalScale", self.largeHorizontalScale);
			SetCVar("NamePlateVerticalScale", self.largeVerticalScale);
			SetCVar("NamePlateClassificationScale", self.largeClassificationScale);
		else
			SetCVar("NamePlateHorizontalScale", self.normalHorizontalScale);
			SetCVar("NamePlateVerticalScale", self.normalVerticalScale);
			SetCVar("NamePlateClassificationScale", self.normalClassificationScale);
		end
		NamePlateDriverFrame:UpdateNamePlateOptions();
	end

	self.type = CONTROLTYPE_CHECKBOX;
	self.defaultValue = "0";
	BlizzardOptionsPanel_RegisterControl(self, self:GetParent():GetParent());
end
Unfortunately, I got no clue how to prevent that.

Last edited by muleyo : 03-15-22 at 06:41 PM.
  Reply With Quote
03-16-22, 02:08 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
InterfaceOptionsLargerNamePlate_OnLoad() just sets up those functions to run when you click on the button. :setFunc() gets called by InterfaceOptionsPanel_CheckButton_Update() through InterfaceOptionsPanel_CheckButton_OnClick(). This is also called from InterfaceOptionsPanel_CancelControl() under certain circumstances.

The easiest method would be to nuke :setFunc(). I would also advise disabling the button if this is to be in a published addon.

Lua Code:
  1. InterfaceOptionsNamesPanelUnitNameplatesMakeLarger.setFunc=nop;--   Overwrite with Blizzard-provided NoOp function
  2. InterfaceOptionsNamesPanelUnitNameplatesMakeLarger.value="0";--     Set our own value to unchecked (see custom :GetValue())
  3. BlizzardOptionsPanel_CheckButton_Disable(InterfaceOptionsNamesPanelUnitNameplatesMakeLarger);-- Disable button
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-16-22, 11:23 AM   #3
muleyo
A Deviate Faerie Dragon
Join Date: Apr 2021
Posts: 12
Originally Posted by SDPhantom View Post
InterfaceOptionsLargerNamePlate_OnLoad() just sets up those functions to run when you click on the button. :setFunc() gets called by InterfaceOptionsPanel_CheckButton_Update() through InterfaceOptionsPanel_CheckButton_OnClick(). This is also called from InterfaceOptionsPanel_CancelControl() under certain circumstances.

The easiest method would be to nuke :setFunc(). I would also advise disabling the button if this is to be in a published addon.

Lua Code:
  1. InterfaceOptionsNamesPanelUnitNameplatesMakeLarger.setFunc=nop;--   Overwrite with Blizzard-provided NoOp function
  2. InterfaceOptionsNamesPanelUnitNameplatesMakeLarger.value="0";--     Set our own value to unchecked (see custom :GetValue())
  3. BlizzardOptionsPanel_CheckButton_Disable(InterfaceOptionsNamesPanelUnitNameplatesMakeLarger);-- Disable button
Thank you! That resolved it.

The addon is just for private use and just working with CVars n stuff, just to make sure that every single character has the same settings etc.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » CVars set via addon reset when entering Interface options

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off