local name, addon = ...
function addon:CreateKeyboard()
local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
-- _G["Keyboard"] = Keyboard
tinsert(UISpecialFrames, "KeyUIMainFrame")
Keyboard:SetWidth(1099)
Keyboard:SetHeight(448)
Keyboard:SetBackdropColor(0, 0, 0, 0.9)
Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
Keyboard:SetMovable(true) -- make the keyboard moveable
Keyboard:SetScale(1)
-- Keyboard:Hide()
-- Keyboard.Close = CreateFrame("Button", "$parentClose", Keyboard, "UIPanelCloseButton") -- Close button is on the Controls frame
-- Keyboard.Close:SetSize(25, 25)
-- Keyboard.Close:SetPoint("TOPRIGHT", Keyboard, "TOPRIGHT", 0, 0)
-- Keyboard.Close:SetScript("OnClick", function(self) print(self:GetParent():GetName(), KBControlsFrame:GetParent():GetName()) end)
addon.keyboardFrame = Keyboard
return Keyboard
end
function addon:CreateControls()
local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
-- _G["Controls"] = Controls
-- tinsert(UISpecialFrames, "KBControlsFrame")
local Keyboard = addon.keyboardFrame
local Mouse = addon.MouseFrame
local modif = self.modif
Controls:SetBackdropColor(0, 0, 0, 1)
Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
-- Controls:Hide()
local function OnMaximize()
Controls:SetHeight(100)
Controls:SetWidth(Keyboard:GetWidth())
maximizeFlag = true
end
local function OnMinimize()
Controls:SetHeight(26)
Controls:SetWidth(Keyboard:GetWidth())
maximizeFlag = false
end
Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
Controls.Close:SetSize(20, 20)
Controls.Close:SetPoint("TOPRIGHT", -2, -2)
Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:SetShown(not KeyUIMainFrame:IsShown()) end) -- Toggle the Keyboard frame show/hide
Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
if maximizeFlag then
Controls.Refresh = CreateFrame("Button", nil, Controls, "RefreshButtonTemplate")
Controls.Refresh:SetSize(24, 24)
Controls.Refresh:SetPoint("TOP", Controls.Close, "BOTTOM", 0, 4)
Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
Controls.Slider:SetMinMaxValues(0.5, 1)
Controls.Slider:SetValueStep(0.05)
Controls.Slider:SetValue(1)
_G[Controls.Slider:GetName().."Low"]:SetText("0.5")
_G[Controls.Slider:GetName().."High"]:SetText("1")
Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
Controls.Slider:SetWidth(224)
Controls.Slider:SetHeight(20)
Controls.Slider:SetPoint("BOTTOMLEFT", Controls, "BOTTOMLEFT", 15, 55)
Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
_G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
Controls.ShiftCB:SetScript("OnClick", function(s)
if s:GetChecked() then
modif.SHIFT = "SHIFT-"
else
modif.SHIFT = ""
end
addon:RefreshKeys()
end)
Controls.ShiftCB:SetSize(30, 30)
Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
_G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
Controls.CtrlCB:SetScript("OnClick", function(s)
if s:GetChecked() then
modif.CTRL = "CTRL-"
else
modif.CTRL = ""
end
addon:RefreshKeys()
end)
Controls.CtrlCB:SetSize(30, 30)
Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
_G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
Controls.AltCB:SetScript("OnClick", function(s)
if s:GetChecked() then
modif.ALT = "ALT-"
else
modif.ALT = ""
end
addon:RefreshKeys()
end)
Controls.AltCB:SetSize(30, 30)
else
-- if Controls.Close then
-- Controls.Close:Hide()
-- end
if Controls.Refresh then
Controls.Refresh:Hide()
end
if Controls.Slider then
Controls.Slider:Hide()
end
if Controls.ShiftCB then
Controls.ShiftCB:Hide()
end
if Controls.CtrlCB then
Controls.CtrlCB:Hide()
end
if Controls.AltCB then
Controls.AltCB:Hide()
end
end
Controls.MinMax.isMinimized = false -- Set the MinMax button & control frame size to Minimize
Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
return Controls
end
addon:CreateKeyboard()
local ctl = addon:CreateControls()
ctl:SetScript("OnEvent", function(self, isInitialLogin, isReloadingUi)
if isInitialLogin or isReloadingUi then
self:Show()
addon.keyboardFrame:Show()
end
end)
ctl:RegisterEvent("PLAYER_ENTERING_WORLD")