PDA

View Full Version : Quickmenu without .menu :D



kung foo man
5th April 2013, 19:45
Hey all,

I've had a nice idea and maybe somebody wants to do it:

pseudocode:





while (isDefined(player))
{
if (player useButtonPressed())
{
createAllQuickMenuHuds();
mouse = getMousePositionFromPlayerAngles();
drawMousePointer(mouse["x"], mouse["y"]);
item = findSelectedItem(mouse);
doSomethingWithItem(item);
} else {
deleteAllQuickMenuHuds();
}

}


The idea is, that if the player is pressing USE, an overlay will appear. To "fake" a mouse-pointer, the player-angles are used. Which item is used, depends on where to release the mouse-pointer on.

That would work with every weapon, though it could be restricted to a "tool gun".

I would like such a system to buy Turrets e.g. in the BaseTDM.

If something is unclear, just ask :)

Jeplaa
5th April 2013, 20:05
Sounds really nice.
Menu like in Garry's Mod, popping-up while holding key ?

Good luck with that. :D

kung foo man
5th April 2013, 20:57
Yea, like gmod, but maybe a bit more dynamic (because of hud limit)

A tree-like structure, with options in options etc.


Its just an idea, maybe somebody wants to do it. :D

IzNoGoD
5th April 2013, 21:05
here, possible findSelectedItem(mouse, items) //added items as it is useful to have a list of items to check against...

findSelectedItem(mouse, items)
{
for(i = 0; i < items.size; i++)
{
if(mouse["x"] > items[i]["x"] && mouse["x"] <= items[i]["x"] + items[i]["xsize"])
{
if(mouse["y"] > items[i]["y"] && mouse["y"] <= items[i]["y"] + items[i]["ysize"])
{
return items[i];
}
}
}
return undefined;
}

serthy
6th April 2013, 18:49
lol its indeed funny
i doubt on using huds on my first thougth, but huds arent static like menu.vars!

you can have alot fun with them, i did a short test, and it works
nothing big, only to test, how the menu reacts to the mouse...
i added a treshold, maybe 10 is still too big
also there is nothing dynamic in it, there are just 4 menus
maybe, when you choose the menu, on one side the submenu will appear, on the other side a back-menu will appear
feel free to do it better xD
but good idea kung!

>>>WATCH ME<<< (http://www.xfire.com/video/5f0d2d)




init()
{
level.quickmenu[0] = &"^1Menu 1"; precacheString( level.quickmenu[0] );
level.quickmenu[1] = &"^2Menu 2"; precacheString( level.quickmenu[1] );
level.quickmenu[2] = &"^3Menu 3"; precacheString( level.quickmenu[2] );
level.quickmenu[3] = &"^4Menu 4"; precacheString( level.quickmenu[3] );

precacheShader( "white" );

level thread onPlayerConnecting();
}

onPlayerConnecting()
{
while( true )
{
level waittill( "connected" , player );

player thread onPlayerSpawned();
}
}

onPlayerSpawned()
{
self endon( "disconnect" );

while( true )
{
self waittill( "spawned_player" );

self thread quickMenu();
}
}

quickMenu()
{
self endon( "disconnect" );
self endon( "killed_player" );

if( isSubStr( self.name , "bot" ) )
return;

self thread cleanUp();

menuCount = 4;
radius = 100;
treshold = 10;

while( true )
{
while( !self useButtonPressed() )
{
wait( 0.5 );
}

oa = self getPlayerAngles();
na = oa;

self.active_menu = 0;

while( self useButtonPressed() )
{
if( !isDefined( self.quickhud_string ) )
{
self.quickhud_string = [];
self.quickhud_shader = [];

for( i = 0 ; i < menuCount ; i++ )
{
/*
Menu2
/ \
/ \
Menu1 Menu3
\ /
\ /
Menu0
*/

deg = 360 / menuCount * i;
x = sin( deg ) * radius;
y = cos( deg ) * radius;

self.quickhud_string[i] = newMenuStringHud( self , x , y , i );
self.quickhud_shader[i] = newMenuShaderHud( self , x , y );
}

self setActiveMenu( 0 );
}

na = self getPlayerAngles();

if( na != oa )
{
hDiff = angleDiff( na[1] , oa[1] );
vDiff = angleDiff( na[0] , oa[0] );

if( hDiff > treshold )
{
// self iPrintLn( "hDiff = " + hDiff + " side = right" );
self setActiveMenu( 1 );
}
else if( hDiff < 0 - treshold )
{
// self iPrintLn( "hDiff = " + hDiff + " side = left" );
self setActiveMenu( 3 );
}
else
{
// iPrintLn( "hDiff = " + hDiff );
}

if( vDiff > treshold )
{
// self iPrintLn( "vDiff = " + vDiff + " side = up" );
self setActiveMenu( 2 );
}
else if( vDiff < 0 - treshold )
{
// self iPrintLn( "vDiff = " + vDiff + " side = down" );
self setActiveMenu( 0 );
}
else
{
// iPrintLn( "vDiff = " + vDiff );
}
}

oa = na;

wait( 0.5 );
}

if( isDefined( self.quickhud_string ) )
{
for( i = 0 ; i < self.quickhud_string.size ; i++ )
{
self.quickhud_string[i] destroy();
self.quickhud_shader[i] destroy();
}

self.quickhud_string = undefined;
self.quickhud_shader = undefined;
}
}
}

setActiveMenu( menuID )
{
ID = self.active_menu;

self.quickhud_string[ID].color = ( 1 , 1 , 1 );
self.quickhud_string[ID].fontscale = 1.0;

self.quickhud_shader[ID].color = ( 1 , 1 , 1 );
self.quickhud_shader[ID].alpha = 0.2;

self.active_menu = menuID;

self.quickhud_string[menuID].color = ( 0 , 0 , 1 );
self.quickhud_string[menuID].fontscale = 1.5;

self.quickhud_shader[menuID].color = ( 0 , 0 , 1 );
self.quickhud_shader[menuID].alpha = 0.5;
}

newMenuStringHud( player , x , y , menuID )
{
hud = newClientHudElem( player );
hud.x = x;
hud.y = y;
hud.horzAlign = "center";
hud.vertAlign = "middle";
hud.alignX = "center";
hud.alignY = "middle";
hud setText( level.quickmenu[menuID] );

return hud;
}

newMenuShaderHud( player , x , y )
{
w = 50;
h = 20;

hud = newClientHudElem( player );
hud.x = x - ( w * 0.5 );
hud.y = y - ( h * 0.5 );
hud.horzAlign = "center";
hud.vertAlign = "middle";
hud.alpha = 0.2;
hud setShader( "white" , w , h );

return hud;
}

cleanUp()
{
self waittill( "killed_player" );

if( isDefined( self.quickhud_string ) )
{
for( i = 0 ; i < self.quickhud_string.size ; i++ )
{
self.quickhud_string[i] destroy();
self.quickhud_shader[i] destroy();
}

self.quickhud_string = undefined;
self.quickhud_shader = undefined;
}
}

angleDiff( firstAngle , secondAngle )
{
/*
diff = int( secondAngle - firstAngle );
while( diff < -180 ) diff += 360;
while( diff > 180 ) diff -= 360;
*/
diff = secondAngle - firstAngle;

if( diff > 180 || diff <= -180 )
{
diff = ( 360 / 2048 ) * ( int( diff * 2048 / 360 ) & 2047 );

if( diff >= 180 )
diff -= 360;
}

return diff;
}

kung foo man
6th April 2013, 21:14
Nice PoC (Proof of Concept) :)