View Single Post
10-11-23, 04:56 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
Because you have the
Lua Code:
  1. if maximizeFlag then
  2.          Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  3.          --...
  4. end
inside
Code:
function addon:CreateControls()
then maximizeFlag has to set BEFORE you call the function and create the Controls frame. I can only guess you are doing that when the addon loads.

That said, you only want to call the function once as frames (widgets in general including Textures and FontStrings) are not destroyed (deleted, removed...) until you exit the game (or logout or /reload) so once created you Show/Hide them as required.

Possibly what you want to do is
Lua Code:
  1. local function OnMaximize()
  2.         Controls:SetHeight(100)
  3.         Controls:SetWidth(Keyboard:GetWidth())
  4.         maximizeFlag = true
  5.         print("maximizeFlag is true")
  6.         if not Controls.Slider then -- if his is the first time maximized then create the slider etc.
  7.                 Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  8.                 -- and all the other stuff
  9.         end
  10.         Controls.Slider:Show()
  11.         -- show all the other controls on maximize
  12. end
  13. local function OnMinimize()
  14.         Controls:SetHeight(26)
  15.         Controls:SetWidth(Keyboard:GetWidth())
  16.         maximizeFlag = false
  17.         print("maximizeFlag is false")
  18.         Controls.Slider:Hide()
  19.         -- hide all the other controls on minimize
  20. end

It might all look something like:
Lua Code:
  1. local name, addon = ...
  2.      
  3.     function addon:CreateKeyboard()
  4.         local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
  5.         tinsert(UISpecialFrames, "KeyUIMainFrame")
  6.      
  7.         Keyboard:SetWidth(1099)
  8.         Keyboard:SetHeight(448)
  9.         Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  10.         Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  11.      
  12.         Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  13.         Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  14.         Keyboard:SetMovable(true) -- make the keyboard moveable
  15.         Keyboard:SetScale(1)
  16.      
  17.         addon.keyboardFrame = Keyboard
  18.      
  19.         return Keyboard
  20.     end
  21.      
  22.     function addon:CreateControls()
  23.         local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  24.         tinsert(UISpecialFrames, "KBControlsFrame")
  25.         local Keyboard = addon.keyboardFrame
  26.         local modif = self.modif
  27.         Controls:SetBackdropColor(0, 0, 0, 1)
  28.         Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  29.      
  30.         local function OnMaximize()
  31.             Controls:SetHeight(100)
  32.             Controls:SetWidth(Keyboard:GetWidth())
  33.             maximizeFlag = true
  34.             print("maximizeFlag is true")
  35.             if not Controls.Slider then
  36.                 Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  37.                 Controls.Slider:SetMinMaxValues(0.5, 1)
  38.                 Controls.Slider:SetValueStep(0.05)
  39.                 Controls.Slider:SetValue(1)
  40.                 _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  41.                 _G[Controls.Slider:GetName().."High"]:SetText("1")
  42.                 Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  43.                 Controls.Slider:SetWidth(224)
  44.                 Controls.Slider:SetHeight(20)
  45.                 Controls.Slider:SetPoint("BOTTOM", Controls, "BOTTOM", 0, 0)
  46.      
  47.                 Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate")
  48.                 _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  49.                 Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  50.                 Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  51.                 Controls.ShiftCB:SetScript("OnClick", function(s)
  52.                     if s:GetChecked() then
  53.                         modif.SHIFT = "SHIFT-"
  54.                     else
  55.                         modif.SHIFT = ""
  56.                     end
  57.                     addon:RefreshKeys()
  58.                 end)
  59.                 Controls.ShiftCB:SetSize(30, 30)
  60.      
  61.                 Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate")
  62.                 _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  63.                 Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  64.                 Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  65.                 Controls.CtrlCB:SetScript("OnClick", function(s)
  66.                     if s:GetChecked() then
  67.                         modif.CTRL = "CTRL-"
  68.                     else
  69.                         modif.CTRL = ""
  70.                     end
  71.                     addon:RefreshKeys()
  72.                 end)
  73.                 Controls.CtrlCB:SetSize(30, 30)
  74.      
  75.                 Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate")
  76.                 _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  77.                 Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  78.                 Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  79.                 Controls.AltCB:SetScript("OnClick", function(s)
  80.                     if s:GetChecked() then
  81.                         modif.ALT = "ALT-"
  82.                     else
  83.                         modif.ALT = ""
  84.                     end
  85.                     addon:RefreshKeys()
  86.                 end)
  87.                 Controls.AltCB:SetSize(30, 30)
  88.              end
  89.              Controls.Slider:Show()
  90.              Controls.ShiftCB:Show()
  91.              Controls.CtrlCB:Show()
  92.              Controls.AltCB:Show()
  93.  
  94.         end
  95.        
  96.         local function OnMinimize()
  97.             Controls:SetHeight(26)
  98.             Controls:SetWidth(Keyboard:GetWidth())
  99.             maximizeFlag = false
  100.             print("maximizeFlag is false")
  101.             if Controls.Slider then
  102.                 Controls.Slider:Hide()
  103.                 Controls.ShiftCB:Hide()
  104.                 Controls.CtrlCB:Hide()
  105.                 Controls.AltCB:Hide()
  106.             end
  107.         end
  108.        
  109.         Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
  110.         Controls.Close:SetSize(22, 22)
  111.         Controls.Close:SetPoint("TOPRIGHT", -2, -2)
  112.         Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:Hide() KBControlsFrame:Hide() end) -- Toggle the Keyboard frame show/hide
  113.      
  114.         Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
  115.         Controls.MinMax:SetSize(22, 22)
  116.         Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
  117.         Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  118.         Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  119.      
  120.         Controls.Refresh = CreateFrame("Button", "#parentRefresh", Controls, "RefreshButtonTemplate")
  121.         Controls.Refresh:SetSize(24, 24)
  122.         Controls.Refresh:SetPoint("RIGHT", Controls.MinMax, "LEFT", 0, 0)
  123.         Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  124.        
  125.        
  126.         --Controls.MinMax.isMinimized = true -- Set the MinMax button & control frame size to Minimize  -- this seems to have no effect?
  127.         Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
  128.         Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
  129.      
  130.         addon.controlsFrame = KBControlsFrame
  131.      
  132.         return Controls
  133.     end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-11-23 at 07:12 PM.
  Reply With Quote