TourGuide
[WoW-TourGuide.git] / StatusFrame.lua
blobe9b678bcf7ba02b0489e41ae7b43482d215c6b66
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, UIParent, "SecureActionButtonTemplate")
26 item:SetHeight(24)
27 item:SetWidth(24)
28 item:SetPoint("BOTTOMRIGHT", QuestWatchFrame, "TOPRIGHT", 0, 18)
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 local hasuseitem = useitem and self:FindBagSlot(useitem)
96 if not nextstep then
97 local incomplete
98 if action == "ITEM" then incomplete = hasitem
99 elseif action == "ACCEPT" then incomplete = (not optional or hasitem or hasuseitem) and not logi
100 elseif action == "TURNIN" then incomplete = not optional
101 elseif action == "COMPLETE" then incomplete = not complete and (not optional or logi)
102 else incomplete = not logi end
103 if incomplete then nextstep = i end
106 if action == "COMPLETE" and logi then
107 local j = i
108 repeat
109 action, _, _, logi, complete = self:GetObjectiveInfo(j)
110 if action == "COMPLETE" and logi and not complete then AddQuestWatch(logi) -- Watch if we're in a 'COMPLETE' block
111 elseif action == "COMPLETE" and logi then RemoveQuestWatch(logi) end -- or unwatch if done
112 j = j + 1
113 until action ~= "COMPLETE"
117 QuestLog_Update()
118 QuestWatch_Update()
120 if not nextstep and self:LoadNextGuide() then return self:UpdateStatusFrame() end
122 if not nextstep then return end
124 self:SetText(nextstep)
125 self.current = nextstep
126 local action, quest, note, logi, complete, hasitem, turnedin, fullquest, useitem, optional = self:GetObjectiveInfo(nextstep)
129 -- TomTom coord mapping
130 if note and TomTom and not mapped[action..quest] then
131 mapped[action..quest] = true
132 for x,y in note:gmatch("%(([%d.]+),([%d.]+)%)") do
133 TomTom:AddWaypoint(tonumber(x), tonumber(y), quest)
138 local newtext = (quest or "???")..(note and " [?]" or "")
140 if text:GetText() ~= newtext or icon:GetTexture() ~= self.icons[action] then
141 oldsize = f:GetWidth()
142 icon:SetAlpha(0)
143 text:SetAlpha(0)
144 elapsed = 0
145 f2:SetPoint("RIGHT", f, "RIGHT", 0, 0)
146 f2:SetAlpha(1)
147 icon2:SetTexture(icon:GetTexture())
148 text2:SetText(text:GetText())
149 f2:Show()
152 icon:SetTexture(self.icons[action])
153 text:SetText(newtext)
154 check:SetChecked(false)
155 if not f2:IsVisible() then f:SetWidth(72 + text:GetWidth()) end
156 newsize = 72 + text:GetWidth()
158 local tex = useitem and select(10, GetItemInfo(tonumber(useitem)))
159 if tex then
160 itemicon:SetTexture(tex)
161 item:SetAttribute("type1", "item")
162 item:SetAttribute("item1", "item:"..useitem)
163 item:Show()
164 else item:Hide() end
166 self:UpdateOHPanel()
170 f:SetScript("OnClick", function(self, btn)
171 if btn == "RightButton" then
172 OptionHouse:Open("Tour Guide", "Objectives")
173 else
174 local i = TourGuide:GetQuestLogIndexByName()
175 if i then SelectQuestLogEntry(i) end
176 ShowUIPanel(QuestLogFrame)
178 end)
181 check:SetScript("OnClick", function(self, btn) TourGuide:SetTurnedIn() end)
184 f:SetScript("OnDragStart", function(self) self:StartMoving() end)
185 f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
188 f:SetScript("OnLeave", function() GameTooltip:Hide() end)
189 f:SetScript("OnEnter", function(self)
190 local tip = TourGuide.notes[TourGuide.current]
191 if not tip then return end
193 GameTooltip:SetOwner(self, "ANCHOR_NONE")
194 GameTooltip:SetPoint("TOPRIGHT", self, "TOPLEFT")
195 GameTooltip:SetText(tip, nil, nil, nil, nil, true)
196 end)
199 item:HookScript("OnClick", function()
200 if self:GetCurrentObjectiveInfo() == "USE" then self:SetTurnedIn() end
201 end)