WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   CVars set via addon reset when entering Interface options (https://www.wowinterface.com/forums/showthread.php?t=59069)

muleyo 03-15-22 05:19 PM

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.

SDPhantom 03-16-22 02:08 AM

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

muleyo 03-16-22 11:23 AM

Quote:

Originally Posted by SDPhantom (Post 340422)
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. :)


All times are GMT -6. The time now is 01:38 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI