Game Development Community

button onhover toggling

by Louis Marchant · in Torque 3D Beginner · 10/31/2012 (4:35 pm) · 6 replies

ok, so my project is advancing steadily, but i have another quick GUI related question.

i have some buttons that have an attached _h file, for when you hover over them. that all works fine
and when you click on said button(after certain checks, irrelevant here) it changes a dynamic variable and the bitmap. think like buying unlocks.
what i want is for only the next one to react on hover.

for example if i havent unlocked any only the first wants to change the bitmap onhover
if i onlocked first, only the second wants to onhover, and so on.

now i have the following code for the first button, and similar for the next 4.

function buttonP1::onClick(%this)
{
	if(%this.useStates == true && %this.isUnlocked == 0)
	{
		echo("unlocked");
		buttonP2.useStates = true;
		%this.isUnlocked = 1;
	}
	else
	{
		echo("can't unlock");
	}
}

and this kind of works, with the only drawback that once you unlock the first, the seconds onhover bitmap is a plainwhite instead of the one it should be(same one as first button) and same issue fro buttons 3-5.

#1
10/31/2012 (4:36 pm)
just thought, might be related to the moment it loads graphics, so i might jsut need to force set the bitmap to what it's already set to, in the 'if'. trying it now...
#2
10/31/2012 (4:39 pm)
yea adding
buttonP2.bitmap = buttonP2.bitmap;
inside the if true part, forcing bitmap reload, fixed it.

sorry for wasting everyone time
#3
10/31/2012 (7:54 pm)
"buttonP2.bitmap = buttonP2.bitmap; " !!!!!!!!!!

i was wondering on what circumstances we need to do force reload of bitmap.
it cannot be the real issue.may be there is something wrong happening on source level.
can u show full code that is working now?
#4
11/01/2012 (8:50 am)
i can, but it's jsut the top code, with that line in it (well ive added the rest on my unrelated checks since then too):

function buttonP1::onClick(%this)
{
	if(%this.useStates == true && %this.isUnlocked == 0)
	{
		if(numericalMoneyHUD.text > 4000)
		{
			echo("unlocked");
			buttonP2.useStates = true;
			%this.isUnlocked = 1;
			buttonP2.bitmap = buttonP2.bitmap;
			%this.bitmap = "art/gui/buildmenu/powercolour";
			textpower.text = 40;
		}
		else
		{
			echo("too poor");
		}
	}
	else
	{
		echo("can't unlock now");
	}
}

can only assume it's because useStates is set to false when the interface innitially loads, and that it must put all the gui bitmaps in memory at this point. so since it's set not to use them, it doesnt bother loading the ..._h bitmap. hence you getting a blanks white when useStates is subsequently changed, but it finds no ..._h in memory, because it didnt bother loading it earlier. forcing the reload then puts them all in memory , fixing this. Only speculation, especially since if the ..._h isnt found it should jsut do nothing, not load blank.(would still ammount to same needing force reload tho)
#5
11/01/2012 (11:06 am)
You are aware of the inactive state for buttons? Set a button's active property to false and it will use the supplied inactive graphic. Then in script when you want to make it usable just set the active property to true and the button will function as normal with the other available (normal, hover, pressed) states.
#6
11/01/2012 (11:40 am)
yes that was my initial train of thought, only it kept changing the active state to values i didnt want, ive sicne realised it was only an issue from setting it in the F10 editor, and if i do it at code point it works fine - that said it's fully working and compelted with my makeshift method now, so will see if i can be bothered to recode it all or not, most of the code would still be there anyway. only real difference is useing useStates instead of active, and adding the force bitmap load. everything else there is required for other things.