View Single Post
10-11-23, 12:15 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
Given you haven 't added your startup code, I may be misunderstanding the question but I think this may be closer to what you're trying to do,

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. --    _G["Keyboard"] = Keyboard
  6.     tinsert(UISpecialFrames, "KeyUIMainFrame")
  7.  
  8.     Keyboard:SetWidth(1099)
  9.     Keyboard:SetHeight(448)
  10.     Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  11.     Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  12.  
  13.     Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  14.     Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  15.     Keyboard:SetMovable(true) -- make the keyboard moveable
  16.     Keyboard:SetScale(1)
  17. --    Keyboard:Hide()
  18. --    Keyboard.Close = CreateFrame("Button", "$parentClose", Keyboard, "UIPanelCloseButton") -- Close button is on the Controls frame
  19. --    Keyboard.Close:SetSize(25, 25)
  20. --    Keyboard.Close:SetPoint("TOPRIGHT", Keyboard, "TOPRIGHT", 0, 0)
  21. --    Keyboard.Close:SetScript("OnClick", function(self) print(self:GetParent():GetName(), KBControlsFrame:GetParent():GetName()) end)
  22.  
  23.     addon.keyboardFrame = Keyboard
  24.  
  25.     return Keyboard
  26. end
  27.  
  28. function addon:CreateControls()
  29.     local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  30. --    _G["Controls"] = Controls
  31. --    tinsert(UISpecialFrames, "KBControlsFrame")
  32.     local Keyboard = addon.keyboardFrame
  33.     local Mouse = addon.MouseFrame
  34.     local modif = self.modif
  35.     Controls:SetBackdropColor(0, 0, 0, 1)
  36.     Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  37. --    Controls:Hide()
  38.  
  39.     local function OnMaximize()
  40.         Controls:SetHeight(100)
  41.         Controls:SetWidth(Keyboard:GetWidth())
  42.         maximizeFlag = true
  43.     end
  44.      
  45.     local function OnMinimize()
  46.         Controls:SetHeight(26)
  47.         Controls:SetWidth(Keyboard:GetWidth())
  48.         maximizeFlag = false
  49.     end
  50.  
  51.     Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
  52.     Controls.Close:SetSize(20, 20)
  53.     Controls.Close:SetPoint("TOPRIGHT", -2, -2)
  54.     Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:SetShown(not KeyUIMainFrame:IsShown())  end) -- Toggle the Keyboard frame show/hide
  55.  
  56.     Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
  57.     Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
  58.     Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  59.     Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  60.    
  61.     if maximizeFlag then
  62.  
  63.         Controls.Refresh = CreateFrame("Button", nil, Controls, "RefreshButtonTemplate")
  64.         Controls.Refresh:SetSize(24, 24)
  65.         Controls.Refresh:SetPoint("TOP", Controls.Close, "BOTTOM", 0, 4)
  66.         Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  67.  
  68.         Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  69.         Controls.Slider:SetMinMaxValues(0.5, 1)
  70.         Controls.Slider:SetValueStep(0.05)
  71.         Controls.Slider:SetValue(1)
  72.         _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  73.         _G[Controls.Slider:GetName().."High"]:SetText("1")
  74.         Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  75.         Controls.Slider:SetWidth(224)
  76.         Controls.Slider:SetHeight(20)
  77.         Controls.Slider:SetPoint("BOTTOMLEFT", Controls, "BOTTOMLEFT", 15, 55)
  78.  
  79.         Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  80.         _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  81.         Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  82.         Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  83.         Controls.ShiftCB:SetScript("OnClick", function(s)
  84.             if s:GetChecked() then
  85.                 modif.SHIFT = "SHIFT-"
  86.             else
  87.                 modif.SHIFT = ""
  88.             end
  89.             addon:RefreshKeys()
  90.         end)
  91.         Controls.ShiftCB:SetSize(30, 30)
  92.  
  93.         Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  94.         _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  95.         Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  96.         Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  97.         Controls.CtrlCB:SetScript("OnClick", function(s)
  98.             if s:GetChecked() then
  99.                 modif.CTRL = "CTRL-"
  100.             else
  101.                 modif.CTRL = ""
  102.             end
  103.             addon:RefreshKeys()
  104.         end)
  105.         Controls.CtrlCB:SetSize(30, 30)
  106.  
  107.         Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  108.         _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  109.         Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  110.         Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  111.         Controls.AltCB:SetScript("OnClick", function(s)
  112.             if s:GetChecked() then
  113.                 modif.ALT = "ALT-"
  114.             else
  115.                 modif.ALT = ""
  116.             end
  117.             addon:RefreshKeys()
  118.         end)
  119.         Controls.AltCB:SetSize(30, 30)
  120.  
  121.     else
  122.  
  123. --        if Controls.Close then
  124. --            Controls.Close:Hide()
  125. --        end
  126.    
  127.         if Controls.Refresh then
  128.             Controls.Refresh:Hide()
  129.         end
  130.  
  131.         if Controls.Slider then
  132.             Controls.Slider:Hide()
  133.         end
  134.  
  135.         if Controls.ShiftCB then
  136.             Controls.ShiftCB:Hide()
  137.         end
  138.  
  139.         if Controls.CtrlCB then
  140.             Controls.CtrlCB:Hide()
  141.         end
  142.        
  143.         if Controls.AltCB then
  144.             Controls.AltCB:Hide()
  145.         end
  146.        
  147.     end
  148.     Controls.MinMax.isMinimized = false -- Set the MinMax button & control frame size to Minimize
  149.     Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
  150.     Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
  151.  
  152.     return Controls
  153. end
  154. addon:CreateKeyboard()
  155. local ctl = addon:CreateControls()
  156.  
  157. ctl:SetScript("OnEvent", function(self, isInitialLogin, isReloadingUi)
  158.     if isInitialLogin or isReloadingUi then
  159.         self:Show()
  160.         addon.keyboardFrame:Show()
  161.     end
  162. end)
  163. ctl:RegisterEvent("PLAYER_ENTERING_WORLD")

As an aside, a frame with a name automatically has that name added to the global table as a reference to the frame so:
Code:
_G["Keyboard"] = Keyboard
is not required as you can refer to the frame via KeyUIMainFrame
Code:
KeyUIMainFrame:Show()
which is why it is best to make sure your frame names are unique by doing something like prefixing them with your addon name.

Blizzard will use the simplest/common names for things (including frames and globals) so words like Keyboard or Controls are not recommended on their own.
__________________
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 01:31 PM.
  Reply With Quote