forked from beyond-all-reason/BYAR-Chobby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_battle_room_window.lua
More file actions
3602 lines (3172 loc) · 100 KB
/
gui_battle_room_window.lua
File metadata and controls
3602 lines (3172 loc) · 100 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
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Battle Room Window",
desc = "Battle Room Window handler.",
author = "GoogleFrog",
date = "30 June 2016",
license = "GNU LGPL, v2.1 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Local variables
-- Chili controls
local mainWindow
-- Globals
local battleLobby
local wrapperControl
local mainWindowFunctions
local showDefaultStartCheckbox = false
local currentStartRects = {}
local singleplayerWrapper
local multiplayerWrapper
local spadsStatusPanel
local barManagerPresent
local singleplayerGame = "Chobby $VERSION"
local IMG_READY = LUA_DIRNAME .. "images/ready.png"
local IMG_UNREADY = LUA_DIRNAME .. "images/unready.png"
local IMG_LINK = LUA_DIRNAME .. "images/link.png"
local MINIMUM_QUICKPLAY_PLAYERS = 4 -- Hax until the server tells me a number.
local lastUserToChangeStartBoxes = ''
local readyButton
local btnStartBattle = nil
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Download management
local emptyTeamIndex = 0
local haveMapAndGame = false
local function HasGame(gameName)
return VFS.HasArchive(gameName)
end
local function UpdateArchiveStatus(updateSync)
if not battleLobby or not battleLobby:GetMyBattleID() then
return
end
local battle = battleLobby:GetBattle(battleLobby:GetMyBattleID())
if not battle then
haveMapAndGame = false
return
end
local haveGame = HasGame(battle.gameName)
local haveMap = VFS.HasArchive(battle.mapName)
if mainWindowFunctions and mainWindowFunctions.GetInfoHandler() then
local infoHandler = mainWindowFunctions.GetInfoHandler()
infoHandler.SetHaveGame(haveGame)
infoHandler.SetHaveMap(haveMap)
end
haveMapAndGame = (haveGame and haveMap)
if btnStartBattle then
if haveMapAndGame then
btnStartBattle.tooltip = "Start the game, or call a vote to start multiplayer, or join a running game"
ButtonUtilities.SetButtonDeselected(btnStartBattle)
else
btnStartBattle.tooltip = "Please wait for downloads to finish before starting."
ButtonUtilities.SetButtonDeselected(btnStartBattle)
end
end
if updateSync and battleLobby then
battleLobby:SetBattleStatus({
sync = (haveMapAndGame and 1) or 2, -- 0 = unknown, 1 = synced, 2 = unsynced
})
end
end
local function MaybeDownloadGame(battle)
WG.DownloadHandler.MaybeDownloadArchive(battle.gameName, "game", -1)
end
local function MaybeDownloadMap(battle)
WG.DownloadHandler.MaybeDownloadArchive(battle.mapName, "map", -1)
end
local OpenNewTeam
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Chili/interface management
local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUserName)
local config = WG.Chobby.Configuration
local minimapBottomClearance = 160
local currentMapName
local mapLinkWidth = 150
currentStartRects = {}
local externalFunctions = {}
local btnMapLink = Button:New {
x = 3,
y = 0,
right = 3,
height = 20,
classname = "button_square",
caption = "",
padding = {0, 0, 0, 0},
parent = rightInfo,
--tooltip = "Choose a different map",
OnClick = {
function ()
if currentMapName and config.gameConfig.link_particularMapPage ~= nil then
WG.BrowserHandler.OpenUrl(config.gameConfig.link_particularMapPage(currentMapName))
end
end
}
}
local startBoxPanel = Control:New{
x = 0,
y = 22,
width = "100%",
height = 25,
padding = {0,0,0,0},
parent = rightInfo,
}
-- the buttons needed are:
-- splitV , splitH, splitC1_2, splitC2_2, split4, add, remove
local btnSplitV = Button:New{
x = "0%",
bottom = 0,
width = "12%",
height = "100%",
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
parent = startBoxPanel,
tooltip = "Split start boxes left vs right",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 50,
caption = "Change start boxes",
labelCaption = "Split the map start boxes vertically, with X percent of the map going to left and right start boxes.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_v.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 0, integervalue *2, 200)
externalFunctions.AddStartRect(1, 200 - integervalue *2, 0, 200, 200)
else
battleLobby:SayBattle("!split v "..tostring(integervalue))
end
end
})
end
}
}
local imSplitV = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_v.png",
parent = btnSplitV,
tooltip = btnSplitV.tooltip,
}
local btnSplitH = Button:New{
x = "12.5%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Split start boxes top vs bottom",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 50,
caption = "Change start boxes",
labelCaption = "Split the map start boxes horizontally, with X percent of the map going to top and bottom start boxes.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_h.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 0, 200, integervalue * 2)
externalFunctions.AddStartRect(1, 0, 200 - integervalue *2, 200, 200)
else
battleLobby:SayBattle("!split h "..tostring(integervalue))
end
end
})
end
}
}
local imSplitH = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_h.png",
parent = btnSplitH,
tooltip = btnSplitH.tooltip,
}
local btnSplitC1 = Button:New{
x = "25%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Split start boxes top left vs bottom right",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 50,
caption = "Change start boxes",
labelCaption = "Split the map start boxes along the corners, with X percent of the map going to top left and bottom right start boxes.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_c1.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 0, integervalue *2, integervalue * 2)
externalFunctions.AddStartRect(1, 200 - integervalue *2, 200 - integervalue *2, 200, 200)
else
battleLobby:SayBattle("!split c1 "..tostring(integervalue))
end
end
})
end
}
}
local imSplitC1 = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_c1.png",
parent = btnSplitC1,
tooltip = btnSplitC1.tooltip,
}
local btnSplitC2 = Button:New{
x = "37.5%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Split start boxes bottom left vs top right",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 50,
caption = "Change start boxes",
labelCaption = "Split the map start boxes along the corners, with X percent of the map going to bottom left and top right start boxes.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_c2.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200)
externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 )
else
battleLobby:SayBattle("!split c2 "..tostring(integervalue))
end
end
})
end
}
}
local imSplitC2 = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_c2.png",
parent = btnSplitC2,
tooltip = btnSplitC2.tooltip,
}
local btnSplitC4 = Button:New{
x = "50%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Split start boxes into 4 corners for 4 teams",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 50,
caption = "Change start boxes",
labelCaption = "Split the map start boxes along the corners, with X percent of the map going to all 4 corners.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_c.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 200- integervalue*2 , integervalue *2, 200)
externalFunctions.AddStartRect(1, 200-integervalue *2, 0, 200, integervalue *2 )
externalFunctions.AddStartRect(2, 0, 0, integervalue *2, integervalue * 2)
externalFunctions.AddStartRect(3, 200 - integervalue *2, 200 - integervalue *2, 200, 200)
else
battleLobby:SayBattle("!split c "..tostring(integervalue))
end
end
})
end
}
}
local imSplitC4 = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_c.png",
parent = btnSplitC4,
tooltip = btnSplitC4.tooltip,
}
local btnSplitS4 = Button:New{
x = "62.5%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Split start boxes into 4 sides for 4 teams",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
WG.IntegerSelectorWindow.CreateIntegerSelectorWindow({
defaultValue = 20,
minValue = 3,
maxValue = 33,
caption = "Change start boxes",
labelCaption = "Split the map start boxes along the sides, with X percent of the map going to all 4 sides.",
imageFile = LUA_DIRNAME .. "images/startboxsplit_s.png",
OnAccepted = function(integervalue)
if battleLobby.name == "singleplayer" then
externalFunctions.RemoveStartRect()
externalFunctions.AddStartRect(0, 0, 100 - integervalue , integervalue *2, 100 + integervalue)
externalFunctions.AddStartRect(1, 200-integervalue *2, 100-integervalue, 200, 100 + integervalue)
externalFunctions.AddStartRect(2, 100 - integervalue , 0, 100 + integervalue, integervalue * 2)
externalFunctions.AddStartRect(3, 100 - integervalue , 200 - integervalue *2, 100+ integervalue, 200)
else
battleLobby:SayBattle("!split s "..tostring(integervalue))
end
end
})
end
}
}
local imSplitS4 = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_s.png",
parent = btnSplitS4,
tooltip = btnSplitS4.tooltip,
}
local btnAddBox = Button:New{
x = "75%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Add a new start box in the center",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
if battleLobby.name == "singleplayer" then
externalFunctions.AddStartRect(#currentStartRects,66, 66, 133, 133)
else
battleLobby:SayBattle("!addbox 66 66 133 133")
end
end
}
}
local imAddBox = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_add.png",
parent = btnAddBox,
tooltip = btnAddBox.tooltip,
}
local btnClearBox = Button:New{
x = "87.5%",
bottom = 0,
width = '12%',
height = "100%",
parent = startBoxPanel,
classname = "option_button",
caption = "",
padding = {0, 0, 0, 0},
tooltip = "Remove last start box",
OnClick = {
function ()
local battleStatus = battleLobby:GetUserBattleStatus(myUserName) or {}
if battleStatus.isSpectator then
return
end
if battleLobby.name == "singleplayer" then
if #currentStartRects > 0 then
externalFunctions.RemoveStartRect(#currentStartRects -1)
end
else
battleLobby:SayBattle("!clearbox ".. tostring(#currentStartRects))
end
end
}
}
local imClearBox = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false,
file = LUA_DIRNAME .. "images/startboxsplit_remove.png",
parent = btnClearBox,
tooltip = btnClearBox.tooltip,
}
local function UpdateStartRectPositionsInMinimap(width)
for i, rect in pairs(currentStartRects) do
-- FIXME: THIS IS IMPORTANt
--Spring.Log("Chobby",LOG.WARNING,"start rect resized",width, height,obj.x, obj.y) --this works!
--obj.x = math.max(0, math.min(obj.parent.width - obj.minWidth, obj.x))
--obj.y = math.max(0, math.min(obj.parent.height - obj.minHeight, obj.y))
--obj.width = math.max(obj.minWidth ,math.min(obj.parent.width - obj.x, obj.width))
--obj.height= math.max(obj.minHeight,math.min(obj.parent.height- obj.y, obj.height))
if false then --could check width?
rect:SetPos(
math.floor(width*(rect.spadsSizes.left)/200),
math.floor(width*(rect.spadsSizes.top)/200),
math.floor(width*(rect.spadsSizes.right - rect.spadsSizes.left)/200),
math.floor(width*(rect.spadsSizes.bottom - rect.spadsSizes.top)/200)
) -- x,y,w,h
else
rect:SetPos(
math.floor(rect.parent.width*(rect.spadsSizes.left)/200),
math.floor(rect.parent.height*(rect.spadsSizes.top)/200),
math.floor(rect.parent.width*(rect.spadsSizes.right - rect.spadsSizes.left)/200),
math.floor(rect.parent.height*(rect.spadsSizes.bottom - rect.spadsSizes.top)/200)
) -- x,y,w,h
end
rect:Invalidate()
rect:BringToFront()
end
end
externalFunctions.UpdateStartRectPositionsInMinimap = UpdateStartRectPositionsInMinimap
local tbMapName = TextBox:New {
name = "tbMapName",
x = 2,
y = 3,
right = 20,
align = "left",
parent = btnMapLink,
fontsize = config:GetFont(2).size,
}
--[[
local imMapLink = Image:New {
x = 0,
y = 1,
width = 18,
height = 18,
keepAspect = true,
file = IMG_LINK,
parent = btnMapLink,
}
]]--
local function SetMapName(mapName, width)
currentMapName = mapName
mapLinkWidth = width
UpdateStartRectPositionsInMinimap(width)
if not currentMapName then
return
end
mapName = battle.mapName:gsub("_", " ")
mapName = StringUtilities.GetTruncatedStringWithDotDot(mapName, tbMapName.font, width - 22)
tbMapName:SetText(mapName)
local length = tbMapName.font:GetTextWidth(mapName)
--imMapLink:SetPos(length + 5)
end
SetMapName(battle.mapName, mapLinkWidth)
btnMapLink.OnResize[#btnMapLink.OnResize + 1] = function (self, xSize, ySize)
SetMapName(currentMapName, xSize)
end
local minimapPanel = Panel:New {
x = 0,
y = 0,
right = 0,
height = 200,
padding = {1,1,1,1},
parent = rightInfo,
}
--[[local btnMinimap = Button:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
classname = "button_square",
caption = "",
parent = minimapPanel,
padding = {2,2,2,2},
OnClick = {
function()
WG.MapListPanel.Show(battleLobby, battle.mapName)
end
},
}]]--
local mapImageFile, needDownload = config:GetMinimapImage(battle.mapName)
local imMinimap = Image:New {
x = 0,
y = 0,
right = 0,
bottom = 0,
keepAspect = false, -- force wrong aspect ratio for correct start boxes display
file = mapImageFile,
fallbackFile = config:GetLoadingImage(3),
checkFileExists = needDownload,
parent = minimapPanel,
tooltip = "Currently selected map. Green boxes show where each team will start"
}
--[[
--Obsolete:
if showDefaultStartCheckbox then
local cbUseDefaultStartBoxes = Checkbox:New {
x = 0,
bottom = 130,
boxalign = "left",
boxsize = 15,
caption = "Use Start Boxes",
checked = true,
tooltip = "All teams start together in pre-specified areas",
font = config:GetFont(2),
parent = rightInfo,
OnClick = {function (obj)
config.gameConfig.useDefaultStartBoxes = obj.checked
end},
}
end
]]--
if config.devMode then
local comboboxstartpostype = ComboBox:New{
x = 0,
bottom = 100,
right = 0,
height = 30,
itemHeight = 22,
selectByName = true,
captionHorAlign = -12,
text = "",
font = config:GetFont(2),
items = {"Fixed", "Random", "Choose In Game", "Choose Before Game"},
itemFontSize = config:GetFont(2).size,
selected = "Choose In Game",
OnSelectName = {
function (obj, selectedName)
for k,v in ipairs {"Fixed", "Random", "Choose In Game", "Choose Before Game"} do
if selectedName == v then
battle.startPosType = k - 1
Spring.Echo("Selected startPosType", k,v, k-1,selectedName)
return
end
end
battle.startPosType = nil
end
},
parent = rightInfo,
}
end
local function RejoinBattleFunc()
--Spring.Echo("\LuaMenu\widgets\chobby\components\battle\battle_watch_list_window.lua","RejoinBattleFunc()","") -- Beherith Debug
battleLobby:RejoinBattle(battleID)
WG.Analytics.SendOnetimeEvent("lobby:multiplayer:custom:rejoin")
end
if battleLobby.name ~= "singleplayer" then
readyButton = Button:New {
x = 0,
right = "50.5%",
bottom = 0,
height = 48,
classname = "ready_button",
font = config:GetFont(3),
disabledFont = config:GetFont(3),
hasDisabledFont = true,
caption = i18n("unready"),
tooltip = i18n("unready_tooltip"), -- Set in OnUpdateUserBattleStatus
OnClick = {
function(readyButton)
if not readyButton.state.enabled then return end
local newReady = not battleLobby.userBattleStatus[battleLobby.myUserName].isReady
battleLobby:SetBattleStatus({ isReady = newReady })
end
},
parent = rightInfo,
}
readyButton:SetEnabled(false)
readyButton:StyleUnready()
end
btnStartBattle = Button:New {
x = ((readyButton == nil) and 0 or "50.5%"),
right = 0,
bottom = 0,
height = 48,
caption = i18n("start"),
classname = "action_button",
font = config:GetFont(3),
tooltip = "Start the game, or call a vote to start multiplayer, or join a running game",
OnClick = {
function()
if not haveMapAndGame then
Spring.Echo("Do something if map or game is missing")
return
end
if battle.isRunning then
if Spring.GetGameName() == "" then
RejoinBattleFunc()
else
WG.Chobby.ConfirmationPopup(RejoinBattleFunc, "Are you sure you want to leave your current game to rejoin this one?", nil, 315, 200)
end
else
if battleLobby.name == "singleplayer" then
local Configuration = WG.Chobby.Configuration
if Configuration.gameConfig.mapStartBoxes.singleplayerboxes then
if currentStartRects ~= {} then
Configuration.gameConfig.mapStartBoxes.singleplayerboxes = currentStartRects
end
end
WG.Analytics.SendOnetimeEvent("lobby:singleplayer:skirmish:start")
WG.SteamCoopHandler.AttemptGameStart("skirmish", battle.gameName, battle.mapName)
else
WG.Analytics.SendOnetimeEvent("lobby:multiplayer:custom:start")
battleLobby:StartBattle("skirmish")
end
end
end
},
parent = rightInfo,
}
local btnPlay
local btnSpectate
local function SetButtonStatePlaying()
ButtonUtilities.SetButtonDeselected(btnSpectate)
ButtonUtilities.SetCaption(btnSpectate, i18n("spectate"))
ButtonUtilities.SetButtonSelected(btnPlay)
ButtonUtilities.SetCaption(btnPlay, i18n("playing"))
btnPlay.suppressButtonReaction = true
btnSpectate.suppressButtonReaction = false
btnPlay.tooltip = i18n("tooltip_is_player")
btnSpectate.tooltip = i18n("tooltip_become_spectator")
end
local function SetButtonStateSpectating()
ButtonUtilities.SetButtonDeselected(btnPlay)
ButtonUtilities.SetCaption(btnPlay, i18n("play"))
ButtonUtilities.SetButtonSelected(btnSpectate)
btnSpectate.suppressButtonReaction = true
btnPlay.suppressButtonReaction = false
btnSpectate.tooltip = i18n("tooltip_is_spectator")
btnPlay.tooltip = i18n("tooltip_become_player")
ButtonUtilities.SetCaption(btnSpectate, i18n("spectating"))
end
btnSpectate = Button:New { -- Some properties set by SetButtonStatePlaying() after both buttons are initialised.
x = "50.5%",
right = 0,
bottom = 51,
height = 32,
classname = "button_highlight",
caption = "",
font = config:GetFont(2),
OnClick = {
function(obj)
battleLobby:SetBattleStatus({
isSpectator = true,
isReady = false
})
SetButtonStateSpectating()
WG.Analytics.SendOnetimeEvent("lobby:multiplayer:custom:spectate")
WG.Chobby.Configuration:SetConfigValue("lastGameSpectatorState", true)
end
},
parent = rightInfo,
}
btnPlay = Button:New { -- Some properties set by SetButtonStatePlaying() after both buttons are initialised.
x = 0,
right = "50.5%",
bottom = 51,
height = 32,
classname = "button_highlight",
caption = "",
font = config:GetFont(2),
OnClick = {
function(obj)
local unusedTeamID = battleLobby:GetUnusedTeamID()
--Spring.Echo("unusedTeamID",unusedTeamID)
battleLobby:SetBattleStatus({
isSpectator = false,
isReady = false,
side = (WG.Chobby.Configuration.lastFactionChoice or 0),
teamNumber = unusedTeamID})
SetButtonStatePlaying()
WG.Analytics.SendOnetimeEvent("lobby:multiplayer:custom:play")
WG.Chobby.Configuration:SetConfigValue("lastGameSpectatorState", false)
end
},
parent = rightInfo,
}
SetButtonStatePlaying()
rightInfo.OnResize = {
function (obj, xSize, ySize)
if xSize + minimapBottomClearance < ySize then
minimapPanel._relativeBounds.left = 0
minimapPanel._relativeBounds.right = 0
minimapPanel:SetPos(nil, nil, nil, xSize)
UpdateStartRectPositionsInMinimap()
minimapPanel:UpdateClientArea()
btnMapLink:SetPos(nil, xSize + 2)
startBoxPanel:SetPos(nil,xSize + 24,nil, xSize / 8)
else
local horPadding = ((xSize + minimapBottomClearance) - ySize)/2
minimapPanel._relativeBounds.left = horPadding
minimapPanel._relativeBounds.right = horPadding
minimapPanel:SetPos(nil, nil, nil, ySize - minimapBottomClearance)
UpdateStartRectPositionsInMinimap()
minimapPanel:UpdateClientArea()
btnMapLink:SetPos(nil, ySize - minimapBottomClearance + 2)
startBoxPanel:SetPos(nil,ySize - minimapBottomClearance + 24,nil, xSize / 8)
end
end
}
local leftOffset = 0
local btnNewTeam = Button:New {
name = "btnNewTeam",
x = 5,
y = leftOffset,
height = 35,
right = 5,
classname = "option_button",
caption = i18n("add_team") .. "\b",
font = config:GetFont(2),
tooltip = "Add another team for players or AI to join into",
OnClick = {
function()
if OpenNewTeam then
OpenNewTeam()
end
end
},
-- Combo box settings
--ignoreItemCaption = true,
--itemFontSize = config:GetFont(1).size,
--itemHeight = 30,
--selected = 0,
--maxDropDownWidth = 120,
--minDropDownHeight = 0,
--items = {"Join", "Add AI"},
--OnSelect = {
-- function (obj)
-- if obj.selected == 1 then
-- battleLobby:SetBattleStatus({
-- allyNumber = emptyTeamIndex,
-- isSpectator = false,
-- })
-- elseif obj.selected == 2 then
-- WG.PopupPreloader.ShowAiListWindow(battleLobby, battle.gameName, emptyTeamIndex)
-- end
-- end
--},
parent = leftInfo
}
leftOffset = leftOffset + 38
local btnPickMap = Button:New {
x = 5,
y = leftOffset,
height = 35,
right = 5,
classname = "option_button",
caption = i18n("pick_map") .. "\b",
font = config:GetFont(2),
tooltip = "Select a map from the maps you have downloaded",
OnClick = {
function()
WG.MapListPanel.Show(battleLobby, battle.mapName)
end
},
parent = leftInfo,
}
leftOffset = leftOffset + 38
WG.ModoptionsPanel.LoadModotpions(battle.gameName, battleLobby)
local btnModoptions = Button:New {
x = 5,
y = leftOffset,
height = 35,
right = 5,
classname = "option_button",
caption = "Adv Options" .. "\b",
font = config:GetFont(2),
tooltip = "Configure custom gameplay options",
OnClick = {
function()
WG.ModoptionsPanel.ShowModoptions()
end
},
parent = leftInfo,
}
leftOffset = leftOffset + 40
local lblGame = Label:New {
x = 8,
y = leftOffset,
caption = WG.Chobby.Configuration.gameConfig.ShortenNameString(battle.gameName),
font = config:GetFont(1),
parent = leftInfo,
}
leftOffset = leftOffset + 26
local imHaveGame = Image:New {
x = 8,
y = leftOffset,
width = 15,
height = 15,
file = IMG_READY,
parent = leftInfo,
}
local lblHaveGame = Label:New {
x = 28,
y = leftOffset,
caption = "",
font = config:GetFont(1),
parent = leftInfo,
}
leftOffset = leftOffset + 25
local imHaveMap = Image:New {
x = 8,
y = leftOffset,
width = 15,
height = 15,
file = IMG_READY,
parent = leftInfo,
}
local lblHaveMap = Label:New {
x = 28,
y = leftOffset,
caption = "",
font = config:GetFont(1),
parent = leftInfo,
}
leftOffset = leftOffset + 25
local modoptionsHolder = Control:New {
x = 0,
y = leftOffset,
right = 0,
height = 120,