TourGuide - More data tweakering
[WoW-TourGuide.git] / StatusFrame.lua
blob8d75c0bfcdcafffa406043223fd6d48a402b6f4f
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 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, note, logi, complete, hasitem = self:GetObjectiveInfo(i)
88 local newtext = (quest or"???")..(note 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
117 for i in ipairs(self.actions) do
118 local name = self.quests[i]
119 if not self.turnedin[name] and not nextstep then
120 local action, name, note, logi, complete, hasitem, turnedin, quest, useitem, optional, lootitem, lootqty = self:GetObjectiveInfo(i)
121 self:Debug(11, "UpdateStatusFrame", i, action, name, note, logi, complete, hasitem, turnedin, quest, useitem, optional, lootitem, lootqty)
122 local hasuseitem = useitem and self:FindBagSlot(useitem)
124 if action == "NOTE" and not optional and lootitem and GetItemCount(lootitem) >= lootqty then return self:SetTurnedIn(i, true) end
126 local incomplete
127 if action == "ACCEPT" then incomplete = (not optional or hasitem or hasuseitem) and not logi
128 elseif action == "TURNIN" then incomplete = not optional or logi and complete
129 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
130 elseif action == "NOTE" then incomplete = not optional or lootitem and GetItemCount(lootitem) >= lootqty
131 else incomplete = not logi end
133 if incomplete then nextstep = i end
135 if action == "COMPLETE" and logi then
136 local j = i
137 repeat
138 action, _, _, logi, complete = self:GetObjectiveInfo(j)
139 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
140 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
141 j = j + 1
142 until action ~= "COMPLETE"
146 QuestLog_Update()
147 QuestWatch_Update()
149 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
151 if not nextstep then return end
153 self:SetText(nextstep)
154 self.current = nextstep
155 local action, quest, note, logi, complete, hasitem, turnedin, fullquest, useitem, optional = self:GetObjectiveInfo(nextstep)
158 -- TomTom coord mapping
159 if note and (TomTom or Cartographer_Waypoints) and not mapped[action..quest] then
160 mapped[action..quest] = true
161 for x,y in note:gmatch("%(([%d.]+),([%d.]+)%)") do
162 if (TomTom) then
163 TomTom:AddWaypoint(tonumber(x), tonumber(y), quest)
164 elseif (Cartographer_Waypoints) then
165 Cartographer_Waypoints:AddLHWaypoint(nil, nil, tonumber(x), tonumber(y), note)
172 local newtext = (quest or "???")..(note and " [?]" or "")
174 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
175 oldsize = f:GetWidth()
176 icon:SetAlpha(0)
177 text:SetAlpha(0)
178 elapsed = 0
179 f2:SetWidth(f:GetWidth())
180 f2anchor = select(3, GetQuadrant(f))
181 f2:ClearAllPoints()
182 f2:SetPoint(f2anchor, f,f2anchor, 0, 0)
183 f2:SetAlpha(1)
184 icon2:SetTexture(icon:GetTexture())
185 text2:SetText(text:GetText())
186 f2:Show()
189 icon:SetTexture(self.icons[action])
190 text:SetText(newtext)
191 check:SetChecked(false)
192 if not f2:IsVisible() then f:SetWidth(72 + text:GetWidth()) end
193 newsize = 72 + text:GetWidth()
195 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
196 if tex then
197 itemicon:SetTexture(tex)
198 item:SetAttribute("type1", "item")
199 item:SetAttribute("item1", "item:"..useitem)
200 item:Show()
201 else item:Hide() end
203 self:UpdateOHPanel()
207 f:SetScript("OnClick", function(self, btn)
208 if btn == "RightButton" then
209 OptionHouse:Open("Tour Guide", "Objectives")
210 else
211 local i = TourGuide:GetQuestLogIndexByName()
212 if i then SelectQuestLogEntry(i) end
213 ShowUIPanel(QuestLogFrame)
215 end)
218 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
221 item:HookScript("OnClick", function()
222 if TourGuide:GetCurrentObjectiveInfo() == "USE" then TourGuide:SetTurnedIn() end
223 end)
226 local function ShowTooltip(self)
227 local tip = TourGuide.notes[TourGuide.current]
228 if not tip then return end
230 GameTooltip:SetOwner(self, "ANCHOR_NONE")
231 local quad, vhalf, hhalf = GetQuadrant(self)
232 local anchpoint = vhalf..(hhalf == "LEFT" and "RIGHT" or "LEFT")
233 TourGuide:Debug(11, "Setting tooltip anchor", anchpoint, quad, hhalf, vhalf)
234 GameTooltip:SetPoint(quad, self, anchpoint)
235 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
239 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
240 f:SetScript("OnEnter", ShowTooltip)
243 local function GetUIParentAnchor(frame)
244 local w, h, x, y = UIParent:GetWidth(), UIParent:GetHeight(), frame:GetCenter()
245 local hhalf, vhalf = (x > w/2) and "RIGHT" or "LEFT", (y > h/2) and "TOP" or "BOTTOM"
246 local dx = hhalf == "RIGHT" and math.floor(frame:GetRight() + 0.5) - w or math.floor(frame:GetLeft() + 0.5)
247 local dy = vhalf == "TOP" and math.floor(frame:GetTop() + 0.5) - h or math.floor(frame:GetBottom() + 0.5)
249 return vhalf..hhalf, dx, dy
253 f:RegisterForDrag("LeftButton")
254 f:SetMovable(true)
255 f:SetClampedToScreen(true)
256 f:SetScript("OnDragStart", function(frame)
257 GameTooltip:Hide()
258 frame:StartMoving()
259 end)
260 f:SetScript("OnDragStop", function(frame)
261 frame:StopMovingOrSizing()
262 TourGuide:Debug(1, "Status frame moved", GetUIParentAnchor(frame))
263 TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey = GetUIParentAnchor(frame)
264 frame:ClearAllPoints()
265 frame:SetPoint(TourGuide.db.profile.statusframepoint, TourGuide.db.profile.statusframex, TourGuide.db.profile.statusframey)
266 ShowTooltip(frame)
267 end)
270 item:RegisterForDrag("LeftButton")
271 item:SetMovable(true)
272 item:SetClampedToScreen(true)
273 item:SetScript("OnDragStart", item.StartMoving)
274 item:SetScript("OnDragStop", function(frame)
275 frame:StopMovingOrSizing()
276 TourGuide:Debug(1, "Item frame moved", GetUIParentAnchor(frame))
277 TourGuide.db.profile.itemframepoint, TourGuide.db.profile.itemframex, TourGuide.db.profile.itemframey = GetUIParentAnchor(frame)
278 end)