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
17 local f
= CreateFrame("Button", nil, UIParent
)
18 f
:SetPoint("BOTTOMRIGHT", QuestWatchFrame
, "TOPRIGHT", 0, -15)
20 f
:SetFrameStrata("LOW")
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 TourGuide
:Debug(1, "Frame strata", f
:GetFrameStrata())
29 local check
= ww
.SummonCheckBox(20, f
, "LEFT", 8, 0)
30 local icon
= ww
.SummonTexture(f
, "ARTWORK", 24, 24, nil, "LEFT", check
, "RIGHT", 4, 0)
31 local text
= ww
.SummonFontString(f
, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
32 text
:SetPoint("LEFT", icon
, "RIGHT", 4, 0)
34 local item
= CreateFrame("Button", nil, UIParent
, "SecureActionButtonTemplate")
35 item
:SetFrameStrata("LOW")
38 item
:SetPoint("BOTTOMRIGHT", QuestWatchFrame
, "TOPRIGHT", 0, 18)
39 item
:RegisterForClicks("anyUp")
40 local itemicon
= ww
.SummonTexture(item
, "ARTWORK", 24, 24, "Interface\\Icons\\INV_Misc_Bag_08")
41 itemicon
:SetAllPoints(item
)
44 local f2
= CreateFrame("Frame", nil, UIParent
)
45 local f2anchor
= "RIGHT"
48 local text2
= ww
.SummonFontString(f2
, "OVERLAY", "GameFontNormal", nil, "RIGHT", -12, 0)
49 local icon2
= ww
.SummonTexture(f2
, "ARTWORK", 24, 24, nil, "RIGHT", text2
, "LEFT", -4, 0)
50 local check2
= ww
.SummonCheckBox(20, f2
, "RIGHT", icon2
, "LEFT", -4, 0)
51 check2
:SetChecked(true)
55 local elapsed
, oldsize
, newsize
56 f2
:SetScript("OnUpdate", function(self
, el
)
57 elapsed
= elapsed
+ el
64 self
:SetPoint(f2anchor
, f
, f2anchor
, 0, elapsed
*40)
65 self
:SetAlpha(1 - elapsed
)
66 text
:SetAlpha(elapsed
)
67 icon
:SetAlpha(elapsed
)
68 f
:SetWidth(oldsize
+ (newsize
-oldsize
)*elapsed
)
73 function TourGuide
:PositionStatusFrame()
74 if self
.db
.profile
.statusframepoint
then
76 f
:SetPoint(self
.db
.profile
.statusframepoint
, self
.db
.profile
.statusframex
, self
.db
.profile
.statusframey
)
79 if self
.db
.profile
.itemframepoint
then
81 item
:SetPoint(self
.db
.profile
.itemframepoint
, self
.db
.profile
.itemframex
, self
.db
.profile
.itemframey
)
86 function TourGuide
:SetText(i
)
88 local action
, quest
, note
, logi
, complete
, hasitem
= self
:GetObjectiveInfo(i
)
90 local newtext
= (quest
or"???")..(note
and " [?]" or "")
92 if text
:GetText() ~= newtext
or icon
:GetTexture() ~= self
.icons
[action
] then
93 oldsize
= f
:GetWidth()
97 f2
:SetWidth(f
:GetWidth())
98 f2anchor
= select(3, GetQuadrant(f
))
100 f2
:SetPoint(f2anchor
, f
, f2anchor
, 0, 0)
102 icon2
:SetTexture(icon
:GetTexture())
103 text2
:SetText(text
:GetText())
107 icon
:SetTexture(self
.icons
[action
])
108 text
:SetText(newtext
)
109 check
:SetChecked(false)
110 if i
== 1 then f
:SetWidth(72 + text
:GetWidth()) end
111 newsize
= 72 + text
:GetWidth()
116 function TourGuide
:UpdateStatusFrame()
119 for i
in ipairs(self
.actions
) do
120 local name
= self
.quests
[i
]
121 if not self
.turnedin
[name
] and not nextstep
then
122 local action
, name
, note
, logi
, complete
, hasitem
, turnedin
, quest
, useitem
, optional
, lootitem
, lootqty
= self
:GetObjectiveInfo(i
)
123 self
:Debug(11, "UpdateStatusFrame", i
, action
, name
, note
, logi
, complete
, hasitem
, turnedin
, quest
, useitem
, optional
, lootitem
, lootqty
)
124 local hasuseitem
= useitem
and self
:FindBagSlot(useitem
)
126 if action
== "NOTE" and not optional
and lootitem
and GetItemCount(lootitem
) >= lootqty
then return self
:SetTurnedIn(i
, true) end
129 if action
== "ACCEPT" then incomplete
= (not optional
or hasitem
or hasuseitem
) and not logi
130 elseif action
== "TURNIN" then incomplete
= not optional
or logi
and complete
131 elseif action
== "COMPLETE" then incomplete
= not complete
and (not optional
or logi
)
132 elseif action
== "NOTE" then incomplete
= not optional
or lootitem
and GetItemCount(lootitem
) >= lootqty
133 else incomplete
= not logi
end
135 if incomplete
then nextstep
= i
end
137 if action
== "COMPLETE" and logi
then
140 action
, _
, _
, logi
, complete
= self
:GetObjectiveInfo(j
)
141 if action
== "COMPLETE" and logi
and not complete
then AddQuestWatch(logi
) -- Watch if we're in a 'COMPLETE' block
142 elseif action
== "COMPLETE" and logi
then RemoveQuestWatch(logi
) end -- or unwatch if done
144 until action
~= "COMPLETE"
151 if not nextstep
and self
:LoadNextGuide() then return self
:UpdateStatusFrame() end
153 if not nextstep
then return end
155 self
:SetText(nextstep
)
156 self
.current
= nextstep
157 local action
, quest
, note
, logi
, complete
, hasitem
, turnedin
, fullquest
, useitem
, optional
= self
:GetObjectiveInfo(nextstep
)
160 -- TomTom coord mapping
161 if note
and (TomTom
or Cartographer_Waypoints
) and not mapped
[action
..quest
] then
162 mapped
[action
..quest
] = true
163 for x
,y
in note
:gmatch("%(([%d.]+),([%d.]+)%)") do
165 TomTom
:AddWaypoint(tonumber(x
), tonumber(y
), quest
)
166 elseif (Cartographer_Waypoints
) then
167 Cartographer_Waypoints
:AddLHWaypoint(nil, nil, tonumber(x
), tonumber(y
), note
)
174 local newtext
= (quest
or "???")..(note
and " [?]" or "")
176 if text
:GetText() ~= newtext
or icon
:GetTexture() ~= self
.icons
[action
] then
177 oldsize
= f
:GetWidth()
181 f2
:SetWidth(f
:GetWidth())
182 f2anchor
= select(3, GetQuadrant(f
))
184 f2
:SetPoint(f2anchor
, f
,f2anchor
, 0, 0)
186 icon2
:SetTexture(icon
:GetTexture())
187 text2
:SetText(text
:GetText())
191 icon
:SetTexture(self
.icons
[action
])
192 text
:SetText(newtext
)
193 check
:SetChecked(false)
194 if not f2
:IsVisible() then f
:SetWidth(72 + text
:GetWidth()) end
195 newsize
= 72 + text
:GetWidth()
197 local tex
= useitem
and select(10, GetItemInfo(tonumber(useitem
)))
199 itemicon
:SetTexture(tex
)
200 item
:SetAttribute("type1", "item")
201 item
:SetAttribute("item1", "item:"..useitem
)
209 f
:SetScript("OnClick", function(self
, btn
)
210 if btn
== "RightButton" then
211 OptionHouse
:Open("Tour Guide", "Objectives")
213 local i
= TourGuide
:GetQuestLogIndexByName()
214 if i
then SelectQuestLogEntry(i
) end
215 ShowUIPanel(QuestLogFrame
)
220 check
:SetScript("OnClick", function(self
, btn
) TourGuide
:SetTurnedIn() end)
223 item
:HookScript("OnClick", function()
224 if self
:GetCurrentObjectiveInfo() == "USE" then self
:SetTurnedIn() end
228 local function ShowTooltip(self
)
229 local tip
= TourGuide
.notes
[TourGuide
.current
]
230 if not tip
then return end
232 GameTooltip
:SetOwner(self
, "ANCHOR_NONE")
233 local quad
, vhalf
, hhalf
= GetQuadrant(self
)
234 local anchpoint
= vhalf
..(hhalf
== "LEFT" and "RIGHT" or "LEFT")
235 TourGuide
:Debug(10, "Setting tooltip anchor", anchpoint
, quad
, hhalf
, vhalf
)
236 GameTooltip
:SetPoint(quad
, self
, anchpoint
)
237 GameTooltip
:SetText(tip
, nil, nil, nil, nil, true)
241 f
:SetScript("OnLeave", function() GameTooltip
:Hide() end)
242 f
:SetScript("OnEnter", ShowTooltip
)
245 local function GetUIParentAnchor(frame
)
246 local w
, h
, x
, y
= UIParent
:GetWidth(), UIParent
:GetHeight(), frame
:GetCenter()
247 local hhalf
, vhalf
= (x
> w
/2) and "RIGHT" or "LEFT", (y
> h
/2) and "TOP" or "BOTTOM"
248 local dx
= hhalf
== "RIGHT" and math
.floor(frame
:GetRight() + 0.5) - w
or math
.floor(frame
:GetLeft() + 0.5)
249 local dy
= vhalf
== "TOP" and math
.floor(frame
:GetTop() + 0.5) - h
or math
.floor(frame
:GetBottom() + 0.5)
251 return vhalf
..hhalf
, dx
, dy
255 f
:RegisterForDrag("LeftButton")
257 f
:SetClampedToScreen(true)
258 f
:SetScript("OnDragStart", function(frame
)
262 f
:SetScript("OnDragStop", function(frame
)
263 frame
:StopMovingOrSizing()
264 TourGuide
:Debug(1, "Status frame moved", GetUIParentAnchor(frame
))
265 TourGuide
.db
.profile
.statusframepoint
, TourGuide
.db
.profile
.statusframex
, TourGuide
.db
.profile
.statusframey
= GetUIParentAnchor(frame
)
266 frame
:ClearAllPoints()
267 frame
:SetPoint(TourGuide
.db
.profile
.statusframepoint
, TourGuide
.db
.profile
.statusframex
, TourGuide
.db
.profile
.statusframey
)
272 item
:RegisterForDrag("LeftButton")
273 item
:SetMovable(true)
274 item
:SetClampedToScreen(true)
275 item
:SetScript("OnDragStart", item
.StartMoving
)
276 item
:SetScript("OnDragStop", function(frame
)
277 frame
:StopMovingOrSizing()
278 TourGuide
:Debug(1, "Item frame moved", GetUIParentAnchor(frame
))
279 TourGuide
.db
.profile
.itemframepoint
, TourGuide
.db
.profile
.itemframex
, TourGuide
.db
.profile
.itemframey
= GetUIParentAnchor(frame
)