01-21-2011, 20:53
Quote:This code is still in its early stages, and I have many plans for this, I'm just releasing my code to get other opinions on it.
PHP Code:
onPlayerSpawned()
{
self endon( "disconnect" );
self thread dpadInit();
self thread menu_instructions();
for(;;)
{
self waittill( "spawned_player" );
wait 0.03;
}
}
initGlobalVars()
{
self.menu = 0;
self.open = 0;
self.max = 1;
}
dpadInit()
{
self endon("disconnect");
for(;;)
{
if(self.open == 1)
{
if(self ActionSlotOneButtonPressed()) self thread doUp();
if(self ActionSlotTwoButtonPressed()) self thread doDown();
if(self ActionSlotThreeButtonPressed()) self thread close_menu();
if(self JumpButtonPressed()) self thread runFunc();
}
if(self.open == 0 && self ActionSlotFourButtonPressed()) self thread open_menu();
wait 0.01;
}
}
menu_instructions()
{
instruct = CreateFontString( "objective", 1.7 );
instruct setPoint( "CENTER", "CENTER", 0, 220);
for(;;)
{
instruct setText( "^2RIGHT ^1Open Menu ^2LEFT ^1Exit Menu" );
}
}
initShader()
{
MenuShad = NewClientHudElem( self );
MenuShad.alignX = "center";
MenuShad.alignY = "center";
MenuShad.x = 320;
MenuShad.y = 0;
MenuShad.alpha = 0.9;
MenuShad setshader("black", 900, 800);
self thread destroyOnAny(MenuShad, "clear_menu" );
}
open_menu()
{
self.getMenu = ::getMenu;
self.getFunc = ::getFunc;
self.open = 1;
self thread initShader();
wait 0.01;
self thread drawMenu( self.scroll );
}
close_menu()
{
self.open = 0;
self notify( "refreshMenu" );
wait 0.01;
self notify( "clear_menu" );
wait 0.01;
}
doUp()
{
self.scroll--;
if(self.scroll < 0)
self.scroll = 0;
self notify( "refreshMenu" );
self thread drawMenu( self.scroll );
wait 0.001;
}
doDown()
{
self.scroll++;
if(self.scroll >= self.max)
self.scroll = self.max;
self notify( "refreshMenu" );
self thread drawMenu( self.scroll );
wait 0.001;
}
getMenu()
{
menu = [];
menu[0] = "Option 1";
menu[1] = "Option 2";
menu[2] = "Option 3";
menu[3] = "Option 4";
menu[4] = "Option 5";
menu[5] = "Option 6";
menu[6] = "Option 7";
menu[7] = "Option 8";
menu[8] = "Option 9";
menu[9] = "Option 10";
menu[10] = "Option 11";
menu[11] = "Option 12";
return menu;
}
getFunc()
{
func = [];
func[0] = ::testFunc;
func[1] = ::testFunc;
func[2] = ::testFunc;
func[3] = ::testFunc;
func[4] = ::testFunc;
func[5] = ::testFunc;
func[6] = ::testFunc;
func[7] = ::testFunc;
func[8] = ::testFunc;
func[9] = ::testFunc;
func[10] = ::testFunc;
func[11] = ::testFunc;
return func;
}
runFunc()
{
func = [[self.getFunc]]();
self thread [[ func[self.scroll] ]]();
wait 1.3;
}
testFunc()
{
self iPrintlnBold("^2TEST!!");
}
drawMenu( scroll )
{
menuDraw = CreateFontString( "objective", 2 );
menuDraw setPoint( "CENTER", "CENTER", 0, -180);
menuText = "";
menu = [[self.getMenu]]();
self.max = menu.size;
for( i = 0; i < menu.size; i++ ){
if(i == scroll)
{
menuText += "^5" + menu[i] + "^7\n";
}
else
{
menuText += menu[i] + "\n";
}
}
menuDraw setText( menuText );
self thread destroyOnAny( menuDraw, "refreshMenu" );
}
destroyOnAny( element, event ){
self waittill( event );
element destroy();
}
You need to convert the Xbox button names into the PC named ones.
Credits:
blackburn