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. */
2011-08-31 11:56:04 +00:00
# include <base/tl/array.h>
2014-06-05 10:11:41 +00:00
# include <sstream>
# include <string>
2011-08-31 11:56:04 +00:00
2008-08-27 15:48:50 +00:00
# include <math.h>
# include <base/system.h>
2010-05-29 07:25:38 +00:00
# include <base/math.h>
# include <base/vmath.h>
2008-08-27 15:48:50 +00:00
2011-03-23 12:06:35 +00:00
# include <engine/config.h>
2011-03-21 23:31:42 +00:00
# include <engine/editor.h>
2011-04-13 18:00:54 +00:00
# include <engine/engine.h>
2011-03-23 12:06:35 +00:00
# include <engine/friends.h>
2010-05-29 07:25:38 +00:00
# include <engine/graphics.h>
# include <engine/keys.h>
2011-03-21 23:31:42 +00:00
# include <engine/serverbrowser.h>
2010-10-06 21:07:35 +00:00
# include <engine/storage.h>
2011-03-21 23:31:42 +00:00
# include <engine/textrender.h>
2014-05-17 12:28:50 +00:00
# include <engine/autoupdate.h>
2010-05-29 07:25:38 +00:00
# include <engine/shared/config.h>
2009-06-13 17:18:06 +00:00
2010-05-29 07:25:38 +00:00
# include <game/version.h>
# include <game/generated/protocol.h>
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
# include <game/generated/client_data.h>
2011-04-13 18:00:54 +00:00
# include <game/client/components/sounds.h>
2010-05-29 07:25:38 +00:00
# include <game/client/gameclient.h>
# include <game/client/lineinput.h>
# include <game/localization.h>
2008-08-27 15:48:50 +00:00
# include <mastersrv/mastersrv.h>
2014-06-05 10:11:41 +00:00
# include <versionsrv/versionsrv.h>
2008-08-27 15:48:50 +00:00
2011-06-29 20:27:32 +00:00
# include "countryflags.h"
2011-03-23 12:06:35 +00:00
# include "menus.h"
# include "skins.h"
2014-06-16 11:29:18 +00:00
# include "controls.h"
2011-03-23 12:06:35 +00:00
2010-05-29 07:25:38 +00:00
vec4 CMenus : : ms_GuiColor ;
vec4 CMenus : : ms_ColorTabbarInactiveOutgame ;
vec4 CMenus : : ms_ColorTabbarActiveOutgame ;
vec4 CMenus : : ms_ColorTabbarInactive ;
2011-11-30 00:41:00 +00:00
vec4 CMenus : : ms_ColorTabbarActive = vec4 ( 0 , 0 , 0 , 0.5f ) ;
2010-05-29 07:25:38 +00:00
vec4 CMenus : : ms_ColorTabbarInactiveIngame ;
vec4 CMenus : : ms_ColorTabbarActiveIngame ;
2008-08-27 15:48:50 +00:00
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
float CMenus : : ms_ButtonHeight = 50.0f ;
float CMenus : : ms_ListheaderHeight = 50.0f ;
float CMenus : : ms_ListitemAdditionalHeight = 33.0f ;
# else
2010-05-29 07:25:38 +00:00
float CMenus : : ms_ButtonHeight = 25.0f ;
float CMenus : : ms_ListheaderHeight = 17.0f ;
2014-06-16 11:29:18 +00:00
# endif
2010-05-29 07:25:38 +00:00
float CMenus : : ms_FontmodHeight = 0.8f ;
2008-10-06 18:05:01 +00:00
2010-05-29 07:25:38 +00:00
IInput : : CEvent CMenus : : m_aInputEvents [ MAX_INPUTEVENTS ] ;
int CMenus : : m_NumInputEvents ;
2008-08-30 09:28:31 +00:00
2010-05-29 07:25:38 +00:00
CMenus : : CMenus ( )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE ;
m_ActivePage = PAGE_INTERNET ;
m_GamePage = PAGE_GAME ;
2011-04-13 18:37:12 +00:00
2010-10-16 09:24:42 +00:00
m_NeedRestartGraphics = false ;
m_NeedRestartSound = false ;
2010-05-29 07:25:38 +00:00
m_NeedSendinfo = false ;
2014-04-28 13:19:57 +00:00
m_NeedSendDummyinfo = false ;
2010-05-29 07:25:38 +00:00
m_MenuActive = true ;
m_UseMouseButtons = true ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
m_EscapePressed = false ;
m_EnterPressed = false ;
2010-09-03 18:05:22 +00:00
m_DeletePressed = false ;
2010-05-29 07:25:38 +00:00
m_NumInputEvents = 0 ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
m_LastInput = time_get ( ) ;
2011-04-13 18:37:12 +00:00
2010-06-04 20:14:02 +00:00
str_copy ( m_aCurrentDemoFolder , " demos " , sizeof ( m_aCurrentDemoFolder ) ) ;
2010-10-09 18:34:17 +00:00
m_aCallvoteReason [ 0 ] = 0 ;
2011-03-23 12:06:35 +00:00
m_FriendlistSelectedIndex = - 1 ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2011-04-09 06:41:31 +00:00
2011-02-23 07:33:21 +00:00
m_DDRacePage = PAGE_BROWSER ;
2014-08-23 15:48:04 +00:00
m_DemoPlayerState = DEMOPLAYER_NONE ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
vec4 CMenus : : ButtonColorMul ( const void * pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
return vec4 ( 1 , 1 , 1 , 0.5f ) ;
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
return vec4 ( 1 , 1 , 1 , 1.5f ) ;
return vec4 ( 1 , 1 , 1 , 1 ) ;
}
2010-11-17 18:46:50 +00:00
int CMenus : : DoButton_Icon ( int ImageId , int SpriteId , const CUIRect * pRect )
2008-08-27 15:48:50 +00:00
{
2010-11-17 18:46:50 +00:00
Graphics ( ) - > TextureSet ( g_pData - > m_aImages [ ImageId ] . m_Id ) ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2010-11-17 18:46:50 +00:00
RenderTools ( ) - > SelectSprite ( SpriteId ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CQuadItem QuadItem ( pRect - > x , pRect - > y , pRect - > w , pRect - > h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
return 0 ;
2008-08-27 15:48:50 +00:00
}
2012-01-10 22:03:23 +00:00
int CMenus : : DoButton_Toggle ( const void * pID , int Checked , const CUIRect * pRect , bool Active )
2011-04-06 18:18:31 +00:00
{
Graphics ( ) - > TextureSet ( g_pData - > m_aImages [ IMAGE_GUIBUTTONS ] . m_Id ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2012-01-10 22:03:23 +00:00
if ( ! Active )
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 0.5f ) ;
2011-04-06 18:18:31 +00:00
RenderTools ( ) - > SelectSprite ( Checked ? SPRITE_GUIBUTTON_ON : SPRITE_GUIBUTTON_OFF ) ;
IGraphics : : CQuadItem QuadItem ( pRect - > x , pRect - > y , pRect - > w , pRect - > h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2012-01-10 22:03:23 +00:00
if ( UI ( ) - > HotItem ( ) = = pID & & Active )
2011-04-06 18:18:31 +00:00
{
RenderTools ( ) - > SelectSprite ( SPRITE_GUIBUTTON_HOVER ) ;
IGraphics : : CQuadItem QuadItem ( pRect - > x , pRect - > y , pRect - > w , pRect - > h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
}
Graphics ( ) - > QuadsEnd ( ) ;
2011-04-13 18:37:12 +00:00
2012-01-10 22:03:23 +00:00
return Active ? UI ( ) - > DoButtonLogic ( pID , " " , Checked , pRect ) : 0 ;
2011-04-06 18:18:31 +00:00
}
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_Menu ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
2008-08-27 15:48:50 +00:00
{
2010-12-06 01:32:44 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , vec4 ( 1 , 1 , 1 , 0.5f ) * ButtonColorMul ( pID ) , CUI : : CORNER_ALL , 5.0f ) ;
2011-04-01 15:57:04 +00:00
CUIRect Temp ;
pRect - > HMargin ( pRect - > h > = 20.0f ? 2.0f : 1.0f , & Temp ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
float TextH = min ( 22.0f , Temp . h ) ;
Temp . y + = ( Temp . h - TextH ) / 2 ;
UI ( ) - > DoLabel ( & Temp , pText , TextH * ms_FontmodHeight , 0 ) ;
# else
2011-04-01 15:57:04 +00:00
UI ( ) - > DoLabel ( & Temp , pText , Temp . h * ms_FontmodHeight , 0 ) ;
2014-06-16 11:29:18 +00:00
# endif
2009-10-27 14:38:53 +00:00
return UI ( ) - > DoButtonLogic ( pID , pText , Checked , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : DoButton_KeySelect ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , vec4 ( 1 , 1 , 1 , 0.5f ) * ButtonColorMul ( pID ) , CUI : : CORNER_ALL , 5.0f ) ;
2011-04-01 15:57:04 +00:00
CUIRect Temp ;
pRect - > HMargin ( 1.0f , & Temp ) ;
UI ( ) - > DoLabel ( & Temp , pText , Temp . h * ms_FontmodHeight , 0 ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_MenuTab ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Corners )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( Checked )
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ms_ColorTabbarActive , Corners , 10.0f ) ;
2008-08-27 15:48:50 +00:00
else
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ms_ColorTabbarInactive , Corners , 10.0f ) ;
2011-04-01 15:57:04 +00:00
CUIRect Temp ;
pRect - > HMargin ( 2.0f , & Temp ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
float TextH = min ( 22.0f , Temp . h ) ;
Temp . y + = ( Temp . h - TextH ) / 2 ;
UI ( ) - > DoLabel ( & Temp , pText , TextH * ms_FontmodHeight , 0 ) ;
# else
2011-04-01 15:57:04 +00:00
UI ( ) - > DoLabel ( & Temp , pText , Temp . h * ms_FontmodHeight , 0 ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
return UI ( ) - > DoButtonLogic ( pID , pText , Checked , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_GridHeader ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
//void CMenus::ui_draw_grid_header(const void *id, const char *text, int checked, const CUIRect *r, const void *extra)
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( Checked )
RenderTools ( ) - > DrawUIRect ( pRect , vec4 ( 1 , 1 , 1 , 0.5f ) , CUI : : CORNER_T , 5.0f ) ;
CUIRect t ;
pRect - > VSplitLeft ( 5.0f , 0 , & t ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
float TextH = min ( 20.0f , pRect - > h ) ;
UI ( ) - > DoLabel ( & t , pText , TextH * ms_FontmodHeight , - 1 ) ;
# else
2010-05-29 07:25:38 +00:00
UI ( ) - > DoLabel ( & t , pText , pRect - > h * ms_FontmodHeight , - 1 ) ;
2014-06-16 11:29:18 +00:00
# endif
2009-10-27 14:38:53 +00:00
return UI ( ) - > DoButtonLogic ( pID , pText , Checked , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_CheckBox_Common ( const void * pID , const char * pText , const char * pBoxText , const CUIRect * pRect )
//void CMenus::ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const CUIRect *r, const void *extra)
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect c = * pRect ;
CUIRect t = * pRect ;
2008-08-27 15:48:50 +00:00
c . w = c . h ;
t . x + = c . w ;
t . w - = c . w ;
2009-10-27 14:38:53 +00:00
t . VSplitLeft ( 5.0f , 0 , & t ) ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
c . Margin ( 2.0f , & c ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & c , vec4 ( 1 , 1 , 1 , 0.25f ) * ButtonColorMul ( pID ) , CUI : : CORNER_ALL , 3.0f ) ;
2008-08-27 15:48:50 +00:00
c . y + = 2 ;
2010-05-29 07:25:38 +00:00
UI ( ) - > DoLabel ( & c , pBoxText , pRect - > h * ms_FontmodHeight * 0.6f , 0 ) ;
UI ( ) - > DoLabel ( & t , pText , pRect - > h * ms_FontmodHeight * 0.8f , - 1 ) ;
2009-10-27 14:38:53 +00:00
return UI ( ) - > DoButtonLogic ( pID , pText , 0 , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_CheckBox ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
return DoButton_CheckBox_Common ( pID , pText , Checked ? " X " : " " , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoButton_CheckBox_Number ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
char aBuf [ 16 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %d " , Checked ) ;
return DoButton_CheckBox_Common ( pID , pText , aBuf , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 15:53:57 +00:00
int CMenus : : DoEditBox ( void * pID , const CUIRect * pRect , char * pStr , unsigned StrSize , float FontSize , float * Offset , bool Hidden , int Corners )
2008-08-27 15:48:50 +00:00
{
2011-04-13 18:37:12 +00:00
int Inside = UI ( ) - > MouseInside ( pRect ) ;
2010-05-29 07:25:38 +00:00
bool ReturnValue = false ;
2010-10-10 23:36:46 +00:00
bool UpdateOffset = false ;
2010-05-29 07:25:38 +00:00
static int s_AtIndex = 0 ;
2010-10-10 23:36:46 +00:00
static bool s_DoScroll = false ;
static float s_ScrollStart = 0.0f ;
2008-08-27 15:48:50 +00:00
2010-12-14 00:20:47 +00:00
FontSize * = UI ( ) - > Scale ( ) ;
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
int Len = str_length ( pStr ) ;
if ( Len = = 0 )
s_AtIndex = 0 ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Inside & & UI ( ) - > MouseButton ( 0 ) )
2008-08-27 15:48:50 +00:00
{
2010-10-10 23:36:46 +00:00
s_DoScroll = true ;
s_ScrollStart = UI ( ) - > MouseX ( ) ;
2010-05-29 07:25:38 +00:00
int MxRel = ( int ) ( UI ( ) - > MouseX ( ) - pRect - > x ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
for ( int i = 1 ; i < = Len ; i + + )
2008-08-27 15:48:50 +00:00
{
2011-06-29 16:39:58 +00:00
if ( TextRender ( ) - > TextWidth ( 0 , FontSize , pStr , i ) - * Offset > MxRel )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
s_AtIndex = i - 1 ;
2008-08-27 15:48:50 +00:00
break ;
}
2010-05-29 07:25:38 +00:00
if ( i = = Len )
s_AtIndex = Len ;
2008-08-27 15:48:50 +00:00
}
}
2010-10-10 23:36:46 +00:00
else if ( ! UI ( ) - > MouseButton ( 0 ) )
s_DoScroll = false ;
else if ( s_DoScroll )
{
// do scrolling
if ( UI ( ) - > MouseX ( ) < pRect - > x & & s_ScrollStart - UI ( ) - > MouseX ( ) > 10.0f )
{
s_AtIndex = max ( 0 , s_AtIndex - 1 ) ;
s_ScrollStart = UI ( ) - > MouseX ( ) ;
UpdateOffset = true ;
}
else if ( UI ( ) - > MouseX ( ) > pRect - > x + pRect - > w & & UI ( ) - > MouseX ( ) - s_ScrollStart > 10.0f )
{
s_AtIndex = min ( Len , s_AtIndex + 1 ) ;
s_ScrollStart = UI ( ) - > MouseX ( ) ;
UpdateOffset = true ;
}
}
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
for ( int i = 0 ; i < m_NumInputEvents ; i + + )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
Len = str_length ( pStr ) ;
2013-04-01 18:30:58 +00:00
int NumChars = Len ;
ReturnValue | = CLineInput : : Manipulate ( m_aInputEvents [ i ] , pStr , StrSize , StrSize , & Len , & s_AtIndex , & NumChars ) ;
2008-08-27 15:48:50 +00:00
}
}
2009-10-27 14:38:53 +00:00
bool JustGotActive = false ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
2010-10-10 23:36:46 +00:00
{
2011-06-27 14:39:23 +00:00
s_AtIndex = min ( s_AtIndex , str_length ( pStr ) ) ;
2010-10-10 23:36:46 +00:00
s_DoScroll = false ;
2009-10-27 14:38:53 +00:00
UI ( ) - > SetActiveItem ( 0 ) ;
2010-10-10 23:36:46 +00:00
}
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > LastActiveItem ( ) ! = pID )
JustGotActive = true ;
UI ( ) - > SetActiveItem ( pID ) ;
2008-08-27 15:48:50 +00:00
}
}
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Inside )
2014-06-16 11:29:18 +00:00
{
2009-10-27 14:38:53 +00:00
UI ( ) - > SetHotItem ( pID ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
if ( UI ( ) - > ActiveItem ( ) = = pID & & UI ( ) - > MouseButtonClicked ( 0 ) )
{
s_AtIndex = 0 ;
UI ( ) - > AndroidBlockAndGetTextInput ( pStr , StrSize , " " ) ;
}
# endif
}
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
CUIRect Textbox = * pRect ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & Textbox , vec4 ( 1 , 1 , 1 , 0.5f ) , Corners , 3.0f ) ;
2010-05-30 12:01:11 +00:00
Textbox . VMargin ( 2.0f , & Textbox ) ;
Textbox . HMargin ( 2.0f , & Textbox ) ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
const char * pDisplayStr = pStr ;
char aStars [ 128 ] ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Hidden )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
unsigned s = str_length ( pStr ) ;
2009-10-27 14:38:53 +00:00
if ( s > = sizeof ( aStars ) )
s = sizeof ( aStars ) - 1 ;
2010-05-29 07:25:38 +00:00
for ( unsigned int i = 0 ; i < s ; + + i )
aStars [ i ] = ' * ' ;
2009-10-27 14:38:53 +00:00
aStars [ s ] = 0 ;
pDisplayStr = aStars ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 15:53:57 +00:00
// check if the text has to be moved
2010-10-10 23:36:46 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = pID & & ! JustGotActive & & ( UpdateOffset | | m_NumInputEvents ) )
2010-05-29 15:53:57 +00:00
{
2010-12-14 00:20:47 +00:00
float w = TextRender ( ) - > TextWidth ( 0 , FontSize , pDisplayStr , s_AtIndex ) ;
2010-05-29 15:53:57 +00:00
if ( w - * Offset > Textbox . w )
{
// move to the left
2010-12-14 00:20:47 +00:00
float wt = TextRender ( ) - > TextWidth ( 0 , FontSize , pDisplayStr , - 1 ) ;
2010-05-29 15:53:57 +00:00
do
{
* Offset + = min ( wt - * Offset - Textbox . w , Textbox . w / 3 ) ;
}
while ( w - * Offset > Textbox . w ) ;
}
else if ( w - * Offset < 0.0f )
{
// move to the right
do
{
* Offset = max ( 0.0f , * Offset - Textbox . w / 3 ) ;
}
while ( w - * Offset < 0.0f ) ;
}
}
UI ( ) - > ClipEnable ( pRect ) ;
2010-12-14 00:20:47 +00:00
Textbox . x - = * Offset ;
2010-05-29 15:53:57 +00:00
2009-10-27 14:38:53 +00:00
UI ( ) - > DoLabel ( & Textbox , pDisplayStr , FontSize , - 1 ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 15:53:57 +00:00
// render the cursor
2010-05-29 07:25:38 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = pID & & ! JustGotActive )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
float w = TextRender ( ) - > TextWidth ( 0 , FontSize , pDisplayStr , s_AtIndex ) ;
Textbox = * pRect ;
Textbox . VSplitLeft ( 2.0f , 0 , & Textbox ) ;
2010-12-14 00:20:47 +00:00
Textbox . x + = ( w - * Offset - TextRender ( ) - > TextWidth ( 0 , FontSize , " | " , - 1 ) / 2 ) ;
2010-05-30 12:01:11 +00:00
2010-05-29 15:53:57 +00:00
if ( ( 2 * time_get ( ) / time_freq ( ) ) % 2 ) // make it blink
2010-05-30 12:01:11 +00:00
UI ( ) - > DoLabel ( & Textbox , " | " , FontSize , - 1 ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 15:53:57 +00:00
UI ( ) - > ClipDisable ( ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
return ReturnValue ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
float CMenus : : DoScrollbarV ( const void * pID , const CUIRect * pRect , float Current )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect Handle ;
static float OffsetY ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
pRect - > HSplitTop ( 50 , & Handle , 0 ) ;
# else
2009-10-27 14:38:53 +00:00
pRect - > HSplitTop ( 33 , & Handle , 0 ) ;
2014-06-16 11:29:18 +00:00
# endif
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
Handle . y + = ( pRect - > h - Handle . h ) * Current ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
// logic
2011-04-13 18:37:12 +00:00
float ReturnValue = Current ;
int Inside = UI ( ) - > MouseInside ( & Handle ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
UI ( ) - > SetActiveItem ( 0 ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
float Min = pRect - > y ;
float Max = pRect - > h - Handle . h ;
float Cur = UI ( ) - > MouseY ( ) - OffsetY ;
ReturnValue = ( Cur - Min ) / Max ;
2009-10-27 14:38:53 +00:00
if ( ReturnValue < 0.0f ) ReturnValue = 0.0f ;
if ( ReturnValue > 1.0f ) ReturnValue = 1.0f ;
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
OffsetY = UI ( ) - > MouseY ( ) - Handle . y ;
2008-08-27 15:48:50 +00:00
}
}
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Inside )
UI ( ) - > SetHotItem ( pID ) ;
2008-08-27 15:48:50 +00:00
// render
2009-10-27 14:38:53 +00:00
CUIRect Rail ;
pRect - > VMargin ( 5.0f , & Rail ) ;
RenderTools ( ) - > DrawUIRect ( & Rail , vec4 ( 1 , 1 , 1 , 0.25f ) , 0 , 0.0f ) ;
CUIRect Slider = Handle ;
Slider . w = Rail . x - Slider . x ;
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_L , 2.5f ) ;
Slider . x = Rail . x + Rail . w ;
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_R , 2.5f ) ;
Slider = Handle ;
Slider . Margin ( 5.0f , & Slider ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) * ButtonColorMul ( pID ) , CUI : : CORNER_ALL , 2.5f ) ;
2011-04-13 18:37:12 +00:00
return ReturnValue ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
float CMenus : : DoScrollbarH ( const void * pID , const CUIRect * pRect , float Current )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect Handle ;
static float OffsetX ;
pRect - > VSplitLeft ( 33 , & Handle , 0 ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
Handle . x + = ( pRect - > w - Handle . w ) * Current ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
// logic
2011-04-13 18:37:12 +00:00
float ReturnValue = Current ;
int Inside = UI ( ) - > MouseInside ( & Handle ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) )
UI ( ) - > SetActiveItem ( 0 ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
float Min = pRect - > x ;
float Max = pRect - > w - Handle . w ;
float Cur = UI ( ) - > MouseX ( ) - OffsetX ;
ReturnValue = ( Cur - Min ) / Max ;
2009-10-27 14:38:53 +00:00
if ( ReturnValue < 0.0f ) ReturnValue = 0.0f ;
if ( ReturnValue > 1.0f ) ReturnValue = 1.0f ;
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
UI ( ) - > SetActiveItem ( pID ) ;
OffsetX = UI ( ) - > MouseX ( ) - Handle . x ;
2008-08-27 15:48:50 +00:00
}
}
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Inside )
UI ( ) - > SetHotItem ( pID ) ;
2008-08-27 15:48:50 +00:00
// render
2009-10-27 14:38:53 +00:00
CUIRect Rail ;
pRect - > HMargin ( 5.0f , & Rail ) ;
RenderTools ( ) - > DrawUIRect ( & Rail , vec4 ( 1 , 1 , 1 , 0.25f ) , 0 , 0.0f ) ;
CUIRect Slider = Handle ;
Slider . h = Rail . y - Slider . y ;
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_T , 2.5f ) ;
Slider . y = Rail . y + Rail . h ;
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_B , 2.5f ) ;
Slider = Handle ;
Slider . Margin ( 5.0f , & Slider ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & Slider , vec4 ( 1 , 1 , 1 , 0.25f ) * ButtonColorMul ( pID ) , CUI : : CORNER_ALL , 2.5f ) ;
2011-04-13 18:37:12 +00:00
return ReturnValue ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : DoKeyReader ( void * pID , const CUIRect * pRect , int Key )
2008-08-27 15:48:50 +00:00
{
// process
2009-10-27 14:38:53 +00:00
static void * pGrabbedID = 0 ;
static bool MouseReleased = true ;
2010-09-12 15:15:09 +00:00
static int ButtonUsed = 0 ;
2009-10-27 14:38:53 +00:00
int Inside = UI ( ) - > MouseInside ( pRect ) ;
int NewKey = Key ;
2011-04-13 18:37:12 +00:00
2010-09-12 15:15:09 +00:00
if ( ! UI ( ) - > MouseButton ( 0 ) & & ! UI ( ) - > MouseButton ( 1 ) & & pGrabbedID = = pID )
2009-10-27 14:38:53 +00:00
MouseReleased = true ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( m_Binder . m_GotKey )
2008-08-27 15:48:50 +00:00
{
2010-09-12 11:40:24 +00:00
// abort with escape key
if ( m_Binder . m_Key . m_Key ! = KEY_ESCAPE )
NewKey = m_Binder . m_Key . m_Key ;
2010-05-29 07:25:38 +00:00
m_Binder . m_GotKey = false ;
2009-10-27 14:38:53 +00:00
UI ( ) - > SetActiveItem ( 0 ) ;
MouseReleased = false ;
pGrabbedID = pID ;
2008-08-27 15:48:50 +00:00
}
2010-09-12 15:15:09 +00:00
if ( ButtonUsed = = 1 & & ! UI ( ) - > MouseButton ( 1 ) )
{
if ( Inside )
NewKey = 0 ;
UI ( ) - > SetActiveItem ( 0 ) ;
}
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2008-08-27 15:48:50 +00:00
{
2010-09-12 15:15:09 +00:00
if ( MouseReleased )
2008-10-20 23:10:00 +00:00
{
2010-09-12 15:15:09 +00:00
if ( UI ( ) - > MouseButton ( 0 ) )
{
m_Binder . m_TakeKey = true ;
m_Binder . m_GotKey = false ;
UI ( ) - > SetActiveItem ( pID ) ;
ButtonUsed = 0 ;
}
if ( UI ( ) - > MouseButton ( 1 ) )
{
UI ( ) - > SetActiveItem ( pID ) ;
ButtonUsed = 1 ;
}
2008-10-20 23:10:00 +00:00
}
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
if ( Inside )
UI ( ) - > SetHotItem ( pID ) ;
2008-08-27 15:48:50 +00:00
// draw
2010-09-12 15:15:09 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID & & ButtonUsed = = 0 )
2009-10-27 14:38:53 +00:00
DoButton_KeySelect ( pID , " ??? " , 0 , pRect ) ;
2008-08-27 15:48:50 +00:00
else
{
2009-10-27 14:38:53 +00:00
if ( Key = = 0 )
DoButton_KeySelect ( pID , " " , 0 , pRect ) ;
2008-08-27 15:48:50 +00:00
else
2010-05-29 07:25:38 +00:00
DoButton_KeySelect ( pID , Input ( ) - > KeyName ( Key ) , 0 , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
return NewKey ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : RenderMenubar ( CUIRect r )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Box = r ;
CUIRect Button ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
m_ActivePage = g_Config . m_UiPage ;
int NewPage = - 1 ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > State ( ) ! = IClient : : STATE_OFFLINE )
m_ActivePage = m_GamePage ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
// offline menus
2014-06-05 10:11:41 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
static int s_NewsButton = 0 ;
if ( DoButton_MenuTab ( & s_NewsButton , Localize ( " News " ) , m_ActivePage = = PAGE_NEWS , & Button , CUI : : CORNER_T ) )
2014-06-16 11:29:18 +00:00
{
2014-06-05 10:11:41 +00:00
NewPage = PAGE_NEWS ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
}
2014-06-05 10:11:41 +00:00
Box . VSplitLeft ( 10.0f , 0 , & Box ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
static int s_InternetButton = 0 ;
if ( DoButton_MenuTab ( & s_InternetButton , Localize ( " Internet " ) , m_ActivePage = = PAGE_INTERNET , & Button , CUI : : CORNER_TL ) )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_INTERNET ) ;
NewPage = PAGE_INTERNET ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
//Box.VSplitLeft(4.0f, 0, &Box);
2014-06-05 10:11:41 +00:00
Box . VSplitLeft ( 70.0f , & Button , & Box ) ;
2010-05-29 07:25:38 +00:00
static int s_LanButton = 0 ;
if ( DoButton_MenuTab ( & s_LanButton , Localize ( " LAN " ) , m_ActivePage = = PAGE_LAN , & Button , 0 ) )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_LAN ) ;
NewPage = PAGE_LAN ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2008-08-27 15:48:50 +00:00
}
2009-10-27 14:38:53 +00:00
//box.VSplitLeft(4.0f, 0, &box);
2010-05-29 07:25:38 +00:00
Box . VSplitLeft ( 110.0f , & Button , & Box ) ;
static int s_FavoritesButton = 0 ;
if ( DoButton_MenuTab ( & s_FavoritesButton , Localize ( " Favorites " ) , m_ActivePage = = PAGE_FAVORITES , & Button , CUI : : CORNER_TR ) )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_FAVORITES ) ;
2011-04-13 18:37:12 +00:00
NewPage = PAGE_FAVORITES ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2014-06-05 10:11:41 +00:00
Box . VSplitLeft ( 10.0f , 0 , & Box ) ;
2010-05-29 07:25:38 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
static int s_DemosButton = 0 ;
if ( DoButton_MenuTab ( & s_DemosButton , Localize ( " Demos " ) , m_ActivePage = = PAGE_DEMOS , & Button , CUI : : CORNER_T ) )
2008-10-06 18:05:01 +00:00
{
2010-05-29 07:25:38 +00:00
DemolistPopulate ( ) ;
2011-04-13 18:37:12 +00:00
NewPage = PAGE_DEMOS ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2011-04-13 18:37:12 +00:00
}
2008-08-27 15:48:50 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
// online menus
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
static int s_GameButton = 0 ;
2011-04-06 18:18:31 +00:00
if ( DoButton_MenuTab ( & s_GameButton , Localize ( " Game " ) , m_ActivePage = = PAGE_GAME , & Button , CUI : : CORNER_TL ) )
2010-05-29 07:25:38 +00:00
NewPage = PAGE_GAME ;
2011-04-06 18:18:31 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
static int s_PlayersButton = 0 ;
if ( DoButton_MenuTab ( & s_PlayersButton , Localize ( " Players " ) , m_ActivePage = = PAGE_PLAYERS , & Button , 0 ) )
NewPage = PAGE_PLAYERS ;
Box . VSplitLeft ( 130.0f , & Button , & Box ) ;
2010-05-29 07:25:38 +00:00
static int s_ServerInfoButton = 0 ;
2011-04-06 18:18:31 +00:00
if ( DoButton_MenuTab ( & s_ServerInfoButton , Localize ( " Server info " ) , m_ActivePage = = PAGE_SERVER_INFO , & Button , 0 ) )
2010-05-29 07:25:38 +00:00
NewPage = PAGE_SERVER_INFO ;
2011-02-16 08:11:00 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
static int s_GhostButton = 0 ;
2013-10-10 10:10:10 +00:00
if ( DoButton_MenuTab ( & s_GhostButton , " Network " , m_ActivePage = = PAGE_DDRace , & Button , 0 ) )
2011-02-23 07:33:21 +00:00
NewPage = PAGE_DDRace ;
2010-05-29 07:25:38 +00:00
2011-04-09 20:45:34 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2010-05-29 07:25:38 +00:00
Box . VSplitLeft ( 4.0f , 0 , & Box ) ;
static int s_CallVoteButton = 0 ;
2011-04-06 18:18:31 +00:00
if ( DoButton_MenuTab ( & s_CallVoteButton , Localize ( " Call vote " ) , m_ActivePage = = PAGE_CALLVOTE , & Button , CUI : : CORNER_TR ) )
2010-05-29 07:25:38 +00:00
NewPage = PAGE_CALLVOTE ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
/*
2009-10-27 14:38:53 +00:00
box . VSplitRight ( 110.0f , & box , & button ) ;
2008-08-27 15:48:50 +00:00
static int system_button = 0 ;
2010-05-29 07:25:38 +00:00
if ( UI ( ) - > DoButton ( & system_button , " System " , g_Config . m_UiPage = = PAGE_SYSTEM , & button ) )
g_Config . m_UiPage = PAGE_SYSTEM ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
box . VSplitRight ( 30.0f , & box , 0 ) ;
2008-08-27 15:48:50 +00:00
*/
2011-04-13 18:37:12 +00:00
2014-07-08 18:21:19 +00:00
Box . VSplitRight ( 30.0f , & Box , & Button ) ;
2010-05-29 07:25:38 +00:00
static int s_QuitButton = 0 ;
2014-07-08 18:21:19 +00:00
if ( DoButton_MenuTab ( & s_QuitButton , " × " , 0 , & Button , CUI : : CORNER_T ) )
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_QUIT ;
2014-05-08 12:08:15 +00:00
Box . VSplitRight ( 10.0f , & Box , & Button ) ;
2014-07-08 18:21:19 +00:00
Box . VSplitRight ( 30.0f , & Box , & Button ) ;
2010-05-29 07:25:38 +00:00
static int s_SettingsButton = 0 ;
2014-07-08 18:21:19 +00:00
if ( DoButton_MenuTab ( & s_SettingsButton , " ⚙ " , m_ActivePage = = PAGE_SETTINGS , & Button , CUI : : CORNER_T ) )
2010-05-29 07:25:38 +00:00
NewPage = PAGE_SETTINGS ;
2011-04-13 18:37:12 +00:00
2014-07-08 18:21:19 +00:00
Box . VSplitRight ( 10.0f , & Box , & Button ) ;
Box . VSplitRight ( 30.0f , & Box , & Button ) ;
static int s_EditorButton = 0 ;
if ( DoButton_MenuTab ( & s_EditorButton , Localize ( " ✎ " ) , 0 , & Button , CUI : : CORNER_T ) )
{
g_Config . m_ClEditor = 1 ;
}
2010-05-29 07:25:38 +00:00
if ( NewPage ! = - 1 )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE )
g_Config . m_UiPage = NewPage ;
2008-08-27 15:48:50 +00:00
else
2010-05-29 07:25:38 +00:00
m_GamePage = NewPage ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
return 0 ;
}
2011-02-27 16:56:03 +00:00
void CMenus : : RenderLoading ( )
2008-08-27 15:48:50 +00:00
{
2011-12-30 15:02:22 +00:00
// TODO: not supported right now due to separate render thread
2010-05-29 07:25:38 +00:00
static int64 LastLoadRender = 0 ;
2011-02-27 16:56:03 +00:00
float Percent = m_LoadCurrent + + / ( float ) m_LoadTotal ;
2009-06-07 14:36:54 +00:00
// make sure that we don't render for each little thing we load
// because that will slow down loading if we have vsync
2010-05-29 07:25:38 +00:00
if ( time_get ( ) - LastLoadRender < time_freq ( ) / 60 )
2009-06-07 14:36:54 +00:00
return ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
LastLoadRender = time_get ( ) ;
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// need up date this here to get correct
2010-05-29 07:25:38 +00:00
vec3 Rgb = HslToRgb ( vec3 ( g_Config . m_UiColorHue / 255.0f , g_Config . m_UiColorSat / 255.0f , g_Config . m_UiColorLht / 255.0f ) ) ;
ms_GuiColor = vec4 ( Rgb . r , Rgb . g , Rgb . b , g_Config . m_UiColorAlpha / 255.0f ) ;
2011-04-13 18:37:12 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ;
2010-12-14 00:20:47 +00:00
2010-05-29 07:25:38 +00:00
RenderBackground ( ) ;
2008-08-27 15:48:50 +00:00
float w = 700 ;
float h = 200 ;
2010-05-29 07:25:38 +00:00
float x = Screen . w / 2 - w / 2 ;
float y = Screen . h / 2 - h / 2 ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
Graphics ( ) - > BlendNormal ( ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.50f ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawRoundRect ( x , y , w , h , 40.0f ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-08-27 15:48:50 +00:00
2014-01-03 02:06:23 +00:00
const char * pCaption = Localize ( " Loading DDNet Client " ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
CUIRect r ;
2008-08-27 15:48:50 +00:00
r . x = x ;
r . y = y + 20 ;
r . w = w ;
r . h = h ;
2010-05-29 07:25:38 +00:00
UI ( ) - > DoLabel ( & r , pCaption , 48.0f , 0 , - 1 ) ;
2008-08-27 15:48:50 +00:00
2009-10-27 14:38:53 +00:00
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 0.75f ) ;
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawRoundRect ( x + 40 , y + h - 75 , ( w - 80 ) * Percent , 25 , 5.0f ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
Graphics ( ) - > Swap ( ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : RenderNews ( CUIRect MainView )
2008-08-27 15:48:50 +00:00
{
2014-06-05 10:11:41 +00:00
// TODO: Like the settings with big fonts
// Make it work WITHOUT version updates
// Show news once after each version or news update
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & MainView , ms_ColorTabbarActive , CUI : : CORNER_ALL , 10.0f ) ;
2014-06-05 10:11:41 +00:00
MainView . HSplitTop ( 15.0f , 0 , & MainView ) ;
MainView . VSplitLeft ( 15.0f , 0 , & MainView ) ;
CUIRect Label ;
std : : istringstream f ( Client ( ) - > m_aNews ) ;
std : : string line ;
while ( std : : getline ( f , line ) )
{
if ( line . size ( ) > 0 & & line . at ( 0 ) = = ' | ' & & line . at ( line . size ( ) - 1 ) = = ' | ' )
{
MainView . HSplitTop ( 30.0f , & Label , & MainView ) ;
UI ( ) - > DoLabelScaled ( & Label , Localize ( line . substr ( 1 , line . size ( ) - 2 ) . c_str ( ) ) , 20.0f , - 1 ) ;
}
else
{
MainView . HSplitTop ( 20.0f , & Label , & MainView ) ;
UI ( ) - > DoLabelScaled ( & Label , line . c_str ( ) , 15.f , - 1 , MainView . w - 30.0f ) ;
}
}
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : OnInit ( )
2008-08-27 15:48:50 +00:00
{
2009-06-13 16:54:04 +00:00
/*
array < string > my_strings ;
array < string > : : range r2 ;
my_strings . add ( " 4 " ) ;
my_strings . add ( " 6 " ) ;
my_strings . add ( " 1 " ) ;
my_strings . add ( " 3 " ) ;
my_strings . add ( " 7 " ) ;
my_strings . add ( " 5 " ) ;
my_strings . add ( " 2 " ) ;
for ( array < string > : : range r = my_strings . all ( ) ; ! r . empty ( ) ; r . pop_front ( ) )
dbg_msg ( " " , " %s " , r . front ( ) . cstr ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
sort ( my_strings . all ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
dbg_msg ( " " , " after: " ) ;
for ( array < string > : : range r = my_strings . all ( ) ; ! r . empty ( ) ; r . pop_front ( ) )
dbg_msg ( " " , " %s " , r . front ( ) . cstr ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
array < int > myarray ;
myarray . add ( 4 ) ;
myarray . add ( 6 ) ;
myarray . add ( 1 ) ;
myarray . add ( 3 ) ;
myarray . add ( 7 ) ;
myarray . add ( 5 ) ;
myarray . add ( 2 ) ;
for ( array < int > : : range r = myarray . all ( ) ; ! r . empty ( ) ; r . pop_front ( ) )
dbg_msg ( " " , " %d " , r . front ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
sort ( myarray . all ( ) ) ;
sort_verify ( myarray . all ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
dbg_msg ( " " , " after: " ) ;
for ( array < int > : : range r = myarray . all ( ) ; ! r . empty ( ) ; r . pop_front ( ) )
dbg_msg ( " " , " %d " , r . front ( ) ) ;
2011-04-13 18:37:12 +00:00
2009-06-13 16:54:04 +00:00
exit ( - 1 ) ;
// */
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( g_Config . m_ClShowWelcome )
2014-02-15 00:19:07 +00:00
{
2010-12-12 18:20:30 +00:00
m_Popup = POPUP_LANGUAGE ;
2014-02-15 00:19:07 +00:00
str_copy ( g_Config . m_BrFilterString , " DDraceNetwork " , sizeof ( g_Config . m_BrFilterString ) ) ;
}
2010-05-29 07:25:38 +00:00
g_Config . m_ClShowWelcome = 0 ;
2010-07-04 14:10:00 +00:00
Console ( ) - > Chain ( " add_favorite " , ConchainServerbrowserUpdate , this ) ;
2011-03-27 16:05:11 +00:00
Console ( ) - > Chain ( " remove_favorite " , ConchainServerbrowserUpdate , this ) ;
2011-06-26 15:10:13 +00:00
Console ( ) - > Chain ( " add_friend " , ConchainFriendlistUpdate , this ) ;
Console ( ) - > Chain ( " remove_friend " , ConchainFriendlistUpdate , this ) ;
2011-02-27 16:56:03 +00:00
// setup load amount
m_LoadCurrent = 0 ;
m_LoadTotal = g_pData - > m_NumImages ;
if ( ! g_Config . m_ClThreadsoundloading )
m_LoadTotal + = g_pData - > m_NumSounds ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : PopupMessage ( const char * pTopic , const char * pBody , const char * pButton )
2009-06-15 13:16:33 +00:00
{
2010-06-03 20:03:27 +00:00
// reset active item
UI ( ) - > SetActiveItem ( 0 ) ;
2010-05-29 07:25:38 +00:00
str_copy ( m_aMessageTopic , pTopic , sizeof ( m_aMessageTopic ) ) ;
str_copy ( m_aMessageBody , pBody , sizeof ( m_aMessageBody ) ) ;
str_copy ( m_aMessageButton , pButton , sizeof ( m_aMessageButton ) ) ;
m_Popup = POPUP_MESSAGE ;
2009-06-15 13:16:33 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : Render ( )
2008-08-27 15:48:50 +00:00
{
2011-04-13 18:37:12 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2010-05-29 07:25:38 +00:00
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
static bool s_First = true ;
if ( s_First )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( g_Config . m_UiPage = = PAGE_INTERNET )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_INTERNET ) ;
else if ( g_Config . m_UiPage = = PAGE_LAN )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_LAN ) ;
else if ( g_Config . m_UiPage = = PAGE_FAVORITES )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_FAVORITES ) ;
2011-04-13 18:00:54 +00:00
m_pClient - > m_pSounds - > Enqueue ( CSounds : : CHN_MUSIC , SOUND_MENU ) ;
2010-05-29 07:25:38 +00:00
s_First = false ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2010-10-25 18:09:08 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_ONLINE )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame ;
ms_ColorTabbarActive = ms_ColorTabbarActiveIngame ;
2008-08-27 15:48:50 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
RenderBackground ( ) ;
ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame ;
ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
CUIRect TabBar ;
CUIRect MainView ;
2008-08-27 15:48:50 +00:00
// some margin around the screen
2010-05-29 07:25:38 +00:00
Screen . Margin ( 10.0f , & Screen ) ;
2011-04-13 18:37:12 +00:00
2011-01-17 12:28:15 +00:00
static bool s_SoundCheck = false ;
if ( ! s_SoundCheck & & m_Popup = = POPUP_NONE )
{
if ( Client ( ) - > SoundInitFailed ( ) )
m_Popup = POPUP_SOUNDERROR ;
s_SoundCheck = true ;
}
2010-05-29 07:25:38 +00:00
if ( m_Popup = = POPUP_NONE )
2008-08-27 15:48:50 +00:00
{
// do tab bar
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Screen . HSplitTop ( 100.0f , & TabBar , & MainView ) ;
# else
2010-05-29 07:25:38 +00:00
Screen . HSplitTop ( 24.0f , & TabBar , & MainView ) ;
2014-06-16 11:29:18 +00:00
# endif
2014-05-08 12:08:15 +00:00
TabBar . VMargin ( 20.0f , & TabBar ) ;
2010-05-29 07:25:38 +00:00
RenderMenubar ( TabBar ) ;
2011-04-13 18:37:12 +00:00
2008-11-17 18:44:05 +00:00
// news is not implemented yet
2014-06-05 10:11:41 +00:00
if ( g_Config . m_UiPage < PAGE_NEWS | | g_Config . m_UiPage > PAGE_SETTINGS | | ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE & & g_Config . m_UiPage > = PAGE_GAME & & g_Config . m_UiPage < = PAGE_CALLVOTE ) )
2008-10-01 18:40:09 +00:00
{
2010-05-29 07:25:38 +00:00
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_INTERNET ) ;
g_Config . m_UiPage = PAGE_INTERNET ;
2014-06-16 11:29:18 +00:00
m_DoubleClickIndex = - 1 ;
2008-10-01 18:40:09 +00:00
}
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// render current page
2010-10-25 18:09:08 +00:00
if ( Client ( ) - > State ( ) ! = IClient : : STATE_OFFLINE )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( m_GamePage = = PAGE_GAME )
RenderGame ( MainView ) ;
2011-04-06 18:18:31 +00:00
else if ( m_GamePage = = PAGE_PLAYERS )
RenderPlayers ( MainView ) ;
2010-05-29 07:25:38 +00:00
else if ( m_GamePage = = PAGE_SERVER_INFO )
RenderServerInfo ( MainView ) ;
2011-04-09 20:45:34 +00:00
else if ( m_GamePage = = PAGE_DDRace )
RenderInGameDDRace ( MainView ) ;
2010-05-29 07:25:38 +00:00
else if ( m_GamePage = = PAGE_CALLVOTE )
RenderServerControl ( MainView ) ;
else if ( m_GamePage = = PAGE_SETTINGS )
RenderSettings ( MainView ) ;
2011-02-23 07:33:21 +00:00
else if ( m_GamePage = = PAGE_GHOST )
RenderGhost ( MainView ) ;
else if ( m_GamePage = = PAGE_BROWSER )
RenderInGameBrowser ( MainView ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( g_Config . m_UiPage = = PAGE_NEWS )
RenderNews ( MainView ) ;
else if ( g_Config . m_UiPage = = PAGE_INTERNET )
RenderServerbrowser ( MainView ) ;
else if ( g_Config . m_UiPage = = PAGE_LAN )
RenderServerbrowser ( MainView ) ;
else if ( g_Config . m_UiPage = = PAGE_DEMOS )
RenderDemoList ( MainView ) ;
else if ( g_Config . m_UiPage = = PAGE_FAVORITES )
RenderServerbrowser ( MainView ) ;
else if ( g_Config . m_UiPage = = PAGE_SETTINGS )
RenderSettings ( MainView ) ;
2008-08-27 15:48:50 +00:00
}
else
{
// make sure that other windows doesn't do anything funnay!
2009-10-27 14:38:53 +00:00
//UI()->SetHotItem(0);
//UI()->SetActiveItem(0);
2010-09-27 19:41:41 +00:00
char aBuf [ 128 ] ;
2010-05-29 07:25:38 +00:00
const char * pTitle = " " ;
const char * pExtraText = " " ;
const char * pButtonText = " " ;
int ExtraAlign = 0 ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( m_Popup = = POPUP_MESSAGE )
2009-06-15 13:16:33 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = m_aMessageTopic ;
pExtraText = m_aMessageBody ;
pButtonText = m_aMessageButton ;
2009-06-15 13:16:33 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_CONNECTING )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = Localize ( " Connecting to " ) ;
2011-04-13 18:37:12 +00:00
pExtraText = g_Config . m_UiServerAddress ; // TODO: query the client about the address
2010-05-29 07:25:38 +00:00
pButtonText = Localize ( " Abort " ) ;
if ( Client ( ) - > MapDownloadTotalsize ( ) > 0 )
2008-08-27 15:48:50 +00:00
{
2014-08-15 23:06:17 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s: %s " , Localize ( " Downloading map " ) , Client ( ) - > MapDownloadName ( ) ) ;
pTitle = aBuf ;
2010-12-16 00:52:29 +00:00
pExtraText = " " ;
2008-08-27 15:48:50 +00:00
}
}
2014-06-26 22:28:57 +00:00
else if ( m_Popup = = POPUP_DISCONNECTED )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = Localize ( " Disconnected " ) ;
pExtraText = Client ( ) - > ErrorString ( ) ;
pButtonText = Localize ( " Ok " ) ;
2014-06-26 22:28:57 +00:00
if ( ( str_find_nocase ( Client ( ) - > ErrorString ( ) , " full " ) ) | | ( str_find_nocase ( Client ( ) - > ErrorString ( ) , " reserved " ) ) )
{
2014-06-27 08:13:57 +00:00
if ( g_Config . m_ClReconnectFull )
2014-06-26 22:28:57 +00:00
{
if ( _my_rtime = = 0 )
_my_rtime = time_get ( ) ;
2014-06-27 08:13:57 +00:00
str_format ( aBuf , sizeof ( aBuf ) , Localize ( " \n \n Reconnect in %d sec " ) , ( ( _my_rtime - time_get ( ) ) / time_freq ( ) + g_Config . m_ClReconnectFullTimeout ) ) ;
2014-06-26 22:28:57 +00:00
pTitle = Client ( ) - > ErrorString ( ) ;
pExtraText = aBuf ;
pButtonText = Localize ( " Abort " ) ;
}
}
else if ( str_find_nocase ( Client ( ) - > ErrorString ( ) , " ban " ) )
{
2014-06-27 08:13:57 +00:00
if ( g_Config . m_ClReconnectBan )
2014-06-26 22:28:57 +00:00
{
if ( _my_rtime = = 0 )
_my_rtime = time_get ( ) ;
2014-06-27 08:13:57 +00:00
str_format ( aBuf , sizeof ( aBuf ) , Localize ( " \n \n Reconnect in %d sec " ) , ( ( _my_rtime - time_get ( ) ) / time_freq ( ) + g_Config . m_ClReconnectBanTimeout ) ) ;
2014-06-26 22:28:57 +00:00
pTitle = Client ( ) - > ErrorString ( ) ;
pExtraText = aBuf ;
pButtonText = Localize ( " Abort " ) ;
}
}
ExtraAlign = 0 ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_PURE )
2009-01-11 10:40:14 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = Localize ( " Disconnected " ) ;
pExtraText = Localize ( " The server is running a non-standard tuning on a pure game type. " ) ;
pButtonText = Localize ( " Ok " ) ;
ExtraAlign = - 1 ;
2009-01-11 10:40:14 +00:00
}
2010-09-05 15:53:31 +00:00
else if ( m_Popup = = POPUP_DELETE_DEMO )
{
pTitle = Localize ( " Delete demo " ) ;
pExtraText = Localize ( " Are you sure that you want to delete the demo? " ) ;
ExtraAlign = - 1 ;
}
2011-03-12 18:08:44 +00:00
else if ( m_Popup = = POPUP_RENAME_DEMO )
{
pTitle = Localize ( " Rename demo " ) ;
pExtraText = " " ;
ExtraAlign = - 1 ;
}
2011-03-23 12:06:35 +00:00
else if ( m_Popup = = POPUP_REMOVE_FRIEND )
{
pTitle = Localize ( " Remove friend " ) ;
pExtraText = Localize ( " Are you sure that you want to remove the player from your friends list? " ) ;
ExtraAlign = - 1 ;
}
2011-01-17 12:28:15 +00:00
else if ( m_Popup = = POPUP_SOUNDERROR )
{
pTitle = Localize ( " Sound error " ) ;
pExtraText = Localize ( " The audio device couldn't be initialised. " ) ;
pButtonText = Localize ( " Ok " ) ;
ExtraAlign = - 1 ;
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_PASSWORD )
2008-08-27 15:48:50 +00:00
{
2010-06-02 19:03:15 +00:00
pTitle = Localize ( " Password incorrect " ) ;
2010-11-20 22:39:17 +00:00
pExtraText = " " ;
2010-05-29 07:25:38 +00:00
pButtonText = Localize ( " Try again " ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_QUIT )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = Localize ( " Quit " ) ;
pExtraText = Localize ( " Are you sure that you want to quit? " ) ;
2011-03-21 23:31:42 +00:00
ExtraAlign = - 1 ;
2008-08-27 15:48:50 +00:00
}
2014-07-08 18:21:19 +00:00
else if ( m_Popup = = POPUP_DISCONNECT )
{
pTitle = Localize ( " Disconnect " ) ;
pExtraText = Localize ( " Are you sure that you want to disconnect? " ) ;
ExtraAlign = - 1 ;
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_FIRST_LAUNCH )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
pTitle = Localize ( " Welcome to Teeworlds " ) ;
pExtraText = Localize ( " As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server. " ) ;
pButtonText = Localize ( " Ok " ) ;
ExtraAlign = - 1 ;
2008-08-27 15:48:50 +00:00
}
2014-06-16 11:29:18 +00:00
# if !defined(CONF_PLATFORM_MACOSX) && !defined(__ANDROID__)
2014-05-17 12:28:50 +00:00
else if ( m_Popup = = POPUP_AUTOUPDATE )
{
pTitle = Localize ( " Auto-Update " ) ;
pExtraText = Localize ( " An update to DDNet client is available. Do you want to update now? This may restart the client. If an update fails, make sure the client has permissions to modify files. " ) ;
ExtraAlign = - 1 ;
}
2014-05-17 17:30:24 +00:00
# endif
2011-04-13 18:37:12 +00:00
2010-09-27 19:41:41 +00:00
CUIRect Box , Part ;
2010-05-29 07:25:38 +00:00
Box = Screen ;
2010-12-14 00:20:47 +00:00
Box . VMargin ( 150.0f / UI ( ) - > Scale ( ) , & Box ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HMargin ( 100.0f / UI ( ) - > Scale ( ) , & Box ) ;
# else
2010-12-14 00:20:47 +00:00
Box . HMargin ( 150.0f / UI ( ) - > Scale ( ) , & Box ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// render the box
2010-05-29 07:25:38 +00:00
RenderTools ( ) - > DrawUIRect ( & Box , vec4 ( 0 , 0 , 0 , 0.5f ) , CUI : : CORNER_ALL , 15.0f ) ;
2011-04-13 18:37:12 +00:00
2010-12-14 00:20:47 +00:00
Box . HSplitTop ( 20.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
Box . HSplitTop ( 24.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
UI ( ) - > DoLabelScaled ( & Part , pTitle , 24.f , 0 ) ;
Box . HSplitTop ( 20.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
Box . HSplitTop ( 24.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
Part . VMargin ( 20.f / UI ( ) - > Scale ( ) , & Part ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( ExtraAlign = = - 1 )
2010-12-14 00:20:47 +00:00
UI ( ) - > DoLabelScaled ( & Part , pExtraText , 20.f , - 1 , ( int ) Part . w ) ;
2008-08-27 15:48:50 +00:00
else
2010-12-14 00:20:47 +00:00
UI ( ) - > DoLabelScaled ( & Part , pExtraText , 20.f , 0 , - 1 ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
if ( m_Popup = = POPUP_QUIT )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-03-21 23:31:42 +00:00
// additional info
Box . HSplitTop ( 10.0f , 0 , & Box ) ;
Box . VMargin ( 20.f / UI ( ) - > Scale ( ) , & Box ) ;
if ( m_pClient - > Editor ( ) - > HasUnsavedData ( ) )
2011-04-02 10:08:46 +00:00
{
2011-04-20 08:21:39 +00:00
char aBuf [ 256 ] ;
2011-04-02 10:08:46 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s \n %s " , Localize ( " There's an unsaved map in the editor, you might want to save it before you quit the game. " ) , Localize ( " Quit anyway? " ) ) ;
UI ( ) - > DoLabelScaled ( & Box , aBuf , 20.f , - 1 , Part . w - 20.0f ) ;
}
2011-03-21 23:31:42 +00:00
// buttons
2010-05-29 07:25:38 +00:00
Part . VMargin ( 80.0f , & Part ) ;
Part . VSplitMid ( & No , & Yes ) ;
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
Client ( ) - > Quit ( ) ;
2008-08-27 15:48:50 +00:00
}
2014-07-08 19:04:04 +00:00
else if ( m_Popup = = POPUP_DISCONNECT )
2014-07-08 18:21:19 +00:00
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
# endif
// buttons
Part . VMargin ( 80.0f , & Part ) ;
Part . VSplitMid ( & No , & Yes ) ;
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
Client ( ) - > Disconnect ( ) ;
}
2014-06-16 11:29:18 +00:00
# if !defined(CONF_PLATFORM_MACOSX) && !defined(__ANDROID__)
2014-05-17 12:28:50 +00:00
else if ( m_Popup = = POPUP_AUTOUPDATE )
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
// buttons
Part . VMargin ( 80.0f , & Part ) ;
Part . VSplitMid ( & No , & Yes ) ;
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
m_pClient - > AutoUpdate ( ) - > DoUpdates ( this ) ;
}
2014-05-17 17:30:24 +00:00
# endif
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_PASSWORD )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Label , TextBox , TryAgain , Abort ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-05-29 07:25:38 +00:00
Part . VMargin ( 80.0f , & Part ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Part . VSplitMid ( & Abort , & TryAgain ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
TryAgain . VMargin ( 20.0f , & TryAgain ) ;
Abort . VMargin ( 20.0f , & Abort ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " Abort " ) , 0 , & Abort ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Try again " ) , 0 , & TryAgain ) | | m_EnterPressed )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
Client ( ) - > Connect ( g_Config . m_UiServerAddress ) ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Part . VSplitLeft ( 60.0f , 0 , & Label ) ;
Label . VSplitLeft ( 100.0f , 0 , & TextBox ) ;
TextBox . VSplitLeft ( 20.0f , 0 , & TextBox ) ;
TextBox . VSplitRight ( 60.0f , & TextBox , 0 ) ;
UI ( ) - > DoLabel ( & Label , Localize ( " Password " ) , 18.0f , - 1 ) ;
2010-05-29 15:53:57 +00:00
static float Offset = 0.0f ;
DoEditBox ( & g_Config . m_Password , & TextBox , g_Config . m_Password , sizeof ( g_Config . m_Password ) , 12.0f , & Offset , true ) ;
2008-08-27 15:48:50 +00:00
}
2010-12-16 00:52:29 +00:00
else if ( m_Popup = = POPUP_CONNECTING )
{
Box = Screen ;
Box . VMargin ( 150.0f , & Box ) ;
Box . HMargin ( 150.0f , & Box ) ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-12-16 00:52:29 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-12-16 00:52:29 +00:00
Part . VMargin ( 120.0f , & Part ) ;
static int s_Button = 0 ;
if ( DoButton_Menu ( & s_Button , pButtonText , 0 , & Part ) | | m_EscapePressed | | m_EnterPressed )
{
Client ( ) - > Disconnect ( ) ;
m_Popup = POPUP_NONE ;
}
if ( Client ( ) - > MapDownloadTotalsize ( ) > 0 )
{
int64 Now = time_get ( ) ;
if ( Now - m_DownloadLastCheckTime > = time_freq ( ) )
{
if ( m_DownloadLastCheckSize > Client ( ) - > MapDownloadAmount ( ) )
{
// map downloaded restarted
m_DownloadLastCheckSize = 0 ;
}
// update download speed
2012-04-20 20:11:41 +00:00
float Diff = ( Client ( ) - > MapDownloadAmount ( ) - m_DownloadLastCheckSize ) / ( ( int ) ( ( Now - m_DownloadLastCheckTime ) / time_freq ( ) ) ) ;
2011-04-12 16:59:08 +00:00
float StartDiff = m_DownloadLastCheckSize - 0.0f ;
if ( StartDiff + Diff > 0.0f )
m_DownloadSpeed = ( Diff / ( StartDiff + Diff ) ) * ( Diff / 1.0f ) + ( StartDiff / ( Diff + StartDiff ) ) * m_DownloadSpeed ;
else
m_DownloadSpeed = 0.0f ;
2010-12-16 00:52:29 +00:00
m_DownloadLastCheckTime = Now ;
m_DownloadLastCheckSize = Client ( ) - > MapDownloadAmount ( ) ;
}
Box . HSplitTop ( 64.f , 0 , & Box ) ;
Box . HSplitTop ( 24.f , & Part , & Box ) ;
2011-04-12 16:59:08 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d/%d KiB (%.1f KiB/s) " , Client ( ) - > MapDownloadAmount ( ) / 1024 , Client ( ) - > MapDownloadTotalsize ( ) / 1024 , m_DownloadSpeed / 1024.0f ) ;
2010-12-16 00:52:29 +00:00
UI ( ) - > DoLabel ( & Part , aBuf , 20.f , 0 , - 1 ) ;
2011-04-13 18:37:12 +00:00
2010-12-16 00:52:29 +00:00
// time left
const char * pTimeLeftString ;
2011-06-27 20:35:23 +00:00
int TimeLeft = max ( 1 , m_DownloadSpeed > 0.0f ? static_cast < int > ( ( Client ( ) - > MapDownloadTotalsize ( ) - Client ( ) - > MapDownloadAmount ( ) ) / m_DownloadSpeed ) : 1 ) ;
2010-12-16 00:52:29 +00:00
if ( TimeLeft > = 60 )
{
TimeLeft / = 60 ;
2011-01-05 16:28:53 +00:00
pTimeLeftString = TimeLeft = = 1 ? Localize ( " %i minute left " ) : Localize ( " %i minutes left " ) ;
2010-12-16 00:52:29 +00:00
}
else
2011-01-05 16:28:53 +00:00
pTimeLeftString = TimeLeft = = 1 ? Localize ( " %i second left " ) : Localize ( " %i seconds left " ) ;
2010-12-16 00:52:29 +00:00
Box . HSplitTop ( 20.f , 0 , & Box ) ;
Box . HSplitTop ( 24.f , & Part , & Box ) ;
2011-01-05 16:28:53 +00:00
str_format ( aBuf , sizeof ( aBuf ) , pTimeLeftString , TimeLeft ) ;
2010-12-16 00:52:29 +00:00
UI ( ) - > DoLabel ( & Part , aBuf , 20.f , 0 , - 1 ) ;
// progress bar
Box . HSplitTop ( 20.f , 0 , & Box ) ;
Box . HSplitTop ( 24.f , & Part , & Box ) ;
Part . VMargin ( 40.0f , & Part ) ;
RenderTools ( ) - > DrawUIRect ( & Part , vec4 ( 1.0f , 1.0f , 1.0f , 0.25f ) , CUI : : CORNER_ALL , 5.0f ) ;
Part . w = max ( 10.0f , ( Part . w * Client ( ) - > MapDownloadAmount ( ) ) / Client ( ) - > MapDownloadTotalsize ( ) ) ;
RenderTools ( ) - > DrawUIRect ( & Part , vec4 ( 1.0f , 1.0f , 1.0f , 0.5f ) , CUI : : CORNER_ALL , 5.0f ) ;
}
}
2010-12-12 18:20:30 +00:00
else if ( m_Popup = = POPUP_LANGUAGE )
{
Box = Screen ;
Box . VMargin ( 150.0f , & Box ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HMargin ( 20.0f , & Box ) ;
# else
2010-12-12 18:20:30 +00:00
Box . HMargin ( 150.0f , & Box ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-12-12 18:20:30 +00:00
Box . HSplitTop ( 20.f , & Part , & Box ) ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-12-12 18:20:30 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-12-12 18:20:30 +00:00
Box . HSplitBottom ( 20.f , & Box , 0 ) ;
Box . VMargin ( 20.0f , & Box ) ;
RenderLanguageSelection ( Box ) ;
Part . VMargin ( 120.0f , & Part ) ;
static int s_Button = 0 ;
if ( DoButton_Menu ( & s_Button , Localize ( " Ok " ) , 0 , & Part ) | | m_EscapePressed | | m_EnterPressed )
m_Popup = POPUP_FIRST_LAUNCH ;
}
2011-06-29 20:27:32 +00:00
else if ( m_Popup = = POPUP_COUNTRY )
{
Box = Screen ;
Box . VMargin ( 150.0f , & Box ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HMargin ( 20.0f , & Box ) ;
# else
2011-06-29 20:27:32 +00:00
Box . HMargin ( 150.0f , & Box ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-06-29 20:27:32 +00:00
Box . HSplitTop ( 20.f , & Part , & Box ) ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2011-06-29 20:27:32 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-06-29 20:27:32 +00:00
Box . HSplitBottom ( 20.f , & Box , 0 ) ;
Box . VMargin ( 20.0f , & Box ) ;
2011-08-11 08:59:14 +00:00
2011-06-29 20:27:32 +00:00
static int ActSelection = - 2 ;
if ( ActSelection = = - 2 )
ActSelection = g_Config . m_BrFilterCountryIndex ;
static float s_ScrollValue = 0.0f ;
int OldSelected = - 1 ;
UiDoListboxStart ( & s_ScrollValue , & Box , 50.0f , Localize ( " Country " ) , " " , m_pClient - > m_pCountryFlags - > Num ( ) , 6 , OldSelected , s_ScrollValue ) ;
for ( int i = 0 ; i < m_pClient - > m_pCountryFlags - > Num ( ) ; + + i )
{
const CCountryFlags : : CCountryFlag * pEntry = m_pClient - > m_pCountryFlags - > GetByIndex ( i ) ;
if ( pEntry - > m_CountryCode = = ActSelection )
OldSelected = i ;
CListboxItem Item = UiDoListboxNextItem ( & pEntry - > m_CountryCode , OldSelected = = i ) ;
if ( Item . m_Visible )
{
2011-07-31 00:04:46 +00:00
CUIRect Label ;
Item . m_Rect . Margin ( 5.0f , & Item . m_Rect ) ;
Item . m_Rect . HSplitBottom ( 10.0f , & Item . m_Rect , & Label ) ;
2011-06-29 20:27:32 +00:00
float OldWidth = Item . m_Rect . w ;
Item . m_Rect . w = Item . m_Rect . h * 2 ;
Item . m_Rect . x + = ( OldWidth - Item . m_Rect . w ) / 2.0f ;
2012-01-08 17:16:38 +00:00
vec4 Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
m_pClient - > m_pCountryFlags - > Render ( pEntry - > m_CountryCode , & Color , Item . m_Rect . x , Item . m_Rect . y , Item . m_Rect . w , Item . m_Rect . h ) ;
2011-07-31 00:04:46 +00:00
UI ( ) - > DoLabel ( & Label , pEntry - > m_aCountryCodeString , 10.0f , 0 ) ;
2011-06-29 20:27:32 +00:00
}
}
const int NewSelected = UiDoListboxEnd ( & s_ScrollValue , 0 ) ;
if ( OldSelected ! = NewSelected )
ActSelection = m_pClient - > m_pCountryFlags - > GetByIndex ( NewSelected ) - > m_CountryCode ;
Part . VMargin ( 120.0f , & Part ) ;
static int s_Button = 0 ;
if ( DoButton_Menu ( & s_Button , Localize ( " Ok " ) , 0 , & Part ) | | m_EnterPressed )
{
g_Config . m_BrFilterCountryIndex = ActSelection ;
Client ( ) - > ServerBrowserUpdate ( ) ;
m_Popup = POPUP_NONE ;
}
if ( m_EscapePressed )
{
ActSelection = g_Config . m_BrFilterCountryIndex ;
m_Popup = POPUP_NONE ;
}
}
2010-09-05 15:53:31 +00:00
else if ( m_Popup = = POPUP_DELETE_DEMO )
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-09-05 15:53:31 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-09-05 15:53:31 +00:00
Part . VMargin ( 80.0f , & Part ) ;
2011-04-13 18:37:12 +00:00
2010-09-05 15:53:31 +00:00
Part . VSplitMid ( & No , & Yes ) ;
2011-04-13 18:37:12 +00:00
2010-09-05 15:53:31 +00:00
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
{
m_Popup = POPUP_NONE ;
2011-01-05 21:22:07 +00:00
// delete demo
if ( m_DemolistSelectedIndex > = 0 & & ! m_DemolistSelectedIsDir )
{
char aBuf [ 512 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %s/%s " , m_aCurrentDemoFolder , m_lDemos [ m_DemolistSelectedIndex ] . m_aFilename ) ;
if ( Storage ( ) - > RemoveFile ( aBuf , m_lDemos [ m_DemolistSelectedIndex ] . m_StorageType ) )
{
DemolistPopulate ( ) ;
DemolistOnUpdate ( false ) ;
}
else
PopupMessage ( Localize ( " Error " ) , Localize ( " Unable to delete the demo " ) , Localize ( " Ok " ) ) ;
}
2010-09-05 15:53:31 +00:00
}
}
2011-03-12 18:08:44 +00:00
else if ( m_Popup = = POPUP_RENAME_DEMO )
{
CUIRect Label , TextBox , Ok , Abort ;
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2011-03-12 18:08:44 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-03-12 18:08:44 +00:00
Part . VMargin ( 80.0f , & Part ) ;
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
Part . VSplitMid ( & Abort , & Ok ) ;
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
Ok . VMargin ( 20.0f , & Ok ) ;
Abort . VMargin ( 20.0f , & Abort ) ;
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " Abort " ) , 0 , & Abort ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
static int s_ButtonOk = 0 ;
if ( DoButton_Menu ( & s_ButtonOk , Localize ( " Ok " ) , 0 , & Ok ) | | m_EnterPressed )
{
m_Popup = POPUP_NONE ;
// rename demo
if ( m_DemolistSelectedIndex > = 0 & & ! m_DemolistSelectedIsDir )
{
char aBufOld [ 512 ] ;
str_format ( aBufOld , sizeof ( aBufOld ) , " %s/%s " , m_aCurrentDemoFolder , m_lDemos [ m_DemolistSelectedIndex ] . m_aFilename ) ;
2011-03-31 16:33:46 +00:00
int Length = str_length ( m_aCurrentDemoFile ) ;
2011-03-12 18:08:44 +00:00
char aBufNew [ 512 ] ;
2011-03-31 16:33:46 +00:00
if ( Length < = 4 | | m_aCurrentDemoFile [ Length - 5 ] ! = ' . ' | | str_comp_nocase ( m_aCurrentDemoFile + Length - 4 , " demo " ) )
str_format ( aBufNew , sizeof ( aBufNew ) , " %s/%s.demo " , m_aCurrentDemoFolder , m_aCurrentDemoFile ) ;
else
str_format ( aBufNew , sizeof ( aBufNew ) , " %s/%s " , m_aCurrentDemoFolder , m_aCurrentDemoFile ) ;
2011-03-12 18:08:44 +00:00
if ( Storage ( ) - > RenameFile ( aBufOld , aBufNew , m_lDemos [ m_DemolistSelectedIndex ] . m_StorageType ) )
{
DemolistPopulate ( ) ;
DemolistOnUpdate ( false ) ;
}
else
PopupMessage ( Localize ( " Error " ) , Localize ( " Unable to rename the demo " ) , Localize ( " Ok " ) ) ;
}
}
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2011-03-12 18:08:44 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2011-03-12 18:08:44 +00:00
Part . VSplitLeft ( 60.0f , 0 , & Label ) ;
Label . VSplitLeft ( 120.0f , 0 , & TextBox ) ;
TextBox . VSplitLeft ( 20.0f , 0 , & TextBox ) ;
TextBox . VSplitRight ( 60.0f , & TextBox , 0 ) ;
UI ( ) - > DoLabel ( & Label , Localize ( " New name: " ) , 18.0f , - 1 ) ;
static float Offset = 0.0f ;
DoEditBox ( & Offset , & TextBox , m_aCurrentDemoFile , sizeof ( m_aCurrentDemoFile ) , 12.0f , & Offset ) ;
}
2011-03-23 12:06:35 +00:00
else if ( m_Popup = = POPUP_REMOVE_FRIEND )
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2011-03-23 12:06:35 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-03-23 12:06:35 +00:00
Part . VMargin ( 80.0f , & Part ) ;
2011-04-13 18:37:12 +00:00
2011-03-23 12:06:35 +00:00
Part . VSplitMid ( & No , & Yes ) ;
2011-04-13 18:37:12 +00:00
2011-03-23 12:06:35 +00:00
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
static int s_ButtonAbort = 0 ;
if ( DoButton_Menu ( & s_ButtonAbort , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_NONE ;
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
{
m_Popup = POPUP_NONE ;
// remove friend
if ( m_FriendlistSelectedIndex > = 0 )
{
2011-06-26 15:10:13 +00:00
m_pClient - > Friends ( ) - > RemoveFriend ( m_lFriends [ m_FriendlistSelectedIndex ] . m_pFriendInfo - > m_aName ,
m_lFriends [ m_FriendlistSelectedIndex ] . m_pFriendInfo - > m_aClan ) ;
FriendlistOnUpdate ( ) ;
2011-03-23 12:06:35 +00:00
Client ( ) - > ServerBrowserUpdate ( ) ;
}
}
}
2010-05-29 07:25:38 +00:00
else if ( m_Popup = = POPUP_FIRST_LAUNCH )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Label , TextBox ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-05-29 07:25:38 +00:00
Part . VMargin ( 80.0f , & Part ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
static int s_EnterButton = 0 ;
if ( DoButton_Menu ( & s_EnterButton , Localize ( " Enter " ) , 0 , & Part ) | | m_EnterPressed )
m_Popup = POPUP_NONE ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 40.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Part . VSplitLeft ( 60.0f , 0 , & Label ) ;
Label . VSplitLeft ( 100.0f , 0 , & TextBox ) ;
TextBox . VSplitLeft ( 20.0f , 0 , & TextBox ) ;
TextBox . VSplitRight ( 60.0f , & TextBox , 0 ) ;
UI ( ) - > DoLabel ( & Label , Localize ( " Nickname " ) , 18.0f , - 1 ) ;
2010-05-29 15:53:57 +00:00
static float Offset = 0.0f ;
DoEditBox ( & g_Config . m_PlayerName , & TextBox , g_Config . m_PlayerName , sizeof ( g_Config . m_PlayerName ) , 12.0f , & Offset ) ;
2008-08-27 15:48:50 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2014-06-16 11:29:18 +00:00
# endif
2010-05-29 07:25:38 +00:00
Part . VMargin ( 120.0f , & Part ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
static int s_Button = 0 ;
if ( DoButton_Menu ( & s_Button , pButtonText , 0 , & Part ) | | m_EscapePressed | | m_EnterPressed )
m_Popup = POPUP_NONE ;
2008-08-27 15:48:50 +00:00
}
2013-03-16 14:30:40 +00:00
if ( m_Popup = = POPUP_NONE )
UI ( ) - > SetActiveItem ( 0 ) ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2014-06-27 08:13:57 +00:00
if ( m_Popup = = POPUP_DISCONNECTED )
2014-06-26 22:28:57 +00:00
{
2014-06-27 08:13:57 +00:00
if ( str_find_nocase ( Client ( ) - > ErrorString ( ) , " full " ) | | str_find_nocase ( Client ( ) - > ErrorString ( ) , " reserved " ) )
2014-06-26 22:28:57 +00:00
{
2014-06-27 08:13:57 +00:00
if ( g_Config . m_ClReconnectFull & & time_get ( ) > _my_rtime + time_freq ( ) * g_Config . m_ClReconnectFullTimeout )
2014-06-26 22:28:57 +00:00
Client ( ) - > Connect ( g_Config . m_UiServerAddress ) ;
}
2014-06-27 08:13:57 +00:00
else if ( str_find_nocase ( Client ( ) - > ErrorString ( ) , " ban " ) | | str_find_nocase ( Client ( ) - > ErrorString ( ) , " kick " ) )
2014-06-26 22:28:57 +00:00
{
2014-06-27 08:13:57 +00:00
if ( g_Config . m_ClReconnectBan & & time_get ( ) > _my_rtime + time_freq ( ) * g_Config . m_ClReconnectBanTimeout )
2014-06-26 22:28:57 +00:00
Client ( ) - > Connect ( g_Config . m_UiServerAddress ) ;
}
}
else if ( _my_rtime ! = 0 ) {
_my_rtime = 0 ;
}
2008-08-27 15:48:50 +00:00
return 0 ;
}
2008-10-20 23:38:23 +00:00
2010-05-29 07:25:38 +00:00
void CMenus : : SetActive ( bool Active )
2008-10-20 23:38:23 +00:00
{
2010-05-29 07:25:38 +00:00
m_MenuActive = Active ;
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
UI ( ) - > AndroidShowScreenKeys ( ! m_MenuActive & & ! m_pClient - > m_pControls - > m_UsingGamepad ) ;
# endif
2010-09-12 10:43:03 +00:00
if ( ! m_MenuActive )
2008-10-20 23:38:23 +00:00
{
2010-09-12 10:43:03 +00:00
if ( m_NeedSendinfo )
{
m_pClient - > SendInfo ( false ) ;
m_NeedSendinfo = false ;
}
2014-04-28 13:19:57 +00:00
if ( m_NeedSendDummyinfo )
{
m_pClient - > SendDummyInfo ( false ) ;
m_NeedSendDummyinfo = false ;
}
2010-10-25 18:09:08 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_ONLINE )
2010-09-12 10:43:03 +00:00
{
m_pClient - > OnRelease ( ) ;
}
2008-10-20 23:38:23 +00:00
}
2011-01-12 00:33:16 +00:00
else if ( Client ( ) - > State ( ) = = IClient : : STATE_DEMOPLAYBACK )
{
m_pClient - > OnRelease ( ) ;
}
2008-10-20 23:38:23 +00:00
}
2010-05-29 07:25:38 +00:00
void CMenus : : OnReset ( )
2008-08-27 15:48:50 +00:00
{
}
2010-05-29 07:25:38 +00:00
bool CMenus : : OnMouseMove ( float x , float y )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
m_LastInput = time_get ( ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( ! m_MenuActive )
2008-08-27 15:48:50 +00:00
return false ;
2011-04-13 18:37:12 +00:00
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__) // No relative mouse on Android
m_MousePos . x = x ;
m_MousePos . y = y ;
# else
2011-07-02 22:36:07 +00:00
UI ( ) - > ConvertMouseMove ( & x , & y ) ;
2010-05-29 07:25:38 +00:00
m_MousePos . x + = x ;
m_MousePos . y + = y ;
2014-06-16 11:29:18 +00:00
# endif
2010-05-29 07:25:38 +00:00
if ( m_MousePos . x < 0 ) m_MousePos . x = 0 ;
if ( m_MousePos . y < 0 ) m_MousePos . y = 0 ;
if ( m_MousePos . x > Graphics ( ) - > ScreenWidth ( ) ) m_MousePos . x = Graphics ( ) - > ScreenWidth ( ) ;
if ( m_MousePos . y > Graphics ( ) - > ScreenHeight ( ) ) m_MousePos . y = Graphics ( ) - > ScreenHeight ( ) ;
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
return true ;
}
2010-05-29 07:25:38 +00:00
bool CMenus : : OnInput ( IInput : : CEvent e )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
m_LastInput = time_get ( ) ;
2011-04-13 18:37:12 +00:00
2008-10-21 18:25:28 +00:00
// special handle esc and enter for popup purposes
2010-05-29 07:25:38 +00:00
if ( e . m_Flags & IInput : : FLAG_PRESS )
2008-08-27 20:23:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( e . m_Key = = KEY_ESCAPE )
2008-10-18 10:52:26 +00:00
{
2010-05-29 07:25:38 +00:00
m_EscapePressed = true ;
SetActive ( ! IsActive ( ) ) ;
2008-10-21 18:25:28 +00:00
return true ;
2008-10-18 10:52:26 +00:00
}
2008-10-21 18:25:28 +00:00
}
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( IsActive ( ) )
2008-10-21 18:25:28 +00:00
{
2010-09-03 18:05:22 +00:00
if ( e . m_Flags & IInput : : FLAG_PRESS )
{
// special for popups
2010-09-08 00:32:41 +00:00
if ( e . m_Key = = KEY_RETURN | | e . m_Key = = KEY_KP_ENTER )
2010-09-03 18:05:22 +00:00
m_EnterPressed = true ;
else if ( e . m_Key = = KEY_DELETE )
m_DeletePressed = true ;
}
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( m_NumInputEvents < MAX_INPUTEVENTS )
m_aInputEvents [ m_NumInputEvents + + ] = e ;
2008-08-27 20:23:50 +00:00
return true ;
2008-08-30 09:28:31 +00:00
}
2008-08-27 15:48:50 +00:00
return false ;
}
2010-05-29 07:25:38 +00:00
void CMenus : : OnStateChange ( int NewState , int OldState )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
// reset active item
UI ( ) - > SetActiveItem ( 0 ) ;
if ( NewState = = IClient : : STATE_OFFLINE )
2008-08-27 15:48:50 +00:00
{
2012-01-06 19:03:57 +00:00
if ( OldState > = IClient : : STATE_ONLINE & & NewState < IClient : : STATE_QUITING )
2012-01-06 18:38:40 +00:00
m_pClient - > m_pSounds - > Play ( CSounds : : CHN_MUSIC , SOUND_MENU , 1.0f ) ;
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE ;
if ( Client ( ) - > ErrorString ( ) & & Client ( ) - > ErrorString ( ) [ 0 ] ! = 0 )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
if ( str_find ( Client ( ) - > ErrorString ( ) , " password " ) )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_PASSWORD ;
UI ( ) - > SetHotItem ( & g_Config . m_Password ) ;
UI ( ) - > SetActiveItem ( & g_Config . m_Password ) ;
2008-08-27 15:48:50 +00:00
}
else
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_DISCONNECTED ;
}
}
else if ( NewState = = IClient : : STATE_LOADING )
2009-01-12 14:03:19 +00:00
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_CONNECTING ;
2010-12-16 00:52:29 +00:00
m_DownloadLastCheckTime = time_get ( ) ;
m_DownloadLastCheckSize = 0 ;
2011-04-12 16:59:08 +00:00
m_DownloadSpeed = 0.0f ;
2010-05-29 07:25:38 +00:00
//client_serverinfo_request();
2009-01-12 14:03:19 +00:00
}
2010-05-29 07:25:38 +00:00
else if ( NewState = = IClient : : STATE_CONNECTING )
m_Popup = POPUP_CONNECTING ;
else if ( NewState = = IClient : : STATE_ONLINE | | NewState = = IClient : : STATE_DEMOPLAYBACK )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE ;
SetActive ( false ) ;
2008-08-27 15:48:50 +00:00
}
}
2009-06-07 14:36:54 +00:00
extern " C " void font_debug_render ( ) ;
2010-05-29 07:25:38 +00:00
void CMenus : : OnRender ( )
2008-08-27 15:48:50 +00:00
{
2009-06-07 16:06:03 +00:00
/*
// text rendering test stuff
render_background ( ) ;
2010-05-29 07:25:38 +00:00
CTextCursor cursor ;
TextRender ( ) - > SetCursor ( & cursor , 10 , 10 , 20 , TEXTFLAG_RENDER ) ;
TextRender ( ) - > TextEx ( & cursor , " ようこそ - ガイド " , - 1 ) ;
2009-06-07 16:06:03 +00:00
2010-05-29 07:25:38 +00:00
TextRender ( ) - > SetCursor ( & cursor , 10 , 30 , 15 , TEXTFLAG_RENDER ) ;
TextRender ( ) - > TextEx ( & cursor , " ようこそ - ガイド " , - 1 ) ;
2011-04-13 18:37:12 +00:00
2009-10-27 14:38:53 +00:00
//Graphics()->TextureSet(-1);
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > QuadsDrawTL ( 60 , 60 , 5000 , 5000 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
2009-06-07 16:06:03 +00:00
return ; */
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > State ( ) ! = IClient : : STATE_ONLINE & & Client ( ) - > State ( ) ! = IClient : : STATE_DEMOPLAYBACK )
SetActive ( true ) ;
2008-10-06 18:05:01 +00:00
2010-05-29 07:25:38 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_DEMOPLAYBACK )
2008-10-06 18:05:01 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ;
RenderDemoPlayer ( Screen ) ;
2008-10-06 18:05:01 +00:00
}
2011-04-13 18:37:12 +00:00
2010-10-22 13:22:17 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_ONLINE & & m_pClient - > m_ServerMode = = m_pClient - > SERVERMODE_PUREMOD )
2009-01-11 10:40:14 +00:00
{
2010-05-29 07:25:38 +00:00
Client ( ) - > Disconnect ( ) ;
SetActive ( true ) ;
m_Popup = POPUP_PURE ;
2010-10-22 13:22:17 +00:00
}
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( ! IsActive ( ) )
2008-10-18 10:52:26 +00:00
{
2010-05-29 07:25:38 +00:00
m_EscapePressed = false ;
m_EnterPressed = false ;
2010-09-03 18:05:22 +00:00
m_DeletePressed = false ;
2010-05-29 07:25:38 +00:00
m_NumInputEvents = 0 ;
2008-08-27 15:48:50 +00:00
return ;
2008-10-18 10:52:26 +00:00
}
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// update colors
2010-05-29 07:25:38 +00:00
vec3 Rgb = HslToRgb ( vec3 ( g_Config . m_UiColorHue / 255.0f , g_Config . m_UiColorSat / 255.0f , g_Config . m_UiColorLht / 255.0f ) ) ;
ms_GuiColor = vec4 ( Rgb . r , Rgb . g , Rgb . b , g_Config . m_UiColorAlpha / 255.0f ) ;
ms_ColorTabbarInactiveOutgame = vec4 ( 0 , 0 , 0 , 0.25f ) ;
ms_ColorTabbarActiveOutgame = vec4 ( 0 , 0 , 0 , 0.5f ) ;
float ColorIngameScaleI = 0.5f ;
float ColorIngameAcaleA = 0.2f ;
ms_ColorTabbarInactiveIngame = vec4 (
ms_GuiColor . r * ColorIngameScaleI ,
ms_GuiColor . g * ColorIngameScaleI ,
ms_GuiColor . b * ColorIngameScaleI ,
ms_GuiColor . a * 0.8f ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
ms_ColorTabbarActiveIngame = vec4 (
ms_GuiColor . r * ColorIngameAcaleA ,
ms_GuiColor . g * ColorIngameAcaleA ,
ms_GuiColor . b * ColorIngameAcaleA ,
ms_GuiColor . a ) ;
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// update the ui
2010-05-29 07:25:38 +00:00
CUIRect * pScreen = UI ( ) - > Screen ( ) ;
float mx = ( m_MousePos . x / ( float ) Graphics ( ) - > ScreenWidth ( ) ) * pScreen - > w ;
float my = ( m_MousePos . y / ( float ) Graphics ( ) - > ScreenHeight ( ) ) * pScreen - > h ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
int Buttons = 0 ;
if ( m_UseMouseButtons )
{
if ( Input ( ) - > KeyPressed ( KEY_MOUSE_1 ) ) Buttons | = 1 ;
if ( Input ( ) - > KeyPressed ( KEY_MOUSE_2 ) ) Buttons | = 2 ;
if ( Input ( ) - > KeyPressed ( KEY_MOUSE_3 ) ) Buttons | = 4 ;
}
2011-04-13 18:37:12 +00:00
2014-06-16 11:29:18 +00:00
# if defined(__ANDROID__)
static int ButtonsOneFrameDelay = 0 ; // For Android touch input
UI ( ) - > Update ( mx , my , mx * 3.0f , my * 3.0f , ButtonsOneFrameDelay ) ;
ButtonsOneFrameDelay = Buttons ;
# else
2010-05-29 07:25:38 +00:00
UI ( ) - > Update ( mx , my , mx * 3.0f , my * 3.0f , Buttons ) ;
2014-06-16 11:29:18 +00:00
# endif
2011-04-13 18:37:12 +00:00
2009-01-10 11:16:21 +00:00
// render
2010-10-25 18:09:08 +00:00
if ( Client ( ) - > State ( ) ! = IClient : : STATE_DEMOPLAYBACK )
2010-05-29 07:25:38 +00:00
Render ( ) ;
2008-09-24 15:09:09 +00:00
2009-01-10 11:16:21 +00:00
// render cursor
2010-05-29 07:25:38 +00:00
Graphics ( ) - > TextureSet ( g_pData - > m_aImages [ IMAGE_CURSOR ] . m_Id ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CQuadItem QuadItem ( mx , my , 24 , 24 ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2009-01-10 11:16:21 +00:00
// render debug information
2010-05-29 07:25:38 +00:00
if ( g_Config . m_Debug )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ;
char aBuf [ 512 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %p %p %p " , UI ( ) - > HotItem ( ) , UI ( ) - > ActiveItem ( ) , UI ( ) - > LastActiveItem ( ) ) ;
CTextCursor Cursor ;
TextRender ( ) - > SetCursor ( & Cursor , 10 , 10 , 10 , TEXTFLAG_RENDER ) ;
TextRender ( ) - > TextEx ( & Cursor , aBuf , - 1 ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
m_EscapePressed = false ;
m_EnterPressed = false ;
2010-09-03 18:05:22 +00:00
m_DeletePressed = false ;
2010-05-29 07:25:38 +00:00
m_NumInputEvents = 0 ;
2008-08-27 15:48:50 +00:00
}
2008-09-11 22:45:28 +00:00
2010-05-29 07:25:38 +00:00
static int gs_TextureBlob = - 1 ;
2008-09-24 15:09:09 +00:00
2010-05-29 07:25:38 +00:00
void CMenus : : RenderBackground ( )
2008-09-11 22:45:28 +00:00
{
2009-10-27 14:38:53 +00:00
//Graphics()->Clear(1,1,1);
2008-09-24 15:09:09 +00:00
//render_sunrays(0,0);
2010-05-29 07:25:38 +00:00
if ( gs_TextureBlob = = - 1 )
2010-10-06 21:07:35 +00:00
gs_TextureBlob = Graphics ( ) - > LoadTexture ( " blob.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , 0 ) ;
2008-09-24 15:09:09 +00:00
2009-10-27 14:38:53 +00:00
float sw = 300 * Graphics ( ) - > ScreenAspect ( ) ;
2008-09-24 15:09:09 +00:00
float sh = 300 ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > MapScreen ( 0 , 0 , sw , sh ) ;
2008-09-23 11:58:12 +00:00
2008-09-24 15:09:09 +00:00
// render background color
2009-10-27 14:38:53 +00:00
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2008-09-24 15:09:09 +00:00
//vec4 bottom(gui_color.r*0.3f, gui_color.g*0.3f, gui_color.b*0.3f, 1.0f);
//vec4 bottom(0, 0, 0, 1.0f);
2010-05-29 07:25:38 +00:00
vec4 Bottom ( ms_GuiColor . r , ms_GuiColor . g , ms_GuiColor . b , 1.0f ) ;
vec4 Top ( ms_GuiColor . r , ms_GuiColor . g , ms_GuiColor . b , 1.0f ) ;
IGraphics : : CColorVertex Array [ 4 ] = {
IGraphics : : CColorVertex ( 0 , Top . r , Top . g , Top . b , Top . a ) ,
IGraphics : : CColorVertex ( 1 , Top . r , Top . g , Top . b , Top . a ) ,
IGraphics : : CColorVertex ( 2 , Bottom . r , Bottom . g , Bottom . b , Bottom . a ) ,
IGraphics : : CColorVertex ( 3 , Bottom . r , Bottom . g , Bottom . b , Bottom . a ) } ;
Graphics ( ) - > SetColorVertex ( Array , 4 ) ;
IGraphics : : CQuadItem QuadItem ( 0 , 0 , sw , sh ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2011-04-13 18:37:12 +00:00
2008-09-24 15:09:09 +00:00
// render the tiles
2009-10-27 14:38:53 +00:00
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
2010-05-29 07:25:38 +00:00
float Size = 15.0f ;
float OffsetTime = fmod ( Client ( ) - > LocalTime ( ) * 0.15f , 2.0f ) ;
for ( int y = - 2 ; y < ( int ) ( sw / Size ) ; y + + )
for ( int x = - 2 ; x < ( int ) ( sh / Size ) ; x + + )
2008-09-24 15:09:09 +00:00
{
2009-10-27 14:38:53 +00:00
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.045f ) ;
2010-05-29 07:25:38 +00:00
IGraphics : : CQuadItem QuadItem ( ( x - OffsetTime ) * Size * 2 + ( y & 1 ) * Size , ( y + OffsetTime ) * Size , Size , Size ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2008-09-24 15:09:09 +00:00
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-09-24 15:09:09 +00:00
// render border fade
2010-05-29 07:25:38 +00:00
Graphics ( ) - > TextureSet ( gs_TextureBlob ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.5f ) ;
2010-05-29 07:25:38 +00:00
QuadItem = IGraphics : : CQuadItem ( - 100 , - 100 , sw + 200 , sh + 200 ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-09-24 15:09:09 +00:00
2011-04-13 18:37:12 +00:00
// restore screen
{ CUIRect Screen = * UI ( ) - > Screen ( ) ;
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ; }
2008-09-11 22:45:28 +00:00
}
2011-01-30 16:21:41 +00:00
int CMenus : : DoButton_CheckBox_DontCare ( const void * pID , const char * pText , int Checked , const CUIRect * pRect )
{
switch ( Checked )
{
case 0 :
return DoButton_CheckBox_Common ( pID , pText , " " , pRect ) ;
case 1 :
return DoButton_CheckBox_Common ( pID , pText , " X " , pRect ) ;
case 2 :
return DoButton_CheckBox_Common ( pID , pText , " O " , pRect ) ;
default :
return DoButton_CheckBox_Common ( pID , pText , " " , pRect ) ;
}
2011-12-01 17:48:09 +00:00
}
2014-04-27 03:01:03 +00:00
void CMenus : : RenderUpdating ( const char * pCaption , int current , int total )
{
// make sure that we don't render for each little thing we load
// because that will slow down loading if we have vsync
static int64 LastLoadRender = 0 ;
if ( time_get ( ) - LastLoadRender < time_freq ( ) / 60 )
return ;
LastLoadRender = time_get ( ) ;
// need up date this here to get correct
vec3 Rgb = HslToRgb ( vec3 ( g_Config . m_UiColorHue / 255.0f , g_Config . m_UiColorSat / 255.0f , g_Config . m_UiColorLht / 255.0f ) ) ;
ms_GuiColor = vec4 ( Rgb . r , Rgb . g , Rgb . b , g_Config . m_UiColorAlpha / 255.0f ) ;
CUIRect Screen = * UI ( ) - > Screen ( ) ;
Graphics ( ) - > MapScreen ( Screen . x , Screen . y , Screen . w , Screen . h ) ;
RenderBackground ( ) ;
float w = 700 ;
float h = 200 ;
float x = Screen . w / 2 - w / 2 ;
float y = Screen . h / 2 - h / 2 ;
Graphics ( ) - > BlendNormal ( ) ;
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.50f ) ;
RenderTools ( ) - > DrawRoundRect ( 0 , y , Screen . w , h , 0.0f ) ;
Graphics ( ) - > QuadsEnd ( ) ;
CUIRect r ;
r . x = x ;
r . y = y + 20 ;
r . w = w ;
r . h = h ;
UI ( ) - > DoLabel ( & r , Localize ( pCaption ) , 32.0f , 0 , - 1 ) ;
if ( total > 0 )
{
float Percent = current / ( float ) total ;
Graphics ( ) - > TextureSet ( - 1 ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 0.15f , 0.15f , 0.15f , 0.75f ) ;
RenderTools ( ) - > DrawRoundRect ( x + 40 , y + h - 75 , w - 80 , 30 , 5.0f ) ;
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 0.75f ) ;
RenderTools ( ) - > DrawRoundRect ( x + 45 , y + h - 70 , ( w - 85 ) * Percent , 20 , 5.0f ) ;
Graphics ( ) - > QuadsEnd ( ) ;
}
Graphics ( ) - > Swap ( ) ;
}