Advertisement
CsokiHUN

MTSA panel multiple tabs

Jul 16th, 2020
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. --Script By Csoki
  2.  
  3. local screenX, screenY = guiGetScreenSize()
  4.  
  5. local currentTab = 1
  6. local tabs = {
  7.     {
  8.         name = "oldal 1",
  9.         content = function(x, y, w, h) --Ide amit fel akarsz rajzolni tartalom
  10.             dxDrawText("oldal 1", x, y, x + w, y + h, tocolor(255, 0, 0), 1, "sans", "center", "center")
  11.         end
  12.     },
  13.     {
  14.         name = "oldal 2",
  15.         content = function(x, y, w, h) --Ide amit fel akarsz rajzolni tartalom
  16.             dxDrawText("oldal 2", x, y, x + w, y + h, tocolor(0, 255, 0), 1, "sans", "center", "center")
  17.         end
  18.     }
  19. }
  20. local hoverButton = false
  21.  
  22. function renderPanel()
  23.     hoverButton = false
  24.  
  25.     local padding = 10
  26.  
  27.     local w, h = 300, 200
  28.     local x, y = screenX/2 - w/2, screenY/2 - h/2
  29.     local _x, _y = x, y
  30.     dxDrawRectangle(x, y, w, h, tocolor(0, 0, 0, 180))
  31.  
  32.     local tabW, tabH = 100, 20
  33.     x = x - tabW - padding
  34.     for tabID, value in pairs(tabs) do
  35.         dxDrawRectangle(x, y, tabW, tabH, tocolor(0, 0, 0, 180))
  36.         if isMouseInPosition(x, y, tabW, tabH) then
  37.             dxDrawRectangle(x, y, tabW, tabH, tocolor(100, 100, 100, 50))
  38.             hoverButton = tabID
  39.         end
  40.         dxDrawText(value.name, x, y, x + tabW, y + tabH, tocolor(255, 255, 255), 1, "default", "center", "center")
  41.  
  42.         y = y + tabH + padding
  43.     end
  44.  
  45.     if tabs[currentTab] then
  46.         tabs[currentTab].content(_x, _y, w, h)
  47.     end
  48.  
  49. end
  50.  
  51. function clickPanel(button, state)
  52.     if button == "left" and state == "down" then
  53.         if hoverButton then
  54.             if currentTab ~= hoverButton then
  55.                 currentTab = hoverButton
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. function openPanel()
  62.     removeEventHandler("onClientRender", root, renderPanel)
  63.     addEventHandler("onClientRender", root, renderPanel)
  64.  
  65.     removeEventHandler("onClientClick", root, clickPanel)
  66.     addEventHandler("onClientClick", root, clickPanel)
  67.  
  68.     hoverButton = false
  69. end
  70. addEventHandler("onClientResourceStart", root, openPanel)
  71.  
  72. --Useful from mta wiki
  73. function isMouseInPosition ( x, y, width, height )
  74.     if ( not isCursorShowing( ) ) then
  75.         return false
  76.     end
  77.     local sx, sy = guiGetScreenSize ( )
  78.     local cx, cy = getCursorPosition ( )
  79.     local cx, cy = ( cx * sx ), ( cy * sy )
  80.    
  81.     return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement