New LUA GUI feature

New LUA GUI feature

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

New LUA GUI feature

Post by trepan »

A new LUA gui feature soon to be committed...

Here's the code that generated the ugliness:

Code: Select all

function SetColor(color)
  -- a hack to set the color state without doing it per-vertex
  Spring.DrawShape(GL_TRIANGLES, "", { { vertex = {}, color = color } })
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  DrawMapItems
--
   
function DrawMapItems(windowSizeX, windowSizeY)

  alpha  = 0.25

  red    = { 1, 0, 0, alpha }
  blue   = { 0, 0, 1, alpha }
  green  = { 0, 1, 0, alpha }
  yellow = { 1, 1, 0, alpha }
  
  s = 200
  h = 200
  xc = (Game.mapX * 512) / 2
  zc = (Game.mapY * 512) / 2
  
  v0 = { vertex = { xc - s,  h,          zc - s } }
  v1 = { vertex = { xc + s,  h,          zc - s } }
  v2 = { vertex = { xc + s,  h,          zc + s } }
  v3 = { vertex = { xc - s,  h,          zc + s } }
  v4 = { vertex = { xc - s,  h + s * 2,  zc - s } }
  v5 = { vertex = { xc + s,  h + s * 2,  zc - s } }
  v6 = { vertex = { xc + s,  h + s * 2,  zc + s } }
  v7 = { vertex = { xc - s,  h + s * 2,  zc + s } }

  SetColor(green)
  Spring.DrawShape(GL_QUADS, "", {
    v3, v2, v1, v0,  v4, v5, v6, v7,  v0, v1, v5, v4,
    v1, v2, v6, v5,  v2, v3, v7, v6,  v3, v0, v4, v7 
  })

  SetColor(red)
  Spring.DrawShape(GL_LINE_LOOP, "", { v0, v1, v2, v3})
  Spring.DrawShape(GL_LINE_LOOP, "", { v4, v5, v6, v7})
  Spring.DrawShape(GL_LINES, "", { v0, v4, v1, v5, v2, v6, v3, v7})
end
   
   
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  DrawScreenItems
--
  
function DrawScreenItems(windowSizeX, windowSizeY)

  alpha  = 0.5

  red    = { 1, 0, 0, alpha }
  blue   = { 0, 0, 1, alpha }
  green  = { 0, 1, 0, alpha }
  yellow = { 1, 1, 0, alpha }

  v0 = { vertex = { 100, 200 }, texcoord = { 0, 0 }, color = red }
  v1 = { vertex = { 200, 200 }, texcoord = { 3, 0 }, color = blue }
  v2 = { vertex = { 200, 300 }, texcoord = { 3, 3 }, color = green }
  v3 = { vertex = { 100, 300 }, texcoord = { 0, 3 }, color = yellow }
  Spring.DrawShape(GL_QUADS, "bitmaps/arm1.gif", { v0, v1, v2, v3 }) 

  red[4] = 1
  green[4] = 1
  midx = windowSizeX / 2
  white  = { } -- 1,1,1,1 is the default
  black  = { 0, 0, 0 }

  v4 = { vertex = { midx, 100 },               color = black }
  v5 = { vertex = { midx, windowSizeY - 100 }, color = white }
  Spring.DrawShape(GL_LINES, "", { v4, v5 })

  Spring.DrawText( "Screen Space Quad", 86, 300, 12, "o")
  Spring.DrawText( YellowStr .. "Test Message", midx, 350, 25, "oc")
  Spring.DrawText( GreenStr  .. "Test Message", midx, 300, 20, "r") 
  Spring.DrawText( BlueStr   .. "Test Message", midx, 250, 15, "o") 
  Spring.DrawText( RedStr    .. "Test Message", midx, 200, 10, "")  

  print("window = " .. windowSizeX .. "x" .. windowSizeY)
end

Image
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

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

Post by trepan »

You also get access to the mouse clicks before
the normal GUI, so scroll bars can be made, etc...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

That cube of green ractangles, it would be immensely useful if AIs could draw those.

It would also be incredibly useful if the AIs could expose to the lua interface an AI config button for which they could then provide a lua config file for an AI along with access to a get and set function for passing and retrieving data from the AI. It would make groupAI' so much more useful.
bamb
Posts: 350
Joined: 04 Apr 2006, 14:20

Post by bamb »

Tweak-on-the-run AI:s! Yay!
User avatar
diggz2k
Posts: 208
Joined: 04 Mar 2005, 06:34

Post by diggz2k »

I'm still not clear on what this is, is it just a way to see lua scripts ingame?
User avatar
Snipawolf
Posts: 4357
Joined: 12 Dec 2005, 01:49

Post by Snipawolf »

Custom Options, and plenty of other goodies, messages on screen if something happens..

A bunch of stuff that reminds me of GMod 9...
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post by LOrDo »

Wtf? This guy just came outta no where, signed up for dev, and done the best thing to the GUI since well...the GUI?
Nice job, watch your back for NewGUI monsters. I reccomend shotguns.
User avatar
mehere101
Posts: 293
Joined: 15 Mar 2006, 02:38

Post by mehere101 »

Spam kroggies. there's no other defense strong enough
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

I've added a few more functions to make the LUA interface
a little more useful. Note the addition of the list create/run
calls. These will let you render complex shapes with very
little speed penalty due to the LUA interface.

The additional features:

Code: Select all

Spring.PlaySoundFile("sound.wav")

Spring.DrawTranslate(x, y, z)
Spring.DrawScale(x, y, z)
Spring.DrawRotate(r, x, y, z)

Spring.DrawPushMatrix()
Spring.DrawPopMatrix()

list = Spring.DrawListCreate(func, arg1, arg2, ...)
Spring.DrawListRun(list)

Spring.DrawState({
  reset = true,
  lighting = true,
  depthmask = true,
  depthtest = true,
  blending = {},
  blending = {GL_SRC_ALPHA, GL_ONE},
  alphatest = {},
  alphatest = {GL_GREATER, 0.1),
  logicop = {},
  logicop = {GL_INVERT},
  culling = {},
  culling = {GL_BACK}
})
P.S. The lighting state is useless until material parameters can be setup.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

trepan, I think you're going to have a huge problem with user friendliness. It seems the only major attempts at suign the existing lua interface that have yielded any results are ones that you did, there's not much in the way of documentation, and tbh the above code looks very intimidating and befuddling, I would have no idea how to use half of it without a very good example.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Post by LOrDo »

mehere101 wrote:Spam kroggies. there's no other defense strong enough
Wrong thread? :?
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

He was talking about how to beat the NewGUI monsters.
User avatar
mehere101
Posts: 293
Joined: 15 Mar 2006, 02:38

Post by mehere101 »

+1 ILMTitan
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

trepan: More important than the code is teh documentation as to how to use it. AF is right ( GASP! ;) ) in that right now, these interface enhancements (this and everything you made before) are a series of buried crypts the likes of which only you have dared explore.
User avatar
NOiZE
Balanced Annihilation Developer
Posts: 3984
Joined: 28 Apr 2005, 19:29

Post by NOiZE »

maybe someone can document it.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I tried to implement a unit limits hack before yeha added it and got befuddled by howto use it, and in the end not being able todo != in an if statement just pissed me off and I gave up (turns out it was ~= ?!?!?!?!? wtf).

And please add these to the AI interface, I can see AIdevs would make use of these much sooner than modders, and get much more out of it in the longrun.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

~ is an alternative to !; Verilog uses it, for example...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

!= not equal to 5 !=6
== exactly equal to 5 == 5
~= approximately equal to 5.4 ~= 5.41

That is how I and my maths teachers understand it.

Another variant I've come across is 5 >< 6 or 5 <> 6.

~= is just silly though, maybe someone can patch the lua interpreter to accept != too.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

In terms of Mathematical notation either ¬A or ~A are used for 'NOT', !A is a purely programming concept afaik.
Post Reply

Return to “Lua Scripts”