Lua FPS huds

Lua FPS huds

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Lua FPS huds

Post by trepan »

WhiteHawk requested this, so I'll post the code here.

Image

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  
     
     
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post by LOrDo »

Zomgz. Ive wanted this since the day I discovered Com Shooter. NICE!

EDIT: Waitaminute... thats a flag I see in that screen?
Could it...
possibly...
just mabye...

CAPTURE THE FLAG IN NEXT SPRING?
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

If you want to do the lua coding for capture the flag, sure.

The flag is just a test widget for a multi-textured frag/vert shader.
It moves dynamically (with the game wind), and will look pretty
good once I get the normals and specular lighting done. Using a
vertex texture will be the cool way to do it, but I'm not planning on
adding that level of configurability to the lua textures yet.
User avatar
Zenka
Posts: 1235
Joined: 05 Oct 2005, 15:29

Post by Zenka »

<borg persuasion>You will comply. give us vertex shaders.</borg>
the screen is just stunning. Thjat's all I'd say.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

I'd already added vertex shaders (that's how the flag in the image is done).
http://spring.clan-sy.com/phpbb/viewtop ... 872#190872 introduced
vertex shader texture access (after looking at it, I decided it was too simple not
to add).
WhiteHawk
Posts: 10
Joined: 13 Jul 2006, 14:36

Post by WhiteHawk »

well, what can I say?

Thats perfect.

Fantastic Job trepan. A sure credits mention for you.

Where can I get the SVN build?

WhiteHawk.
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

that hud should be on by default for every mod. guess modders could set an alternate or turrn it off seperately, but it looks so pro!
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Post by Warlord Zsinj »

Haha, and to think 1944 spent all that time trying to model a realistically fluttering flag...

Hmm, I wonder if they could implement some sort of lua-based gaia capture the flag system, with a flag system similar to CoH... hmmm...
User avatar
Nemo
Spring 1944 Developer
Posts: 1376
Joined: 30 Jan 2005, 19:44

Post by Nemo »

If by all that time you mean dividing it into four sections and giving it five minutes worth of animation work, then yes :P

Sweet stuff trepan, next release is going to be le awesome.
User avatar
Snipawolf
Posts: 4357
Joined: 12 Dec 2005, 01:49

Post by Snipawolf »

lol @ 1944


Now then, this looks pretty interesting, that one looks good, but I can't imagine driving a tank with that... However it looks like it would totally work with a different color scheme for an airplane or mech.
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

is there some way of making the model you are driving not vanish, so you could see it around you?
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

Dude
Dude
Dude

Natural Selection in Spring.
As a default mode for all mods

shoudl be possible.

YES.


Edit: OMG, this + better aircraft code = mad TIE FIGHTERZ skillz :O
User avatar
Zenka
Posts: 1235
Joined: 05 Oct 2005, 15:29

Post by Zenka »

Dragon45 wrote:Edit: OMG, this + better aircraft code = mad TIE FIGHTERZ skillz :O
well turning an originally land based RTS engine into an SW emulator game... err.... I do like tie fighter though :)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Dragon45 wrote:Dude
Dude
Dude

Natural Selection in Spring.
As a default mode for all mods

shoudl be possible.

YES.
Warp effect for aliens! Haha that'd be great.
NightfallGemini
Posts: 59
Joined: 07 May 2005, 23:48

Post by NightfallGemini »

1v0ry_k1ng wrote:is there some way of making the model you are driving not vanish, so you could see it around you?
Like, for example, to see that Maverick's guns?

{ EDITED by trepan }

If anyone knows if this can be done, PLEASE tell us!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

You can draw a model of the parts you want visible while in FPS mode, kinda like the weapon in a real FPS (which uses a different model in first person than third person, BTW).
User avatar
Fanger
Expand & Exterminate Developer
Posts: 1509
Joined: 22 Nov 2005, 22:58

Post by Fanger »

MECHWARRIOR!!!!!!!!!!!!!!!!!!!!!!!!!
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

Fanger wrote:MECHWARRIOR!!!!!!!!!!!!!!!!!!!!!!!!!
He called it, I echo.
User avatar
gamer17
Posts: 235
Joined: 21 Feb 2007, 23:51

Post by gamer17 »

Where can I get a SVN build from?
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

Post Reply

Return to “Lua Scripts”