Skip to content

Commit

Permalink
unit wait + idle builder icons: dont show when unit is being built
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwetuin committed Jun 29, 2024
1 parent a588027 commit 2fc1399
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 57 deletions.
57 changes: 26 additions & 31 deletions luaui/Widgets/gui_unit_idlebuilder_icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ local iconSequenceFrametime = 0.02 -- duration per frame
local teamUnits = {} -- table of teamid to table of stallable unitID : unitDefID
local teamList = {} -- {team1, team2, team3....}
local idleUnitList = {}
local unitBeingBuilt = {}

local spGetCommandQueue = Spring.GetCommandQueue
local spGetFactoryCommands = Spring.GetFactoryCommands
local spGetUnitTeam = Spring.GetUnitTeam
local spec, fullview = Spring.GetSpectatingState()
local myTeamID = Spring.GetMyTeamID()
local spValidUnitID = Spring.ValidUnitID
local spGetUnitIsDead = Spring.GetUnitIsDead
local spGetUnitIsBeingBuilt = Spring.GetUnitIsBeingBuilt

local unitConf = {}
for unitDefID, unitDef in pairs(UnitDefs) do
Expand Down Expand Up @@ -110,36 +112,32 @@ function widget:Initialize()
end

local function updateIcon(unitID, unitDefID, gf)
if unitBeingBuilt[unitID] and not Spring.GetUnitIsBeingBuilt(unitID) then
unitBeingBuilt[unitID] = nil
else
if not (unitConf[unitDefID][3] and spGetFactoryCommands(unitID, 1)[1] or spGetCommandQueue(unitID, 1)[1]) then
if iconVBO.instanceIDtoIndex[unitID] == nil then -- not already being drawn
if Spring.ValidUnitID(unitID) and not Spring.GetUnitIsDead(unitID) then
if not idleUnitList[unitID] then
idleUnitList[unitID] = os.clock()
elseif idleUnitList[unitID] < os.clock() - idleUnitDelay then
pushElementInstance(
iconVBO, -- push into this Instance VBO Table
{unitConf[unitDefID][1], unitConf[unitDefID][1], 0, unitConf[unitDefID][2], -- lengthwidthcornerheight
0, --Spring.GetUnitTeam(featureID), -- teamID
4, -- how many vertices should we make ( 2 is a quad)
gf, 0, 0.8 , 0, -- the gameFrame (for animations), and any other parameters one might want to add
1,0,1,0, -- These are our default UV atlas tranformations, note how X axis is flipped for atlas
0, 0, 0, 0}, -- these are just padding zeros, that will get filled in
unitID, -- this is the key inside the VBO Table, should be unique per unit
false, -- update existing element
true, -- noupload, dont use unless you know what you want to batch push/pop
unitID) -- last one should be featureID!
end
if not (unitConf[unitDefID][3] and spGetFactoryCommands(unitID, 1)[1] or spGetCommandQueue(unitID, 1)[1]) then
if iconVBO.instanceIDtoIndex[unitID] == nil then -- not already being drawn
if spValidUnitID(unitID) and not spGetUnitIsDead(unitID) and not spGetUnitIsBeingBuilt(unitID) then
if not idleUnitList[unitID] then
idleUnitList[unitID] = os.clock()
elseif idleUnitList[unitID] < os.clock() - idleUnitDelay then
pushElementInstance(
iconVBO, -- push into this Instance VBO Table
{unitConf[unitDefID][1], unitConf[unitDefID][1], 0, unitConf[unitDefID][2], -- lengthwidthcornerheight
0, --Spring.GetUnitTeam(featureID), -- teamID
4, -- how many vertices should we make ( 2 is a quad)
gf, 0, 0.8 , 0, -- the gameFrame (for animations), and any other parameters one might want to add
1,0,1,0, -- These are our default UV atlas tranformations, note how X axis is flipped for atlas
0, 0, 0, 0}, -- these are just padding zeros, that will get filled in
unitID, -- this is the key inside the VBO Table, should be unique per unit
false, -- update existing element
true, -- noupload, dont use unless you know what you want to batch push/pop
unitID) -- last one should be featureID!
end
end
else
if iconVBO.instanceIDtoIndex[unitID] then
popElementInstance(iconVBO, unitID, true)
end
idleUnitList[unitID] = nil
end
else
if iconVBO.instanceIDtoIndex[unitID] then
popElementInstance(iconVBO, unitID, true)
end
idleUnitList[unitID] = nil
end
end

Expand Down Expand Up @@ -171,9 +169,6 @@ function widget:VisibleUnitAdded(unitID, unitDefID, unitTeam) -- remove the corr
if unitConf[unitDefID] then
if teamUnits[unitTeam] == nil then teamUnits[unitTeam] = {} end
teamUnits[unitTeam][unitID] = unitDefID
if Spring.GetUnitIsBeingBuilt(unitID) then
unitBeingBuilt[unitID] = true
end
end
end

Expand Down
48 changes: 22 additions & 26 deletions luaui/Widgets/gui_unit_wait_icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ local CMD_WAIT = CMD.WAIT

local teamUnits = {} -- table of teamid to table of stallable unitID : unitDefID
local teamList = {} -- {team1, team2, team3....}
local unitBeingBuilt = {}

local spGetCommandQueue = Spring.GetCommandQueue
local spGetFactoryCommands = Spring.GetFactoryCommands
local spGetUnitTeam = Spring.GetUnitTeam
local spec, fullview = Spring.GetSpectatingState()
local myTeamID = Spring.GetMyTeamID()
local spValidUnitID = Spring.ValidUnitID
local spGetUnitIsDead = Spring.GetUnitIsDead
local spGetUnitIsBeingBuilt = Spring.GetUnitIsBeingBuilt


local unitConf = {}
for udid, unitDef in pairs(UnitDefs) do
Expand Down Expand Up @@ -124,30 +127,26 @@ local function updateIcons()
end

local function updateIcon(unitID, unitDefID, gf)
if unitBeingBuilt[unitID] and not Spring.GetUnitIsBeingBuilt(unitID) then
unitBeingBuilt[unitID] = nil
else
local queue = unitConf[unitDefID][3] and spGetFactoryCommands(unitID, 1) or spGetCommandQueue(unitID, 1)
if queue ~= nil and queue[1] and queue[1].id == CMD_WAIT then
if iconVBO.instanceIDtoIndex[unitID] == nil then -- not already being drawn
if Spring.ValidUnitID(unitID) and not Spring.GetUnitIsDead(unitID) then
pushElementInstance(
iconVBO, -- push into this Instance VBO Table
{unitConf[unitDefID][1], unitConf[unitDefID][1], 0, unitConf[unitDefID][2], -- lengthwidthcornerheight
0, --Spring.GetUnitTeam(featureID), -- teamID
4, -- how many vertices should we make ( 2 is a quad)
gf, 0, 0.75 , 0, -- the gameFrame (for animations), and any other parameters one might want to add
0,1,0,1, -- These are our default UV atlas tranformations, note how X axis is flipped for atlas
0, 0, 0, 0}, -- these are just padding zeros, that will get filled in
unitID, -- this is the key inside the VBO Table, should be unique per unit
false, -- update existing element
true, -- noupload, dont use unless you know what you want to batch push/pop
unitID) -- last one should be featureID!
end
local queue = unitConf[unitDefID][3] and spGetFactoryCommands(unitID, 1) or spGetCommandQueue(unitID, 1)
if queue ~= nil and queue[1] and queue[1].id == CMD_WAIT then
if iconVBO.instanceIDtoIndex[unitID] == nil then -- not already being drawn
if spValidUnitID(unitID) and not spGetUnitIsDead(unitID) and not spGetUnitIsBeingBuilt(unitID) then
pushElementInstance(
iconVBO, -- push into this Instance VBO Table
{unitConf[unitDefID][1], unitConf[unitDefID][1], 0, unitConf[unitDefID][2], -- lengthwidthcornerheight
0, --Spring.GetUnitTeam(featureID), -- teamID
4, -- how many vertices should we make ( 2 is a quad)
gf, 0, 0.75 , 0, -- the gameFrame (for animations), and any other parameters one might want to add
0,1,0,1, -- These are our default UV atlas tranformations, note how X axis is flipped for atlas
0, 0, 0, 0}, -- these are just padding zeros, that will get filled in
unitID, -- this is the key inside the VBO Table, should be unique per unit
false, -- update existing element
true, -- noupload, dont use unless you know what you want to batch push/pop
unitID) -- last one should be featureID!
end
elseif iconVBO.instanceIDtoIndex[unitID] then
popElementInstance(iconVBO, unitID, true)
end
elseif iconVBO.instanceIDtoIndex[unitID] then
popElementInstance(iconVBO, unitID, true)
end
end

Expand Down Expand Up @@ -179,9 +178,6 @@ function widget:VisibleUnitAdded(unitID, unitDefID, unitTeam) -- remove the corr
if unitConf[unitDefID] then
if teamUnits[unitTeam] == nil then teamUnits[unitTeam] = {} end
teamUnits[unitTeam][unitID] = unitDefID
if Spring.GetUnitIsBeingBuilt(unitID) then
unitBeingBuilt[unitID] = true
end
end
end

Expand Down

0 comments on commit 2fc1399

Please sign in to comment.