-
Notifications
You must be signed in to change notification settings - Fork 9
/
NautUI.lua
443 lines (369 loc) · 12.2 KB
/
NautUI.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
-- declare colour codes for console messages
local RED = "|cffff0000"
local GREEN = "|cff00ff00"
local YELLOW = "|cffffff00"
local WHITE = "|cffffffff"
local GREY = "|cffbababa"
-- constants
local NONE = -1
local ARTWORK_PATH = "Interface\\AddOns\\NauticusClassic\\Artwork\\"
local ARTWORK_LOGO = ARTWORK_PATH.."NauticusClassicLogo"
local ARTWORK_ALARM = "Interface\\Icons\\INV_Misc_PocketWatch_02"
local NUMBER_FONT = "Fonts\\ARIALN.TTF"
local NauticusClassic = NauticusClassic
local L = LibStub("AceLocale-3.0"):GetLocale("NauticusClassic")
local transports = NauticusClassic.transports
local function AddLine(text, func, checked, value, tooltipTitle, tooltipText)
local info = UIDropDownMenu_CreateInfo()
info.text = text; info.func = func
if value then info.value = value; end
if checked then info.checked = true; end
if tooltipTitle == true then
info.tooltipTitle = text
elseif tooltipTitle then
info.tooltipTitle = tooltipTitle
end
if tooltipText then info.tooltipText = tooltipText; end
UIDropDownMenu_AddButton(info)
end
local function AddSeparator()
local info = UIDropDownMenu_CreateInfo()
info.notClickable = 1
UIDropDownMenu_AddButton(info)
end
function NauticusClassic:TransportSelectInitialise(frame, level)
if level == 1 then
local info = UIDropDownMenu_CreateInfo()
info.text = self.title; info.isTitle = 1
UIDropDownMenu_AddButton(info)
AddLine(
L["List friendly faction only"], -- text
function() -- func
NauticusClassic.db.profile.factionSpecific = not NauticusClassic.db.profile.factionSpecific
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
NauticusClassic:DrawMapIcons(true, true)
end,
self.db.profile.factionSpecific, -- checked?
nil, -- value
true, -- tooltipTitle
L["Shows only neutral transports and those of your faction."] -- tooltipText
)
AddLine(
L["List relevant to current zone only"], -- text
function() -- func
NauticusClassic.db.profile.zoneSpecific = not NauticusClassic.db.profile.zoneSpecific
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
end,
self.db.profile.zoneSpecific, -- checked?
nil, -- value
true, -- tooltipTitle
L["Shows only transports relevant to your current zone."] -- tooltipText
)
AddSeparator()
AddLine(
GREY..L["Select None"], -- text
function() -- func
NauticusClassic:SetTransport(NONE)
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
end,
self.activeTransit == NONE, -- checked?
NONE, -- value
true -- tooltipTitle
)
local textdesc
for id = 1, #(transports), 1 do
if self:IsTransportListed(id) then
textdesc = transports[id].name
if self:HasKnownCycle(id) then
if transports[id].faction == UnitFactionGroup("player") then
textdesc = GREEN..textdesc
elseif transports[id].faction == "Neutral" then
textdesc = YELLOW..textdesc
else
textdesc = RED..textdesc
end
else
textdesc = GREY..textdesc
end
AddLine(
textdesc, -- text
function() -- func
NauticusClassic:SetTransport(id)
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
end,
self.activeTransit == id, -- checked?
id, -- value
true -- tooltipTitle
)
end
end
AddSeparator()
AddLine(
L["Options"], -- text
function()
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame); end -- func
)
end
end
local function IsMenuOpen()
return DropDownList1:IsShown() and
UIDROPDOWNMENU_OPEN_MENU == Naut_TransportSelectFrame
end
function NauticusClassic:RefreshMenu()
if IsMenuOpen() then
CloseDropDownMenus()
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
end
end
local tablet = LibStub("LibSimpleFrame-Mod-1.0"):New("NauticusClassic", {
position = { point = "CENTER", x = 0, y = 0 },
lock = true,
scale = 1,
strata = "TOOLTIP",
fade = 1,
opacity = 1,
width = 150,
border = { 1, 1, 1, 1 },
background = { 0, 0, 0, 1 },
min_height = 20,
} )
function NauticusClassic:ShowTooltip(transit)
local has = self:HasKnownCycle(transit)
if has then
local plat_time, depOrArr, r,g,b
local liveData = self.liveData[transit]
local cycle, index = liveData.cycle, liveData.index
tablet:AddLine(transports[transit].vessel_name)
:Color(0.25, 0.75, 1, 1)
:Font(GameFontHighlightLarge:GetFont())
.left:SetJustifyH('CENTER')
for _, data in pairs(self.platforms[transit]) do
tablet:AddLine(data.name)
:Color(1, 1, 1, 1)
if data.index == index then
-- we're at a platform and waiting to depart
plat_time = self:GetCycleByIndex(transit, index) - cycle
if 30 < plat_time then
r,g,b = 1,1,0
else
r,g,b = 1,0,0
end
depOrArr = L["Departure"]
else
plat_time = self:GetCycleByIndex(transit, data.index-1) - cycle
if 0 > plat_time then
plat_time = plat_time + self.rtts[transit]
end
r,g,b = 0,1,0
depOrArr = L["Arrival"]
end
tablet:AddLine(depOrArr..":", self:GetFormattedTime(plat_time), false, 10)
:Color(1, 0.82, 0, 1, r, g, b, 1)
:Font(nil, nil, nil, NUMBER_FONT, 14, nil)
end
if (self.debug and not IsShiftKeyDown()) or (not self.debug and IsShiftKeyDown()) then
tablet:AddLine("Metadata")
:Color(0.75, 0.75, 0.75, 1)
local since, boots, swaps = self:GetKnownCycle(transit)
tablet:AddLine("Age:", SecondsToTime(since), false, 10)
:Font(nil, nil, nil, NUMBER_FONT, 14, nil)
tablet:AddLine("Boots, Swaps:", boots..", "..swaps, false, 10)
:Font(nil, nil, nil, NUMBER_FONT, 14, nil)
end
elseif has == false then
tablet:AddLine(transports[transit].vessel_name)
:Color(0.25, 0.75, 1, 1)
:Font(GameFontHighlightLarge:GetFont())
.left:SetJustifyH('CENTER')
for _, data in pairs(self.platforms[transit]) do
tablet:AddLine(data.name)
:Color(1, 1, 1, 1)
tablet:AddLine(L["Not Available"])
.left:SetJustifyH('CENTER')
end
elseif has == nil then
tablet:AddLine(L["No Transport Selected"])
:Color(1, 0.25, 0, 1)
:Font(GameFontHighlightLarge:GetFont())
.left:SetJustifyH('CENTER')
end
end
local iconTooltip, lastTip
function NauticusClassic:HideTooltip(doHide)
if doHide then
tablet:Hide()
iconTooltip = nil
end
if self.update_available and self.update_available ~= true then
self.update_available = self.update_available + 1.0 - (GetTime()-lastTip)
end
end
local function AddNewVersionLine()
local line = L["New version available! Visit github.com/psynct/NauticusClassic"]
if NauticusClassic.update_available == true then
tablet:AddLine(line, nil, true)
:Color(1, 0.1, 0.1, 1)
else
tablet:AddLine(line.." - ["..math.floor(NauticusClassic.update_available).."]", nil, true)
:Color(1, 0.82, 0, 1)
:Font(nil, 11, nil)
NauticusClassic.update_available = NauticusClassic.update_available - 1
if 0 > NauticusClassic.update_available then
NauticusClassic.update_available = nil
end
end
end
local function GetParentFrame()
if UIParent:IsShown() then
return UIParent
end
local f = GetUIPanel("fullscreen")
if f and f:IsShown() then
return f
end
return nil
end
function NauticusClassic:MapIcon_OnEnter(frame)
local transit = frame:GetID()
tablet:Attach():Clear().db.scale = 0.85
self:ShowTooltip(transit)
for id, data in pairs(transports) do
if transit ~= id and
((data.worldmap_icon:IsVisible() and MouseIsOver(data.worldmap_icon)) or
(data.minimap_icon:IsVisible() and MouseIsOver(data.minimap_icon)))
then
tablet:AddLine("•") -- ascii 149
:Color(0.5, 0.5, 0, 1)
.left:SetJustifyH('CENTER')
self:ShowTooltip(id)
end
end
if self.update_available then
tablet:AddLine("")
AddNewVersionLine()
end
tablet:SetPosition():Size():Show()
iconTooltip = frame
lastTip = GetTime()
end
function NauticusClassic:MapIcon_OnLeave(frame)
self:HideTooltip(true)
end
function NauticusClassic:MapIcon_OnClick(frame)
self:SetTransport(frame:GetID())
end
-- LDB stuff...
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:NewDataObject("NauticusClassic", { type = "data source", text = "NauticusClassic", icon = ARTWORK_LOGO } )
NauticusClassic.dataobj = dataobj
local barTooltipFrame
function NauticusClassic:UpdateDisplay()
dataobj.icon = self:IsAlarmSet() and ARTWORK_ALARM or self.icon or ARTWORK_LOGO
dataobj.text = (0 < self.tempTextCount) and self.tempText or self.lowestNameTime
if not iconTooltip then return; end
if iconTooltip == barTooltipFrame then
dataobj.OnEnter(iconTooltip)
else
self:MapIcon_OnEnter(iconTooltip)
end
end
local function GetBarAnchor(frame)
local x, y = frame:GetCenter()
if not x or not y then return "TOPLEFT", "BOTTOMLEFT"; end
local cx, cy = UIParent:GetWidth() / 3, UIParent:GetHeight() / 2
if x < cx then
if y < cy then return "BOTTOMLEFT", "TOPLEFT"
else return "TOPLEFT", "BOTTOMLEFT"; end
elseif x > 2 * cx then
if y < cy then return "BOTTOMRIGHT", "TOPRIGHT"
else return "TOPRIGHT", "BOTTOMRIGHT"; end
else
if y < cy then return "BOTTOM", "TOP"
else return "TOP", "BOTTOM"; end
end
end
function dataobj:OnEnter()
if IsMenuOpen() then return; end
local point, rel = GetBarAnchor(self)
tablet:Attach(point, self, rel, 0, 0):Clear().db.scale = 1
tablet:AddLine(NauticusClassic.title)
:Font(GameTooltipHeaderText:GetFont())
.left:SetJustifyH('CENTER')
NauticusClassic:ShowTooltip(NauticusClassic.activeTransit)
tablet:AddLine("")
if NauticusClassic.update_available then
AddNewVersionLine()
end
tablet:AddLine(L["Hint: Click to cycle transport."], nil, true)
:Color(0, 1, 0, 1)
tablet:AddLine(L["Alt-Click to set up alarm."], nil, true)
:Color(0, 1, 0, 1)
local _, localizedChannel = NauticusClassic:GetBroadcastChannel()
tablet:AddLine(format(L["Ctrl-Click to broadcast in %s."], localizedChannel), nil, true)
:Color(0, 1, 0, 1)
tablet:SetPosition():Size():Show()
iconTooltip = self
lastTip = GetTime()
barTooltipFrame = self
end
function dataobj:OnLeave()
NauticusClassic:HideTooltip(true)
end
function dataobj:OnClick(button)
if button == "LeftButton" then
if IsMenuOpen() then CloseDropDownMenus(); end
if IsAltKeyDown() then
if NauticusClassic:HasKnownCycle(NauticusClassic.activeTransit) then
NauticusClassic:ToggleAlarm()
NauticusClassic.tempText = "Alarm "..(NauticusClassic:IsAlarmSet() and RED..L["ON"] or GREEN..L["OFF"])
NauticusClassic.tempTextCount = 3
NauticusClassic:HideTooltip()
NauticusClassic:UpdateDisplay()
end
elseif IsControlKeyDown() then
if NauticusClassic:HasKnownCycle(NauticusClassic.activeTransit) then
local liveData = NauticusClassic.liveData[NauticusClassic.activeTransit]
local cycle, index = liveData.cycle, liveData.index
local channel, _ = NauticusClassic:GetBroadcastChannel()
local platformStrings = {}
for _, data in pairs(NauticusClassic.platforms[NauticusClassic.activeTransit]) do
local depOrArr, plat_time
if data.index == index then
-- we're at a platform and waiting to depart
plat_time = NauticusClassic:GetCycleByIndex(NauticusClassic.activeTransit, index) - cycle
depOrArr = L["Departure"]
else
plat_time = NauticusClassic:GetCycleByIndex(NauticusClassic.activeTransit, data.index-1) - cycle
if 0 > plat_time then
plat_time = plat_time + NauticusClassic.rtts[NauticusClassic.activeTransit]
end
depOrArr = L["Arrival"]
end
table.insert(platformStrings, format("%s (%s: %s)", data.name, depOrArr, NauticusClassic:GetFormattedTime(plat_time)))
end
SendChatMessage(table.concat(platformStrings, " <-> "), channel);
end
else
NauticusClassic:HideTooltip()
NauticusClassic:SetTransport(NauticusClassic:NextTransportInList())
end
elseif button == "RightButton" then
NauticusClassic:HideTooltip(true)
local point, rel = GetBarAnchor(self)
UIDropDownMenu_SetAnchor(Naut_TransportSelectFrame, 0, 0, point, self, rel)
ToggleDropDownMenu(1, nil, Naut_TransportSelectFrame)
end
end
-- Titan stuff...
-- don't go any further if Titan isn't loaded
if not IsAddOnLoaded("Titan") then return; end
-- hook menu close (so we can close our dropdown sooner when clicking Titan bar)
do
local orig_TitanUtils_CloseRightClickMenu = TitanUtils_CloseRightClickMenu
function TitanUtils_CloseRightClickMenu(...)
if IsMenuOpen() then CloseDropDownMenus(); end
return orig_TitanUtils_CloseRightClickMenu(...)
end
end