TourGuide - Split gnome and dorf starter quests into 2 files, to avoid class overlap
[WoW-TourGuide.git] / StatusFrame.lua
blobe965f381784aaac36196cc92bd30db8945a25519
2 local bg = {
3 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
4 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
5 edgeSize = 16,
6 insets = {left = 5, right = 5, top = 5, bottom = 5},
7 tile = true, tileSize = 16,
10 local ICONSIZE, CHECKSIZE, GAP = 16, 16, 8
11 local FIXEDWIDTH = ICONSIZE + CHECKSIZE + GAP*4 - 4
13 local TourGuide = TourGuide
14 local OptionHouse = LibStub("OptionHouse-1.1")
15 local ww = WidgetWarlock
18 local function GetQuadrant(frame)
19 local x,y = frame:GetCenter()
20 if not x or not y then return "BOTTOMLEFT", "BOTTOM", "LEFT" end
21 local hhalf = (x > UIParent:GetWidth()/2) and "RIGHT" or "LEFT"
22 local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
23 return vhalf..hhalf, vhalf, hhalf
24 end
27 local f = CreateFrame("Button", nil, UIParent)
28 f:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, -15)
29 f:SetHeight(24)
30 f:SetFrameStrata("LOW")
31 f:EnableMouse(true)
32 f:RegisterForClicks("anyUp")
33 f:SetBackdrop(bg)
34 f:SetBackdropColor(0.09, 0.09, 0.19, 0.5)
35 f:SetBackdropBorderColor(0.5, 0.5, 0.5, 0.5)
37 local check = ww.SummonCheckBox(CHECKSIZE, f, "LEFT", GAP, 0)
38 local icon = ww.SummonTexture(f, "ARTWORK", ICONSIZE, ICONSIZE, nil, "LEFT", check, "RIGHT", GAP-4, 0)
39 local text = ww.SummonFontString(f, "OVERLAY", "GameFontNormalSmall", nil, "RIGHT", -GAP-4, 0)
40 text:SetPoint("LEFT", icon, "RIGHT", GAP-4, 0)
42 local item = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
43 item:SetFrameStrata("LOW")
44 item:SetHeight(36)
45 item:SetWidth(36)
46 item:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, 18)
47 item:RegisterForClicks("anyUp")
48 local itemicon = ww.SummonTexture(item, "ARTWORK", 24, 24, "Interface\\Icons\\INV_Misc_Bag_08")
49 itemicon:SetAllPoints(item)
50 item:Hide()
52 local f2 = CreateFrame("Frame", nil, UIParent)
53 local f2anchor = "RIGHT"
54 f2:SetHeight(32)
55 f2:SetWidth(100)
56 local text2 = ww.SummonFontString(f2, "OVERLAY", "GameFontNormalSmall", nil, "RIGHT", -GAP-4, 0)
57 local icon2 = ww.SummonTexture(f2, "ARTWORK", ICONSIZE, ICONSIZE, nil, "RIGHT", text2, "LEFT", -GAP+4, 0)
58 local check2 = ww.SummonCheckBox(CHECKSIZE, f2, "RIGHT", icon2, "LEFT", -GAP+4, 0)
59 check2:SetChecked(true)
60 f2:Hide()
63 local elapsed, oldsize, newsize
64 f2:SetScript("OnUpdate", function(self, el)
65 elapsed = elapsed + el
66 if elapsed > 1 then
67 self:Hide()
68 icon:SetAlpha(1)
69 text:SetAlpha(1)
70 f:SetWidth(newsize)
71 else
72 self:SetPoint(f2anchor, f, f2anchor, 0, elapsed*40)
73 self:SetAlpha(1 - elapsed)
74 text:SetAlpha(elapsed)
75 icon:SetAlpha(elapsed)
76 f:SetWidth(oldsize + (newsize-oldsize)*elapsed)
77 end
78 end)
81 function TourGuide:PositionStatusFrame()
82 if self.db.profile.statusframepoint then
83 f:ClearAllPoints()
84 f:SetPoint(self.db.profile.statusframepoint, self.db.profile.statusframex, self.db.profile.statusframey)
85 end
87 if self.db.profile.itemframepoint then
88 item:ClearAllPoints()
89 item:SetPoint(self.db.profile.itemframepoint, self.db.profile.itemframex, self.db.profile.itemframey)
90 end
91 end
94 function TourGuide:SetText(i)
95 self.current = i
96 local action, quest = self:GetObjectiveInfo(i)
97 local note = self:GetObjectiveTag("N")
98 local newtext = (quest or"???")..(note and " [?]" or "")
100 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
101 oldsize = f:GetWidth()
102 icon:SetAlpha(0)
103 text:SetAlpha(0)
104 elapsed = 0
105 f2:SetWidth(f:GetWidth())
106 f2anchor = select(3, GetQuadrant(f))
107 f2:ClearAllPoints()
108 f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
109 f2:SetAlpha(1)
110 icon2:SetTexture(icon:GetTexture())
111 icon2:SetTexCoord(4/48, 44/48, 4/48, 44/48)
112 text2:SetText(text:GetText())
113 f2:Show()
116 icon:SetTexture(self.icons[action])
117 if action ~= "ACCEPT" and action ~= "TURNIN" then icon:SetTexCoord(4/48, 44/48, 4/48, 44/48) end
118 text:SetText(newtext)
119 check:SetChecked(false)
120 if i == 1 then f:SetWidth(FIXEDWIDTH + text:GetWidth()) end
121 newsize = FIXEDWIDTH + text:GetWidth()
123 if self.UpdateFubarPlugin then self.UpdateFubarPlugin(quest, self.icons[action], note) end
127 local mapped = {}
128 function TourGuide:UpdateStatusFrame()
129 local nextstep
130 self.updatedelay = nil
132 for i in ipairs(self.actions) do
133 local name = self.quests[i]
134 if not self.turnedin[name] and not nextstep then
135 local action, name, quest = self:GetObjectiveInfo(i)
136 local turnedin, logi, complete = self:GetObjectiveStatus(i)
137 local note, useitem, optional, lootitem, lootqty = self:GetObjectiveTag("N", i), self:GetObjectiveTag("U", i), self:GetObjectiveTag("O", i), self:GetObjectiveTag("L", i)
138 local level = tonumber((self:GetObjectiveTag("LV", i)))
139 local needlevel = level and level > UnitLevel("player")
140 self:Debug(11, "UpdateStatusFrame", i, action, name, note, logi, complete, turnedin, quest, useitem, optional, lootitem, lootqty, lootitem and GetItemCount(lootitem) or 0, level, needlevel)
141 local hasuseitem = useitem and self:FindBagSlot(useitem)
143 -- Test for completed objectives and mark them done
144 if (action == "RUN" or action == "FLY" or action == "HEARTH" or action == "BOAT") and (GetSubZoneText() == name or GetZoneText() == name) then return self:SetTurnedIn(i, true) end
146 if action == "KILL" or action == "NOTE" then
147 if not optional and lootitem and GetItemCount(lootitem) >= lootqty then return self:SetTurnedIn(i, true) end
149 local quest, questtext = self:GetObjectiveTag("Q", i), self:GetObjectiveTag("QO", i)
150 if quest and questtext then
151 local qi = self:GetQuestLogIndexByName(quest)
152 for lbi=1,GetNumQuestLeaderBoards(qi) do
153 self:Debug(1, quest, questtext, qi, GetQuestLogLeaderBoard(lbi, qi))
154 if GetQuestLogLeaderBoard(lbi, qi) == questtext then return self:SetTurnedIn(i, true) end
159 local incomplete
160 if action == "ACCEPT" then incomplete = (not optional or hasuseitem) and not logi
161 elseif action == "TURNIN" then incomplete = not optional or logi and complete
162 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
163 elseif action == "NOTE" or action == "KILL" then incomplete = not optional or lootitem and GetItemCount(lootitem) >= lootqty or needlevel
164 elseif action == "GRIND" then incomplete = needlevel
165 else incomplete = not logi end
167 if incomplete then nextstep = i end
169 if action == "COMPLETE" and logi then
170 local j = i
171 repeat
172 action = self:GetObjectiveInfo(j)
173 turnedin, logi, complete = self:GetObjectiveStatus(j)
174 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
175 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
176 j = j + 1
177 until action ~= "COMPLETE"
181 QuestLog_Update()
182 QuestWatch_Update()
184 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
186 if not nextstep then return end
188 self:SetText(nextstep)
189 self.current = nextstep
190 local action, quest, fullquest = self:GetObjectiveInfo(nextstep)
191 local turnedin, logi, complete = self:GetObjectiveStatus(nextstep)
192 local note, useitem, optional = self:GetObjectiveTag("N", nextstep), self:GetObjectiveTag("U", nextstep), self:GetObjectiveTag("O", nextstep)
193 local zonename = self:GetObjectiveTag("Z", nextstep) or self.zonename
195 -- Mapping
196 if note and (TomTom or Cartographer_Waypoints) and not mapped[action..quest] then
197 mapped[action..quest] = true
198 self:ParseAndMapCoords(note, quest, zonename) --, zone)
202 local newtext = (quest or "???")..(note and " [?]" or "")
204 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
205 oldsize = f:GetWidth()
206 icon:SetAlpha(0)
207 text:SetAlpha(0)
208 elapsed = 0
209 f2:SetWidth(f:GetWidth())
210 f2anchor = select(3, GetQuadrant(f))
211 f2:ClearAllPoints()
212 f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
213 f2:SetAlpha(1)
214 icon2:SetTexture(icon:GetTexture())
215 text2:SetText(text:GetText())
216 f2:Show()
219 icon:SetTexture(self.icons[action])
220 text:SetText(newtext)
221 check:SetChecked(false)
222 if not f2:IsVisible() then f:SetWidth(FIXEDWIDTH + text:GetWidth()) end
223 newsize = FIXEDWIDTH + text:GetWidth()
225 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
226 if tex then
227 itemicon:SetTexture(tex)
228 item:SetAttribute("type1", "item")
229 item:SetAttribute("item1", "item:"..useitem)
230 item:Show()
231 else item:Hide() end
233 self:UpdateOHPanel()
237 f:SetScript("OnClick", function(self, btn)
238 if btn == "RightButton" then
239 OptionHouse:Open("Tour Guide", "Objectives")
240 else
241 local i = TourGuide:GetQuestLogIndexByName()
242 if i then SelectQuestLogEntry(i) end
243 ShowUIPanel(QuestLogFrame)
245 end)
248 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
251 item:HookScript("OnClick", function()
252 if TourGuide:GetObjectiveInfo() == "USE" then TourGuide:SetTurnedIn() end
253 end)
256 local function ShowTooltip(self)
257 local tip = TourGuide:GetObjectiveTag("N")
258 if not tip then return end
260 GameTooltip:SetOwner(self, "ANCHOR_NONE")
261 local quad, vhalf, hhalf = GetQuadrant(self)
262 local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
263 TourGuide:Debug(11, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
264 GameTooltip:SetPoint(quad, self, anchpoint)
265 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
269 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
270 f:SetScript("OnEnter", ShowTooltip)
273 local function GetUIParentAnchor(frame)
274 local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
275 local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
276 local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
277 local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
279 return vhalf..hhalf, dx, dy
283 f:RegisterForDrag("LeftButton")
284 f:SetMovable(true)
285 f:SetClampedToScreen(true)
286 f:SetScript("OnDragStart", function(frame)
287 GameTooltip:Hide()
288 frame:StartMoving()
289 end)
290 f:SetScript("OnDragStop", function(frame)
291 frame:StopMovingOrSizing()
292 TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
293 TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
294 frame:ClearAllPoints()
295 frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
296 ShowTooltip(frame)
297 end)
300 item:RegisterForDrag("LeftButton")
301 item:SetMovable(true)
302 item:SetClampedToScreen(true)
303 item:SetScript("OnDragStart", item.StartMoving)
304 item:SetScript("OnDragStop", function(frame)
305 frame:StopMovingOrSizing()
306 TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame))
307 TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame)
308 end)