diff --git a/.vscode/bookmarks.json b/.vscode/bookmarks.json new file mode 100644 index 00000000..04a08483 --- /dev/null +++ b/.vscode/bookmarks.json @@ -0,0 +1,47 @@ +[ + { + "path": "$ROOTPATH$\\WorldQuestTracker_Core.lua", + "bookmarks": [ + { + "line": 2005, + "column": 23, + "label": "" + }, + { + "line": 2040, + "column": 41, + "label": "" + }, + { + "line": 2119, + "column": 30, + "label": "" + }, + { + "line": 2205, + "column": 35, + "label": "" + }, + { + "line": 2261, + "column": 15, + "label": "" + } + ] + }, + { + "path": "$ROOTPATH$\\WorldQuestTracker_IDs.lua", + "bookmarks": [ + { + "line": 45, + "column": 0, + "label": "" + }, + { + "line": 534, + "column": 0, + "label": "" + } + ] + } +] \ No newline at end of file diff --git a/WorldQuestTracker_Core.lua b/WorldQuestTracker_Core.lua index 1f276e7a..ac513ac1 100644 --- a/WorldQuestTracker_Core.lua +++ b/WorldQuestTracker_Core.lua @@ -1995,62 +1995,69 @@ WorldQuestTracker.OnToggleWorldMap = function (self) local anchorSide = worldSummary.GetAnchorSide (true) factionAnchor:ClearAllPoints() - --set the point of the faction anchor - --[=[ this code is for anchoring in the top left or top right side, the faction anchor got moved to the bottom right with the alliance and horde buttons - if (anchorSide == "left") then - --factionAnchor:SetPoint ("topleft", worldSummary, "topleft", 2, WorldQuestTracker.db.profile.bar_anchor == "top" and -22 or 0) - - elseif (anchorSide == "right") then - --using -40 due to the search button in the topright corner - --factionAnchor:SetPoint ("topright", worldSummary, "topright", -40, WorldQuestTracker.db.profile.bar_anchor == "top" and -22 or 0) - - end - --]=] - local anchorWidth = 0 local anchorHeight = 0 + local buttonId = 1 --set the point of each individual button local widgetWidget = factionAnchor.Widgets [1]:GetWidth() + 3 for buttonIndex, factionButton in ipairs (factionAnchor.Widgets) do factionButton:ClearAllPoints() - - if (anchorSide == "left") then - if (buttonIndex == 1) then - factionButton:SetPoint ("center", factionAnchor, "topleft", 0, 0) + local mapId = WorldQuestTracker.GetCurrentMapAreaID() + local factionsOfTheMap = WorldQuestTracker.GetFactionsAllowedOnMap(mapId) + + if (factionsOfTheMap) then + if (factionsOfTheMap[factionButton.FactionID]) then --error + if (anchorSide == "left") then + if (buttonId == 1) then + factionButton:SetPoint ("center", factionAnchor, "topleft", 0, 0) + else + factionButton:SetPoint ("center", factionAnchor, "topleft", widgetWidget * (buttonId-1), 0) + end + + elseif (anchorSide == "right") then + if (buttonId == 1) then + factionButton:SetPoint ("center", factionAnchor, "topright", 0, 0) + else + factionButton:SetPoint ("center", factionAnchor, "topright", -widgetWidget * (buttonId-1), 0) + end + end - else - --factionButton:SetPoint ("topleft", factionAnchor.Widgets [buttonIndex - 1], "topright", 2, 0) - factionButton:SetPoint ("center", factionAnchor, "topleft", widgetWidget * (buttonIndex-1), 0) - end - - elseif (anchorSide == "right") then - if (buttonIndex == 1) then - factionButton:SetPoint ("center", factionAnchor, "topright", 0, 0) + anchorWidth = anchorWidth + factionButton:GetWidth() + 2 + anchorHeight = factionButton:GetHeight() + + --see the reputation amount and change the alpha + local name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild, factionID, hasBonusRepGain, canBeLFGBonus = GetFactionInfoByID (factionButton.FactionID) + local repAmount = barValue + barMax = barMax - barMin + barValue = barValue - barMin + barMin = 0 + + if (repAmount > 41900) then --exalted + factionButton:SetAlpha(1) + local currentValue, threshold, rewardQuestID, hasRewardPending, tooLowLevelForParagon = C_Reputation.GetFactionParagonInfo(factionButton.FactionID) + if (hasRewardPending) then + factionButton.paragonRewardIcon:Show() + factionButton.glowTexture:Show() + factionButton.paragonRewardIcon.glowAnimation:Play() + else + factionButton.paragonRewardIcon:Hide() + factionButton.glowTexture:Hide() + end + else + factionButton:SetAlpha(1) + end + buttonId = buttonId + 1 + factionButton:Show() else - --factionButton:SetPoint ("topright", factionAnchor.Widgets [buttonIndex - 1], "topleft", -2, 0) - factionButton:SetPoint ("center", factionAnchor, "topright", -widgetWidget * (buttonIndex-1), 0) + --this faction shouldn't show on this map + factionButton:Hide() end - - end - - anchorWidth = anchorWidth + factionButton:GetWidth() + 2 - anchorHeight = factionButton:GetHeight() - - --see the reputation amount and change the alpha - local name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild, factionID, hasBonusRepGain, canBeLFGBonus = GetFactionInfoByID (factionButton.FactionID) - local repAmount = barValue - barMax = barMax - barMin - barValue = barValue - barMin - barMin = 0 - - if (repAmount > 41900) then - factionButton:SetAlpha (.75) - --factionButton.Icon:SetDesaturated (true) else - factionButton:SetAlpha (1) - --factionButton.Icon:SetDesaturated (false) + --no faction is supported by this map + --hide all? + factionButton:Hide() end end @@ -2106,6 +2113,14 @@ WorldQuestTracker.OnToggleWorldMap = function (self) GameCooltip:AddIcon ("", 1, 1, 1, 20) GameCooltip:AddStatusBar (barValue / barMax * 100, 1, 0, 0.65, 0, 0.7, nil, {value = 100, color = {.21, .21, .21, 0.8}, texture = [[Interface\Tooltips\UI-Tooltip-Background]]}, [[Interface\Tooltips\UI-Tooltip-Background]]) + local currentValue, threshold, rewardQuestID, hasRewardPending, tooLowLevelForParagon = C_Reputation.GetFactionParagonInfo(factionID) + if (not tooLowLevelForParagon and rewardQuestID and currentValue and threshold) then + local value = currentValue % threshold + GameCooltip:AddLine ("Paragon", HIGHLIGHT_FONT_COLOR_CODE.." "..format(REPUTATION_PROGRESS_FORMAT, BreakUpLargeNumbers(value), BreakUpLargeNumbers(threshold))..FONT_COLOR_CODE_CLOSE) + GameCooltip:AddIcon ([[Interface\GossipFrame\VendorGossipIcon]], 1, 1, 20, 20, 0, 1, 0, 1) + GameCooltip:AddStatusBar (value / threshold * 100, 1, 0, 0.65, 0, 0.7, nil, {value = 100, color = {.21, .21, .21, 0.8}, texture = [[Interface\Tooltips\UI-Tooltip-Background]]}, [[Interface\Tooltips\UI-Tooltip-Background]]) + end + GameCooltip:Show() if (self.MyObject.OnLeaveAnimation:IsPlaying()) then @@ -2155,10 +2170,10 @@ WorldQuestTracker.OnToggleWorldMap = function (self) end --create buttons - for factionID, factionInfo in pairs (WorldQuestTracker.MapData.ReputationByFaction [playerFaction]) do + --for factionID, factionInfo in pairs (WorldQuestTracker.MapData.ReputationByFaction [playerFaction]) do + for factionID, _ in pairs (WorldQuestTracker.MapData.AllFactionIds) do --creates one button for each faction registered if (type (factionID) == "number") then - local name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild, factionID, hasBonusRepGain, canBeLFGBonus = GetFactionInfoByID (factionID) local factionButton = DF:CreateButton (factionAnchor, worldSummary.OnSelectFaction, 24, 24, "", factionButtonIndex) --animations @@ -2186,6 +2201,29 @@ WorldQuestTracker.OnToggleWorldMap = function (self) DF:CreateBorder (factionButton.OverlayFrame, 1, 0, 0) factionButton.OverlayFrame:SetBorderColor (1, .85, 0) factionButton.OverlayFrame:SetBorderAlpha (.843, .1, .05) + + local paragonRewardIcon = factionButton:CreateTexture(nil, "overlay") + paragonRewardIcon:SetTexture([[Interface\GossipFrame\VendorGossipIcon]]) + paragonRewardIcon:SetPoint("topright", factionButton.widget, "topright", 6, 10) + + local glowTexture = factionButton:CreateTexture(nil, "orverlay") + glowTexture:SetTexture([[Interface\PETBATTLES\PetBattle-SelectedPetGlow]]) + glowTexture:SetSize(32, 32) + glowTexture:SetPoint("center", paragonRewardIcon, "center") + factionButton.glowTexture = glowTexture + + paragonRewardIcon.glowAnimation = DF:CreateAnimationHub (glowTexture, function() end, function() end) + WorldQuestTracker:CreateAnimation(paragonRewardIcon.glowAnimation, "Alpha", 1, 0.750, 0.4, 1) + WorldQuestTracker:CreateAnimation(paragonRewardIcon.glowAnimation, "Alpha", 2, 0.750, 1, 0.4) + paragonRewardIcon.glowAnimation:SetLooping ("REPEAT") + + paragonRewardIcon.anim = paragonRewardIcon.glowAnimation + + paragonRewardIcon:SetDrawLayer("overlay", 6) + glowTexture:SetDrawLayer("overlay", 5) + + paragonRewardIcon:Hide() + factionButton.paragonRewardIcon = paragonRewardIcon local selectedBorder = factionButton:CreateTexture (nil, "overlay") selectedBorder:SetPoint ("center") @@ -2244,12 +2282,8 @@ WorldQuestTracker.OnToggleWorldMap = function (self) function worldSummary.RefreshFactionButtons() for i, factionButton in ipairs (worldSummary.FactionAnchor.Widgets) do if (factionButton.FactionID == worldSummary.FactionSelected) then - --factionButton:SetTemplate (worldSummary.FactionSelectedTemplate) - --factionButton.SelectedBorder:SetAlpha (0.55) factionButton.OverlayFrame:SetAlpha (1) else - --factionButton:SetTemplate (DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")) - --factionButton.SelectedBorder:SetAlpha (0) factionButton.OverlayFrame:SetAlpha (0) end end diff --git a/WorldQuestTracker_IDs.lua b/WorldQuestTracker_IDs.lua index a5f930ca..2928980a 100644 --- a/WorldQuestTracker_IDs.lua +++ b/WorldQuestTracker_IDs.lua @@ -435,6 +435,31 @@ WorldQuestTracker.MapData.ReputationIcons = { [2032591] = true, --7th Legion } +WorldQuestTracker.MapData.AllFactionIds = { + --BFA Factions + [2159] = true, --7th Legion + [2160] = true, --Proudmoore Admiralty + [2161] = true, --Order of Embers + [2162] = true, --Storm's Wake + [2103] = true, --Zandalari Empire + [2156] = true, --Talanji's Expedition + [2157] = true, --The Honorbound + [2158] = true, --Voldunai + [2163] = true, --Tortollan Seekers + [2164] = true, --Champions of Azeroth + + --Legion Factions + [2170] = true, --Argussian Reach + [2045] = true, --Armies of Legionfall + [2165] = true, --Army of the Light + [1900] = true, --Court of Farondis + [1883] = true, --Dreamwavers + [1828] = true, --Highmountain Tribe + [1859] = true, --The Nightfallen + [1894] = true, --The Wardens + [1948] = true, --Valarjar +} + WorldQuestTracker.MapData.FactionIcons = { --BFA [2159] = "Interface\\ICONS\\inv__faction_alliancewareffort", --7th Legion @@ -447,9 +472,88 @@ WorldQuestTracker.MapData.FactionIcons = { [2158] = "Interface\\ICONS\\inv__faction_voldunai", --Voldunai [2163] = "Interface\\ICONS\\inv__faction_tortollanseekers", --Tortollan Seekers [2164] = "Interface\\ICONS\\inv__faction_championsofazeroth", --Champions of Azeroth - + + --Legion + [2170] = "Interface\\ICONS\\INV_Legion_Faction_ArgussianReach", --Argussian Reach + [2045] = "Interface\\ICONS\\INV_Legion_Faction_Legionfall", --Armies of Legionfall + [2165] = "Interface\\ICONS\\INV_Legion_Faction_ArmyoftheLight", --Army of the Light + [1900] = "Interface\\ICONS\\INV_Legion_Faction_CourtofFarnodis", --Court of Farondis + [1883] = "Interface\\ICONS\\INV_Legion_Faction_DreamWeavers", --Dreamwavers + [1828] = "Interface\\ICONS\\INV_Legion_Faction_HightmountainTribes", --Highmountain Tribe + [1859] = "Interface\\ICONS\\INV_Legion_Faction_NightFallen", --The Nightfallen + [1894] = "Interface\\ICONS\\INV_Legion_Faction_Warden", --The Wardens + [1948] = "Interface\\ICONS\\INV_Legion_Faction_Valarjar", --Valarjar +-- /run for i =1, 3000 do local N={GetFactionInfoByID(i)}if(N[1])then print(N[1].." "..N[14])end end +} + +local BFAFactions = { + ["Alliance"] = { + [2159] = true, --7th Legion + [2160] = true, --Proudmoore Admiralty + [2161] = true, --Order of Embers + [2162] = true, --Storm's Wake + [2400] = true, --Waveblade Ankoan + + [2163] = true, --Tortollan Seekers + [2164] = true, --Champions of Azeroth + [2417] = true, --Uldum Accord + [2415] = true, --Rajani + [2391] = true, --Rustbolt Resistance + }, + + ["Horde"] = { + --BFA + [2103] = true, --Zandalari Empire + [2156] = true, --Talanji's Expedition + [2157] = true, --The Honorbound + [2158] = true, --Voldunai + [2373] = true, --The Unshackled + + [2163] = true, --Tortollan Seekers + [2164] = true, --Champions of Azeroth + [2417] = true, --Uldum Accord + [2415] = true, --Rajani + [2391] = true, --Rustbolt Resistance + } +} + +local LegionFactions = { + [2170] = true, --Argussian Reach + [2045] = true, --Armies of Legionfall + [2165] = true, --Army of the Light + [1900] = true, --Court of Farondis + [1883] = true, --Dreamwavers + [1828] = true, --Highmountain Tribe + [1859] = true, --The Nightfallen + [1894] = true, --The Wardens + [1948] = true, --Valarjar } +--what are the factionIds que belong to the map +WorldQuestTracker.MapData.ReputationByMap = { + [WorldQuestTracker.MapData.ZoneIDs.BROKENISLES] = LegionFactions, + [WorldQuestTracker.MapData.ZoneIDs.ARGUS] = LegionFactions, + [WorldQuestTracker.MapData.ZoneIDs.KULTIRAS] = BFAFactions, + [WorldQuestTracker.MapData.ZoneIDs.ZANDALAR] = BFAFactions, + [WorldQuestTracker.MapData.ZoneIDs.AZEROTH] = BFAFactions, +} + +function WorldQuestTracker.GetFactionsAllowedOnMap(mapId) + local factionIdList = WorldQuestTracker.MapData.ReputationByMap[mapId] + if (not factionIdList) then + return + end + + if (factionIdList.Horde and factionIdList.Alliance) then + local playerFactionGroup = UnitFactionGroup("player") + local list = factionIdList[playerFactionGroup] + return list + + else + return factionIdList + end +end + --reputation IDs for each faction -- UnitFactionGroup ("player") --/run for i = 1, 5000 do local name = GetFactionInfoByID (i) if(name)then print (i,name) end end WorldQuestTracker.MapData.ReputationByFaction = { @@ -467,8 +571,31 @@ WorldQuestTracker.MapData.ReputationByFaction = { [GetFactionInfoByID (2162) or "NotFound"] = 2162, --Storm's Wake [GetFactionInfoByID (2163) or "NotFound"] = 2163, --Tortollan Seekers [GetFactionInfoByID (2164) or "NotFound"] = 2164, --Champions of Azeroth + + --Legion + [2170] = GetFactionInfoByID (2170), --Argussian Reach + [2045] = GetFactionInfoByID (2045), --Armies of Legionfall + [2165] = GetFactionInfoByID (2165), --Army of the Light + --[2135] = GetFactionInfoByID (2135), --Chromie + [1900] = GetFactionInfoByID (1900), --Court of Farondis + [1883] = GetFactionInfoByID (1883), --Dreamwavers + [1828] = GetFactionInfoByID (1828), --Highmountain Tribe + [1859] = GetFactionInfoByID (1859), --The Nightfallen + [1894] = GetFactionInfoByID (1894), --The Wardens + [1948] = GetFactionInfoByID (1948), --Valarjar + [GetFactionInfoByID (2170) or "NotFound"] = 2170, --Argussian Reach + [GetFactionInfoByID (2045) or "NotFound"] = 2045, --Armies of Legionfall + [GetFactionInfoByID (2165) or "NotFound"] = 2165, --Army of the Light + --[GetFactionInfoByID (2135) or "NotFound"] = 2135, --Chromie + [GetFactionInfoByID (1900) or "NotFound"] = 1900, --Court of Farondis + [GetFactionInfoByID (1883) or "NotFound"] = 1883, --Dreamwavers + [GetFactionInfoByID (1828) or "NotFound"] = 1828, --Highmountain Tribe + [GetFactionInfoByID (1859) or "NotFound"] = 1859, --The Nightfallen + [GetFactionInfoByID (1894) or "NotFound"] = 1894, --The Wardens + [GetFactionInfoByID (1948) or "NotFound"] = 1948, --Valarjar }, - + --Legion + ["Horde"] = { --BFA [2103] = GetFactionInfoByID (2103), --Zandalari Empire @@ -483,6 +610,28 @@ WorldQuestTracker.MapData.ReputationByFaction = { [GetFactionInfoByID (2158) or "NotFound"] = 2158, --Voldunai [GetFactionInfoByID (2163) or "NotFound"] = 2163, --Tortollan Seekers [GetFactionInfoByID (2164) or "NotFound"] = 2164, --Champions of Azeroth + + --Legion + [2170] = GetFactionInfoByID (2170), --Argussian Reach + [2045] = GetFactionInfoByID (2045), --Armies of Legionfall + [2165] = GetFactionInfoByID (2165), --Army of the Light + --[2135] = GetFactionInfoByID (2135), --Chromie + [1900] = GetFactionInfoByID (1900), --Court of Farondis + [1883] = GetFactionInfoByID (1883), --Dreamwavers + [1828] = GetFactionInfoByID (1828), --Highmountain Tribe + [1859] = GetFactionInfoByID (1859), --The Nightfallen + [1894] = GetFactionInfoByID (1894), --The Wardens + [1948] = GetFactionInfoByID (1948), --Valarjar + [GetFactionInfoByID (2170) or "NotFound"] = 2170, --Argussian Reach + [GetFactionInfoByID (2045) or "NotFound"] = 2045, --Armies of Legionfall + [GetFactionInfoByID (2165) or "NotFound"] = 2165, --Army of the Light + --[GetFactionInfoByID (2135) or "NotFound"] = 2135, --Chromie + [GetFactionInfoByID (1900) or "NotFound"] = 1900, --Court of Farondis + [GetFactionInfoByID (1883) or "NotFound"] = 1883, --Dreamwavers + [GetFactionInfoByID (1828) or "NotFound"] = 1828, --Highmountain Tribe + [GetFactionInfoByID (1859) or "NotFound"] = 1859, --The Nightfallen + [GetFactionInfoByID (1894) or "NotFound"] = 1894, --The Wardens + [GetFactionInfoByID (1948) or "NotFound"] = 1948, --Valarjar }, } diff --git a/libs/DF/button.lua b/libs/DF/button.lua index dd69d21e..9839b6e8 100644 --- a/libs/DF/button.lua +++ b/libs/DF/button.lua @@ -21,6 +21,8 @@ do local metaPrototype = { WidgetType = "button", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, } diff --git a/libs/DF/fw.lua b/libs/DF/fw.lua index c77e8fd5..fd83163a 100644 --- a/libs/DF/fw.lua +++ b/libs/DF/fw.lua @@ -1,5 +1,5 @@ -local dversion = 176 +local dversion = 178 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary (major, minor) @@ -19,6 +19,7 @@ local upper = string.upper local string_match = string.match local tinsert = _G.tinsert local abs = _G.abs +local tremove = _G.tremove local UnitPlayerControlled = UnitPlayerControlled local UnitIsTapDenied = UnitIsTapDenied @@ -934,9 +935,15 @@ end ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --> menus + + local disable_on_combat = {} + local getMenuWidgetVolative = function(parent, widgetType, indexTable) + + local widget + if (widgetType == "label") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then widget = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType], "overlay") tinsert(parent.widget_list, widget) @@ -944,10 +951,9 @@ end end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "dropdown") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then widget = DF:CreateDropDown (parent, function() return {} end, nil, 140, 18, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) @@ -961,42 +967,97 @@ end end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "switch") then - local widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] if (not widget) then - local widget = DF:CreateSwitch (parent, nil, true, 20, 20, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget = DF:CreateSwitch (parent, nil, true, 20, 20, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") tinsert(parent.widget_list, widget) tinsert(parent.widget_list_by_type[widgetType], widget) else widget:ClearHooks() - end indexTable[widgetType] = indexTable[widgetType] + 1 - return widget elseif (widgetType == "slider") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateSlider (parent, 140, 20, 1, 2, 1, 1, false, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "color") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateColorPickButton (parent, "$parentWidget" .. widgetType .. indexTable[widgetType], nil, function()end, 1) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "button") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateButton (parent, function()end, 120, 18, "", nil, nil, nil, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 elseif (widgetType == "textentry") then + widget = parent.widget_list_by_type[widgetType][indexTable[widgetType]] + + if (not widget) then + widget = DF:CreateTextEntry (parent, function()end, 120, 18, nil, "$parentWidget" .. widgetType .. indexTable[widgetType]) + widget.hasLabel = DF:CreateLabel (parent, "", 10, "white", "", nil, "$parentWidget" .. widgetType .. indexTable[widgetType] .. "label", "overlay") + + tinsert(parent.widget_list, widget) + tinsert(parent.widget_list_by_type[widgetType], widget) + else + widget:ClearHooks() + end + + indexTable[widgetType] = indexTable[widgetType] + 1 + end - + --if the widget is inside the no combat table, remove it + for i = 1, #disable_on_combat do + if (disable_on_combat[i] == widget) then + tremove(disable_on_combat, i) + break + end end + + return widget end --volatile menu can be called several times, each time all settings are reset and a new menu is built using the same widgets function DF:BuildMenuVolatile (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template, value_change_hook) + if (not parent.widget_list) then DF:SetAsOptionsPanel (parent) end @@ -1021,128 +1082,334 @@ end for index, widget_table in ipairs(menu) do - --step a line - if (widget_table.type == "blank" or widget_table.type == "space") then - -- do nothing + if (not widget_table.novolatile) then - elseif (widget_table.type == "label" or widget_table.type == "text") then + --step a line + if (widget_table.type == "blank" or widget_table.type == "space") then + -- do nothing - local label = getMenuWidgetVolative(parent, "label", widgetIndexes) + elseif (widget_table.type == "label" or widget_table.type == "text") then - label.text = widget_table.get() or widget_table.text or "" - label.color = widget_table.color - label.fontface = widget_table.font + local label = getMenuWidgetVolative(parent, "label", widgetIndexes) + widget_created = label - if (widget_table.text_template or text_template) then - label:SetTemplate(widget_table.text_template or text_template) - else - label.fontsize = widget_table.size or 10 - end + label.text = widget_table.get() or widget_table.text or "" + label.color = widget_table.color + label.fontface = widget_table.font - label._get = widget_table.get - label.widget_type = "label" - label:ClearAllPoints() - label:SetPoint (cur_x, cur_y) + if (widget_table.text_template or text_template) then + label:SetTemplate(widget_table.text_template or text_template) + else + label.fontsize = widget_table.size or 10 + end - if (widget_table.id) then - parent.widgetids [widget_table.id] = label - end + label._get = widget_table.get + label.widget_type = "label" + label:ClearAllPoints() + label:SetPoint (cur_x, cur_y) - --dropdowns - elseif (widget_table.type == "select" or widget_table.type == "dropdown") then + if (widget_table.id) then + parent.widgetids [widget_table.id] = label + end - local dropdown = getMenuWidgetVolative(parent, "dropdown", widgetIndexes) - dropdown:SetFunction(widget_table.values) - dropdown:Refresh() - dropdown:Select (widget_table.get()) - dropdown:SetTemplate (dropdown_template) + --dropdowns + elseif (widget_table.type == "select" or widget_table.type == "dropdown") then - dropdown.tooltip = widget_table.desc - dropdown._get = widget_table.get - dropdown.widget_type = "select" + local dropdown = getMenuWidgetVolative(parent, "dropdown", widgetIndexes) + widget_created = dropdown + dropdown:SetFunction(widget_table.values) + dropdown:Refresh() + dropdown:Select (widget_table.get()) + dropdown:SetTemplate (dropdown_template) - dropdown.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") - dropdown.hasLabel:SetTemplate(widget_table.text_template or text_template) - dropdown:ClearAllPoints() - dropdown:SetPoint ("left", dropdown.hasLabel, "right", 2) - dropdown.hasLabel:ClearAllPoints() - dropdown.hasLabel:SetPoint (cur_x, cur_y) + dropdown.tooltip = widget_table.desc + dropdown._get = widget_table.get + dropdown.widget_type = "select" - --> global callback - if (value_change_hook) then - dropdown:SetHook ("OnOptionSelected", value_change_hook) - end - - --> hook list (hook list is wiped when getting the widget) - if (widget_table.hooks) then - for hookName, hookFunc in pairs (widget_table.hooks) do - dropdown:SetHook (hookName, hookFunc) + + dropdown.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + dropdown.hasLabel:SetTemplate(widget_table.text_template or text_template) + dropdown:ClearAllPoints() + dropdown:SetPoint ("left", dropdown.hasLabel, "right", 2) + dropdown.hasLabel:ClearAllPoints() + dropdown.hasLabel:SetPoint (cur_x, cur_y) + + --> global callback + if (value_change_hook) then + dropdown:SetHook ("OnOptionSelected", value_change_hook) + end + + --> hook list (hook list is wiped when getting the widget) + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + dropdown:SetHook (hookName, hookFunc) + end end - end - if (widget_table.id) then - parent.widgetids [widget_table.id] = dropdown - end - - local size = dropdown.hasLabel.widget:GetStringWidth() + 140 + 4 - if (size > max_x) then - max_x = size - end + if (widget_table.id) then + parent.widgetids [widget_table.id] = dropdown + end + + local size = dropdown.hasLabel.widget:GetStringWidth() + 140 + 4 + if (size > max_x) then + max_x = size + end - --switchs - elseif (widget_table.type == "toggle" or widget_table.type == "switch") then + --switchs + elseif (widget_table.type == "toggle" or widget_table.type == "switch") then - local switch = getMenuWidgetVolative(parent, "switch", widgetIndexes) + local switch = getMenuWidgetVolative(parent, "switch", widgetIndexes) + widget_created = switch - switch:SetValue(widget_table.get()) - switch:SetTemplate(switch_template) - switch:SetAsCheckBox() --it's always a checkbox on volatile menu + switch:SetValue(widget_table.get()) + switch:SetTemplate(switch_template) + switch:SetAsCheckBox() --it's always a checkbox on volatile menu - switch.tooltip = widget_table.desc - switch._get = widget_table.get - switch.widget_type = "toggle" - switch.OnSwitch = widget_table.set - - if (value_change_hook) then - switch:SetHook ("OnSwitch", value_change_hook) - end - - --> hook list - if (widget_table.hooks) then - for hookName, hookFunc in pairs (widget_table.hooks) do - switch:SetHook (hookName, hookFunc) + switch.tooltip = widget_table.desc + switch._get = widget_table.get + switch.widget_type = "toggle" + switch.OnSwitch = widget_table.set + + if (value_change_hook) then + switch:SetHook ("OnSwitch", value_change_hook) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + switch:SetHook (hookName, hookFunc) + end end - end - switch.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") - switch.hasLabel:SetTemplate(widget_table.text_template or text_template) + switch.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + switch.hasLabel:SetTemplate(widget_table.text_template or text_template) - switch:ClearAllPoints() - switch.hasLabel:ClearAllPoints() + switch:ClearAllPoints() + switch.hasLabel:ClearAllPoints() - if (widget_table.boxfirst) then - switch:SetPoint (cur_x, cur_y) - switch.hasLabel:SetPoint ("left", switch, "right", 2) - else - switch.hasLabel:SetPoint (cur_x, cur_y) - switch:SetPoint ("left", switch.hasLabel, "right", 2) - end + if (widget_table.boxfirst) then + switch:SetPoint (cur_x, cur_y) + switch.hasLabel:SetPoint ("left", switch, "right", 2) + else + switch.hasLabel:SetPoint (cur_x, cur_y) + switch:SetPoint ("left", switch.hasLabel, "right", 2) + end - if (widget_table.id) then - parent.widgetids [widget_table.id] = switch + if (widget_table.id) then + parent.widgetids [widget_table.id] = switch + end + + local size = switch.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + --slider + elseif (widget_table.type == "range" or widget_table.type == "slider") then + + local slider = getMenuWidgetVolative(parent, "slider", widgetIndexes) + widget_created = slider + + slider.slider:SetMinMaxValues (widget_table.min, widget_table.max) + slider.slider:SetValue (widget_table.get()) + slider.ivalue = slider.slider:GetValue() + + if (widget_table.usedecimals) then + slider.slider:SetValueStep (0.01) + else + slider.slider:SetValueStep (widget_table.step) + end + + slider:SetTemplate(slider_template) + + slider.tooltip = widget_table.desc + slider._get = widget_table.get + slider.widget_type = "range" + slider:SetHook ("OnValueChange", widget_table.set) + + if (value_change_hook) then + slider:SetHook ("OnValueChange", value_change_hook) + end + + if (widget_table.thumbscale) then + slider:SetThumbSize (slider.thumb.originalWidth * widget_table.thumbscale, nil) + else + slider:SetThumbSize (slider.thumb.originalWidth * 1.3, nil) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + slider:SetHook (hookName, hookFunc) + end + end + + slider.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + slider.hasLabel:SetTemplate(widget_table.text_template or text_template) + + slider:SetPoint ("left", slider.hasLabel, "right", 2) + slider.hasLabel:SetPoint (cur_x, cur_y) + + if (widget_table.id) then + parent.widgetids [widget_table.id] = slider + end + + local size = slider.hasLabel:GetStringWidth() + 140 + 6 + if (size > max_x) then + max_x = size + end + + --color + elseif (widget_table.type == "color" or widget_table.type == "color") then + + local colorpick = getMenuWidgetVolative(parent, "color", widgetIndexes) + widget_created = colorpick + + colorpick.color_callback = widget_table.set --callback + colorpick:SetTemplate(button_template) + + colorpick.tooltip = widget_table.desc + colorpick._get = widget_table.get + colorpick.widget_type = "color" + + local default_value, g, b, a = widget_table.get() + if (type (default_value) == "table") then + colorpick:SetColor (unpack (default_value)) + else + colorpick:SetColor (default_value, g, b, a) + end + + if (value_change_hook) then + colorpick:SetHook ("OnColorChanged", value_change_hook) + end + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + colorpick:SetHook (hookName, hookFunc) + end + end + + colorpick.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + colorpick.hasLabel:SetTemplate(widget_table.text_template or text_template) + + colorpick:SetPoint ("left", colorpick.hasLabel, "right", 2) + colorpick.hasLabel:SetPoint (cur_x, cur_y) + + if (widget_table.id) then + parent.widgetids [widget_table.id] = colorpick + end + + local size = colorpick.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + --button + elseif (widget_table.type == "execute" or widget_table.type == "button") then + + local button = getMenuWidgetVolative(parent, "button", widgetIndexes) + widget_created = button + + button:SetTemplate(button_template) + button:SetSize(widget_table.width or 120, widget_table.height or 18) + button:SetClickFunction(widget_table.func, widget_table.param1, widget_table.param2) + + local textTemplate = widget_table.text_template or text_template or DF.font_templates ["ORANGE_FONT_TEMPLATE"] + button.textcolor = textTemplate.color + button.textfont = textTemplate.font + button.textsize = textTemplate.size + button.text = widget_table.name + + button:SetPoint (cur_x, cur_y) + button.tooltip = widget_table.desc + button.widget_type = "execute" + + --> execute doesn't trigger global callback + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + button:SetHook (hookName, hookFunc) + end + end + + if (widget_table.id) then + parent.widgetids [widget_table.id] = button + end + + local size = button:GetWidth() + 4 + if (size > max_x) then + max_x = size + end + + --textentry + elseif (widget_table.type == "textentry") then + + local textentry = getMenuWidgetVolative(parent, "textentry", widgetIndexes) + widget_created = textentry + + textentry:SetCommitFunction(widget_table.func) + textentry:SetTemplate(widget_table.template or widget_table.button_template or button_template) + textentry:SetSize(widget_table.width or 120, widget_table.height or 18) + + textentry.tooltip = widget_table.desc + textentry.text = widget_table.get() + textentry._get = widget_table.get + textentry.widget_type = "textentry" + textentry:SetHook ("OnEnterPressed", widget_table.set) + textentry:SetHook ("OnEditFocusLost", widget_table.set) + + textentry.hasLabel.text = widget_table.name .. (use_two_points and ": " or "") + textentry.hasLabel:SetTemplate(widget_table.text_template or text_template) + textentry:SetPoint ("left", textentry.hasLabel, "right", 2) + textentry.hasLabel:SetPoint (cur_x, cur_y) + + --> text entry doesn't trigger global callback + + --> hook list + if (widget_table.hooks) then + for hookName, hookFunc in pairs (widget_table.hooks) do + textentry:SetHook (hookName, hookFunc) + end + end + + if (widget_table.id) then + parent.widgetids [widget_table.id] = textentry + end + + local size = textentry.hasLabel:GetStringWidth() + 60 + 4 + if (size > max_x) then + max_x = size + end + + end --end loop + + if (widget_table.nocombat) then + tinsert (disable_on_combat, widget_created) + end + + if (widget_table.spacement) then + cur_y = cur_y - 30 + else + cur_y = cur_y - 20 end - local size = switch.hasLabel:GetStringWidth() + 60 + 4 - if (size > max_x) then - max_x = size + if (widget_table.type == "breakline" or cur_y < height) then + cur_y = y_offset + cur_x = cur_x + max_x + 30 + line_widgets_created = 0 + max_x = 0 end + + widget_created:Show() end end + + DF.RefreshUnsafeOptionsWidgets() end - local disable_on_combat = {} - function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points, text_template, dropdown_template, switch_template, switch_is_box, slider_template, button_template, value_change_hook) if (not parent.widget_list) then diff --git a/libs/DF/label.lua b/libs/DF/label.lua index 8441960f..bba5c41b 100644 --- a/libs/DF/label.lua +++ b/libs/DF/label.lua @@ -288,7 +288,7 @@ function DF:NewLabel (parent, container, name, member, text, font, size, color, container = container.widget end - font = font or "GameFontHighlightSmall" + font = font == "" and "GameFontHighlightSmall" or font or "GameFontHighlightSmall" LabelObject.label = parent:CreateFontString (name, layer or "OVERLAY", font) LabelObject.widget = LabelObject.label diff --git a/libs/DF/slider.lua b/libs/DF/slider.lua index bd8719d9..1555028c 100644 --- a/libs/DF/slider.lua +++ b/libs/DF/slider.lua @@ -22,7 +22,10 @@ do local metaPrototype = { WidgetType = "slider", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, + } _G [DF.GlobalWidgetControlNames ["slider"]] = _G [DF.GlobalWidgetControlNames ["slider"]] or metaPrototype @@ -1177,6 +1180,8 @@ function DF:NewSlider (parent, container, name, member, w, h, min, max, step, de SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork") SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob") SliderObject.thumb:SetSize (30+(h*0.2), h*1.2) + SliderObject.thumb.originalWidth = SliderObject.thumb:GetWidth() + SliderObject.thumb.originalHeight =SliderObject.thumb:GetHeight() SliderObject.thumb:SetAlpha (0.7) SliderObject.slider:SetThumbTexture (SliderObject.thumb) SliderObject.slider.thumb = SliderObject.thumb diff --git a/libs/DF/textentry.lua b/libs/DF/textentry.lua index 0bfcf45a..fd289be9 100644 --- a/libs/DF/textentry.lua +++ b/libs/DF/textentry.lua @@ -22,6 +22,8 @@ do local metaPrototype = { WidgetType = "textentry", SetHook = DF.SetHook, + HasHook = DF.HasHook, + ClearHooks = DF.ClearHooks, RunHooksForWidget = DF.RunHooksForWidget, } @@ -304,6 +306,12 @@ DF.TextEntryCounter = DF.TextEntryCounter or 1 end end end + + function TextEntryMetaFunctions:SetCommitFunction(func) + if (type(func) == "function") then + self.func = func + end + end ------------------------------------------------------------------------------------------------------------ --> scripts and hooks