-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatTextPanel.lua
More file actions
717 lines (598 loc) · 28.5 KB
/
FloatTextPanel.lua
File metadata and controls
717 lines (598 loc) · 28.5 KB
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
-----------------------------------------------------------------------------------------------
-- Client Lua Script for FloatTextPanel
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "Apollo"
require "DialogSys"
require "Quest"
require "QuestLib"
require "MailSystemLib"
require "Sound"
require "GameLib"
require "Tooltip"
require "XmlDoc"
require "PlayerPathLib"
require "CommunicatorLib"
require "Unit"
require "Spell"
require "CombatFloater"
require "Unit"
require "Challenges"
require "ChallengesLib"
local FloatTextPanel = {}
local kstrSubPanelFont = "CRB_InterfaceLarge_B"
local kstrSubPanelFontBacked = "CRB_InterfaceMedium"
local kcrQuestFontColor = "ffffffff"
local kcrPathFontColor = "ffff8000"
local kcrBodyFontColor = "ffffffff"
local kcrBodyFontColorBacked = "ff7fffb9"
local kfFirstMessageDelay = 0.75 -- how long do we want to stall the first floater; gives them time to amass and clear other notices
local kfFramerateRefreshRate = 0.1 -- how often do we update our framerate?
local kfMessageSpawnDelay = 1.85 --from the sprite
local kfMessageDespawnDelay = 0.26 --from the sprite
local karPathMissionLabels =
{
Apollo.GetString("FloatText_SoldierMissionUnlocked"),
Apollo.GetString("FloatText_SettlerMissionUnlocked"),
Apollo.GetString("FloatText_ScientistMissionUnlocked"),
Apollo.GetString("FloatText_ExplorerMissionUnlocked")
}
local karChallengeSprites =
{
[ChallengesLib.ChallengeType_Combat] = "CRB_ChallengeTrackerSprites:sprChallengeTypeKillLarge",
[ChallengesLib.ChallengeType_Ability] = "CRB_ChallengeTrackerSprites:sprChallengeTypeSkillLarge",
[ChallengesLib.ChallengeType_General] = "CRB_ChallengeTrackerSprites:sprChallengeTypeGenericLarge",
[ChallengesLib.ChallengeType_Item] = "CRB_ChallengeTrackerSprites:sprChallengeTypeLootLarge",
}
function FloatTextPanel:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function FloatTextPanel:Init()
Apollo.RegisterAddon(self)
end
-----------------------------------------------------------------------------------------------
-- FloatTextPanel OnLoad
-----------------------------------------------------------------------------------------------
function FloatTextPanel:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("FloatTextPanel.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function FloatTextPanel:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("Death", "OnDeath", self)
Apollo.RegisterEventHandler("QuestInit", "OnQuestInit", self)
Apollo.RegisterEventHandler("QuestFloater", "OnQuestNotice", self)
Apollo.RegisterEventHandler("SettlerHubReward", "OnSettlerHubReward", self)
Apollo.RegisterEventHandler("EpisodeStateChanged", "OnEpisodeStateChanged", self)
Apollo.RegisterEventHandler("AchievementUpdated", "OnAchievementUpdated", self)
Apollo.RegisterEventHandler("AlertAchievement", "OnAchievementNotice", self)
Apollo.RegisterEventHandler("AlertTitle", "OnTitletNotice", self)
Apollo.RegisterEventHandler("PlayerPathMissionUnlocked", "OnPlayerPathMissionUnlocked", self)
Apollo.RegisterEventHandler("PlayerPathMissionUpdate", "OnPlayerPathUpdated", self) -- specific mission update, send the mission
Apollo.RegisterTimerHandler("FirstMessageDelaySub", "OnFirstMessageDelaySub", self)
Apollo.RegisterTimerHandler("DelayAlertMain", "OnDelayAlertMain", self)
Apollo.RegisterTimerHandler("DelayAlertMainAnim", "OnDelayAlertMainAnim", self)
Apollo.RegisterTimerHandler("MessageTimerMain", "OnMessageTimerMain", self)
Apollo.RegisterTimerHandler("MessageTimerMainDelay", "OnMessageTimerMainDelay", self)
Apollo.RegisterTimerHandler("DelayExpiredMain", "OnDelayExpiredMain", self)
Apollo.RegisterEventHandler("ToggleFramerate", "OnToggleFramerate", self)
Apollo.RegisterTimerHandler("FramerateRefreshTimer", "OnFramerateRefreshTimer", self)
Apollo.RegisterEventHandler("HintArrowDistanceUpdate", "OnHintArrowDistanceUpdate", self)
-- load our forms
self.wndMain = Apollo.LoadForm(self.xmlDoc, "FloaterPanel", nil, self)
self.wndPrimaryParent = Apollo.LoadForm(self.xmlDoc, "FloaterPanelLower", nil, self)
self.wndPrimary = self.wndPrimaryParent:FindChild("MainPanel")
self.wndPrimaryParent:FindChild("Anim_OpenBurst"):SetSprite("")
self.wndPrimaryParent:FindChild("Anim_CloseBurst"):SetSprite("")
self.wndPrimaryParent:FindChild("Anim_MessageBacker"):SetSprite("")
self.wndPrimary:Show(false)
self.bShowingAlertMain = false
self.tMainWindowDurations = {}
self.tMainWindow =
{
self.wndPrimary:FindChild("MainContent_Episode"),
self.wndPrimary:FindChild("MainContent_Zone"), -- DEPRECATED
self.wndPrimary:FindChild("MainContent_Dead"),
self.wndPrimary:FindChild("MainContent_Level"),
self.wndPrimary:FindChild("MainContent_Settler"),
self.wndPrimary:FindChild("MainContent_Path"),
self.wndPrimary:FindChild("MainContent_PathEpisode"),
self.wndPrimary:FindChild("MainContent_Achievement"),
self.wndPrimary:FindChild("MainContent_ChallengeUnlock")
}
self.tMainWindowDurations =
{
4.000, -- durations for each message type; 1 is episode
4.000, -- zone
4.000, -- dead
0.000, -- level
8.000, -- Settler
4.000, -- path level
4.000, -- path ep completed
4.500, -- Achievement unlocked
4.000, -- challenge unlock
}
self.tQueueMain = {nFirst = 0, nLast = -1}
self.wndSecondary = self.wndMain:FindChild("SubPanel")
self.wndSecondary:Show(false)
self.bShowingAlertSub = false
self.tSubWindow = {}
self.tSubWindowDurations = {}
self.tSubWindow =
{
self.wndSecondary:FindChild("SubContent_Objective"),
self.wndSecondary:FindChild("SubContent_Title"),
self.wndSecondary:FindChild("SubContent_MissionUnlock"),
self.wndSecondary:FindChild("SubContent_Mission"),
self.wndSecondary:FindChild("SubContent_Mission"),
}
self.tSubWindowDurations =
{
2.8, -- quest objective
3.8, -- title objective
5.0, -- mission unlock
5.0, -- mission advance
5.0, -- mission complete
}
self.tQueueSub = {nFirst = 0, nLast = -1}
-- maintain a table of completed missions so we don't double-up floaters (the UI will get two calls: 1. last progression 2. completion call)
self.tCompletedMissions = {}
self.bIsCharacterLoaded = GameLib.IsCharacterLoaded()
self.iDisplayedTypeSub = 0 -- used to pass along what we're showing currently
self.missionLastCompleted = nil
self.bFirstMessageDelaySub = false
self.bEmptyQueueSub = true
self.wndFramerate = Apollo.LoadForm(self.xmlDoc, "FramerateDisplay", nil, self)
self.wndFramerate:Show(false, true)
Apollo.CreateTimer("FramerateRefreshTimer", kfFramerateRefreshRate, true)
self.wndHintArrowDistance = Apollo.LoadForm(self.xmlDoc ,"HintArrowDistanceDisplay", nil, self)
self.wndHintArrowDistance:Show(false, true)
self.xmlDoc = nil
end
function FloatTextPanel:OnAdvanceErrorTimer()
self.tErrors[3] = nil
self.tErrors[3] = self.tErrors[2]
self.tErrors[2] = self.tErrors[1]
if self.tErrors[1] ~= nil then
self.tErrors[1] = nil
end
local bStillQueued = false
for idx = 1, 3 do
if self.tErrors[idx] ~= nil then
self.tErrorsWnd[idx]:SetText(self.tErrors[idx])
bStillQueued = true
else
self.tErrorsWnd[idx]:SetText("")
end
end
if bStillQueued == true then
Apollo.CreateTimer("AdvanceErrorTimer", 0.10, false)
end
end
function FloatTextPanel:OnQuestInit()
self.bIsCharacterLoaded = true
end
function FloatTextPanel:OnEpisodeStateChanged(idEpisode, eOldState, eNewState)
if not self.bIsCharacterLoaded or eNewState ~= Episode.EpisodeState_Active then
return
end
local episodeCurr = QuestLib.GetEpisode(idEpisode)
if episodeCurr and not episodeCurr:IsTaskOnly() then
Event_FireGenericEvent("PopupText_ShowEpisodeAlert", episodeCurr:GetTitle())
--self:AddToQueueMain(1, episode:GetTitle())
end
end
function FloatTextPanel:OnDeath()
self:AddToQueueMain(3, Apollo.GetString("Player_Dead"))
end
function FloatTextPanel:OnSettlerHubReward(strText)
self:AddToQueueMain(5, strText)
end
function FloatTextPanel:OnAchievementNotice(strAchievement)
self:AddToQueueMain(8, strAchievement)
end
function FloatTextPanel:OnAchievementUpdated(achUpdated)
if self.tMainWindow and self.tMainWindow[8] then
self.tMainWindow[8]:SetData(achUpdated)
end
end
function FloatTextPanel:OnMainContent_AchievementMouseUp(wndHandler, wndControl)
Event_FireGenericEvent("FloatTextPanel_ToggleAchievementWindow", wndHandler:GetData())
end
---------------------------------------------------------------------------------------------------
-- Primary Timer Structure
---------------------------------------------------------------------------------------------------
function FloatTextPanel:AddToQueueMain(eAlertType, strAlertString)
local nLast = self.tQueueMain.nLast + 1
self.tQueueMain.nLast = nLast
self.tQueueMain[nLast] = {iType = eAlertType, strMessage = strAlertString}
if not self.bShowingAlertMain then
self:ProcessAlertsMain()
end
end
function FloatTextPanel:ProcessAlertsMain()
self:ClearFieldsMain()
local nFirst = self.tQueueMain.nFirst
if nFirst > self.tQueueMain.nLast then
return
end
-- Delay for the sprite to draw
self.wndPrimaryParent:FindChild("Anim_OpenBurst"):SetSprite("CRB_Anim_WindowBirth:Burst_Open")
self.wndPrimaryParent:FindChild("Anim_MessageBacker"):SetSprite("CRB_Anim_WindowBirth:BracketOpen")
Apollo.CreateTimer("DelayAlertMain", kfMessageSpawnDelay - 1.2, false) -- makes the text fade on sooner
Apollo.CreateTimer("DelayAlertMainAnim", kfMessageSpawnDelay, false)
end
function FloatTextPanel:OnDelayAlertMain()
local nFirst = self.tQueueMain.nFirst
local t = self.tQueueMain[nFirst]
self.tQueueMain[nFirst] = nil
self.tQueueMain.nFirst = nFirst + 1
self:DisplayAlertMain(t.iType, t.strMessage)
end
function FloatTextPanel:OnDelayAlertMainAnim()
self.wndPrimaryParent:FindChild("Anim_MessageBacker"):SetSprite("CRB_Anim_WindowBirth:BracketLoop")
end
function FloatTextPanel:DisplayAlertMain(iType, strInfo)
if iType == 6 or iType == 7 then -- Path notice
if PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Soldier then
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite("ClientSprites:Icon_Windows_UI_CRB_Soldier")
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Settler then
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite("ClientSprites:Icon_Windows_UI_CRB_Colonist")
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Explorer then
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite("ClientSprites:Icon_Windows_UI_CRB_Explorer")
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Scientist then
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite("ClientSprites:Icon_Windows_UI_CRB_Scientist")
else
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite("")
end
end
if iType == 8 then
Sound.Play(Sound.PlayUIAchievementGranted)
end
if iType == 9 then
local eChallengeType = strInfo:GetType()
local strUnlockType = ""
self.tMainWindow[iType]:FindChild("BackerSprite2"):SetSprite(karChallengeSprites[nChallengeType])
if eChallengeType == ChallengesLib.ChallengeType_Combat then
strUnlockType = Apollo.GetString("FloatText_CombatChallengeHeader")
elseif eChallengeType == ChallengesLib.ChallengeType_Ability then
strUnlockType = Apollo.GetString("FloatText_AbilityChallengeHeader")
elseif eChallengeType == ChallengesLib.ChallengeType_General then
strUnlockType = Apollo.GetString("FloatText_GeneralChallengeHeader")
elseif eChallengeType == ChallengesLib.ChallengeType_Item then
strUnlockType = Apollo.GetString("FloatText_ItemChallengeHeader")
end
self.tMainWindow[iType]:FindChild("Text2"):SetText(strUnlockType)
strInfo = strInfo:GetName() -- convert to string for use below
end
self.bShowingAlertMain = true
-- TODO REFACTOR
self.wndPrimaryParent:Invoke()
self.wndPrimary:Show(true)
self.tMainWindow[iType]:Show(true)
self.tMainWindow[iType]:FindChild("Text"):SetText(strInfo)
self:StartMessageTimerMain(self.tMainWindowDurations[iType])
end
function FloatTextPanel:StartMessageTimerMain(fDuration) -- showing
Apollo.CreateTimer("MessageTimerMain", fDuration, false)
end
function FloatTextPanel:OnMessageTimerMain() -- clear the text and still before running the clearing animation
self.wndPrimary:Show(false)
Apollo.CreateTimer("MessageTimerMainDelay", 0.500, false)
end
function FloatTextPanel:OnMessageTimerMainDelay() -- clearing animation, set the process delay
self.wndPrimaryParent:FindChild("Anim_MessageBacker"):SetSprite("CRB_Anim_WindowBirth:BracketClose")
Apollo.CreateTimer("DelayExpiredMain", kfMessageDespawnDelay, false)
end
function FloatTextPanel:OnDelayExpiredMain()
self.wndPrimaryParent:FindChild("Anim_CloseBurst"):SetSprite("CRB_Anim_WindowBirth:Burst_Close")
self.bShowingAlertMain = false
self:ProcessAlertsMain()
end
function FloatTextPanel:OnToggleFramerate()
self.wndFramerate:Show(not self.wndFramerate:IsShown())
end
function FloatTextPanel:OnFramerateRefreshTimer()
if not self.wndFramerate:IsShown() then
return
end
self.wndFramerate:SetText(math.floor(GameLib.GetFrameRate()*10)*0.1 .. " " .. Apollo.GetString("CRB_FPS"))
end
function FloatTextPanel:OnHintArrowDistanceUpdate(fDistance)
local bShow = Apollo.GetConsoleVariable("ui.showHintArrowDistance") and fDistance ~= -1
self.wndHintArrowDistance:Show(bShow, false, bShow and 0.1 or 0.3)
if bShow then
local strMeterAppended = String_GetWeaselString(Apollo.GetString("CRB_Distance"), math.max(1, math.floor(fDistance)))
self.wndHintArrowDistance:SetText(fDistance == -1 and "" or strMeterAppended)
end
end
function FloatTextPanel:ClearFieldsMain() --clear everything
for i = 1, #self.tMainWindow do
self.tMainWindow[i]:FindChild("Text"):SetText("")
self.tMainWindow[i]:Show(false)
end
end
-----------------------------------------------------------------------------------------------
-- Secondary FloatTextPanelForm Functions
-----------------------------------------------------------------------------------------------
function FloatTextPanel:OnQuestNotice(unitTarget, strMessage, questCurr) -- uses a ML window
local strWeasel = String_GetWeaselString(Apollo.GetString("FloatText_QuestNotice"), strMessage)
local strFormatted = string.format("<P Font=\"%s\" Align=\"Center\" TextColor=\"%s\">%s</P>", kstrSubPanelFont, kcrBodyFontColor, strWeasel)
local bMatch = false
for idx, message in pairs(self.tQueueSub) do
if type(message) == "table" then
if questCurr ~= nil and message.iType == 1 and message.content ~= nil and questCurr:GetTitle() == message.content:GetTitle() then
bMatch = true
message.strMessage = strFormatted
end
end
end
if not bMatch then
self:AddToQueueSub(1, strFormatted, questCurr)
end
end
function FloatTextPanel:OnTitletNotice(strMessage)
self:AddToQueueSub(2, strMessage)
end
function FloatTextPanel:OnPlayerPathMissionUnlocked(mission) -- uses a ML window
local strMissionTitle = mission:GetName()
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFontBacked, kcrBodyFontColorBacked, strMissionTitle)
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strBody)
-- see if we already have unlock messages.
local bMatch = false
for idx, message in pairs(self.tQueueSub) do
if type(message) == "table" then
if message.iType == 3 then
bMatch = true
local strMultiple = "-- " .. Apollo.GetString("CRB_Several_New_Missions_Added") .. " --"
strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFontBacked, kcrBodyFontColorBacked, strMultiple)
strFormatted = string.format("<P Align=\"Center\">%s</P>", strBody)
message.strMessage = strFormatted
message.tContent = nil
end
end
end
if not bMatch then
self:AddToQueueSub(3, strFormatted, mission)
end
end
function FloatTextPanel:OnPlayerPathUpdated(mission) -- uses a ML window
if mission:IsComplete() == true then -- we don't care about formatting if they're complete
if self.tCompletedMissions[mission:GetName()] == true then -- TODO: Not key off the name...
return -- we've already gotten a signal for this mission
end
self.tCompletedMissions[mission:GetName()] = true
local strMissionTitle = mission:GetName()
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, strMissionTitle)
local strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_MissionCompleted"), strBody))
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strTitle)
--self:AddToQueueSub(5, strFormatted, mission)
self:HelperReplaceOrAddMission(5, strFormatted, mission, true)
else
-- Check/destroy other messages about this mission
if PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Soldier then
self:PathUpdateMessageSoldier(mission)
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Settler then
self:PathUpdateMessageSettler(mission)
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Scientist then
self:PathUpdateMessageScientist(mission)
elseif PlayerPathLib.GetPlayerPathType() == PlayerPathLib.PlayerPathType_Explorer then
self:PathUpdateMessageExplorer(mission)
else
end
end
end
function FloatTextPanel:PathUpdateMessageSoldier(mission) -- uses a ML window
local strMissionTitle = mission:GetName()
local nNumNeeded = mission:GetNumNeeded()
local nNumCompleted = mission:GetNumCompleted()
local strTitle = ""
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, String_GetWeaselString(Apollo.GetString("FloatText_MissionProgress"), strMissionTitle, nNumCompleted, nNumNeeded))
if nNumCompleted == 0 then -- mission was just activated
return
end
if mission:GetType() == PathMission.PathMissionType_Soldier_Demolition then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_DemolitionMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Soldier_Assassinate then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_AssassinateMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Soldier_SWAT then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_SWATMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Soldier_Rescue then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_RescueMission"), strBody))
else
return
end
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strTitle)
self:HelperReplaceOrAddMission(4, strFormatted, mission)
end
function FloatTextPanel:PathUpdateMessageSettler(mission) -- uses a ML window
local strMissionTitle = mission:GetName()
local nNumNeeded = mission:GetNumNeeded()
local nNumCompleted = mission:GetNumCompleted()
local strTitle = ""
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, String_GetWeaselString(Apollo.GetString("FloatText_MissionProgress"), strMissionTitle, nNumCompleted, nNumNeeded))
if nNumCompleted == 0 then -- mission was just activated
return
end
if mission:GetType() == PathMission.PathMissionType_Settler_Hub then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_HubMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Settler_Infrastructure then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_InfrastructureMission"), strBody))
else
return
end
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strTitle)
self:HelperReplaceOrAddMission(4, strFormatted, mission)
end
function FloatTextPanel:PathUpdateMessageScientist(mission) -- uses a ML window
local strMissionTitle = mission:GetName()
local nNumNeeded = mission:GetNumNeeded() -- a percent out of 100
local nNumCompleted = mission:GetNumCompleted() -- a percent out of 100
local strTitle = ""
local strBlankSpace = string.format("<T Font=\"%s\" TextColor=\"00ffffff\">%s</T>", kstrSubPanelFont, "-")
local strCount = ""
if nNumCompleted == 0 then -- mission was just activated; might not do this here since we're dealing in percents
return
end
if mission:GetType() == PathMission.PathMissionType_Scientist_Scan then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, Apollo.GetString("FloatText_ScanMission"))
strCount = String_GetWeaselString(Apollo.GetString("FloatText_MissionProgressPercent"), strMissionTitle, nNumCompleted)
elseif mission:GetType() == PathMission.PathMissionType_Scientist_ScanChecklist then -- TODO: Number based after CPP change
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, Apollo.GetString("FloatText_ChecklistMission"))
strCount = String_GetWeaselString(Apollo.GetString("FloatText_MissionProgressPercent"), strMissionTitle, nNumCompleted)
elseif mission:GetType() == PathMission.PathMissionType_Scientist_FieldStudy then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, Apollo.GetString("FloatText_FieldStudy"))
strCount = String_GetWeaselString(Apollo.GetString("FloatText_MissionProgress"), strMissionTitle, nNumCompleted, nNumNeeded)
elseif mission:GetType() == PathMission.PathMissionType_Scientist_SpecimenSurvey then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, Apollo.GetString("FloatText_SpecimenSurvey"))
strCount = String_GetWeaselString(Apollo.GetString("FloatText_MissionProgress"), strMissionTitle, nNumCompleted, nNumNeeded)
else
return
end
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, strCount)
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(strTitle, strBody))
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strTitle)
self:HelperReplaceOrAddMission(4, strFormatted, mission)
end
function FloatTextPanel:PathUpdateMessageExplorer(mission) -- uses a ML window
local strMissionTitle = mission:GetName()
local nNumNeeded = mission:GetNumNeeded()
local nNumCompleted = mission:GetNumCompleted()
local strTitle = ""
local strBlankSpace = string.format("<T Font=\"%s\" TextColor=\"00ffffff\">%s</T>", kstrSubPanelFont, "-")
local strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, String_GetWeaselString(Apollo.GetString("FloatText_MissionProgress"), strMissionTitle, nNumCompleted, nNumNeeded))
if nNumCompleted == 0 then -- mission was just activated
return
end
if mission:GetType() == PathMission.PathMissionType_Explorer_ActivateChecklist then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_ActivateChecklistMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Explorer_Area then
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_ClaimMission"), strBody))
elseif mission:GetType() == PathMission.PathMissionType_Explorer_ScavengerHunt then
strBody = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrBodyFontColor, String_GetWeaselString(Apollo.GetString("FloatText_ScavengerProgress"), strMissionTitle, nNumCompleted, nNumNeeded))
strTitle = string.format("<T Font=\"%s\" TextColor=\"%s\">%s</T>", kstrSubPanelFont, kcrPathFontColor, String_GetWeaselString(Apollo.GetString("FloatText_ScavengerMission"), strBody))
else
return
end
local strFormatted = string.format("<P Align=\"Center\">%s</P>", strTitle)
self:HelperReplaceOrAddMission(4, strFormatted, mission)
end
function FloatTextPanel:HelperReplaceOrAddMission(iType, strMessage, mission, bComplete)
-- see if we already have a message about this mission. If we do, replace it with a later one.
local bMatch = false
for idx, message in pairs(self.tQueueSub) do
if type(message) == "table" then
if message.iType == 4 and message.tContent:GetName() == mission:GetName() then
bMatch = true
message.strMessage = strMessage
if bComplete ~= nil and bComplete == true then
-- replace with type 5
message.iType = 5
end
end
end
end
if not bMatch then
self:AddToQueueSub(iType, strMessage, mission)
end
end
---------------------------------------------------------------------------------------------------
-- Secondary Timer Structure
---------------------------------------------------------------------------------------------------
function FloatTextPanel:AddToQueueSub(iAlertType, strAlertString, tAlertContent)
local t = {iType = iAlertType, strMessage = strAlertString, tContent = tAlertContent}
local nLast = self.tQueueSub.nLast + 1
self.tQueueSub.nLast = nLast
self.tQueueSub[nLast] = t
if self.bShowingAlertSub == true then
return
elseif self.bEmptyQueueSub then
-- if the queue is empty, stall to let floaters amass
Apollo.CreateTimer("FirstMessageDelaySub", kfFirstMessageDelay, false)
elseif self.bFirstMessageDelaySub then -- if the delay is set, we'll get past this when the queue re-cycles
self:ProcessAlertsSub()
end
end
function FloatTextPanel:OnFirstMessageDelaySub() -- Delay if this is the first message to give floaters time to build
self:ProcessAlertsSub()
self.bFirstMessageDelaySub = false
end
function FloatTextPanel:ProcessAlertsSub()
self:ClearFieldsSub()
local nFirst = self.tQueueSub.nFirst
if nFirst > self.tQueueSub.nLast then
self.bEmptyQueueSub = true
return
end
local t = self.tQueueSub[nFirst]
self.tQueueSub[nFirst] = nil
self.tQueueSub.nFirst = nFirst + 1
self.bEmptyQueueSub = false
self:DisplayAlertSub(t.iType, t.strMessage, t.tContent)
end
function FloatTextPanel:DisplayAlertSub(iType, strMessage, tContent)
self.iDisplayedTypeSub = iType
self.bShowingAlertSub = true
if iType == 3 then
Event_FireGenericEvent("PopupText_ShowPathAlert", strMessage, tContent)
else
self.wndSecondary:Invoke()
self.tSubWindow[iType]:Invoke()
self.tSubWindow[iType]:FindChild("Text"):SetText(strMessage)
end
self:StartMessageTimerSub(iType, tContent)
end
function FloatTextPanel:StartMessageTimerSub(iType, tContent)
local fDuration = self.tSubWindowDurations[iType]
Apollo.CreateTimer("MessageTimerSub", fDuration, false)
if not self.SubMessageHandlerSet then
Apollo.RegisterTimerHandler("MessageTimerSub", "OnMessageTimerSub", self)
self.SubMessageHandlerSet = true
end
if iType == 3 then -- mission unlocked
if tContent ~= nil then
Event_FireGenericEvent("PlayerPath_NotificationSent", 1, tContent:GetName()) -- 1 is unlock signal
else -- multiple missions
Event_FireGenericEvent("PlayerPath_NotificationSent", 1, Apollo.GetString("CRB_Several_New_Missions_Added"))
end
end
if iType == 5 then -- mission completed; 4 (progression) sends no signals
self.missionLastCompleted = tContent
if tContent ~= nil then
Event_FireGenericEvent("PlayerPath_NotificationSent", 2, tContent:GetName()) -- 2 is completed signal
else
Event_FireGenericEvent("PlayerPath_NotificationSent", 2, "")
end
end
end
function FloatTextPanel:OnMessageTimerSub()
self.wndSecondary:Show(false)
Apollo.CreateTimer("DelayExpiredSub", 0.400, false)
if not self.bDelayHandlerSetSub then
Apollo.RegisterTimerHandler("DelayExpiredSub", "OnDelayExpiredSub", self)
self.bDelayHandlerSetSub = true
end
end
function FloatTextPanel:OnDelayExpiredSub()
self.bShowingAlertSub = false
if self.iDisplayedTypeSub == 5 then -- done showing completion notice; we want to remove it from the table
self.tCompletedMissions[self.missionLastCompleted:GetName()] = nil -- cleanup our completed table
end
self:ProcessAlertsSub()
end
function FloatTextPanel:ClearFieldsSub() --clear everything
self.iDisplayedTypeSub = 0
self.missionLastCompleted = nil
for i = 1, #self.tSubWindow do
self.tSubWindow[i]:FindChild("Text"):SetText("")
self.tSubWindow[i]:Show(false)
end
end
local FloatTextPanelInst = FloatTextPanel:new()
FloatTextPanelInst:Init()