Jump to content

Adding a White Tint to HUD objects


Recommended Posts

Back again with another question that I thought was going to be easy.

The title says it all, I'm trying to add a white tint to an object on the hud (more specifically, trying to make that object match the environment's ambient colors and lighting as if it was being simulated in the world along with the player)

I tried the usual  huditem:GetAnimState():SetAddColour(1,1,1,0.5)   only to find that, strangely enough, SetAddColour() doesn't seem to work on hud objects... It seems the UIAnim widget just doesn't do anything with it, despite handling SetMultColour() just fine.

I opened up every single game file in the widgets/screens folder and did an encompassing Ctrl-F for "AddColour" and "tint" and came up totally empty handed. anything related to tint was only referring to black tint. And it seems most "highlighted" versions of buttons have their own separate sprite, while their color values aren't changed.

 

Not really sure where to go from here. I hope I'm just missing something small. I'd be a little disappointed to find out that adding a white hue to a hud image just isn't possible

Link to comment
Share on other sites

@pickleplayer

If you can't get anything to work, then a workaround might be to make your own additive layer.

By creating an Image("images/global.xml", "square.tex") as a child to the UI element, you can then call SetTint(R,G,B,A) for ranges [0..1] on each, with the Alpha channel being less than 1.

Don't forget to set this child's SetClickable(false) else it may rob your root UI element's clicks.

Edited by CarlZalph
Link to comment
Share on other sites

1 hour ago, bizziboi said:

You could try SetAddColour?

That was the first thing I tried. I use SetAddColour all the time on non-hud objects all the time, but for some reason, it doesn't seem to work here.

I can use SetMultColour(1,1,1,0.5) to cut its opacity in half, and it works fine. But when I replace it with SetAddColour(1,1,1,0.5), nothing happens. I've tried it with all sorts of different values, and on other existing hud objects, but the results are always the same.

Link to comment
Share on other sites

4 hours ago, CarlZalph said:

@pickleplayer

If you can't get anything to work, then a workaround might be to make your own additive layer.

By creating an Image("images/global.xml", "square.tex") as a child to the UI element, you can then call SetTint(R,G,B,A) for ranges [0..1] on each, with the Alpha channel being less than 1.

Don't forget to set this child's SetClickable(false) else it may rob your root UI element's clicks.

Unfortunately, my hud object is not square shaped, and it takes all sorts of shapes and sizes and is also animated. Unless there is some sort of layer masking function, I wont be able to just use a white square over it. I also messed around with blendmodes to see if there was a way to only apply it to the hud layer, but no dice. Duplicating a white version of it to layer on top of it is not really an option either, given how many different forms it takes.

And since it's animated, it has to be a UIAnim, so i can't make it an Image and use SetTint() on it directly. I even messed around with transplanting code from the image widget into the uianim widget to see if I could replicate the SetTint() function for UIAnims, but didn't get anywhere.

Link to comment
Share on other sites

40 minutes ago, bizziboi said:

Hmmm, you could try UIAnim:TintTo? 

Alas, that requires the underlying widget to have a tinting function (self.inst.widget.SetTint)- used by Image widgets.

I did a test at the main menu with the UIAnim and I'd have to say that this might be a bug.

I can't seem to get an applied additive field to the AnimState to take effect.

Example code:

UIAnim = require "widgets/uianim"
cz_t = UIAnim()
cz_t:GetAnimState():SetBank("saving_indicator")
cz_t:GetAnimState():SetBuild("saving_indicator")
cz_t:GetAnimState():PlayAnimation("save_loop", true)
cz_t:SetVAnchor(ANCHOR_BOTTOM)
cz_t:SetHAnchor(ANCHOR_RIGHT)
cz_t:SetScaleMode(SCALEMODE_PROPORTIONAL)
cz_t:SetMaxPropUpscale(MAX_HUD_SCALE)
cz_t:SetPosition(-10, 40)
cz_t:GetAnimState():SetAddColour(1,0,0,1)
print(cz_t:GetAnimState():GetAddColour())

Prints out the proper set value, but the animating dibbly doesn't doobly out the desired colour application.

Edited by CarlZalph
Link to comment
Share on other sites

26 minutes ago, bizziboi said:

Drat, I didn't read your original post - apologies. So much for trying to be helpful.

 

Hmmm, you could try UIAnim:TintTo? 

Oh! I didn't notice there was a second uianim.lua in the components folder. sneaky.

Inserting a few temporary print fns into the game files, I followed it's path through the code and found that it gets to the first line of the function

function UIAnim:TintTo(start, dest, duration, whendone)
if not self.inst.widget.SetTint then
	return
end

and immediately ends there, because only Image widgets have SetTint(). the UIAnim widget does not.

I then made a new version of UIAnim widget that DOES have a SetTint() function, and this let it get past the first 3 lines of the TintTo function. It then proceeded to do nothing, once again.

Link to comment
Share on other sites

  • Developer
1 hour ago, pickleplayer said:

But when I replace it with SetAddColour(1,1,1,0.5), nothing happens.

Yeah it turns out that shader constant wasn't being used in the UI anim shader. I've added that in now, and will do some testing before it gets released.

Edit: looks like it's working. You'll just need to do something like this

self.bg_anim:GetAnimState():SetAddColour(1,1,1,0)

The alpha channel isn't currently used though. I left it out to be consistent with the in-game shaders.

Link to comment
Share on other sites

49 minutes ago, PeterA said:

Yeah it turns out that shader constant wasn't being used in the UI anim shader. I've added that in now, and will do some testing before it gets released.

Edit: looks like it's working. You'll just need to do something like this

self.bg_anim:GetAnimState():SetAddColour(1,1,1,0)

The alpha channel isn't currently used though. I left it out to be consistent with the in-game shaders.

Awesome! 

Thank you all very much for all your help! 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...