main
jeffi 11 months ago
parent 892f29cd2b
commit d00e705bfe
  1. 3
      DiesalGUI-2.0/DiesalGUI-2.0.lua
  2. 71
      DiesalGUI-2.0/Objects/DropDown.lua
  3. 71
      DiesalGUI-2.0/Objects/DropDownItem.lua
  4. 7
      DiesalGUI-2.0/Objects/ObjectBase.lua
  5. 4
      DiesalGUI-2.0/Objects/Toggle.lua

@ -111,8 +111,7 @@ end
---|DiesalTree ---|DiesalTree
---|DiesalWindow ---|DiesalWindow
---@diagnostic disable-next-line: undefined-field WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse)
_G.WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse)
-- Objects (widgets) that are defined for use in DiesalGUI -- Objects (widgets) that are defined for use in DiesalGUI
---@alias Diesal.Object.Type ---@alias Diesal.Object.Type

@ -100,6 +100,7 @@ local methods = {
self:SetStylesheet(Stylesheet) self:SetStylesheet(Stylesheet)
-- self:SetStylesheet(wireFrameSheet) -- self:SetStylesheet(wireFrameSheet)
self:Show() self:Show()
self:SetFrameStrata("TOOLTIP")
end, end,
---@param self Diesal.GUI.Object.DropDown ---@param self Diesal.GUI.Object.DropDown
@ -135,8 +136,10 @@ local methods = {
settings.list = list settings.list = list
local foldColor = "353535" local foldColor = "353535"
local expandColor = "5a5a5a" local expandColor = "5a5a5a"
self.dropdown:SetFrameStrata("TOOLTIP")
for position, item in ipairs(list) do for position, item in ipairs(list) do
local dropdownItem = DiesalGUI:Create("DiesalDropDownItem") local dropdownItem = DiesalGUI:Create("DiesalDropDownItem")
DiesalGUI:OnMouse(dropdownItem.frame, "LeftButton")
self:AddChild(dropdownItem) self:AddChild(dropdownItem)
dropdownItem:SetParentObject(self) dropdownItem:SetParentObject(self)
dropdownItem:SetSettings({ dropdownItem:SetSettings({
@ -191,6 +194,7 @@ local methods = {
SetValue = function(self, key) SetValue = function(self, key)
local selectionTable = {} local selectionTable = {}
local selectedKey, dropdownText, selectedValue local selectedKey, dropdownText, selectedValue
local selectedCount = 0
if key ~= "CLEAR" then if key ~= "CLEAR" then
if self.settings.multiSelect then if self.settings.multiSelect then
@ -200,6 +204,7 @@ local methods = {
self.children[i]:SetSelected(true) self.children[i]:SetSelected(true)
end end
if self.children[i].settings.selected then if self.children[i].settings.selected then
selectedCount = selectedCount + 1
if dropdownText then if dropdownText then
dropdownText = format("%s, %s", dropdownText, self.children[i].settings.value) dropdownText = format("%s, %s", dropdownText, self.children[i].settings.value)
else else
@ -225,6 +230,10 @@ local methods = {
self:ClearSelection() self:ClearSelection()
end end
if self.settings.multiSelect then
dropdownText = string.format("+%d", selectedCount)
end
if selectedKey then if selectedKey then
self:SetText(dropdownText) self:SetText(dropdownText)
self:FireEvent("OnValueChanged", selectedKey, selectedValue, selectionTable) self:FireEvent("OnValueChanged", selectedKey, selectedValue, selectionTable)
@ -251,6 +260,7 @@ local methods = {
local selectionTable = {} local selectionTable = {}
local selectedKey local selectedKey
local dropdownText local dropdownText
local selectedCount = 0
for i = 1, #dropdownItems do for i = 1, #dropdownItems do
local dropdownItem = dropdownItems[i] local dropdownItem = dropdownItems[i]
@ -258,12 +268,18 @@ local methods = {
for _, key in ipairs(keyTable) do for _, key in ipairs(keyTable) do
if dropdownItem.settings.key == key then if dropdownItem.settings.key == key then
dropdownItem:SetSelected(true) 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 selectionTable[#selectionTable + 1] = dropdownItem.settings.key
end end
end end
end end
self:FireEvent("OnValueChanged", nil, nil, selectionTable) self:FireEvent("OnValueChanged", nil, nil, selectionTable)
if self.settings.multiSelect then
dropdownText = string.format("+%d", selectedCount)
end
self:SetText(dropdownText) self:SetText(dropdownText)
end, end,
@ -290,6 +306,7 @@ local methods = {
---@param self Diesal.GUI.Object.DropDown ---@param self Diesal.GUI.Object.DropDown
ClearFocus = function(self) ClearFocus = function(self)
self.dropdownShown = false
self.dropdown:Hide() self.dropdown:Hide()
end, end,
@ -312,6 +329,27 @@ local methods = {
SetJustifyH = function(self, justify) SetJustifyH = function(self, justify)
self.text:SetJustifyH(justify) self.text:SetJustifyH(justify)
end, 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 ---@class Diesal.GUI.Obeject.DropDown.Settings
@ -327,6 +365,8 @@ local methods = {
---@class DiesalDropDown : Diesal.GUI.Object.DropDown ---@class DiesalDropDown : Diesal.GUI.Object.DropDown
local f = CreateFrame("Button", nil, UIParent)
-- ~~| Dropdown Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~| Dropdown Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local function Constructor() local function Constructor()
---@class Diesal.GUI.Object.DropDown : Diesal.GUI.ObjectBase, Diesal.GUI.DropDown.Methods ---@class Diesal.GUI.Object.DropDown : Diesal.GUI.ObjectBase, Diesal.GUI.DropDown.Methods
@ -337,8 +377,11 @@ local function Constructor()
---@field content Frame ---@field content Frame
---@field value string ---@field value string
local self = DiesalGUI:Create(Type, true) local self = DiesalGUI:Create(Type, true)
self:SetMethods(methods)
self.dropdownShown = true
local frame = CreateFrame("Button", nil, UIParent) local frame = CreateFrame("Button", nil, UIParent)
frame:SetFrameStrata("TOOLTIP")
self.frame = frame self.frame = frame
self.isContainer = true self.isContainer = true
@ -356,16 +399,16 @@ local function Constructor()
-- OnValueSelected(event,selectedKey,selectedValue,selectionTable) -- OnValueSelected(event,selectedKey,selectedValue,selectionTable)
-- OnEnter, OnLeave -- OnEnter, OnLeave
-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
frame:SetScript("OnMouseUp", function(this, button) frame:SetScript("OnClick", function(this, button, down)
if button == "LeftButton" then if button == "LeftButton" then
local dropdown = self.dropdown if self.dropdown:IsVisible() then
local visible = dropdown:IsVisible() self.dropdown:Hide()
DiesalGUI:OnMouse(this, button) else
dropdown[visible and "Hide" or "Show"](dropdown) DiesalGUI:OnMouse(this, button)
self.dropdown:Show()
end
end end
end) self:FireEvent("OnClick", button, down)
frame:SetScript("OnClick", function(this, ...)
self:FireEvent("OnClick", ...)
end) end)
frame:SetScript("OnEnter", function(this, ...) frame:SetScript("OnEnter", function(this, ...)
self:FireEvent("OnEnter", ...) self:FireEvent("OnEnter", ...)
@ -382,18 +425,24 @@ local function Constructor()
text:SetJustifyH("LEFT") text:SetJustifyH("LEFT")
local dropdown = self:CreateRegion("Frame", "dropdown", frame) 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("TOPRIGHT", frame, "BOTTOMRIGHT", 0, -2)
dropdown:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, -2) dropdown:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, -2)
dropdown:SetScript("OnShow", function(this) dropdown:SetScript("OnShow", function(this)
self:SetFocus() self:SetFocus()
end) end)
dropdown:SetScript("OnHide", function(this)
self.dropdownShown = false
end)
dropdown:Hide() dropdown:Hide()
self.dropdown = dropdown
self:CreateRegion("Frame", "content", dropdown) self:CreateRegion("Frame", "content", dropdown)
-- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
self:SetMethods(methods) --self:SetMethods(methods)
--[[ for method, func in pairs(methods) do --[[ for method, func in pairs(methods) do
self[method] = func self[method] = func
end ]] end ]]

@ -44,7 +44,6 @@ local methods = {
local settings = self.settings local settings = self.settings
local dropdownSettings = settings.parentObject.settings local dropdownSettings = settings.parentObject.settings
local text = self.text local text = self.text
if settings.position == 1 then if settings.position == 1 then
self:SetPoint("TOPLEFT") self:SetPoint("TOPLEFT")
else else
@ -72,42 +71,49 @@ local methods = {
["OnClick"] = function(self) ["OnClick"] = function(self)
local settings = self.settings local settings = self.settings
local dropdown = settings.parentObject local dropdown = settings.parentObject
local dropdownSettings = dropdown.settings if dropdown then
local dropdownItems = dropdown.children ---@cast dropdown Diesal.GUI.Object.DropDown
local dropdownSettings = dropdown.settings
local dropdownItems = dropdown.children
local selectedCount = 0
local selectionTable = {} local selectionTable = {}
local dropdownText local dropdownText
if not settings.clickable then if not settings.clickable then
return return
end end
if settings.key ~= "CLEAR" then if settings.key ~= "CLEAR" then
if dropdownSettings.multiSelect then if dropdownSettings.multiSelect then
self:SetSelected(not settings.selected) self:SetSelected(not settings.selected)
for i = 1, #dropdownItems do for i = 1, #dropdownItems do
if dropdownItems[i].settings.selected then if dropdownItems[i].settings.selected then
dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItems[i].settings.value) or dropdownItems[i].settings.value selectedCount = selectedCount + 1
selectionTable[#selectionTable + 1] = dropdownItems[i].settings.key 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
end else
else for i = 1, #dropdownItems do
for i = 1, #dropdownItems do if dropdownItems[i].SetSelected then
if dropdownItems[i].SetSelected then dropdownItems[i]:SetSelected(false)
dropdownItems[i]:SetSelected(false) end
end end
self:SetSelected(true)
dropdownText = settings.value
selectionTable = { settings.key }
dropdown.dropdown:Hide()
end end
self:SetSelected(true) else
dropdownText = settings.value
selectionTable = { settings.key }
dropdown.dropdown:Hide() dropdown.dropdown:Hide()
dropdown:ClearSelection()
end end
else if dropdownSettings.multiSelect then
dropdown.dropdown:Hide() dropdownText = string.format("+%d", selectedCount)
dropdown:ClearSelection() end
dropdown:SetText(dropdownText)
dropdown:FireEvent("OnValueChanged", settings.key, settings.value, selectionTable)
dropdown:FireEvent("OnValueSelected", settings.key, settings.value, selectionTable)
end end
dropdown:SetText(dropdownText)
dropdown:FireEvent("OnValueChanged", settings.key, settings.value, selectionTable)
dropdown:FireEvent("OnValueSelected", settings.key, settings.value, selectionTable)
end, end,
---@param self Diesal.GUI.Object.DropDown.Item ---@param self Diesal.GUI.Object.DropDown.Item
["SetSelected"] = function(self, selected) ["SetSelected"] = function(self, selected)
@ -125,6 +131,7 @@ local methods = {
---@field clickable boolean ---@field clickable boolean
---@field indent number ---@field indent number
---@field header boolean ---@field header boolean
---@field parentObject Diesal.GUI.Object.DropDown
---@class DiesalDropDownItem : Diesal.GUI.Object.DropDown.Item ---@class DiesalDropDownItem : Diesal.GUI.Object.DropDown.Item
@ -136,6 +143,10 @@ local function Constructor()
---@field settings Diesal.GUI.DropDownItem.Settings ---@field settings Diesal.GUI.DropDownItem.Settings
local self = DiesalGUI:Create(Type, true) local self = DiesalGUI:Create(Type, true)
local frame = CreateFrame("Button", nil, UIParent) local frame = CreateFrame("Button", nil, UIParent)
frame:SetToplevel(true)
frame:SetFrameLevel(999)
frame:SetFrameStrata("TOOLTIP")
frame:SetFixedFrameStrata(true)
self.frame = frame self.frame = frame
self.defaults = {} self.defaults = {}
-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -30,6 +30,13 @@ local ObjectBase = {
self.frame:Show() self.frame:Show()
end, 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 ---@generic T : Diesal.GUI.ObjectBase
---@param self T | Diesal.GUI.ObjectBase ---@param self T | Diesal.GUI.ObjectBase
---@param parent Frame ---@param parent Frame

@ -226,6 +226,10 @@ local function Constructor()
frame:SetScript("OnEnable", function(this) frame:SetScript("OnEnable", function(this)
self:FireEvent("OnEnable") self:FireEvent("OnEnable")
end) end)
---@param this Frame
frame:SetScript("OnShow", function(this)
this:SetFrameStrata("FULLSCREEN")
end)
fontString:SetPoint("LEFT", frame, "RIGHT", 5, 0) fontString:SetPoint("LEFT", frame, "RIGHT", 5, 0)
fontString:SetHeight(15) fontString:SetHeight(15)

Loading…
Cancel
Save