diff --git a/Modules/Clamp/Clamp.lua b/Modules/Clamp/Clamp.lua index e14f7cd..2f2663b 100644 --- a/Modules/Clamp/Clamp.lua +++ b/Modules/Clamp/Clamp.lua @@ -1,28 +1,19 @@ -local mod = StarTip:NewModule("Fade", "AceHook-3.0") -mod.name = "Fade" +local mod = StarTip:NewModule("Clamp", "AceHook-3.0") +mod.name = "Clamp" local _G = _G local GameTooltip = _G.GameTooltip local StarTip = _G.StarTip local UnitExists = _G.UnitExists local self = mod local L = StarTip.L +local Evaluator = LibStub("LibScriptableUtilsEvaluator-1.0") local defaults = { profile = { - unitFrames = 2, - otherFrames = 1, - units = 2, - objects = 2, + script = "return 1, 1, 1, 1", } } -mod.defaults = defaults - -local choices = { - "Hide", - "Fade out" -} - local get = function(info) return self.db.profile[info[#info]] end @@ -32,42 +23,16 @@ local set = function(info, v) end local options = { - units = { - name = L["World Units"], - desc = L["What to do with tooltips for world frames"], - type = "select", - values = choices, + script = { + name = L["Script"], + desc = L["This will be ran when the tooltip shows."], + type = "input", + width = "half", + multiline = true, get = get, set = set, order = 4 }, - unitFrames = { - name = L["Unit Frames"], - desc = L["What to do with tooltips for unit frames"], - type = "select", - values = choices, - get = get, - set = set, - order = 5 - }, - otherFrames = { - name = L["Other Frames"], - desc = L["What to do with tooltips for other frames (spells, macros, items, etc..)"], - type = "select", - values = choices, - get = get, - set = set, - order = 6 - }, - objects = { - name = L["World Objects"], - desc = L["What to do with tooltips for world objects (mailboxes, portals, etc..)"], - type = "select", - values = choices, - get = get, - set = set, - order = 7 - } } function mod:OnInitialize() @@ -89,131 +54,9 @@ function mod:GetOptions() end function mod:GameTooltip_SetDefaultAnchor(this, owner) - if owner ~= UIParent and mod.isUnit then -- This is terrible. Fixes a bug, but it likely introduces another bug related to passing over unit frames. Didn't seem to bother anything in a BG test. - StarTip.tooltipMain:Hide() - end -end - --- CowTip's solution below -local updateExistenceFrame = CreateFrame("Frame") -local updateAlphaFrame = CreateFrame("Frame") - -local checkExistence = function() - if not UnitExists(StarTip.unit) and mod.isUnit then - updateExistenceFrame:SetScript("OnUpdate", nil) - local kind - if GameTooltip:GetOwner() == UIParent then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - if kind == 2 then - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - end + local cleft, cright, ctop, cbottom = Evaluator.Execute(StarTip.environment, "StarTip.Clamp", self.db.profile.script) + StarTip.tooltipMain:SetClampRectInsets(cleft or 0, cright or 0, ctop or 0, cbottom or 0) + StarTip.tooltipMain:SetClampedToScreen(true) + GameTooltip:SetClampedToScreen(true) end -local checkTooltipAlpha = function() - if GameTooltip:GetAlpha() < 1 then - updateAlphaFrame:SetScript("OnUpdate", nil) - local kind - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - if kind == 2 then - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - end -end - -function mod:OnShow() - if self.isUnit and UnitExists(StarTip.unit) then - updateExistenceFrame:SetScript("OnUpdate", checkExistence) - else - updateAlphaFrame:SetScript("OnUpdate", checkTooltipAlpha) - end -end - -function mod:OnFadeOut(this, ...) - if self.justFade then - self.justFade = nil - return true - end - local kind - if self.isUnit then - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - else - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - end - self.isUnit = false - if kind == 2 then - return true - else - self.justHide = true - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - -end - -function mod:GameTooltipHide(this, ...) - if self.justHide then - self.justHide = nil - return true - end - local kind - if self.isUnit then - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - else - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - end - self.isUnit = false - if kind == 2 then - self.justFade = true - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - return true - end -end - -function mod:SetUnit() - self.isUnit = true - updateExistenceFrame:SetScript("OnUpdate", checkExistence) -end - -function mod:SetItem() - self.isUnit = false - updateExistenceFrame:SetScript("OnUpdate", nil) -end - -function mod:SetSpell() - self.isUnit = false - updateExistenceFrame:SetScript("OnUpdate", nil) -end diff --git a/Modules/Clamp/StarTip_Clamp.lua b/Modules/Clamp/StarTip_Clamp.lua deleted file mode 100644 index e14f7cd..0000000 --- a/Modules/Clamp/StarTip_Clamp.lua +++ /dev/null @@ -1,219 +0,0 @@ -local mod = StarTip:NewModule("Fade", "AceHook-3.0") -mod.name = "Fade" -local _G = _G -local GameTooltip = _G.GameTooltip -local StarTip = _G.StarTip -local UnitExists = _G.UnitExists -local self = mod -local L = StarTip.L - -local defaults = { - profile = { - unitFrames = 2, - otherFrames = 1, - units = 2, - objects = 2, - } -} - -mod.defaults = defaults - -local choices = { - "Hide", - "Fade out" -} - -local get = function(info) - return self.db.profile[info[#info]] -end - -local set = function(info, v) - self.db.profile[info[#info]] = v -end - -local options = { - units = { - name = L["World Units"], - desc = L["What to do with tooltips for world frames"], - type = "select", - values = choices, - get = get, - set = set, - order = 4 - }, - unitFrames = { - name = L["Unit Frames"], - desc = L["What to do with tooltips for unit frames"], - type = "select", - values = choices, - get = get, - set = set, - order = 5 - }, - otherFrames = { - name = L["Other Frames"], - desc = L["What to do with tooltips for other frames (spells, macros, items, etc..)"], - type = "select", - values = choices, - get = get, - set = set, - order = 6 - }, - objects = { - name = L["World Objects"], - desc = L["What to do with tooltips for world objects (mailboxes, portals, etc..)"], - type = "select", - values = choices, - get = get, - set = set, - order = 7 - } -} - -function mod:OnInitialize() - self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults) - StarTip:SetOptionsDisabled(options, true) - self:SecureHook("GameTooltip_SetDefaultAnchor") -end - -function mod:OnEnable() - StarTip:SetOptionsDisabled(options, false) -end - -function mod:OnDisable() - StarTip:SetOptionsDisabled(options, true) -end - -function mod:GetOptions() - return options -end - -function mod:GameTooltip_SetDefaultAnchor(this, owner) - if owner ~= UIParent and mod.isUnit then -- This is terrible. Fixes a bug, but it likely introduces another bug related to passing over unit frames. Didn't seem to bother anything in a BG test. - StarTip.tooltipMain:Hide() - end -end - --- CowTip's solution below -local updateExistenceFrame = CreateFrame("Frame") -local updateAlphaFrame = CreateFrame("Frame") - -local checkExistence = function() - if not UnitExists(StarTip.unit) and mod.isUnit then - updateExistenceFrame:SetScript("OnUpdate", nil) - local kind - if GameTooltip:GetOwner() == UIParent then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - if kind == 2 then - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - end -end - -local checkTooltipAlpha = function() - if GameTooltip:GetAlpha() < 1 then - updateAlphaFrame:SetScript("OnUpdate", nil) - local kind - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - if kind == 2 then - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - end -end - -function mod:OnShow() - if self.isUnit and UnitExists(StarTip.unit) then - updateExistenceFrame:SetScript("OnUpdate", checkExistence) - else - updateAlphaFrame:SetScript("OnUpdate", checkTooltipAlpha) - end -end - -function mod:OnFadeOut(this, ...) - if self.justFade then - self.justFade = nil - return true - end - local kind - if self.isUnit then - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - else - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - end - self.isUnit = false - if kind == 2 then - return true - else - self.justHide = true - GameTooltip:Hide() - StarTip.tooltipMain:Hide() - end - -end - -function mod:GameTooltipHide(this, ...) - if self.justHide then - self.justHide = nil - return true - end - local kind - if self.isUnit then - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.units - else - kind = self.db.profile.unitFrames - end - else - if GameTooltip:IsOwned(UIParent) then - kind = self.db.profile.objects - else - kind = self.db.profile.otherFrames - end - end - self.isUnit = false - if kind == 2 then - self.justFade = true - GameTooltip:FadeOut() - StarTip.tooltipMain:FadeOut() - else - return true - end -end - -function mod:SetUnit() - self.isUnit = true - updateExistenceFrame:SetScript("OnUpdate", checkExistence) -end - -function mod:SetItem() - self.isUnit = false - updateExistenceFrame:SetScript("OnUpdate", nil) -end - -function mod:SetSpell() - self.isUnit = false - updateExistenceFrame:SetScript("OnUpdate", nil) -end diff --git a/Modules/Clamp/StarTip_Clamp.toc b/Modules/Clamp/StarTip_Clamp.toc index 09b2f3c..4690c04 100644 --- a/Modules/Clamp/StarTip_Clamp.toc +++ b/Modules/Clamp/StarTip_Clamp.toc @@ -1,5 +1,5 @@ ## Interface: 40200 -## Title: StarTip [Fade] +## Title: StarTip [Clamp] ## Notes: Tooltips from Outerspace ## Author: Starlon ## Version: 1.0 @@ -7,4 +7,4 @@ ## X-Category: Tooltip ## X-Part-Of: StarTip -Fade.lua +Clamp.lua