TourGuide
[WoW-TourGuide.git] / StatusFrame.lua
blob1ec7788d5450301f9c5e5e14b31994a4384ff222
3 local TourGuide = TourGuide
4 local OptionHouse = LibStub("OptionHouse-1.1")
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 local check = ww.SummonCheckBox(20, f, "LEFT", 8, 0)
28 local icon = ww.SummonTexture(f, "ARTWORK", 24, 24, nil, "LEFT", check, "RIGHT", 4, 0)
29 local text = ww.SummonFontString(f, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
30 text:SetPoint("LEFT", icon, "RIGHT", 4, 0)
32 local item = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
33 item:SetFrameStrata("LOW")
34 item:SetHeight(36)
35 item:SetWidth(36)
36 item:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, 18)
37 item:RegisterForClicks("anyUp")
38 local itemicon = ww.SummonTexture(item, "ARTWORK", 24, 24, "Interface\\Icons\\INV_Misc_Bag_08")
39 itemicon:SetAllPoints(item)
40 item:Hide()
42 local f2 = CreateFrame("Frame", nil, UIParent)
43 local f2anchor = "RIGHT"
44 f2:SetHeight(32)
45 f2:SetWidth(100)
46 local text2 = ww.SummonFontString(f2, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
47 local icon2 = ww.SummonTexture(f2, "ARTWORK", 24, 24, nil, "RIGHT", text2, "LEFT", -4, 0)
48 local check2 = ww.SummonCheckBox(20, f2, "RIGHT", icon2, "LEFT", -4, 0)
49 check2:SetChecked(true)
50 f2:Hide()
53 local elapsed, oldsize, newsize
54 f2:SetScript("OnUpdate", function(self, el)
55 elapsed = elapsed + el
56 if elapsed > 1 then
57 self:Hide()
58 icon:SetAlpha(1)
59 text:SetAlpha(1)
60 f:SetWidth(newsize)
61 else
62 self:SetPoint(f2anchor, f, f2anchor, 0, elapsed*40)
63 self:SetAlpha(1 - elapsed)
64 text:SetAlpha(elapsed)
65 icon:SetAlpha(elapsed)
66 f:SetWidth(oldsize + (newsize-oldsize)*elapsed)
67 end
68 end)
71 function TourGuide:PositionStatusFrame()
72 if self.db.profile.statusframepoint then
73 f:ClearAllPoints()
74 f:SetPoint(self.db.profile.statusframepoint, self.db.profile.statusframex, self.db.profile.statusframey)
75 end
77 if self.db.profile.itemframepoint then
78 item:ClearAllPoints()
79 item:SetPoint(self.db.profile.itemframepoint, self.db.profile.itemframex, self.db.profile.itemframey)
80 end
81 end
84 function TourGuide:SetText(i)
85 self.current = i
86 local action, quest = self:GetObjectiveInfo(i)
88 local newtext = (quest or"???")..(self:GetObjectiveTag("N") and " [?]" or "")
90 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
91 oldsize = f:GetWidth()
92 icon:SetAlpha(0)
93 text:SetAlpha(0)
94 elapsed = 0
95 f2:SetWidth(f:GetWidth())
96 f2anchor = select(3, GetQuadrant(f))
97 f2:ClearAllPoints()
98 f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
99 f2:SetAlpha(1)
100 icon2:SetTexture(icon:GetTexture())
101 text2:SetText(text:GetText())
102 f2:Show()
105 icon:SetTexture(self.icons[action])
106 text:SetText(newtext)
107 check:SetChecked(false)
108 if i == 1 then f:SetWidth(72 + text:GetWidth()) end
109 newsize = 72 + text:GetWidth()
113 local mapped = {}
114 function TourGuide:UpdateStatusFrame()
115 local nextstep
116 self.updatedelay = nil
118 for i in ipairs(self.actions) do
119 local name = self.quests[i]
120 if not self.turnedin[name] and not nextstep then
121 local action, name, quest = self:GetObjectiveInfo(i)
122 local turnedin, logi, complete = self:GetObjectiveStatus(i)
123 local note, useitem, optional, lootitem, lootqty = self:GetObjectiveTag("N", i), self:GetObjectiveTag("U", i), self:GetObjectiveTag("O", i), self:GetObjectiveTag("L", i)
124 self:Debug(11, "UpdateStatusFrame", i, action, name, note, logi, complete, turnedin, quest, useitem, optional, lootitem, lootqty)
125 local hasuseitem = useitem and self:FindBagSlot(useitem)
127 if action == "NOTE" and not optional and lootitem and GetItemCount(lootitem) >= lootqty then return self:SetTurnedIn(i, true) end
129 local incomplete
130 if action == "ACCEPT" then incomplete = (not optional or hasuseitem) and not logi
131 elseif action == "TURNIN" then incomplete = not optional or logi and complete
132 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
133 elseif action == "NOTE" then incomplete = not optional or lootitem and GetItemCount(lootitem) >= lootqty
134 else incomplete = not logi end
136 if incomplete then nextstep = i end
138 if action == "COMPLETE" and logi then
139 local j = i
140 repeat
141 action = self:GetObjectiveInfo(j)
142 turnedin, logi, complete = self:GetObjectiveStatus(j)
143 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
144 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
145 j = j + 1
146 until action ~= "COMPLETE"
150 QuestLog_Update()
151 QuestWatch_Update()
153 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
155 if not nextstep then return end
157 self:SetText(nextstep)
158 self.current = nextstep
159 local action, quest, fullquest = self:GetObjectiveInfo(nextstep)
160 local turnedin, logi, complete = self:GetObjectiveStatus(nextstep)
161 local note, useitem, optional = self:GetObjectiveTag("N", nextstep), self:GetObjectiveTag("U", nextstep), self:GetObjectiveTag("O", nextstep)
164 -- TomTom coord mapping
165 if note and (TomTom or Cartographer_Waypoints) and not mapped[action..quest] then
166 mapped[action..quest] = true
167 for x,y in note:gmatch("%(([%d.]+),([%d.]+)%)") do
168 if TomTom then TomTom:AddWaypoint(tonumber(x), tonumber(y), quest)
169 elseif Cartographer_Waypoints then Cartographer_Waypoints:AddLHWaypoint(nil, nil, tonumber(x), tonumber(y), quest) end
174 local newtext = (quest or "???")..(note and " [?]" or "")
176 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
177 oldsize = f:GetWidth()
178 icon:SetAlpha(0)
179 text:SetAlpha(0)
180 elapsed = 0
181 f2:SetWidth(f:GetWidth())
182 f2anchor = select(3, GetQuadrant(f))
183 f2:ClearAllPoints()
184 f2:SetPoint(f2anchor, f,f2anchor, 0, 0)
185 f2:SetAlpha(1)
186 icon2:SetTexture(icon:GetTexture())
187 text2:SetText(text:GetText())
188 f2:Show()
191 icon:SetTexture(self.icons[action])
192 text:SetText(newtext)
193 check:SetChecked(false)
194 if not f2:IsVisible() then f:SetWidth(72 + text:GetWidth()) end
195 newsize = 72 + text:GetWidth()
197 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
198 if tex then
199 itemicon:SetTexture(tex)
200 item:SetAttribute("type1", "item")
201 item:SetAttribute("item1", "item:"..useitem)
202 item:Show()
203 else item:Hide() end
205 self:UpdateOHPanel()
209 f:SetScript("OnClick", function(self, btn)
210 if btn == "RightButton" then
211 OptionHouse:Open("Tour Guide", "Objectives")
212 else
213 local i = TourGuide:GetQuestLogIndexByName()
214 if i then SelectQuestLogEntry(i) end
215 ShowUIPanel(QuestLogFrame)
217 end)
220 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
223 item:HookScript("OnClick", function()
224 if TourGuide:GetObjectiveInfo() == "USE" then TourGuide:SetTurnedIn() end
225 end)
228 local function ShowTooltip(self)
229 local tip = TourGuide.notes[TourGuide.current]
230 if not tip then return end
232 GameTooltip:SetOwner(self, "ANCHOR_NONE")
233 local quad, vhalf, hhalf = GetQuadrant(self)
234 local anchpoint = vhalf..(hhalf == "LEFT" and "RIGHT" or "LEFT")
235 TourGuide:Debug(11, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
236 GameTooltip:SetPoint(quad, self, anchpoint)
237 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
241 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
242 f:SetScript("OnEnter", ShowTooltip)
245 local function GetUIParentAnchor(frame)
246 local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
247 local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
248 local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
249 local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
251 return vhalf..hhalf, dx, dy
255 f:RegisterForDrag("LeftButton")
256 f:SetMovable(true)
257 f:SetClampedToScreen(true)
258 f:SetScript("OnDragStart", function(frame)
259 GameTooltip:Hide()
260 frame:StartMoving()
261 end)
262 f:SetScript("OnDragStop", function(frame)
263 frame:StopMovingOrSizing()
264 TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
265 TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
266 frame:ClearAllPoints()
267 frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
268 ShowTooltip(frame)
269 end)
272 item:RegisterForDrag("LeftButton")
273 item:SetMovable(true)
274 item:SetClampedToScreen(true)
275 item:SetScript("OnDragStart", item.StartMoving)
276 item:SetScript("OnDragStop", function(frame)
277 frame:StopMovingOrSizing()
278 TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame))
279 TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame)
280 end)