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
2020-09-18 16:45:42 +00:00
# include <vector>
2011-08-31 11:56:04 +00:00
# include <base/tl/array.h>
2008-08-27 15:48:50 +00:00
# include <math.h>
2010-05-29 07:25:38 +00:00
# include <base/math.h>
2020-09-22 16:02:03 +00:00
# include <base/system.h>
2010-05-29 07:25:38 +00:00
# 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>
2020-09-22 16:02:03 +00:00
# include <engine/shared/config.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>
2009-06-13 17:18:06 +00:00
2010-05-29 07:25:38 +00:00
# include <game/generated/protocol.h>
2020-09-22 16:02:03 +00:00
# include <game/version.h>
2008-08-27 15:48:50 +00:00
2020-09-16 01:30:03 +00:00
# include <engine/client/updater.h>
2019-04-28 17:22:19 +00:00
# include <game/client/components/binds.h>
2020-09-03 12:08:26 +00:00
# include <game/client/components/console.h>
2020-09-18 16:45:42 +00:00
# include <game/client/components/menu_background.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>
2020-09-10 18:14:47 +00:00
# include <game/generated/client_data.h>
2010-05-29 07:25:38 +00:00
# include <game/localization.h>
2008-08-27 15:48:50 +00:00
# include <mastersrv/mastersrv.h>
2020-09-22 16:02:03 +00:00
# include "controls.h"
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"
2020-11-15 06:01:53 +00:00
# include <limits>
2019-04-26 21:47:34 +00:00
ColorRGBA CMenus : : ms_GuiColor ;
ColorRGBA CMenus : : ms_ColorTabbarInactiveOutgame ;
ColorRGBA CMenus : : ms_ColorTabbarActiveOutgame ;
2020-09-16 01:30:03 +00:00
ColorRGBA CMenus : : ms_ColorTabbarHoverOutgame ;
2019-04-26 21:47:34 +00:00
ColorRGBA CMenus : : ms_ColorTabbarInactive ;
2020-09-16 01:30:03 +00:00
ColorRGBA CMenus : : ms_ColorTabbarActive = ColorRGBA ( 0 , 0 , 0 , 0.5f ) ;
ColorRGBA CMenus : : ms_ColorTabbarHover ;
2019-04-26 21:47:34 +00:00
ColorRGBA CMenus : : ms_ColorTabbarInactiveIngame ;
ColorRGBA CMenus : : ms_ColorTabbarActiveIngame ;
2020-09-16 01:30:03 +00:00
ColorRGBA CMenus : : ms_ColorTabbarHoverIngame ;
2008-08-27 15:48:50 +00:00
2020-10-28 02:59:50 +00:00
SColorPicker CMenus : : ms_ColorPicker ;
2020-12-14 00:51:31 +00:00
bool CMenus : : ms_ValueSelectorTextMode ;
2020-10-28 02:59:50 +00:00
2010-05-29 07:25:38 +00:00
float CMenus : : ms_ButtonHeight = 25.0f ;
float CMenus : : ms_ListheaderHeight = 17.0f ;
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 ;
2020-09-03 12:08:26 +00:00
m_MenuPage = 0 ;
2010-05-29 07:25:38 +00:00
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 ;
2020-09-03 12:08:26 +00:00
m_ShowStart = true ;
2010-05-29 07:25:38 +00:00
m_UseMouseButtons = true ;
2016-05-03 13:11:52 +00:00
m_MouseSlow = false ;
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-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
2014-08-23 15:48:04 +00:00
m_DemoPlayerState = DEMOPLAYER_NONE ;
2015-08-28 18:44:07 +00:00
m_Dummy = false ;
2020-09-03 12:08:26 +00:00
2020-09-05 22:38:35 +00:00
m_ServerProcess . Process = 0 ;
2020-09-03 12:08:26 +00:00
m_ServerProcess . Initialized = false ;
2020-10-26 02:48:05 +00:00
for ( SUIAnimator & animator : m_aAnimatorsSettingsTab )
{
animator . m_YOffset = - 2.5f ;
animator . m_HOffset = 5.0f ;
animator . m_WOffset = 5.0f ;
2020-10-26 03:10:58 +00:00
animator . m_RepositionLabel = true ;
2020-10-26 02:48:05 +00:00
}
for ( SUIAnimator & animator : m_aAnimatorsBigPage )
{
animator . m_YOffset = - 5.0f ;
animator . m_HOffset = 5.0f ;
}
for ( SUIAnimator & animator : m_aAnimatorsSmallPage )
{
animator . m_YOffset = - 2.5f ;
animator . m_HOffset = 2.5f ;
}
2008-08-27 15:48:50 +00:00
}
2019-04-26 21:47:34 +00:00
float 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 )
2020-10-12 10:29:47 +00:00
return ButtonColorMulActive ( ) ;
2009-10-27 14:38:53 +00:00
else if ( UI ( ) - > HotItem ( ) = = pID )
2020-10-12 10:29:47 +00:00
return ButtonColorMulHot ( ) ;
return ButtonColorMulDefault ( ) ;
2008-08-27 15:48:50 +00:00
}
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
{
2019-03-19 15:07:32 +00:00
int x = pRect - > x ;
int y = pRect - > y ;
int w = pRect - > w ;
int h = pRect - > h ;
// Square and center
if ( w > h )
{
2020-09-22 16:02:03 +00:00
x + = ( w - h ) / 2 ;
2019-03-19 15:07:32 +00:00
w = h ;
}
else if ( h > w )
{
2020-09-22 16:02:03 +00:00
y + = ( h - w ) / 2 ;
2019-03-19 15:07:32 +00:00
h = w ;
}
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 ) ;
2019-03-19 15:07:32 +00:00
IGraphics : : CQuadItem QuadItem ( x , y , w , h ) ;
2010-05-29 07:25:38 +00:00
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 ) ;
2020-09-22 16:02:03 +00:00
RenderTools ( ) - > SelectSprite ( Checked ? SPRITE_GUIBUTTON_ON : SPRITE_GUIBUTTON_OFF ) ;
2011-04-06 18:18:31 +00:00
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
2020-10-29 00:55:01 +00:00
int CMenus : : DoButton_Menu ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , const char * pImageName , int Corners , float r , float FontFactor , vec4 ColorHot , vec4 Color , int AlignVertically , bool CheckForActiveColorPicker )
2008-08-27 15:48:50 +00:00
{
2020-09-03 12:08:26 +00:00
CUIRect Text = * pRect ;
2020-10-29 00:55:01 +00:00
bool MouseInsideColorPicker = false ;
if ( CheckForActiveColorPicker )
{
if ( ms_ColorPicker . m_Active )
{
CUIRect PickerRect ;
PickerRect . x = ms_ColorPicker . m_X ;
PickerRect . y = ms_ColorPicker . m_Y ;
PickerRect . w = ms_ColorPicker . ms_Width ;
PickerRect . h = ms_ColorPicker . ms_Height ;
MouseInsideColorPicker = UI ( ) - > MouseInside ( & PickerRect ) ;
}
}
if ( ! MouseInsideColorPicker )
Color . a * = ButtonColorMul ( pID ) ;
2020-09-03 12:08:26 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , Color , Corners , r ) ;
if ( pImageName )
{
CUIRect Image ;
2020-09-10 18:14:47 +00:00
pRect - > VSplitRight ( pRect - > h * 4.0f , & Text , & Image ) ; // always correct ratio for image
2020-09-03 12:08:26 +00:00
// render image
const CMenuImage * pImage = FindMenuImage ( pImageName ) ;
if ( pImage )
{
Graphics ( ) - > TextureSet ( UI ( ) - > HotItem ( ) = = pID ? pImage - > m_OrgTexture : pImage - > m_GreyTexture ) ;
Graphics ( ) - > WrapClamp ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
IGraphics : : CQuadItem QuadItem ( Image . x , Image . y , Image . w , Image . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
Graphics ( ) - > WrapNormal ( ) ;
}
}
2020-09-10 18:14:47 +00:00
Text . HMargin ( pRect - > h > = 20.0f ? 2.0f : 1.0f , & Text ) ;
Text . HMargin ( ( Text . h * FontFactor ) / 2.0f , & Text ) ;
2020-10-06 10:25:10 +00:00
UI ( ) - > DoLabel ( & Text , pText , Text . h * ms_FontmodHeight , 0 , - 1 , AlignVertically ) ;
2020-10-29 00:55:01 +00:00
if ( MouseInsideColorPicker )
return 0 ;
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
{
2020-09-22 16:02:03 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ColorRGBA ( 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 ) ;
2020-09-22 16:02:03 +00:00
UI ( ) - > DoLabel ( & Temp , pText , Temp . h * ms_FontmodHeight , 0 ) ;
2008-08-27 15:48:50 +00:00
}
2020-10-26 01:10:55 +00:00
int CMenus : : DoButton_MenuTab ( const void * pID , const char * pText , int Checked , const CUIRect * pRect , int Corners , SUIAnimator * pAnimator , const ColorRGBA * pDefaultColor , const ColorRGBA * pActiveColor , const ColorRGBA * pHoverColor , float EdgeRounding , int AlignVertically )
2008-08-27 15:48:50 +00:00
{
2020-10-26 01:10:55 +00:00
bool MouseInside = UI ( ) - > MouseInside ( pRect ) ;
CUIRect Rect = * pRect ;
if ( pAnimator ! = NULL )
{
2021-06-23 05:05:49 +00:00
int64_t Time = time_get_microseconds ( ) ;
2020-10-26 01:10:55 +00:00
2021-06-23 05:05:49 +00:00
if ( pAnimator - > m_Time + ( int64_t ) 100000 < Time )
2020-10-26 01:10:55 +00:00
{
pAnimator - > m_Value = pAnimator - > m_Active ? 1 : 0 ;
pAnimator - > m_Time = Time ;
}
pAnimator - > m_Active = Checked | | MouseInside ;
if ( pAnimator - > m_Active )
2020-10-26 14:47:26 +00:00
pAnimator - > m_Value = clamp < float > ( pAnimator - > m_Value + ( Time - pAnimator - > m_Time ) / 100000.f , 0 , 1 ) ;
2020-10-26 01:10:55 +00:00
else
2020-10-26 14:47:26 +00:00
pAnimator - > m_Value = clamp < float > ( pAnimator - > m_Value - ( Time - pAnimator - > m_Time ) / 100000.f , 0 , 1 ) ;
2020-10-26 01:10:55 +00:00
2020-10-26 02:48:05 +00:00
Rect . w + = pAnimator - > m_Value * pAnimator - > m_WOffset ;
Rect . h + = pAnimator - > m_Value * pAnimator - > m_HOffset ;
Rect . x + = pAnimator - > m_Value * pAnimator - > m_XOffset ;
Rect . y + = pAnimator - > m_Value * pAnimator - > m_YOffset ;
2020-10-26 01:43:34 +00:00
pAnimator - > m_Time = Time ;
2020-10-26 01:10:55 +00:00
}
2009-10-27 14:38:53 +00:00
if ( Checked )
2020-09-16 01:30:03 +00:00
{
ColorRGBA ColorMenuTab = ms_ColorTabbarActive ;
if ( pActiveColor )
ColorMenuTab = * pActiveColor ;
2020-10-26 01:10:55 +00:00
RenderTools ( ) - > DrawUIRect ( & Rect , ColorMenuTab , Corners , EdgeRounding ) ;
2020-09-16 01:30:03 +00:00
}
2008-08-27 15:48:50 +00:00
else
2020-09-16 01:30:03 +00:00
{
if ( UI ( ) - > MouseInside ( pRect ) )
{
ColorRGBA HoverColorMenuTab = ms_ColorTabbarHover ;
if ( pHoverColor )
HoverColorMenuTab = * pHoverColor ;
2020-10-26 01:10:55 +00:00
RenderTools ( ) - > DrawUIRect ( & Rect , HoverColorMenuTab , Corners , EdgeRounding ) ;
2020-09-16 01:30:03 +00:00
}
else
{
ColorRGBA ColorMenuTab = ms_ColorTabbarInactive ;
if ( pDefaultColor )
ColorMenuTab = * pDefaultColor ;
2020-10-26 01:10:55 +00:00
RenderTools ( ) - > DrawUIRect ( & Rect , ColorMenuTab , Corners , EdgeRounding ) ;
2020-09-16 01:30:03 +00:00
}
}
2020-10-26 01:10:55 +00:00
2011-04-01 15:57:04 +00:00
CUIRect Temp ;
2020-10-26 02:48:05 +00:00
if ( pAnimator ! = NULL )
{
2020-10-26 03:10:58 +00:00
if ( pAnimator - > m_RepositionLabel )
{
Rect . x + = Rect . w - pRect - > w + Rect . x - pRect - > x ;
Rect . y + = Rect . h - pRect - > h + Rect . y - pRect - > y ;
}
2020-12-13 18:31:37 +00:00
2020-10-26 02:48:05 +00:00
if ( ! pAnimator - > m_ScaleLabel )
{
Rect . w = pRect - > w ;
Rect . h = pRect - > h ;
}
}
2020-12-13 18:31:37 +00:00
2020-10-26 14:47:26 +00:00
Rect . HMargin ( 2.0f , & Temp ) ;
2020-10-06 10:25:10 +00:00
UI ( ) - > DoLabel ( & Temp , pText , Temp . h * ms_FontmodHeight , 0 , - 1 , AlignVertically ) ;
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 )
2008-08-27 15:48:50 +00:00
{
2020-08-24 21:23:37 +00:00
if ( Checked = = 2 )
2020-09-22 16:02:03 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ColorRGBA ( 1 , 0.98f , 0.5f , 0.55f ) , CUI : : CORNER_T , 5.0f ) ;
2020-08-24 21:23:37 +00:00
else if ( Checked )
2020-09-22 16:02:03 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ColorRGBA ( 1 , 1 , 1 , 0.5f ) , CUI : : CORNER_T , 5.0f ) ;
2009-10-27 14:38:53 +00:00
CUIRect t ;
pRect - > VSplitLeft ( 5.0f , 0 , & t ) ;
2020-09-22 16:02:03 +00:00
UI ( ) - > DoLabel ( & t , pText , pRect - > h * ms_FontmodHeight , - 1 ) ;
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 )
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 ) ;
2020-09-22 16:02:03 +00:00
RenderTools ( ) - > DrawUIRect ( & c , ColorRGBA ( 1 , 1 , 1 , 0.25f * ButtonColorMul ( pID ) ) , CUI : : CORNER_ALL , 3.0f ) ;
2018-03-13 20:59:07 +00:00
bool CheckAble = * pBoxText = = ' X ' ;
if ( CheckAble )
{
2020-10-06 10:25:10 +00:00
TextRender ( ) - > SetRenderFlags ( ETextRenderFlags : : TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_OVERSIZE | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT ) ;
2018-03-13 20:59:07 +00:00
TextRender ( ) - > SetCurFont ( TextRender ( ) - > GetFont ( TEXT_FONT_ICON_FONT ) ) ;
2020-10-06 10:25:10 +00:00
UI ( ) - > DoLabel ( & c , " \xEE \x97 \x8D " , c . h * ms_FontmodHeight , 0 , - 1 , 0 ) ;
2018-03-13 20:59:07 +00:00
TextRender ( ) - > SetCurFont ( NULL ) ;
}
else
2020-10-06 10:25:10 +00:00
UI ( ) - > DoLabel ( & c , pBoxText , c . h * ms_FontmodHeight , 0 , - 1 , 0 ) ;
2018-03-13 20:59:07 +00:00
TextRender ( ) - > SetRenderFlags ( 0 ) ;
2020-09-22 16:02:03 +00:00
UI ( ) - > DoLabel ( & t , pText , c . h * ms_FontmodHeight , - 1 ) ;
2018-03-13 20:59:07 +00:00
2009-10-27 14:38:53 +00:00
return UI ( ) - > DoButtonLogic ( pID , pText , 0 , pRect ) ;
2008-08-27 15:48:50 +00:00
}
2020-10-29 00:55:01 +00:00
void CMenus : : DoLaserPreview ( const CUIRect * pRect , const ColorHSLA LaserOutlineColor , const ColorHSLA LaserInnerColor )
{
ColorRGBA LaserRGB ;
CUIRect Section = * pRect ;
vec2 From = vec2 ( Section . x , Section . y + Section . h / 2.0f ) ;
vec2 Pos = vec2 ( Section . x + Section . w - 10.0f , Section . y + Section . h / 2.0f ) ;
Graphics ( ) - > BlendNormal ( ) ;
Graphics ( ) - > TextureClear ( ) ;
Graphics ( ) - > QuadsBegin ( ) ;
LaserRGB = color_cast < ColorRGBA , ColorHSLA > ( LaserOutlineColor ) ;
ColorRGBA OuterColor ( LaserRGB . r , LaserRGB . g , LaserRGB . b , 1.0f ) ;
Graphics ( ) - > SetColor ( LaserRGB . r , LaserRGB . g , LaserRGB . b , 1.0f ) ;
2020-12-14 01:18:04 +00:00
vec2 Out = vec2 ( 0.0f , - 1.0f ) * ( 3.15f ) ;
2020-10-29 00:55:01 +00:00
IGraphics : : CFreeformItem Freeform ( From . x - Out . x , From . y - Out . y , From . x + Out . x , From . y + Out . y , Pos . x - Out . x , Pos . y - Out . y , Pos . x + Out . x , Pos . y + Out . y ) ;
Graphics ( ) - > QuadsDrawFreeform ( & Freeform , 1 ) ;
LaserRGB = color_cast < ColorRGBA , ColorHSLA > ( LaserInnerColor ) ;
ColorRGBA InnerColor ( LaserRGB . r , LaserRGB . g , LaserRGB . b , 1.0f ) ;
Out = vec2 ( 0.0f , - 1.0f ) * ( 2.25f ) ;
Graphics ( ) - > SetColor ( InnerColor . r , InnerColor . g , InnerColor . b , 1.0f ) ;
Freeform = IGraphics : : CFreeformItem ( From . x - Out . x , From . y - Out . y , From . x + Out . x , From . y + Out . y , Pos . x - Out . x , Pos . y - Out . y , Pos . x + Out . x , Pos . y + Out . y ) ;
Graphics ( ) - > QuadsDrawFreeform ( & Freeform , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
Graphics ( ) - > BlendNormal ( ) ;
int SpriteIndex = time_get ( ) % 3 ;
Graphics ( ) - > TextureSet ( GameClient ( ) - > m_ParticlesSkin . m_SpriteParticleSplat [ SpriteIndex ] ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > QuadsSetRotation ( time_get ( ) ) ;
Graphics ( ) - > SetColor ( OuterColor . r , OuterColor . g , OuterColor . b , 1.0f ) ;
IGraphics : : CQuadItem QuadItem ( Pos . x , Pos . y , 24 , 24 ) ;
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
Graphics ( ) - > SetColor ( InnerColor . r , InnerColor . g , InnerColor . b , 1.0f ) ;
QuadItem = IGraphics : : CQuadItem ( Pos . x , Pos . y , 20 , 20 ) ;
Graphics ( ) - > QuadsDraw ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
Graphics ( ) - > TextureSet ( GameClient ( ) - > m_GameSkin . m_SpriteWeaponLaser ) ;
Graphics ( ) - > QuadsBegin ( ) ;
RenderTools ( ) - > SelectSprite ( SPRITE_WEAPON_LASER_BODY ) ;
Graphics ( ) - > QuadsSetSubset ( 0 , 0 , 1 , 1 ) ;
RenderTools ( ) - > DrawSprite ( Section . x , Section . y + Section . h / 2.0f , 60.0f ) ;
Graphics ( ) - > QuadsEnd ( ) ;
}
ColorHSLA CMenus : : DoLine_ColorPicker ( int * pResetID , const float LineSize , const float WantedPickerPosition , const float LabelSize , const float BottomMargin , CUIRect * pMainRect , const char * pText , unsigned int * pColorValue , const ColorRGBA DefaultColor , bool CheckBoxSpacing , bool UseCheckBox , int * pCheckBoxValue )
{
CUIRect Section , Button , Label ;
pMainRect - > HSplitTop ( LineSize , & Section , pMainRect ) ;
pMainRect - > HSplitTop ( BottomMargin , 0x0 , pMainRect ) ;
float SectionWidth = Section . w ;
if ( CheckBoxSpacing | | UseCheckBox )
Section . VSplitLeft ( 20.0f , & Button , & Section ) ;
if ( UseCheckBox )
{
CUIRect CheckBox ;
Button . Margin ( 2.0f , & CheckBox ) ;
if ( DoButton_CheckBox ( pCheckBoxValue , " " , * pCheckBoxValue , & CheckBox ) )
* pCheckBoxValue ^ = 1 ;
}
Section . VSplitLeft ( 5.0f , 0x0 , & Section ) ;
float LabelWidth = TextRender ( ) - > TextWidth ( 0 , 14.0f , pText , - 1 , - 1.0f ) ;
Section . VSplitLeft ( LabelWidth , & Label , & Section ) ;
UI ( ) - > DoLabelScaled ( & Label , pText , LabelSize , - 1 ) ;
float Cut = WantedPickerPosition - ( SectionWidth - Section . w ) ;
if ( Cut < 5 )
Cut = 5.0f ;
Section . VSplitLeft ( Cut , 0x0 , & Section ) ;
Section . VSplitLeft ( LineSize , & Button , & Section ) ;
ColorHSLA PickedColor = RenderHSLColorPicker ( & Button , pColorValue , false ) ;
Section . VSplitLeft ( 7.5f , 0x0 , & Section ) ;
Section . VSplitLeft ( 55.0f , & Button , & Section ) ;
Button . HSplitTop ( 2.0f , 0x0 , & Button ) ;
Button . HSplitBottom ( 2.0f , & Button , 0x0 ) ;
if ( DoButton_Menu ( pResetID , Localize ( " Reset " ) , 0 , & Button , 0 , CUI : : CORNER_ALL , 8.0f , 0 , vec4 ( 1 , 1 , 1 , 0.5f ) , vec4 ( 1 , 1 , 1 , 0.25f ) , 1 , true ) )
{
ColorHSLA HSL = color_cast < ColorHSLA > ( DefaultColor ) ;
* pColorValue = HSL . Pack ( false ) ;
}
return PickedColor ;
}
int CMenus : : DoButton_CheckBoxAutoVMarginAndSet ( const void * pID , const char * pText , int * pValue , CUIRect * pRect , float VMargin )
{
CUIRect CheckBoxRect ;
pRect - > HSplitTop ( VMargin , & CheckBoxRect , pRect ) ;
int Logic = DoButton_CheckBox_Common ( pID , pText , * pValue ? " X " : " " , & CheckBoxRect ) ;
if ( Logic )
* pValue ^ = 1 ;
return Logic ;
}
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
{
2020-09-22 16:02:03 +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
}
2020-12-14 00:51:31 +00:00
int CMenus : : DoValueSelector ( void * pID , CUIRect * pRect , const char * pLabel , bool UseScroll , int Current , int Min , int Max , int Step , float Scale , bool IsHex , float Round , ColorRGBA * Color )
{
// logic
static float s_Value ;
static char s_NumStr [ 64 ] ;
static void * s_LastTextpID = pID ;
int Inside = UI ( ) - > MouseInside ( pRect ) ;
if ( Inside )
UI ( ) - > SetHotItem ( pID ) ;
if ( UI ( ) - > MouseButtonReleased ( 1 ) & & UI ( ) - > HotItem ( ) = = pID )
{
s_LastTextpID = pID ;
ms_ValueSelectorTextMode = true ;
if ( IsHex )
str_format ( s_NumStr , sizeof ( s_NumStr ) , " %06X " , Current ) ;
else
str_format ( s_NumStr , sizeof ( s_NumStr ) , " %d " , Current ) ;
}
if ( UI ( ) - > ActiveItem ( ) = = pID )
{
if ( ! UI ( ) - > MouseButton ( 0 ) )
{
//m_LockMouse = false;
UI ( ) - > SetActiveItem ( 0 ) ;
ms_ValueSelectorTextMode = false ;
}
}
if ( ms_ValueSelectorTextMode & & s_LastTextpID = = pID )
{
static float s_NumberBoxID = 0 ;
DoEditBox ( & s_NumberBoxID , pRect , s_NumStr , sizeof ( s_NumStr ) , 10.0f , & s_NumberBoxID , false , CUI : : CORNER_ALL ) ;
UI ( ) - > SetActiveItem ( & s_NumberBoxID ) ;
if ( Input ( ) - > KeyIsPressed ( KEY_RETURN ) | | Input ( ) - > KeyIsPressed ( KEY_KP_ENTER ) | |
( ( UI ( ) - > MouseButtonClicked ( 1 ) | | UI ( ) - > MouseButtonClicked ( 0 ) ) & & ! Inside ) )
{
if ( IsHex )
Current = clamp ( str_toint_base ( s_NumStr , 16 ) , Min , Max ) ;
else
Current = clamp ( str_toint ( s_NumStr ) , Min , Max ) ;
//m_LockMouse = false;
UI ( ) - > SetActiveItem ( 0 ) ;
ms_ValueSelectorTextMode = false ;
}
if ( Input ( ) - > KeyIsPressed ( KEY_ESCAPE ) )
{
//m_LockMouse = false;
UI ( ) - > SetActiveItem ( 0 ) ;
ms_ValueSelectorTextMode = false ;
}
}
else
{
if ( UI ( ) - > ActiveItem ( ) = = pID )
{
if ( UseScroll )
{
if ( UI ( ) - > MouseButton ( 0 ) )
{
float delta = UI ( ) - > MouseDeltaX ( ) ;
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
s_Value + = delta * 0.05f ;
else
s_Value + = delta ;
if ( absolute ( s_Value ) > Scale )
{
int Count = ( int ) ( s_Value / Scale ) ;
s_Value = fmod ( s_Value , Scale ) ;
Current + = Step * Count ;
Current = clamp ( Current , Min , Max ) ;
// Constrain to discrete steps
if ( Count > 0 )
Current = Current / Step * Step ;
else
Current = round_ceil ( Current / ( float ) Step ) * Step ;
}
}
}
}
else if ( UI ( ) - > HotItem ( ) = = pID )
{
if ( UI ( ) - > MouseButtonClicked ( 0 ) )
{
//m_LockMouse = true;
s_Value = 0 ;
UI ( ) - > SetActiveItem ( pID ) ;
}
}
// render
char aBuf [ 128 ] ;
if ( pLabel [ 0 ] ! = ' \0 ' )
{
if ( IsHex )
str_format ( aBuf , sizeof ( aBuf ) , " %s #%06X " , pLabel , Current ) ;
else
str_format ( aBuf , sizeof ( aBuf ) , " %s %d " , pLabel , Current ) ;
}
else
{
if ( IsHex )
str_format ( aBuf , sizeof ( aBuf ) , " #%06X " , Current ) ;
else
str_format ( aBuf , sizeof ( aBuf ) , " %d " , Current ) ;
}
RenderTools ( ) - > DrawUIRect ( pRect , * Color , CUI : : CORNER_ALL , Round ) ;
UI ( ) - > DoLabel ( pRect , aBuf , 10 , 0 , - 1 ) ;
}
return Current ;
}
2014-12-24 02:38:40 +00:00
int CMenus : : DoEditBox ( void * pID , const CUIRect * pRect , char * pStr , unsigned StrSize , float FontSize , float * Offset , bool Hidden , int Corners , const char * pEmptyText )
2008-08-27 15:48:50 +00:00
{
2021-05-26 13:01:50 +00:00
return m_UIEx . DoEditBox ( pID , pRect , pStr , StrSize , FontSize , Offset , Hidden , Corners , pEmptyText ) ;
2008-08-27 15:48:50 +00:00
}
2018-09-20 05:43:05 +00:00
int CMenus : : DoClearableEditBox ( void * pID , void * pClearID , const CUIRect * pRect , char * pStr , unsigned StrSize , float FontSize , float * Offset , bool Hidden , int Corners , const char * pEmptyText )
{
bool ReturnValue = false ;
CUIRect EditBox ;
CUIRect ClearButton ;
pRect - > VSplitRight ( 15.0f , & EditBox , & ClearButton ) ;
2020-09-16 01:30:03 +00:00
if ( DoEditBox ( pID , & EditBox , pStr , StrSize , FontSize , Offset , Hidden , Corners & ~ CUI : : CORNER_R , pEmptyText ) )
2018-09-20 05:43:05 +00:00
{
ReturnValue = true ;
}
2020-10-06 10:25:10 +00:00
TextRender ( ) - > SetRenderFlags ( ETextRenderFlags : : TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT ) ;
2020-09-20 09:42:30 +00:00
RenderTools ( ) - > DrawUIRect ( & ClearButton , ColorRGBA ( 1 , 1 , 1 , 0.33f * ButtonColorMul ( pClearID ) ) , Corners & ~ CUI : : CORNER_L , 3.0f ) ;
2020-10-06 10:25:10 +00:00
UI ( ) - > DoLabel ( & ClearButton , " × " , ClearButton . h * ms_FontmodHeight , 0 , - 1 , 0 ) ;
TextRender ( ) - > SetRenderFlags ( 0 ) ;
2018-09-20 05:43:05 +00:00
if ( UI ( ) - > DoButtonLogic ( pClearID , " × " , 0 , & ClearButton ) )
{
pStr [ 0 ] = 0 ;
UI ( ) - > SetActiveItem ( pID ) ;
ReturnValue = true ;
}
return ReturnValue ;
}
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 ;
pRect - > HSplitTop ( 33 , & Handle , 0 ) ;
2008-08-27 15:48:50 +00:00
2020-12-14 05:50:20 +00:00
Current = clamp ( Current , 0.0f , 1.0f ) ;
Handle . y = pRect - > 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
2016-05-03 13:11:52 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2021-10-23 11:48:21 +00:00
m_MouseSlow = true ;
2016-05-03 13:11:52 +00:00
2010-05-29 07:25:38 +00:00
float Min = pRect - > y ;
2020-09-22 16:02:03 +00:00
float Max = pRect - > h - Handle . h ;
float Cur = UI ( ) - > MouseY ( ) - OffsetY ;
ReturnValue = ( Cur - Min ) / Max ;
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 ) ;
2020-09-22 16:02:03 +00:00
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
2020-12-14 04:57:57 +00:00
RenderTools ( ) - > DrawUIRect ( pRect , ColorRGBA ( 0 , 0 , 0 , 0.25f ) , CUI : : CORNER_ALL , 5.0f ) ;
2009-10-27 14:38:53 +00:00
2020-09-16 01:30:03 +00:00
float ColorSlider = 0 ;
2011-04-13 18:37:12 +00:00
2020-09-16 01:30:03 +00:00
if ( UI ( ) - > ActiveItem ( ) = = pID )
ColorSlider = 1.0f ;
else if ( UI ( ) - > HotItem ( ) = = pID )
ColorSlider = 0.9f ;
else
ColorSlider = 0.75f ;
2008-08-27 15:48:50 +00:00
2020-12-14 04:57:57 +00:00
RenderTools ( ) - > DrawUIRect ( & Handle , ColorRGBA ( ColorSlider , ColorSlider , ColorSlider , 0.75f ) , CUI : : CORNER_ALL , 5.0f ) ;
2008-08-27 15:48:50 +00:00
2020-09-16 01:30:03 +00:00
return ReturnValue ;
}
2008-08-27 15:48:50 +00:00
2021-05-03 03:59:50 +00:00
float CMenus : : DoScrollbarH ( const void * pID , const CUIRect * pRect , float Current , bool ColorPickerSlider , ColorRGBA * pColorInner )
2008-08-27 15:48:50 +00:00
{
2009-10-27 14:38:53 +00:00
CUIRect Handle ;
static float OffsetX ;
2021-05-03 03:59:50 +00:00
pRect - > VSplitLeft ( ColorPickerSlider ? 8 : 33 , & Handle , 0 ) ;
2008-08-27 15:48:50 +00:00
2020-09-22 16:02:03 +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
2016-05-03 13:11:52 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) | | Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) )
2021-10-23 11:48:21 +00:00
m_MouseSlow = true ;
2016-05-03 13:11:52 +00:00
2010-05-29 07:25:38 +00:00
float Min = pRect - > x ;
2020-09-22 16:02:03 +00:00
float Max = pRect - > w - Handle . w ;
float Cur = UI ( ) - > MouseX ( ) - OffsetX ;
ReturnValue = ( Cur - Min ) / Max ;
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 ) ;
2020-09-22 16:02:03 +00:00
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
2021-05-03 03:59:50 +00:00
if ( ! ColorPickerSlider )
{
CUIRect Rail ;
pRect - > HMargin ( 5.0f , & Rail ) ;
RenderTools ( ) - > DrawUIRect ( & Rail , ColorRGBA ( 1 , 1 , 1 , 0.25f ) , 0 , 0.0f ) ;
CUIRect Slider = Handle ;
Slider . h = Rail . y - Slider . y ;
RenderTools ( ) - > DrawUIRect ( & Slider , ColorRGBA ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_T , 2.5f ) ;
Slider . y = Rail . y + Rail . h ;
RenderTools ( ) - > DrawUIRect ( & Slider , ColorRGBA ( 1 , 1 , 1 , 0.25f ) , CUI : : CORNER_B , 2.5f ) ;
Slider = Handle ;
Slider . Margin ( 5.0f , & Slider ) ;
RenderTools ( ) - > DrawUIRect ( & Slider , ColorRGBA ( 1 , 1 , 1 , 0.25f * ButtonColorMul ( pID ) ) , CUI : : CORNER_ALL , 2.5f ) ;
}
else
{
CUIRect Slider = Handle ;
float MarginW = 4.0f ;
float MarginH = 9.0f ;
Slider . x - = MarginW / 2 ;
Slider . y - = MarginH / 2 ;
Slider . w + = MarginW ;
Slider . h + = MarginH ;
2021-09-25 07:50:11 +00:00
RenderTools ( ) - > DrawUIRect ( & Slider , ColorRGBA ( 0.15f , 0.15f , 0.15f , 1.0f ) , CUI : : CORNER_ALL , 5.0f ) ;
2021-05-03 03:59:50 +00:00
Slider . Margin ( 2 , & Slider ) ;
RenderTools ( ) - > DrawUIRect ( & Slider , * pColorInner , CUI : : CORNER_ALL , 3.0f ) ;
}
2011-04-13 18:37:12 +00:00
return ReturnValue ;
2008-08-27 15:48:50 +00:00
}
2019-04-28 17:22:19 +00:00
int CMenus : : DoKeyReader ( void * pID , const CUIRect * pRect , int Key , int Modifier , int * NewModifier )
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 ;
2019-04-28 17:22:19 +00:00
* NewModifier = Modifier ;
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 )
2019-04-28 17:22:19 +00:00
{
2010-09-12 11:40:24 +00:00
NewKey = m_Binder . m_Key . m_Key ;
2019-04-28 17:22:19 +00:00
* NewModifier = m_Binder . m_Modifier ;
}
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
2018-03-13 20:59:07 +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
{
2019-04-28 17:22:19 +00:00
if ( Key )
{
char aBuf [ 64 ] ;
if ( * NewModifier )
str_format ( aBuf , sizeof ( aBuf ) , " %s+%s " , CBinds : : GetModifierName ( * NewModifier ) , Input ( ) - > KeyName ( Key ) ) ;
else
str_format ( aBuf , sizeof ( aBuf ) , " %s " , Input ( ) - > KeyName ( Key ) ) ;
DoButton_KeySelect ( pID , aBuf , 0 , pRect ) ;
}
2008-08-27 15:48:50 +00:00
else
2019-04-28 17:22:19 +00:00
DoButton_KeySelect ( pID , " " , 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
2020-09-03 12:08:26 +00:00
m_ActivePage = m_MenuPage ;
2010-05-29 07:25:38 +00:00
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
{
2020-09-15 13:31:04 +00:00
Box . VSplitLeft ( 33.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_StartButton = 0 ;
2020-09-15 13:31:04 +00:00
TextRender ( ) - > SetCurFont ( TextRender ( ) - > GetFont ( TEXT_FONT_ICON_FONT ) ) ;
2020-10-06 10:25:10 +00:00
TextRender ( ) - > SetRenderFlags ( ETextRenderFlags : : TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_OVERSIZE ) ;
2020-09-15 13:31:04 +00:00
2020-09-16 01:30:03 +00:00
bool GotNewsOrUpdate = false ;
# if defined(CONF_AUTOUPDATE)
int State = Updater ( ) - > GetCurrentState ( ) ;
bool NeedUpdate = str_comp ( Client ( ) - > LatestVersion ( ) , " 0 " ) ;
if ( State = = IUpdater : : CLEAN & & NeedUpdate )
{
GotNewsOrUpdate = true ;
}
# endif
GotNewsOrUpdate | = ( bool ) g_Config . m_UiUnreadNews ;
ColorRGBA HomeButtonColorAlert ( 0 , 1 , 0 , 0.25f ) ;
ColorRGBA HomeButtonColorAlertHover ( 0 , 1 , 0 , 0.5f ) ;
ColorRGBA * pHomeButtonColor = NULL ;
ColorRGBA * pHomeButtonColorHover = NULL ;
const char * pHomeScreenButtonLabel = " \xEE \xA2 \x8A " ;
if ( GotNewsOrUpdate )
{
pHomeScreenButtonLabel = " \xEE \x80 \xB1 " ;
pHomeButtonColor = & HomeButtonColorAlert ;
pHomeButtonColorHover = & HomeButtonColorAlertHover ;
}
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_StartButton , pHomeScreenButtonLabel , false , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_HOME ] , pHomeButtonColor , pHomeButtonColor , pHomeButtonColorHover , 10.0f , 0 ) )
2014-06-16 11:29:18 +00:00
{
2020-09-05 21:43:39 +00:00
m_ShowStart = true ;
2020-06-19 15:04:35 +00:00
m_DoubleClickIndex = - 1 ;
}
2020-09-15 13:31:04 +00:00
TextRender ( ) - > SetRenderFlags ( 0 ) ;
TextRender ( ) - > SetCurFont ( NULL ) ;
2020-09-15 16:49:43 +00:00
Box . VSplitLeft ( 10.0f , 0 , & Box ) ;
2008-08-27 15:48:50 +00:00
2020-09-05 21:43:39 +00:00
// offline menus
if ( m_ActivePage = = PAGE_NEWS )
2008-08-27 15:48:50 +00:00
{
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_NewsButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_NewsButton , Localize ( " News " ) , m_ActivePage = = PAGE_NEWS , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_NEWS ] ) )
2020-09-05 21:43:39 +00:00
{
NewPage = PAGE_NEWS ;
m_DoubleClickIndex = - 1 ;
}
2008-08-27 15:48:50 +00:00
}
2020-09-05 21:43:39 +00:00
else if ( m_ActivePage = = PAGE_DEMOS )
2008-08-27 15:48:50 +00:00
{
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_DemosButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_DemosButton , Localize ( " Demos " ) , m_ActivePage = = PAGE_DEMOS , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_DEMOS ] ) )
2020-09-05 21:43:39 +00:00
{
DemolistPopulate ( ) ;
NewPage = PAGE_DEMOS ;
m_DoubleClickIndex = - 1 ;
}
2008-08-27 15:48:50 +00:00
}
2020-09-05 21:43:39 +00:00
else
2008-08-27 15:48:50 +00:00
{
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_InternetButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_InternetButton , Localize ( " Internet " ) , m_ActivePage = = PAGE_INTERNET , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_INTERNET ] ) )
2020-09-05 21:43:39 +00:00
{
if ( ServerBrowser ( ) - > GetCurrentType ( ) ! = IServerBrowser : : TYPE_INTERNET )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_INTERNET ) ;
NewPage = PAGE_INTERNET ;
m_DoubleClickIndex = - 1 ;
}
2011-04-13 18:37:12 +00:00
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_LanButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_LanButton , Localize ( " LAN " ) , m_ActivePage = = PAGE_LAN , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_LAN ] ) )
2017-09-03 15:36:51 +00:00
{
2020-09-05 21:43:39 +00:00
if ( ServerBrowser ( ) - > GetCurrentType ( ) ! = IServerBrowser : : TYPE_LAN )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_LAN ) ;
NewPage = PAGE_LAN ;
m_DoubleClickIndex = - 1 ;
2017-09-03 15:36:51 +00:00
}
2014-09-13 14:36:25 +00:00
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 100.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_FavoritesButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_FavoritesButton , Localize ( " Favorites " ) , m_ActivePage = = PAGE_FAVORITES , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_FAVORITES ] ) )
2019-03-24 22:15:38 +00:00
{
2020-09-05 21:43:39 +00:00
if ( ServerBrowser ( ) - > GetCurrentType ( ) ! = IServerBrowser : : TYPE_FAVORITES )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_FAVORITES ) ;
NewPage = PAGE_FAVORITES ;
m_DoubleClickIndex = - 1 ;
2019-03-24 22:15:38 +00:00
}
2020-09-15 16:49:43 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_DDNetButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_DDNetButton , " DDNet " , m_ActivePage = = PAGE_DDNET , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_DDNET ] ) )
2020-09-05 21:43:39 +00:00
{
if ( ServerBrowser ( ) - > GetCurrentType ( ) ! = IServerBrowser : : TYPE_DDNET )
{
Client ( ) - > RequestDDNetInfo ( ) ;
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_DDNET ) ;
}
NewPage = PAGE_DDNET ;
m_DoubleClickIndex = - 1 ;
}
2020-09-15 16:49:43 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
static int s_KoGButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_KoGButton , " KoG " , m_ActivePage = = PAGE_KOG , & Button , CUI : : CORNER_T , & m_aAnimatorsBigPage [ BIG_TAB_KOG ] ) )
2020-09-05 21:43:39 +00:00
{
if ( ServerBrowser ( ) - > GetCurrentType ( ) ! = IServerBrowser : : TYPE_KOG )
{
Client ( ) - > RequestDDNetInfo ( ) ;
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_KOG ) ;
}
NewPage = PAGE_KOG ;
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 ) ;
2020-09-22 16:02:03 +00:00
static int s_GameButton = 0 ;
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 ) ;
2020-09-22 16:02:03 +00:00
static int s_PlayersButton = 0 ;
if ( DoButton_MenuTab ( & s_PlayersButton , Localize ( " Players " ) , m_ActivePage = = PAGE_PLAYERS , & Button , 0 ) )
2011-04-06 18:18:31 +00:00
NewPage = PAGE_PLAYERS ;
Box . VSplitLeft ( 130.0f , & Button , & Box ) ;
2020-09-22 16:02:03 +00:00
static int s_ServerInfoButton = 0 ;
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 ;
2016-04-27 18:14:03 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
2020-09-22 16:02:03 +00:00
static int s_NetworkButton = 0 ;
if ( DoButton_MenuTab ( & s_NetworkButton , Localize ( " Browser " ) , m_ActivePage = = PAGE_NETWORK , & Button , 0 ) )
2016-04-27 18:14:03 +00:00
NewPage = PAGE_NETWORK ;
2016-04-28 20:40:46 +00:00
{
2019-07-18 15:56:01 +00:00
static int s_GhostButton = 0 ;
2019-06-03 19:52:14 +00:00
if ( GameClient ( ) - > m_GameInfo . m_Race )
2016-04-28 20:40:46 +00:00
{
2020-09-05 21:43:39 +00:00
Box . VSplitLeft ( 90.0f , & Button , & Box ) ;
2020-09-10 18:14:47 +00:00
if ( DoButton_MenuTab ( & s_GhostButton , Localize ( " Ghost " ) , m_ActivePage = = PAGE_GHOST , & Button , 0 ) )
2016-04-28 20:40:46 +00:00
NewPage = PAGE_GHOST ;
}
}
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 ) ;
2020-09-22 16:02:03 +00:00
static int s_CallVoteButton = 0 ;
if ( DoButton_MenuTab ( & s_CallVoteButton , Localize ( " Call vote " ) , m_ActivePage = = PAGE_CALLVOTE , & Button , CUI : : CORNER_TR ) )
2021-03-14 18:57:21 +00:00
{
2010-05-29 07:25:38 +00:00
NewPage = PAGE_CALLVOTE ;
2021-03-14 18:57:21 +00:00
m_ControlPageOpening = true ;
}
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2018-03-13 20:59:07 +00:00
TextRender ( ) - > SetCurFont ( TextRender ( ) - > GetFont ( TEXT_FONT_ICON_FONT ) ) ;
2020-10-06 10:25:10 +00:00
TextRender ( ) - > SetRenderFlags ( ETextRenderFlags : : TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT | ETextRenderFlags : : TEXT_RENDER_FLAG_NO_OVERSIZE ) ;
2018-03-13 20:59:07 +00:00
Box . VSplitRight ( 33.0f , & Box , & Button ) ;
2020-09-16 01:30:03 +00:00
static int s_QuitButton = 0 ;
ColorRGBA QuitColor ( 1 , 0 , 0 , 0.5f ) ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_QuitButton , " \xEE \x97 \x8D " , 0 , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_QUIT ] , NULL , NULL , & QuitColor , 10.0f , 0 ) )
2019-03-25 19:02:50 +00:00
{
2019-03-29 13:56:02 +00:00
if ( m_pClient - > Editor ( ) - > HasUnsavedData ( ) | | ( Client ( ) - > GetCurrentRaceTime ( ) / 60 > = g_Config . m_ClConfirmQuitTime & & g_Config . m_ClConfirmQuitTime > = 0 ) )
2019-03-25 19:02:50 +00:00
{
m_Popup = POPUP_QUIT ;
}
else
{
Client ( ) - > Quit ( ) ;
}
}
2010-05-29 07:25:38 +00:00
2014-05-08 12:08:15 +00:00
Box . VSplitRight ( 10.0f , & Box , & Button ) ;
2018-03-13 20:59:07 +00:00
Box . VSplitRight ( 33.0f , & Box , & Button ) ;
2020-09-22 16:02:03 +00:00
static int s_SettingsButton = 0 ;
2019-04-28 17:22:19 +00:00
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_SettingsButton , " \xEE \xA2 \xB8 " , m_ActivePage = = PAGE_SETTINGS , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_SETTINGS ] , NULL , NULL , NULL , 10.0f , 0 ) )
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 ) ;
2018-03-13 20:59:07 +00:00
Box . VSplitRight ( 33.0f , & Box , & Button ) ;
2020-09-22 16:02:03 +00:00
static int s_EditorButton = 0 ;
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_EditorButton , " \xEE \x8F \x89 " , 0 , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_EDITOR ] , NULL , NULL , NULL , 10.0f , 0 ) )
2014-07-08 18:21:19 +00:00
{
g_Config . m_ClEditor = 1 ;
}
2020-09-16 00:14:11 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE )
{
Box . VSplitRight ( 10.0f , & Box , & Button ) ;
Box . VSplitRight ( 33.0f , & Box , & Button ) ;
static int s_DemoButton = 0 ;
2020-09-15 13:31:04 +00:00
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_DemoButton , " \xEE \x80 \xAC " , m_ActivePage = = PAGE_DEMOS , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_DEMOBUTTON ] , NULL , NULL , NULL , 10.0f , 0 ) )
2020-09-16 00:14:11 +00:00
NewPage = PAGE_DEMOS ;
2020-09-15 13:31:04 +00:00
2020-09-16 00:14:11 +00:00
Box . VSplitRight ( 10.0f , & Box , & Button ) ;
Box . VSplitRight ( 33.0f , & Box , & Button ) ;
static int s_ServerButton = 0 ;
2020-09-15 13:31:04 +00:00
2020-10-26 02:48:05 +00:00
if ( DoButton_MenuTab ( & s_ServerButton , " \xEE \xA0 \x8B " , m_ActivePage = = g_Config . m_UiPage , & Button , CUI : : CORNER_T , & m_aAnimatorsSmallPage [ SMALL_TAB_SERVER ] , NULL , NULL , NULL , 10.0f , 0 ) )
2020-09-16 00:14:11 +00:00
NewPage = g_Config . m_UiPage ;
}
2020-09-15 13:31:04 +00:00
2018-03-13 20:59:07 +00:00
TextRender ( ) - > SetRenderFlags ( 0 ) ;
TextRender ( ) - > SetCurFont ( NULL ) ;
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 )
2020-09-03 12:08:26 +00:00
SetMenuPage ( 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
2021-06-23 05:05:49 +00:00
static int64_t LastLoadRender = 0 ;
2020-09-22 16:02: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
2020-09-22 16:02:03 +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
2019-04-26 23:02:31 +00:00
ms_GuiColor = color_cast < ColorRGBA > ( ColorHSLA ( g_Config . m_UiColor , true ) ) ;
2011-04-13 18:37:12 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-12-14 00:20:47 +00:00
2020-09-18 16:45:42 +00:00
if ( ! m_pBackground - > Render ( ) )
{
RenderBackground ( ) ;
}
2008-08-27 15:48:50 +00:00
float w = 700 ;
float h = 200 ;
2020-09-22 16:02:03 +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
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
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 ;
2020-09-22 16:02:03 +00:00
r . y = y + 20 ;
2008-08-27 15:48:50 +00:00
r . w = w ;
2018-03-13 20:59:07 +00:00
r . h = h - 130 ;
2010-05-29 07:25:38 +00:00
UI ( ) - > DoLabel ( & r , pCaption , 48.0f , 0 , - 1 ) ;
2008-08-27 15:48:50 +00:00
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 0.75f ) ;
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
{
2020-09-03 12:08:26 +00:00
g_Config . m_UiUnreadNews = false ;
2019-03-24 22:15:38 +00:00
RenderTools ( ) - > DrawUIRect ( & MainView , ms_ColorTabbarActive , CUI : : CORNER_B , 10.0f ) ;
2014-06-05 10:11:41 +00:00
MainView . HSplitTop ( 15.0f , 0 , & MainView ) ;
MainView . VSplitLeft ( 15.0f , 0 , & MainView ) ;
CUIRect Label ;
2019-04-29 20:55:12 +00:00
const char * pStr = Client ( ) - > m_aNews ;
char aLine [ 256 ] ;
while ( ( pStr = str_next_token ( pStr , " \n " , aLine , sizeof ( aLine ) ) ) )
2014-06-05 10:11:41 +00:00
{
2019-04-29 20:55:12 +00:00
const int Len = str_length ( aLine ) ;
2020-09-22 16:02:03 +00:00
if ( Len > 0 & & aLine [ 0 ] = = ' | ' & & aLine [ Len - 1 ] = = ' | ' )
2014-06-05 10:11:41 +00:00
{
MainView . HSplitTop ( 30.0f , & Label , & MainView ) ;
2020-09-22 16:02:03 +00:00
aLine [ Len - 1 ] = ' \0 ' ;
2019-04-29 20:55:12 +00:00
UI ( ) - > DoLabelScaled ( & Label , aLine + 1 , 20.0f , - 1 ) ;
2014-06-05 10:11:41 +00:00
}
else
{
MainView . HSplitTop ( 20.0f , & Label , & MainView ) ;
2020-06-14 09:38:52 +00:00
UI ( ) - > DoLabelScaled ( & Label , aLine , 15.f , - 1 , - 1 ) ;
2014-06-05 10:11:41 +00:00
}
}
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
{
2010-05-29 07:25:38 +00:00
if ( g_Config . m_ClShowWelcome )
2010-12-12 18:20:30 +00:00
m_Popup = POPUP_LANGUAGE ;
2020-09-03 12:08:26 +00:00
if ( g_Config . m_ClSkipStartMenu )
m_ShowStart = false ;
2010-07-04 14:10:00 +00:00
2021-05-31 09:43:02 +00:00
m_UIEx . Init ( UI ( ) , Kernel ( ) , RenderTools ( ) , m_aInputEvents , & m_NumInputEvents ) ;
2021-05-26 13:01:50 +00:00
2021-09-13 21:48:10 +00:00
m_RefreshButton . Init ( UI ( ) , - 1 ) ;
m_ConnectButton . Init ( UI ( ) , - 1 ) ;
2020-10-12 10:29:47 +00:00
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
2021-04-11 12:34:08 +00:00
Console ( ) - > Chain ( " cl_assets_entities " , ConchainAssetsEntities , this ) ;
Console ( ) - > Chain ( " cl_asset_game " , ConchainAssetGame , this ) ;
Console ( ) - > Chain ( " cl_asset_emoticons " , ConchainAssetEmoticons , this ) ;
Console ( ) - > Chain ( " cl_asset_particles " , ConchainAssetParticles , this ) ;
2012-08-12 10:41:50 +00:00
m_TextureBlob = Graphics ( ) - > LoadTexture ( " blob.png " , IStorage : : TYPE_ALL , CImageInfo : : FORMAT_AUTO , 0 ) ;
2011-02-27 16:56:03 +00:00
// setup load amount
2020-09-10 20:56:59 +00:00
const int NumMenuImages = 5 ;
2011-02-27 16:56:03 +00:00
m_LoadCurrent = 0 ;
2020-09-10 20:56:59 +00:00
m_LoadTotal = g_pData - > m_NumImages + NumMenuImages ;
2011-02-27 16:56:03 +00:00
if ( ! g_Config . m_ClThreadsoundloading )
m_LoadTotal + = g_pData - > m_NumSounds ;
2020-09-10 20:56:59 +00:00
// load menu images
m_lMenuImages . clear ( ) ;
Storage ( ) - > ListDirectory ( IStorage : : TYPE_ALL , " menuimages " , MenuImageScan , this ) ;
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 ) ) ;
2020-09-05 14:54:20 +00:00
m_Popup = POPUP_MESSAGE ;
2009-06-15 13:16:33 +00:00
}
2021-06-23 05:05:49 +00:00
void CMenus : : PopupWarning ( const char * pTopic , const char * pBody , const char * pButton , int64_t Duration )
2020-08-29 10:49:45 +00:00
{
2020-10-02 13:43:52 +00:00
dbg_msg ( pTopic , " %s " , pBody ) ;
2020-08-29 10:49:45 +00:00
// reset active item
UI ( ) - > SetActiveItem ( 0 ) ;
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_WARNING ;
SetActive ( true ) ;
m_PopupWarningDuration = Duration ;
m_PopupWarningLastTime = time_get_microseconds ( ) ;
}
bool CMenus : : CanDisplayWarning ( )
{
2020-10-02 13:43:52 +00:00
return m_Popup = = POPUP_NONE ;
2020-08-29 10:49:45 +00:00
}
2009-06-15 13:16:33 +00:00
2020-10-28 02:59:50 +00:00
void CMenus : : RenderColorPicker ( )
{
2021-02-01 22:49:42 +00:00
if ( m_EscapePressed )
{
ms_ColorPicker . m_Active = false ;
ms_ValueSelectorTextMode = false ;
UI ( ) - > SetActiveItem ( 0 ) ;
}
2020-10-28 02:59:50 +00:00
if ( ! ms_ColorPicker . m_Active )
return ;
// First check if we should disable color picker
CUIRect PickerRect ;
PickerRect . x = ms_ColorPicker . m_X ;
PickerRect . y = ms_ColorPicker . m_Y ;
PickerRect . w = ms_ColorPicker . ms_Width ;
PickerRect . h = ms_ColorPicker . ms_Height ;
2020-10-29 00:55:01 +00:00
2020-12-14 00:51:31 +00:00
if ( UI ( ) - > MouseButtonClicked ( 0 ) & & ! UI ( ) - > MouseInside ( & PickerRect ) & & ! UI ( ) - > MouseInside ( & ms_ColorPicker . m_AttachedRect ) )
2020-10-28 02:59:50 +00:00
{
ms_ColorPicker . m_Active = false ;
2020-12-14 00:51:31 +00:00
ms_ValueSelectorTextMode = false ;
UI ( ) - > SetActiveItem ( 0 ) ;
2020-10-28 02:59:50 +00:00
return ;
}
// Render
2020-12-14 00:51:31 +00:00
ColorRGBA BackgroundColor ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
2020-10-28 02:59:50 +00:00
RenderTools ( ) - > DrawUIRect ( & PickerRect , BackgroundColor , 0 , 0 ) ;
2020-12-14 00:51:31 +00:00
CUIRect ColorsArea , HueArea , ValuesHitbox , BottomArea , HSVHRect , HSVSRect , HSVVRect , HEXRect , ALPHARect ;
2020-10-28 02:59:50 +00:00
PickerRect . Margin ( 3 , & ColorsArea ) ;
2020-12-14 00:51:31 +00:00
ColorsArea . HSplitBottom ( ms_ColorPicker . ms_Height - 140.0f , & ColorsArea , & ValuesHitbox ) ;
2020-10-28 02:59:50 +00:00
ColorsArea . VSplitRight ( 20 , & ColorsArea , & HueArea ) ;
2020-12-14 00:51:31 +00:00
BottomArea = ValuesHitbox ;
2020-10-28 02:59:50 +00:00
BottomArea . HSplitTop ( 3 , 0x0 , & BottomArea ) ;
HueArea . VSplitLeft ( 3 , 0x0 , & HueArea ) ;
2020-12-14 00:51:31 +00:00
BottomArea . HSplitTop ( 20 , & HSVHRect , & BottomArea ) ;
BottomArea . HSplitTop ( 3 , 0x0 , & BottomArea ) ;
constexpr float ValuePadding = 5.0f ;
const float HSVValueWidth = ( HSVHRect . w - ValuePadding * 2 ) / 3.0f ;
const float HEXValueWidth = HSVValueWidth * 2 + ValuePadding ;
HSVHRect . VSplitLeft ( HSVValueWidth , & HSVHRect , & HSVSRect ) ;
HSVSRect . VSplitLeft ( ValuePadding , 0x0 , & HSVSRect ) ;
HSVSRect . VSplitLeft ( HSVValueWidth , & HSVSRect , & HSVVRect ) ;
HSVVRect . VSplitLeft ( ValuePadding , 0x0 , & HSVVRect ) ;
BottomArea . HSplitTop ( 20 , & HEXRect , & BottomArea ) ;
HEXRect . VSplitLeft ( HEXValueWidth , & HEXRect , & ALPHARect ) ;
ALPHARect . VSplitLeft ( ValuePadding , 0x0 , & ALPHARect ) ;
2020-10-28 02:59:50 +00:00
2020-12-14 00:51:31 +00:00
if ( UI ( ) - > MouseButtonReleased ( 1 ) & & ! UI ( ) - > MouseInside ( & ValuesHitbox ) )
{
ms_ColorPicker . m_Active = false ;
ms_ValueSelectorTextMode = false ;
UI ( ) - > SetActiveItem ( 0 ) ;
return ;
}
ColorRGBA BlackColor ( 0 , 0 , 0 , 0.5f ) ;
RenderTools ( ) - > DrawUIRect ( & HueArea , BlackColor , 0 , 0 ) ;
2020-10-28 02:59:50 +00:00
HueArea . Margin ( 1 , & HueArea ) ;
2020-12-14 00:51:31 +00:00
RenderTools ( ) - > DrawUIRect ( & ColorsArea , BlackColor , 0 , 0 ) ;
2020-10-28 02:59:50 +00:00
ColorsArea . Margin ( 1 , & ColorsArea ) ;
2020-12-14 00:51:31 +00:00
unsigned int H = ms_ColorPicker . m_HSVColor / ( 1 < < 16 ) ;
unsigned int S = ( ms_ColorPicker . m_HSVColor - ( H < < 16 ) ) / ( 1 < < 8 ) ;
unsigned int V = ms_ColorPicker . m_HSVColor % ( 1 < < 8 ) ;
ColorHSVA PickerColorHSV ( ms_ColorPicker . m_HSVColor ) ;
2020-10-28 02:59:50 +00:00
// Color Area
ColorRGBA rgb ;
2020-12-14 00:51:31 +00:00
rgb = color_cast < ColorRGBA , ColorHSVA > ( ColorHSVA ( PickerColorHSV . x , 0.0f , 1.0f ) ) ;
2020-10-28 02:59:50 +00:00
vec4 TL ( rgb . r , rgb . g , rgb . b , 1.0f ) ;
2020-12-14 00:51:31 +00:00
rgb = color_cast < ColorRGBA , ColorHSVA > ( ColorHSVA ( PickerColorHSV . x , 1.0f , 1.0f ) ) ;
2020-10-28 02:59:50 +00:00
vec4 TR ( rgb . r , rgb . g , rgb . b , 1.0f ) ;
2020-12-14 00:51:31 +00:00
rgb = color_cast < ColorRGBA , ColorHSVA > ( ColorHSVA ( PickerColorHSV . x , 0.0f , 1.0f ) ) ;
2020-10-28 02:59:50 +00:00
vec4 BL ( rgb . r , rgb . g , rgb . b , 1.0f ) ;
2020-12-14 00:51:31 +00:00
rgb = color_cast < ColorRGBA , ColorHSVA > ( ColorHSVA ( PickerColorHSV . x , 1.0f , 1.0f ) ) ;
2020-10-28 02:59:50 +00:00
vec4 BR ( rgb . r , rgb . g , rgb . b , 1.0f ) ;
RenderTools ( ) - > DrawUIRect4NoRounding ( & ColorsArea , TL , TR , BL , BR ) ;
TL = vec4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
TR = vec4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
BL = vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ;
BR = vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ;
RenderTools ( ) - > DrawUIRect4NoRounding ( & ColorsArea , TL , TR , BL , BR ) ;
// Hue Area
static const float s_aColorIndices [ 7 ] [ 3 ] = {
{ 1.0f , 0.0f , 0.0f } , // red
{ 1.0f , 0.0f , 1.0f } , // magenta
{ 0.0f , 0.0f , 1.0f } , // blue
{ 0.0f , 1.0f , 1.0f } , // cyan
{ 0.0f , 1.0f , 0.0f } , // green
{ 1.0f , 1.0f , 0.0f } , // yellow
{ 1.0f , 0.0f , 0.0f } // red
} ;
float HuePickerOffset = HueArea . h / 6.0f ;
CUIRect HuePartialArea = HueArea ;
HuePartialArea . h = HuePickerOffset ;
for ( int j = 0 ; j < 6 ; j + + )
{
TL = vec4 ( s_aColorIndices [ j ] [ 0 ] , s_aColorIndices [ j ] [ 1 ] , s_aColorIndices [ j ] [ 2 ] , 1.0f ) ;
BL = vec4 ( s_aColorIndices [ j + 1 ] [ 0 ] , s_aColorIndices [ j + 1 ] [ 1 ] , s_aColorIndices [ j + 1 ] [ 2 ] , 1.0f ) ;
HuePartialArea . y = HueArea . y + HuePickerOffset * j ;
RenderTools ( ) - > DrawUIRect4NoRounding ( & HuePartialArea , TL , TL , BL , BL ) ;
}
2020-12-14 00:51:31 +00:00
//Editboxes Area
ColorRGBA EditboxBackground ( 0 , 0 , 0 , 0.4f ) ;
static int RGBRID = 0 ;
static int RGBGID = 0 ;
static int RGBBID = 0 ;
H = DoValueSelector ( & RGBRID , & HSVHRect , " H: " , true , H , 0 , 255 , 1 , 1 , false , 5.0f , & EditboxBackground ) ;
S = DoValueSelector ( & RGBGID , & HSVSRect , " S: " , true , S , 0 , 255 , 1 , 1 , false , 5.0f , & EditboxBackground ) ;
V = DoValueSelector ( & RGBBID , & HSVVRect , " V: " , true , V , 0 , 255 , 1 , 1 , false , 5.0f , & EditboxBackground ) ;
PickerColorHSV = ColorHSVA ( ( H < < 16 ) + ( S < < 8 ) + V ) ;
2020-10-28 02:59:50 +00:00
2020-12-14 00:51:31 +00:00
unsigned int HEX = color_cast < ColorRGBA , ColorHSVA > ( PickerColorHSV ) . Pack ( false ) ;
static int HEXID = 0 ;
2020-10-28 02:59:50 +00:00
2020-12-14 00:51:31 +00:00
unsigned int NEWHEX = DoValueSelector ( & HEXID , & HEXRect , " HEX: " , false , HEX , 0 , 0xFFFFFF , 1 , 1 , true , 5.0f , & EditboxBackground ) ;
if ( HEX ! = NEWHEX )
PickerColorHSV = color_cast < ColorHSVA , ColorRGBA > ( NEWHEX ) ;
// TODO : ALPHA SUPPORT
2020-12-14 01:18:04 +00:00
//static int ALPHAID = 0;
2020-12-14 00:51:31 +00:00
UI ( ) - > DoLabel ( & ALPHARect , " A: 255 " , 10 , 0 , - 1 ) ;
RenderTools ( ) - > DrawUIRect ( & ALPHARect , ColorRGBA ( 0 , 0 , 0 , 0.65f ) , CUI : : CORNER_ALL , 5.0f ) ;
2020-10-28 02:59:50 +00:00
// Logic
float PickerX , PickerY ;
2020-12-14 01:49:24 +00:00
static int ColorPickerID = 0 ;
static int HuePickerID = 0 ;
if ( UI ( ) - > DoPickerLogic ( & ColorPickerID , & ColorsArea , & PickerX , & PickerY ) )
2020-10-28 02:59:50 +00:00
{
2020-12-14 00:51:31 +00:00
PickerColorHSV . y = PickerX / ColorsArea . w ;
PickerColorHSV . z = 1.0f - PickerY / ColorsArea . h ;
2020-10-28 02:59:50 +00:00
}
2020-12-14 01:49:24 +00:00
if ( UI ( ) - > DoPickerLogic ( & HuePickerID , & HueArea , & PickerX , & PickerY ) )
2020-12-14 00:51:31 +00:00
PickerColorHSV . x = 1.0f - PickerY / HueArea . h ;
2020-10-28 02:59:50 +00:00
// Marker Color Area
2020-12-14 00:51:31 +00:00
float MarkerX = ColorsArea . x + ColorsArea . w * PickerColorHSV . y ;
float MarkerY = ColorsArea . y + ColorsArea . h * ( 1.0f - PickerColorHSV . z ) ;
2020-10-28 02:59:50 +00:00
2020-12-14 00:51:31 +00:00
int MarkerOutlineInd = PickerColorHSV . z > 0.5f ? 0.0f : 1.0f ;
2020-10-28 02:59:50 +00:00
ColorRGBA MarkerOutline ( MarkerOutlineInd , MarkerOutlineInd , MarkerOutlineInd , 1.0f ) ;
2020-12-14 00:51:31 +00:00
Graphics ( ) - > TextureClear ( ) ;
2020-10-28 02:59:50 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( MarkerOutline ) ;
2020-12-14 00:51:31 +00:00
RenderTools ( ) - > DrawCircle ( MarkerX , MarkerY , 4.5f , 32 ) ;
Graphics ( ) - > SetColor ( color_cast < ColorRGBA , ColorHSVA > ( PickerColorHSV ) ) ;
RenderTools ( ) - > DrawCircle ( MarkerX , MarkerY , 3.5f , 32 ) ;
2020-10-28 02:59:50 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2020-10-29 00:55:01 +00:00
// Marker Hue Area
CUIRect HueMarker ;
HueArea . Margin ( - 2.5f , & HueMarker ) ;
2020-12-14 00:51:31 +00:00
HueMarker . h = 6.5f ;
HueMarker . y = ( HueArea . y + HueArea . h * ( 1.0f - PickerColorHSV . x ) ) - HueMarker . h / 2.0f ;
2020-10-29 00:55:01 +00:00
2020-12-14 00:51:31 +00:00
ColorRGBA HueMarkerColor = color_cast < ColorRGBA , ColorHSVA > ( ColorHSVA ( PickerColorHSV . x , 1 , 1 , 1 ) ) ;
const float HMOColor = PickerColorHSV . x > 0.75f ? 1.0f : 0.0f ;
ColorRGBA HueMarkerOutline ( HMOColor , HMOColor , HMOColor , 1 ) ;
2020-10-29 00:55:01 +00:00
2020-12-14 00:51:31 +00:00
RenderTools ( ) - > DrawUIRect ( & HueMarker , HueMarkerOutline , CUI : : CORNER_ALL , 1.2f ) ;
HueMarker . Margin ( 1.2f , & HueMarker ) ;
RenderTools ( ) - > DrawUIRect ( & HueMarker , HueMarkerColor , CUI : : CORNER_ALL , 1.2f ) ;
2020-10-29 00:55:01 +00:00
2020-12-14 00:51:31 +00:00
ms_ColorPicker . m_HSVColor = PickerColorHSV . Pack ( false ) ;
* ms_ColorPicker . m_pColor = color_cast < ColorHSLA , ColorHSVA > ( PickerColorHSV ) . Pack ( false ) ;
2020-10-28 02:59:50 +00:00
}
2010-05-29 07:25:38 +00:00
int CMenus : : Render ( )
2008-08-27 15:48:50 +00:00
{
2020-08-29 10:49:45 +00:00
if ( Client ( ) - > State ( ) = = IClient : : STATE_DEMOPLAYBACK & & m_Popup = = POPUP_NONE )
return 0 ;
2011-04-13 18:37:12 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2008-08-27 15:48:50 +00:00
2021-10-23 11:48:21 +00:00
m_MouseSlow = false ;
2016-05-03 13:11:52 +00:00
2016-06-03 17:50:49 +00:00
static int s_Frame = 0 ;
if ( s_Frame = = 0 )
{
2020-09-03 12:08:26 +00:00
m_MenuPage = g_Config . m_UiPage ;
2016-06-03 17:50:49 +00:00
s_Frame + + ;
}
else if ( s_Frame = = 1 )
2008-08-27 15:48:50 +00:00
{
2021-07-12 09:43:56 +00:00
m_pClient - > m_Sounds . Enqueue ( CSounds : : CHN_MUSIC , SOUND_MENU ) ;
2016-06-03 17:50:49 +00:00
s_Frame + + ;
2014-09-20 14:20:27 +00:00
m_DoubleClickIndex = - 1 ;
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 ) ;
2014-09-13 14:36:25 +00:00
else if ( g_Config . m_UiPage = = PAGE_DDNET )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_DDNET ) ;
2019-03-24 22:15:38 +00:00
else if ( g_Config . m_UiPage = = PAGE_KOG )
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_KOG ) ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2020-08-29 10:49:45 +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 ;
2020-09-16 01:30:03 +00:00
ms_ColorTabbarHover = ms_ColorTabbarHoverIngame ;
2008-08-27 15:48:50 +00:00
}
else
{
2020-09-18 16:45:42 +00:00
if ( ! m_pBackground - > Render ( ) )
{
RenderBackground ( ) ;
}
2010-05-29 07:25:38 +00:00
ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame ;
ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame ;
2020-09-16 01:30:03 +00:00
ms_ColorTabbarHover = ms_ColorTabbarHoverOutgame ;
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
{
2020-09-03 12:08:26 +00:00
if ( m_ShowStart & & Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE )
2020-09-18 16:45:42 +00:00
{
m_pBackground - > ChangePosition ( CMenuBackground : : POS_START ) ;
2020-09-03 12:08:26 +00:00
RenderStartMenu ( Screen ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else
2008-10-01 18:40:09 +00:00
{
2020-09-03 12:08:26 +00:00
Screen . HSplitTop ( 24.0f , & TabBar , & MainView ) ;
if ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE & & m_EscapePressed )
{
m_ShowStart = true ;
}
2011-04-13 18:37:12 +00:00
2020-09-03 12:08:26 +00:00
// render news
if ( m_MenuPage < PAGE_NEWS | | m_MenuPage > PAGE_SETTINGS | | ( Client ( ) - > State ( ) = = IClient : : STATE_OFFLINE & & m_MenuPage > = PAGE_GAME & & m_MenuPage < = PAGE_CALLVOTE ) )
{
ServerBrowser ( ) - > Refresh ( IServerBrowser : : TYPE_INTERNET ) ;
SetMenuPage ( PAGE_INTERNET ) ;
m_DoubleClickIndex = - 1 ;
}
// render current page
if ( Client ( ) - > State ( ) ! = IClient : : STATE_OFFLINE )
{
if ( m_GamePage = = PAGE_GAME )
RenderGame ( MainView ) ;
else if ( m_GamePage = = PAGE_PLAYERS )
RenderPlayers ( MainView ) ;
else if ( m_GamePage = = PAGE_SERVER_INFO )
RenderServerInfo ( MainView ) ;
else if ( m_GamePage = = PAGE_NETWORK )
RenderInGameNetwork ( MainView ) ;
else if ( m_GamePage = = PAGE_GHOST )
RenderGhost ( MainView ) ;
else if ( m_GamePage = = PAGE_CALLVOTE )
RenderServerControl ( MainView ) ;
else if ( m_GamePage = = PAGE_SETTINGS )
RenderSettings ( MainView ) ;
}
else if ( m_MenuPage = = PAGE_NEWS )
2020-09-18 16:45:42 +00:00
{
m_pBackground - > ChangePosition ( CMenuBackground : : POS_NEWS ) ;
2020-09-03 12:08:26 +00:00
RenderNews ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_INTERNET )
2020-09-18 16:45:42 +00:00
{
2020-09-26 07:37:35 +00:00
m_pBackground - > ChangePosition ( CMenuBackground : : POS_BROWSER_INTERNET ) ;
2020-09-03 12:08:26 +00:00
RenderServerbrowser ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_LAN )
2020-09-18 16:45:42 +00:00
{
2020-09-26 07:37:35 +00:00
m_pBackground - > ChangePosition ( CMenuBackground : : POS_BROWSER_LAN ) ;
2020-09-03 12:08:26 +00:00
RenderServerbrowser ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_DEMOS )
2020-09-18 16:45:42 +00:00
{
m_pBackground - > ChangePosition ( CMenuBackground : : POS_DEMOS ) ;
2020-09-03 12:08:26 +00:00
RenderDemoList ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_FAVORITES )
2020-09-18 16:45:42 +00:00
{
2020-09-26 07:37:35 +00:00
m_pBackground - > ChangePosition ( CMenuBackground : : POS_BROWSER_FAVORITES ) ;
2020-09-03 12:08:26 +00:00
RenderServerbrowser ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_DDNET )
2020-09-18 16:45:42 +00:00
{
2020-09-26 07:37:35 +00:00
m_pBackground - > ChangePosition ( CMenuBackground : : POS_BROWSER_CUSTOM0 ) ;
2020-09-03 12:08:26 +00:00
RenderServerbrowser ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_KOG )
2020-09-18 16:45:42 +00:00
{
2020-09-26 07:37:35 +00:00
m_pBackground - > ChangePosition ( CMenuBackground : : POS_BROWSER_CUSTOM0 + 1 ) ;
2020-09-03 12:08:26 +00:00
RenderServerbrowser ( MainView ) ;
2020-09-18 16:45:42 +00:00
}
2020-09-03 12:08:26 +00:00
else if ( m_MenuPage = = PAGE_SETTINGS )
2010-05-29 07:25:38 +00:00
RenderSettings ( MainView ) ;
2020-10-28 02:59:50 +00:00
2020-09-03 12:08:26 +00:00
// do tab bar
RenderMenubar ( TabBar ) ;
}
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);
2020-06-26 16:17:20 +00:00
char aBuf [ 1536 ] ;
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
2021-09-25 07:50:11 +00:00
ColorRGBA BgColor = ColorRGBA ( 0.0f , 0.0f , 0.0f , 0.5f ) ;
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
}
}
2018-03-13 20:59:07 +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 " ) ;
2016-05-04 16:23:00 +00:00
if ( Client ( ) - > m_ReconnectTime > 0 )
2014-06-26 22:28:57 +00:00
{
2020-06-26 16:17:20 +00:00
str_format ( aBuf , sizeof ( aBuf ) , Localize ( " Reconnect in %d sec " ) , ( int ) ( ( Client ( ) - > m_ReconnectTime - time_get ( ) ) / time_freq ( ) ) ) ;
2016-05-04 16:23:00 +00:00
pTitle = Client ( ) - > ErrorString ( ) ;
pExtraText = aBuf ;
pButtonText = Localize ( " Abort " ) ;
2014-06-26 22:28:57 +00:00
}
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 ;
}
2020-09-22 16:02:03 +00:00
# if defined(CONF_VIDEORECORDER)
2019-09-27 03:06:02 +00:00
else if ( m_Popup = = POPUP_RENDER_DEMO )
{
pTitle = Localize ( " Render demo " ) ;
pExtraText = " " ;
ExtraAlign = - 1 ;
}
2019-09-27 06:51:08 +00:00
else if ( m_Popup = = POPUP_REPLACE_VIDEO )
{
pTitle = Localize ( " Replace video " ) ;
2019-11-03 03:20:24 +00:00
pExtraText = Localize ( " File already exists, do you want to overwrite it? " ) ;
2019-09-27 06:51:08 +00:00
ExtraAlign = - 1 ;
}
2020-09-22 16:02:03 +00:00
# endif
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 ;
}
2019-03-30 15:59:25 +00:00
else if ( m_Popup = = POPUP_DISCONNECT_DUMMY )
{
pTitle = Localize ( " Disconnect Dummy " ) ;
pExtraText = Localize ( " Are you sure that you want to disconnect your dummy? " ) ;
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
{
2017-09-07 18:51:46 +00:00
pTitle = Localize ( " Welcome to DDNet " ) ;
2020-08-18 08:32:44 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %s \n \n %s \n \n %s \n \n %s \n \n %s \n \n %s \n \n %s \n \n %s " ,
2020-06-26 16:17:20 +00:00
Localize ( " DDraceNetwork is a cooperative online game where the goal is for you and your group of tees to reach the finish line of the map. As a newcomer you should start on Novice servers, which host the easiest maps. Consider the ping to choose a server close to you. " ) ,
Localize ( " The maps contain freeze, which temporarily make a tee unable to move. You have to work together to get through these parts. " ) ,
Localize ( " The mouse wheel changes weapons. Hammer (left mouse) can be used to hit other tees and wake them up from being frozen. " ) ,
Localize ( " Hook (right mouse) can be used to swing through the map and to hook other tees to you. " ) ,
Localize ( " Most importantly communication is key: There is no tutorial so you'll have to chat (t key) with other players to learn the basics and tricks of the game. " ) ,
2020-08-18 08:32:44 +00:00
Localize ( " Use k key to kill (restart), q to pause and watch other players. See settings for other key binds. " ) ,
2020-06-26 16:17:20 +00:00
Localize ( " It's recommended that you check the settings to adjust them to your liking before joining a server. " ) ,
2020-11-05 08:32:14 +00:00
Localize ( " Please enter your nickname below. " ) ) ;
2020-06-26 16:17:20 +00:00
pExtraText = aBuf ;
2010-05-29 07:25:38 +00:00
pButtonText = Localize ( " Ok " ) ;
ExtraAlign = - 1 ;
2008-08-27 15:48:50 +00:00
}
2020-10-23 21:25:58 +00:00
else if ( m_Popup = = POPUP_POINTS )
{
pTitle = Localize ( " Existing Player " ) ;
if ( Client ( ) - > m_Points > 50 )
{
2020-11-05 08:32:14 +00:00
str_format ( aBuf , sizeof ( aBuf ) , Localize ( " Your nickname '%s' is already used (%d points). Do you still want to use it? " ) , Client ( ) - > PlayerName ( ) , Client ( ) - > m_Points ) ;
2020-10-23 21:25:58 +00:00
pExtraText = aBuf ;
}
else if ( Client ( ) - > m_Points > = 0 )
{
m_Popup = POPUP_NONE ;
}
else
{
pExtraText = Localize ( " Checking for existing player with your name " ) ;
}
ExtraAlign = - 1 ;
}
2020-08-29 10:49:45 +00:00
else if ( m_Popup = = POPUP_WARNING )
{
2021-09-25 07:50:11 +00:00
BgColor = ColorRGBA ( 0.5f , 0.0f , 0.0f , 0.7f ) ;
2020-08-29 10:49:45 +00:00
pTitle = m_aMessageTopic ;
pExtraText = m_aMessageBody ;
pButtonText = m_aMessageButton ;
ExtraAlign = - 1 ;
}
2021-06-26 11:39:14 +00:00
else if ( m_Popup = = POPUP_SWITCH_SERVER )
{
pTitle = Localize ( " Disconnect " ) ;
pExtraText = Localize ( " Are you sure that you want to disconnect and switch to a different server? " ) ;
ExtraAlign = - 1 ;
}
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 ;
2020-06-19 09:53:26 +00:00
if ( m_Popup ! = POPUP_FIRST_LAUNCH )
{
2020-09-22 16:02:03 +00:00
Box . VMargin ( 150.0f / UI ( ) - > Scale ( ) , & Box ) ;
Box . HMargin ( 150.0f / UI ( ) - > Scale ( ) , & Box ) ;
2020-06-19 09:53:26 +00:00
}
2011-04-13 18:37:12 +00:00
2008-08-27 15:48:50 +00:00
// render the box
2020-08-29 10:49:45 +00:00
RenderTools ( ) - > DrawUIRect ( & Box , BgColor , CUI : : CORNER_ALL , 15.0f ) ;
2011-04-13 18:37:12 +00:00
2020-09-22 16:02:03 +00:00
Box . HSplitTop ( 20.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
Box . HSplitTop ( 24.f / UI ( ) - > Scale ( ) , & Part , & Box ) ;
Part . VMargin ( 20.f / UI ( ) - > Scale ( ) , & Part ) ;
2020-07-15 19:10:13 +00:00
if ( TextRender ( ) - > TextWidth ( 0 , 24.f , pTitle , - 1 , - 1.0f ) > Part . w )
2015-03-29 12:20:34 +00:00
UI ( ) - > DoLabelScaled ( & Part , pTitle , 24.f , - 1 , ( int ) Part . w ) ;
else
UI ( ) - > DoLabelScaled ( & Part , pTitle , 24.f , 0 ) ;
2020-09-22 16:02:03 +00:00
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
2020-06-19 09:53:26 +00:00
float FontSize = m_Popup = = POPUP_FIRST_LAUNCH ? 16.0f : 20.f ;
2010-05-29 07:25:38 +00:00
if ( ExtraAlign = = - 1 )
2020-06-19 09:53:26 +00:00
UI ( ) - > DoLabelScaled ( & Part , pExtraText , FontSize , - 1 , ( int ) Part . w ) ;
2008-08-27 15:48:50 +00:00
else
2015-04-27 21:17:28 +00:00
{
2020-07-15 19:10:13 +00:00
if ( TextRender ( ) - > TextWidth ( 0 , FontSize , pExtraText , - 1 , - 1.0f ) > Part . w )
2020-06-19 09:53:26 +00:00
UI ( ) - > DoLabelScaled ( & Part , pExtraText , FontSize , - 1 , ( int ) Part . w ) ;
2015-04-27 21:17:28 +00:00
else
2020-06-19 09:53:26 +00:00
UI ( ) - > DoLabelScaled ( & Part , pExtraText , FontSize , 0 , - 1 ) ;
2015-04-27 21:17:28 +00:00
}
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2011-03-21 23:31:42 +00:00
// additional info
2020-09-22 16:02:03 +00:00
Box . VMargin ( 20.f / UI ( ) - > Scale ( ) , & Box ) ;
2011-03-21 23:31:42 +00:00
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? " ) ) ;
2020-09-22 16:02:03 +00:00
UI ( ) - > DoLabelScaled ( & Box , aBuf , 20.f , - 1 , Part . w - 20.0f ) ;
2011-04-02 10:08:46 +00:00
}
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 )
2020-10-02 13:43:52 +00:00
{
m_Popup = POPUP_NONE ;
2010-05-29 07:25:38 +00:00
Client ( ) - > Quit ( ) ;
2020-10-02 13:43:52 +00:00
}
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 ) ;
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 )
Client ( ) - > Disconnect ( ) ;
}
2019-03-30 15:59:25 +00:00
else if ( m_Popup = = POPUP_DISCONNECT_DUMMY )
{
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 )
{
Client ( ) - > DummyDisconnect ( 0 ) ;
m_Popup = POPUP_NONE ;
2020-09-05 15:13:32 +00:00
SetActive ( false ) ;
2019-03-30 15:59:25 +00:00
}
}
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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
{
2017-07-15 15:29:20 +00:00
Client ( ) - > Connect ( g_Config . m_UiServerAddress , g_Config . m_Password ) ;
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
Part . VMargin ( 120.0f , & Part ) ;
static int s_Button = 0 ;
2020-11-06 23:00:21 +00:00
if ( DoButton_Menu ( & s_Button , pButtonText , 0 , & Part ) | | m_EscapePressed | | ( m_EnterPressed & & m_Popup ! = POPUP_CONNECTING ) )
2010-12-16 00:52:29 +00:00
{
Client ( ) - > Disconnect ( ) ;
m_Popup = POPUP_NONE ;
}
if ( Client ( ) - > MapDownloadTotalsize ( ) > 0 )
{
2021-06-23 05:05:49 +00:00
int64_t Now = time_get ( ) ;
2020-09-22 16:02:03 +00:00
if ( Now - m_DownloadLastCheckTime > = time_freq ( ) )
2010-12-16 00:52:29 +00:00
{
if ( m_DownloadLastCheckSize > Client ( ) - > MapDownloadAmount ( ) )
{
// map downloaded restarted
m_DownloadLastCheckSize = 0 ;
}
// update download speed
2020-09-22 16:02:03 +00:00
float Diff = ( Client ( ) - > MapDownloadAmount ( ) - m_DownloadLastCheckSize ) / ( ( int ) ( ( Now - m_DownloadLastCheckTime ) / time_freq ( ) ) ) ;
float StartDiff = m_DownloadLastCheckSize - 0.0f ;
if ( StartDiff + Diff > 0.0f )
m_DownloadSpeed = ( Diff / ( StartDiff + Diff ) ) * ( Diff / 1.0f ) + ( StartDiff / ( Diff + StartDiff ) ) * m_DownloadSpeed ;
2011-04-12 16:59:08 +00:00
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 ) ;
2020-09-22 16:02:03 +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
2020-09-22 16:02:03 +00:00
int TimeLeft = maximum ( 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 ;
2017-07-26 01:58:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , TimeLeft = = 1 ? Localize ( " %i minute left " ) : Localize ( " %i minutes left " ) , TimeLeft ) ;
2010-12-16 00:52:29 +00:00
}
else
2017-07-26 01:58:00 +00:00
{
str_format ( aBuf , sizeof ( aBuf ) , TimeLeft = = 1 ? Localize ( " %i second left " ) : Localize ( " %i seconds left " ) , TimeLeft ) ;
}
2010-12-16 00:52:29 +00:00
Box . HSplitTop ( 20.f , 0 , & Box ) ;
Box . HSplitTop ( 24.f , & Part , & Box ) ;
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 ) ;
2019-04-26 21:47:34 +00:00
RenderTools ( ) - > DrawUIRect ( & Part , ColorRGBA ( 1.0f , 1.0f , 1.0f , 0.25f ) , CUI : : CORNER_ALL , 5.0f ) ;
2020-09-22 16:02:03 +00:00
Part . w = maximum ( 10.0f , ( Part . w * Client ( ) - > MapDownloadAmount ( ) ) / Client ( ) - > MapDownloadTotalsize ( ) ) ;
2019-04-26 21:47:34 +00:00
RenderTools ( ) - > DrawUIRect ( & Part , ColorRGBA ( 1.0f , 1.0f , 1.0f , 0.5f ) , CUI : : CORNER_ALL , 5.0f ) ;
2010-12-16 00:52:29 +00:00
}
}
2010-12-12 18:20:30 +00:00
else if ( m_Popup = = POPUP_LANGUAGE )
{
Box = Screen ;
Box . VMargin ( 150.0f , & Box ) ;
Box . HMargin ( 150.0f , & Box ) ;
Box . HSplitTop ( 20.f , & Part , & Box ) ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
Box . HMargin ( 150.0f , & Box ) ;
Box . HSplitTop ( 20.f , & Part , & Box ) ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ;
2021-07-12 09:43:56 +00:00
UiDoListboxStart ( & s_ScrollValue , & Box , 50.0f , Localize ( " Country / Region " ) , " " , m_pClient - > m_CountryFlags . Num ( ) , 6 , OldSelected , s_ScrollValue ) ;
2011-06-29 20:27:32 +00:00
2021-07-12 09:43:56 +00:00
for ( int i = 0 ; i < m_pClient - > m_CountryFlags . Num ( ) ; + + i )
2011-06-29 20:27:32 +00:00
{
2021-07-12 09:43:56 +00:00
const CCountryFlags : : CCountryFlag * pEntry = m_pClient - > m_CountryFlags . GetByIndex ( i ) ;
2011-06-29 20:27:32 +00:00
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 ;
2020-09-22 16:02:03 +00:00
Item . m_Rect . w = Item . m_Rect . h * 2 ;
Item . m_Rect . x + = ( OldWidth - Item . m_Rect . w ) / 2.0f ;
2019-04-26 21:47:34 +00:00
ColorRGBA Color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
2021-07-12 09:43:56 +00:00
m_pClient - > m_CountryFlags . 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 )
2021-07-12 09:43:56 +00:00
ActSelection = m_pClient - > m_CountryFlags . GetByIndex ( NewSelected ) - > m_CountryCode ;
2011-06-29 20:27:32 +00:00
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ] ;
2020-09-22 16:02:03 +00:00
if ( Length < = 4 | | m_aCurrentDemoFile [ Length - 5 ] ! = ' . ' | | str_comp_nocase ( m_aCurrentDemoFile + Length - 4 , " demo " ) )
2011-03-31 16:33:46 +00:00
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
}
2019-09-27 07:22:50 +00:00
# if defined(CONF_VIDEORECORDER)
2019-09-27 03:06:02 +00:00
else if ( m_Popup = = POPUP_RENDER_DEMO )
{
2019-09-28 04:18:38 +00:00
CUIRect Label , TextBox , Ok , Abort , IncSpeed , DecSpeed , Button ;
2019-09-27 03:06:02 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
# endif
Part . VMargin ( 80.0f , & Part ) ;
Part . VSplitMid ( & Abort , & Ok ) ;
Ok . VMargin ( 20.0f , & Ok ) ;
Abort . VMargin ( 20.0f , & Abort ) ;
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 ;
// name video
if ( m_DemolistSelectedIndex > = 0 & & ! m_DemolistSelectedIsDir )
{
char aBufOld [ 512 ] ;
str_format ( aBufOld , sizeof ( aBufOld ) , " %s/%s " , m_aCurrentDemoFolder , m_lDemos [ m_DemolistSelectedIndex ] . m_aFilename ) ;
int Length = str_length ( m_aCurrentDemoFile ) ;
char aBufNew [ 512 ] ;
2020-09-22 16:02:03 +00:00
if ( Length < = 3 | | m_aCurrentDemoFile [ Length - 4 ] ! = ' . ' | | str_comp_nocase ( m_aCurrentDemoFile + Length - 3 , " mp4 " ) )
2019-09-27 03:06:02 +00:00
str_format ( aBufNew , sizeof ( aBufNew ) , " %s.mp4 " , m_aCurrentDemoFile ) ;
else
str_format ( aBufNew , sizeof ( aBufNew ) , " %s " , m_aCurrentDemoFile ) ;
2019-09-27 06:51:08 +00:00
char aWholePath [ 1024 ] ;
// store new video filename to origin buffer
str_copy ( m_aCurrentDemoFile , aBufNew , sizeof ( m_aCurrentDemoFile ) ) ;
if ( Storage ( ) - > FindFile ( m_aCurrentDemoFile , " videos " , IStorage : : TYPE_ALL , aWholePath , sizeof ( aWholePath ) ) )
{
PopupMessage ( Localize ( " Error " ) , Localize ( " Destination file already exist " ) , Localize ( " Ok " ) ) ;
m_Popup = POPUP_REPLACE_VIDEO ;
}
else
{
2019-09-28 04:18:38 +00:00
const char * pError = Client ( ) - > DemoPlayer_Render ( aBufOld , m_lDemos [ m_DemolistSelectedIndex ] . m_StorageType , m_aCurrentDemoFile , m_Speed ) ;
m_Speed = 4 ;
2019-09-27 06:51:08 +00:00
//Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "demo_render_path", aWholePath);
if ( pError )
PopupMessage ( Localize ( " Error " ) , str_comp ( pError , " error loading demo " ) ? pError : Localize ( " Error loading demo " ) , Localize ( " Ok " ) ) ;
}
2019-09-27 03:06:02 +00:00
}
}
2020-10-07 21:11:09 +00:00
Box . HSplitBottom ( 30.f , & Box , 0 ) ;
2020-09-08 09:31:45 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2020-10-07 21:11:09 +00:00
Box . HSplitBottom ( 10.f , & Box , 0 ) ;
2020-09-08 09:31:45 +00:00
2020-10-07 21:11:09 +00:00
float ButtonSize = 20.0f ;
2020-09-08 09:31:45 +00:00
Part . VSplitLeft ( 113.0f , 0 , & Part ) ;
2020-10-07 21:11:09 +00:00
Part . VSplitLeft ( ButtonSize , & Button , & Part ) ;
2020-09-08 09:31:45 +00:00
if ( DoButton_CheckBox ( & g_Config . m_ClVideoShowChat , Localize ( " Show chat " ) , g_Config . m_ClVideoShowChat , & Button ) )
g_Config . m_ClVideoShowChat ^ = 1 ;
Part . VSplitLeft ( 112.0f , 0 , & Part ) ;
2020-10-07 21:11:09 +00:00
Part . VSplitLeft ( ButtonSize , & Button , & Part ) ;
2020-09-08 09:31:45 +00:00
if ( DoButton_CheckBox ( & g_Config . m_ClVideoSndEnable , Localize ( " Use sounds " ) , g_Config . m_ClVideoSndEnable , & Button ) )
g_Config . m_ClVideoSndEnable ^ = 1 ;
2019-09-28 04:18:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Part . VSplitLeft ( 60.0f , 0 , & Part ) ;
Part . VSplitLeft ( 60.0f , 0 , & Label ) ;
Part . VSplitMid ( & IncSpeed , & DecSpeed ) ;
IncSpeed . VMargin ( 20.0f , & IncSpeed ) ;
DecSpeed . VMargin ( 20.0f , & DecSpeed ) ;
Part . VSplitLeft ( 20.0f , & Button , & Part ) ;
bool IncDemoSpeed = false , DecDemoSpeed = false ;
// slowdown
Part . VSplitLeft ( 5.0f , 0 , & Part ) ;
2020-10-07 21:11:09 +00:00
Part . VSplitLeft ( ButtonSize , & Button , & Part ) ;
2019-09-28 04:18:38 +00:00
static int s_SlowDownButton = 0 ;
if ( DoButton_Sprite ( & s_SlowDownButton , IMAGE_DEMOBUTTONS , SPRITE_DEMOBUTTON_SLOWER , 0 , & Button , CUI : : CORNER_ALL ) )
DecDemoSpeed = true ;
// fastforward
Part . VSplitLeft ( 5.0f , 0 , & Part ) ;
2020-10-07 21:11:09 +00:00
Part . VSplitLeft ( ButtonSize , & Button , & Part ) ;
2019-09-28 04:18:38 +00:00
static int s_FastForwardButton = 0 ;
if ( DoButton_Sprite ( & s_FastForwardButton , IMAGE_DEMOBUTTONS , SPRITE_DEMOBUTTON_FASTER , 0 , & Button , CUI : : CORNER_ALL ) )
IncDemoSpeed = true ;
// speed meter
2020-09-08 09:31:45 +00:00
Part . VSplitLeft ( 8.0f , 0 , & Part ) ;
2019-09-28 04:18:38 +00:00
char aBuffer [ 64 ] ;
2020-09-08 09:31:45 +00:00
str_format ( aBuffer , sizeof ( aBuffer ) , " %s: × %g " , Localize ( " Speed " ) , g_aSpeeds [ m_Speed ] ) ;
UI ( ) - > DoLabel ( & Part , aBuffer , 12.8f , - 1 ) ;
2019-09-28 04:18:38 +00:00
if ( IncDemoSpeed )
2020-09-22 16:02:03 +00:00
m_Speed = clamp ( m_Speed + 1 , 0 , ( int ) ( sizeof ( g_aSpeeds ) / sizeof ( g_aSpeeds [ 0 ] ) - 1 ) ) ;
2019-09-28 04:18:38 +00:00
else if ( DecDemoSpeed )
2020-09-22 16:02:03 +00:00
m_Speed = clamp ( m_Speed - 1 , 0 , ( int ) ( sizeof ( g_aSpeeds ) / sizeof ( g_aSpeeds [ 0 ] ) - 1 ) ) ;
2019-09-28 04:18:38 +00:00
2020-09-08 09:31:45 +00:00
Part . VSplitLeft ( 107.0f , 0 , & Part ) ;
2020-10-07 21:11:09 +00:00
Part . VSplitLeft ( ButtonSize , & Button , & Part ) ;
2019-10-02 05:11:58 +00:00
if ( DoButton_CheckBox ( & g_Config . m_ClVideoShowhud , Localize ( " Show ingame HUD " ) , g_Config . m_ClVideoShowhud , & Button ) )
g_Config . m_ClVideoShowhud ^ = 1 ;
2019-09-28 04:18:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2019-09-27 03:06:02 +00:00
# if defined(__ANDROID__)
Box . HSplitBottom ( 60.f , & Box , & Part ) ;
# else
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
# endif
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 ( " Video name: " ) , 18.0f , - 1 ) ;
static float Offset = 0.0f ;
DoEditBox ( & Offset , & TextBox , m_aCurrentDemoFile , sizeof ( m_aCurrentDemoFile ) , 12.0f , & Offset ) ;
}
2019-09-27 06:51:08 +00:00
else if ( m_Popup = = POPUP_REPLACE_VIDEO )
{
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
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_RENDER_DEMO ;
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
{
m_Popup = POPUP_NONE ;
// render video
char aBuf [ 512 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %s/%s " , m_aCurrentDemoFolder , m_lDemos [ m_DemolistSelectedIndex ] . m_aFilename ) ;
2019-09-28 04:18:38 +00:00
const char * pError = Client ( ) - > DemoPlayer_Render ( aBuf , m_lDemos [ m_DemolistSelectedIndex ] . m_StorageType , m_aCurrentDemoFile , m_Speed ) ;
m_Speed = 4 ;
2019-09-27 06:51:08 +00:00
if ( pError )
PopupMessage ( Localize ( " Error " ) , str_comp ( pError , " error loading demo " ) ? pError : Localize ( " Error loading demo " ) , Localize ( " Ok " ) ) ;
}
}
2019-09-27 07:22:50 +00:00
# endif
2011-03-23 12:06:35 +00:00
else if ( m_Popup = = POPUP_REMOVE_FRIEND )
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 )
2017-09-07 18:51:46 +00:00
{
Client ( ) - > RequestDDNetInfo ( ) ;
2020-10-23 21:25:58 +00:00
if ( g_Config . m_BrIndicateFinished )
m_Popup = POPUP_POINTS ;
else
{
m_Popup = POPUP_NONE ;
}
2017-09-07 18:51:46 +00:00
}
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
2020-06-19 09:53:26 +00:00
Part . VSplitLeft ( 30.0f , 0 , & Part ) ;
2020-06-26 16:17:20 +00:00
char aBuf [ 128 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " %s \n (%s) " ,
Localize ( " Show DDNet map finishes in server browser " ) ,
2020-08-19 15:50:36 +00:00
Localize ( " transmits your player name to info2.ddnet.tw " ) ) ;
2020-06-26 16:17:20 +00:00
if ( DoButton_CheckBox ( & g_Config . m_BrIndicateFinished , aBuf , g_Config . m_BrIndicateFinished , & Part ) )
2017-09-07 18:51:46 +00:00
g_Config . m_BrIndicateFinished ^ = 1 ;
2011-04-13 18:37:12 +00:00
2020-06-19 09:53:26 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 ) ;
2020-06-19 09:53:26 +00:00
UI ( ) - > DoLabel ( & Label , Localize ( " Nickname " ) , 16.0f , - 1 ) ;
2010-05-29 15:53:57 +00:00
static float Offset = 0.0f ;
2020-08-20 10:19:03 +00:00
DoEditBox ( & g_Config . m_PlayerName , & TextBox , g_Config . m_PlayerName , sizeof ( g_Config . m_PlayerName ) , 12.0f , & Offset , false , CUI : : CORNER_ALL , Client ( ) - > PlayerName ( ) ) ;
2008-08-27 15:48:50 +00:00
}
2020-10-23 21:25:58 +00:00
else if ( m_Popup = = POPUP_POINTS )
{
CUIRect Yes , No ;
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
Part . VMargin ( 80.0f , & Part ) ;
Part . VSplitMid ( & No , & Yes ) ;
Yes . VMargin ( 20.0f , & Yes ) ;
No . VMargin ( 20.0f , & No ) ;
static int s_ButtonNo = 0 ;
if ( DoButton_Menu ( & s_ButtonNo , Localize ( " No " ) , 0 , & No ) | | m_EscapePressed )
m_Popup = POPUP_FIRST_LAUNCH ;
static int s_ButtonYes = 0 ;
if ( DoButton_Menu ( & s_ButtonYes , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
m_Popup = POPUP_NONE ;
}
2020-08-29 10:49:45 +00:00
else if ( m_Popup = = POPUP_WARNING )
{
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
Part . VMargin ( 120.0f , & Part ) ;
static int s_Button = 0 ;
if ( DoButton_Menu ( & s_Button , pButtonText , 0 , & Part ) | | m_EscapePressed | | m_EnterPressed | | ( time_get_microseconds ( ) - m_PopupWarningLastTime > = m_PopupWarningDuration ) )
{
m_Popup = POPUP_NONE ;
SetActive ( false ) ;
}
}
2021-06-26 11:39:14 +00:00
else if ( m_Popup = = POPUP_SWITCH_SERVER )
{
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 ;
m_aNextServer [ 0 ] = ' \0 ' ;
}
static int s_ButtonTryAgain = 0 ;
if ( DoButton_Menu ( & s_ButtonTryAgain , Localize ( " Yes " ) , 0 , & Yes ) | | m_EnterPressed )
Client ( ) - > Connect ( m_aNextServer ) ;
}
2008-08-27 15:48:50 +00:00
else
{
2010-05-29 07:25:38 +00:00
Box . HSplitBottom ( 20.f , & Box , & Part ) ;
Box . HSplitBottom ( 24.f , & Box , & Part ) ;
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 )
2016-05-07 14:12:23 +00:00
{
if ( m_Popup = = POPUP_DISCONNECTED & & Client ( ) - > m_ReconnectTime > 0 )
Client ( ) - > m_ReconnectTime = 0 ;
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE ;
2016-05-07 14:12:23 +00:00
}
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
}
return 0 ;
}
2020-09-18 16:45:42 +00:00
void CMenus : : RenderThemeSelection ( CUIRect MainView , bool Header )
{
std : : vector < CTheme > & ThemesRef = m_pBackground - > GetThemes ( ) ;
int SelectedTheme = - 1 ;
for ( int i = 0 ; i < ( int ) ThemesRef . size ( ) ; i + + )
{
if ( str_comp ( ThemesRef [ i ] . m_Name , g_Config . m_ClMenuMap ) = = 0 )
{
SelectedTheme = i ;
break ;
}
}
static int s_ListBox = 0 ;
static float s_ScrollValue = 0.0f ;
2020-09-19 06:53:26 +00:00
UiDoListboxStart ( & s_ListBox , & MainView , 26.0f , Localize ( " Theme " ) , " " , ThemesRef . size ( ) , 1 , - 1 , s_ScrollValue ) ;
2020-09-18 16:45:42 +00:00
for ( int i = 0 ; i < ( int ) ThemesRef . size ( ) ; i + + )
{
CListboxItem Item = UiDoListboxNextItem ( & ThemesRef [ i ] . m_Name , i = = SelectedTheme ) ;
CTheme & Theme = ThemesRef [ i ] ;
if ( ! Item . m_Visible )
continue ;
CUIRect Icon ;
Item . m_Rect . VSplitLeft ( Item . m_Rect . h * 2.0f , & Icon , & Item . m_Rect ) ;
// draw icon if it exists
2012-08-12 12:02:50 +00:00
if ( Theme . m_IconTexture . IsValid ( ) )
2020-09-18 16:45:42 +00:00
{
Icon . VMargin ( 6.0f , & Icon ) ;
Icon . HMargin ( 3.0f , & Icon ) ;
Graphics ( ) - > TextureSet ( Theme . m_IconTexture ) ;
Graphics ( ) - > QuadsBegin ( ) ;
Graphics ( ) - > SetColor ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
IGraphics : : CQuadItem QuadItem ( Icon . x , Icon . y , Icon . w , Icon . h ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
Graphics ( ) - > QuadsEnd ( ) ;
}
char aName [ 128 ] ;
if ( ! Theme . m_Name [ 0 ] )
str_copy ( aName , " (none) " , sizeof ( aName ) ) ;
else if ( str_comp ( Theme . m_Name , " auto " ) = = 0 )
str_copy ( aName , " (seasons) " , sizeof ( aName ) ) ;
else if ( str_comp ( Theme . m_Name , " rand " ) = = 0 )
str_copy ( aName , " (random) " , sizeof ( aName ) ) ;
else if ( Theme . m_HasDay & & Theme . m_HasNight )
str_format ( aName , sizeof ( aName ) , " %s " , Theme . m_Name . cstr ( ) ) ;
else if ( Theme . m_HasDay & & ! Theme . m_HasNight )
str_format ( aName , sizeof ( aName ) , " %s (day) " , Theme . m_Name . cstr ( ) ) ;
else if ( ! Theme . m_HasDay & & Theme . m_HasNight )
str_format ( aName , sizeof ( aName ) , " %s (night) " , Theme . m_Name . cstr ( ) ) ;
else // generic
str_format ( aName , sizeof ( aName ) , " %s " , Theme . m_Name . cstr ( ) ) ;
2020-09-19 06:53:26 +00:00
UI ( ) - > DoLabel ( & Item . m_Rect , aName , 16 * ms_FontmodHeight , - 1 ) ;
2020-09-18 16:45:42 +00:00
}
bool ItemActive = false ;
int NewSelected = UiDoListboxEnd ( & s_ScrollValue , 0 , & ItemActive ) ;
if ( ItemActive & & NewSelected ! = SelectedTheme )
{
str_format ( g_Config . m_ClMenuMap , sizeof ( g_Config . m_ClMenuMap ) , " %s " , ThemesRef [ NewSelected ] . m_Name . cstr ( ) ) ;
m_pBackground - > LoadMenuBackground ( ThemesRef [ NewSelected ] . m_HasDay , ThemesRef [ NewSelected ] . m_HasNight ) ;
}
}
2010-05-29 07:25:38 +00:00
void CMenus : : SetActive ( bool Active )
2008-10-20 23:38:23 +00:00
{
2017-07-15 13:37:05 +00:00
if ( Active ! = m_MenuActive )
2020-12-16 04:55:41 +00:00
{
ms_ColorPicker . m_Active = false ;
2017-07-15 13:37:05 +00:00
Input ( ) - > SetIMEState ( Active ) ;
2020-12-16 04:55:41 +00:00
}
2010-05-29 07:25:38 +00:00
m_MenuActive = Active ;
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
{
}
2021-10-23 11:48:21 +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
if ( ! m_MenuActive )
2021-10-23 11:48:21 +00:00
return false ;
2011-04-13 18:37:12 +00:00
2021-10-23 11:48:21 +00:00
UI ( ) - > ConvertMouseMove ( & x , & y ) ;
2016-05-03 13:11:52 +00:00
if ( m_MouseSlow )
{
2021-10-23 11:48:21 +00:00
m_MousePos . x + = x * 0.05f ;
m_MousePos . y + = y * 0.05f ;
2016-05-03 13:11:52 +00:00
}
else
{
2021-10-23 11:48:21 +00:00
m_MousePos . x + = x ;
m_MousePos . y + = y ;
2016-05-03 13:11:52 +00:00
}
2021-10-23 11:48:21 +00:00
m_MousePos . x = clamp ( m_MousePos . x , 0.f , ( float ) Graphics ( ) - > ScreenWidth ( ) ) ;
m_MousePos . y = clamp ( m_MousePos . y , 0.f , ( float ) Graphics ( ) - > ScreenHeight ( ) ) ;
2011-04-13 18:37:12 +00:00
2021-10-23 11:48:21 +00:00
return true ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
bool CMenus : : OnInput ( IInput : : CEvent e )
2008-08-27 15:48:50 +00:00
{
2008-10-21 18:25:28 +00:00
// special handle esc and enter for popup purposes
2020-09-22 16:02:03 +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 ;
2019-03-25 19:01:10 +00:00
if ( m_Popup = = POPUP_NONE )
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
{
2020-09-22 16:02:03 +00:00
if ( e . m_Flags & IInput : : FLAG_PRESS )
2010-09-03 18:05:22 +00:00
{
// 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
{
2020-10-02 13:44:27 +00:00
if ( OldState > = IClient : : STATE_ONLINE & & NewState < IClient : : STATE_QUITTING )
2021-07-12 09:43:56 +00:00
m_pClient - > m_Sounds . 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 ;
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 ;
2018-03-13 20:59:07 +00:00
else if ( NewState = = IClient : : STATE_ONLINE | | NewState = = IClient : : STATE_DEMOPLAYBACK )
2008-08-27 15:48:50 +00:00
{
2020-08-29 10:49:45 +00:00
if ( m_Popup ! = POPUP_WARNING )
{
m_Popup = POPUP_NONE ;
SetActive ( false ) ;
}
2008-08-27 15:48:50 +00:00
}
}
2010-05-29 07:25:38 +00:00
void CMenus : : OnRender ( )
2008-08-27 15:48:50 +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
{
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
RenderDemoPlayer ( * UI ( ) - > 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
2019-04-26 23:02:31 +00:00
ms_GuiColor = color_cast < ColorRGBA > ( ColorHSLA ( g_Config . m_UiColor , true ) ) ;
2010-05-29 07:25:38 +00:00
2020-09-16 01:30:03 +00:00
ms_ColorTabbarInactiveOutgame = ColorRGBA ( 0 , 0 , 0 , 0.25f ) ;
ms_ColorTabbarActiveOutgame = ColorRGBA ( 0 , 0 , 0 , 0.5f ) ;
ms_ColorTabbarHoverOutgame = ColorRGBA ( 1 , 1 , 1 , 0.25f ) ;
2010-05-29 07:25:38 +00:00
float ColorIngameScaleI = 0.5f ;
float ColorIngameAcaleA = 0.2f ;
2020-09-16 01:30:03 +00:00
2019-04-26 21:47:34 +00:00
ms_ColorTabbarInactiveIngame = ColorRGBA (
2020-09-16 01:30:03 +00:00
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
2019-04-26 21:47:34 +00:00
ms_ColorTabbarActiveIngame = ColorRGBA (
2020-09-22 16:02:03 +00:00
ms_GuiColor . r * ColorIngameAcaleA ,
ms_GuiColor . g * ColorIngameAcaleA ,
ms_GuiColor . b * ColorIngameAcaleA ,
2010-05-29 07:25:38 +00:00
ms_GuiColor . a ) ;
2011-04-13 18:37:12 +00:00
2020-09-16 01:30:03 +00:00
ms_ColorTabbarHoverIngame = ColorRGBA ( 1 , 1 , 1 , 0.75f ) ;
2008-08-27 15:48:50 +00:00
// update the ui
2010-05-29 07:25:38 +00:00
CUIRect * pScreen = UI ( ) - > Screen ( ) ;
2021-10-23 11:48:21 +00:00
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 )
{
2020-09-22 16:02:03 +00:00
if ( Input ( ) - > KeyIsPressed ( KEY_MOUSE_1 ) )
Buttons | = 1 ;
if ( Input ( ) - > KeyIsPressed ( KEY_MOUSE_2 ) )
Buttons | = 2 ;
if ( Input ( ) - > KeyIsPressed ( KEY_MOUSE_3 ) )
Buttons | = 4 ;
2010-05-29 07:25:38 +00:00
}
2011-04-13 18:37:12 +00:00
2020-09-22 16:02:03 +00:00
UI ( ) - > Update ( mx , my , mx * 3.0f , my * 3.0f , Buttons ) ;
2011-04-13 18:37:12 +00:00
2009-01-10 11:16:21 +00:00
// render
2020-08-29 10:49:45 +00:00
Render ( ) ;
2008-09-24 15:09:09 +00:00
2009-01-10 11:16:21 +00:00
// render cursor
2020-09-15 14:18:12 +00:00
Graphics ( ) - > WrapClamp ( ) ;
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 ( ) ;
2020-09-22 16:02:03 +00:00
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 ( ) ;
2020-09-15 14:18:12 +00:00
Graphics ( ) - > WrapNormal ( ) ;
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
{
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2010-05-29 07:25:38 +00:00
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
void CMenus : : RenderBackground ( )
2008-09-11 22:45:28 +00:00
{
2020-08-31 14:18:45 +00:00
Graphics ( ) - > BlendNormal ( ) ;
2020-09-05 15:13:32 +00:00
2020-09-22 16:02:03 +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
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
ColorRGBA Bottom ( ms_GuiColor . r , ms_GuiColor . g , ms_GuiColor . b , 1.0f ) ;
ColorRGBA 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
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
float Size = 15.0f ;
float OffsetTime = fmod ( LocalTime ( ) * 0.15f , 2.0f ) ;
for ( int y = - 2 ; y < ( int ) ( sw / Size ) ; y + + )
for ( int x = - 2 ; x < ( int ) ( sh / Size ) ; x + + )
{
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.045f ) ;
IGraphics : : CQuadItem QuadItem ( ( x - OffsetTime ) * Size * 2 + ( y & 1 ) * Size , ( y + OffsetTime ) * Size , Size , Size ) ;
Graphics ( ) - > QuadsDrawTL ( & QuadItem , 1 ) ;
}
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
2008-09-24 15:09:09 +00:00
// render border fade
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureSet ( m_TextureBlob ) ;
2009-10-27 14:38:53 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
Graphics ( ) - > SetColor ( 1 , 1 , 1 , 1 ) ;
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
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2008-09-11 22:45:28 +00:00
}
2011-01-30 16:21:41 +00:00
2020-09-03 12:08:26 +00:00
bool CMenus : : CheckHotKey ( int Key ) const
{
return m_Popup = = POPUP_NONE & &
2020-09-10 18:14:47 +00:00
! Input ( ) - > KeyIsPressed ( KEY_LSHIFT ) & & ! Input ( ) - > KeyIsPressed ( KEY_RSHIFT ) & & ! Input ( ) - > KeyIsPressed ( KEY_LCTRL ) & & ! Input ( ) - > KeyIsPressed ( KEY_RCTRL ) & & ! Input ( ) - > KeyIsPressed ( KEY_LALT ) & & // no modifier
2021-07-12 09:43:56 +00:00
Input ( ) - > KeyIsPressed ( Key ) & & m_pClient - > m_GameConsole . IsClosed ( ) ;
2020-09-03 12:08:26 +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
2021-06-23 05:05:49 +00:00
static int64_t LastLoadRender = 0 ;
2020-09-22 16:02:03 +00:00
if ( time_get ( ) - LastLoadRender < time_freq ( ) / 60 )
2014-04-27 03:01:03 +00:00
return ;
LastLoadRender = time_get ( ) ;
// need up date this here to get correct
2019-04-26 23:02:31 +00:00
ms_GuiColor = color_cast < ColorRGBA > ( ColorHSLA ( g_Config . m_UiColor , true ) ) ;
2014-04-27 03:01:03 +00:00
CUIRect Screen = * UI ( ) - > Screen ( ) ;
2021-09-22 19:48:55 +00:00
UI ( ) - > MapScreen ( ) ;
2019-04-28 17:22:19 +00:00
2014-04-27 03:01:03 +00:00
RenderBackground ( ) ;
float w = 700 ;
float h = 200 ;
2020-09-22 16:02:03 +00:00
float x = Screen . w / 2 - w / 2 ;
float y = Screen . h / 2 - h / 2 ;
2014-04-27 03:01:03 +00:00
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2014-04-27 03:01:03 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
Graphics ( ) - > SetColor ( 0 , 0 , 0 , 0.50f ) ;
2014-04-27 03:01:03 +00:00
RenderTools ( ) - > DrawRoundRect ( 0 , y , Screen . w , h , 0.0f ) ;
Graphics ( ) - > QuadsEnd ( ) ;
CUIRect r ;
r . x = x ;
2020-09-22 16:02:03 +00:00
r . y = y + 20 ;
2014-04-27 03:01:03 +00:00
r . w = w ;
r . h = h ;
UI ( ) - > DoLabel ( & r , Localize ( pCaption ) , 32.0f , 0 , - 1 ) ;
2020-09-22 16:02:03 +00:00
if ( total > 0 )
2014-04-27 03:01:03 +00:00
{
2020-09-22 16:02:03 +00:00
float Percent = current / ( float ) total ;
2012-08-12 10:41:50 +00:00
Graphics ( ) - > TextureClear ( ) ;
2014-04-27 03:01:03 +00:00
Graphics ( ) - > QuadsBegin ( ) ;
2020-09-22 16:02:03 +00:00
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 ) ;
2014-04-27 03:01:03 +00:00
Graphics ( ) - > QuadsEnd ( ) ;
}
Graphics ( ) - > Swap ( ) ;
}
2020-09-03 12:08:26 +00:00
int CMenus : : MenuImageScan ( const char * pName , int IsDir , int DirType , void * pUser )
{
CMenus * pSelf = ( CMenus * ) pUser ;
if ( IsDir | | ! str_endswith ( pName , " .png " ) )
return 0 ;
2021-09-13 08:06:34 +00:00
char aBuf [ IO_MAX_PATH_LENGTH ] ;
2020-09-03 12:08:26 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " menuimages/%s " , pName ) ;
CImageInfo Info ;
if ( ! pSelf - > Graphics ( ) - > LoadPNG ( & Info , aBuf , DirType ) )
{
str_format ( aBuf , sizeof ( aBuf ) , " failed to load menu image from %s " , pName ) ;
pSelf - > Console ( ) - > Print ( IConsole : : OUTPUT_LEVEL_ADDINFO , " game " , aBuf ) ;
return 0 ;
}
CMenuImage MenuImage ;
MenuImage . m_OrgTexture = pSelf - > Graphics ( ) - > LoadTextureRaw ( Info . m_Width , Info . m_Height , Info . m_Format , Info . m_pData , Info . m_Format , 0 ) ;
unsigned char * d = ( unsigned char * ) Info . m_pData ;
//int Pitch = Info.m_Width*4;
// create colorless version
int Step = Info . m_Format = = CImageInfo : : FORMAT_RGBA ? 4 : 3 ;
// make the texture gray scale
2020-09-22 16:02:03 +00:00
for ( int i = 0 ; i < Info . m_Width * Info . m_Height ; i + + )
2020-09-03 12:08:26 +00:00
{
2020-09-22 16:02:03 +00:00
int v = ( d [ i * Step ] + d [ i * Step + 1 ] + d [ i * Step + 2 ] ) / 3 ;
d [ i * Step ] = v ;
d [ i * Step + 1 ] = v ;
d [ i * Step + 2 ] = v ;
2020-09-03 12:08:26 +00:00
}
/* same grey like sinks
int Freq [ 256 ] = { 0 } ;
int OrgWeight = 0 ;
int NewWeight = 192 ;
// find most common frequence
for ( int y = 0 ; y < Info . m_Height ; y + + )
for ( int x = 0 ; x < Info . m_Width ; x + + )
{
if ( d [ y * Pitch + x * 4 + 3 ] > 128 )
Freq [ d [ y * Pitch + x * 4 ] ] + + ;
}
for ( int i = 1 ; i < 256 ; i + + )
{
if ( Freq [ OrgWeight ] < Freq [ i ] )
OrgWeight = i ;
}
// reorder
int InvOrgWeight = 255 - OrgWeight ;
int InvNewWeight = 255 - NewWeight ;
for ( int y = 0 ; y < Info . m_Height ; y + + )
for ( int x = 0 ; x < Info . m_Width ; x + + )
{
int v = d [ y * Pitch + x * 4 ] ;
if ( v < = OrgWeight )
v = ( int ) ( ( ( v / ( float ) OrgWeight ) * NewWeight ) ) ;
else
v = ( int ) ( ( ( v - OrgWeight ) / ( float ) InvOrgWeight ) * InvNewWeight + NewWeight ) ;
d [ y * Pitch + x * 4 ] = v ;
d [ y * Pitch + x * 4 + 1 ] = v ;
d [ y * Pitch + x * 4 + 2 ] = v ;
}
*/
MenuImage . m_GreyTexture = pSelf - > Graphics ( ) - > LoadTextureRaw ( Info . m_Width , Info . m_Height , Info . m_Format , Info . m_pData , Info . m_Format , 0 ) ;
2020-11-25 12:05:53 +00:00
pSelf - > Graphics ( ) - > FreePNG ( & Info ) ;
2020-09-03 12:08:26 +00:00
// set menu image data
str_truncate ( MenuImage . m_aName , sizeof ( MenuImage . m_aName ) , pName , str_length ( pName ) - 4 ) ;
pSelf - > m_lMenuImages . add ( MenuImage ) ;
pSelf - > RenderLoading ( ) ;
return 0 ;
}
const CMenus : : CMenuImage * CMenus : : FindMenuImage ( const char * pName )
{
for ( int i = 0 ; i < m_lMenuImages . size ( ) ; i + + )
{
if ( str_comp ( m_lMenuImages [ i ] . m_aName , pName ) = = 0 )
return & m_lMenuImages [ i ] ;
}
return 0 ;
}
void CMenus : : SetMenuPage ( int NewPage )
{
m_MenuPage = NewPage ;
if ( NewPage > = PAGE_INTERNET & & NewPage < = PAGE_KOG )
g_Config . m_UiPage = NewPage ;
}
2020-11-12 13:20:38 +00:00
bool CMenus : : HandleListInputs ( const CUIRect & View , float & ScrollValue , const float ScrollAmount , int * pScrollOffset , const float ElemHeight , int & SelectedIndex , const int NumElems )
{
2021-04-20 16:54:32 +00:00
if ( NumElems = = 0 )
{
ScrollValue = 0 ;
SelectedIndex = 0 ;
return false ;
}
2020-11-12 13:20:38 +00:00
int NewIndex = - 1 ;
2020-12-16 06:03:32 +00:00
int Num = ( int ) ( View . h / ElemHeight ) ;
int ScrollNum = maximum ( NumElems - Num , 0 ) ;
2020-11-12 13:20:38 +00:00
if ( ScrollNum > 0 )
{
if ( pScrollOffset & & * pScrollOffset > = 0 )
{
ScrollValue = ( float ) ( * pScrollOffset ) / ScrollNum ;
* pScrollOffset = - 1 ;
}
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_UP ) & & UI ( ) - > MouseInside ( & View ) )
ScrollValue - = 3.0f / ScrollNum ;
if ( Input ( ) - > KeyPress ( KEY_MOUSE_WHEEL_DOWN ) & & UI ( ) - > MouseInside ( & View ) )
ScrollValue + = 3.0f / ScrollNum ;
}
2020-11-21 17:30:24 +00:00
ScrollValue = clamp ( ScrollValue , 0.0f , 1.0f ) ;
2021-04-20 16:54:32 +00:00
SelectedIndex = clamp ( SelectedIndex , 0 , NumElems - 1 ) ;
2020-11-12 13:20:38 +00:00
for ( int i = 0 ; i < m_NumInputEvents ; i + + )
{
if ( m_aInputEvents [ i ] . m_Flags & IInput : : FLAG_PRESS )
{
2021-07-26 06:34:31 +00:00
if ( UI ( ) - > LastActiveItem ( ) = = & g_Config . m_UiServerAddress )
return false ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_DOWN )
2020-11-12 13:20:38 +00:00
NewIndex = minimum ( SelectedIndex + 1 , NumElems - 1 ) ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_UP )
NewIndex = maximum ( SelectedIndex - 1 , 0 ) ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_PAGEUP )
NewIndex = maximum ( SelectedIndex - 25 , 0 ) ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_PAGEDOWN )
NewIndex = minimum ( SelectedIndex + 25 , NumElems - 1 ) ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_HOME )
NewIndex = 0 ;
else if ( m_aInputEvents [ i ] . m_Key = = KEY_END )
NewIndex = NumElems - 1 ;
}
if ( NewIndex > - 1 & & NewIndex < NumElems )
{
//scroll
float IndexY = View . y - ScrollValue * ScrollNum * ElemHeight + NewIndex * ElemHeight ;
int Scroll = View . y > IndexY ? - 1 : View . y + View . h < IndexY + ElemHeight ? 1 : 0 ;
if ( Scroll )
{
if ( Scroll < 0 )
{
int NumScrolls = ( View . y - IndexY + ElemHeight - 1.0f ) / ElemHeight ;
ScrollValue - = ( 1.0f / ScrollNum ) * NumScrolls ;
}
else
{
int NumScrolls = ( IndexY + ElemHeight - ( View . y + View . h ) + ElemHeight - 1.0f ) / ElemHeight ;
ScrollValue + = ( 1.0f / ScrollNum ) * NumScrolls ;
}
}
SelectedIndex = NewIndex ;
}
}
return NewIndex ! = - 1 ;
}