function widget:GetInfo() return { name = "XPicons", desc = "blabla", author = "q", date = "today", license = "GNU GPL, v2 or later", layer = 5, enabled = false -- loaded by default? } end ---------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------ local pos = {} -- unit position local rect = {} -- rectangle for i = 1,4 do --rectangle points rect[i] = {} end local tex = {} --texture coordinates tex[1] = {0, 0} tex[2] = {0, 1} tex[3] = {1, 1} tex[4] = {1, 0} local myAllyTeamID = Spring.GetMyAllyTeamID() ------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------- --Speed-ups local gl = gl local IsUnitVisible = Spring.IsUnitVisible local GetUnitPosition = Spring.GetUnitPosition local GetUnitDefID = Spring.GetUnitDefID local GetUnitDefDimensions = Spring.GetUnitDefDimensions local GetCameraVectors = Spring.GetCameraVectors local GetUnitExperience = Spring.GetUnitExperience local GetUnitAllyTeam = Spring.GetUnitAllyTeam ------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------- function widget:DrawWorld() local allUnits = Spring.GetAllUnits() for _,unitID in ipairs(allUnits) do if (IsUnitVisible(unitID)) then local allyTeamID = GetUnitAllyTeam(unitID) if (allyTeamID == myAllyTeamID) then local cam = Spring.GetCameraVectors() local unitDefID = GetUnitDefID(unitID) local h = GetUnitDefDimensions(unitDefID).height local xp = GetUnitExperience(unitID) local rank = math.min(math.floor(xp*10)+1, 11) pos[1], pos[2], pos[3] = GetUnitPosition(unitID) pos[2] = pos[2] + h*0.75 for i = 1, 3 do --set up the rectangle coordinates rect[1][i] = pos[i] + cam.up[i]*12 - cam.right[i]* 0 rect[2][i] = pos[i] + cam.up[i]*12 + cam.right[i]*12 rect[3][i] = pos[i] - cam.up[i]* 0 + cam.right[i]*12 rect[4][i] = pos[i] - cam.up[i]* 0 - cam.right[i]* 0 end gl.ResetState() gl.DepthTest(true) gl.Texture("LuaUI/Images/ranks/"..rank..".tga") gl.MatrixMode(GL.TEXTURE) gl.PushMatrix() gl.Rotate(90, 1, 0, 0) gl.PopMatrix() gl.MatrixMode(GL.MODELVIEW) gl.PushMatrix() gl.Translate(-15*cam.right[1], -15*cam.right[2], -15*cam.right[3]) gl.PopMatrix() gl.BeginEnd(GL.QUADS, function() for i = 1, 4 do -- draw rectangle gl.Vertex(rect[i][1], rect[i][2], rect[i][3]) gl.TexCoord(tex[i][1], tex[i][2]) end end ) gl.ResetState() end end end end