Advertisement
Guest User

The ui for interaction detection

a guest
Jan 25th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local infoBar = {};
  2. local isShowing = false;
  3. local sx, sy = guiGetScreenSize();
  4. local bgColor = tocolor(0, 0, 0, 180); -- DRY
  5. local dc = tocolor(255, 0, 0);
  6. local dc2 = tocolor(0, 255, 0);
  7. local dc3 = tocolor(0, 0, 255);
  8.    
  9. -- Testing only
  10. local title = "There is an interactable object";
  11.  
  12. function drawInfoBar()
  13.     -- Draw the background
  14.     dxDrawRectangle( (sx/2)-180, 0, 360, 50, bgColor );  
  15.    
  16.     -- Draw the title
  17.     local width = dxGetTextWidth( infoBar.text, 1.2 );
  18.     dxDrawText( infoBar.text, (sx/2)-(width/2), 12, sx, sy, tocolor(255, 255, 255), 1.2 );
  19. end
  20.  
  21. function toggleInfoBar(text)
  22.     text = text or "";
  23.    
  24.     if isShowing then
  25.         local result = removeEventHandler("onClientRender", getRootElement(), drawInfoBar);
  26.         if result then
  27.             infoBar = {};
  28.             isShowing = false;
  29.         end
  30.     else
  31.         infoBar = {
  32.             text = text,
  33.         };
  34.         local result = addEventHandler("onClientRender", getRootElement(), drawInfoBar);
  35.         if result then
  36.             isShowing = true;
  37.         end
  38.     end
  39. end
  40.  
  41. addCommandHandler("testbar",
  42.     function()
  43.         toggleInfoBar("Press 'B' to interact with this object!");
  44.     end
  45. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement