TourGuide
[WoW-TourGuide.git] / StatusFrame.lua
blob8b331276290e9368699c095f93eea21636b8211f
3 local TourGuide = TourGuide
4 local OptionHouse = DongleStub("OptionHouse-1.0")
5 local ww = WidgetWarlock
8 local f = CreateFrame("Button", nil, UIParent)
9 f:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, -15)
10 f:SetHeight(32)
11 f:EnableMouse(true)
12 f:RegisterForDrag("LeftButton")
13 f:RegisterForClicks("anyUp")
14 f:SetMovable(true)
15 f:SetClampedToScreen(true)
16 f:SetBackdrop(ww.TooltipBorderBG)
17 f:SetBackdropColor(0,0,0,0.3)
18 f:SetBackdropBorderColor(0,0,0,0.7)
20 local check = ww.SummonCheckBox(20, f, "LEFT", 8, 0)
21 local icon = ww.SummonTexture(f, 24, 24, nil, "LEFT", check, "RIGHT", 4, 0)
22 local text = ww.SummonFontString(f, nil, nil, "GameFontNormal", nil, "RIGHT", -12, 0)
23 text:SetPoint("LEFT", icon, "RIGHT", 4, 0)
25 local item = CreateFrame("Button", nil, f, "SecureActionButtonTemplate")
26 item:SetHeight(24)
27 item:SetWidth(24)
28 item:SetPoint("BOTTOMLEFT", QuestWatchFrame, "TOPRIGHT", 0, 10)
29 item:RegisterForClicks("anyUp")
30 local itemicon = ww.SummonTexture(item, 24, 24, "Interface\\Icons\\INV_Misc_Bag_08")
31 itemicon:SetAllPoints(item)
32 item:Hide()
34 local f2 = CreateFrame("Frame", nil, UIParent)
35 f2:SetHeight(32)
36 f2:SetWidth(100)
37 local text2 = ww.SummonFontString(f2, nil, nil, "GameFontNormal", nil, "RIGHT", -12, 0)
38 local icon2 = ww.SummonTexture(f2, 24, 24, nil, "RIGHT", text2, "LEFT", -4, 0)
39 local check2 = ww.SummonCheckBox(20, f2, "RIGHT", icon2, "LEFT", -4, 0)
40 check2:SetChecked(true)
41 f2:Hide()
44 local elapsed, oldsize, newsize
45 f2:SetScript("OnUpdate", function(self, el)
46 elapsed = elapsed + el
47 if elapsed > 1 then
48 self:Hide()
49 icon:SetAlpha(1)
50 text:SetAlpha(1)
51 f:SetWidth(newsize)
52 else
53 self:SetPoint("RIGHT", f, "RIGHT", 0, elapsed*40)
54 self:SetAlpha(1 - elapsed)
55 text:SetAlpha(elapsed)
56 icon:SetAlpha(elapsed)
57 f:SetWidth(oldsize + (newsize-oldsize)*elapsed)
58 end
59 end)
61 function TourGuide:SetText(i)
62 self.current = i
63 local action, quest, note, logi, complete, hasitem = self:GetObjectiveInfo(i)
65 local newtext = (quest or"???")..(note and " [?]" or "")
67 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
68 oldsize = f:GetWidth()
69 icon:SetAlpha(0)
70 text:SetAlpha(0)
71 elapsed = 0
72 f2:SetPoint("RIGHT", f, "RIGHT", 0, 0)
73 f2:SetAlpha(1)
74 icon2:SetTexture(icon:GetTexture())
75 text2:SetText(text:GetText())
76 f2:Show()
77 end
79 icon:SetTexture(self.icons[action])
80 text:SetText(newtext)
81 check:SetChecked(false)
82 if i == 1 then f:SetWidth(72 + text:GetWidth()) end
83 newsize = 72 + text:GetWidth()
84 end
87 local mapped = {}
88 function TourGuide:UpdateStatusFrame()
89 local nextstep
91 for i in ipairs(self.actions) do
92 local name = self.quests[i]
93 if not self.turnedin[name] and not nextstep then
94 local action, name, note, logi, complete, hasitem, turnedin, quest, useitem, optional = self:GetObjectiveInfo(i)
95 if not nextstep then
96 local incomplete
97 if action == "ITEM" then incomplete = hasitem
98 elseif action == "ACCEPT" then incomplete = (not optional or hasitem) and not logi
99 elseif action == "TURNIN" then incomplete = not optional
100 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
101 else incomplete = not logi end
102 if incomplete then nextstep = i end
105 if action == "COMPLETE" and logi then
106 local j = i
107 repeat
108 action, _, _, logi, complete = self:GetObjectiveInfo(j)
109 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
110 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
111 j = j + 1
112 until action ~= "COMPLETE"
116 QuestLog_Update()
117 QuestWatch_Update()
119 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
121 if not nextstep then return end
123 self:SetText(nextstep)
124 self.current = nextstep
125 local action, quest, note, logi, complete, hasitem, turnedin, fullquest, useitem, optional = self:GetObjectiveInfo(nextstep)
128 -- TomTom coord mapping
129 if note and TomTom and not mapped[action..quest] then
130 mapped[action..quest] = true
131 for x,y in note:gmatch("%(([%d.]+),([%d.]+)%)") do
132 TomTom:AddWaypoint(tonumber(x), tonumber(y), quest)
137 local newtext = (quest or "???")..(note and " [?]" or "")
139 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
140 oldsize = f:GetWidth()
141 icon:SetAlpha(0)
142 text:SetAlpha(0)
143 elapsed = 0
144 f2:SetPoint("RIGHT", f, "RIGHT", 0, 0)
145 f2:SetAlpha(1)
146 icon2:SetTexture(icon:GetTexture())
147 text2:SetText(text:GetText())
148 f2:Show()
151 icon:SetTexture(self.icons[action])
152 text:SetText(newtext)
153 check:SetChecked(false)
154 if not f2:IsVisible() then f:SetWidth(72 + text:GetWidth()) end
155 newsize = 72 + text:GetWidth()
157 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
158 if tex then
159 itemicon:SetTexture(tex)
160 item:SetAttribute("type1", "item")
161 item:SetAttribute("item1", "item:"..useitem)
162 item:Show()
163 else item:Hide() end
165 self:UpdateOHPanel()
169 f:SetScript("OnClick", function(self, btn)
170 if btn == "RightButton" then
171 OptionHouse:Open("Tour Guide", "Objectives")
172 else
173 local i = TourGuide:GetQuestLogIndexByName()
174 if i then SelectQuestLogEntry(i) end
175 ShowUIPanel(QuestLogFrame)
177 end)
180 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
183 f:SetScript("OnDragStart", function(self) self:StartMoving() end)
184 f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
187 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
188 f:SetScript("OnEnter", function(self)
189 local tip = TourGuide.notes[TourGuide.current]
190 if not tip then return end
192 GameTooltip:SetOwner(self, "ANCHOR_NONE")
193 GameTooltip:SetPoint("TOPRIGHT", self, "TOPLEFT")
194 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
195 end)
198 item:HookScript("OnClick", function()
199 if self:GetCurrentObjectiveInfo() == "USE" then self:SetTurnedIn() end
200 end)