diff --git a/DiesalGUI-2.0/DiesalGUI-2.0.lua b/DiesalGUI-2.0/DiesalGUI-2.0.lua index 9557402..3ba36dc 100644 --- a/DiesalGUI-2.0/DiesalGUI-2.0.lua +++ b/DiesalGUI-2.0/DiesalGUI-2.0.lua @@ -111,8 +111,7 @@ end ---|DiesalTree ---|DiesalWindow ----@diagnostic disable-next-line: undefined-field -_G.WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse) +WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse) -- Objects (widgets) that are defined for use in DiesalGUI ---@alias Diesal.Object.Type diff --git a/DiesalGUI-2.0/Objects/DropDown.lua b/DiesalGUI-2.0/Objects/DropDown.lua index e20867d..b6334c9 100644 --- a/DiesalGUI-2.0/Objects/DropDown.lua +++ b/DiesalGUI-2.0/Objects/DropDown.lua @@ -100,6 +100,7 @@ local methods = { self:SetStylesheet(Stylesheet) -- self:SetStylesheet(wireFrameSheet) self:Show() + self:SetFrameStrata("TOOLTIP") end, ---@param self Diesal.GUI.Object.DropDown @@ -135,8 +136,10 @@ local methods = { settings.list = list local foldColor = "353535" local expandColor = "5a5a5a" + self.dropdown:SetFrameStrata("TOOLTIP") for position, item in ipairs(list) do local dropdownItem = DiesalGUI:Create("DiesalDropDownItem") + DiesalGUI:OnMouse(dropdownItem.frame, "LeftButton") self:AddChild(dropdownItem) dropdownItem:SetParentObject(self) dropdownItem:SetSettings({ @@ -191,6 +194,7 @@ local methods = { SetValue = function(self, key) local selectionTable = {} local selectedKey, dropdownText, selectedValue + local selectedCount = 0 if key ~= "CLEAR" then if self.settings.multiSelect then @@ -200,6 +204,7 @@ local methods = { self.children[i]:SetSelected(true) end if self.children[i].settings.selected then + selectedCount = selectedCount + 1 if dropdownText then dropdownText = format("%s, %s", dropdownText, self.children[i].settings.value) else @@ -225,6 +230,10 @@ local methods = { self:ClearSelection() end + if self.settings.multiSelect then + dropdownText = string.format("+%d", selectedCount) + end + if selectedKey then self:SetText(dropdownText) self:FireEvent("OnValueChanged", selectedKey, selectedValue, selectionTable) @@ -251,6 +260,7 @@ local methods = { local selectionTable = {} local selectedKey local dropdownText + local selectedCount = 0 for i = 1, #dropdownItems do local dropdownItem = dropdownItems[i] @@ -258,12 +268,18 @@ local methods = { for _, key in ipairs(keyTable) do if dropdownItem.settings.key == key then dropdownItem:SetSelected(true) - dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItem.settings.value) or dropdownItem.settings.value + selectedCount = selectedCount + 1 + if not self.settings.multiSelect then + dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItem.settings.value) or dropdownItem.settings.value + end selectionTable[#selectionTable + 1] = dropdownItem.settings.key end end end self:FireEvent("OnValueChanged", nil, nil, selectionTable) + if self.settings.multiSelect then + dropdownText = string.format("+%d", selectedCount) + end self:SetText(dropdownText) end, @@ -290,6 +306,7 @@ local methods = { ---@param self Diesal.GUI.Object.DropDown ClearFocus = function(self) + self.dropdownShown = false self.dropdown:Hide() end, @@ -312,6 +329,27 @@ local methods = { SetJustifyH = function(self, justify) self.text:SetJustifyH(justify) end, + ---@param self Diesal.GUI.Object.DropDown + ShowDropDown = function(self) + self.dropdown:SetFrameStrata("TOOLTIP") + self.dropdown:SetParent(self.frame) + self.dropdown:Show() + self.dropdownShown = true + end, + ---@param self Diesal.GUI.Object.DropDown + HideDropDown = function(self) + self.dropdown:Hide() + self.dropdownShown = false + end, + ---@param self Diesal.GUI.Object.DropDown + ToggleDropDown = function(self) + print("ToggleDropDown", self.dropdown:IsShown()) + if self.dropdownShown then + self:HideDropDown() + else + self:ShowDropDown() + end + end, } ---@class Diesal.GUI.Obeject.DropDown.Settings @@ -327,6 +365,8 @@ local methods = { ---@class DiesalDropDown : Diesal.GUI.Object.DropDown +local f = CreateFrame("Button", nil, UIParent) + -- ~~| Dropdown Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ local function Constructor() ---@class Diesal.GUI.Object.DropDown : Diesal.GUI.ObjectBase, Diesal.GUI.DropDown.Methods @@ -337,8 +377,11 @@ local function Constructor() ---@field content Frame ---@field value string local self = DiesalGUI:Create(Type, true) + self:SetMethods(methods) + self.dropdownShown = true local frame = CreateFrame("Button", nil, UIParent) + frame:SetFrameStrata("TOOLTIP") self.frame = frame self.isContainer = true @@ -356,16 +399,16 @@ local function Constructor() -- OnValueSelected(event,selectedKey,selectedValue,selectionTable) -- OnEnter, OnLeave -- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - frame:SetScript("OnMouseUp", function(this, button) + frame:SetScript("OnClick", function(this, button, down) if button == "LeftButton" then - local dropdown = self.dropdown - local visible = dropdown:IsVisible() - DiesalGUI:OnMouse(this, button) - dropdown[visible and "Hide" or "Show"](dropdown) + if self.dropdown:IsVisible() then + self.dropdown:Hide() + else + DiesalGUI:OnMouse(this, button) + self.dropdown:Show() + end end - end) - frame:SetScript("OnClick", function(this, ...) - self:FireEvent("OnClick", ...) + self:FireEvent("OnClick", button, down) end) frame:SetScript("OnEnter", function(this, ...) self:FireEvent("OnEnter", ...) @@ -382,18 +425,24 @@ local function Constructor() text:SetJustifyH("LEFT") local dropdown = self:CreateRegion("Frame", "dropdown", frame) - dropdown:SetFrameStrata("FULLSCREEN_DIALOG") + dropdown:SetFrameStrata("TOOLTIP") + dropdown:SetFrameLevel(998) + dropdown:SetToplevel(true) dropdown:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", 0, -2) dropdown:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, -2) dropdown:SetScript("OnShow", function(this) self:SetFocus() end) + dropdown:SetScript("OnHide", function(this) + self.dropdownShown = false + end) dropdown:Hide() + self.dropdown = dropdown self:CreateRegion("Frame", "content", dropdown) -- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - self:SetMethods(methods) + --self:SetMethods(methods) --[[ for method, func in pairs(methods) do self[method] = func end ]] diff --git a/DiesalGUI-2.0/Objects/DropDownItem.lua b/DiesalGUI-2.0/Objects/DropDownItem.lua index 0ce8cdb..26bcedb 100644 --- a/DiesalGUI-2.0/Objects/DropDownItem.lua +++ b/DiesalGUI-2.0/Objects/DropDownItem.lua @@ -44,7 +44,6 @@ local methods = { local settings = self.settings local dropdownSettings = settings.parentObject.settings local text = self.text - if settings.position == 1 then self:SetPoint("TOPLEFT") else @@ -72,42 +71,49 @@ local methods = { ["OnClick"] = function(self) local settings = self.settings local dropdown = settings.parentObject - local dropdownSettings = dropdown.settings - local dropdownItems = dropdown.children + if dropdown then + ---@cast dropdown Diesal.GUI.Object.DropDown + local dropdownSettings = dropdown.settings + local dropdownItems = dropdown.children + local selectedCount = 0 - local selectionTable = {} - local dropdownText - if not settings.clickable then - return - end - if settings.key ~= "CLEAR" then - if dropdownSettings.multiSelect then - self:SetSelected(not settings.selected) - for i = 1, #dropdownItems do - if dropdownItems[i].settings.selected then - dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItems[i].settings.value) or dropdownItems[i].settings.value - selectionTable[#selectionTable + 1] = dropdownItems[i].settings.key + local selectionTable = {} + local dropdownText + if not settings.clickable then + return + end + if settings.key ~= "CLEAR" then + if dropdownSettings.multiSelect then + self:SetSelected(not settings.selected) + for i = 1, #dropdownItems do + if dropdownItems[i].settings.selected then + selectedCount = selectedCount + 1 + dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItems[i].settings.value) or dropdownItems[i].settings.value + selectionTable[#selectionTable + 1] = dropdownItems[i].settings.key + end end - end - else - for i = 1, #dropdownItems do - if dropdownItems[i].SetSelected then - dropdownItems[i]:SetSelected(false) + else + for i = 1, #dropdownItems do + if dropdownItems[i].SetSelected then + dropdownItems[i]:SetSelected(false) + end end + self:SetSelected(true) + dropdownText = settings.value + selectionTable = { settings.key } + dropdown.dropdown:Hide() end - self:SetSelected(true) - dropdownText = settings.value - selectionTable = { settings.key } + else dropdown.dropdown:Hide() + dropdown:ClearSelection() end - else - dropdown.dropdown:Hide() - dropdown:ClearSelection() + if dropdownSettings.multiSelect then + dropdownText = string.format("+%d", selectedCount) + end + dropdown:SetText(dropdownText) + dropdown:FireEvent("OnValueChanged", settings.key, settings.value, selectionTable) + dropdown:FireEvent("OnValueSelected", settings.key, settings.value, selectionTable) end - - dropdown:SetText(dropdownText) - dropdown:FireEvent("OnValueChanged", settings.key, settings.value, selectionTable) - dropdown:FireEvent("OnValueSelected", settings.key, settings.value, selectionTable) end, ---@param self Diesal.GUI.Object.DropDown.Item ["SetSelected"] = function(self, selected) @@ -125,6 +131,7 @@ local methods = { ---@field clickable boolean ---@field indent number ---@field header boolean +---@field parentObject Diesal.GUI.Object.DropDown ---@class DiesalDropDownItem : Diesal.GUI.Object.DropDown.Item @@ -136,6 +143,10 @@ local function Constructor() ---@field settings Diesal.GUI.DropDownItem.Settings local self = DiesalGUI:Create(Type, true) local frame = CreateFrame("Button", nil, UIParent) + frame:SetToplevel(true) + frame:SetFrameLevel(999) + frame:SetFrameStrata("TOOLTIP") + frame:SetFixedFrameStrata(true) self.frame = frame self.defaults = {} -- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/DiesalGUI-2.0/Objects/ObjectBase.lua b/DiesalGUI-2.0/Objects/ObjectBase.lua index 601b379..415f301 100644 --- a/DiesalGUI-2.0/Objects/ObjectBase.lua +++ b/DiesalGUI-2.0/Objects/ObjectBase.lua @@ -30,6 +30,13 @@ local ObjectBase = { self.frame:Show() end, + ---@generic T : Diesal.GUI.ObjectBase + ---@param self T | Diesal.GUI.ObjectBase + ---@param strata FrameStrata + SetFrameStrata = function(self, strata) + self.frame:SetFrameStrata(strata) + end, + ---@generic T : Diesal.GUI.ObjectBase ---@param self T | Diesal.GUI.ObjectBase ---@param parent Frame diff --git a/DiesalGUI-2.0/Objects/Toggle.lua b/DiesalGUI-2.0/Objects/Toggle.lua index ada167e..9582a7f 100644 --- a/DiesalGUI-2.0/Objects/Toggle.lua +++ b/DiesalGUI-2.0/Objects/Toggle.lua @@ -226,6 +226,10 @@ local function Constructor() frame:SetScript("OnEnable", function(this) self:FireEvent("OnEnable") end) + ---@param this Frame + frame:SetScript("OnShow", function(this) + this:SetFrameStrata("FULLSCREEN") + end) fontString:SetPoint("LEFT", frame, "RIGHT", 5, 0) fontString:SetHeight(15)