2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
# include <base/math.h>
2008-09-29 11:34:49 +00:00
2011-03-23 12:06:35 +00:00
# include <engine/config.h>
2010-08-09 12:14:15 +00:00
# include <engine/demo.h>
2011-03-23 12:06:35 +00:00
# include <engine/friends.h>
2011-04-06 18:18:31 +00:00
# include <engine/graphics.h>
2010-05-29 07:25:38 +00:00
# include <engine/serverbrowser.h>
# include <engine/textrender.h>
# include <engine/shared/config.h>
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
# include <game/generated/protocol.h>
# include <game/generated/client_data.h>
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
# include <game/localization.h>
2011-03-22 21:41:27 +00:00
# include <game/client/animstate.h>
# include <game/client/gameclient.h>
# include <game/client/render.h>
# include <game/client/ui.h>
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
# include "menus.h"
# include "motd.h"
# include "voting.h"
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
void CMenus : : RenderGame ( CUIRect MainView )
2008-09-29 11:34:49 +00:00
{
2011-04-06 18:18:31 +00:00
CUIRect Button , ButtonBar ;
MainView . HSplitTop ( 45.0f , & ButtonBar , & MainView ) ;
RenderTools ( ) - > DrawUIRect ( & ButtonBar , ms_ColorTabbarActive , CUI : : CORNER_ALL , 10.0f ) ;
2008-09-29 11:34:49 +00:00
2011-03-22 21:41:27 +00:00
// button bar
ButtonBar . HSplitTop ( 10.0f , 0 , & ButtonBar ) ;
ButtonBar . HSplitTop ( 25.0f , & ButtonBar , 0 ) ;
ButtonBar . VMargin ( 10.0f , & ButtonBar ) ;
ButtonBar . VSplitRight ( 120.0f , & ButtonBar , & Button ) ;
2010-05-29 07:25:38 +00:00
static int s_DisconnectButton = 0 ;
if ( DoButton_Menu ( & s_DisconnectButton , Localize ( " Disconnect " ) , 0 , & Button ) )
Client ( ) - > Disconnect ( ) ;
2008-09-29 11:34:49 +00:00
2011-03-04 16:08:10 +00:00
if ( m_pClient - > m_Snap . m_pLocalInfo & & m_pClient - > m_Snap . m_pGameInfoObj )
2008-09-29 11:34:49 +00:00
{
2011-01-03 11:50:38 +00:00
if ( m_pClient - > m_Snap . m_pLocalInfo - > m_Team ! = TEAM_SPECTATORS )
2008-09-29 11:34:49 +00:00
{
2011-03-22 21:41:27 +00:00
ButtonBar . VSplitLeft ( 10.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( 120.0f , & Button , & ButtonBar ) ;
2010-05-29 07:25:38 +00:00
static int s_SpectateButton = 0 ;
if ( DoButton_Menu ( & s_SpectateButton , Localize ( " Spectate " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2011-01-03 11:50:38 +00:00
m_pClient - > SendSwitchTeam ( TEAM_SPECTATORS ) ;
2010-05-29 07:25:38 +00:00
SetActive ( false ) ;
2008-09-29 11:34:49 +00:00
}
}
2011-03-04 16:08:10 +00:00
if ( m_pClient - > m_Snap . m_pGameInfoObj - > m_GameFlags & GAMEFLAG_TEAMS )
2008-09-29 11:34:49 +00:00
{
2011-01-03 11:50:38 +00:00
if ( m_pClient - > m_Snap . m_pLocalInfo - > m_Team ! = TEAM_RED )
2008-09-29 11:34:49 +00:00
{
2011-03-22 21:41:27 +00:00
ButtonBar . VSplitLeft ( 10.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( 120.0f , & Button , & ButtonBar ) ;
2010-05-29 07:25:38 +00:00
static int s_SpectateButton = 0 ;
if ( DoButton_Menu ( & s_SpectateButton , Localize ( " Join red " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2011-01-03 11:50:38 +00:00
m_pClient - > SendSwitchTeam ( TEAM_RED ) ;
2010-05-29 07:25:38 +00:00
SetActive ( false ) ;
2008-09-29 11:34:49 +00:00
}
}
2011-01-03 11:50:38 +00:00
if ( m_pClient - > m_Snap . m_pLocalInfo - > m_Team ! = TEAM_BLUE )
2008-09-29 11:34:49 +00:00
{
2011-03-22 21:41:27 +00:00
ButtonBar . VSplitLeft ( 10.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( 120.0f , & Button , & ButtonBar ) ;
2010-05-29 07:25:38 +00:00
static int s_SpectateButton = 0 ;
if ( DoButton_Menu ( & s_SpectateButton , Localize ( " Join blue " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2011-01-03 11:50:38 +00:00
m_pClient - > SendSwitchTeam ( TEAM_BLUE ) ;
2010-05-29 07:25:38 +00:00
SetActive ( false ) ;
2008-09-29 11:34:49 +00:00
}
}
}
else
{
2010-05-29 07:25:38 +00:00
if ( m_pClient - > m_Snap . m_pLocalInfo - > m_Team ! = 0 )
2008-09-29 11:34:49 +00:00
{
2011-03-22 21:41:27 +00:00
ButtonBar . VSplitLeft ( 10.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( 120.0f , & Button , & ButtonBar ) ;
2010-05-29 07:25:38 +00:00
static int s_SpectateButton = 0 ;
if ( DoButton_Menu ( & s_SpectateButton , Localize ( " Join game " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
m_pClient - > SendSwitchTeam ( 0 ) ;
SetActive ( false ) ;
2008-09-29 11:34:49 +00:00
}
}
}
}
2010-08-09 12:14:15 +00:00
2011-03-22 21:41:27 +00:00
ButtonBar . VSplitLeft ( 100.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( 150.0f , & Button , & ButtonBar ) ;
2010-08-09 12:14:15 +00:00
static int s_DemoButton = 0 ;
bool Recording = DemoRecorder ( ) - > IsRecording ( ) ;
if ( DoButton_Menu ( & s_DemoButton , Localize ( Recording ? " Stop record " : " Record demo " ) , 0 , & Button ) ) // Localize("Stop record");Localize("Record demo");
{
if ( ! Recording )
2010-12-07 23:42:32 +00:00
Client ( ) - > DemoRecorder_Start ( " demo " , true ) ;
2010-08-09 12:14:15 +00:00
else
2010-12-07 23:02:24 +00:00
Client ( ) - > DemoRecorder_Stop ( ) ;
2010-08-09 12:14:15 +00:00
}
2011-04-06 18:18:31 +00:00
}
void CMenus : : RenderPlayers ( CUIRect MainView )
{
CUIRect Button , ButtonBar , Options , Player ;
RenderTools ( ) - > DrawUIRect ( & MainView , ms_ColorTabbarActive , CUI : : CORNER_ALL , 10.0f ) ;
2011-03-22 21:41:27 +00:00
// player options
MainView . Margin ( 10.0f , & Options ) ;
RenderTools ( ) - > DrawUIRect ( & Options , vec4 ( 1.0f , 1.0f , 1.0f , 0.25f ) , CUI : : CORNER_ALL , 10.0f ) ;
Options . Margin ( 10.0f , & Options ) ;
Options . HSplitTop ( 50.0f , & Button , & Options ) ;
UI ( ) - > DoLabelScaled ( & Button , Localize ( " Player options " ) , 34.0f , - 1 ) ;
2011-04-06 18:18:31 +00:00
// headline
Options . HSplitTop ( 34.0f , & ButtonBar , & Options ) ;
ButtonBar . VSplitRight ( 220.0f , & Player , & ButtonBar ) ;
UI ( ) - > DoLabelScaled ( & Player , Localize ( " Player " ) , 24.0f , - 1 ) ;
ButtonBar . HMargin ( 1.0f , & ButtonBar ) ;
float Width = ButtonBar . h * 2.0f ;
ButtonBar . VSplitLeft ( Width , & Button , & ButtonBar ) ;
Graphics ( ) - > TextureSet ( g_pData - > m_aImages [ IMAGE_GUIICONS ] . m_Id ) ;
Graphics ( ) - > QuadsBegin ( ) ;
RenderTools ( ) - > SelectSprite ( SPRITE_GUIICON_MUTE ) ;
IGraphics : : CQuadItem QuadItem ( Button . x , Button . y , Button . w , Button . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
ButtonBar . VSplitLeft ( 20.0f , 0 , & ButtonBar ) ;
ButtonBar . VSplitLeft ( Width , & Button , & ButtonBar ) ;
Graphics ( ) - > TextureSet ( g_pData - > m_aImages [ IMAGE_GUIICONS ] . m_Id ) ;
Graphics ( ) - > QuadsBegin ( ) ;
RenderTools ( ) - > SelectSprite ( SPRITE_GUIICON_FRIEND ) ;
QuadItem = IGraphics : : CQuadItem ( Button . x , Button . y , Button . w , Button . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
// options
static int s_aPlayerIDs [ MAX_CLIENTS ] [ 2 ] = { { 0 } } ;
for ( int i = 0 , Count = 0 ; i < MAX_CLIENTS ; + + i )
2011-03-22 21:41:27 +00:00
{
if ( ! m_pClient - > m_Snap . m_paPlayerInfos [ i ] | | i = = m_pClient - > m_Snap . m_LocalClientID )
continue ;
2011-03-28 19:10:37 +00:00
Options . HSplitTop ( 28.0f , & ButtonBar , & Options ) ;
2011-04-06 18:18:31 +00:00
if ( Count + + % 2 = = 0 )
RenderTools ( ) - > DrawUIRect ( & ButtonBar , vec4 ( 1.0f , 1.0f , 1.0f , 0.25f ) , CUI : : CORNER_ALL , 10.0f ) ;
2011-03-28 22:48:36 +00:00
ButtonBar . VSplitRight ( 220.0f , & Player , & ButtonBar ) ;
2011-03-22 21:41:27 +00:00
// player info
2011-03-28 19:10:37 +00:00
Player . VSplitLeft ( 28.0f , & Button , & Player ) ;
2011-03-22 21:41:27 +00:00
CTeeRenderInfo Info = m_pClient - > m_aClients [ i ] . m_RenderInfo ;
Info . m_Size = Button . h ;
RenderTools ( ) - > RenderTee ( CAnimState : : GetIdle ( ) , & Info , EMOTE_NORMAL , vec2 ( 1.0f , 0.0f ) , vec2 ( Button . x + Button . h / 2 , Button . y + Button . h / 2 ) ) ;
Player . HSplitTop ( 1.5f , 0 , & Player ) ;
Player . VSplitMid ( & Player , & Button ) ;
CTextCursor Cursor ;
TextRender ( ) - > SetCursor ( & Cursor , Player . x , Player . y , 14.0f , TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END ) ;
Cursor . m_LineWidth = Player . w ;
TextRender ( ) - > TextEx ( & Cursor , m_pClient - > m_aClients [ i ] . m_aName , - 1 ) ;
TextRender ( ) - > SetCursor ( & Cursor , Button . x , Button . y , 14.0f , TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END ) ;
Cursor . m_LineWidth = Button . w ;
TextRender ( ) - > TextEx ( & Cursor , m_pClient - > m_aClients [ i ] . m_aClan , - 1 ) ;
// ignore button
2011-04-06 18:18:31 +00:00
ButtonBar . HMargin ( 2.0f , & ButtonBar ) ;
ButtonBar . VSplitLeft ( Width , & Button , & ButtonBar ) ;
Button . VSplitLeft ( ( Width - Button . h ) / 4.0f , 0 , & Button ) ;
Button . VSplitLeft ( Button . h , & Button , 0 ) ;
if ( DoButton_Toggle ( & s_aPlayerIDs [ i ] [ 0 ] , m_pClient - > m_aClients [ i ] . m_ChatIgnore , & Button ) )
m_pClient - > m_aClients [ i ] . m_ChatIgnore ^ = 1 ;
2011-03-23 12:06:35 +00:00
// friend button
2011-04-06 18:18:31 +00:00
ButtonBar . VSplitLeft ( 20.0f , & Button , & ButtonBar ) ;
ButtonBar . VSplitLeft ( Width , & Button , & ButtonBar ) ;
Button . VSplitLeft ( ( Width - Button . h ) / 4.0f , 0 , & Button ) ;
Button . VSplitLeft ( Button . h , & Button , 0 ) ;
if ( DoButton_Toggle ( & s_aPlayerIDs [ i ] [ 1 ] , m_pClient - > m_aClients [ i ] . m_Friend , & Button ) )
if ( m_pClient - > m_aClients [ i ] . m_Friend )
m_pClient - > Friends ( ) - > RemoveFriend ( m_pClient - > m_aClients [ i ] . m_aName , m_pClient - > m_aClients [ i ] . m_aClan ) ;
else
m_pClient - > Friends ( ) - > AddFriend ( m_pClient - > m_aClients [ i ] . m_aName , m_pClient - > m_aClients [ i ] . m_aClan ) ;
2011-03-22 21:41:27 +00:00
}
2008-09-29 11:34:49 +00:00
/*
2009-10-27 14:38:53 +00:00
CUIRect bars ;
votearea . HSplitTop ( 10.0f , 0 , & votearea ) ;
votearea . HSplitTop ( 25.0f + 10.0f * 3 + 25.0f , & votearea , & bars ) ;
2008-09-29 11:34:49 +00:00
2009-10-27 14:38:53 +00:00
RenderTools ( ) - > DrawUIRect ( & votearea , color_tabbar_active , CUI : : CORNER_ALL , 10.0f ) ;
2008-09-29 11:34:49 +00:00
2009-10-27 14:38:53 +00:00
votearea . VMargin ( 20.0f , & votearea ) ;
votearea . HMargin ( 10.0f , & votearea ) ;
2008-09-29 11:34:49 +00:00
2009-10-27 14:38:53 +00:00
votearea . HSplitBottom ( 35.0f , & votearea , & bars ) ;
2008-09-29 11:34:49 +00:00
if ( gameclient . voting - > is_voting ( ) )
{
// do yes button
2009-10-27 14:38:53 +00:00
votearea . VSplitLeft ( 50.0f , & button , & votearea ) ;
2008-09-29 11:34:49 +00:00
static int yes_button = 0 ;
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > DoButton ( & yes_button , " Yes " , 0 , & button , ui_draw_menu_button , 0 ) )
2008-09-29 11:34:49 +00:00
gameclient . voting - > vote ( 1 ) ;
// do no button
2009-10-27 14:38:53 +00:00
votearea . VSplitLeft ( 5.0f , 0 , & votearea ) ;
votearea . VSplitLeft ( 50.0f , & button , & votearea ) ;
2008-09-29 11:34:49 +00:00
static int no_button = 0 ;
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > DoButton ( & no_button , " No " , 0 , & button , ui_draw_menu_button , 0 ) )
2008-09-29 11:34:49 +00:00
gameclient . voting - > vote ( - 1 ) ;
// do time left
2009-10-27 14:38:53 +00:00
votearea . VSplitRight ( 50.0f , & votearea , & button ) ;
2008-09-29 11:34:49 +00:00
char buf [ 256 ] ;
str_format ( buf , sizeof ( buf ) , " %d " , gameclient . voting - > seconds_left ( ) ) ;
2009-10-27 14:38:53 +00:00
UI ( ) - > DoLabel ( & button , buf , 24.0f , 0 ) ;
2008-09-29 11:34:49 +00:00
// do description and command
2009-10-27 14:38:53 +00:00
votearea . VSplitLeft ( 5.0f , 0 , & votearea ) ;
UI ( ) - > DoLabel ( & votearea , gameclient . voting - > vote_description ( ) , 14.0f , - 1 ) ;
votearea . HSplitTop ( 16.0f , 0 , & votearea ) ;
UI ( ) - > DoLabel ( & votearea , gameclient . voting - > vote_command ( ) , 10.0f , - 1 ) ;
2008-09-29 11:34:49 +00:00
// do bars
2009-10-27 14:38:53 +00:00
bars . HSplitTop ( 10.0f , 0 , & bars ) ;
bars . HMargin ( 5.0f , & bars ) ;
2008-09-29 11:34:49 +00:00
gameclient . voting - > render_bars ( bars , true ) ;
}
else
{
2009-10-27 14:38:53 +00:00
UI ( ) - > DoLabel ( & votearea , " No vote in progress " , 18.0f , - 1 ) ;
2008-09-29 11:34:49 +00:00
} */
}
2010-05-29 07:25:38 +00:00
void CMenus : : RenderServerInfo ( CUIRect MainView )
2008-09-29 11:34:49 +00:00
{
2011-03-13 10:14:35 +00:00
if ( ! m_pClient - > m_Snap . m_pLocalInfo )
return ;
2008-10-17 21:16:23 +00:00
// fetch server info
2010-05-29 07:25:38 +00:00
CServerInfo CurrentServerInfo ;
Client ( ) - > GetServerInfo ( & CurrentServerInfo ) ;
2008-10-17 21:16:23 +00:00
2008-09-29 11:34:49 +00:00
// render background
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & MainView , ms_ColorTabbarActive , CUI : : CORNER_ALL , 10.0f ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
CUIRect View , ServerInfo , GameInfo , Motd ;
2008-09-29 11:34:49 +00:00
float x = 0.0f ;
float y = 0.0f ;
2010-05-29 07:25:38 +00:00
char aBuf [ 1024 ] ;
2008-09-29 11:34:49 +00:00
// set view to use for all sub-modules
2010-05-29 07:25:38 +00:00
MainView . Margin ( 10.0f , & View ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
// serverinfo
2010-12-14 00:20:47 +00:00
View . HSplitTop ( View . h / 2 / UI ( ) - > Scale ( ) - 5.0f , & ServerInfo , & Motd ) ;
ServerInfo . VSplitLeft ( View . w / 2 / UI ( ) - > Scale ( ) - 5.0f , & ServerInfo , & GameInfo ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & ServerInfo , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_ALL , 10.0f ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
ServerInfo . Margin ( 5.0f , & ServerInfo ) ;
2008-09-29 11:34:49 +00:00
x = 5.0f ;
y = 0.0f ;
2010-05-29 07:25:38 +00:00
TextRender ( ) - > Text ( 0 , ServerInfo . x + x , ServerInfo . y + y , 32 , Localize ( " Server info " ) , 250 ) ;
2008-09-29 11:34:49 +00:00
y + = 32.0f + 5.0f ;
2010-05-29 07:25:38 +00:00
mem_zero ( aBuf , sizeof ( aBuf ) ) ;
2008-09-29 11:34:49 +00:00
str_format (
2010-05-29 07:25:38 +00:00
aBuf ,
sizeof ( aBuf ) ,
2008-09-29 11:34:49 +00:00
" %s \n \n "
2009-06-15 07:34:25 +00:00
" %s: %s \n "
" %s: %d \n "
" %s: %s \n "
" %s: %s \n " ,
2010-05-29 07:25:38 +00:00
CurrentServerInfo . m_aName ,
Localize ( " Address " ) , g_Config . m_UiServerAddress ,
Localize ( " Ping " ) , m_pClient - > m_Snap . m_pLocalInfo - > m_Latency ,
Localize ( " Version " ) , CurrentServerInfo . m_aVersion ,
Localize ( " Password " ) , CurrentServerInfo . m_Flags & 1 ? Localize ( " Yes " ) : Localize ( " No " )
2008-09-29 11:34:49 +00:00
) ;
2008-10-20 23:20:28 +00:00
2010-05-29 07:25:38 +00:00
TextRender ( ) - > Text ( 0 , ServerInfo . x + x , ServerInfo . y + y , 20 , aBuf , 250 ) ;
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
int IsFavorite = ServerBrowser ( ) - > IsFavorite ( CurrentServerInfo . m_NetAddr ) ;
ServerInfo . HSplitBottom ( 20.0f , & ServerInfo , & Button ) ;
static int s_AddFavButton = 0 ;
if ( DoButton_CheckBox ( & s_AddFavButton , Localize ( " Favorite " ) , IsFavorite , & Button ) )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
if ( IsFavorite )
ServerBrowser ( ) - > RemoveFavorite ( CurrentServerInfo . m_NetAddr ) ;
2008-09-29 11:34:49 +00:00
else
2010-05-29 07:25:38 +00:00
ServerBrowser ( ) - > AddFavorite ( CurrentServerInfo . m_NetAddr ) ;
2008-09-29 11:34:49 +00:00
}
}
2010-05-29 07:25:38 +00:00
// gameinfo
GameInfo . VSplitLeft ( 10.0f , 0x0 , & GameInfo ) ;
RenderTools ( ) - > DrawUIRect ( & GameInfo , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_ALL , 10.0f ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
GameInfo . Margin ( 5.0f , & GameInfo ) ;
2008-09-29 11:34:49 +00:00
x = 5.0f ;
y = 0.0f ;
2010-05-29 07:25:38 +00:00
TextRender ( ) - > Text ( 0 , GameInfo . x + x , GameInfo . y + y , 32 , Localize ( " Game info " ) , 250 ) ;
2008-09-29 11:34:49 +00:00
y + = 32.0f + 5.0f ;
2011-03-04 16:08:10 +00:00
if ( m_pClient - > m_Snap . m_pGameInfoObj )
{
mem_zero ( aBuf , sizeof ( aBuf ) ) ;
str_format (
aBuf ,
sizeof ( aBuf ) ,
" \n \n "
" %s: %s \n "
" %s: %s \n "
" %s: %d \n "
" %s: %d \n "
" \n "
" %s: %d/%d \n " ,
Localize ( " Game type " ) , CurrentServerInfo . m_aGameType ,
Localize ( " Map " ) , CurrentServerInfo . m_aMap ,
Localize ( " Score limit " ) , m_pClient - > m_Snap . m_pGameInfoObj - > m_ScoreLimit ,
Localize ( " Time limit " ) , m_pClient - > m_Snap . m_pGameInfoObj - > m_TimeLimit ,
2011-03-20 14:33:49 +00:00
Localize ( " Players " ) , m_pClient - > m_Snap . m_NumPlayers , CurrentServerInfo . m_MaxClients
2011-03-04 16:08:10 +00:00
) ;
TextRender ( ) - > Text ( 0 , GameInfo . x + x , GameInfo . y + y , 20 , aBuf , 250 ) ;
}
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
// motd
Motd . HSplitTop ( 10.0f , 0 , & Motd ) ;
RenderTools ( ) - > DrawUIRect ( & Motd , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_ALL , 10.0f ) ;
Motd . Margin ( 5.0f , & Motd ) ;
2008-09-29 11:34:49 +00:00
y = 0.0f ;
x = 5.0f ;
2010-05-29 07:25:38 +00:00
TextRender ( ) - > Text ( 0 , Motd . x + x , Motd . y + y , 32 , Localize ( " MOTD " ) , - 1 ) ;
2008-09-29 11:34:49 +00:00
y + = 32.0f + 5.0f ;
2010-05-29 07:25:38 +00:00
TextRender ( ) - > Text ( 0 , Motd . x + x , Motd . y + y , 16 , m_pClient - > m_pMotd - > m_aServerMotd , ( int ) Motd . w ) ;
2008-09-29 11:34:49 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : RenderServerControlServer ( CUIRect MainView )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
static int s_VoteList = 0 ;
static float s_ScrollValue = 0 ;
CUIRect List = MainView ;
2011-03-28 21:51:46 +00:00
UiDoListboxStart ( & s_VoteList , & List , 24.0f , Localize ( " Change settings " ) , " " , m_pClient - > m_pVoting - > m_NumVoteOptions , 1 , m_CallvoteSelectedOption , s_ScrollValue ) ;
2009-01-21 23:13:37 +00:00
2011-03-26 16:44:34 +00:00
for ( CVoteOptionClient * pOption = m_pClient - > m_pVoting - > m_pFirst ; pOption ; pOption = pOption - > m_pNext )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
CListboxItem Item = UiDoListboxNextItem ( pOption ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
if ( Item . m_Visible )
2011-03-25 09:26:59 +00:00
UI ( ) - > DoLabelScaled ( & Item . m_Rect , pOption - > m_aDescription , 16.0f , - 1 ) ;
2008-10-06 18:05:01 +00:00
}
2009-01-21 23:13:37 +00:00
2010-05-29 07:25:38 +00:00
m_CallvoteSelectedOption = UiDoListboxEnd ( & s_ScrollValue , 0 ) ;
2008-09-29 11:34:49 +00:00
}
2011-03-26 15:56:59 +00:00
void CMenus : : RenderServerControlKick ( CUIRect MainView , bool FilterSpectators )
2008-09-29 11:34:49 +00:00
{
2010-05-31 15:36:20 +00:00
int NumOptions = 0 ;
2010-05-31 20:05:45 +00:00
int Selected = - 1 ;
static int aPlayerIDs [ MAX_CLIENTS ] ;
2010-05-31 15:36:20 +00:00
for ( int i = 0 ; i < MAX_CLIENTS ; i + + )
{
2011-03-25 08:27:46 +00:00
if ( ! m_pClient - > m_Snap . m_paPlayerInfos [ i ] | | i = = m_pClient - > m_Snap . m_LocalClientID )
2010-05-31 15:36:20 +00:00
continue ;
2011-03-26 15:56:59 +00:00
if ( FilterSpectators & & m_pClient - > m_Snap . m_paPlayerInfos [ i ] - > m_Team = = TEAM_SPECTATORS )
continue ;
2010-05-31 20:05:45 +00:00
if ( m_CallvoteSelectedPlayer = = i )
Selected = NumOptions ;
aPlayerIDs [ NumOptions + + ] = i ;
2010-05-31 15:36:20 +00:00
}
2008-09-29 11:34:49 +00:00
2010-05-31 15:36:20 +00:00
static int s_VoteList = 0 ;
static float s_ScrollValue = 0 ;
2010-05-29 07:25:38 +00:00
CUIRect List = MainView ;
2011-03-31 13:43:12 +00:00
UiDoListboxStart ( & s_VoteList , & List , 24.0f , FilterSpectators ? Localize ( " Move player to spectators " ) : Localize ( " Kick player " ) , " " , NumOptions , 1 , Selected , s_ScrollValue ) ;
2010-05-31 15:36:20 +00:00
2010-05-31 20:05:45 +00:00
for ( int i = 0 ; i < NumOptions ; i + + )
2008-09-29 11:34:49 +00:00
{
2010-05-31 20:05:45 +00:00
CListboxItem Item = UiDoListboxNextItem ( & aPlayerIDs [ i ] ) ;
2008-09-29 11:34:49 +00:00
2010-05-31 15:36:20 +00:00
if ( Item . m_Visible )
{
2010-05-31 20:05:45 +00:00
CTeeRenderInfo Info = m_pClient - > m_aClients [ aPlayerIDs [ i ] ] . m_RenderInfo ;
2010-05-31 15:36:20 +00:00
Info . m_Size = Item . m_Rect . h ;
Item . m_Rect . HSplitTop ( 5.0f , 0 , & Item . m_Rect ) ; // some margin from the top
RenderTools ( ) - > RenderTee ( CAnimState : : GetIdle ( ) , & Info , EMOTE_NORMAL , vec2 ( 1 , 0 ) , vec2 ( Item . m_Rect . x + Item . m_Rect . h / 2 , Item . m_Rect . y + Item . m_Rect . h / 2 ) ) ;
Item . m_Rect . x + = Info . m_Size ;
2010-12-14 00:20:47 +00:00
UI ( ) - > DoLabelScaled ( & Item . m_Rect , m_pClient - > m_aClients [ aPlayerIDs [ i ] ] . m_aName , 16.0f , - 1 ) ;
2010-05-31 15:36:20 +00:00
}
2008-09-29 11:34:49 +00:00
}
2010-05-31 15:36:20 +00:00
2010-05-31 20:05:45 +00:00
Selected = UiDoListboxEnd ( & s_ScrollValue , 0 ) ;
m_CallvoteSelectedPlayer = Selected ! = - 1 ? aPlayerIDs [ Selected ] : - 1 ;
2008-09-29 11:34:49 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : RenderServerControl ( CUIRect MainView )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
static int s_ControlPage = 0 ;
2008-09-29 11:34:49 +00:00
// render background
2011-04-06 09:41:40 +00:00
CUIRect Bottom , Extended , TabBar , Button ;
MainView . HSplitBottom ( 20.0f , & MainView , & TabBar ) ;
RenderTools ( ) - > DrawUIRect ( & MainView , ms_ColorTabbarActive , CUI : : CORNER_T , 10.0f ) ;
MainView . Margin ( 10.0f , & MainView ) ;
MainView . HSplitBottom ( 90.0f , & MainView , & Extended ) ;
// tab bar
2008-09-29 11:34:49 +00:00
{
2011-04-06 09:41:40 +00:00
TabBar . VSplitLeft ( TabBar . w / 3 , & Button , & TabBar ) ;
static int s_Button0 = 0 ;
if ( DoButton_MenuTab ( & s_Button0 , Localize ( " Change settings " ) , s_ControlPage = = 0 , & Button , CUI : : CORNER_BL ) )
s_ControlPage = 0 ;
TabBar . VSplitMid ( & Button , & TabBar ) ;
static int s_Button1 = 0 ;
if ( DoButton_MenuTab ( & s_Button1 , Localize ( " Kick player " ) , s_ControlPage = = 1 , & Button , 0 ) )
s_ControlPage = 1 ;
static int s_Button2 = 0 ;
if ( DoButton_MenuTab ( & s_Button2 , Localize ( " Move player to spectators " ) , s_ControlPage = = 2 , & TabBar , CUI : : CORNER_BR ) )
s_ControlPage = 2 ;
2008-09-29 11:34:49 +00:00
}
2011-03-31 13:43:12 +00:00
// render page
2010-05-29 07:25:38 +00:00
MainView . HSplitBottom ( ms_ButtonHeight + 5 * 2 , & MainView , & Bottom ) ;
Bottom . HMargin ( 5.0f , & Bottom ) ;
2011-03-31 13:43:12 +00:00
2010-05-29 07:25:38 +00:00
if ( s_ControlPage = = 0 )
RenderServerControlServer ( MainView ) ;
else if ( s_ControlPage = = 1 )
2011-03-26 15:56:59 +00:00
RenderServerControlKick ( MainView , false ) ;
else if ( s_ControlPage = = 2 )
2011-03-31 13:43:12 +00:00
RenderServerControlKick ( MainView , true ) ;
2008-09-29 11:34:49 +00:00
2011-03-31 13:43:12 +00:00
// vote menu
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Button ;
Bottom . VSplitRight ( 120.0f , & Bottom , & Button ) ;
2008-09-29 11:34:49 +00:00
2010-05-29 07:25:38 +00:00
static int s_CallVoteButton = 0 ;
if ( DoButton_Menu ( & s_CallVoteButton , Localize ( " Call vote " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
if ( s_ControlPage = = 0 )
2011-03-25 09:26:59 +00:00
m_pClient - > m_pVoting - > CallvoteOption ( m_CallvoteSelectedOption , m_aCallvoteReason ) ;
2010-05-29 07:25:38 +00:00
else if ( s_ControlPage = = 1 )
{
if ( m_CallvoteSelectedPlayer > = 0 & & m_CallvoteSelectedPlayer < MAX_CLIENTS & &
m_pClient - > m_Snap . m_paPlayerInfos [ m_CallvoteSelectedPlayer ] )
{
2010-10-09 18:34:17 +00:00
m_pClient - > m_pVoting - > CallvoteKick ( m_CallvoteSelectedPlayer , m_aCallvoteReason ) ;
2010-05-29 07:25:38 +00:00
SetActive ( false ) ;
}
}
2011-03-26 15:56:59 +00:00
else if ( s_ControlPage = = 2 )
{
if ( m_CallvoteSelectedPlayer > = 0 & & m_CallvoteSelectedPlayer < MAX_CLIENTS & &
m_pClient - > m_Snap . m_paPlayerInfos [ m_CallvoteSelectedPlayer ] )
{
m_pClient - > m_pVoting - > CallvoteSpectate ( m_CallvoteSelectedPlayer , m_aCallvoteReason ) ;
SetActive ( false ) ;
}
}
2011-03-25 11:06:45 +00:00
m_aCallvoteReason [ 0 ] = 0 ;
2010-05-29 07:25:38 +00:00
}
2010-10-09 18:34:17 +00:00
// render kick reason
2011-03-25 09:26:59 +00:00
CUIRect Reason ;
Bottom . VSplitRight ( 40.0f , & Bottom , 0 ) ;
Bottom . VSplitRight ( 160.0f , & Bottom , & Reason ) ;
Reason . HSplitTop ( 5.0f , 0 , & Reason ) ;
const char * pLabel = Localize ( " Reason: " ) ;
UI ( ) - > DoLabelScaled ( & Reason , pLabel , 14.0f , - 1 ) ;
float w = TextRender ( ) - > TextWidth ( 0 , 14.0f , pLabel , - 1 ) ;
Reason . VSplitLeft ( w + 10.0f , 0 , & Reason ) ;
static float s_Offset = 0.0f ;
DoEditBox ( & m_aCallvoteReason , & Reason , m_aCallvoteReason , sizeof ( m_aCallvoteReason ) , 14.0f , & s_Offset , false , CUI : : CORNER_ALL ) ;
2010-10-09 18:34:17 +00:00
2011-03-26 17:43:43 +00:00
// extended features (only available when authed in rcon)
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > RconAuthed ( ) )
{
2011-03-26 17:43:43 +00:00
// background
Extended . Margin ( 10.0f , & Extended ) ;
Extended . HSplitTop ( 20.0f , & Bottom , & Extended ) ;
Extended . HSplitTop ( 5.0f , 0 , & Extended ) ;
// force vote
Bottom . VSplitLeft ( 5.0f , 0 , & Bottom ) ;
2010-05-29 07:25:38 +00:00
Bottom . VSplitLeft ( 120.0f , & Button , & Bottom ) ;
static int s_ForceVoteButton = 0 ;
if ( DoButton_Menu ( & s_ForceVoteButton , Localize ( " Force vote " ) , 0 , & Button ) )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
if ( s_ControlPage = = 0 )
2011-03-25 11:06:45 +00:00
m_pClient - > m_pVoting - > CallvoteOption ( m_CallvoteSelectedOption , m_aCallvoteReason , true ) ;
2010-05-29 07:25:38 +00:00
else if ( s_ControlPage = = 1 )
2008-09-29 11:34:49 +00:00
{
2010-05-29 07:25:38 +00:00
if ( m_CallvoteSelectedPlayer > = 0 & & m_CallvoteSelectedPlayer < MAX_CLIENTS & &
m_pClient - > m_Snap . m_paPlayerInfos [ m_CallvoteSelectedPlayer ] )
{
2011-03-25 11:06:45 +00:00
m_pClient - > m_pVoting - > CallvoteKick ( m_CallvoteSelectedPlayer , m_aCallvoteReason , true ) ;
2010-05-29 07:25:38 +00:00
SetActive ( false ) ;
}
2008-09-29 11:34:49 +00:00
}
2011-03-26 15:56:59 +00:00
else if ( s_ControlPage = = 2 )
{
if ( m_CallvoteSelectedPlayer > = 0 & & m_CallvoteSelectedPlayer < MAX_CLIENTS & &
m_pClient - > m_Snap . m_paPlayerInfos [ m_CallvoteSelectedPlayer ] )
{
m_pClient - > m_pVoting - > CallvoteSpectate ( m_CallvoteSelectedPlayer , m_aCallvoteReason , true ) ;
SetActive ( false ) ;
}
}
2011-03-25 11:06:45 +00:00
m_aCallvoteReason [ 0 ] = 0 ;
2008-09-29 11:34:49 +00:00
}
2011-03-26 17:43:43 +00:00
if ( s_ControlPage = = 0 )
{
// remove vote
Bottom . VSplitRight ( 10.0f , & Bottom , 0 ) ;
Bottom . VSplitRight ( 120.0f , 0 , & Button ) ;
static int s_RemoveVoteButton = 0 ;
if ( DoButton_Menu ( & s_RemoveVoteButton , Localize ( " Remove " ) , 0 , & Button ) )
m_pClient - > m_pVoting - > RemovevoteOption ( m_CallvoteSelectedOption ) ;
// add vote
Extended . HSplitTop ( 20.0f , & Bottom , & Extended ) ;
Bottom . VSplitLeft ( 5.0f , 0 , & Bottom ) ;
Bottom . VSplitLeft ( 250.0f , & Button , & Bottom ) ;
UI ( ) - > DoLabelScaled ( & Button , Localize ( " Vote description: " ) , 14.0f , - 1 ) ;
Bottom . VSplitLeft ( 20.0f , 0 , & Button ) ;
UI ( ) - > DoLabelScaled ( & Button , Localize ( " Vote command: " ) , 14.0f , - 1 ) ;
static char s_aVoteDescription [ 64 ] = { 0 } ;
static char s_aVoteCommand [ 512 ] = { 0 } ;
Extended . HSplitTop ( 20.0f , & Bottom , & Extended ) ;
Bottom . VSplitRight ( 10.0f , & Bottom , 0 ) ;
Bottom . VSplitRight ( 120.0f , & Bottom , & Button ) ;
static int s_AddVoteButton = 0 ;
if ( DoButton_Menu ( & s_AddVoteButton , Localize ( " Add " ) , 0 , & Button ) )
2011-04-05 18:06:41 +00:00
if ( s_aVoteDescription [ 0 ] ! = 0 & & s_aVoteCommand [ 0 ] ! = 0 )
m_pClient - > m_pVoting - > AddvoteOption ( s_aVoteDescription , s_aVoteCommand ) ;
2011-03-26 17:43:43 +00:00
Bottom . VSplitLeft ( 5.0f , 0 , & Bottom ) ;
Bottom . VSplitLeft ( 250.0f , & Button , & Bottom ) ;
static float s_OffsetDesc = 0.0f ;
DoEditBox ( & s_aVoteDescription , & Button , s_aVoteDescription , sizeof ( s_aVoteDescription ) , 14.0f , & s_OffsetDesc , false , CUI : : CORNER_ALL ) ;
Bottom . VMargin ( 20.0f , & Button ) ;
static float s_OffsetCmd = 0.0f ;
DoEditBox ( & s_aVoteCommand , & Button , s_aVoteCommand , sizeof ( s_aVoteCommand ) , 14.0f , & s_OffsetCmd , false , CUI : : CORNER_ALL ) ;
}
2008-09-29 11:34:49 +00:00
}
2011-03-31 13:43:12 +00:00
}
2008-09-29 11:34:49 +00:00
}