Skip to content

Commit c3f7235

Browse files
Colorize battle buttons based on their states
1 parent 5b76607 commit c3f7235

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

LuaMenu/widgets/chili/skins/Evolved/skin.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ skin.positive_button = {
164164
DrawControl = DrawButton,
165165
}
166166

167+
skin.battle_default_button = { --Blue
168+
TileImageBK = ":cl:tech_button_bk.png",
169+
TileImageFG = ":cl:tech_button_bright_small_fg.png",
170+
tiles = {20, 20, 20, 20}, --// tile widths: left,top,right,bottom
171+
padding = {10, 10, 10, 10},
172+
173+
backgroundColor = {0.10, 0.10, 0.1, 0.65},
174+
focusColor = {1.0, 1.0, 1.0, 0.1}, -- color when focused
175+
borderColor = {0.1, 0.1, 0.1, 0.05},
176+
177+
DrawControl = DrawButton,
178+
}
179+
167180
skin.combobox = {
168181
TileImageBK = ":cl:combobox_ctrl.png",
169182
TileImageFG = ":cl:combobox_ctrl_fg.png",

LuaMenu/widgets/chobby/components/battle/battle_list_window.lua

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function BattleListWindow:init(parent)
181181
return
182182
end
183183
self:OnUpdateBattleInfo(battleID)
184+
self:UpdateButtonColor(battleID)
184185
SoftUpdate()
185186
end
186187
lobby:AddListener("OnUpdateBattleInfo", self.onUpdateBattleInfo)
@@ -235,6 +236,11 @@ function BattleListWindow:Update()
235236
for _, battle in pairs(battles) do
236237
self:AddBattle(battle.battleID, battle)
237238
end
239+
240+
for _, battle in pairs(battles) do
241+
self:UpdateButtonColor(battle.battleID)
242+
end
243+
238244
self:UpdateFilters()
239245
self:UpdateInfoPanel()
240246
end
@@ -274,7 +280,7 @@ end
274280
function BattleListWindow:MakeWatchBattle(battleID, battle)
275281
local height = self.itemHeight - 20
276282
local parentButton = Button:New {
277-
classname = "button_rounded",
283+
classname = "battle_default_button",
278284
name = "battleButton",
279285
x = 0,
280286
right = 0,
@@ -468,7 +474,7 @@ end
468474
function BattleListWindow:MakeJoinBattle(battleID, battle)
469475
local height = self.itemHeight - 20
470476
local parentButton = Button:New {
471-
classname = "button_rounded",
477+
classname = "battle_default_button",
472478
name = "battleButton",
473479
x = 0,
474480
right = 0,
@@ -633,6 +639,7 @@ function BattleListWindow:AddBattle(battleID, battle)
633639
end
634640

635641
self:AddRow({button}, battle.battleID)
642+
self:UpdateButtonColor(battleID) -- necessary for some reason, despite BAR not needing this
636643
end
637644

638645
function BattleListWindow:ItemInFilter(id)
@@ -689,6 +696,45 @@ function BattleListWindow:CompareItems(id1, id2)
689696
end
690697
end
691698

699+
function BattleListWindow:UpdateButtonColor(battleID)
700+
701+
local items = self:GetRowItems(battleID)
702+
if not items then
703+
return
704+
end
705+
local battle = lobby:GetBattle(battleID)
706+
if battle == nil then return end
707+
708+
local oldbuttonstyle = items.battleButton.backgroundColor
709+
local battlebuttonstyle = {0.10, 0.10, 0.95, 0.65} --blue
710+
if battle.passworded then
711+
battlebuttonstyle = {0.60, 0.10, 0.85, 0.65} --violet
712+
elseif battle.isMatchMaker then
713+
battlebuttonstyle = {0.90, 0.10, 0.10, 0.65} --red
714+
elseif lobby:GetBattlePlayerCount(battleID) < 1 then
715+
battlebuttonstyle = {0.10, 0.10, 0.95, 0.65} --blue
716+
elseif battle.isRunning then
717+
battlebuttonstyle = {0.70, 0.60, 0.1, 0.65} --yellow
718+
else
719+
battlebuttonstyle = {0.10, 0.50, 0.10, 0.65} --green
720+
end
721+
local colorChanged = false
722+
for i, c in ipairs(oldbuttonstyle) do
723+
if c ~= battlebuttonstyle[i] then
724+
colorChanged = true
725+
break
726+
end
727+
end
728+
--Spring.Echo("BattleListWindow:UpdateButtonColor",battleID,battlebuttonstyle, items.battleButton.backgroundColor,battle.isRunning ,battle.passworded, lobby:GetBattlePlayerCount(battleID))
729+
730+
if colorChanged then
731+
--Spring.Echo("BattleListWindow:UpdateButtonColor",battleID,battlebuttonstyle, items.battleButton.backgroundColor,battle.isRunning ,battle.passworded, lobby:GetBattlePlayerCount(battleID))
732+
items.battleButton.backgroundColor = battlebuttonstyle
733+
items.battleButton.focusColor = battlebuttonstyle
734+
items.battleButton:Invalidate()
735+
end
736+
end
737+
692738
function BattleListWindow:RecalculateOrder(id)
693739
if lobby.commandBuffer then
694740
return
@@ -771,6 +817,7 @@ function BattleListWindow:JoinedBattle(battleID)
771817
local playerCount = lobby:GetBattlePlayerCount(battleID)
772818
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
773819
end
820+
self:UpdateButtonColor(battleID)
774821
self:RecalculateOrder(battleID)
775822
end
776823

@@ -794,6 +841,7 @@ function BattleListWindow:LeftBattle(battleID)
794841
local playerCount = lobby:GetBattlePlayerCount(battleID)
795842
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
796843
end
844+
self:UpdateButtonColor(battleID)
797845
self:RecalculateOrder(battleID)
798846
end
799847

@@ -870,6 +918,7 @@ function BattleListWindow:OnUpdateBattleInfo(battleID)
870918
local playerCount = lobby:GetBattlePlayerCount(battleID)
871919
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
872920
end
921+
self:UpdateButtonColor(battleID)
873922
self:RecalculateOrder(battleID)
874923
end
875924

@@ -892,6 +941,7 @@ function BattleListWindow:OnBattleIngameUpdate(battleID, isRunning)
892941
runningImage.file = BATTLE_NOT_RUNNING
893942
end
894943
runningImage:Invalidate()
944+
self:UpdateButtonColor(battleID)
895945
self:RecalculateOrder(battleID)
896946
end
897947

LuaMenu/widgets/chobby/components/battle/battle_watch_list_window.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ function BattleWatchListWindow:Update()
9595
for _, battle in pairs(battles) do
9696
self:AddBattle(battle.battleID, battle)
9797
end
98+
99+
for _, battle in pairs(battles) do
100+
self:UpdateButtonColor(battle.battleID)
101+
end
98102
end
99103

100104
function BattleWatchListWindow:AddBattle(battleID)
@@ -262,6 +266,7 @@ function BattleWatchListWindow:JoinedBattle(battleID)
262266
local playersOnMapCaption = items.battleButton:GetChildByName("playersOnMapCaption")
263267
local playerCount = lobby:GetBattlePlayerCount(battleID)
264268
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
269+
self:UpdateButtonColor(battleID)
265270
self:RecalculateOrder(battleID)
266271
end
267272

@@ -274,6 +279,7 @@ function BattleWatchListWindow:LeftBattle(battleID)
274279
local playersOnMapCaption = items.battleButton:GetChildByName("playersOnMapCaption")
275280
local playerCount = lobby:GetBattlePlayerCount(battleID)
276281
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
282+
self:UpdateButtonColor(battleID)
277283
self:RecalculateOrder(battleID)
278284
end
279285

@@ -304,7 +310,7 @@ function BattleWatchListWindow:OnUpdateBattleInfo(battleID)
304310
local playersOnMapCaption = items.battleButton:GetChildByName("playersOnMapCaption")
305311
local playerCount = lobby:GetBattlePlayerCount(battleID)
306312
playersOnMapCaption:SetCaption(playerCount .. ((playerCount == 1 and " player on " ) or " players on ") .. battle.mapName:gsub("_", " "))
307-
313+
self:UpdateButtonColor(battleID)
308314
self:RecalculateOrder(battleID)
309315
end
310316

0 commit comments

Comments
 (0)