Menu: Committed example Menu-VGUI... it's not ready for use but a good widget showcase nonetheless.

This commit is contained in:
Marco Cawthorne 2020-09-24 22:31:30 +02:00
parent 70868ddd84
commit dbd5b5d566
17 changed files with 1243 additions and 0 deletions

5
src/menu-vgui/Makefile Normal file
View file

@ -0,0 +1,5 @@
CC=fteqcc
all:
mkdir -p ../../platform/data.pk3dir
$(CC) progs.src

48
src/menu-vgui/background.cpp Executable file
View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef GAME_TW
#define BACKGROUND_IMG "textures/gfx/background"
#elif GAME_CS
#define BACKGROUND_IMG "textures/gfx/background"
#else
#define BACKGROUND_IMG "gfx/conback"
#endif
var int g_iBackgroundLoaded = FALSE;
void Background_Init ( void )
{
precache_pic( BACKGROUND_IMG );
if ( iscachedpic( BACKGROUND_IMG ) ) {
g_iBackgroundLoaded = TRUE;
}
}
void Background_Draw ( vector vecSize )
{
if ( clientstate() == 2 ) {
drawfill( [ 0, 0 ], vecSize, [ 0, 0, 0 ], 0.5f );
} else {
if ( g_iBackgroundLoaded == TRUE ) {
drawpic( [ 0, 0 ], BACKGROUND_IMG, vecSize, [ 1, 1, 1 ], 1.0f );
} else {
drawfill( [ 0, 0 ], vecSize, [ 0, 0, 0 ], 1.0f );
drawfill( [ 0, 0 ], vecSize, UI_MAINCOLOR, 0.5f );
}
}
}

31
src/menu-vgui/defs.h Executable file
View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iMenuActive;
vector video_res;
var float frametime;
var float lasttime;
#define UI_DEVELOPER
#define KEY_UNKNOWN -1
#define KEY_GAME 0
#define KEY_MENU 2
#define KEY_MENU_GRABBED 3
#define TARGET_MENU 1
#define TARGET_CLIENT 2

125
src/menu-vgui/desktop.cpp Executable file
View file

@ -0,0 +1,125 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
void Desktop_Init ( void )
{
static CUIMenuButton btnNewgame;
static CUIMenuButton btnLoadgame;
static CUIMenuButton btnFindserver;
static CUIMenuButton btnCreateserver;
static CUIMenuButton btnOptions;
static CUIMenuButton btnQuit;
static CUIMenuButton btnMPlayer;
static CUIMenuButton btnMViewer;
static CUIMenuButton btnResume;
static CUIMenuButton btnDisconnect;
static void Desktop_ResumeGame ( void ) {
m_toggle( 0 );
}
static void Desktop_DisconnectGame ( void ) {
localcmd( "disconnect\n" );
}
g_uiDesktop = spawn( CUIWidget );
g_uiDesktop.FlagAdd( 1 );
btnNewgame = spawn( CUIMenuButton );
btnNewgame.SetTitle( "New Game" );
btnNewgame.SetSize( '128 24' );
btnNewgame.SetPos( '32 64' );
btnNewgame.SetFunc( UI_NewGame_Show );
btnNewgame.FlagRemove( MBUTTON_SHOWSP | MBUTTON_SHOWMP );
btnNewgame.SetIcon( "textures/ui/icons/desktop" );
btnDisconnect = spawn( CUIMenuButton );
btnDisconnect.SetTitle( "Disconnect" );
btnDisconnect.SetSize( '128 24' );
btnDisconnect.SetPos( '32 64' );
btnDisconnect.SetFunc( Desktop_DisconnectGame );
btnDisconnect.FlagRemove( MBUTTON_SHOWOFFLINE );
btnDisconnect.SetIcon( "textures/ui/icons/disconnect" );
btnLoadgame = spawn( CUIMenuButton );
btnLoadgame.SetTitle( "Load Game" );
btnLoadgame.SetSize( '128 24' );
btnLoadgame.SetPos( '32 96' );
btnLoadgame.SetIcon( "textures/ui/icons/folder" );
btnFindserver = spawn( CUIMenuButton );
btnFindserver.SetTitle( "Find Servers" );
btnFindserver.SetSize( '128 24' );
btnFindserver.SetPos( '32 128' );
btnFindserver.SetFunc( UI_FindServers_Show );
btnFindserver.SetIcon( "textures/ui/icons/servers" );
btnCreateserver = spawn( CUIMenuButton );
btnCreateserver.SetTitle( "Create Server" );
btnCreateserver.SetSize( '128 24' );
btnCreateserver.SetPos( '32 160' );
btnCreateserver.SetFunc( UI_CreateServer_Show );
btnCreateserver.SetIcon( "textures/ui/icons/server-new" );
btnOptions = spawn( CUIMenuButton );
btnOptions.SetTitle( "Options" );
btnOptions.SetSize( '128 24' );
btnOptions.SetPos( '32 192' );
btnOptions.SetIcon( "textures/ui/icons/gear" );
btnQuit = spawn( CUIMenuButton );
btnQuit.SetTitle( "Quit Game" );
btnQuit.SetSize( '128 24' );
btnQuit.SetPos( '32 224' );
btnQuit.SetFunc( UI_QuitGame_Show );
btnQuit.SetIcon( "textures/ui/icons/cancel" );
btnMPlayer = spawn( CUIMenuButton );
btnMPlayer.SetTitle( "Music Player" );
btnMPlayer.SetSize( '128 24' );
btnMPlayer.SetPos( '32 288' );
btnMPlayer.SetFunc( UI_MusicPlayer_Show );
btnMPlayer.SetIcon( "textures/ui/icons/cd" );
btnMViewer = spawn( CUIMenuButton );
btnMViewer.SetTitle( "Model Viewer" );
btnMViewer.SetSize( '128 24' );
btnMViewer.SetPos( '32 320' );
btnMViewer.SetFunc( UI_ModelViewer_Show );
btnMViewer.SetIcon( "textures/ui/icons/hdd" );
btnResume = spawn( CUIMenuButton );
btnResume.SetTitle( "Resume Game" );
btnResume.SetSize( '128 24' );
btnResume.SetPos( '32 384' );
btnResume.SetFunc( Desktop_ResumeGame );
btnResume.FlagRemove( MBUTTON_SHOWOFFLINE );
g_uiDesktop.Add( btnNewgame );
g_uiDesktop.Add( btnLoadgame );
g_uiDesktop.Add( btnFindserver );
g_uiDesktop.Add( btnCreateserver );
g_uiDesktop.Add( btnOptions );
g_uiDesktop.Add( btnQuit );
g_uiDesktop.Add( btnMPlayer );
g_uiDesktop.Add( btnMViewer );
g_uiDesktop.Add( btnResume );
g_uiDesktop.Add( btnDisconnect );
}
void Desktop_Draw ( void )
{
g_uiDesktop.Draw();
}

30
src/menu-vgui/loading.cpp Executable file
View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
void Loading_Draw ( vector vecSize )
{
drawpic( [ 0, 0 ], "textures/gfx/background", vecSize, [ 1, 1, 1 ], 1.0f );
vector vecLoadingSize = [ 256, 96 ];
vector vecLoadingPos = ( video_res / 2 ) - ( vecLoadingSize / 2 );
drawfill( vecLoadingPos, vecLoadingSize, UI_MAINCOLOR, UI_MAINALPHA );
drawfill( vecLoadingPos, [vecLoadingSize[0], 1], [1,1,1], 0.5f );
drawfill( vecLoadingPos + [ 0, vecLoadingSize[1] - 1], [vecLoadingSize[0], 1], [0,0,0], 0.5f );
drawfill( vecLoadingPos + [ 0, 1], [1, vecLoadingSize[1] - 2], [1,1,1], 0.5f );
drawfill( vecLoadingPos + [ vecLoadingSize[0] - 1, 1], [1, vecLoadingSize[1] - 2], [0,0,0], 0.5f );
Font_DrawText( vecLoadingPos + [ 8, 8 ], "Loading...", g_fntDefault );
}

120
src/menu-vgui/main.cpp Executable file
View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
var int autocvar_r_autoscale = TRUE;
void
Menu_AutoScale(void)
{
if (autocvar_r_autoscale) {
/* override for vid_conautoscales */
vector psize = getproperty(VF_SCREENPSIZE);
if (psize[1] >= (480 * 4)) {
cvar_set("vid_conautoscale", "4");
} else if (psize[1] >= (480 * 3)) {
cvar_set("vid_conautoscale", "3");
} else if (psize[1] >= (480 * 2)) {
cvar_set("vid_conautoscale", "2");
} else {
cvar_set("vid_conautoscale", "1");
}
}
}
void m_init ( void )
{
UISystem_Init();
Background_Init();
Desktop_Init();
registercommand( "menu_quit" );
registercommand( "menu_music" );
Menu_AutoScale();
}
void
Menu_RendererRestarted(void)
{
localcmd("menu_restart\n");
Menu_AutoScale();
}
void m_shutdown ( void )
{
}
void m_draw ( vector vecScreensize )
{
if (vecScreensize != video_res) {
Menu_AutoScale();
}
if ( !g_iMenuActive ) {
return;
}
frametime = time - lasttime;
lasttime = time;
video_res = vecScreensize;
Background_Draw( vecScreensize );
Desktop_Draw();
}
float Menu_InputEvent ( float flEvType, float flScanX, float flCharY, float flDevID )
{
g_uiDesktop.Input( flEvType, flScanX, flCharY, flDevID );
return (float)g_iMenuActive;
}
void m_toggle ( float flWantMode )
{
dprint( sprintf( "[MENU] m_toggle: %d\n", flWantMode ) );
if ( flWantMode == 0 ) {
g_iMenuActive = FALSE;
setkeydest( KEY_GAME );
setmousetarget( TARGET_CLIENT );
setcursormode( FALSE );
} else {
g_iMenuActive = TRUE;
setkeydest( KEY_MENU );
setmousetarget( TARGET_MENU );
setcursormode( TRUE, "gfx/cursor" );
}
}
float m_consolecommand ( string strCommand )
{
dprint( sprintf( "[MENU] m_consolecommand: %s\n", strCommand ) );
tokenize( strCommand );
switch ( argv( 0 ) ) {
case "menu_quit":
UI_QuitGame_Show();
break;
case "menu_music":
UI_MusicPlayer_Show();
break;
case "showconsole":
UI_Console_Show();
break;
default:
return FALSE;
}
return TRUE;
}

17
src/menu-vgui/main.h Executable file
View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
CUIWidget g_uiDesktop;

24
src/menu-vgui/progs.src Executable file
View file

@ -0,0 +1,24 @@
#pragma target fte
#pragma progs_dat "../../platform/data.pk3dir/menu.dat"
#define MENU
#includelist
../shared/fteextensions.qc
defs.h
../vgui/include.src
background.cpp
loading.cpp
main.h
ui_console.cpp
ui_newgame.cpp
ui_quitgame.cpp
ui_createserver.cpp
ui_findservers.cpp
ui_musicplayer.cpp
ui_modelviewer.cpp
desktop.cpp
main.cpp
#endlist

43
src/menu-vgui/ui_console.cpp Executable file
View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iConsoleInitialized;
void UI_Console_Show ( void )
{
static CUIWindow winConsole;
static CUIButton btnSend;
static void Console_Send ( void ) {
}
if ( !g_iConsoleInitialized ) {
g_iConsoleInitialized = TRUE;
winConsole = spawn( CUIWindow );
winConsole.SetTitle( "Console" );
winConsole.SetSize( '320 240' );
btnSend = spawn( CUIButton );
btnSend.SetTitle( "Send" );
btnSend.SetSize( '48 24' );
btnSend.SetPos( winConsole.GetSize() - '64 32' );
btnSend.SetFunc( Console_Send );
winConsole.Add( btnSend );
g_uiDesktop.Add( winConsole );
}
winConsole.Show();
}

139
src/menu-vgui/ui_createserver.cpp Executable file
View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iCreateServerInitialized;
void UI_CreateServer_Show ( void )
{
static CUIScrollbar scrlMaps;
static CUIWindow winCreate;
static CUIButton btnCancel;
static CUIButton btnStart;
static CUIList lsbMaps;
static CUILabel lblHostname;
static CUITextBox txbHostname;
static CUILabel lblMaxplayers;
static CUITextBox txbMaxplayers;
static CUILabel lblPassword;
static CUITextBox txbPassword;
static void CreateServer_Start ( void ) {
int iEndMap = lsbMaps.GetSelected();
if ( lsbMaps.GetSelected() == 0 ) {
iEndMap = (int)( rint( random( 1, lsbMaps.GetItemCount() ) ) );
}
localcmd( sprintf( "hostname %s\n", txbHostname.GetText() ) );
localcmd( sprintf( "maxplayers %s\n", txbMaxplayers.GetText() ) );
localcmd( sprintf( "sv_password %s\n", txbPassword.GetText() ) );
localcmd( sprintf( "map %s\n", lsbMaps.GetItem( iEndMap ) ) );
winCreate.Hide();
}
static void CreateServer_Cancel ( void ) {
winCreate.Hide();
}
static void CreateServer_ListUpdate ( void ) {
lsbMaps.SetOffset( scrlMaps.GetValue(), FALSE );
}
static void CreateServer_Scrolled ( void ) {
scrlMaps.SetValue( lsbMaps.GetOffset(), FALSE );
}
if ( !g_iCreateServerInitialized ) {
g_iCreateServerInitialized = TRUE;
winCreate = spawn( CUIWindow );
winCreate.SetTitle( "Create Server" );
winCreate.SetSize( '338 385' );
winCreate.SetIcon( "textures/ui/icons/server-new" );
searchhandle shMaps = search_begin( "maps/*.bsp", TRUE, TRUE );
lsbMaps = spawn( CUIList );
lsbMaps.SetSize( '128 306' );
lsbMaps.SetPos( '175 32 ' );
lsbMaps.SetItemCount( search_getsize( shMaps ) );
lsbMaps.CallOnScroll( CreateServer_Scrolled );
lsbMaps.SetSelected( 0 );
lsbMaps.AddItem( "< Random Map >" );
for ( int i = 0; i < search_getsize( shMaps ); i++ ) {
string strMap = search_getfilename( shMaps, i );
lsbMaps.AddItem( substring( strMap, 5, strlen( strMap ) - 9 ) );
//lsbMaps.AddItem( search_getfilename( shMaps, i ) );
}
scrlMaps = spawn( CUIScrollbar );
scrlMaps.SetLength( 306 );
scrlMaps.SetPos( '303 32' );
scrlMaps.SetMin( 0 );
scrlMaps.SetStep( 1 );
scrlMaps.SetMax( lsbMaps.GetMaxVisibleItems() );
scrlMaps.CallOnChange( CreateServer_ListUpdate );
btnStart = spawn( CUIButton );
btnStart.SetTitle( "Start" );
btnStart.SetSize( '64 24' );
btnStart.SetPos( winCreate.GetSize() - '152 32' );
btnStart.SetFunc( CreateServer_Start );
btnCancel = spawn( CUIButton );
btnCancel.SetTitle( "Cancel" );
btnCancel.SetSize( '64 24' );
btnCancel.SetPos( winCreate.GetSize() - '80 32' );
btnCancel.SetFunc( CreateServer_Cancel );
lblHostname = spawn( CUILabel );
lblHostname.SetPos( '20 32' );
lblHostname.SetTitle( "Server name" );
txbHostname = spawn( CUITextBox );
txbHostname.SetPos( [ 20, 50 ] );
txbHostname.SetSize( [ 124, 24 ] );
txbHostname.SetText( cvar_string( "hostname" ) );
lblMaxplayers = spawn( CUILabel );
lblMaxplayers.SetPos( '20 84' );
lblMaxplayers.SetTitle( "Max players" );
txbMaxplayers = spawn( CUITextBox );
txbMaxplayers.SetPos( [ 20, 102 ] );
txbMaxplayers.SetSize( [ 124, 24 ] );
txbMaxplayers.SetText( cvar_string( "sv_playerslots" ) );
lblPassword = spawn( CUILabel );
lblPassword.SetPos( '20 136' );
lblPassword.SetTitle( "Password" );
txbPassword = spawn( CUITextBox );
txbPassword.SetPos( [ 20, 154 ] );
txbPassword.SetSize( [ 124, 24 ] );
txbPassword.SetText( cvar_string( "sv_password" ) );
g_uiDesktop.Add( winCreate );
winCreate.Add( lsbMaps );
winCreate.Add( scrlMaps );
winCreate.Add( btnStart );
winCreate.Add( btnCancel );
winCreate.Add( lblHostname );
winCreate.Add( txbHostname );
winCreate.Add( lblMaxplayers );
winCreate.Add( txbMaxplayers );
winCreate.Add( lblPassword );
winCreate.Add( txbPassword );
search_end( shMaps );
}
winCreate.Show();
winCreate.SetPos( ( video_res / 2 ) - ( winCreate.GetSize() / 2 ) );
}

35
src/menu-vgui/ui_fileopen.cpp Executable file
View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iFindServersInitialized;
void UI_FindServers_Show ( void )
{
static CUIWindow winFind;
if ( !g_iFindServersInitialized ) {
g_iFindServersInitialized = TRUE;
winFind = spawn( CUIWindow );
winFind.SetTitle( "File Open..." );
winFind.SetSize( '256 400' );
winFind.SetIcon( "textures/ui/icons/server-new" );
g_uiDesktop.Add( winFind );
}
winFind.Show();
winFind.SetPos( ( g_vecResolution / 2 ) - ( winFind.GetSize() / 2 ) );
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iFindServersInitialized;
void UI_FindServers_Show ( void )
{
static CUIWindow winFind;
if ( !g_iFindServersInitialized ) {
g_iFindServersInitialized = TRUE;
winFind = spawn( CUIWindow );
winFind.SetTitle( "Find Servers" );
winFind.SetSize( '600 400' );
winFind.SetIcon( "textures/ui/icons/servers" );
g_uiDesktop.Add( winFind );
}
winFind.Show();
winFind.SetPos( ( video_res / 2 ) - ( winFind.GetSize() / 2 ) );
}

338
src/menu-vgui/ui_modelviewer.cpp Executable file
View file

@ -0,0 +1,338 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iModelViewerInitialized;
// menuqc doesn't have access to makevectors... screw you, guys
vector v_forward;
vector v_up;
vector v_right;
void AngleVectors ( vector angles )
{
float angle;
float sr, sp, sy, cr, cp, cy;
angle = angles[1] * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
angle = angles[0] * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = angles[2] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);
v_forward[0] = cp*cy;
v_forward[1] = cp*sy;
v_forward[2] = -sp;
v_right[0] = (-1*sr*sp*cy+-1*cr*-sy);
v_right[1] = (-1*sr*sp*sy+-1*cr*cy);
v_right[2] = -1*sr*cp;
v_up[0] = (cr*sp*cy+-sr*-sy);
v_up[1] = (cr*sp*sy+-sr*cy);
v_up[2] = cr*cp;
}
void UI_ModelViewer_Show ( void )
{
static entity eModel;
static vector vecDistance = [ 90, 0, 0 ];
static CUIWindow winViewer;
static CUI3DView viewModel;
static CUIPic picBackground;
static CUIButton btnTabRenderer;
static CUIButton btnTabSequence;
static CUIButton btnTabBody;
static CUIButton btnTabTexture;
static CUIList lstModels;
static CUIScrollbar scrlModels;
static CUIButton btnLoadModel;
// Renderer
static CUICheckbox chkBackground;
static CUICheckbox chkGround;
static CUICheckbox chkMirror;
static CUIButton btnFirstperson;
// Sequences
static CUILabel lblSeqFrame;
static CUIButton btnSeqNext;
static CUIButton btnSeqPrev;
static void UI_ModelViewer_Firstperson( void ) {
vecDistance = [ 0, 0, 0 ];
viewModel.Set3DAngles( [0,0,0] );
viewModel.Set3DPos( [0,0,0] );
}
static void UI_ModelViewer_SetFrame( int iFrame ) {
eModel.frame = (float)iFrame;
lblSeqFrame.SetTitle( sprintf( "Frame: %i", iFrame ) );
eModel.frame1time = 0;
}
static void UI_ModelViewer_SetFrameP( void ) {
UI_ModelViewer_SetFrame( ++eModel.frame );
}
static void UI_ModelViewer_SetFrameM( void ) {
if ( eModel.frame ) {
UI_ModelViewer_SetFrame( --eModel.frame );
}
}
static void UI_ModelViewer_SetModel( string strModel ) {
setmodel( eModel, strModel );
winViewer.SetTitle( sprintf( "Model Viewer (%s)", strModel ) );
UI_ModelViewer_SetFrame( 0 );
}
static void UI_ModelViewer_Draw ( void ) {
static int initialized = FALSE;
if ( !initialized ) {
initialized = TRUE;
eModel = spawn();
UI_ModelViewer_SetModel( "models/player.mdl" );
AngleVectors( viewModel.Get3DAngles() );
viewModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
}
addentity( eModel );
eModel.frame1time += frametime;
if ( chkGround.GetValue() == TRUE ) {
R_BeginPolygon( "", 0, FALSE );
R_PolygonVertex( [ 64, -64, 0 ], '1 0', [1,1,1], 1.0f ); // Top Right
R_PolygonVertex( [ -64, -64, 0 ], '0 0', [1,1,1], 1.0f ); // Top left
R_PolygonVertex( [ -64, 64, 0 ], '0 1', [1,1,1], 1.0f ); // Bottom left
R_PolygonVertex( [ 64, 64, 0 ], '1 1', [1,1,1], 1.0f ); // Bottom right
R_EndPolygon();
}
if ( chkBackground.GetValue() == TRUE ) {
picBackground.FlagAdd( IMAGE_VISIBLE );
} else {
picBackground.FlagRemove( IMAGE_VISIBLE );
}
}
static void UI_ModelViewer_Input ( float flEVType, float flKey, float flChar, float flDevID ) {
static int iMouseDrag = FALSE;
static int iShiftDrag = FALSE;
static vector vecDragOfs;
vector vecDifference;
int iMouseOver = Util_MouseAbove( getmousepos(), viewModel.m_parent.GetPos() + viewModel.GetPos(), viewModel.GetSize() );
if ( flEVType == IE_KEYDOWN ) {
if ( flKey == K_MOUSE1 && iMouseOver == TRUE ) {
iMouseDrag = TRUE;
vecDragOfs = getmousepos();
} else if ( flKey == K_MWHEELUP && iMouseOver == TRUE ) {
vecDistance[0] = bound( 0, --vecDistance[0], 512 );
AngleVectors( viewModel.Get3DAngles() );
viewModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
} else if ( flKey == K_MWHEELDOWN && iMouseOver == TRUE ) {
vecDistance[0] = bound( 0, ++vecDistance[0], 512 );
AngleVectors( viewModel.Get3DAngles() );
viewModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
} else if ( flKey == K_LSHIFT && iMouseOver == TRUE ) {
iShiftDrag = TRUE;
}
} else if ( flEVType == IE_KEYUP ) {
if ( flKey == K_MOUSE1 ) {
iMouseDrag = FALSE;
} else if ( flKey == K_LSHIFT ) {
iShiftDrag = FALSE;
}
}
if ( iMouseDrag == TRUE && iShiftDrag == FALSE ) {
if ( flEVType == IE_MOUSEABS ) {
vecDifference = [ flChar, flKey ] - [ vecDragOfs[1], vecDragOfs[0] ];
viewModel.Set3DAngles( viewModel.Get3DAngles() + vecDifference );
AngleVectors( viewModel.Get3DAngles() );
viewModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
vecDragOfs = getmousepos();
}
} else if ( iMouseDrag == TRUE && iShiftDrag == TRUE ) {
if ( flEVType == IE_MOUSEABS ) {
vecDifference = [ flChar, flKey ] - [ vecDragOfs[1], vecDragOfs[0] ];
vecDistance[1] -= vecDifference[1];
vecDistance[2] += vecDifference[0];
viewModel.Set3DPos( v_forward * -vecDistance[0] + v_right * vecDistance[1] + v_up * vecDistance[2] );
vecDragOfs = getmousepos();
}
}
}
static void UI_ModelViewer_Resize ( void ) {
// Resize the background and viewer
vector vWinSize = winViewer.GetSize();
picBackground.SetSize( [vWinSize[0] - 12 - 192, vWinSize[1] - 128 ] );
viewModel.SetSize( picBackground.GetSize() );
btnTabRenderer.SetPos( [ 6, vWinSize[1] - 92 ] );
btnTabSequence.SetPos( btnTabRenderer.GetPos() + [ btnTabRenderer.GetSizeWidth() + 1, 0 ] );
btnTabBody.SetPos( btnTabSequence.GetPos() + [ btnTabSequence.GetSizeWidth() + 1, 0 ] );
btnTabTexture.SetPos( btnTabBody.GetPos() + [ btnTabBody.GetSizeWidth() + 1, 0 ] );
chkBackground.SetPos( btnTabRenderer.GetPos() + [ 0, 30 ] );
chkGround.SetPos( btnTabRenderer.GetPos() + [ 0, 50 ] );
chkMirror.SetPos( btnTabRenderer.GetPos() + [ 0, 70 ] );
lstModels.SetPos( viewModel.GetPos() + [ viewModel.GetSize()[0], 0 ] );
lstModels.SetSize( [ 172, viewModel.GetSize()[1] ] );
scrlModels.SetPos( lstModels.GetPos() + [ 172, 0 ] );
scrlModels.SetLength( viewModel.GetSize()[1] );
scrlModels.SetMax( lstModels.GetMaxVisibleItems() );
btnLoadModel.SetPos( lstModels.GetPos() + [ 0, lstModels.GetSize()[1] + 1 ] );
btnFirstperson.SetPos( btnTabRenderer.GetPos() + [ 128, 30 ] );
lblSeqFrame.SetPos( btnTabRenderer.GetPos() + [ 0, 30 ] );
btnSeqPrev.SetPos( btnTabRenderer.GetPos() + [ 0, 50 ] );
btnSeqNext.SetPos( btnTabRenderer.GetPos() + [ 64, 50 ] );
}
static void UI_ModelViewer_HideAll( void ) {
chkBackground.FlagRemove( 1 );
chkGround.FlagRemove( 1 );
chkMirror.FlagRemove( 1 );
lblSeqFrame.FlagRemove( 1 );
btnSeqPrev.FlagRemove( 1 );
btnSeqNext.FlagRemove( 1 );
btnFirstperson.FlagRemove( 1 );
}
static void UI_ModelViewer_ShowRenderer( void ) {
UI_ModelViewer_HideAll();
chkBackground.FlagAdd( 1 );
chkGround.FlagAdd( 1 );
chkMirror.FlagAdd( 1 );
btnFirstperson.FlagAdd( 1 );
}
static void UI_ModelViewer_ShowSequence( void ) {
UI_ModelViewer_HideAll();
lblSeqFrame.FlagAdd( 1 );
btnSeqPrev.FlagAdd( 1 );
btnSeqNext.FlagAdd( 1 );
}
static void UI_ModelViewer_ShowBody( void ) {
UI_ModelViewer_HideAll();
}
static void UI_ModelViewer_ShowTexture( void ) {
UI_ModelViewer_HideAll();
}
static void ModelViewer_ScrollUpdate ( void ) {
scrlModels.SetValue( lstModels.GetOffset(), FALSE );
}
static void ModelViewer_ListUpdate ( void ) {
lstModels.SetOffset( scrlModels.GetValue(), FALSE );
}
if ( !g_iModelViewerInitialized ) {
g_iModelViewerInitialized = TRUE;
winViewer = spawn( CUIWindow );
winViewer.SetTitle( "Model Viewer" );
winViewer.SetSize( [ 550, 390 ] );
winViewer.SetMinSize( [ 430, 256 ] );
winViewer.SetMaxSize( [ 9999, 9999 ] );
winViewer.FlagAdd( WINDOW_CANRESIZE );
winViewer.SetPos( [ 172, 64 ] );
winViewer.SetIcon( "textures/ui/icons/hdd" );
winViewer.CallOnResize( UI_ModelViewer_Resize );
picBackground = spawn( CUIPic );
picBackground.SetImage( "textures/dev/black" );
picBackground.SetPos( [ 6, 32 ] );
viewModel = spawn( CUI3DView );
viewModel.SetDrawFunc( UI_ModelViewer_Draw );
viewModel.SetInputFunc( UI_ModelViewer_Input );
viewModel.SetPos( [ 6, 32 ] );
btnTabRenderer = spawn( CUIButton );
btnTabRenderer.SetTitle( "Renderer" );
btnTabRenderer.SetFunc( UI_ModelViewer_ShowRenderer );
btnTabSequence = spawn( CUIButton );
btnTabSequence.SetTitle( "Sequence" );
btnTabSequence.SetFunc( UI_ModelViewer_ShowSequence );
btnTabBody = spawn( CUIButton );
btnTabBody.SetTitle( "Body" );
btnTabBody.SetFunc( UI_ModelViewer_ShowBody );
btnTabTexture = spawn( CUIButton );
btnTabTexture.SetTitle( "Texture" );
btnTabTexture.SetFunc( UI_ModelViewer_ShowTexture );
chkBackground = spawn( CUICheckbox );
chkBackground.SetTitle( "Background" );
chkBackground.SetValue( TRUE );
chkGround = spawn( CUICheckbox );
chkGround.SetTitle( "Ground" );
chkMirror = spawn( CUICheckbox );
chkMirror.SetTitle( "Mirror on Ground" );
btnFirstperson = spawn( CUIButton );
btnFirstperson.SetTitle( "FPS-CAM" );
btnFirstperson.SetFunc( UI_ModelViewer_Firstperson );
lblSeqFrame = spawn( CUILabel );
lblSeqFrame.SetTitle( "Frame: 0" );
btnSeqNext = spawn( CUIButton );
btnSeqNext.SetTitle( ">>" );
btnSeqNext.SetFunc( UI_ModelViewer_SetFrameP );
btnSeqPrev = spawn( CUIButton );
btnSeqPrev.SetTitle( "<<" );
btnSeqPrev.SetFunc( UI_ModelViewer_SetFrameM );
searchhandle shModels = search_begin( "models/*.mdl", TRUE, TRUE );
lstModels = spawn( CUIList );
lstModels.SetItemCount( search_getsize( shModels ) );
lstModels.CallOnScroll( ModelViewer_ScrollUpdate );
for ( int i = 0; i < search_getsize( shModels ); i++ ) {
string strAdd = search_getfilename( shModels, i );
lstModels.AddItem( substring( strAdd , 6, strlen( strAdd ) - 6 ) );
}
search_end( shModels );
scrlModels = spawn( CUIScrollbar );
scrlModels.SetMin( 0 );
scrlModels.SetStep( 1 );
scrlModels.CallOnChange( ModelViewer_ListUpdate );
static void UI_ModelViewer_LoadSelected ( void ) {
UI_ModelViewer_SetModel( sprintf( "models/%s", lstModels.GetItem( lstModels.GetSelected() ) ) );
}
btnLoadModel = spawn( CUIButton );
btnLoadModel.SetTitle( "Load Selected" );
btnLoadModel.SetFunc( UI_ModelViewer_LoadSelected );
btnLoadModel.SetSize( '192 24' );
UI_ModelViewer_Resize();
UI_ModelViewer_ShowRenderer();
g_uiDesktop.Add( winViewer );
winViewer.Add( picBackground );
winViewer.Add( viewModel );
winViewer.Add( btnTabRenderer );
winViewer.Add( btnTabSequence );
winViewer.Add( btnTabBody );
winViewer.Add( btnTabTexture );
winViewer.Add( chkBackground );
winViewer.Add( chkGround );
winViewer.Add( chkMirror );
winViewer.Add( lstModels );
winViewer.Add( lblSeqFrame );
winViewer.Add( btnSeqNext );
winViewer.Add( btnSeqPrev );
winViewer.Add( btnFirstperson );
winViewer.Add( btnLoadModel );
winViewer.Add( scrlModels );
}
winViewer.Show();
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iMusicPlayerInitialized;
void UI_MusicPlayer_Show ( void )
{
static CUIWindow winMusicPlayer;
static CUIList lsbSongs;
static CUIScrollbar scrlSong;
static CUIButton btnPlay;
static CUIButton btnStop;
static void MusicPlayer_Play ( void ) {
string strSong;
strSong = lsbSongs.GetItem( lsbSongs.GetSelected() );
localcmd( sprintf( "music %s\n", substring( strSong, 11, strlen( strSong ) - 15 ) ) );
}
static void MusicPlayer_Stop ( void ) {
localcmd( "stopmusic\n" );
}
static void MusicPlayer_ScrollUpdate ( void ) {
scrlSong.SetValue( lsbSongs.GetOffset(), FALSE );
}
static void MusicPlayer_ListUpdate ( void ) {
lsbSongs.SetOffset( scrlSong.GetValue(), FALSE );
}
if ( !g_iMusicPlayerInitialized ) {
g_iMusicPlayerInitialized = TRUE;
winMusicPlayer = spawn( CUIWindow );
winMusicPlayer.SetTitle( "Music Player" );
winMusicPlayer.SetSize( '256 180' );
winMusicPlayer.SetIcon( "textures/ui/icons/cd" );
searchhandle shSongs = search_begin( "music/*.ogg", TRUE, TRUE );
lsbSongs = spawn( CUIList );
lsbSongs.SetSize( '192 96' );
lsbSongs.SetPos( '8 32 ' );
lsbSongs.SetItemCount( search_getsize( shSongs ) );
lsbSongs.CallOnScroll( MusicPlayer_ScrollUpdate );
for ( int i = 0; i < search_getsize( shSongs ); i++ ) {
lsbSongs.AddItem( search_getfilename( shSongs, i ) );
}
scrlSong = spawn( CUIScrollbar );
scrlSong.SetLength( 96 );
scrlSong.SetPos( '201 32' );
scrlSong.SetMin( 0 );
scrlSong.SetStep( 1 );
scrlSong.SetMax( lsbSongs.GetMaxVisibleItems() );
scrlSong.CallOnChange( MusicPlayer_ListUpdate );
btnPlay = spawn( CUIButton );
btnPlay.SetTitle( "Play" );
btnPlay.SetPos( '8 132' );
btnPlay.SetFunc( MusicPlayer_Play );
btnStop = spawn( CUIButton );
btnStop.SetTitle( "Stop" );
btnStop.SetPos( '96 132' );
btnStop.SetFunc( MusicPlayer_Stop );
g_uiDesktop.Add( winMusicPlayer );
winMusicPlayer.Add( lsbSongs );
winMusicPlayer.Add( scrlSong );
winMusicPlayer.Add( btnPlay );
winMusicPlayer.Add( btnStop );
search_end( shSongs );
}
winMusicPlayer.Show();
winMusicPlayer.SetPos( ( video_res / 2 ) - ( winMusicPlayer.GetSize() / 2 ) );
}

99
src/menu-vgui/ui_newgame.cpp Executable file
View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iNewGameInitialized;
void UI_NewGame_Show ( void )
{
static CUIWindow winNewGame;
static CUIButton btnPlay;
static CUIButton btnCancel;
static CUIRadio radTraining;
static CUIRadio radEasy;
static CUIRadio radMedium;
static CUIRadio radHard;
static void NewGame_Play ( void ) {
localcmd( "maxplayers 1\nmap measure\n" );
winNewGame.Hide();
}
static void NewGame_Cancel ( void ) {
winNewGame.Hide();
}
static void NewGame_Uncheck ( void ) {
radTraining.SetValue( FALSE );
radEasy.SetValue( FALSE );
radMedium.SetValue( FALSE );
radHard.SetValue( FALSE );
}
if ( !g_iNewGameInitialized ) {
g_iNewGameInitialized = TRUE;
winNewGame = spawn( CUIWindow );
winNewGame.SetTitle( "New Game" );
winNewGame.SetSize( '192 168' );
winNewGame.SetIcon( "textures/ui/icons/desktop" );
g_uiDesktop.Add( winNewGame );
btnPlay = spawn( CUIButton );
btnPlay.SetTitle( "Play" );
btnPlay.SetSize( '64 24' );
btnPlay.SetPos( winNewGame.GetSize() - '152 32' );
btnPlay.SetFunc( NewGame_Play );
btnCancel = spawn( CUIButton );
btnCancel.SetTitle( "Cancel" );
btnCancel.SetSize( '64 24' );
btnCancel.SetPos( winNewGame.GetSize() - '80 32' );
btnCancel.SetFunc( NewGame_Cancel );
radTraining = spawn( CUIRadio );
radTraining.SetTitle( "Training" );
radTraining.SetSize( '96 16' );
radTraining.SetPos( '32 32' );
radEasy = spawn( CUIRadio );
radEasy.SetTitle( "Easy" );
radEasy.SetSize( '96 16' );
radEasy.SetPos( '32 56' );
radMedium = spawn( CUIRadio );
radMedium.SetTitle( "Medium" );
radMedium.SetSize( '96 16' );
radMedium.SetPos( '32 80' );
radMedium.SetValue( TRUE );
radHard = spawn( CUIRadio );
radHard.SetTitle( "Hard" );
radHard.SetSize( '96 16' );
radHard.SetPos( '32 104' );
radTraining.SetFunc( NewGame_Uncheck );
radEasy.SetFunc( NewGame_Uncheck );
radMedium.SetFunc( NewGame_Uncheck );
radHard.SetFunc( NewGame_Uncheck );
winNewGame.Add( btnPlay );
winNewGame.Add( btnCancel );
winNewGame.Add( radTraining );
winNewGame.Add( radEasy );
winNewGame.Add( radMedium );
winNewGame.Add( radHard );
}
winNewGame.Show();
winNewGame.SetPos( ( video_res / 2 ) - ( winNewGame.GetSize() / 2 ) );
}

66
src/menu-vgui/ui_quitgame.cpp Executable file
View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
int g_iQuitGameInitialized;
void UI_QuitGame_Show ( void )
{
static CUIWindow winQuitGame;
static CUILabel lblSure;
static CUIButton btnQuit;
static CUIButton btnCancel;
static void QuitGame_Yes ( void ) {
winQuitGame.Hide();
localcmd( "quit\n" );
}
static void QuitGame_No ( void ) {
winQuitGame.Hide();
}
if ( !g_iQuitGameInitialized ) {
g_iQuitGameInitialized = TRUE;
winQuitGame = spawn( CUIWindow );
winQuitGame.SetTitle( "Quit Game" );
winQuitGame.SetSize( '256 128' );
winQuitGame.SetIcon( "textures/ui/icons/cancel" );
g_uiDesktop.Add( winQuitGame );
btnQuit = spawn( CUIButton );
btnQuit.SetTitle( "Quit" );
btnQuit.SetSize( '64 24' );
btnQuit.SetPos( winQuitGame.GetSize() - '152 32' );
btnCancel = spawn( CUIButton );
btnCancel.SetTitle( "Cancel" );
btnCancel.SetSize( '64 24' );
btnCancel.SetPos( winQuitGame.GetSize() - '80 32' );
lblSure = spawn( CUILabel );
lblSure.SetTitle( "Do you wish to stop playing now?" );
lblSure.SetSize( '256 16' );
lblSure.SetPos( '0 48' );
btnQuit.SetFunc( QuitGame_Yes );
btnCancel.SetFunc( QuitGame_No );
winQuitGame.Add( btnQuit );
winQuitGame.Add( btnCancel );
winQuitGame.Add( lblSure );
}
winQuitGame.Show();
winQuitGame.SetPos( ( video_res / 2 ) - ( winQuitGame.GetSize() / 2 ) );
}