forked from Spring-Chobby/Chobby
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathconfiguration.lua
More file actions
1186 lines (1058 loc) · 34.8 KB
/
Copy pathconfiguration.lua
File metadata and controls
1186 lines (1058 loc) · 34.8 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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Configuration = LCS.class{}
VFS.Include("libs/liblobby/lobby/json.lua")
LIB_LOBBY_DIRNAME = "libs/liblobby/lobby/"
MINIMAP_THUMB_DOWNLOAD_DIR = "LuaMenu/Images/MinimapThumbnails"
-- all configuration attribute changes should use the :Set*Attribute*() and :Get*Attribute*() methods in order to assure proper functionality
function Configuration:init()
self.listeners = {}
local fileConfig
if VFS.FileExists(LUA_DIRNAME .. "configs/liblobby_configuration.lua") then
fileConfig = VFS.Include(LUA_DIRNAME .. "configs/liblobby_configuration.lua", nil, VFS.RAW_FIRST)
end
if not fileConfig.game then
Spring.Log("Chobby", LOG.WARNING, "Missing game in chobby_config.json file.")
-- FIXME: This will be changed to "generic" in future versions.
fileConfig.game = "zk"
end
--self.serverAddress = "localhost"
self.serverAddress = WG.Server.address
self.serverPort = WG.Server.port
local realWidth, realHeight = Spring.Orig.GetViewSizes()
self.uiScale = math.floor(math.max(1, realHeight/950))
self.defaultUiScale = self.uiScale
self.maxUiScale = math.max(2, realWidth/1000)
self.minUiScale = math.min(0.5, realWidth/4000)
WG.uiScale = self.uiScale
self.userListWidth = 205 -- Main user list width. Possibly configurable in the future.
self.chatMaxNameLength = 185 -- Pixels
self.statusMaxNameLength = 185
self.friendMaxNameLength = 290
self.notificationMaxNameLength = 230
self.steamOverlayEnablable = true
self.useChatTabBadges = false
self.userName = false
self.suggestedNameFromSteam = false
self.password = false
self.autoLogin = true
self.firstLoginEver = true
self.canAuthenticateWithSteam = false
self.wantAuthenticateWithSteam = true
self.useSteamBrowser = true
self.steamLinkComplete = false
self.alreadySeenFactionPopup4 = false
self.firstBattleStarted = false
self.hideWelcomeMessage = false
self.lobbyTimeoutTime = 60 -- Seconds
self.battleFilterPassworded3 = false
self.battleFilterNonFriend = false
self.battleFilterRunning = false
self.manualBorderless = {
game = {},
lobby = {},
}
self.manualFullscreen = {
game = {},
lobby = {},
}
self.manualWindowed = {
game = {},
lobby = {},
}
self.settingsToSendExternal = {
'HardwareCursor',
'ShadowMapSize',
'GroundDecals',
'MaxParticles',
'UnitLodDist',
'UnitIconDist',
'AdvUnitShading',
'snd_volmaster',
'snd_volbattle',
'snd_volui',
'snd_volunitreply',
'snd_volgeneral',
}
self.ignoreLevel = false
self.errorColor = "\255\255\0\0"
self.warningColor = "\255\255\255\0"
self.normalColor = "\255\255\255\255"
self.successColor = "\255\0\255\0"
self.partialColor = "\255\190\210\50"
self.selectedColor = "\255\99\184\255"
self.highlightedColor = "\255\125\255\0"
self.meColor = "\255\0\190\190"
self.moderatorColor = {0.68, 0.78, 1, 1}
self.founderColor = {0.7, 1, 0.65, 1}
self.ignoredUserNameColor = {0.6, 0.6, 0.6, 1}
self.userNameColor = {1, 1, 1, 1}
self.buttonFocusColor = {0.54,0.72,1,0.3}
self.buttonSelectedColor = {0.54,0.72,1,0.95}--{1.0, 1.0, 1.0, 1.0}
self.loadLocalWidgets = false
self.displayBots = false
self.displayBadEngines3 = true
self.allEnginesRunnable = true
self.doNotSetAnySpringSettings = false
self.agressivelySetBorderlessWindowed = false
self.useWrongEngine = false
self.multiplayerLaunchNewSpring = false
self.myAccountID = false
self.lastAddedAiName = false
self.noNaiveConfigOverride = {
settingsMenuValues = true,
}
self.battleTypeToName = {
[5] = "cooperative",
[6] = "team",
[3] = "oneVsOne",
[4] = "freeForAll",
[0] = "custom",
}
self.battleTypeToHumanName = {
[5] = "Coop",
[6] = "Team",
[3] = "1v1",
[4] = "FFA",
[0] = "Custom",
}
-- Do not ask again tests.
self.confirmation_mainMenuFromBattle = false
self.confirmation_battleFromBattle = false
self.leaveMultiplayerOnMainMenu = false
self.backConfirmation = {
multiplayer = {
self.leaveMultiplayerOnMainMenu and {
doNotAskAgainKey = "confirmation_mainMenuFromBattle",
question = "You are in a battle and will leave it if you return to the main menu. Are you sure you want to return to the main menu?",
testFunction = function ()
local battleID = lobby:GetMyBattleID()
if not battleID then
return false
end
if self.showMatchMakerBattles then
return true
end
local battle = lobby:GetBattle(battleID)
return (battle and not battle.isMatchMaker) or false
end
} or nil
},
singleplayer = {
}
}
local gameConfPath = LUA_DIRNAME .. "configs/gameConfig/"
self.gameConfigName = fileConfig.game
self:LoadGameConfig(gameConfPath .. self.gameConfigName .. "/mainConfig.lua")
self.campaignPath = "campaign/sample"
self.campaignConfigName = "sample"
self.campaignConfig = VFS.Include("campaign/sample/mainConfig.lua")
self.campaignSaveFile = nil -- Set by user
self.nextCampaignSaveNumber = 1
self.campaignConfigOptions = {
"sample",
"--dev"
}
self.campaignConfigHumanNames = {
"Sample",
--"Dev"
}
local gameConfigOptions = {}
local subdirs = VFS.SubDirs(gameConfPath)
for index, subdir in ipairs(subdirs) do
-- get just the folder name
subdir = string.gsub(subdir, gameConfPath, "")
subdir = string.sub(subdir, 1, -2) -- truncate trailing slash
Spring.Log(LOG_SECTION, LOG.NOTICE, "Detected game config", subdir)
gameConfigOptions[#gameConfigOptions+1] = subdir
end
self.gameConfigOptions = {}
self.gameConfigHumanNames = {}
for i = 1, #gameConfigOptions do
local fileName = gameConfPath .. gameConfigOptions[i] .. "/mainConfig.lua"
Spring.Log(LOG_SECTION, LOG.INFO, "Attempting to load game config: " .. fileName)
if VFS.FileExists(fileName) then
Spring.Log(LOG_SECTION, LOG.INFO, "Game config found:" .. fileName)
local gameConfig = VFS.Include(fileName, nil, VFS.RAW_FIRST)
if gameConfig.CheckAvailability() then
self.gameConfigHumanNames[#self.gameConfigHumanNames + 1] = gameConfig.name
self.gameConfigOptions[#self.gameConfigOptions + 1] = gameConfigOptions[i]
end
else
Spring.Log(LOG_SECTION, LOG.WARNING, "Game config not found: " .. fileName)
end
end
self.lastLoginChatLength = 25
self.notifyForAllChat = true
self.autosaveOnMatchmaker = true
self.planetwarsNotifications2 = false -- Possibly too intrusive? See how it goes.
self.ingameNotifcations = true -- Party, chat
self.nonFriendNotifications = true -- Party, chat
self.friendNotifyIngame = true
self.simplifiedSkirmishSetup = true
self.debugMode = false
self.devMode = VFS.FileExists("devmode.txt") or VFS.FileExists("devmode.txt.txt")
self.debugRawMessages = false
self.enableProfiler = false
self.showPlanetUnlocks = false
self.showPlanetCodex = false
self.showPlanetMinimap = false
self.showPlanetEnemyUnits = false
self.campaignSpawnDebug = false
self.editCampaign = false
self.activeDebugConsole = false
self.debugLobbyGameChat = false
self.onlyShowFeaturedMaps = true
self.showFullModList = false
self.simpleAiList2 = true
self.enableDebugBuffer = false
self.useSpringRestart = false
self.menuMusicVolume = 0.5
self.menuNotificationVolume = 0.8
self.menuBackgroundBrightness = 1
self.gameOverlayOpacity = 0.5
self.coopConnectDelay = 5
self.showMatchMakerBattles = false
self.hideInterface = false
self.enableTextToSpeech = true
self.showOldAiVersions = false
self.drawAtFullSpeed = false
self.lobbyIdleSleep = false
self.rememberQueuesOnStart2 = true
self.blockedJoinBattles = false
self.channels = {}
if self.gameConfig.defaultChatChannels ~= nil then
for _, channelName in ipairs(self.gameConfig.defaultChatChannels) do
self.channels[channelName] = true
end
end
self.language = "en"
self.languages = {
["en"] = {locale = "en", name="English"},
["de"] = {locale = "de", name="Deutsch (unvollständig)"},
["it"] = {locale = "it", name="Italiano"},
["ru"] = {locale = "ru", name="Russian (Русский)"},
}
self.lobby_fullscreen = 1
self.game_fullscreen = 1
self.chatFontSize = 18
self.fontName = "LuaMenu/widgets/chili/skins/Evolved/fonts/n019003l.pfb"
self.fontRaw = {
[0] = {size = 10, shadow = false},
[1] = {size = 14, shadow = false},
[2] = {size = 18, shadow = false},
[3] = {size = 22, shadow = false},
[4] = {size = 32, shadow = false},
[5] = {size = 48, shadow = false},
}
self.fontSpecial = {}
self.font = {}
for i = 0, #self.fontRaw do
self.font[i] = WG.Chili.Font:New {
size = self.fontRaw[i].size,
font = self.fontName,
color = {1,1,1,1},
outlineColor = {0.05,0.05,0.05,0.9},
outline = false,
shadow = false,
}
end
self.configParamTypes = {}
for _, param in pairs(Spring.GetConfigParams()) do
self.configParamTypes[param.name] = param.type
end
self.AtiIntelSettingsOverride = {
AdvSky = 0,
VSync = 1,
FSAA = 0,
MSAALevel = 0,
SmoothLines = 0,
SmoothPoints = 0,
}
self.countryShortnames = VFS.Include(LUA_DIRNAME .. "configs/countryShortname.lua")
if self.gameConfig.springSettingsPath ~= nil then
self.game_settings = VFS.Include(self.gameConfig.springSettingsPath)
else
self.game_settings = VFS.Include(LUA_DIRNAME .. "configs/springsettings/springsettings.lua")
end
self.forcedCompatibilityProfile = VFS.Include(LUA_DIRNAME .. "configs/springsettings/forcedCompatibilityProfile.lua")
local default = self.gameConfig.SettingsPresetFunc and self.gameConfig.SettingsPresetFunc()
if default then
self.settingsMenuValues = {}
for name, defValue in pairs(default) do
self:SetSettingsConfigOption(name, defValue)
end
else
self.settingsMenuValues = self.gameConfig.settingsDefault -- Only until configuration data is loaded.
end
self.animate_lobby = (gl.CreateShader ~= nil)
self.minimapDownloads = {}
self.minimapDownloadStarted = {}
self.downloadRetryCount = 3
local saneCharacterList = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "[", "]", "_",
}
self.saneCharacters = {}
for i = 1, #saneCharacterList do
self.saneCharacters[saneCharacterList[i]] = true
end
-- UI Styling globals that are really not config, but need to be somewhere.
WG.TOP_LABEL_Y = 16
WG.TOP_BUTTON_Y = 8
WG.BUTTON_HEIGHT = 41
end
---------------------------------------------------------------------------------
-- Settings
---------------------------------------------------------------------------------
function Configuration:LoadGameConfig(path)
self.gameConfig = VFS.Include(path)
if type(self.gameConfig) ~= 'table' then
Spring.Log("Settings", LOG.ERROR, 'Chobby configuration error. Returned game config is not a table: ' .. tostring(path))
return
end
local mandatoryFields = {"settingsNames"}
for _, mandatoryField in ipairs(mandatoryFields) do
if self.gameConfig[mandatoryField] == nil then
Spring.Log("Settings", LOG.ERROR, "Chobby configuration error. Mandatory field is missing: " .. mandatoryField .. ". Check your game settings")
end
end
localLobby.useTeamColor = not self.gameConfig.disableColorChoosing
end
function Configuration:SetSpringsettingsValue(key, value, compatOverride)
if self.doNotSetAnySpringSettings then
return
end
if not compatOverride then
local compatProfile = self.forcedCompatibilityProfile
if compatProfile and compatProfile[key] then
return
end
end
value = (self.fixedSettingsOverride and self.fixedSettingsOverride[key]) or value
local configType = self.configParamTypes[key]
if configType == "int" then
Spring.Echo("SetSettings Int", key, value)
Spring.SetConfigInt(key, value)
elseif configType == "bool" or configType == "float" then
Spring.Echo("SetSettings Value", key, value)
Spring.SetConfigString(key, value)
elseif configType == nil then
Spring.Log("Settings", LOG.WARNING, "No such key: " .. tostring(key) .. ", but setting it as string anyway.")
Spring.SetConfigString(key, value)
else
Spring.Log("Settings", LOG.WARNING, "Unexpected key type: " .. configType .. ", but setting it as string anyway.")
Spring.SetConfigString(key, value)
end
end
function Configuration:UpdateFixedSettings(newOverride)
local gameSettings = self.game_settings
-- Reset old
local oldOverride = self.fixedSettingsOverride
self.fixedSettingsOverride = nil
if oldOverride then
for key, value in pairs(oldOverride) do
if gameSettings[key] then
self:SetSpringsettingsValue(key, gameSettings[key])
end
end
end
-- Apply new
self.fixedSettingsOverride = newOverride
if newOverride then
for key, value in pairs(newOverride) do
self:SetSpringsettingsValue(key, value)
end
end
end
function Configuration:SetSettingsConfigOption(name, newValue)
local setting = self.gameConfig.settingsNames[name]
if not setting then
return false
end
self.settingsMenuValues[name] = newValue
if setting.isNumberSetting then
local applyFunction = setting.applyFunction
if applyFunction then
local applyData = applyFunction(newValue, self)
if applyData then
for applyName, value in pairs(applyData) do
self.game_settings[applyName] = value
self:SetSpringsettingsValue(applyName, value)
end
end
else
local springValue = setting.springConversion(newValue)
self.game_settings[setting.applyName] = springValue
self:SetSpringsettingsValue(setting.applyName, springValue)
end
else
if setting.optionNames == nil or (not setting.optionNames[newValue]) then
return false
end
-- Selection from multiple options
local selectedOption = setting.optionNames[newValue]
if setting.fileTarget then
self.settingsMenuValues[name .. "_file"] = selectedOption.file
if setting.applyFunction then
setting.applyFunction(selectedOption.file, self)
else
local sourceFile = VFS.LoadFile(selectedOption.file)
local settingsFile = io.open(setting.fileTarget, "w")
settingsFile:write(sourceFile)
settingsFile:close()
end
else
local applyData = selectedOption.apply or (selectedOption.applyFunction and selectedOption.applyFunction(nil, self))
if not applyData then
return true
end
for applyName, value in pairs(applyData) do
self.game_settings[applyName] = value
self:SetSpringsettingsValue(applyName, value)
end
end
end
return true
end
function Configuration:ApplySettingsConfigPreset(preset)
for name, value in pairs(preset) do
self:SetSettingsConfigOption(name, value)
end
end
function Configuration:SetTutorialComplete()
self.hideWelcomeMessage = true
end
---------------------------------------------------------------------------------
-- Widget interface callins
---------------------------------------------------------------------------------
function Configuration:SetConfigData(data)
if data.campaignConfigName == "dev" then
data.campaignConfigName = "sample"
end
if data ~= nil then
for k, v in pairs(data) do
if not self.noNaiveConfigOverride[k] then
self:SetConfigValue(k, v)
end
end
end
-- Fix old channel memory.
for key, value in pairs(self.channels) do
if string.find(key, "debriefing") or string.find(key, "party_") then
self.channels[key] = nil
end
end
self.game_settings.XResolutionWindowed = nil
self.game_settings.YResolutionWindowed = nil
self.game_settings.WindowPosX = nil
self.game_settings.WindowPosY = nil
self.game_settings.WindowBorderless = nil
self.game_settings.Fullscreen = nil
-- Fix old memory
self.game_settings.UnitIconDist = nil
if self.serverAddress == "zero-k.com" then
self.serverAddress = "zero-k.info"
end
local newSpringsettings, onlyIfMissingSettings, onlyIfOutdated, onlyIfValueBelow, settingsVersion = VFS.Include(LUA_DIRNAME .. "configs/springsettings/springsettingsChanges.lua")
for key, value in pairs(newSpringsettings) do
self.game_settings[key] = value
end
for key, value in pairs(onlyIfMissingSettings) do
if self.game_settings[key] == nil then
self.game_settings[key] = value
end
end
for key, value in pairs(onlyIfValueBelow) do
if self.game_settings[key] == nil then
self.game_settings[key] = value
end
if self.game_settings[key] < value then
self.game_settings[key] = value
end
end
if (self.lobbySettingsVersion or 0) < 1 then
self.settingsMenuValues.InterfaceScale = nil -- Reset the setting
end
self.lobbySettingsVersion = 1
if (self.settingsVersion or 0) < settingsVersion then
for key, value in pairs(onlyIfOutdated) do
self.game_settings[key] = value
end
self.settingsVersion = settingsVersion
end
if data.settingsMenuValues then
for name, value in pairs(data.settingsMenuValues) do
self:SetSettingsConfigOption(name, value)
end
end
end
function Configuration:GetConfigData()
return {
serverAddress = self.serverAddress,
serverPort = self.serverPort,
userName = self.userName,
suggestedNameFromSteam = self.suggestedNameFromSteam,
uiScale = self.uiScale,
password = self.password,
autoLogin = self.autoLogin,
firstLoginEver = self.firstLoginEver,
wantAuthenticateWithSteam = self.wantAuthenticateWithSteam,
hideWelcomeMessage = self.hideWelcomeMessage,
useSteamBrowser = self.useSteamBrowser,
steamLinkComplete = self.steamLinkComplete,
alreadySeenFactionPopup4 = self.alreadySeenFactionPopup4,
firstBattleStarted = self.firstBattleStarted,
battleFilterPassworded3 = self.battleFilterPassworded3,
battleFilterNonFriend = self.battleFilterNonFriend,
battleFilterRunning = self.battleFilterRunning,
channels = self.channels,
gameConfigName = self.gameConfigName,
language = self.language,
game_fullscreen = self.game_fullscreen,
panel_layout = self.panel_layout,
lobby_fullscreen = self.lobby_fullscreen,
manualBorderless = self.manualBorderless,
manualFullscreen = self.manualFullscreen,
manualWindowed = self.manualWindowed,
animate_lobby = self.animate_lobby,
game_settings = self.game_settings,
notifyForAllChat = self.notifyForAllChat,
planetwarsNotifications2 = self.planetwarsNotifications2,
ingameNotifcations = self.ingameNotifcations,
nonFriendNotifications = self.nonFriendNotifications,
friendNotifyIngame = self.friendNotifyIngame,
simplifiedSkirmishSetup = self.simplifiedSkirmishSetup,
debugMode = self.debugMode,
debugAutoWin = self.debugAutoWin,
debugRawMessages = self.debugRawMessages,
enableProfiler = self.enableProfiler,
showPlanetUnlocks = self.showPlanetUnlocks,
showPlanetCodex = self.showPlanetCodex,
showPlanetMinimap = self.showPlanetMinimap,
showPlanetEnemyUnits = self.showPlanetEnemyUnits,
campaignSpawnDebug = self.campaignSpawnDebug,
editCampaign = self.editCampaign,
confirmation_mainMenuFromBattle = self.confirmation_mainMenuFromBattle,
confirmation_battleFromBattle = self.confirmation_battleFromBattle,
drawAtFullSpeed = self.drawAtFullSpeed,
lobbyIdleSleep = self.lobbyIdleSleep,
rememberQueuesOnStart2 = self.rememberQueuesOnStart2,
blockedJoinBattles = self.blockedJoinBattles,
queue_handicap = self.queue_handicap,
queue_wide = self.queue_wide,
loadLocalWidgets = self.loadLocalWidgets,
activeDebugConsole = self.activeDebugConsole,
debugLobbyGameChat = self.debugLobbyGameChat,
onlyShowFeaturedMaps = self.onlyShowFeaturedMaps,
showFullModList = self.showFullModList,
simpleAiList2 = self.simpleAiList2,
coopConnectDelay = self.coopConnectDelay,
useSpringRestart = self.useSpringRestart,
displayBots = self.displayBots,
displayBadEngines3 = self.displayBadEngines3,
useWrongEngine = self.useWrongEngine,
multiplayerLaunchNewSpring = self.multiplayerLaunchNewSpring,
doNotSetAnySpringSettings = self.doNotSetAnySpringSettings,
agressivelySetBorderlessWindowed = self.agressivelySetBorderlessWindowed,
fixedSettingsOverride = self.fixedSettingsOverride,
settingsMenuValues = self.settingsMenuValues,
menuMusicVolume = self.menuMusicVolume,
menuNotificationVolume = self.menuNotificationVolume,
menuBackgroundBrightness = self.menuBackgroundBrightness,
gameOverlayOpacity = self.gameOverlayOpacity,
showMatchMakerBattles = self.showMatchMakerBattles,
matchmakerRejectTime = self.matchmakerRejectTime,
matchmakerRejectCount = self.matchmakerRejectCount,
matchmakerPopupTime = self.matchmakerPopupTime,
enableTextToSpeech = self.enableTextToSpeech,
showOldAiVersions = self.showOldAiVersions,
chatFontSize = self.chatFontSize,
myAccountID = self.myAccountID,
lastAddedAiName = self.lastAddedAiName,
window_WindowPosX = self.window_WindowPosX,
window_WindowPosY = self.window_WindowPosY,
window_XResolutionWindowed = self.window_XResolutionWindowed,
window_YResolutionWindowed = self.window_YResolutionWindowed,
campaignSaveFile = self.campaignSaveFile,
nextCampaignSaveNumber = self.nextCampaignSaveNumber,
steamReleasePopupSeen = self.steamReleasePopupSeen,
campaignConfigName = self.campaignConfigName,
settingsVersion = self.settingsVersion,
lobbySettingsVersion = self.lobbySettingsVersion,
}
end
---------------------------------------------------------------------------------
-- Setters
---------------------------------------------------------------------------------
function Configuration:SetConfigValue(key, value)
if self[key] == value then
return
end
self[key] = value
if key == "useSpringRestart" then
lobby.useSpringRestart = value
localLobby.useSpringRestart = value
end
if key == "disableColorChoosing" then
localLobby.useTeamColor = not value
end
if key == "uiScale" then
self[key] = math.max(self.minUiScale, math.min(self.maxUiScale, value))
WG.uiScale = self[key]
local screenWidth, screenHeight = Spring.GetViewSizes()
screen0:Resize(screenWidth, screenHeight)
end
if key == "gameConfigName" then
self:LoadGameConfig(LUA_DIRNAME .. "configs/gameConfig/" .. value .. "/mainConfig.lua")
end
if key == "campaignConfigName" then
self.campaignPath = "campaign/" .. value
self.campaignConfig = VFS.Include("campaign/" .. value .. "/mainConfig.lua")
end
self:_CallListeners("OnConfigurationChange", key, value)
end
---------------------------------------------------------------------------------
-- Getters
---------------------------------------------------------------------------------
function Configuration:IsLobbyVisible()
return WG.Chobby.interfaceRoot.GetLobbyInterfaceHolder().visible
end
function Configuration:GetServerAddress()
if self.ForceDefaultServer then
return self.DefaultServerHost
end
return self.serverAddress
end
function Configuration:GetServerPort()
if self.ForceDefaultServer then
return self.DefaultServerPort
end
return self.serverPort
end
function Configuration:GetErrorColor()
return self.errorColor
end
function Configuration:GetWarningColor()
return self.warningColor
end
function Configuration:GetNormalColor()
return self.normalColor
end
function Configuration:GetSuccessColor()
return self.successColor
end
function Configuration:GetPartialColor()
return self.partialColor
end
function Configuration:GetSelectedColor()
return self.selectedColor
end
function Configuration:GetHighlightedColor()
return self.highlightedColor
end
function Configuration:GetButtonFocusColor()
return self.buttonFocusColor
end
function Configuration:GetModeratorColor()
return self.moderatorColor
end
function Configuration:GetFounderColor()
return self.founderColor
end
function Configuration:GetIgnoredUserNameColor()
return self.ignoredUserNameColor
end
function Configuration:GetUserNameColor()
return self.userNameColor
end
-- NOTE: this one is in opengl range [0,1]
function Configuration:GetButtonSelectedColor()
return self.buttonSelectedColor
end
function Configuration:GetChannels()
return self.channels
end
function Configuration:GetCross()
return self:GetErrorColor() .. "X"
end
function Configuration:GetTick()
return self:GetSuccessColor() .. "O"
end
function Configuration:GetFont(sizeScale, specialName, specialData, rawSize)
if not specialName and not rawSize then
return self.font[sizeScale]
end
local size = (rawSize and sizeScale) or self.fontRaw[sizeScale].size
if not self.fontSpecial[size] then
self.fontSpecial[size] = {}
end
if not self.fontSpecial[size][specialName] then
specialData = specialData or {}
specialData.font = self.fontName
specialData.size = size
specialData.color = specialData.color or {1,1,1,1}
specialData.outlineColor = specialData.outlineColor or {0.05,0.05,0.05,0.9}
specialData.outline = specialData.outline or false
specialData.shadow = specialData.shadow or false
self.fontSpecial[size][specialName] = WG.Chili.Font:New(specialData)
end
return self.fontSpecial[size][specialName]
end
function Configuration:GetHintFont(sizeScale, specialName, specialData, rawSize)
specialName = (specialName or "") .. "_hint_" .. sizeScale
specialData = specialData or {}
specialData.color = {1,1,1,0.48}
return self:GetFont(sizeScale, specialName, specialData, rawSize)
end
function Configuration:GetButtonFont(sizeScale, specialName, specialData, rawSize)
specialName = (specialName or "") .. "_button_" .. sizeScale
specialData = specialData or {}
specialData.outline = true
specialData.outlineWidth = 2
specialData.outlineHeight = 3
return self:GetFont(sizeScale, specialName, specialData, rawSize)
end
function Configuration:AllowNotification(playerName, playerList)
if (not self.ingameNotifcations) and (Spring.GetGameName() ~= "") then
return false
end
if lobby and not self.nonFriendNotifications then
if playerName then
local userInfo = lobby:TryGetUser(playerName)
if not userInfo.isFriend then
return false
end
end
if playerList then
local foundFriend = false
for i = 1, #playerList do
local userInfo = lobby:TryGetUser(playerList[i])
if userInfo.isFriend then
foundFriend = true
break
end
end
if not foundFriend then
return false
end
end
end
return true
end
function Configuration:ImageFileExists(filePath)
if not VFS.FileExists(filePath) then
return false
end
local data = gl.TextureInfo(filePath)
return data and data.ysize ~= -1
end
function Configuration:GetMinimapSmallImage(mapName)
mapName = string.gsub(mapName, "[^a-zA-Z0-9%-%(%)%.]", "_")
local filePath = self.gameConfig.minimapThumbnailPath .. mapName .. ".png"
if self:ImageFileExists(filePath) then
return filePath, false
end
filePath = MINIMAP_THUMB_DOWNLOAD_DIR .. mapName .. ".jpg"
if self:ImageFileExists(filePath) then
return filePath, false
end
if not self.minimapDownloadStarted[mapName] and WG.WrapperLoopback and WG.WrapperLoopback.DownloadImage then
Spring.CreateDir(MINIMAP_THUMB_DOWNLOAD_DIR)
WG.WrapperLoopback.DownloadImage({ImageUrl = "https://zero-k.info/Resources/" .. mapName .. ".thumbnail.jpg", TargetPath = filePath})
self.minimapDownloadStarted[mapName] = true
end
return filePath, true
end
function Configuration:GetMinimapImage(mapName)
if not self.gameConfig.minimapOverridePath then
return LUA_DIRNAME .. "images/minimapNotFound1.png"
end
mapName = string.gsub(mapName, "[^a-zA-Z0-9%-%(%)%.]", "_")
local filePath = self.gameConfig.minimapOverridePath .. mapName .. ".jpg"
if not self:ImageFileExists(filePath) then
filePath = "LuaMenu/Images/Minimaps/" .. mapName .. ".jpg"
end
if WG.WrapperLoopback and WG.WrapperLoopback.DownloadImage and (not self:ImageFileExists(filePath)) then
if not self.minimapDownloads[mapName] then
Spring.CreateDir("LuaMenu/Images/Minimaps")
WG.WrapperLoopback.DownloadImage({ImageUrl = "https://zero-k.info/Resources/" .. mapName .. ".minimap.jpg", TargetPath = filePath})
self.minimapDownloads[mapName] = true
end
return filePath, true
end
return filePath
end
function Configuration:GetModoptions(gameName)
if not (gameName and VFS.HasArchive(gameName)) then
Spring.Log(LOG_SECTION, LOG.ERROR, "Missing game archive, cannot fetch modoptions")
return false
end
local function ReadModoptions()
if not VFS.FileExists("modoptions.lua", VFS.ZIP) then
return false
end
return VFS.Include("modoptions.lua", nil, VFS.ZIP)
end
local alreadyLoaded = false
for _, archive in pairs(VFS.GetLoadedArchives()) do
if archive == gameName then
alreadyLoaded = true
break
end
end
if alreadyLoaded then
return VFS.Include("modoptions.lua", nil, VFS.ZIP)
end
return VFS.UseArchive(gameName, ReadModoptions)
end
function Configuration:GetLoadingImage(size)
if size == 1 then
return LUA_DIRNAME .. "images/load_img_32.png"
elseif size == 2 then
return LUA_DIRNAME .. "images/load_img_128.png"
elseif size == 3 then
return LUA_DIRNAME .. "images/load_img_512.png"
end
return LUA_DIRNAME .. "images/load_img_128.png"
end
function Configuration:GetCountryLongname(shortname)
if shortname and self.countryShortnames[shortname] then
return self.countryShortnames[shortname]
end
return shortname
end
function Configuration:GetHeadingImage(fullscreenMode, title)
local subheadings = self.gameConfig.subheadings
if fullscreenMode then
return (subheadings and subheadings.large and subheadings.large[title]) or self.gameConfig.headingLarge
else
return (subheadings and subheadings.small and subheadings.small[title]) or self.gameConfig.headingSmall
end
end
function Configuration:GetTruncatedEngineVersion(overrideEngineName)
local engineVer = overrideEngineName or Spring.Utilities.GetEngineVersion()
if tonumber(engineVer) then
-- Master releases lack the '.0' at the end. Who knows what other cases are wrong.
-- Add as required.
return (engineVer .. ".0")
else
return string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(engineVer, " BAR105", ""), " BAR", ""), "Spring ", ""), " maintenance", ""), " develop", "")
end
end
function Configuration:IsValidEngineVersion(engineVersion)
return engineVersion == Spring.Utilities.GetEngineVersion() or engineVersion == self:GetTruncatedEngineVersion()
end
function Configuration:IsCurrentVersionNewerThan(rel, dev)
-- Argument example, <rel>.0.1-<dev>-g5072695
local thisVersion = self:GetTruncatedEngineVersion()
local thisRel, thisDev
local i = 1
for word in thisVersion:gmatch("[^%-]+") do
if i == 1 then
local j = 1
for subword in word:gmatch("[^%.]+") do
if j == 1 then
thisRel = tonumber(subword)
if thisRel then
if thisRel < rel then
return false
end
if thisRel > rel then
return true
end
end
end
j = j + 1
end
elseif i == 2 then
thisDev = tonumber(word)
if thisDev then
return thisDev > dev
end
end
i = i + 1
end
return false -- A newer version would not fail to return before now
end
function Configuration:SanitizeName(name, usedNames)
local ret = ""
local length = string.len(name)
Spring.Echo("SanitizeName", name)
for i = 1, length do
local c = string.sub(name, i, i)
if self.saneCharacters[c] then
ret = ret .. c
end
end