Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class: CUIRaceJoin ( CDoPulse, CUIAsyncQuery )
- {
- Fonts =
- {
- Medium = DXFont( "Montserrat/Montserrat-Bold.otf", 10 );
- Medium2 = DXFont( "Montserrat/Montserrat-Bold.otf", 12 );
- Medium3 = DXFont( "Montserrat/Montserrat-Bold.otf", 9 );
- };
- Colors =
- {
- White = "#ffffff";
- Black = "#000000";
- Theme = "#fbbd2f";
- Red = "#e31111";
- };
- m_sPath = S_IMAGES_RESOURCE_UI_PATH + "race_join/";
- m_iStartX = 0;
- m_iStartY = 103;
- m_iItemHeight = 26;
- m_iOffsetY = 16;
- m_iWaitTime = 0;
- CUIRaceJoin = function( this, pData )
- this.m_pData = pData;
- this.m_sLimits = pData.Limits;
- -- Показываем фейд
- this.m_pFade = CUIFadeBackground();
- -- Поле.
- this.m_pField = CUILib():CreateField()
- {
- X = "center";
- Y = 104;
- Width = 520;
- Height = 404;
- };
- -- Поле (вверх)
- this.m_pFieldTop = this.m_pField:CreateField()
- {
- X = 0;
- Y = 0;
- Width = this.m_pField.Width;
- Height = 60;
- };
- -- Иконка (гонка)
- this.m_pImageIcon = this.m_pFieldTop:CreateStaticImage( this.m_sPath + "icon.png" )
- {
- X = - 5;
- Y = "center";
- Width = 35;
- Height = 35;
- };
- -- 35
- this.m_pLabelRaceName = this.m_pFieldTop:CreateLabel( ( pData.Name or "" ):upper() )
- {
- X = 37;
- Y = 20 - 5;
- Width = 350;
- Height = 30;
- Font = this.Fonts.Medium2;
- };
- this.m_pLabelRaceType = this.m_pFieldTop:CreateLabel( _( pData.Type or "" ) )
- {
- X = this.m_pLabelRaceName.X;
- Y = this.m_pLabelRaceName.Y + 20;
- Width = this.m_pLabelRaceName.Width;
- Height = this.m_pLabelRaceName.Height;
- Font = this.Fonts.Medium;
- Color = this.Colors.Theme;
- };
- -- Карта
- this.m_pImageMap = this.m_pFieldTop:CreateStaticImage( this.m_sPath + "map.png" )
- {
- X = this.m_pFieldTop.Width - 100;
- Y = "center";
- Width = 100;
- Height = 70;
- };
- -- Список-блоки
- local sCategory = pData.Category;
- this.m_pBlockCategory = this:CreateBlock( _( "Car category:" ) )
- {
- X = this.m_iStartX;
- Y = this.m_iStartY;
- Width = this.m_pField.Width - ( this.m_iStartX * 2 );
- Height = this.m_iItemHeight;
- Description = sCategory or "";
- };
- this.m_pBlockPlayersCount = this:CreateBlock( _( "Number of players" ) )
- {
- X = this.m_pBlockCategory.X;
- Y = this.m_pBlockCategory.Y + this.m_pBlockCategory.Height + this.m_iOffsetY;
- Width = this.m_pBlockCategory.Width;
- Height = this.m_pBlockCategory.Height;
- Description = "";
- };
- local fDistance = pData.Distance;
- this.m_pBlockDistance = this:CreateBlock( _( "Distance" ) )
- {
- X = this.m_pBlockPlayersCount.X;
- Y = this.m_pBlockPlayersCount.Y + this.m_pBlockPlayersCount.Height + this.m_iOffsetY;
- Width = this.m_pBlockPlayersCount.Width;
- Height = this.m_pBlockPlayersCount.Height;
- Description = (string)( math.floor( fDistance ) ) .. _( " km." );
- };
- local iReward = pData.Reward;
- this.m_pBlockReward = this:CreateBlock( _( "Reward" ) )
- {
- X = this.m_pBlockDistance.X;
- Y = this.m_pBlockDistance.Y + this.m_pBlockDistance.Height + this.m_iOffsetY;
- Width = this.m_pBlockDistance.Width;
- Height = this.m_pBlockDistance.Height;
- Description = math.currency( iReward );
- };
- -- Гонка начнется через.
- this.m_pLabelRaceStartTime = this.m_pField:CreateLabel( "" )
- {
- X = 0;
- Y = 278;
- Width = this.m_pField.Width;
- Height = 30;
- Font = this.Fonts.Medium;
- HorizontalAlign = { "center" };
- ColorCoded = true;
- };
- -- Блок кнопок, чтобы их отцентрировать нормально.
- this.m_pFieldBottom = this.m_pField:CreateField()
- {
- X = "center";
- Y = 330;
- Width = 311;
- Height = 39;
- };
- -- Выйти
- this.m_pButtonLeave = this.m_pFieldBottom:CreateButtonImpl( _( "LEAVE" ) )
- {
- X = 0;
- Y = 0;
- Width = 127;
- Height = this.m_pFieldBottom.Height;
- OnClick = function()
- if ( this:IsInLobby() ) then
- local function Complete()
- HideRaceJoin();
- end;
- this:RPC( Complete, "OnPlayerLeave" );
- else
- HideRaceJoin();
- end
- end;
- };
- -- Присоедениться.
- this.m_pButtonJoin = this.m_pFieldBottom:CreateButtonImpl( _( "JOIN" ) )
- {
- X = this.m_pButtonLeave.X + this.m_pButtonLeave.Width + 13;
- Y = this.m_pButtonLeave.Y;
- Width = 170;
- Height = this.m_pFieldBottom.Height;
- OnClick = function()
- -- Останавливаем машину чтобы из маркера не укатился.
- CLIENT:GetVehicle():SetSpeed( 0.0 );
- if ( this:IsInLobby() ) then
- ShowMessage( "Внимание", _( "You're already in the lobby" ), "Warning" );
- return;
- end
- local sLimits = this:GetLimits();
- if ( sLimits and sLimits ~= "" ) then
- ShowMessage( "Внимание", sLimits, "Warning" );
- return;
- end
- local function Complete()
- -- Выключаем кнопку присоедениться.
- this.m_pButtonJoin:SetEnabled( false );
- end;
- this:RPC( Complete, "OnPlayerJoin" );
- end;
- };
- -- Ограничения. + 57y
- this.m_pLabelLimits = this.m_pField:CreateLabel( pData.Limits or "" )
- {
- X = 0;
- Y = this.m_pFieldBottom.Y + 57;
- Width = this.m_pField.Width;
- Height = 60;
- HorizontalAlign = { "center", true };
- Font = this.Fonts.Medium3;
- Color = this.Colors.Red;
- };
- if ( pData.Time ) then
- this:SetWaitCount( pData.Time );
- end
- if ( pData.Wait ) then
- this:SetWaitStatus( pData.Wait );
- end
- if ( pData.Players ) then
- this:SetPlayers( pData.Players );
- end
- this:CDoPulse( 300 );
- this:DoPulse();
- showCursor( true );
- CTimer(
- function()
- if ( not IsRaceJoinVisible() ) then
- return;
- end
- showCursor( true );
- end,
- 1000, 1 );
- this.m_pEventHandler = CEventHandler( this );
- this.m_pEventHandler:GetEvent():Bind( "onClientChatInputToggle", CLIENT, this.OnUpdateCursor );
- -- Режем скорость.
- exports.gm_ui_enterdialog:API( "EvalCall", "CUIEnterDialog", "ChangeSpeed" );
- end;
- _CUIRaceJoin = function( this )
- delete( this.m_pEventHandler );
- this:_CUIAsyncQuery();
- showCursor( false );
- this:_CDoPulse();
- delete( this.m_pFade );
- this.m_pFade = NULL;
- this.m_pField:Delete();
- this.m_pField = NULL;
- end;
- DoPulse = function( this )
- this:UpdateRaceInfo();
- end;
- ------
- -- Utils
- UpdateRaceInfo = function( this )
- -- Обновляем кол-во игроков.
- local iPlayers = this:GetPlayers();
- local iMaxPlayers = this:GetMaxPlayers();
- this.m_pBlockPlayersCount.m_pLabelDescription:SetText( (string)( iPlayers ) .. "/" .. (string)( iMaxPlayers ) );
- -- Обновляем ожидание.
- if ( this:IsWaitStatus() ) then
- if ( this:GetMaxPlayers() == 1 ) then
- this.m_pLabelRaceStartTime:SetText( _( "WAIT PLAYER (NEED 1 PLAYER FOR START)" ) );
- elseif ( this:GetMaxPlayers() > 1 ) then
- this.m_pLabelRaceStartTime:SetText( _( "WAIT PLAYERS (NEED 1 MORE PLAYER FOR START)" ) );
- end
- return;
- end
- local iTime = this:GetWaitCount();
- local sMin, sSec = MsToTimeStr( iTime * 1000 );
- this.m_pLabelRaceStartTime:SetText( _( "RACE WILL STARTS IN: " ) .. this.Colors.Theme .. "" .. sMin .. ":" .. sSec );
- end;
- SetWaitStatus = function( this, bState )
- this.m_bWaitStatus = (bool)(bState);
- end;
- IsWaitStatus = function( this )
- return this.m_bWaitStatus;
- end;
- SetWaitCount = function( this, iCount )
- this.m_iWaitCount = (int)(iCount);
- end;
- GetWaitCount = function( this )
- return this.m_iWaitCount;
- end;
- SetPlayers = function( this, iCount )
- this.m_iPlayers = (int)(iCount);
- end;
- GetPlayers = function( this )
- return this.m_iPlayers;
- end;
- CreateBlock = function( this, sTitle )
- return function( pData )
- local pBlock = this.m_pField:CreateField()
- {
- X = pData.X;
- Y = pData.Y;
- Width = pData.Width;
- Height = pData.Height;
- };
- local pLabelTitle = pBlock:CreateLabel( sTitle )
- {
- X = 0;
- Y = 0;
- Width = pBlock.Width;
- Height = 30;
- Font = this.Fonts.Medium;
- };
- local pLabelDescription = pBlock:CreateLabel( pData.Description or "" )
- {
- X = 0;
- Y = 0;
- Width = pBlock.Width;
- Height = 30;
- HorizontalAlign = { "right" };
- Font = this.Fonts.Medium;
- Color = this.Colors.Theme;
- };
- local pRectLine = pBlock:CreateRectangle()
- {
- X = 0;
- Y = 30;
- Width = pBlock.Width;
- Height = 1;
- Color = this.Colors.White;
- Opacity = pData.LineOpacity or 0.15;
- };
- pBlock.m_pLabelTitle = pLabelTitle;
- pBlock.m_pLabelDescription = pLabelDescription;
- return pBlock;
- end;
- end;
- GetLimits = function( this )
- return this.m_sLimits;
- end;
- RPC = function( this, vCallBack, sMethod )
- this:AsyncQuery( vCallBack, "Race__CallServerRPC", sMethod );
- end;
- IsInLobby = function( this )
- return CLIENT:GetStatus() == "race_lobby";
- end;
- GetMaxPlayers = function( this )
- return this.m_pData.MaxPlayers;
- end;
- OnUpdateCursor = function( this, bState )
- if ( not bState ) then
- showCursor( true );
- end
- end;
- };
- local pUIRaceJoin;
- function ShowRaceJoin( pData )
- if ( pUIRaceJoin ) then
- delete( pUIRaceJoin );
- end
- pUIRaceJoin = CUIRaceJoin( pData );
- end
- function HideRaceJoin()
- if ( pUIRaceJoin ) then
- delete( pUIRaceJoin );
- pUIRaceJoin = NULL;
- end
- end
- function IsRaceJoinVisible()
- return pUIRaceJoin ~= NULL;
- end
- function UpdateRaceJoinWait( pData )
- if ( not pUIRaceJoin ) then
- return;
- end
- pUIRaceJoin:SetPlayers( pData.m_iPlayers );
- pUIRaceJoin:SetWaitStatus( pData.m_bWait );
- pUIRaceJoin:SetWaitCount( pData.m_iCount );
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement