Skip to content

Commit

Permalink
Merge pull request #27 from Road-block/master
Browse files Browse the repository at this point in the history
Cleanup frame code.
  • Loading branch information
cralor authored Jun 18, 2018
2 parents 413159e + 8935003 commit becca55
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 79 deletions.
53 changes: 5 additions & 48 deletions GuideListFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions OptionsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 6 additions & 31 deletions StatusFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
15 changes: 15 additions & 0 deletions TourGuide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit becca55

Please sign in to comment.