-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgui_info.lua
1940 lines (1738 loc) · 70.7 KB
/
gui_info.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
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 = "Info",
desc = "Persistant version, modified by Errrrrrr",
author = "Floris",
date = "April 2020",
license = "GNU GPL, v2 or later",
layer = 1,
enabled = true
}
end
local alwaysShow = false
local width = 0
local height = 0
local zoomMult = 1.5
local defaultCellZoom = 0 * zoomMult
local rightclickCellZoom = 0.065 * zoomMult
local clickCellZoom = 0.065 * zoomMult
local hoverCellZoom = 0.03 * zoomMult
local showBuilderBuildlist = true
local displayMapPosition = false
local emptyInfo = false
local showEngineTooltip = false -- straight up display old engine delivered text
local texts = {}
local fontfile = "fonts/" .. Spring.GetConfigString("bar_font", "Poppins-Regular.otf")
local fontfile2 = "fonts/" .. Spring.GetConfigString("bar_font2", "Exo2-SemiBold.otf")
local vsx, vsy = Spring.GetViewGeometry()
local hoverType, hoverData = '', ''
local sound_button = 'LuaUI/Sounds/buildbar_add.wav'
local sound_button2 = 'LuaUI/Sounds/buildbar_rem.wav'
local ui_scale = tonumber(Spring.GetConfigFloat("ui_scale", 1) or 1)
local backgroundRect = { 0, 0, 0, 0 }
local currentTooltip = ''
local lastUpdateClock = 0
local infoShows = false
local tooltipTitleColor = '\255\205\255\205'
local tooltipTextColor = '\255\255\255\255'
local tooltipLabelTextColor = '\255\200\200\200'
local tooltipDarkTextColor = '\255\133\133\133'
local tooltipValueColor = '\255\255\255\255'
local tooltipValueWhiteColor = '\255\255\255\255'
local selectionHowto = tooltipTextColor .. "Left click" .. tooltipLabelTextColor .. ": Select\n " .. tooltipTextColor .. " + CTRL" .. tooltipLabelTextColor .. ": Select units of this type on map\n " .. tooltipTextColor .. " + ALT" .. tooltipLabelTextColor .. ": Select 1 single unit of this unit type\n " .. tooltipTextColor .. "Right click" .. tooltipLabelTextColor .. ": Remove\n " .. tooltipTextColor .. " + CTRL" .. tooltipLabelTextColor .. ": Remove only 1 unit from that unit type\n " .. tooltipTextColor .. "Middle click" .. tooltipLabelTextColor .. ": Move to center location\n " .. tooltipTextColor .. " + CTRL" .. tooltipLabelTextColor .. ": Move to center off whole selection"
local anonymousMode = Spring.GetModOptions().teamcolors_anonymous_mode
local anonymousTeamColor = {Spring.GetConfigInt("anonymousColorR", 255)/255, Spring.GetConfigInt("anonymousColorG", 0)/255, Spring.GetConfigInt("anonymousColorB", 0)/255}
local iconTypesMap, dlistGuishader, bgpadding, ViewResizeUpdate, texOffset, displayMode
local loadedFontSize, font, font2, font3, cfgDisplayUnitID, rankTextures
local cellRect, cellPadding, cornerSize, cellsize, cellHovered
local gridHeight, selUnitsSorted, selUnitsCounts, selectionCells, customInfoArea, contentPadding
local displayUnitID, displayUnitDefID, doUpdateClock, lastHoverDataClock, lastHoverData
local contentWidth, dlistInfo, bfcolormap, selUnitTypes
local RectRound, UiElement, UiUnit, elementCorner
local spGetCurrentTooltip = Spring.GetCurrentTooltip
local spGetSelectedUnitsCounts = Spring.GetSelectedUnitsCounts
local spGetSelectedUnitsSorted = Spring.GetSelectedUnitsSorted
local spGetSelectedUnitsCount = Spring.GetSelectedUnitsCount
local SelectedUnitsCount = Spring.GetSelectedUnitsCount()
local selectedUnits = Spring.GetSelectedUnits()
local spGetUnitDefID = Spring.GetUnitDefID
local spGetFeatureDefID = Spring.GetFeatureDefID
local spTraceScreenRay = Spring.TraceScreenRay
local spGetMouseState = Spring.GetMouseState
local spGetModKeyState = Spring.GetModKeyState
local spSelectUnitArray = Spring.SelectUnitArray
local spGetTeamUnitsSorted = Spring.GetTeamUnitsSorted
local spSelectUnitMap = Spring.SelectUnitMap
local spGetUnitHealth = Spring.GetUnitHealth
local spGetUnitResources = Spring.GetUnitResources
local spGetUnitMaxRange = Spring.GetUnitMaxRange
local spGetUnitExperience = Spring.GetUnitExperience
local spGetUnitMetalExtraction = Spring.GetUnitMetalExtraction
local spGetUnitStates = Spring.GetUnitStates
local spGetUnitStockpile = Spring.GetUnitStockpile
local spGetUnitWeaponState = Spring.GetUnitWeaponState
local spGetUnitRulesParam = Spring.GetUnitRulesParam
local math_floor = math.floor
local math_ceil = math.ceil
local math_min = math.min
local math_max = math.max
local math_isInRect = math.isInRect
local string_lines = string.lines
local os_clock = os.clock
local myTeamID = Spring.GetMyTeamID()
local mySpec = Spring.GetSpectatingState()
local GL_QUADS = GL.QUADS
local glTexture = gl.Texture
local glTexRect = gl.TexRect
local glColor = gl.Color
local glBlending = gl.Blending
local GL_SRC_ALPHA = GL.SRC_ALPHA
local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA
local GL_ONE = GL.ONE
local hideBuildlist
local function round(value, numDecimalPlaces)
if value then
return string.format("%0." .. numDecimalPlaces .. "f", math.round(value, numDecimalPlaces))
else
return 0
end
end
local function convertColor(r, g, b)
return string.char(255, (r * 255), (g * 255), (b * 255))
end
local unitDefInfo = {}
local unitRestricted = {}
local isWaterUnit = {}
local isGeothermalUnit = {}
local function refreshUnitInfo()
for unitDefID, unitDef in pairs(UnitDefs) do
unitDefInfo[unitDefID] = {}
if unitDef.name == 'armdl' or unitDef.name == 'cordl' or unitDef.name == 'armlance' or unitDef.name == 'cortitan'
or (unitDef.minWaterDepth > 0 or unitDef.modCategories['ship']) then
if not (unitDef.modCategories['hover'] or (unitDef.modCategories['mobile'] and unitDef.modCategories['canbeuw'])) then
isWaterUnit[unitDefID] = true
end
end
if unitDef.needGeo then
isGeothermalUnit[unitDefID] = true
end
if unitDef.maxThisUnit == 0 then
unitRestricted[unitDefID] = true
end
if unitDef.isAirUnit then
unitDefInfo[unitDefID].airUnit = true
end
if not unitDef.cantBeTransported then --unitDef.isImmobile or unitDef.isBuilding then
unitDefInfo[unitDefID].transportable = true
end
unitDefInfo[unitDefID].translatedHumanName = unitDef.translatedHumanName
if unitDef.maxWeaponRange > 16 then
unitDefInfo[unitDefID].maxWeaponRange = unitDef.maxWeaponRange
end
if unitDef.speed > 0 then
unitDefInfo[unitDefID].speed = round(unitDef.speed, 0)
end
if unitDef.rSpeed > 0 then
unitDefInfo[unitDefID].reverseSpeed = round(unitDef.rSpeed, 0)
end
if unitDef.mass > 0 then
unitDefInfo[unitDefID].mass = unitDef.mass
end
if unitDef.xsize > 0 then
unitDefInfo[unitDefID].footprint = unitDef.xsize * unitDef.zsize
end
if unitDef.stealth then
unitDefInfo[unitDefID].stealth = true
end
if unitDef.cloakCost and unitDef.canCloak then
unitDefInfo[unitDefID].cloakCost = unitDef.cloakCost
if unitDef.cloakCostMoving > unitDef.cloakCost then
unitDefInfo[unitDefID].cloakCostMoving = unitDef.cloakCostMoving
end
end
if unitDef.isTransport then
unitDefInfo[unitDefID].transport = { unitDef.transportMass, unitDef.transportSize, unitDef.transportCapacity }
end
if unitDef.customParams.paralyzemultiplier then
unitDefInfo[unitDefID].paralyzeMult = tonumber(unitDef.customParams.paralyzemultiplier)
end
unitDefInfo[unitDefID].armorType = Game.armorTypes[unitDef.armorType or 0] or '???'
if unitDef.losRadius > 0 then
unitDefInfo[unitDefID].losRadius = unitDef.losRadius
end
if unitDef.airLosRadius > 0 then
unitDefInfo[unitDefID].airLosRadius = unitDef.airLosRadius
end
if unitDef.radarRadius > 0 then
unitDefInfo[unitDefID].radarRadius = unitDef.radarRadius
end
if unitDef.sonarRadius > 0 then
unitDefInfo[unitDefID].sonarRadius = unitDef.sonarRadius
end
if unitDef.jammerRadius > 0 then
unitDefInfo[unitDefID].jammerRadius = unitDef.jammerRadius
end
if unitDef.sonarJamRadius > 0 then
unitDefInfo[unitDefID].sonarJamRadius = unitDef.sonarJamRadius
end
if unitDef.seismicRadius > 0 then
unitDefInfo[unitDefID].seismicRadius = unitDef.seismicRadius
end
if unitDef.customParams.energyconv_capacity and unitDef.customParams.energyconv_efficiency then
unitDefInfo[unitDefID].metalmaker = { tonumber(unitDef.customParams.energyconv_capacity), tonumber(unitDef.customParams.energyconv_efficiency) }
end
unitDefInfo[unitDefID].tooltip = unitDef.translatedTooltip
unitDefInfo[unitDefID].iconType = unitDef.iconType
unitDefInfo[unitDefID].energyCost = unitDef.energyCost
unitDefInfo[unitDefID].metalCost = unitDef.metalCost
unitDefInfo[unitDefID].energyStorage = unitDef.energyStorage
unitDefInfo[unitDefID].metalStorage = unitDef.metalStorage
unitDefInfo[unitDefID].health = unitDef.health
unitDefInfo[unitDefID].buildTime = unitDef.buildTime
unitDefInfo[unitDefID].buildPic = unitDef.buildpicname and true or false
if unitDef.canStockpile then
unitDefInfo[unitDefID].canStockpile = true
end
if unitDef.buildSpeed > 0 then
unitDefInfo[unitDefID].buildSpeed = unitDef.buildSpeed
end
if unitDef.buildOptions[1] then
unitDefInfo[unitDefID].buildOptions = unitDef.buildOptions
end
if unitDef.extractsMetal > 0 then
unitDefInfo[unitDefID].mex = true
end
local totalDps = 0
local weapons = unitDef.weapons
for i = 1, #weapons do
if not unitDefInfo[unitDefID].weapons then
unitDefInfo[unitDefID].weapons = {}
unitDefInfo[unitDefID].dps = 0
unitDefInfo[unitDefID].reloadTime = 0
unitDefInfo[unitDefID].mainWeapon = i
end
unitDefInfo[unitDefID].weapons[i] = weapons[i].weaponDef
local weaponDef = WeaponDefs[weapons[i].weaponDef]
if weaponDef.interceptor ~= 0 and weaponDef.coverageRange then
unitDefInfo[unitDefID].maxCoverage = math.max(unitDefInfo[unitDefID].maxCoverage or 1, weaponDef.coverageRange)
end
if weaponDef.damages then
-- get highest damage category
local maxDmg = 0
local reloadTime = 0
for _, v in pairs(weaponDef.damages) do
if v > maxDmg then
maxDmg = v
reloadTime = weaponDef.reload
end
end
local dps = math_floor(maxDmg * weaponDef.salvoSize / weaponDef.reload)
if dps > unitDefInfo[unitDefID].dps then
--unitDefInfo[unitDefID].dps = dps
unitDefInfo[unitDefID].reloadTime = reloadTime -- only main weapon is relevant
unitDefInfo[unitDefID].mainWeapon = i
end
totalDps = totalDps + dps
unitDefInfo[unitDefID].dps = totalDps
end
if weapons[i].onlyTargets['vtol'] ~= nil then
unitDefInfo[unitDefID].isAaUnit = true
end
if weaponDef.energyCost > 0 and (not unitDefInfo[unitDefID].energyPerShot or weaponDef.energyCost > unitDefInfo[unitDefID].energyPerShot) then
unitDefInfo[unitDefID].energyPerShot = weaponDef.energyCost
end
if weaponDef.metalCost > 0 and (not unitDefInfo[unitDefID].metalPerShot or weaponDef.metalCost > unitDefInfo[unitDefID].metalPerShot) then
unitDefInfo[unitDefID].metalPerShot = weaponDef.metalCost
end
end
if unitDef.customParams.unitgroup and unitDef.customParams.unitgroup == 'explo' and unitDef.deathExplosion and WeaponDefNames[unitDef.deathExplosion] then
local weapon = WeaponDefs[WeaponDefNames[unitDef.deathExplosion].id]
if weapon then
unitDefInfo[unitDefID].dps = weapon.damages[Game.armorTypes["default"]]
unitDefInfo[unitDefID].reloadTime = nil
end
end
end
end
local groups, unitGroup = {}, {} -- retrieves from buildmenu in initialize
local unitOrder = {} -- retrieves from buildmenu in initialize
local unitDisabled = {}
local minWaterUnitDepth = -11
local showWaterUnits = false
local _, _, mapMinWater, _ = Spring.GetGroundExtremes()
if mapMinWater <= minWaterUnitDepth then
showWaterUnits = true
end
-- make them a disabled unit (instead of removing it entirely)
if not showWaterUnits then
for unitDefID,_ in pairs(isWaterUnit) do
unitDisabled[unitDefID] = true
end
end
local showGeothermalUnits = false
local function checkGeothermalFeatures()
showGeothermalUnits = false
local geoThermalFeatures = {}
for defID, def in pairs(FeatureDefs) do
if def.geoThermal then
geoThermalFeatures[defID] = true
end
end
local features = Spring.GetAllFeatures()
for i = 1, #features do
if geoThermalFeatures[Spring.GetFeatureDefID(features[i])] then
showGeothermalUnits = true
break
end
end
-- make them a disabled unit (instead of removing it entirely)
for unitDefID,_ in pairs(isGeothermalUnit) do
if not showGeothermalUnits then
unitDisabled[unitDefID] = true
else
if not isWaterUnit[unitDefID] or showWaterUnits then
unitDisabled[unitDefID] = nil
end
end
end
end
local function checkGuishader(force)
if WG['guishader'] then
if force and dlistGuishader then
dlistGuishader = gl.DeleteList(dlistGuishader)
end
if not dlistGuishader then
dlistGuishader = gl.CreateList(function()
RectRound(backgroundRect[1], backgroundRect[2], backgroundRect[3], backgroundRect[4], elementCorner, 0, 1, 0, 0)
end)
WG['guishader'].InsertDlist(dlistGuishader, 'info')
end
elseif dlistGuishader then
dlistGuishader = gl.DeleteList(dlistGuishader)
end
end
function widget:PlayerChanged(playerID)
myTeamID = Spring.GetMyTeamID()
mySpec = Spring.GetSpectatingState()
end
function widget:ViewResize()
ViewResizeUpdate = true
vsx, vsy = Spring.GetViewGeometry()
width = 0.2125
height = 0.14 * ui_scale
width = width / (vsx / vsy) * 1.78 -- make smaller for ultrawide screens
width = width * ui_scale
-- make pixel aligned
height = math_floor(height * vsy) / vsy
width = math_floor(width * vsx) / vsx
bgpadding = WG.FlowUI.elementPadding
elementCorner = WG.FlowUI.elementCorner
RectRound = WG.FlowUI.Draw.RectRound
UiElement = WG.FlowUI.Draw.Element
UiUnit = WG.FlowUI.Draw.Unit
backgroundRect = { 0, 0, width * vsx, height * vsy }
doUpdate = true
clear()
checkGuishader(true)
font, loadedFontSize = WG['fonts'].getFont(fontfile)
font2 = WG['fonts'].getFont(fontfile2)
font3 = WG['fonts'].getFont(fontfile2, 1.2, 0.28, 1.6)
end
function GetColor(colormap, slider)
local coln = #colormap
if slider >= 1 then
local col = colormap[coln]
return col[1], col[2], col[3], col[4]
end
if slider < 0 then
slider = 0
elseif slider > 1 then
slider = 1
end
local posn = 1 + (coln - 1) * slider
local iposn = math_floor(posn)
local aa = posn - iposn
local ia = 1 - aa
local col1, col2 = colormap[iposn], colormap[iposn + 1]
return col1[1] * ia + col2[1] * aa, col1[2] * ia + col2[2] * aa,
col1[3] * ia + col2[3] * aa, col1[4] * ia + col2[4] * aa
end
function widget:GameFrame(n)
if checkGeothermalFeatures then
checkGeothermalFeatures()
checkGeothermalFeatures = nil
widgetHandler:RemoveCallIn("GameFrame")
end
end
function widget:Initialize()
refreshUnitInfo()
texts = Spring.I18N('ui.info')
checkGeothermalFeatures()
widget:ViewResize()
WG['info'] = {}
WG['info'].getShowBuilderBuildlist = function()
return showBuilderBuildlist
end
WG['info'].setShowBuilderBuildlist = function(value)
showBuilderBuildlist = value
end
WG['info'].getDisplayMapPosition = function()
return displayMapPosition
end
WG['info'].setDisplayMapPosition = function(value)
displayMapPosition = value
end
WG['info'].getAlwaysShow = function()
return alwaysShow
end
WG['info'].setAlwaysShow = function(value)
alwaysShow = value
end
WG['info'].displayUnitID = function(unitID)
cfgDisplayUnitID = unitID
end
WG['info'].clearDisplayUnitID = function()
cfgDisplayUnitID = nil
end
WG['info'].getPosition = function()
return width, height
end
WG['info'].getIsShowing = function()
return infoShows
end
if WG['buildmenu'] then
if WG['buildmenu'].getGroups then
groups, unitGroup = WG['buildmenu'].getGroups()
end
if WG['buildmenu'].getOrder then
unitOrder = WG['buildmenu'].getOrder()
-- order buildoptions
for uDefID, def in pairs(unitDefInfo) do
if def.buildOptions then
local temp = {}
for i, udid in pairs(def.buildOptions) do
temp[udid] = i
end
local newBuildOptions = {}
local newBuildOptionsCount = 0
for k, orderUDefID in pairs(unitOrder) do
if temp[orderUDefID] then
newBuildOptionsCount = newBuildOptionsCount + 1
newBuildOptions[newBuildOptionsCount] = orderUDefID
end
end
unitDefInfo[uDefID].buildOptions = newBuildOptions
end
end
end
end
iconTypesMap = {}
if Script.LuaRules('GetIconTypes') then
iconTypesMap = Script.LuaRules.GetIconTypes()
end
Spring.SetDrawSelectionInfo(false) -- disables springs default display of selected units count
Spring.SendCommands("tooltip 0")
if WG['rankicons'] then
rankTextures = WG['rankicons'].getRankTextures()
end
bfcolormap = {}
local hpcolormap = { { 1, 0.0, 0.0, 1 }, { 0.8, 0.60, 0.0, 1 }, { 0.0, 0.75, 0.0, 1 } }
for hp = 0, 100 do
bfcolormap[hp] = { GetColor(hpcolormap, hp * 0.01) }
end
end
function clear()
dlistInfo = gl.DeleteList(dlistInfo)
end
function widget:Shutdown()
Spring.SetDrawSelectionInfo(true) --disables springs default display of selected units count
Spring.SendCommands("tooltip 1")
clear()
if WG['guishader'] and dlistGuishader then
WG['guishader'].DeleteDlist('info')
dlistGuishader = nil
end
end
local sec2 = 0
local sec = 0
local lastCameraPanMode = false
function widget:Update(dt)
infoShows = false
local x, y, b, b2, b3, mouseOffScreen, cameraPanMode = spGetMouseState()
if lastCameraPanMode ~= cameraPanMode then
lastCameraPanMode = cameraPanMode
checkChanges()
end
if not alwaysShow and (cameraPanMode or mouseOffScreen) and Spring.GetGameFrame() > 0 then
if SelectedUnitsCount == 0 then
if dlistGuishader then
WG['guishader'].DeleteDlist('info')
dlistGuishader = nil
end
end
return
end
sec2 = sec2 + dt
if sec2 > 0.5 then
sec2 = 0
if not rankTextures and WG['rankicons'] then
rankTextures = WG['rankicons'].getRankTextures()
end
local _, _, mapMinWater, _ = Spring.GetGroundExtremes()
if mapMinWater <= minWaterUnitDepth then
if not showWaterUnits then
showWaterUnits = true
for unitDefID,_ in pairs(isWaterUnit) do
if not isGeothermalUnit[unitDefID] or showGeothermalUnits then -- make sure geothermal units keep being disabled if that should be the case
unitDisabled[unitDefID] = nil
end
end
end
end
end
sec = sec + dt
if sec > 0.035 then
sec = 0
checkChanges()
if alwaysShow or not emptyInfo then
checkGuishader()
end
end
if ViewResizeUpdate then
ViewResizeUpdate = nil
end
if doUpdate or (doUpdateClock and os_clock() >= doUpdateClock) or (os_clock() >= doUpdateClock2) then
doUpdateClock = nil
doUpdateClock2 = os_clock() + 0.9
clear()
doUpdate = nil
lastUpdateClock = os_clock()
end
if displayUnitID and not Spring.ValidUnitID(displayUnitID) then
displayMode = 'text'
displayUnitID = nil
displayUnitDefID = nil
end
if (not alwaysShow and (cameraPanMode or mouseOffScreen) and SelectedUnitsCount == 0 and Spring.GetGameFrame() > 0) then
return
end
if alwaysShow or not emptyInfo or Spring.GetGameFrame() == 0 then
infoShows = true
end
end
local function DrawRectRoundCircle(x, y, z, radius, cs, centerOffset, color1, color2)
if not color2 then
color2 = color1
end
--centerOffset = 0
local coords = {
{ x - radius + cs, z + radius, y }, -- top left
{ x + radius - cs, z + radius, y }, -- top right
{ x + radius, z + radius - cs, y }, -- right top
{ x + radius, z - radius + cs, y }, -- right bottom
{ x + radius - cs, z - radius, y }, -- bottom right
{ x - radius + cs, z - radius, y }, -- bottom left
{ x - radius, z - radius + cs, y }, -- left bottom
{ x - radius, z + radius - cs, y }, -- left top
}
local cs2 = cs * (centerOffset / radius)
local coords2 = {
{ x - centerOffset + cs2, z + centerOffset, y }, -- top left
{ x + centerOffset - cs2, z + centerOffset, y }, -- top right
{ x + centerOffset, z + centerOffset - cs2, y }, -- right top
{ x + centerOffset, z - centerOffset + cs2, y }, -- right bottom
{ x + centerOffset - cs2, z - centerOffset, y }, -- bottom right
{ x - centerOffset + cs2, z - centerOffset, y }, -- bottom left
{ x - centerOffset, z - centerOffset + cs2, y }, -- left bottom
{ x - centerOffset, z + centerOffset - cs2, y }, -- left top
}
for i = 1, 8 do
local i2 = (i >= 8 and 1 or i + 1)
gl.Color(color2)
gl.Vertex(coords[i][1], coords[i][2], coords[i][3])
gl.Vertex(coords[i2][1], coords[i2][2], coords[i2][3])
gl.Color(color1)
gl.Vertex(coords2[i2][1], coords2[i2][2], coords2[i2][3])
gl.Vertex(coords2[i][1], coords2[i][2], coords2[i][3])
end
end
local function RectRoundCircle(x, y, z, radius, cs, centerOffset, color1, color2)
gl.BeginEnd(GL_QUADS, DrawRectRoundCircle, x, y, z, radius, cs, centerOffset, color1, color2)
end
local function drawSelectionCell(cellID, uDefID, usedZoom, highlightColor)
if not usedZoom then
usedZoom = defaultCellZoom
end
glColor(1,1,1,1)
UiUnit(
cellRect[cellID][1] + cellPadding, cellRect[cellID][2] + cellPadding, cellRect[cellID][3], cellRect[cellID][4],
cornerSize,
1,1,1,1,
usedZoom,
nil, nil,
"#" .. uDefID,
nil,
groups[unitGroup[uDefID]]
)
-- unit count
local fontSize = math_min(gridHeight * 0.17, cellsize * 0.6) * (1 - ((1 + string.len(selUnitsCounts[uDefID])) * 0.066))
if selUnitsCounts[uDefID] > 1 then
--font3:Begin()
font3:Print(selUnitsCounts[uDefID], cellRect[cellID][3] - cellPadding - (fontSize * 0.09), cellRect[cellID][2] + (fontSize * 0.3), fontSize, "ro")
--font3:End()
end
-- kill count
local kills = 0
for i, unitID in ipairs(selUnitsSorted[uDefID]) do
local unitKills = spGetUnitRulesParam(unitID, "kills")
if unitKills then
kills = kills + unitKills
end
end
if kills > 0 then
local size = math_floor((cellRect[cellID][3] - (cellRect[cellID][1] + (cellPadding*0.5)))*0.33)
glColor(0.88,0.88,0.88,0.66)
glTexture(":l:LuaUI/Images/skull.dds")
glTexRect(cellRect[cellID][3] - size+(cellPadding*0.5), cellRect[cellID][4]-size-(cellPadding*0.5), cellRect[cellID][3]+(cellPadding*0.5), cellRect[cellID][4]-(cellPadding*0.5))
glTexture(false)
--font3:Begin()
font3:Print('\255\233\233\233'..kills, cellRect[cellID][3] - (size * 0.5)+(cellPadding*0.5), cellRect[cellID][4] -(cellPadding*0.5)- (size * 0.5) - (fontSize * 0.19), fontSize * 0.66, "oc")
--font3:End()
end
end
local function drawSelection()
selUnitsCounts = spGetSelectedUnitsCounts()
selUnitsSorted = spGetSelectedUnitsSorted()
selUnitTypes = 0
selectionCells = {}
for k, uDefID in pairs(unitOrder) do
if selUnitsSorted[uDefID] then
if type(selUnitsSorted[uDefID]) == 'table' then
selUnitTypes = selUnitTypes + 1
selectionCells[selUnitTypes] = uDefID
end
end
end
-- draw selection totals
local numLines
--local stats = getSelectionTotals(selectionCells)
local fontSize = (height * vsy * 0.115) * (0.95 - ((1 - ui_scale) * 0.5))
local height = 0
local heightStep = (fontSize * 1.36)
font2:Begin()
font2:Print(tooltipTextColor .. #selectedUnits .. tooltipLabelTextColor .. " "..texts.unitsselected, backgroundRect[1] + contentPadding, backgroundRect[4] - contentPadding - (fontSize * 1.2) - height, (fontSize * 1.23), "o")
font2:End()
font:Begin()
height = height + (fontSize * 0.85)
-- loop all unitdefs/cells (but not individual unitID's)
local totalMetalValue = 0
local totalEnergyValue = 0
for _, unitDefID in pairs(selectionCells) do
-- metal cost
if unitDefInfo[unitDefID].metalCost then
totalMetalValue = totalMetalValue + (unitDefInfo[unitDefID].metalCost * selUnitsCounts[unitDefID])
end
-- energy cost
if unitDefInfo[unitDefID].energyCost then
totalEnergyValue = totalEnergyValue + (unitDefInfo[unitDefID].energyCost * selUnitsCounts[unitDefID])
end
end
-- loop all unitID's
local totalMaxHealthValue = 0
local totalMetalMake, totalMetalUse, totalEnergyMake, totalEnergyUse = 0, 0, 0, 0
local totalKills = 0
for _, unitID in pairs(cellHovered and selUnitsSorted[selectionCells[cellHovered]] or selectedUnits) do
local metalMake, metalUse, energyMake, energyUse = spGetUnitResources(unitID)
if metalMake then
totalMetalMake = totalMetalMake + metalMake
totalMetalUse = totalMetalUse + metalUse
totalEnergyMake = totalEnergyMake + energyMake
totalEnergyUse = totalEnergyUse + energyUse
end
local kills = spGetUnitRulesParam(unitID, "kills")
if kills then
totalKills = totalKills + kills
end
end
local valuePlusColor = '\255\180\255\180'
local valueMinColor = '\255\255\180\180'
if totalMetalUse > 0 or totalMetalMake > 0 then
height = height + heightStep
font:Print( tooltipLabelTextColor .. texts.m.." " .. (totalMetalMake > 0 and valuePlusColor .. '+' .. (totalMetalMake < 10 and round(totalMetalMake, 1) or round(totalMetalMake, 0)) .. ' ' or '') .. (totalMetalUse > 0 and valueMinColor .. '-' .. (totalMetalUse < 10 and round(totalMetalUse, 1) or round(totalMetalUse, 0)) or ''), backgroundRect[1] + contentPadding, backgroundRect[4] - (bgpadding*2.4) - (fontSize * 0.8) - height, fontSize, "o")
end
if totalEnergyUse > 0 or totalEnergyMake > 0 then
height = height + heightStep
font:Print( tooltipLabelTextColor .. texts.e.." " .. (totalEnergyMake > 0 and valuePlusColor .. '+' .. (totalEnergyMake < 10 and round(totalEnergyMake, 1) or round(totalEnergyMake, 0)) .. ' ' or '') .. (totalEnergyUse > 0 and valueMinColor .. '-' .. (totalEnergyUse < 10 and round(totalEnergyUse, 1) or round(totalEnergyUse, 0)) or ''), backgroundRect[1] + contentPadding, backgroundRect[4] - (bgpadding*2.4) - (fontSize * 0.8) - height, fontSize, "o")
end
-- metal cost
height = height + heightStep
font:Print( tooltipLabelTextColor .. texts.costm.." " .. tooltipValueWhiteColor .. totalMetalValue, backgroundRect[1] + contentPadding, backgroundRect[4] - (bgpadding*2.4) - (fontSize * 0.8) - height, fontSize, "o")
-- energy cost
height = height + heightStep
font:Print( tooltipLabelTextColor .. texts.coste.."\255\255\255\128 " .. totalEnergyValue, backgroundRect[1] + contentPadding, backgroundRect[4] - (bgpadding*2.4) - (fontSize * 0.8) - height, fontSize, "o")
-- kills
if totalKills > 0 then
height = height + heightStep
font:Print( tooltipLabelTextColor .. texts.kills.." " .. tooltipValueColor .. totalKills, backgroundRect[1] + contentPadding, backgroundRect[4] - (bgpadding*2.4) - (fontSize * 0.8) - height, fontSize, "o")
end
font:End()
-- selected units grid area
local gridWidth = math_floor((backgroundRect[3] - backgroundRect[1] - bgpadding) * 0.6) -- leaving some room for the totals
gridHeight = math_floor((backgroundRect[4] - backgroundRect[2]) - bgpadding)
customInfoArea = { backgroundRect[3] - gridWidth, backgroundRect[2], backgroundRect[3] - bgpadding, backgroundRect[2] + gridHeight }
-- draw selected unit icons
local rows = 2
local maxRows = 15 -- just to be sure
local colls = math_ceil(selUnitTypes / rows)
cellsize = math_floor(math_min(gridWidth / colls, gridHeight / rows))
while cellsize < gridHeight / (rows + 1) do
rows = rows + 1
colls = math_ceil(selUnitTypes / rows)
cellsize = math_min(gridWidth / colls, gridHeight / rows)
if rows > maxRows then
break
end
end
-- adjust grid size to add some padding at the top and right side
cellsize = math_floor((cellsize * (1 - (0.04 / rows))) + 0.5) -- leave some space at the top
cellPadding = math_max(1, math_floor(cellsize * 0.03))
customInfoArea[3] = customInfoArea[3] - cellPadding -- leave space at the right side
-- draw grid (bottom right to top left)
cellRect = {}
texOffset = (0.03 * rows) * zoomMult
cornerSize = math_max(1, cellPadding * 0.9)
if texOffset > 0.25 then
texOffset = 0.25
end
local cellID = selUnitTypes
for row = 1, rows do
for coll = 1, colls do
if selectionCells[cellID] then
local uDefID = selectionCells[cellID]
cellRect[cellID] = { math_ceil(customInfoArea[3] - cellPadding - (coll * cellsize)), math_ceil(customInfoArea[2] + cellPadding + ((row - 1) * cellsize)), math_ceil(customInfoArea[3] - cellPadding - ((coll - 1) * cellsize)), math_ceil(customInfoArea[2] + cellPadding + ((row) * cellsize)) }
drawSelectionCell(cellID, selectionCells[cellID], texOffset)
end
cellID = cellID - 1
if cellID <= 0 then
break
end
end
if cellID <= 0 then
break
end
end
glTexture(false)
glColor(1, 1, 1, 1)
end
local function ColourString(R, G, B)
local R255 = math.floor(R * 255)
local G255 = math.floor(G * 255)
local B255 = math.floor(B * 255)
if R255 % 10 == 0 then
R255 = R255 + 1
end
if G255 % 10 == 0 then
G255 = G255 + 1
end
if B255 % 10 == 0 then
B255 = B255 + 1
end
return "\255" .. string.char(R255) .. string.char(G255) .. string.char(B255)
end
local function GetAIName(teamID)
local _, _, _, name, _, options = Spring.GetAIInfo(teamID)
local niceName = Spring.GetGameRulesParam('ainame_' .. teamID)
if niceName then
name = niceName
--if Spring.Utilities.ShowDevUI() and options.profile then
-- name = name .. " [" .. options.profile .. "]"
--end
end
return Spring.I18N('ui.playersList.aiName', { name = name })
end
local function drawUnitInfo()
local fontSize = (height * vsy * 0.123) * (0.94 - ((1 - math.max(1.05, ui_scale)) * 0.4))
local iconSize = math.floor(fontSize * 4.4)
local iconPadding = math.floor(fontSize * 0.22)
if unitDefInfo[displayUnitDefID].buildPic then
local iconX = backgroundRect[1] + iconPadding
local iconY = backgroundRect[4] - iconPadding - bgpadding
-- unit icon
glColor(1,1,1,1)
UiUnit(
iconX, iconY - iconSize, iconX + iconSize, iconY,
nil,
1, 1, 1, 1,
0.03,
nil, nil,
"#" .. displayUnitDefID,
((unitDefInfo[displayUnitDefID].iconType and iconTypesMap[unitDefInfo[displayUnitDefID].iconType]) and ':l:' .. iconTypesMap[unitDefInfo[displayUnitDefID].iconType] or nil),
groups[unitGroup[displayUnitDefID]],
{unitDefInfo[displayUnitDefID].metalCost, unitDefInfo[displayUnitDefID].energyCost}
)
-- price
local halfSize = iconSize * 0.5
local padding = (halfSize + halfSize) * 0.045
local size = (halfSize + halfSize) * 0.18
font3:Print("\255\245\245\245" .. unitDefInfo[displayUnitDefID].metalCost .. "\n\255\255\255\000" .. unitDefInfo[displayUnitDefID].energyCost, iconX + padding, iconY - halfSize - halfSize + padding + (size * 1.07), size, "o")
end
iconSize = iconSize + iconPadding
local dps, metalExtraction, stockpile, maxRange, exp, metalMake, metalUse, energyMake, energyUse
local text, unitDescriptionLines = font:WrapText(unitDefInfo[displayUnitDefID].tooltip, (contentWidth - iconSize) * (loadedFontSize / fontSize))
if displayUnitID then
exp = spGetUnitExperience(displayUnitID)
if exp and exp > 0.009 and WG['rankicons'] and rankTextures then
if displayUnitID then
local rank = WG['rankicons'].getRank(displayUnitDefID, exp)
if rankTextures[rank] then
local rankIconSize = math_floor((height * vsy * 0.24) + 0.5)
local rankIconMarginX = math_floor((height * vsy * 0.015) + 0.5)
local rankIconMarginY = math_floor((height * vsy * 0.18) + 0.5)
glColor(1, 1, 1, 0.88)
glTexture(':lr' .. (rankIconSize * 2) .. ',' .. (rankIconSize * 2) .. ':' .. rankTextures[rank])
glTexRect(backgroundRect[3] - rankIconMarginX - rankIconSize, backgroundRect[4] - rankIconMarginY - rankIconSize, backgroundRect[3] - rankIconMarginX, backgroundRect[4] - rankIconMarginY)
glTexture(false)
glColor(1, 1, 1, 1)
end
end
end
local kills = spGetUnitRulesParam(displayUnitID, "kills")
if kills then
local rankIconSize = math_floor((height * vsy * 0.16))
local rankIconMarginY = math_floor((height * vsy * 0.07) + 0.5)
local rankIconMarginX = math_floor((height * vsy * 0.053) + 0.5)
glColor(0.7,0.7,0.7,0.55)
glTexture(":l:LuaUI/Images/skull.dds")
glTexRect(backgroundRect[3] - rankIconMarginX - rankIconSize, backgroundRect[4] - rankIconMarginY - rankIconSize, backgroundRect[3] - rankIconMarginX, backgroundRect[4] - rankIconMarginY)
glTexture(false)
font2:Begin()
font2:Print('\255\215\215\215'..kills, backgroundRect[3] - rankIconMarginX - (rankIconSize * 0.5), backgroundRect[4] - (rankIconMarginY * 2.05) - (fontSize * 0.31), fontSize * 0.87, "oc")
font2:End()
end
end
local unitNameColor = tooltipTitleColor
if SelectedUnitsCount > 0 then
if not displayMode == 'unitdef' or (WG['buildmenu'] and (WG['buildmenu'].selectedID and (not WG['buildmenu'].hoverID or (WG['buildmenu'].selectedID == WG['buildmenu'].hoverID)))) then
unitNameColor = '\255\125\255\125'
end
end
local descriptionColor = '\255\240\240\240'
local metalColor = '\255\245\245\245'
local energyColor = '\255\255\255\000'
local healthColor = '\255\100\255\100'
local labelColor = '\255\205\205\205'
local valueColor = '\255\255\255\255'
local valuePlusColor = '\255\180\255\180'
local valueMinColor = '\255\255\180\180'
-- custom unit info background
local width = contentWidth * 0.82
local height = (backgroundRect[4] - backgroundRect[2]) * (unitDescriptionLines > 1 and 0.495 or 0.6)
-- unit tooltip
font:Begin()
font:Print(descriptionColor .. text, backgroundRect[3] - width + bgpadding, backgroundRect[4] - contentPadding - (fontSize * 2.17), fontSize * 0.94, "o")
font:End()
-- unit name
local nameFontSize = fontSize * 1.12
local humanName = unitDefInfo[displayUnitDefID].translatedHumanName
humanName = string.gsub(humanName, 'Scavenger', 'Scav')
if font:GetTextWidth(humanName) * nameFontSize > width*1.05 then
while font:GetTextWidth(humanName) * nameFontSize > width do
humanName = string.sub(humanName, 1, string.len(humanName)-1)
end
humanName = humanName..'...'
end
font2:Begin()
font2:Print(unitNameColor .. humanName, backgroundRect[3] - width + bgpadding, backgroundRect[4] - contentPadding - (nameFontSize * 0.76), nameFontSize, "o")
--font2:End()
-- custom unit info area
customInfoArea = { math_floor(backgroundRect[3] - width - bgpadding), math_floor(backgroundRect[2]), math_floor(backgroundRect[3] - bgpadding), math_floor(backgroundRect[2] + height) }
if not displayMode == 'unitdef' or not showBuilderBuildlist or not unitDefInfo[displayUnitDefID].buildOptions or (not (WG['buildmenu'] and WG['buildmenu'].hoverID)) then
RectRound(customInfoArea[1], customInfoArea[2], customInfoArea[3], customInfoArea[4], elementCorner*0.66, 1, 0, 0, 0, { 0.8, 0.8, 0.8, 0.08 }, { 0.8, 0.8, 0.8, 0.15 })
end
local contentPaddingLeft = contentPadding * 0.6
local texSize = fontSize * 0.6
local leftSideHeight = (backgroundRect[4] - backgroundRect[2]) * 0.47
local posY1 = math_floor(backgroundRect[2] + leftSideHeight) - contentPadding - ((math_floor(backgroundRect[2] + leftSideHeight) - math_floor(backgroundRect[2])) * 0.1)
local posY2 = math_floor(backgroundRect[2] + leftSideHeight) - contentPadding - ((math_floor(backgroundRect[2] + leftSideHeight) - math_floor(backgroundRect[2])) * 0.38)
local posY3 = math_floor(backgroundRect[2] + leftSideHeight) - contentPadding - ((math_floor(backgroundRect[2] + leftSideHeight) - math_floor(backgroundRect[2])) * 0.67)
local valueY1, valueY2, valueY3 = '', '', ''
local health, maxHealth, _, _, buildProgress
if displayUnitID then
local metalMake, metalUse, energyMake, energyUse = spGetUnitResources(displayUnitID)
if metalMake then
valueY1 = (metalMake > 0 and valuePlusColor .. '+' .. (metalMake < 10 and round(metalMake, 1) or round(metalMake, 0)) .. ' ' or '') .. (metalUse > 0 and valueMinColor .. '-' .. (metalUse < 10 and round(metalUse, 1) or round(metalUse, 0)) or '')
valueY2 = (energyMake > 0 and valuePlusColor .. '+' .. (energyMake < 10 and round(energyMake, 1) or round(energyMake, 0)) .. ' ' or '') .. (energyUse > 0 and valueMinColor .. '-' .. (energyUse < 10 and round(energyUse, 1) or round(energyUse, 0)) or '')
valueY3 = ''
end
-- display health value/bar
health, maxHealth, _, _, buildProgress = spGetUnitHealth(displayUnitID)
if health then
local color = bfcolormap[math_min(math_max(math_floor((health / maxHealth) * 100), 0), 100)]
valueY3 = convertColor(color[1], color[2], color[3]) .. math_floor(health)
end
-- display unit owner name
local teamID = Spring.GetUnitTeam(displayUnitID)
if mySpec or (myTeamID ~= teamID) then
local _, playerID, _, isAiTeam = Spring.GetTeamInfo(teamID, false)
local name = Spring.GetPlayerInfo(playerID, false)
if isAiTeam then
name = GetAIName(teamID)
end
if not mySpec and Spring.GetModOptions().teamcolors_anonymous_mode ~= 'disabled' then
name = "??????"
end
if name then
local fontSizeOwner = fontSize * 0.87