Advertisement
Guest User

sourceC.lua

a guest
Feb 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 KB | None | 0 0
  1. local displayWidth, displayHeight = guiGetScreenSize();
  2.  
  3. local notificationData = {};
  4.  
  5. local notificationFont = dxCreateFont('files/fonts/roboto.ttf', 12 * 2, false);
  6. local iconsFont = dxCreateFont('files/fonts/icons.ttf', 12 * 2, false);
  7.  
  8. addEventHandler('onClientRender', root,
  9.     function()
  10.         for k, v in pairs(notificationData) do
  11.             if (v.State == 'fadeIn') then
  12.                 local alphaProgress = (getTickCount() - v.AlphaTick) / 650;
  13.                 local alphaAnimation = interpolateBetween(0, 0, 0, 255, 0, 0, alphaProgress, 'Linear');
  14.                
  15.                 if (alphaAnimation) then
  16.                     v.Alpha = alphaAnimation;
  17.                 else
  18.                     v.Alpha = 255;
  19.                 end
  20.                
  21.                 if (alphaProgress > 1) then
  22.                     v.Tick = getTickCount();
  23.                     v.State = 'openTile';
  24.                 end
  25.             elseif (v.State == 'fadeOut') then
  26.                 local alphaProgress = (getTickCount() - v.AlphaTick) / 650;
  27.                 local alphaAnimation = interpolateBetween(255, 0, 0, 0, 0, 0, alphaProgress, 'Linear');
  28.                
  29.                 if (alphaAnimation) then
  30.                     v.Alpha = alphaAnimation;
  31.                 else
  32.                     v.Alpha = 0;
  33.                 end
  34.                
  35.                 if (alphaProgress > 1) then
  36.                     notificationData = {};
  37.                 end
  38.             elseif (v.State == 'openTile') then
  39.                 local tileProgress = (getTickCount() - v.Tick) / 350;
  40.                 local tilePosition = interpolateBetween(v.StartX, 0, 0, v.EndX, 0, 0, tileProgress, 'Linear');
  41.                 local tileWidth = interpolateBetween(0, 0, 0, v.Width, 0, 0, tileProgress, 'Linear');
  42.                
  43.                 if (tilePosition and tileWidth) then
  44.                     v.CurrentX = tilePosition;
  45.                     v.CurrentWidth = tileWidth;
  46.                 else
  47.                     v.CurrentX = v.EndX;
  48.                     v.CurrentWidth = v.Width;
  49.                 end
  50.                
  51.                 if (tileProgress > 1) then
  52.                     v.State = 'fixTile';
  53.                    
  54.                     setTimer(function()
  55.                         v.Tick = getTickCount();
  56.                         v.State = 'closeTile';
  57.                     end, string.len(v.Text) * 45 + 5000, 1);
  58.                 end
  59.             elseif (v.State == 'closeTile') then
  60.                 local tileProgress = (getTickCount() - v.Tick) / 350;
  61.                 local tilePosition = interpolateBetween(v.EndX, 0, 0, v.StartX, 0, 0, tileProgress, 'Linear');
  62.                 local tileWidth = interpolateBetween(v.Width, 0, 0, 0, 0, 0, tileProgress, 'Linear');
  63.                
  64.                 if (tilePosition and tileWidth) then
  65.                     v.CurrentX = tilePosition;
  66.                     v.CurrentWidth = tileWidth;
  67.                 else
  68.                     v.CurrentX = v.StartX;
  69.                     v.CurrentWidth = 0;
  70.                 end
  71.                
  72.                 if (tileProgress > 1) then
  73.                     v.AlphaTick = getTickCount();
  74.                     v.State = 'fadeOut';
  75.                 end
  76.             elseif (v.State == 'fixTile') then
  77.                 v.Alpha = 255;
  78.                 v.CurrentX = v.EndX;
  79.                 v.CurrentWidth = v.Width;
  80.             end
  81.            
  82.             roundedRectangle(v.CurrentX, 20, 25 + v.CurrentWidth, 25, tocolor(0, 0, 0, 150 * v.Alpha / 255), _, true);
  83.             dxDrawRectangle(v.CurrentX, 20, 25, 25, tocolor(0, 0, 0, 255 * v.Alpha / 255), true);
  84.            
  85.             if (v.Alpha == 255) then
  86.                 dxDrawText(v.Text, v.CurrentX + 25 + 10, 20, v.CurrentX + 25 + 10 + v.CurrentWidth - 20, 20 + 25, tocolor(255, 255, 255, 255), 0.40, notificationFont, 'center', 'center', true, false, true);
  87.             end
  88.            
  89.             if (v.Type == 'error') then
  90.                 dxDrawText('', v.CurrentX + 5, 20, v.CurrentX + 5 + 25 - 10, 20 + 25, tocolor(215, 90, 90, v.Alpha), 0.50, iconsFont, 'center', 'center', false, false, true);
  91.             elseif (v.Type == 'warning') then
  92.                 dxDrawText('', v.CurrentX + 5, 20, v.CurrentX + 5 + 25 - 10, 20 + 25, tocolor(220, 180, 80, v.Alpha), 0.50, iconsFont, 'center', 'center', false, false, true);
  93.             elseif (v.Type == 'info') then
  94.                 dxDrawText('', v.CurrentX + 5, 20, v.CurrentX + 5 + 25 - 10, 20 + 25, tocolor(85, 180, 245, v.Alpha), 0.50, iconsFont, 'center', 'center', false, false, true);
  95.             elseif (v.Type == 'success') then
  96.                 dxDrawText('', v.CurrentX + 5, 20, v.CurrentX + 5 + 25 - 10, 20 + 25, tocolor(80, 205, 105, v.Alpha), 0.50, iconsFont, 'center', 'center', false, false, true);
  97.             end
  98.         end
  99.     end
  100. )
  101.  
  102. function addNotification(text, type)
  103.     if (text and type) then
  104.         if (notificationData ~= nil) then
  105.             table.remove(notificationData, #notificationData);
  106.         end
  107.        
  108.         table.insert(notificationData,
  109.             {
  110.                 StartX = (displayWidth / 2) - (25 / 2),
  111.                 EndX = (displayWidth / 2) - ((dxGetTextWidth(text, 0.40, notificationFont) + 20 + 25) / 2),
  112.                 Text = text,
  113.                 Width = dxGetTextWidth(text, 0.40, notificationFont) + 20,
  114.                 Alpha = 0,
  115.                 State = 'fadeIn',
  116.                 Tick = 0,
  117.                 AlphaTick = getTickCount(),
  118.                 CurrentX = (displayWidth / 2) - (25 / 2),
  119.                 CurrentWidth = 0,
  120.                 Type = type or 'info'
  121.             }
  122.         );
  123.        
  124.         playSoundFrontEnd(11);
  125.     end
  126. end
  127.  
  128. function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI)
  129.     if (x and y and w and h) then
  130.         if (not borderColor) then
  131.             borderColor = tocolor(0, 0, 0, 200);
  132.         end
  133.        
  134.         if (not bgColor) then
  135.             bgColor = borderColor;
  136.         end
  137.        
  138.         --> Background
  139.         dxDrawRectangle(x, y, w, h, bgColor, postGUI);
  140.        
  141.         --> Border
  142.         dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI); -- top
  143.         dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI); -- bottom
  144.         dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI); -- left
  145.         dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI); -- right
  146.     end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement