Game Development Community

Scrolling button bar GUIscrollctrl

by Flybynight Studios · in Torque Game Engine · 11/19/2007 (7:19 pm) · 3 replies

So basically I am trying to achieve using the engine's scroll control to scroll a number of buttons to the left or the right.

Lets say I have 50 buttons but can only view 5 of them at a time. I want to be able to scroll them left or right using a gui control and then have the mouseover and button click work..

I've recently invested some time getting the guiMLscroll control work exactly the way I want it but I am missing something with the standard scroll control. Anyone got any example code for how to make a window with a scroll control and put buttons inside of it? Kind of like an inventory bag with tons of buttons in it. It's the same concept.

Thank you all.

#1
11/19/2007 (9:44 pm)
I did resolve this (or at least Im well on the way) shortly after posting.. (That is the norm for me.. I only post after spending several hours beating my head against the wall but in this case walking away for a day and coming back to the issue gave me a new perspective and the solution was very simple.)

I will post an example of the code once I get it cleaned up slightly since righ tnow it's all outta whack for testing purposes.
#2
11/20/2007 (2:05 am)
Ok, wow I got really deep into this stuff heh. I forgot how much of a pain in the a... err.. I mean how.. "challenging" working in the GUIs was :). My script is all very proprietary and quite a mess but suffice to say this is all very simple and easy to accomplish if you know your GUI controls and are good at nested loops and scripting.

I built a little card game as a quick and dirty example for anyone following in my footsteps:

while ( %counter1 <= $mystats::totalcards ) {
		error("Adding card "@%counter1@" to my deck with a value of "@%value1@" at position "@%pos);
		$mydeck.add(%counter1, %value1);
		%cardimg = "~/ui/card"@%value1@"";
		%buttonname = "T1B"@%value1@"";
		error("This buttonname is "@%buttonname);
		%newbutton[%value1] = new GuiBitmapButtonCtrl(%buttonname) {
			profile = "GuiButtonProfile";
			horizSizing = "right";
			vertSizing = "top";
			position = %pos;
			extent = "125 165";
			minExtent = "8 8";
			visible = "1";
			helpTag = "0";
    		         command = "toggleskillinfo();";
    		         buttonType = "PushButton";
    		         bitmap = ""@%cardimg@"";
		};
		deckscroll.add(%newbutton[%value1]);
		%counter1++;
		%value1++;
		%x= %x+150;
		%pos = %x SPC %y;
		%deckpos = %x SPC 185;
		deckscroll.extent=%deckpos;		
	}

PS: BTW if you search hard on these forums you will find there was once a GUIBuilder resource half done. I couldnt find the resource but I did find some snippets of code from it that helped me understand the dynamic button creation. Just giving a props out where it's due :)
#3
11/20/2007 (6:49 am)
Fun. Thanks for that!