Skip to content

Commit

Permalink
autocolors: keep randomized color variation the same (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwetuin authored Feb 5, 2025
1 parent 80f502f commit 1cc254c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
44 changes: 18 additions & 26 deletions luarules/gadgets/game_autocolors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ local teamColors = {
},
}

math.randomseed(1) -- make sure the next sequence of randoms can be reproduced
local teamRandoms = {}
for i = 1, #teamList do
teamRandoms[teamList[i]] = { math.random(), math.random(), math.random() }
end
math.randomseed(math.random())

local function shuffleTable(Table)
local originalTable = {}
table.append(originalTable, Table)
Expand Down Expand Up @@ -765,15 +772,10 @@ else -- UNSYNCED
elseif allyTeamID ~= myAllyTeamID then
color = {Spring.GetConfigInt("SimpleTeamColorsEnemyR", 255), Spring.GetConfigInt("SimpleTeamColorsEnemyG", 16), Spring.GetConfigInt("SimpleTeamColorsEnemyB", 5)}
end
color[1] = math.min(color[1] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
color[2] = math.min(color[2] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
color[3] = math.min(color[3] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
Spring.SetTeamColor(
teamID,
color[1] / 255,
color[2] / 255,
color[3] / 255
)
color[1] = math.min(color[1] + brightnessVariation, 255) + ((teamRandoms[teamID][1] * (maxColorVariation * 2)) - maxColorVariation)
color[2] = math.min(color[2] + brightnessVariation, 255) + ((teamRandoms[teamID][2] * (maxColorVariation * 2)) - maxColorVariation)
color[3] = math.min(color[3] + brightnessVariation, 255) + ((teamRandoms[teamID][3] * (maxColorVariation * 2)) - maxColorVariation)
Spring.SetTeamColor(teamID, color[1] / 255, color[2] / 255, color[3] / 255)

-- auto ffa gradient colored for huge player games
elseif
Expand All @@ -789,22 +791,14 @@ else -- UNSYNCED
elseif teamID == myTeamID then
brightnessVariation = 0
maxColorVariation = 0
color[1] = color[1] + 210
color[2] = color[2] + 210
color[3] = color[3] + 210
elseif allyTeamID == myAllyTeamID then
brightnessVariation = brightnessVariation - 40
maxColorVariation = math.ceil(maxColorVariation * 1.2)
color[1] = color[1] + 200
color[2] = color[2] + 200
color[3] = color[3] + 200
end
color[1] = math.min(color[1] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
color[2] = math.min(color[2] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
color[3] = math.min(color[3] + brightnessVariation, 255) + math.random(-maxColorVariation, maxColorVariation)
Spring.SetTeamColor(
teamID,
color[1] / 255,
color[2] / 255,
color[3] / 255
)
color[1] = math.min(color[1] + brightnessVariation, 255) + ((teamRandoms[teamID][1] * (maxColorVariation * 2)) - maxColorVariation)
color[2] = math.min(color[2] + brightnessVariation, 255) + ((teamRandoms[teamID][2] * (maxColorVariation * 2)) - maxColorVariation)
color[3] = math.min(color[3] + brightnessVariation, 255) + ((teamRandoms[teamID][3] * (maxColorVariation * 2)) - maxColorVariation)
Spring.SetTeamColor(teamID, color[1] / 255, color[2] / 255, color[3] / 255)

else
Spring.SetTeamColor(teamID, r, g, b)
Expand Down Expand Up @@ -833,9 +827,7 @@ else -- UNSYNCED
if playerID ~= myPlayerID then
return
end

mySpecState = Spring.GetSpectatingState()

Spring.SetConfigInt("UpdateTeamColors", 1)
end
end
19 changes: 3 additions & 16 deletions luaui/Widgets/gui_com_nametags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ local showSkillValue = true
local playerRankSize = fontSize * 1.05
local playerRankImages = "luaui\\images\\advplayerslist\\ranks\\"

local comLevelSize = fontSize * 2.5
local comLevelImages = "luaui\\images\\Ranks\\rank"

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Expand All @@ -46,8 +43,6 @@ local IsUnitVisible = Spring.IsUnitVisible
local IsUnitIcon = Spring.IsUnitIcon
local GetCameraPosition = Spring.GetCameraPosition
local GetUnitPosition = Spring.GetUnitPosition
local GetUnitExperience = Spring.GetUnitExperience
local GetUnitRulesParam = Spring.GetUnitRulesParam

local glTexture = gl.Texture
local glTexRect = gl.TexRect
Expand All @@ -69,8 +64,6 @@ local diag = math.diag
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------



local vsx, vsy = Spring.GetViewGeometry()

local fontfile = "fonts/" .. Spring.GetConfigString("bar_font2", "Exo2-SemiBold.otf")
Expand Down Expand Up @@ -111,7 +104,6 @@ local CheckedForSpec = false

local spec = Spring.GetSpectatingState()
local myTeamID = Spring.GetMyTeamID()
local myPlayerID = Spring.GetMyPlayerID()
local GaiaTeam = Spring.GetGaiaTeamID()

local comHeight = {}
Expand Down Expand Up @@ -157,7 +149,7 @@ local function GetCommAttributes(unitID, unitDefID)
else
name = Spring.I18N('ui.playersList.aiName', { name = Spring.GetGameRulesParam('ainame_' .. team) })
end

else
if UnitDefs[unitDefID].customParams.decoyfor then
name = Spring.I18N('units.decoyCommanderNameTag')
Expand Down Expand Up @@ -342,7 +334,6 @@ function widget:Update(dt)
end
-- new
myTeamID = Spring.GetMyTeamID()
myPlayerID = Spring.GetMyPlayerID()
name = GetPlayerInfo(select(2, GetTeamInfo(myTeamID, false)), false)
if comnameList[name] ~= nil then
comnameList[name] = gl.DeleteList(comnameList[name])
Expand Down Expand Up @@ -499,15 +490,11 @@ function widget:Shutdown()
end

function widget:PlayerChanged(playerID)
local prevSpec = spec
spec = Spring.GetSpectatingState()
if spec and prevSpec ~= spec then
CheckTeamColors()
RemoveLists()
end
myTeamID = Spring.GetMyTeamID()
local name, _ = GetPlayerInfo(playerID, false)
comnameList[name] = nil
CheckAllComs() -- handle substitutions, etc
sec = 99
end

function widget:UnitCreated(unitID, unitDefID, unitTeam)
Expand Down

0 comments on commit 1cc254c

Please sign in to comment.