
A few points:
1. This will not work with 0.74b3, you'll need an SVN build
2. This is mod specific, and should probably be included in
the mod package as a mod widget. If that's the case, then
you can remove the modName check in widget:Initialize()
3. It would be better to load some HUDs as several cut-up
textures rather than one texture. It's a waste of video ram to
use big textures with large transparent gaps in them.
4. This code does not render "pixel-perfect" images. For that,
you'd need correctly sized textures and the ':n:' prefix for the
texture names (GL_NEAREST filtering mode).
5 The hud is drawn over the FPS info panel. IIRC, lua has the
ability to completely redraw the FPS info panel, and you can
use "fpshud 0" to disable the engine's version. You could also
use a LuaRules gadget instead of a mod widget ... I think that
they get drawn before any of the engine's UI elements.
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: gui_cockpits.lua
-- brief: cockpits for FPS mode
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Cockpits",
desc = "Cockpits for FPS mode",
author = "trepan",
date = "May 23, 2007",
license = "GNU GPL, v2 or later",
layer = 9, -- draw early
enabled = false -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local modName = 'BA52.sd7'
local IMAGE_DIR = LUAUI_DIRNAME .. 'Images/cockpits/'
local cockpits = {
armcom = IMAGE_DIR .. 'cauldronbornecockpit.png',
armmav = IMAGE_DIR .. 'diashicockpit.png',
armwar = IMAGE_DIR .. 'fireflycockpit.png'
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local activeImage = nil -- used to free textures
local vsx, vsy = widgetHandler:GetViewSizes()
function widget:ViewResize(viewSizeX, viewSizeY)
vsx = viewSizeX
vsy = viewSizeY
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
if (Game.modName ~= modName) then
widgetHandler:RemoveWidget()
return
end
-- convert names to numeric ids
for unitName, image in pairs(cockpits) do
local ud = UnitDefNames[unitName]
if (ud) then
cockpits[ud.id] = image
print(ud.id, image)
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- speed-ups
--
local glTexture = gl.Texture
local glTexRect = gl.TexRect
local glFreeTexture = gl.FreeTexture
local GetUnitDefID = Spring.GetUnitDefID
local GetMyPlayerID = Spring.GetMyPlayerID
local GetPlayerControlledUnit = Spring.GetPlayerControlledUnit
function widget:DrawScreen()
local unitID = GetPlayerControlledUnit(GetMyPlayerID())
if (unitID) then
local udid = GetUnitDefID(unitID)
local image = udid and cockpits[udid] or nil
if (image) then
if (activeImage and (activeImage ~= image)) then
glFreeTexture(activeImage)
end
activeImage = image
glTexture(image)
glTexRect(0, 0, vsx, vsy)
glTexture(false)
end
elseif (activeImage) then
glFreeTexture(activeImage)
activeImage = nil
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------