Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | None | 0 0
  1.  
  2. class: CPlayerBalanceHUD ( CHUDImplUtils )
  3. {
  4.     Fonts =
  5.     {
  6.         Medium      = DXFont( "Ubuntu/Ubuntu-Regular.ttf", 10 );
  7.         Medium2     = DXFont( "Ubuntu/Ubuntu-Regular.ttf", 11 );
  8.         Small       = DXFont( "Ubuntu/Ubuntu-Regular.ttf", 9 );
  9.     };
  10.    
  11.     Colors =
  12.     {
  13.         White   = "#ffffff";
  14.         Black   = "#000000";
  15.         Theme   = "#d19d22";
  16.     };
  17.  
  18.     m_iX        = F_SCREEN_X - 30 - 219;
  19.     m_iY        = 22;
  20.    
  21.     m_iWidth    = 219;
  22.     m_iHeight   = 33;
  23.    
  24.     m_sPath     = S_IMAGES_RESOURCE_HUD_PATH + "Player/balance/";
  25.    
  26.     m_iLastMoney    = - 1;
  27.     m_iLastLvl      = - 1;
  28.     m_iLastExp      = - 1;
  29.    
  30.     CPlayerBalanceHUD = function( this )
  31.         this.m_pBackground = CUILib():CreateStaticImage( this.m_sPath + "bg.png" )
  32.         {
  33.             X       = this.m_iX;
  34.             Y       = this.m_iY;
  35.            
  36.             Width   = this.m_iWidth;
  37.             Height  = this.m_iHeight;
  38.         };
  39.        
  40.         this.m_pLabelText = this.m_pBackground:CreateLabel( "" )
  41.         {
  42.             X       = 0;
  43.             Y       = -1;
  44.            
  45.             Width   = this.m_pBackground.Width - 14;
  46.             Height  = this.m_pBackground.Height;
  47.            
  48.             Font    = this.Fonts.Medium;
  49.            
  50.             Color   = this.Colors.Theme;
  51.            
  52.             HorizontalAlign = { "right" };
  53.             VerticalAlign = "center";
  54.         };
  55.        
  56.         this.m_pLabelLevel = this.m_pBackground:CreateLabel( "" )
  57.         {
  58.             X       = 57;
  59.             Y       = 5;
  60.            
  61.             Width   = 100;
  62.             Height  = 30;
  63.            
  64.             Font    = this.Fonts.Medium2;
  65.            
  66.             Color   = this.Colors.White;
  67.         };
  68.        
  69.         -- divider
  70.         this.m_pRectDiv = this.m_pBackground:CreateRectangle()
  71.         {
  72.             X       = 53;
  73.             Y       = "center";
  74.            
  75.             Width   = 1;
  76.             Height  = 27;
  77.            
  78.             Color   = this.Colors.White;
  79.            
  80.             Opacity = 0.2;
  81.         };
  82.        
  83.         this.m_pLabelPrevExp = this.m_pBackground:CreateLabel( "" )
  84.         {
  85.             X       = 8;
  86.             Y       = 3;
  87.            
  88.             Width   = this.m_pLabelLevel.Width;
  89.             Height  = this.m_pLabelLevel.Height;
  90.            
  91.             Font    = this.Fonts.Small;
  92.            
  93.             Color   = this.Colors.White;
  94.            
  95.             Opacity = 1.0;
  96.         };
  97.        
  98.         this.m_pLabelNextExp = this.m_pBackground:CreateLabel( "" )
  99.         {
  100.             X       = this.m_pLabelPrevExp.X;
  101.             Y       = this.m_pLabelPrevExp.Y + this.m_pLabelPrevExp:GetTextHeight() - 5;
  102.            
  103.             Width   = this.m_pLabelLevel.Width;
  104.             Height  = this.m_pLabelLevel.Height;
  105.            
  106.             Font    = this.m_pLabelPrevExp.Font;
  107.            
  108.             Color   = this.m_pLabelPrevExp.Color;
  109.            
  110.             Opacity = 1.0;
  111.         };
  112.        
  113.         this.m_pRectProgressBg = this.m_pBackground:CreateRectangle()
  114.         {
  115.             X       = this.m_pLabelNextExp.X;
  116.             Y       = this.m_pLabelNextExp.Y + this.m_pLabelNextExp:GetTextHeight() - 2;
  117.            
  118.             Width   = 0;
  119.             Height  = 3;
  120.            
  121.             Color   = this.Colors.Black;
  122.            
  123.             Opacity = 0.5;
  124.         };
  125.        
  126.         this.m_pRectProgress = this.m_pRectProgressBg:CreateRectangle()
  127.         {
  128.             X       = 0;
  129.             Y       = 0;
  130.            
  131.             Width   = 0;
  132.             Height  = this.m_pRectProgressBg.Height;
  133.            
  134.             Color   = this.Colors.White;
  135.            
  136.             Opacity = 0.5;
  137.         };
  138.        
  139.         this:CHUD();
  140.     end;
  141.    
  142.     _CPlayerBalanceHUD = function( this )
  143.         this:_CHUD();
  144.        
  145.         this.m_pBackground:Delete();
  146.        
  147.         this.m_pBackground = NULL;
  148.     end;
  149.    
  150.     OnRender = function( this )
  151.         local iMoney = CLIENT:GetMoney();
  152.        
  153.         if ( iMoney ~= this.m_iLastMoney ) then
  154.             this.m_iLastMoney = iMoney;
  155.            
  156.             local sMoney = math.currency( iMoney );
  157.        
  158.             this.m_pLabelText:SetText( sMoney );
  159.         end
  160.        
  161.         local iLvl  = CLIENT:GetLevel();
  162.        
  163.         if ( iLvl ~= this.m_iLastLvl ) then
  164.             this.m_iLastLvl = iLvl;
  165.            
  166.             this.m_pLabelLevel:SetText( tostring( iLvl ) .. " " .. _( "Lvl" ) );
  167.         end
  168.        
  169.         local iExp = CLIENT:GetExp();
  170.        
  171.         if ( iExp ~= this.m_iLastExp ) then
  172.             this.m_iLastExp = iExp;
  173.            
  174.             local iPrevExp      = CLIENT:GetMaxExpByLevel( iLvl );
  175.             local iNextExp      = CLIENT:GetMaxExpByLevel( iLvl + 1 );
  176.             local fPercent      = CPercent.Between( iPrevExp, iExp, iNextExp );
  177.            
  178.             local sPrevExp = tostring( iExp );
  179.             local sNextExp = tostring( iNextExp );
  180.            
  181.             this.m_pLabelPrevExp:SetText( sPrevExp .. " /" );
  182.             this.m_pLabelNextExp:SetText( sNextExp );
  183.            
  184.             local iFullWidth    = this.m_pLabelPrevExp:GetTextExtent() + 2;
  185.            
  186.             -- Если меньше чем exp снизу, то берем снизу.
  187.             if ( iFullWidth < this.m_pLabelNextExp:GetTextExtent() ) then
  188.                 iFullWidth      = this.m_pLabelNextExp:GetTextExtent();
  189.             end
  190.            
  191.             local iWidth        = (int)( iFullWidth * ( fPercent / 100 ) );
  192.            
  193.             this.m_pRectProgress:SetWidth( iWidth );
  194.             this.m_pRectProgressBg:SetWidth( iFullWidth );
  195.         end
  196.     end;
  197.    
  198.     OnOverrideVisible = function( this, bState )
  199.         this.m_pBackground:SetVisible( bState, true );
  200.     end;
  201. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement