This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.lua
232 lines (185 loc) · 5.71 KB
/
Core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
------------------------------------------
-- This addon was heavily inspired by --
-- HandyNotes_Lorewalkers --
-- HandyNotes_LostAndFound --
-- by Kemayo --
------------------------------------------
-- declaration
local _, LunarFestival = ...
LunarFestival.points = {}
-- our db and defaults
local db
local defaults = { profile = { completed = false, icon_scale = 1.4, icon_alpha = 0.8 } }
-- upvalues
local _G = getfenv(0)
local CloseDropDownMenus = _G.CloseDropDownMenus
local GameTooltip = _G.GameTooltip
local GetAchievementCriteriaInfo = _G.GetAchievementCriteriaInfo
local IsQuestFlaggedCompleted = _G.IsQuestFlaggedCompleted
local LibStub = _G.LibStub
local next = _G.next
local pairs = _G.pairs
local ToggleDropDownMenu = _G.ToggleDropDownMenu
local UIDropDownMenu_AddButton = _G.UIDropDownMenu_AddButton
local UIParent = _G.UIParent
local WorldMapButton = _G.WorldMapButton
local WorldMapTooltip = _G.WorldMapTooltip
local Cartographer_Waypoints = _G.Cartographer_Waypoints
local HandyNotes = _G.HandyNotes
local NotePoint = _G.NotePoint
local TomTom = _G.TomTom
-- plugin handler for HandyNotes
local function infoFromCoord(mapFile, coord)
local point = LunarFestival.points[mapFile] and LunarFestival.points[mapFile][coord]
if point then
return GetAchievementCriteriaInfo(point[2], point[3])
end
end
function LunarFestival:OnEnter(mapFile, coord)
local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
if self:GetCenter() > UIParent:GetCenter() then -- compare X coordinate
tooltip:SetOwner(self, "ANCHOR_LEFT")
else
tooltip:SetOwner(self, "ANCHOR_RIGHT")
end
local nameOfElder = infoFromCoord(mapFile, coord)
tooltip:SetText(nameOfElder or "Lunar Festival NPC")
tooltip:Show()
end
function LunarFestival:OnLeave()
if self:GetParent() == WorldMapButton then
WorldMapTooltip:Hide()
else
GameTooltip:Hide()
end
end
local function createWaypoint(button, mapFile, coord)
local c, z = HandyNotes:GetCZ(mapFile)
local x, y = HandyNotes:getXY(coord)
local nameOfElder = infoFromCoord(mapFile, coord)
if TomTom then
TomTom:AddZWaypoint(c, z, x * 100, y * 100, nameOfElder or "Lunar Festival NPC")
elseif Cartographer_Waypoints then
Cartographer_Waypoints:AddWaypoint( NotePoint:new(HandyNotes:GetCZToZone(c, z), x, y, nameOfElder or "Lunar Festival NPC") )
end
end
do
-- context menu generator
local info = {}
local currentZone, currentCoord
local function close()
-- we call it here to avoid "for initial value must be a number" errors
CloseDropDownMenus()
end
local function generateMenu(button, level)
if not level then return end
for k in pairs(info) do info[k] = nil end
if level == 1 then
-- create the title of the menu
info.isTitle = 1
info.text = "HandyNotes - Lunar Festival"
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
if TomTom or Cartographer_Waypoints then
-- waypoint menu item
info.disabled = nil
info.isTitle = nil
info.notCheckable = nil
info.text = "Create waypoint"
info.icon = nil
info.func = createWaypoint
info.arg1 = currentZone
info.arg2 = currentCoord
UIDropDownMenu_AddButton(info, level)
end
-- close menu item
info.text = "Close"
info.icon = nil
info.func = close
info.arg1 = nil
info.arg2 = nil
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
end
end
local dropdown = CreateFrame("Frame", "HandyNotes_LunarFestivalDropdownMenu")
dropdown.displayMode = "MENU"
dropdown.initialize = generateMenu
function LunarFestival:OnClick(button, down, mapFile, coord)
if button == "RightButton" and not down then
currentZone = mapFile
currentCoord = coord
ToggleDropDownMenu(1, nil, dropdown, self, 0, 0)
end
end
end
do
-- custom iterator we use to iterate over every node in a given zone
local function iter(t, prestate)
if not t then return nil end
local state, value = next(t, prestate)
while state do -- have we reached the end of this zone?
if value and (db.completed or not IsQuestFlaggedCompleted(value[1])) then
return state, nil, "interface\\icons\\inv_misc_elvencoins", db.icon_scale, db.icon_alpha
end
state, value = next(t, state) -- get next data
end
return nil, nil, nil, nil
end
function LunarFestival:GetNodes(mapFile)
return iter, self.points[mapFile], nil
end
end
-- config
local options = {
type = "group",
name = "Lunar Festival",
desc = "Lunar Festival elder NPC locations.",
get = function(info) return db[info[#info]] end,
set = function(info, v)
db[info[#info]] = v
LunarFestival:Refresh()
end,
args = {
desc = {
name = "These settings control the look and feel of the icon.",
type = "description",
order = 1,
},
completed = {
name = "Show completed",
desc = "Show icons for elder NPCs you have already visited.",
type = "toggle",
width = "full",
arg = "completed",
order = 2,
},
icon_scale = {
type = "range",
name = "Icon Scale",
desc = "Change the size of the icons.",
min = 0.25, max = 2, step = 0.01,
arg = "icon_scale",
order = 3,
},
icon_alpha = {
type = "range",
name = "Icon Alpha",
desc = "Change the transparency of the icons.",
min = 0, max = 1, step = 0.01,
arg = "icon_alpha",
order = 4,
},
},
}
-- initialise
function LunarFestival:OnEnable()
HandyNotes:RegisterPluginDB("LunarFestival", self, options)
self:RegisterEvent("QUEST_FINISHED", "Refresh")
db = LibStub("AceDB-3.0"):New("HandyNotes_LunarFestivalDB", defaults, "Default").profile
end
function LunarFestival:Refresh()
self:SendMessage("HandyNotes_NotifyUpdate", "LunarFestival")
end
-- activate
LibStub("AceAddon-3.0"):NewAddon(LunarFestival, "HandyNotes_LunarFestival", "AceEvent-3.0")