@@ -54,7 +54,7 @@ local loadoutDisplay
5454
5555---- ----------------------------------------------------------------------------
5656---- ----------------------------------------------------------------------------
57- -- Utils
57+ -- Loadout Handling
5858
5959local function AddItemToLoadout (reward )
6060 local targetTable
@@ -66,6 +66,9 @@ local function AddItemToLoadout(reward)
6666 elseif reward .structure then
6767 targetTable = currentLoadout .structures
6868 itemType = " structure"
69+ elseif reward .commander then
70+ targetTable = currentLoadout .commander
71+ itemType = " commander"
6972 end
7073 targetTable [# targetTable + 1 ] = reward
7174 loadoutDisplay .AddToLoadoutDisplay (reward )
@@ -76,6 +79,21 @@ local function SendLoadout()
7679 Spring .SendLuaRulesMsg (" rk_loadout " .. encoded )
7780end
7881
82+ local function ReadLoadout ()
83+ local teamID = Spring .GetMyTeamID ()
84+ local encoded = Spring .GetTeamRulesParam (teamID , " rk_loadout" )
85+ local loadout = CustomKeyToUsefulTable (encoded )
86+ if loadout .needInit then
87+ loadout = VFS .Include (" LuaRules/Configs/RogueK/base_loadout.lua" )
88+ end
89+ return loadout
90+ end
91+
92+ ---- ----------------------------------------------------------------------------
93+ ---- ----------------------------------------------------------------------------
94+ -- Utils
95+
96+
7997local function ClickRewardCategoryButton (buttonID )
8098 for i = 1 , # rewardButtons do
8199 rewardButtons [i ].SetSelection (buttonID == i )
@@ -155,9 +173,6 @@ local function SetupRewardSelectionView(parent)
155173 holder :SetVisibility (true )
156174
157175 for i = 1 , math.max (# buttons , # rewardOptions ) do
158- if not rewardOptions [i ] then
159- buttons [i ]:SetVisibility (false )
160- end
161176 if not buttons [i ] then
162177 buttons [i ] = Chili .Button :New {
163178 parent = holder ,
@@ -168,10 +183,15 @@ local function SetupRewardSelectionView(parent)
168183 height = 45 ,
169184 }
170185 end
171- local rewardName = rewardOptions [i ]
172- buttons [i ]:SetCaption (rewardDefs .flatRewards [rewardName ].humanName )
173- buttons [i ].OnClick [1 ] = function ()
174- SelectReward (buttonID , rewardID , rewardName )
186+ if rewardOptions [i ] then
187+ local rewardName = rewardOptions [i ]
188+ buttons [i ]:SetCaption (rewardDefs .flatRewards [rewardName ].humanName )
189+ buttons [i ].OnClick [1 ] = function ()
190+ SelectReward (buttonID , rewardID , rewardName )
191+ end
192+ buttons [i ]:SetVisibility (true )
193+ else
194+ buttons [i ]:SetVisibility (false )
175195 end
176196 end
177197 end
@@ -349,24 +369,35 @@ local function MakeRewardList(holder, name, leftBound, rightBound, itemList)
349369
350370 function externalFunctions .AddItem (item )
351371 x , y , paragraphOffset = GetIconPosition (posIndex , iconsAcross , paragraphOffset )
352- local rawTooltip = item .name
353- local imageControl = Chili .Image :New {
372+ local button = Chili .Button :New {
354373 x = x ,
355374 y = y ,
356375 width = LOADOUT_ICON_SIZE ,
357376 height = LOADOUT_ICON_SIZE ,
358- keepAspect = true ,
359- color = color ,
360- tooltip = item . name ,
361- file = ' unitpics/ ' .. item . name .. ' .png ' ,
377+ tooltip = item . description ,
378+ caption = false ,
379+ padding = { 0 , 0 , 0 , 0 } ,
380+ noFont = true ,
362381 parent = rewardsHolder ,
363382 }
383+ local image = Chili .Image :New {
384+ x = 0 ,
385+ y = 0 ,
386+ width = LOADOUT_ICON_SIZE ,
387+ height = LOADOUT_ICON_SIZE ,
388+ file = item .image ,
389+ parent = button ,
390+ }
364391 local text = Chili .TextBox :New {
365392 text = item .humanName or item .name ,
366- parent = imageControl ,
393+ x = 4 ,
394+ y = 4 ,
395+ right = 4 ,
396+ font = {size = 10 },
397+ parent = image ,
367398 }
368399 itemControls [# itemControls + 1 ] = {
369- image = imageControl ,
400+ button = button ,
370401 }
371402 posIndex = posIndex + 1
372403 end
@@ -381,7 +412,7 @@ local function MakeRewardList(holder, name, leftBound, rightBound, itemList)
381412 posIndex = 0
382413 for i = 1 , # itemControls do
383414 x , y , paragraphOffset = GetIconPosition (posIndex , iconsAcross , paragraphOffset )
384- itemControls [i ].image :SetPos (x , y )
415+ itemControls [i ].button :SetPos (x , y )
385416
386417 posIndex = posIndex + 1
387418 end
@@ -402,14 +433,18 @@ local function SetupLoadoutPanel(bottomPanel)
402433 return
403434 end
404435
405- local structures
436+ local structures , commanderModules
406437 local factories = {}
407438 local function ResizeLoadout (xSize )
408439 local offset = 5
409440 if structures then
410441 structures .ResizeFunction (xSize / 2 )
411442 offset = structures .SetPosition (offset )
412443 end
444+ if commanderModules then
445+ commanderModules .ResizeFunction (xSize / 2 )
446+ offset = commanderModules .SetPosition (offset )
447+ end
413448
414449 offset = 5
415450 for i = 1 , # factories do
@@ -439,6 +474,7 @@ local function SetupLoadoutPanel(bottomPanel)
439474 }
440475
441476 structures = MakeRewardList (loadoutPanel , " Structures" , " 50%" , 12 , currentLoadout .structures )
477+ commanderModules = MakeRewardList (loadoutPanel , " Commander" , " 50%" , 12 , currentLoadout .commander )
442478 for i = 1 , # currentLoadout .factories do
443479 factories [i ] = MakeRewardList (loadoutPanel , " Factory " .. i , 12 , " 50%" , currentLoadout .factories [i ].units )
444480 end
@@ -451,6 +487,8 @@ local function SetupLoadoutPanel(bottomPanel)
451487 factories [item .factory ].AddItem (item )
452488 elseif item .structure then
453489 structures .AddItem (item )
490+ elseif item .commander then
491+ commanderModules .AddItem (item )
454492 end
455493 ResizeLoadout (loadoutPanel .width )
456494 end
@@ -542,10 +580,7 @@ local function MakePostgamePanel()
542580end
543581
544582local function InitializeRewardSelection ()
545- local teamID = Spring .GetMyTeamID ()
546- local encoded = Spring .GetTeamRulesParam (teamID , " rk_loadout" )
547- currentLoadout = CustomKeyToUsefulTable (encoded )
548-
583+ currentLoadout = ReadLoadout ()
549584 MakePostgamePanel ()
550585 ClickFirstEnabledButton ()
551586end
0 commit comments