Flashing/Fading text colors in lua text drawing?

Flashing/Fading text colors in lua text drawing?

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

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

https://github.com/EvolutionRTS/Evoluti ... isplay.lua


I as planning to make the numbers flash when storage is nearly full. Now because I can do all this in gameframe all I need is a simple if statement checking the values vs one another. So that part is simple, but I would like to make the number fade slowly from red to yellow to red again while it is in the nearly full range. I could just make it flash, but I'd rather not cause seizures if I can help it.

I've seen this done in chili widgets before. Does anyone know how to do it in "\255\255\255\255" style?
User avatar
Silentwings
Moderator
Posts: 3686
Joined: 25 Oct 2008, 00:23

Re: Flashing/Fading text colors in lua text drawing?

Post by Silentwings »

Change the third number as slowly as you like from \255\255\1\1 through to \255\255\255\1 and then back again.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Re: Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

How did this topic get in help and bugs? Can someone move it back to game development?
User avatar
Silentwings
Moderator
Posts: 3686
Joined: 25 Oct 2008, 00:23

Re: Flashing/Fading text colors in lua text drawing?

Post by Silentwings »

It is moved to the generic forum in which people ask for help because it is a trivial request for help.

(The answer to which can be found on the wiki - https://springrts.com/wiki/Lua_Fonts#Inlined_ColorCodes).
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Re: Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

I wasn't asking for the basics of how to use inline color codes -_- I was asking about fading text from one color to another and then back again which is a much larger issue.
Last edited by Forboding Angel on 27 Aug 2016, 11:32, edited 1 time in total.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Re: Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

After some trial and error, I have an increment counter that counts from 0 to 255 then back down. There are prettier ways to write it I'm sure.

So this is what I have:

Code: Select all

local increment = 0

function widget:GameFrame(n)
	local myTeamID = Spring.GetMyTeamID()
    local ec, es, ep, ei, ee = Spring.GetTeamResources(myTeamID, "energy")

--Normal Energy Display
--    str = yellow .. "Energy:" .. orange .. " ± " .. tostring(math.round(ei - ee)) .. green .. " +" .. tostring(math.round(ei)) .. white .. "/" .. red .. "-" .. tostring(math.round(ep)) .. white .. " (" .. tostring(math.round(ec)) .. "/" .. tostring(math.round(es)) .. ")"

--Custom Evo Energy display
	local warningColor = white -- If the word "energy" displays as white, something below isn't working correctly
	if ec <= 75 then
		warning = true
	else
		warning = false
	end
	
	if warning == true then
		if increment == 0 then
			countUp = true
		end
	
		if increment < 255 and countUp == true then
			increment = increment + 1
		elseif increment > 0 then
			countUp = false
			increment = increment - 1
		end
		
		warningColor = "\255\255\\" .. increment .. "\0"

	else
		warningColor = yellow
	end

	str = warningColor .. "Energy:" .. orange .. " ± " .. tostring(math.round(ei - ee)) .. green .. " +" .. tostring(math.round(ei)) .. white .. "/" .. red .. "-" .. tostring(math.round(ep)) .. white .. " (" .. yellow .. tostring(math.round(ec)).. white .. "/" .. tostring(math.round(es)) .. ")"
end
This doesn't work, obviously, because warningColor isn't a complete string at that point due to the last \ being escaped in order to use increment. So this of course results in a counter counting from 0 to 255 and back to 0.

How can I get warningColor to work properly? Are there other ways of doing colors that I don't know about? Explicit examples would be welcome so that learning can be done. :-)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Re: Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

Code man helped me sort it out, the correct line to use is:

warningColor = "\255\255" .. string.char (increment) .. "\0"
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6235
Joined: 29 Apr 2005, 01:14

Re: Flashing/Fading text colors in lua text drawing?

Post by FLOZi »

Silentwings wrote:It is moved to the generic forum in which people ask for help because it is a trivial request for help.

(The answer to which can be found on the wiki - https://springrts.com/wiki/Lua_Fonts#Inlined_ColorCodes).
Frankly, nonsense. It is a question about how to do something in lua.

We have a forum for that.
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Flashing/Fading text colors in lua text drawing?

Post by 8611z »

FLOZi wrote:
Silentwings wrote:It is moved to the generic forum in which people ask for help because it is a trivial request for help.

(The answer to which can be found on the wiki - https://springrts.com/wiki/Lua_Fonts#Inlined_ColorCodes).
Frankly, nonsense. It is a question about how to do something in lua.

We have a forum for that.
The forum for threads without own approach to problem is called "Bounty Offers" and a thread about this task is at viewtopic.php?f=86&t=34107
I hope code_man got paid.

User was warned for this post, felony 2. (Silentwings)

Please avoid repeated unconstructive comments.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14650
Joined: 17 Nov 2005, 02:43

Re: Flashing/Fading text colors in lua text drawing?

Post by Forboding Angel »

The problem with not reading every post in a thread is that sometimes you come out looking awfully silly.

Code_Man helped me with some particularly challenging aspects of the control_victory gadget, and helped me with the basis of the resource widgets, all of which is am extremely grateful to him for. I have actually tried to pay him on multiple occasions, but because of various reasons it seems that I am not able to get money to him. I have even offered to wire it to him, which would cost me more than the amount sent in the first place, but I offered to do it because it was the right thing to do.

As it stands, I either owe him some money, or, my time when/if ever he asks.

But frankly, none of this is any of your business, but I don't really care who knows *shrug*

Fwiw, this is the original widget that he give to me (this is after I had already edited the string quite a bit, but tomato, tomato):
https://github.com/EvolutionRTS/Evoluti ... isplay.lua
*** April 12, 2016 at 11:44:42 AM PDT
[1:30:23 PM] <[Evo]Forboding_Angel> can you pastebin them real quick?
[1:31:59 PM] <Code_Man> http://pastebin.com/xYNrKjaB
He hasn't touched the widgets since then. Sadly, he didn't set the paste to last forever.

And this is the latest iteration:
https://github.com/EvolutionRTS/Evoluti ... isplay.lua

As I said, none of this is your business, but... *shrug*
Post Reply

Return to “Lua Scripts”

cron