However, I found that then when I use this widget in Kernel Panic, it shows lots of 0 when building. This is most probably due to the beam laser that are used to replace nano, and are actually real weapon with very low power.
From a general standpoint, I am torn about whether 0 damage should be shown or not.
But for KP I have to disable it or have "0" comes out of everything under construction. So far I disable the showing of 0 damage like that:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- . file: . . gui_display_dps.lua
-- . brief: . Displays DPS done to your allies units
-- . author: . Owen Martindell
--
-- . Copyright (C) 2007.
-- . Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
. return {
. . name . . . = "Display DPS",
. . desc . . . = "Displays damage per second done to your allies units v1.1",
. . author . . = "TheFatController",
. . date . . . = "August 05, 2007",
. . license . = "GNU GPL, v2 or later",
. . layer . . = 0,
. . enabled . = true . -- . loaded by default
. }
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Speed Up
local GetUnitDefID . . . . = Spring.GetUnitDefID
local GetUnitDefDimensions = Spring.GetUnitDefDimensions
local AreTeamsAllied . . . = Spring.AreTeamsAllied
local GetMyTeamID . . . . . = Spring.GetMyTeamID
local GetGameSpeed . . . . = Spring.GetGameSpeed
local glTranslate . . . = gl.Translate
local glColor . . . . . = gl.Color
local glBillboard . . . = gl.Billboard
local glText . . . . . = gl.Text
local glDepthMask . . . = gl.DepthMask
local glDepthTest . . . = gl.DepthTest
local glAlphaTest . . . = gl.AlphaTest
local glBlending . . . = gl.Blending
local glDrawFuncAtUnit = gl.DrawFuncAtUnit
local GL_GREATER . . . . . . = GL.GREATER
local GL_SRC_ALPHA . . . . . = GL.SRC_ALPHA
local GL_ONE . . . . . . . . = GL.ONE
local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local damageTable = {}
local unitParalyze = {}
local unitDamage = {}
local countDown = 0
local paused = false
local update = false
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
. for udid, ud in ipairs(UnitDefs) do
. . ud.show_dps_height = (GetUnitDefDimensions(udid).height * 0.9)
. end
end
local function getTextSize(damage, paralyze)
. local sizeMod = 3
. if paralyze then sizeMod = 2.25 end
. return math.floor(8 * (1 + sizeMod * (1 - (200 / (200 + damage)))))
end
local function calcDPS(inTable, paralyze)
. for unitID,damage in pairs(inTable) do
. . local unitDefID . = GetUnitDefID(unitID)
. . local unitDef . . = UnitDefs[unitDefID]
. . if (unitDef ~= nil) then
. . . local textSize = getTextSize(damage, paralyze)
. . . if (damage >= 1) then
. . . . table.insert(damageTable, {
. . . . . unitID,
. . . . . math.floor(damage),
. . . . . unitDef.show_dps_height,
. . . . . (6 - math.random(0,12)),
. . . . . textSize,
. . . . . 0,
. . . . . 1,
. . . . . paralyze
. . . . })
. . . . inTable[unitID] = 0
. . . else
. . . . inTable[unitID] = nil
. . . end
. . end
. end
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
. unitDamage[unitID] = nil
. unitParalyze[unitID] = nil
. for i, damage in pairs(damageTable) do
. . if (damage[1] == unitID) then
. . . table.remove(damageTable, i)
. . end
. end
end
function widget:UnitTaken(unitID, unitDefID, oldTeam, newTeam)
. if (AreTeamsAllied(oldTeam, newTeam)) then
. . return
. else
. . widget:UnitDestroyed(unitID, unitDefID, newTeam)
. end
end
function widget:Update(DeltaTime)
if paused then return end
if (countDown > 1) then
. countDown = 0
. update = true
else
. countDown = countDown + DeltaTime
end
end
local function addDamage(inTable, damage, unitID, ud, paralyze)
. for uID,_ in pairs(inTable) do
. . if (uID == unitID) then
. . . inTable[uID] = inTable[uID] + damage
. . . return
. . end
. end
.
. if not update then
.
. . inTable[unitID] = 0
.
. . local textSize = getTextSize(damage, paralyze)
.
. . table.insert(damageTable, {
. . . unitID,
. . . math.floor(damage),
. . . ud.show_dps_height,
. . . (6 - math.random(0,12)),
. . . textSize,
. . . 0,
. . . 1,
. . . paralyze
. . })
.
. . table.sort(damageTable, function(m1,m2) return m1[2] < m2[2]; end)
. .
. end
end
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer)
. local ud = UnitDefs[unitDefID]
. if (ud == nil) then
. . return
. end
.
. if paralyzer then
. . addDamage(unitParalyze, damage, unitID, ud, true) .
. else
. . addDamage(unitDamage, damage, unitID, ud, false) .
. end
end
local function DrawUnitFunc(yshift, xshift, damage, textSize, alpha, paralyze)
. if(damage>=1) then
. . glTranslate(xshift, yshift, 0)
. . glBillboard()
. . gl.MultiTexCoord(1, 0.25 + (0.5 * alpha))
. . if paralyze then
. . . glColor(0, 0, 1)
. . . glText(damage, 0, 0, textSize, 'cnO')
. . else
. . . glColor(1, 1, 1)
. . . glText(damage, 0, 0, textSize, 'cno')
. . end
. end
end
function widget:DrawWorld()
. if update then
. . if next(unitDamage) then calcDPS(unitDamage, false) end
. . if next(unitParalyze) then calcDPS(unitParalyze, true) end
. . table.sort(damageTable, function(m1,m2) return m1[2] < m2[2]; end)
. . update = false
. end
.
. if (next(damageTable) == nil) then
. . return
. end
.
. _,_,paused = GetGameSpeed()
. .
. glDepthMask(true)
. glDepthTest(true)
. glAlphaTest(GL_GREATER, 0)
. glBlending(GL_SRC_ALPHA, GL_ONE)
. gl.Texture(1, LUAUI_DIRNAME .. "Images/gradient_alpha_2.png")
. for i, damage in pairs(damageTable) do
. . if (damage[7] <= 0) then
. . . table.remove(damageTable,i)
. . else
. . . glDrawFuncAtUnit(damage[1], false, DrawUnitFunc,
. . . . . . . . . . . . (damage[3] + damage[6]),
. . . . . . . . . . . . damage[4], damage[2], damage[5],
. . . . . . . . . . . . damage[7], damage[8])
. . . if not paused then
. . . . if damage[8] then
. . . . . damage[7] = damage[7] - 0.05
. . . . . damage[5] = damage[5] + 0.2
. . . . else
. . . . . local fadeTime = math.max(0.03 - (damage[2] / 333333), 0.015)
. . . . . local riseTime = 1 + math.min((damage[2] / 2500), 2)
. . . . . damage[6] = damage[6] + riseTime
. . . . . if (damage[6] > 25) then
. . . . . . damage[7] = damage[7] - fadeTime
. . . . . end
. . . . end
. . . end
. . end
. end
. gl.Texture(1, false)
. glBlending(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
. glAlphaTest(false)
. glDepthTest(false)
. glDepthMask(false)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
But I don't understand most of that code, so I hope it wasn't a too awful method of removing the zeroes.