From 89350039ad99359005b5e60f0a04b59415f1dd2f Mon Sep 17 00:00:00 2001 From: Road-block Date: Mon, 18 Jun 2018 13:27:52 +0300 Subject: [PATCH] Cleanup frame code. Hide all child frames of the status frame when dragging to have consistent behavior. Fixes #18 as well as similar issues with the options frame and title. --- GuideListFrame.lua | 53 +++++----------------------------------------- OptionsFrame.lua | 12 +++++++++++ StatusFrame.lua | 37 ++++++-------------------------- TourGuide.lua | 15 +++++++++++++ 4 files changed, 38 insertions(+), 79 deletions(-) diff --git a/GuideListFrame.lua b/GuideListFrame.lua index 7bdfbcc..938d8b7 100644 --- a/GuideListFrame.lua +++ b/GuideListFrame.lua @@ -63,7 +63,7 @@ local closebutton = CreateFrame("Button", nil, frame, "UIPanelCloseButton") closebutton:SetPoint("TOPRIGHT", frame, "TOPRIGHT") frame.closebutton = closebutton -local title = ww.SummonFontString(frame, nil, "SubZoneTextFont", nil, "BOTTOMLEFT", frame, "TOPLEFT", 5, 0) +local title = ww.SummonFontString(frame, nil, "SubZoneTextFont", nil, "BOTTOM", frame, "TOP") local fontname, fontheight, fontflags = title:GetFont() title:SetFont(fontname, 18, fontflags) title:SetText("Guide List") @@ -101,8 +101,11 @@ frame.title = title rows[i] = row end ---frame:SetScript("OnShow", OnShow) frame:SetScript("OnShow", function() + local quad, vhalf, hhalf = TourGuide.GetQuadrant(TourGuide.statusframe) + local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf + this:ClearAllPoints() + this:SetPoint(quad, TourGuide.statusframe, anchpoint) TourGuide:UpdateGuideListPanel() this:SetAlpha(0) this:SetScript("OnUpdate", ww.FadeIn) @@ -120,52 +123,6 @@ end) ww.SetFadeTime(frame, 0.7) table.insert(UISpecialFrames, "TourGuideGuideList") ---[[ -function TourGuide:CreateGuideListPanel() - frame = CreateFrame("Frame", nil, UIParent) - rows = {} - for i=1,NUMROWS*3 do - local anchor, point = rows[i-1], "BOTTOMLEFT" - if i == 1 then anchor, point = frame, "TOPLEFT" - elseif i == (NUMROWS + 1) then anchor, point = rows[1], "TOPRIGHT" - elseif i == (NUMROWS*2 + 1) then anchor, point = rows[NUMROWS + 1], "TOPRIGHT" end - - local row = CreateFrame("CheckButton", nil, frame) - row:SetPoint("TOPLEFT", anchor, point) - row:SetHeight(ROWHEIGHT) - row:SetWidth(COLWIDTH) - - local highlight = ww.SummonTexture(row, nil, nil, nil, "Interface\\HelpFrame\\HelpFrameButton-Highlight") - highlight:SetTexCoord(0, 1, 0, 0.578125) - highlight:SetAllPoints() - row:SetHighlightTexture(highlight) - row:SetCheckedTexture(highlight) - - local text = ww.SummonFontString(row, nil, "GameFontWhite", nil, "LEFT", 6, 0) - - --row:SetScript("OnClick", OnClick) - row:SetScript("OnEnter", ShowTooltip) - row:SetScript("OnLeave", HideTooltip) - - row.text = text - rows[i] = row - end - - frame:EnableMouseWheel() - frame:SetScript("OnMouseWheel", function() - local f,val = this,arg1 - offset = offset - val*NUMROWS - if (offset + NUMROWS*2) > table.getn(self.guidelistframe) then offset = offset - NUMROWS end - if offset < 0 then offset = 0 end - self:UpdateGuidePanel() - end) - - frame:SetScript("OnShow", OnShow) - ww.SetFadeTime(frame, 0.5) - OnShow(frame) - return frame -end -]] function TourGuide:UpdateGuideListPanel() if not frame or not frame:IsVisible() then return end diff --git a/OptionsFrame.lua b/OptionsFrame.lua index 80d10dd..2477245 100644 --- a/OptionsFrame.lua +++ b/OptionsFrame.lua @@ -21,6 +21,18 @@ frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 0.5) frame:Hide() frame:SetScript("OnShow", function() + local quad, vhalf, hhalf = TourGuide.GetQuadrant(TourGuide.statusframe) + local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf + this:ClearAllPoints() + this:SetPoint(quad, TourGuide.statusframe, anchpoint) + local title_point,title_anchor,title_x,title_y + if quad == "TOPLEFT" then + title_point,title_anchor,title_x,title_y = "BOTTOMRIGHT", "TOPRIGHT", -5, 0 + else + title_point,title_anchor,title_x,title_y = "BOTTOMLEFT", "TOPLEFT", 5, 0 + end + title:ClearAllPoints() + title:SetPoint(title_point,this,title_anchor,title_x,title_y) this:SetAlpha(0) this:SetScript("OnUpdate", ww.FadeIn) end) diff --git a/StatusFrame.lua b/StatusFrame.lua index 82ba522..eec6fae 100644 --- a/StatusFrame.lua +++ b/StatusFrame.lua @@ -13,16 +13,6 @@ local FIXEDWIDTH = ICONSIZE + CHECKSIZE + GAP*4 - 4 local TourGuide = TourGuide local ww = WidgetWarlock - -local function GetQuadrant(frame) - local x,y = frame:GetCenter() - if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end - local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT" - local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" - return vhalf..hhalf, vhalf, hhalf -end - - local f = CreateFrame("Button", nil, UIParent) TourGuide.statusframe = f f:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", -60, -15) @@ -104,7 +94,7 @@ function TourGuide:SetText(i) text:SetAlpha(0) elapsed = 0 f2:SetWidth(f:GetWidth()) - f2anchor = select(3, GetQuadrant(f)) + f2anchor = select(3, self.GetQuadrant(f)) f2:ClearAllPoints() f2:SetPoint(f2anchor, f, f2anchor, 0, 0) f2:SetAlpha(1) @@ -224,7 +214,7 @@ function TourGuide:UpdateStatusFrame() text:SetAlpha(0) elapsed = 0 f2:SetWidth(f:GetWidth()) - f2anchor = select(3, GetQuadrant(f)) + f2anchor = select(3, self.GetQuadrant(f)) f2:ClearAllPoints() f2:SetPoint(f2anchor, f, f2anchor, 0, 0) f2:SetAlpha(1) @@ -252,9 +242,6 @@ end function TourGuide:PLAYER_REGEN_ENABLED() if tex then itemicon:SetTexture(tex) - -- SetAttribute applies only to SecureFrames, not in Vanilla yet... - --item:SetAttribute("type1", "item") - --item:SetAttribute("item1", "item:"..uitem) item:Show() tex = nil else item:Hide() end @@ -271,7 +258,7 @@ f:SetScript("OnClick", function() if TourGuide.objectiveframe:IsVisible() then HideUIPanel(TourGuide.objectiveframe) else - local quad, vhalf, hhalf = GetQuadrant(self) + local quad, vhalf, hhalf = TourGuide.GetQuadrant(self) local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf TourGuide.objectiveframe:ClearAllPoints() TourGuide.objectiveframe:SetPoint(quad, self, anchpoint) @@ -303,7 +290,7 @@ local function ShowTooltip() local tip = TourGuide:GetObjectiveTag("N") if not tip or tip == "" then return end tip = tostring(tip) - local quad, vhalf, hhalf = GetQuadrant(self) + local quad, vhalf, hhalf = TourGuide.GetQuadrant(self) --local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf local anchpoint = "ANCHOR_TOP"..hhalf TourGuide:Debug(11, "Setting tooltip anchor", anchpoint) @@ -321,32 +308,22 @@ end f:SetScript("OnLeave", HideTooltip) f:SetScript("OnEnter", ShowTooltip) - -local function GetUIParentAnchor(frame) - local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter() - local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM" - local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5) - local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5) - return vhalf..hhalf, dx, dy -end - - f:RegisterForDrag("LeftButton") f:SetMovable(true) f:SetClampedToScreen(true) f:SetScript("OnDragStart", function() local frame = this if TourGuide.objectiveframe:IsVisible() then HideUIPanel(TourGuide.objectiveframe) end + if TourGuide.optionsframe:IsVisible() then HideUIPanel(TourGuide.optionsframe) end + if TourGuide.guidelistframe:IsVisible() then HideUIPanel(TourGuide.guidelistframe) end GameTooltip:Hide() frame:StartMoving() end) f:SetScript("OnDragStop", function() local frame = this frame:StopMovingOrSizing() - TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame)) local _ TourGuide.db.profile.statusframepoint, _, _, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = frame:GetPoint() - --TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame) frame:ClearAllPoints() frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey) ShowTooltip(frame) @@ -360,8 +337,6 @@ item:SetScript("OnDragStart", function() local frame = this frame:StartMoving() item:SetScript("OnDragStop", function() local frame = this frame:StopMovingOrSizing() - TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame)) local _ TourGuide.db.profile.itemframepoint, _, _, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = frame:GetPoint() - --TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame) end) diff --git a/TourGuide.lua b/TourGuide.lua index c77770f..e05680f 100644 --- a/TourGuide.lua +++ b/TourGuide.lua @@ -239,6 +239,21 @@ function TourGuide.ColorGradient(perc) return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc end +function TourGuide.GetQuadrant(frame) + local x,y = frame:GetCenter() + if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end + local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT" + local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM" + return vhalf..hhalf, vhalf, hhalf +end + +function TourGuide.GetUIParentAnchor(frame) + local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter() + local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM" + local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5) + local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5) + return vhalf..hhalf, dx, dy +end function TourGuide:DumpLoc() if IsShiftKeyDown() then