Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.17 KB | None | 0 0
  1.  
  2. class: CUIRaceJoin ( CDoPulse, CUIAsyncQuery )
  3. {
  4. Fonts =
  5. {
  6. Medium = DXFont( "Montserrat/Montserrat-Bold.otf", 10 );
  7. Medium2 = DXFont( "Montserrat/Montserrat-Bold.otf", 12 );
  8. Medium3 = DXFont( "Montserrat/Montserrat-Bold.otf", 9 );
  9. };
  10.  
  11. Colors =
  12. {
  13. White = "#ffffff";
  14. Black = "#000000";
  15. Theme = "#fbbd2f";
  16. Red = "#e31111";
  17. };
  18.  
  19. m_sPath = S_IMAGES_RESOURCE_UI_PATH + "race_join/";
  20.  
  21. m_iStartX = 0;
  22. m_iStartY = 103;
  23.  
  24. m_iItemHeight = 26;
  25.  
  26. m_iOffsetY = 16;
  27. m_iWaitTime = 0;
  28.  
  29. CUIRaceJoin = function( this, pData )
  30. this.m_pData = pData;
  31.  
  32. this.m_sLimits = pData.Limits;
  33.  
  34. -- Показываем фейд
  35. this.m_pFade = CUIFadeBackground();
  36.  
  37. -- Поле.
  38. this.m_pField = CUILib():CreateField()
  39. {
  40. X = "center";
  41. Y = 104;
  42.  
  43. Width = 520;
  44. Height = 404;
  45. };
  46.  
  47. -- Поле (вверх)
  48. this.m_pFieldTop = this.m_pField:CreateField()
  49. {
  50. X = 0;
  51. Y = 0;
  52.  
  53. Width = this.m_pField.Width;
  54. Height = 60;
  55. };
  56.  
  57. -- Иконка (гонка)
  58. this.m_pImageIcon = this.m_pFieldTop:CreateStaticImage( this.m_sPath + "icon.png" )
  59. {
  60. X = - 5;
  61. Y = "center";
  62.  
  63. Width = 35;
  64. Height = 35;
  65. };
  66.  
  67. -- 35
  68. this.m_pLabelRaceName = this.m_pFieldTop:CreateLabel( ( pData.Name or "" ):upper() )
  69. {
  70. X = 37;
  71. Y = 20 - 5;
  72.  
  73. Width = 350;
  74. Height = 30;
  75.  
  76. Font = this.Fonts.Medium2;
  77. };
  78.  
  79. this.m_pLabelRaceType = this.m_pFieldTop:CreateLabel( _( pData.Type or "" ) )
  80. {
  81. X = this.m_pLabelRaceName.X;
  82. Y = this.m_pLabelRaceName.Y + 20;
  83.  
  84. Width = this.m_pLabelRaceName.Width;
  85. Height = this.m_pLabelRaceName.Height;
  86.  
  87. Font = this.Fonts.Medium;
  88.  
  89. Color = this.Colors.Theme;
  90. };
  91.  
  92. -- Карта
  93. this.m_pImageMap = this.m_pFieldTop:CreateStaticImage( this.m_sPath + "map.png" )
  94. {
  95. X = this.m_pFieldTop.Width - 100;
  96. Y = "center";
  97.  
  98. Width = 100;
  99. Height = 70;
  100. };
  101.  
  102. -- Список-блоки
  103. local sCategory = pData.Category;
  104.  
  105. this.m_pBlockCategory = this:CreateBlock( _( "Car category:" ) )
  106. {
  107. X = this.m_iStartX;
  108. Y = this.m_iStartY;
  109.  
  110. Width = this.m_pField.Width - ( this.m_iStartX * 2 );
  111. Height = this.m_iItemHeight;
  112.  
  113. Description = sCategory or "";
  114. };
  115.  
  116. this.m_pBlockPlayersCount = this:CreateBlock( _( "Number of players" ) )
  117. {
  118. X = this.m_pBlockCategory.X;
  119. Y = this.m_pBlockCategory.Y + this.m_pBlockCategory.Height + this.m_iOffsetY;
  120.  
  121. Width = this.m_pBlockCategory.Width;
  122. Height = this.m_pBlockCategory.Height;
  123.  
  124. Description = "";
  125. };
  126.  
  127. local fDistance = pData.Distance;
  128.  
  129. this.m_pBlockDistance = this:CreateBlock( _( "Distance" ) )
  130. {
  131. X = this.m_pBlockPlayersCount.X;
  132. Y = this.m_pBlockPlayersCount.Y + this.m_pBlockPlayersCount.Height + this.m_iOffsetY;
  133.  
  134. Width = this.m_pBlockPlayersCount.Width;
  135. Height = this.m_pBlockPlayersCount.Height;
  136.  
  137. Description = (string)( math.floor( fDistance ) ) .. _( " km." );
  138. };
  139.  
  140. local iReward = pData.Reward;
  141.  
  142. this.m_pBlockReward = this:CreateBlock( _( "Reward" ) )
  143. {
  144. X = this.m_pBlockDistance.X;
  145. Y = this.m_pBlockDistance.Y + this.m_pBlockDistance.Height + this.m_iOffsetY;
  146.  
  147. Width = this.m_pBlockDistance.Width;
  148. Height = this.m_pBlockDistance.Height;
  149.  
  150. Description = math.currency( iReward );
  151. };
  152.  
  153. -- Гонка начнется через.
  154. this.m_pLabelRaceStartTime = this.m_pField:CreateLabel( "" )
  155. {
  156. X = 0;
  157. Y = 278;
  158.  
  159. Width = this.m_pField.Width;
  160. Height = 30;
  161.  
  162. Font = this.Fonts.Medium;
  163.  
  164. HorizontalAlign = { "center" };
  165.  
  166. ColorCoded = true;
  167. };
  168.  
  169. -- Блок кнопок, чтобы их отцентрировать нормально.
  170. this.m_pFieldBottom = this.m_pField:CreateField()
  171. {
  172. X = "center";
  173. Y = 330;
  174.  
  175. Width = 311;
  176. Height = 39;
  177. };
  178.  
  179. -- Выйти
  180. this.m_pButtonLeave = this.m_pFieldBottom:CreateButtonImpl( _( "LEAVE" ) )
  181. {
  182. X = 0;
  183. Y = 0;
  184.  
  185. Width = 127;
  186. Height = this.m_pFieldBottom.Height;
  187.  
  188. OnClick = function()
  189. if ( this:IsInLobby() ) then
  190. local function Complete()
  191. HideRaceJoin();
  192. end;
  193.  
  194. this:RPC( Complete, "OnPlayerLeave" );
  195. else
  196. HideRaceJoin();
  197. end
  198. end;
  199. };
  200.  
  201. -- Присоедениться.
  202. this.m_pButtonJoin = this.m_pFieldBottom:CreateButtonImpl( _( "JOIN" ) )
  203. {
  204. X = this.m_pButtonLeave.X + this.m_pButtonLeave.Width + 13;
  205. Y = this.m_pButtonLeave.Y;
  206.  
  207. Width = 170;
  208. Height = this.m_pFieldBottom.Height;
  209.  
  210. OnClick = function()
  211. -- Останавливаем машину чтобы из маркера не укатился.
  212. CLIENT:GetVehicle():SetSpeed( 0.0 );
  213.  
  214. if ( this:IsInLobby() ) then
  215. ShowMessage( "Внимание", _( "You're already in the lobby" ), "Warning" );
  216.  
  217. return;
  218. end
  219.  
  220. local sLimits = this:GetLimits();
  221.  
  222. if ( sLimits and sLimits ~= "" ) then
  223. ShowMessage( "Внимание", sLimits, "Warning" );
  224.  
  225. return;
  226. end
  227.  
  228. local function Complete()
  229. -- Выключаем кнопку присоедениться.
  230. this.m_pButtonJoin:SetEnabled( false );
  231. end;
  232.  
  233. this:RPC( Complete, "OnPlayerJoin" );
  234. end;
  235. };
  236.  
  237. -- Ограничения. + 57y
  238. this.m_pLabelLimits = this.m_pField:CreateLabel( pData.Limits or "" )
  239. {
  240. X = 0;
  241. Y = this.m_pFieldBottom.Y + 57;
  242.  
  243. Width = this.m_pField.Width;
  244. Height = 60;
  245.  
  246. HorizontalAlign = { "center", true };
  247.  
  248. Font = this.Fonts.Medium3;
  249.  
  250. Color = this.Colors.Red;
  251. };
  252.  
  253. if ( pData.Time ) then
  254. this:SetWaitCount( pData.Time );
  255. end
  256.  
  257. if ( pData.Wait ) then
  258. this:SetWaitStatus( pData.Wait );
  259. end
  260.  
  261. if ( pData.Players ) then
  262. this:SetPlayers( pData.Players );
  263. end
  264.  
  265. this:CDoPulse( 300 );
  266.  
  267. this:DoPulse();
  268.  
  269. showCursor( true );
  270.  
  271. CTimer(
  272. function()
  273. if ( not IsRaceJoinVisible() ) then
  274. return;
  275. end
  276.  
  277. showCursor( true );
  278. end,
  279. 1000, 1 );
  280.  
  281. this.m_pEventHandler = CEventHandler( this );
  282.  
  283. this.m_pEventHandler:GetEvent():Bind( "onClientChatInputToggle", CLIENT, this.OnUpdateCursor );
  284.  
  285. -- Режем скорость.
  286. exports.gm_ui_enterdialog:API( "EvalCall", "CUIEnterDialog", "ChangeSpeed" );
  287. end;
  288.  
  289. _CUIRaceJoin = function( this )
  290. delete( this.m_pEventHandler );
  291.  
  292. this:_CUIAsyncQuery();
  293.  
  294. showCursor( false );
  295.  
  296. this:_CDoPulse();
  297.  
  298. delete( this.m_pFade );
  299.  
  300. this.m_pFade = NULL;
  301.  
  302. this.m_pField:Delete();
  303.  
  304. this.m_pField = NULL;
  305. end;
  306.  
  307. DoPulse = function( this )
  308. this:UpdateRaceInfo();
  309. end;
  310.  
  311. ------
  312. -- Utils
  313.  
  314. UpdateRaceInfo = function( this )
  315. -- Обновляем кол-во игроков.
  316. local iPlayers = this:GetPlayers();
  317. local iMaxPlayers = this:GetMaxPlayers();
  318.  
  319. this.m_pBlockPlayersCount.m_pLabelDescription:SetText( (string)( iPlayers ) .. "/" .. (string)( iMaxPlayers ) );
  320.  
  321. -- Обновляем ожидание.
  322. if ( this:IsWaitStatus() ) then
  323. if ( this:GetMaxPlayers() == 1 ) then
  324. this.m_pLabelRaceStartTime:SetText( _( "WAIT PLAYER (NEED 1 PLAYER FOR START)" ) );
  325. elseif ( this:GetMaxPlayers() > 1 ) then
  326. this.m_pLabelRaceStartTime:SetText( _( "WAIT PLAYERS (NEED 1 MORE PLAYER FOR START)" ) );
  327. end
  328.  
  329. return;
  330. end
  331.  
  332. local iTime = this:GetWaitCount();
  333.  
  334. local sMin, sSec = MsToTimeStr( iTime * 1000 );
  335.  
  336. this.m_pLabelRaceStartTime:SetText( _( "RACE WILL STARTS IN: " ) .. this.Colors.Theme .. "" .. sMin .. ":" .. sSec );
  337. end;
  338.  
  339. SetWaitStatus = function( this, bState )
  340. this.m_bWaitStatus = (bool)(bState);
  341. end;
  342.  
  343. IsWaitStatus = function( this )
  344. return this.m_bWaitStatus;
  345. end;
  346.  
  347. SetWaitCount = function( this, iCount )
  348. this.m_iWaitCount = (int)(iCount);
  349. end;
  350.  
  351. GetWaitCount = function( this )
  352. return this.m_iWaitCount;
  353. end;
  354.  
  355. SetPlayers = function( this, iCount )
  356. this.m_iPlayers = (int)(iCount);
  357. end;
  358.  
  359. GetPlayers = function( this )
  360. return this.m_iPlayers;
  361. end;
  362.  
  363. CreateBlock = function( this, sTitle )
  364. return function( pData )
  365. local pBlock = this.m_pField:CreateField()
  366. {
  367. X = pData.X;
  368. Y = pData.Y;
  369.  
  370. Width = pData.Width;
  371. Height = pData.Height;
  372. };
  373.  
  374. local pLabelTitle = pBlock:CreateLabel( sTitle )
  375. {
  376. X = 0;
  377. Y = 0;
  378.  
  379. Width = pBlock.Width;
  380. Height = 30;
  381.  
  382. Font = this.Fonts.Medium;
  383. };
  384.  
  385. local pLabelDescription = pBlock:CreateLabel( pData.Description or "" )
  386. {
  387. X = 0;
  388. Y = 0;
  389.  
  390. Width = pBlock.Width;
  391. Height = 30;
  392.  
  393. HorizontalAlign = { "right" };
  394.  
  395. Font = this.Fonts.Medium;
  396.  
  397. Color = this.Colors.Theme;
  398. };
  399.  
  400. local pRectLine = pBlock:CreateRectangle()
  401. {
  402. X = 0;
  403. Y = 30;
  404.  
  405. Width = pBlock.Width;
  406. Height = 1;
  407.  
  408. Color = this.Colors.White;
  409.  
  410. Opacity = pData.LineOpacity or 0.15;
  411. };
  412.  
  413. pBlock.m_pLabelTitle = pLabelTitle;
  414. pBlock.m_pLabelDescription = pLabelDescription;
  415.  
  416. return pBlock;
  417. end;
  418. end;
  419.  
  420. GetLimits = function( this )
  421. return this.m_sLimits;
  422. end;
  423.  
  424. RPC = function( this, vCallBack, sMethod )
  425. this:AsyncQuery( vCallBack, "Race__CallServerRPC", sMethod );
  426. end;
  427.  
  428. IsInLobby = function( this )
  429. return CLIENT:GetStatus() == "race_lobby";
  430. end;
  431.  
  432. GetMaxPlayers = function( this )
  433. return this.m_pData.MaxPlayers;
  434. end;
  435.  
  436. OnUpdateCursor = function( this, bState )
  437. if ( not bState ) then
  438. showCursor( true );
  439. end
  440. end;
  441. };
  442.  
  443. local pUIRaceJoin;
  444.  
  445. function ShowRaceJoin( pData )
  446. if ( pUIRaceJoin ) then
  447. delete( pUIRaceJoin );
  448. end
  449.  
  450. pUIRaceJoin = CUIRaceJoin( pData );
  451. end
  452.  
  453. function HideRaceJoin()
  454. if ( pUIRaceJoin ) then
  455. delete( pUIRaceJoin );
  456.  
  457. pUIRaceJoin = NULL;
  458. end
  459. end
  460.  
  461. function IsRaceJoinVisible()
  462. return pUIRaceJoin ~= NULL;
  463. end
  464.  
  465. function UpdateRaceJoinWait( pData )
  466. if ( not pUIRaceJoin ) then
  467. return;
  468. end
  469.  
  470. pUIRaceJoin:SetPlayers( pData.m_iPlayers );
  471. pUIRaceJoin:SetWaitStatus( pData.m_bWait );
  472. pUIRaceJoin:SetWaitCount( pData.m_iCount );
  473. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement