TourGuide - Tweaks to root out the ever-eluse chain turnin bug... guide data tweaks
[WoW-TourGuide.git] / StatusFrame.lua
blob15da329f235d92a00d00367f5ce792102f2cd84c
3 local TourGuide = TourGuide
4 local OptionHouse = DongleStub("OptionHouse-1.0")
5 local ww = WidgetWarlock
8 local function GetQuadrant(frame)
9 local x,y = frame:GetCenter()
10 if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end
11 local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT"
12 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
13 return vhalf..hhalf, vhalf, hhalf
14 end
17 local f = CreateFrame("Button", nil, UIParent)
18 f:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, -15)
19 f:SetHeight(32)
20 f:SetFrameStrata("LOW")
21 f:EnableMouse(true)
22 f:RegisterForClicks("anyUp")
23 f:SetBackdrop(ww.TooltipBorderBG)
24 f:SetBackdropColor(0,0,0,0.3)
25 f:SetBackdropBorderColor(0,0,0,0.7)
27 TourGuide:Debug(1, "Frame strata", f:GetFrameStrata())
29 local check = ww.SummonCheckBox(20, f, "LEFT", 8, 0)
30 local icon = ww.SummonTexture(f, "ARTWORK", 24, 24, nil, "LEFT", check, "RIGHT", 4, 0)
31 local text = ww.SummonFontString(f, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
32 text:SetPoint("LEFT", icon, "RIGHT", 4, 0)
34 local item = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
35 item:SetFrameStrata("LOW")
36 item:SetHeight(36)
37 item:SetWidth(36)
38 item:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, 18)
39 item:RegisterForClicks("anyUp")
40 local itemicon = ww.SummonTexture(item, "ARTWORK", 24, 24, "Interface\\Icons\\INV_Misc_Bag_08")
41 itemicon:SetAllPoints(item)
42 item:Hide()
44 local f2 = CreateFrame("Frame", nil, UIParent)
45 local f2anchor = "RIGHT"
46 f2:SetHeight(32)
47 f2:SetWidth(100)
48 local text2 = ww.SummonFontString(f2, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
49 local icon2 = ww.SummonTexture(f2, "ARTWORK", 24, 24, nil, "RIGHT", text2, "LEFT", -4, 0)
50 local check2 = ww.SummonCheckBox(20, f2, "RIGHT", icon2, "LEFT", -4, 0)
51 check2:SetChecked(true)
52 f2:Hide()
55 local elapsed, oldsize, newsize
56 f2:SetScript("OnUpdate", function(self, el)
57 elapsed = elapsed + el
58 if elapsed > 1 then
59 self:Hide()
60 icon:SetAlpha(1)
61 text:SetAlpha(1)
62 f:SetWidth(newsize)
63 else
64 self:SetPoint(f2anchor, f, f2anchor, 0, elapsed*40)
65 self:SetAlpha(1 - elapsed)
66 text:SetAlpha(elapsed)
67 icon:SetAlpha(elapsed)
68 f:SetWidth(oldsize + (newsize-oldsize)*elapsed)
69 end
70 end)
73 function TourGuide:PositionStatusFrame()
74 if self.db.profile.statusframepoint then
75 f:ClearAllPoints()
76 f:SetPoint(self.db.profile.statusframepoint, self.db.profile.statusframex, self.db.profile.statusframey)
77 end
79 if self.db.profile.itemframepoint then
80 item:ClearAllPoints()
81 item:SetPoint(self.db.profile.itemframepoint, self.db.profile.itemframex, self.db.profile.itemframey)
82 end
83 end
86 function TourGuide:SetText(i)
87 self.current = i
88 local action, quest, note, logi, complete, hasitem = self:GetObjectiveInfo(i)
90 local newtext = (quest or"???")..(note and " [?]" or "")
92 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
93 oldsize = f:GetWidth()
94 icon:SetAlpha(0)
95 text:SetAlpha(0)
96 elapsed = 0
97 f2:SetWidth(f:GetWidth())
98 f2anchor = select(3, GetQuadrant(f))
99 f2:ClearAllPoints()
100 f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
101 f2:SetAlpha(1)
102 icon2:SetTexture(icon:GetTexture())
103 text2:SetText(text:GetText())
104 f2:Show()
107 icon:SetTexture(self.icons[action])
108 text:SetText(newtext)
109 check:SetChecked(false)
110 if i == 1 then f:SetWidth(72 + text:GetWidth()) end
111 newsize = 72 + text:GetWidth()
115 local mapped = {}
116 function TourGuide:UpdateStatusFrame()
117 local nextstep
119 for i in ipairs(self.actions) do
120 local name = self.quests[i]
121 if not self.turnedin[name] and not nextstep then
122 local action, name, note, logi, complete, hasitem, turnedin, quest, useitem, optional = self:GetObjectiveInfo(i)
123 local hasuseitem = useitem and self:FindBagSlot(useitem)
124 if not nextstep then
125 local incomplete
126 if action == "ACCEPT" then incomplete = (not optional or hasitem or hasuseitem) and not logi
127 elseif action == "TURNIN" then incomplete = not optional or logi
128 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
129 else incomplete = not logi end
130 if incomplete then nextstep = i end
133 if action == "COMPLETE" and logi then
134 local j = i
135 repeat
136 action, _, _, logi, complete = self:GetObjectiveInfo(j)
137 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
138 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
139 j = j + 1
140 until action ~= "COMPLETE"
144 QuestLog_Update()
145 QuestWatch_Update()
147 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
149 if not nextstep then return end
151 self:SetText(nextstep)
152 self.current = nextstep
153 local action, quest, note, logi, complete, hasitem, turnedin, fullquest, useitem, optional = self:GetObjectiveInfo(nextstep)
156 -- TomTom coord mapping
157 if note and (TomTom or Cartographer_Waypoints) and not mapped[action..quest] then
158 mapped[action..quest] = true
159 for x,y in note:gmatch("%(([%d.]+),([%d.]+)%)") do
160 if (TomTom) then
161 TomTom:AddWaypoint(tonumber(x), tonumber(y), quest)
162 elseif (Cartographer_Waypoints) then
163 Cartographer_Waypoints:AddLHWaypoint(nil, nil, tonumber(x), tonumber(y), note)
170 local newtext = (quest or "???")..(note and " [?]" or "")
172 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
173 oldsize = f:GetWidth()
174 icon:SetAlpha(0)
175 text:SetAlpha(0)
176 elapsed = 0
177 f2:SetWidth(f:GetWidth())
178 f2anchor = select(3, GetQuadrant(f))
179 f2:ClearAllPoints()
180 f2:SetPoint(f2anchor, f,f2anchor, 0, 0)
181 f2:SetAlpha(1)
182 icon2:SetTexture(icon:GetTexture())
183 text2:SetText(text:GetText())
184 f2:Show()
187 icon:SetTexture(self.icons[action])
188 text:SetText(newtext)
189 check:SetChecked(false)
190 if not f2:IsVisible() then f:SetWidth(72 + text:GetWidth()) end
191 newsize = 72 + text:GetWidth()
193 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
194 if tex then
195 itemicon:SetTexture(tex)
196 item:SetAttribute("type1", "item")
197 item:SetAttribute("item1", "item:"..useitem)
198 item:Show()
199 else item:Hide() end
201 self:UpdateOHPanel()
205 f:SetScript("OnClick", function(self, btn)
206 if btn == "RightButton" then
207 OptionHouse:Open("Tour Guide", "Objectives")
208 else
209 local i = TourGuide:GetQuestLogIndexByName()
210 if i then SelectQuestLogEntry(i) end
211 ShowUIPanel(QuestLogFrame)
213 end)
216 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
219 item:HookScript("OnClick", function()
220 if self:GetCurrentObjectiveInfo() == "USE" then self:SetTurnedIn() end
221 end)
224 local function ShowTooltip(self)
225 local tip = TourGuide.notes[TourGuide.current]
226 if not tip then return end
228 GameTooltip:SetOwner(self, "ANCHOR_NONE")
229 local quad, vhalf, hhalf = GetQuadrant(self)
230 local anchpoint = vhalf..(hhalf == "LEFT" and "RIGHT" or "LEFT")
231 TourGuide:Debug(10, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
232 GameTooltip:SetPoint(quad, self, anchpoint)
233 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
237 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
238 f:SetScript("OnEnter", ShowTooltip)
241 local function GetUIParentAnchor(frame)
242 local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
243 local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
244 local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
245 local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
247 return vhalf..hhalf, dx, dy
251 f:RegisterForDrag("LeftButton")
252 f:SetMovable(true)
253 f:SetClampedToScreen(true)
254 f:SetScript("OnDragStart", function(frame)
255 GameTooltip:Hide()
256 frame:StartMoving()
257 end)
258 f:SetScript("OnDragStop", function(frame)
259 frame:StopMovingOrSizing()
260 TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
261 TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
262 frame:ClearAllPoints()
263 frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
264 ShowTooltip(frame)
265 end)
268 item:RegisterForDrag("LeftButton")
269 item:SetMovable(true)
270 item:SetClampedToScreen(true)
271 item:SetScript("OnDragStart", item.StartMoving)
272 item:SetScript("OnDragStop", function(frame)
273 frame:StopMovingOrSizing()
274 TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame))
275 TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame)
276 end)