TourGuide
[WoW-TourGuide.git] / StatusFrame.lua
blob1adac2f8c23e0215f1512f8bc0487a52217f2920
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)
98 local newtext = (quest or"???")..(self:GetObjectiveTag("N") 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()
125 local mapped = {}
126 function TourGuide:UpdateStatusFrame()
127 local nextstep
128 self.updatedelay = nil
130 for i in ipairs(self.actions) do
131 local name = self.quests[i]
132 if not self.turnedin[name] and not nextstep then
133 local action, name, quest = self:GetObjectiveInfo(i)
134 local turnedin, logi, complete = self:GetObjectiveStatus(i)
135 local note, useitem, optional, lootitem, lootqty = self:GetObjectiveTag("N", i), self:GetObjectiveTag("U", i), self:GetObjectiveTag("O", i), self:GetObjectiveTag("L", i)
136 local level = self:GetObjectiveTag("LV", i)
137 local needlevel = level and level > UnitLevel("player")
138 self:Debug(11, "UpdateStatusFrame", i, action, name, note, logi, complete, turnedin, quest, useitem, optional, lootitem, lootqty, lootitem and GetItemCount(lootitem) or 0, level, needlevel)
139 local hasuseitem = useitem and self:FindBagSlot(useitem)
141 if action == "NOTE" and not optional and lootitem and GetItemCount(lootitem) >= lootqty then return self:SetTurnedIn(i, true) end
143 local incomplete
144 if action == "ACCEPT" then incomplete = (not optional or hasuseitem) and not logi
145 elseif action == "TURNIN" then incomplete = not optional or logi and complete
146 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
147 elseif action == "NOTE" then incomplete = not optional or lootitem and GetItemCount(lootitem) >= lootqty or needlevel
148 elseif action == "GRIND" then incomplete = needlevel
149 else incomplete = not logi end
151 if incomplete then nextstep = i end
153 if action == "COMPLETE" and logi then
154 local j = i
155 repeat
156 action = self:GetObjectiveInfo(j)
157 turnedin, logi, complete = self:GetObjectiveStatus(j)
158 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
159 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
160 j = j + 1
161 until action ~= "COMPLETE"
165 QuestLog_Update()
166 QuestWatch_Update()
168 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
170 if not nextstep then return end
172 self:SetText(nextstep)
173 self.current = nextstep
174 local action, quest, fullquest = self:GetObjectiveInfo(nextstep)
175 local turnedin, logi, complete = self:GetObjectiveStatus(nextstep)
176 local note, useitem, optional = self:GetObjectiveTag("N", nextstep), self:GetObjectiveTag("U", nextstep), self:GetObjectiveTag("O", nextstep)
177 local zonename = self:GetObjectiveTag("Z", nextstep) or self.zonename
179 -- Mapping
180 if note and (TomTom or Cartographer_Waypoints) and not mapped[action..quest] then
181 mapped[action..quest] = true
182 self:ParseAndMapCoords(note, quest, zonename) --, zone)
186 local newtext = (quest or "???")..(note and " [?]" or "")
188 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
189 oldsize = f:GetWidth()
190 icon:SetAlpha(0)
191 text:SetAlpha(0)
192 elapsed = 0
193 f2:SetWidth(f:GetWidth())
194 f2anchor = select(3, GetQuadrant(f))
195 f2:ClearAllPoints()
196 f2:SetPoint(f2anchor, f, f2anchor, 0, 0)
197 f2:SetAlpha(1)
198 icon2:SetTexture(icon:GetTexture())
199 text2:SetText(text:GetText())
200 f2:Show()
203 icon:SetTexture(self.icons[action])
204 text:SetText(newtext)
205 check:SetChecked(false)
206 if not f2:IsVisible() then f:SetWidth(FIXEDWIDTH + text:GetWidth()) end
207 newsize = FIXEDWIDTH + text:GetWidth()
209 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
210 if tex then
211 itemicon:SetTexture(tex)
212 item:SetAttribute("type1", "item")
213 item:SetAttribute("item1", "item:"..useitem)
214 item:Show()
215 else item:Hide() end
217 self:UpdateOHPanel()
221 f:SetScript("OnClick", function(self, btn)
222 if btn == "RightButton" then
223 OptionHouse:Open("Tour Guide", "Objectives")
224 else
225 local i = TourGuide:GetQuestLogIndexByName()
226 if i then SelectQuestLogEntry(i) end
227 ShowUIPanel(QuestLogFrame)
229 end)
232 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
235 item:HookScript("OnClick", function()
236 if TourGuide:GetObjectiveInfo() == "USE" then TourGuide:SetTurnedIn() end
237 end)
240 local function ShowTooltip(self)
241 local tip = TourGuide.notes[TourGuide.current]
242 if not tip then return end
244 GameTooltip:SetOwner(self, "ANCHOR_NONE")
245 local quad, vhalf, hhalf = GetQuadrant(self)
246 local anchpoint = (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
247 TourGuide:Debug(11, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
248 GameTooltip:SetPoint(quad, self, anchpoint)
249 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
253 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
254 f:SetScript("OnEnter", ShowTooltip)
257 local function GetUIParentAnchor(frame)
258 local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
259 local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
260 local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
261 local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
263 return vhalf..hhalf, dx, dy
267 f:RegisterForDrag("LeftButton")
268 f:SetMovable(true)
269 f:SetClampedToScreen(true)
270 f:SetScript("OnDragStart", function(frame)
271 GameTooltip:Hide()
272 frame:StartMoving()
273 end)
274 f:SetScript("OnDragStop", function(frame)
275 frame:StopMovingOrSizing()
276 TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
277 TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
278 frame:ClearAllPoints()
279 frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
280 ShowTooltip(frame)
281 end)
284 item:RegisterForDrag("LeftButton")
285 item:SetMovable(true)
286 item:SetClampedToScreen(true)
287 item:SetScript("OnDragStart", item.StartMoving)
288 item:SetScript("OnDragStop", function(frame)
289 frame:StopMovingOrSizing()
290 TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame))
291 TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame)
292 end)