echo, drawing stuff and other noobness

echo, drawing stuff and other noobness

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

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

echo, drawing stuff and other noobness

Post by knorke »

So I made a totally leet widget that warns you if your commander is under attack. :shock:

Looks like this:

Code: Select all

function widget:UnitDamaged (unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
  local ud = UnitDefs[unitDefID]
    if (ud.isCommander) then
      current_time = widgetHandler:GetHourTimer()
	if (current_time > last_attack+2) then
		Echo( "OH FUCK! Commander under attack!" )
		end
	last_attack = current_time
	end
end
I use echo( ) but I am not sure if these are public chat messages or are they like the "unit can not reach location" and are only seen by 'the' player.
In wiki it says "prints to the ingame chat and infolog.txt" but I also read somewhere "prints to console"

Also, will this also warn about your allys commander? (your enemies??) so that I have to check the attacked commanders team?
Or is this unneeded because UnitDamaged only gets called for "your" units anyway?

---------

So I want to draw some basic stuff, like lines or rectangles. For example make the screenborders flash red when the commander is attacked.
Whats the easiest way to do so? OpenGL scares me atm with renderlists and matrix and stuff. I was told to use something like chiliUI - this seems very overkill? What would you recommend?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: echo, drawing stuff and other noobness

Post by FLOZi »

Echo is seen by everyone, use

Code: Select all

SendMessageToTeam ( number teamID, string "message" ) -> nil
It will warn you about your ally's, not sure about enemies though I think it probably will (indeed it depends on how UnitDamaged is called in widgetland).
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: echo, drawing stuff and other noobness

Post by Regret »

You could try Red UI Framework.

Or learn how to draw basic stuff with just spring lua gl., should take about a day or two.

f.e. rectangle:

Code: Select all

function widget:DrawScreen()
	gl.ResetState() --cleanup
	gl.ResetMatrices()

	--draw a white rectangle
	gl.Color(1,1,1,1)
	gl.Rect(px,py,px+sx,py+sy) --px,py - position,  sx,sy - size
	--end

	gl.ResetState() --cleanup
	gl.ResetMatrices()
end
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: echo, drawing stuff and other noobness

Post by very_bad_soldier »

FLOZi wrote:Echo is seen by everyone, use
It does?? I could be totally wrong but I was quite sure that Spring.Echo is just a local output for the player that is running the script.
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: echo, drawing stuff and other noobness

Post by Regret »

very_bad_soldier wrote:I could be totally wrong but I was quite sure that Spring.Echo is just a local output for the player that is running the script.
You are right, echo is only for the widget owner.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: echo, drawing stuff and other noobness

Post by FLOZi »

hmm, I suppose that makes sense after a fashion. I'm too used to working with gadgets, I've done very little LuaUI work.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: echo, drawing stuff and other noobness

Post by knorke »

ok, thanks everybody for clearing that up.

also thanks regret for the example.
So basicly I just call

Code: Select all

gl.ResetState()
 gl.ResetMatrices()
then I draw my stuff and then call these 2 functions again and the buffer gets refreshed to the screen or something? No need to intialize anything?
Ok, thats seems simple enough :)

And when first loading the widget I would probally use gl.GetViewSizes to get the screensize so I do not draw outside the screen and can scale stuff.
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: echo, drawing stuff and other noobness

Post by Regret »

knorke wrote:ok, thanks everybody for clearing that up.

also thanks regret for the example.
So basicly I just call

Code: Select all

gl.ResetState()
 gl.ResetMatrices()
then I draw my stuff and then call these 2 functions again and the buffer gets refreshed to the screen or something? No need to intialize anything?
Ok, thats seems simple enough :)

And when first loading the widget I would probally use gl.GetViewSizes to get the screensize so I do not draw outside the screen and can scale stuff.
Those 2 lines are for cleaning up any previously set gl states by other widgets and then at end for cleaning up your set states like gl.color.

gl works like a state machine.

screen size:

Code: Select all

local vsx,vsy = widgetHandler:GetViewSizes()
if (vsx == 1) then --hax for windowed mode
	vsx,vsy = Spring.GetWindowGeometry()
end
function widget:ViewResize(viewSizeX, viewSizeY)
	vsx,vsy = widgetHandler:GetViewSizes()
end
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: echo, drawing stuff and other noobness

Post by jK »

knorke wrote:So basicly I just call

Code: Select all

gl.ResetState()
 gl.ResetMatrices()
then I draw my stuff and then call these 2 functions again and the buffer gets refreshed to the screen or something? No need to intialize anything?
Ok, thats seems simple enough :)
NEVER EVER USE gl.ResetState!!!
It does NOT do what you expect! Don't use it as long as you really, really, - and yeah, before you forget - really know what you are doing.
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: echo, drawing stuff and other noobness

Post by Regret »

jK wrote:NEVER EVER USE gl.ResetState!!!
It does NOT do what you expect! Don't use it as long as you really, really, - and yeah, before you forget - really know what you are doing.
http://springrts.com/wiki/Lua_OpenGL_Api#Basics
That's pretty clear what it does, and the values it sets are not interfering with anything.

Every widget SHOULD in fact use resetstate to clean up after itself. And before drawing just in case someone forgot to do so.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: echo, drawing stuff and other noobness

Post by jK »

Regret wrote:
jK wrote:NEVER EVER USE gl.ResetState!!!
It does NOT do what you expect! Don't use it as long as you really, really, - and yeah, before you forget - really know what you are doing.
http://springrts.com/wiki/Lua_OpenGL_Api#Basics
That's pretty clear what it does, and the values it sets are not interfering with anything.

Every widget SHOULD in fact use resetstate to clean up after itself. And before drawing just in case someone forgot to do so.
wiki wrote:gl.ResetState DON'T USE IT AS LONG AS YOU KNOW WHAT YOU ARE DOING! each callin has different default states, but this function resets all states no matter what to the states below!
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: echo, drawing stuff and other noobness

Post by knorke »

well, I use non of this variables and seeing as the comm_ends warning widget does work without ResetState, I think I do not need it either.

thanks, found the screensize thing used in another widget already.

as far as i can tell, the UnitDamaged() does not get called for enemy units.

its a bit strange, one can only draw to the screen in this DrawScreen function, but I think ive figured it out now.
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: echo, drawing stuff and other noobness

Post by Regret »

jK wrote:
wiki wrote:gl.ResetState DON'T USE IT AS LONG AS YOU KNOW WHAT YOU ARE DOING! each callin has different default states, but this function resets all states no matter what to the states below!

Code: Select all

 ShadeModel = GL_SMOOTH
 Scissor    = false
 Texture    = false
 Lighting    = false,
 ColorMask  = true, true, true, true
 DepthMask  = false
 DepthTest  = false  (GL_LEQUAL)
 Culling    = false  (GL_BACK)
 LogicOp    = false  (GL_INVERT)
 AlphaTest  = false  (GL_GREATER, 0.5f)
 Blending   = true (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Post Reply

Return to “Lua Scripts”