Advertisement
Mouamle

TGMta

May 5th, 2016
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.81 KB | None | 0 0
  1. function createLayOut(x, y, w, h)
  2.     local ofset = Vector2(0, 0);
  3.     local visable = true;
  4.     Panel = {
  5.         x = 25, y = 25,
  6.         w = 350, h = 600,
  7.  
  8.         comps = {},
  9.  
  10.         render = function ( )
  11.             dxDrawRectangle( Panel.x+ ofset:getX(), Panel.y + ofset:getY(), Panel.w, Panel.h, tocolor( 0, 0, 0, 180 ) )
  12.             for k,v in pairs(Panel.comps) do
  13.                 if ( v.getVisable() ) then
  14.                     v.setOfset(ofset:getX() + Panel.x, ofset:getY() + Panel.y)
  15.                     v.render();
  16.                 end
  17.             end
  18.         end,
  19.         setVisable = function ( bool )
  20.             visable = bool;
  21.         end,
  22.         getVisable = function ( )
  23.             return visable
  24.         end,
  25.         setOfset = function ( x, y )
  26.             ofset:setX(x)
  27.             ofset:setY(y)
  28.         end,
  29.  
  30.         isMouseInside = function (  )
  31.             return false;
  32.         end,
  33.  
  34.         add = function ( comp )
  35.             comp.setOfset(Panel.x, Panel.y)
  36.             table.insert(Panel.comps, comp)
  37.         end
  38.     }
  39.     Panel.x = x; Panel.y = y; Panel.w = w; Panel.h = h;
  40.     return Panel;
  41. end
  42.  
  43. function CreateListView(x, y, w, h)
  44.     local ofset = Vector2(0, 0);
  45.  
  46.     local visable = true;
  47.     List = {
  48.         x = 30, y = 30,
  49.         w = 345, h = 595,
  50.         Color = tocolor( 0, 0, 0, 255 ),
  51.         items = {},
  52.         render = function ( )
  53.             local x = List.x + ofset:getX()
  54.             local y = List.y + ofset:getY()
  55.             local w = List.w + ofset:getX()
  56.             local h = List.h + ofset:getY()
  57.             dxDrawLine( x + 3, y + 5, w - 3, y + 5, List.Color, 3) -- top
  58.             dxDrawLine( x + 3, h - 5, w - 3, h - 5, List.Color, 3) -- bottom
  59.             dxDrawLine( x+3 , y+5, x+3, h-5  , List.Color, 3) -- left
  60.             dxDrawLine( w-5 , h-5, w-5, y+5  , List.Color, 3) -- right
  61.             for k,v in pairs(List.items) do
  62.                 if ( v ~= nil ) then
  63.                     if ( v.getY() + y > y and v.getY() + y + v.getH() < h ) then
  64.                         v.setOfset(x, y)
  65.                         v.render()
  66.                         dxDrawLine(x+2, v.getH() + v.getY() + 5 + y,
  67.                                    w-3, v.getH() + 5 + v.getY() + y,
  68.                                    List.Color, 2)
  69.                     end
  70.                 end
  71.             end
  72.  
  73.         end,
  74.         addItem = function (item)
  75.             table.insert(List.items, item)
  76.         end,
  77.         setOfset = function ( x, y )
  78.             ofset:setX(x)
  79.             ofset:setY(y)
  80.         end,
  81.         setVisable = function ( bool )
  82.             visable = bool;
  83.         end,
  84.         getVisable = function ( )
  85.             return visable
  86.         end,
  87.         move = function ( state )
  88.             for k,v in pairs(List.items) do
  89.                 if ( v ~= nil ) then
  90.                     if ( state == "up" ) then
  91.                         v.setY(v.getY() - List.items[1].getH())
  92.                     elseif ( state == "down" ) then
  93.                         v.setY(v.getY() + List.items[1].getH())
  94.                     end
  95.                 end
  96.             end
  97.         end
  98.     }
  99.  
  100.     List.x = x; List.y = y; List.w = w; List.h = h;
  101.     return List;
  102. end
  103.  
  104. function createThePhone( x, y, width, height )
  105.     local renderBG = true;
  106.     local BGColor = tocolor( 255, 255, 255, 255 )
  107.     local Visable = true;
  108.     local TitleBarClicked = false;
  109.  
  110.     local LastClick = Vector2(0, 0);
  111.     -- color = {99, 137, 168}
  112.     local TitleBarColor = tocolor( 99, 137, 168, 255 )
  113.  
  114.     local function createTextButtons(x, y, w, h, text)
  115.         local visable = true;
  116.         local ofset = Vector2(0, 0)
  117.         local Color = tocolor( 0, 0, 0, 10 )
  118.         local ColorSpeare = Color;
  119.         local HoverColor = tocolor( 0, 0, 0, 100 )
  120.         Button = {
  121.             text = "Button",
  122.             x = 0, y = 0,
  123.             w = 0, h = 0,
  124.  
  125.             render = function (  )
  126.                 dxDrawRectangle( Button.x + ofset:getX(), Button.y + ofset:getY(), w, h, Color )
  127.                 dxDrawText( Button.text, ( (Button.x + ofset:getX()) + (w/2) ) - (string.len(text)*3), ((Button.y + ofset:getY()) - 7) + (h/2)  )
  128.                 --dxDrawText(Button.text, Button.x + ofset:getX(), Button.y + ofset:getY())
  129.             end,
  130.  
  131.             getText = function (  )
  132.                 return Button.text;
  133.             end,
  134.  
  135.             setOfset = function ( x, y )
  136.                 ofset = Vector2(x, y)
  137.             end,
  138.  
  139.             hover = function ( hover )
  140.                 if ( hover ) then
  141.                     Color = HoverColor;
  142.                 else
  143.                     Color = ColorSpeare;
  144.                 end
  145.             end,
  146.             setVisable = function ( bool )
  147.                 visable = bool;
  148.             end,
  149.             getVisable = function ( )
  150.                 return visable
  151.             end,
  152.             isMouseInside = function ()
  153.                 if ( not isCursorShowing() ) then return false; end
  154.                 SX, SY = guiGetScreenSize(); MX, MY = getCursorPosition();
  155.                 NX = MX * SX; NY = MY * SY;
  156.                 if ( NX > x + ofset:getX() and NX <= w + ofset:getX() + x and NY > y + ofset:getY() and NY <= h + ofset:getY() + y ) then
  157.                     return true;
  158.                 end
  159.                 return false;
  160.             end,
  161.  
  162.             onClick = function (b, state, x, y)
  163.                 if ( Button.isMouseInside() ) then
  164.                     if ( state == "down" ) then
  165.                         triggerEvent( "ButtonClicked", getRootElement(), b, Button )
  166.                     end
  167.                 end
  168.             end
  169.         }
  170.  
  171.         Button.x = x; Button.y = y; Button.text = text;
  172.         addEventHandler( "onClientClick", getRootElement(), Button.onClick )
  173.         return Button;
  174.     end
  175.  
  176.     Phone = {
  177.         x = 0, y = 0,
  178.         -- 450, 750,
  179.         width = 500, height = 800,
  180.  
  181.         comps = {},
  182.  
  183.         renderComps = function ()
  184.             for k,v in pairs(Phone.comps) do
  185.                 if ( v ~= nil ) then
  186.                     if ( v.getVisable() ) then
  187.                         v.setOfset(Phone.x, Phone.y)
  188.                         v.render()
  189.                         if ( v.isMouseInside() ) then
  190.                             v.hover(true);
  191.                         else
  192.                             v.hover(false);
  193.                         end
  194.                     end
  195.                 end
  196.             end
  197.         end,
  198.  
  199.         renderBGImage = function ()
  200.             if ( renderBG ) then
  201.                 dxDrawImage( Phone.x + 25, Phone.y + 30, 350, 600, "/res/bgs/MainBG.png" )
  202.             end
  203.         end,
  204.  
  205.         renderTitleBar = function ()
  206.             dxDrawRectangle( Phone.x, Phone.y, Phone.width, 25, TitleBarColor )
  207.             dxDrawText("Mta sa Telegram : " .. getPlayerName(getLocalPlayer()), Phone.x + 5, Phone.y + 5)
  208.         end,
  209.  
  210.         render = function ()
  211.             if ( Visable ) then
  212.                 local MX, MY = getCursorPosition();
  213.                 local SX, SY = guiGetScreenSize();
  214.                 local nx, ny = MX * SX, SY * MY
  215.                 if ( TitleBarClicked ) then
  216.                     Phone.x  = nx;
  217.                     Phone.y  = ny;
  218.                 end
  219.                 dxDrawRectangle( Phone.x, Phone.y, Phone.width, Phone.height, BGColor )
  220.                 Phone.renderBGImage()
  221.                 Phone.renderTitleBar();
  222.  
  223.                 Phone.renderComps()
  224.             end
  225.         end,
  226.  
  227.         onTitleBarClick = function ( b, s, x, y )
  228.             if ( b == "left" ) then
  229.                 if ( s == "down" ) then
  230.                     if ( x > Phone.x and x <= Phone.width + x and y > Phone.y and y <= Phone.y + 25 ) then
  231.                         TitleBarClicked = true;
  232.                     end
  233.                 else
  234.                     TitleBarClicked = false;
  235.                 end
  236.             end
  237.         end,
  238.  
  239.         add = function (comp)
  240.             table.insert(Phone.comps, comp)
  241.         end,
  242.  
  243.         rem = function (comp)
  244.             for k, v in pairs(Phone.comps) do
  245.                 if ( v.getName() == comp.getName() ) then
  246.                     table.remove(Phone.comps, k)
  247.                 end
  248.             end
  249.         end,
  250.  
  251.         xClicked = function ( b, the )
  252.             Visable = false;
  253.             for k,v in pairs(Phone.comps) do
  254.                 v.setVisable(false)
  255.             end
  256.             showCursor(false)
  257.             bindKey ( "F5", "down",
  258.                 function ()
  259.                     Visable = true;
  260.                     for k,v in pairs(Phone.comps) do
  261.                         v.setVisable(true)
  262.                     end
  263.                     showCursor(true)
  264.                 end                
  265.             )
  266.         end,
  267.  
  268.     }
  269.  
  270.     Phone.x = x; Phone.y = y; Phone.width = width; Phone.height = height;
  271.     b1 = createTextButtons(375, 0, 25, 25, "X")
  272.     Phone.add(b1)
  273.     addEvent( "ButtonClicked", false )
  274.     addEventHandler( "onClientClick", getRootElement(), Phone.onTitleBarClick )
  275.     addEventHandler( "ButtonClicked", getRootElement(), Phone.xClicked )
  276.     return Phone;
  277. end
  278.  
  279.  
  280. function createButton( x, y, w, h, text, Color, textColor )
  281.     local xOfset = 0;
  282.     local yOfset = 0;
  283.     local isVisableX = true;
  284.  
  285.     local mouseInside = false;
  286.  
  287.     local swap = Color;
  288.     local swapCheck = 0;
  289.  
  290.     local test = 0;
  291.  
  292.  
  293.     local MButton = {
  294.         x = 0, y = 0,
  295.         w = 80, h = 20,
  296.         text = "Button",
  297.         isVisable = isVisableX,
  298.         textColor = tocolor( 236, 240, 241, 255 ),
  299.         Color = tocolor( 231, 76, 60, 150 ),
  300.         type = "Button",
  301.  
  302.  
  303.         render = function ()
  304.             if ( isVisableX == true ) then
  305.                 dxDrawRectangle( x + xOfset, y + yOfset, w, h, Color )
  306.                 dxDrawText( text, ( (x + xOfset) + (w/2) ) - (string.len(text)*3), ((y + yOfset) - 7) + (h/2)  )
  307.             end
  308.         end,
  309.  
  310.         isMouseInside = function ()
  311.             mouseX, mouseY = getCursorPosition();
  312.             if ( not isCursorShowing ( ) ) then
  313.                 return false
  314.             end
  315.             local Sx, Sy = guiGetScreenSize( )
  316.             x2 = Sx * mouseX;
  317.             y2 = Sy * mouseY;
  318.             --outputChatBox(y + yOfset .. " : " .. h + yOfset + 40 .. ", " .. math.floor(y2))
  319.             --outputChatBox(x + xOfset .. " : " .. w + xOfset + x  .. ", " .. math.floor(x2))
  320.             if ( x2 >= x + xOfset and x2 <= w + xOfset + x and y2 >= y + yOfset and y2 <= h + yOfset + y) then
  321.                 return true;
  322.             end
  323.  
  324.             return false;
  325.         end,
  326.  
  327.  
  328.  
  329.         highlight = function ( value )
  330.             if ( swapCheck == 0 ) then
  331.                 swap = Color;
  332.                 swapCheck = 1;
  333.                 Color = Color + value
  334.             end
  335.         end,
  336.  
  337.         dehighlight = function ()
  338.             Color = swap;
  339.             swapCheck = 0;
  340.         end,
  341.  
  342.         setVisable = function ( visable )
  343.             isVisableX = visable;
  344.         end,
  345.  
  346.         getVisable = function ( )
  347.             return isVisableX;
  348.         end,
  349.  
  350.         setTextColor = function ( color )
  351.             textColor = color;
  352.         end,
  353.  
  354.         setTextColorRGBA = function ( r, g, b, a )
  355.             textColor = tocolor( r, g, b, a )
  356.         end,
  357.  
  358.         getText = function ( )
  359.             return text;
  360.         end,
  361.  
  362.         setText = function ( text2 )
  363.             text = text2;
  364.         end,
  365.  
  366.         setColor = function ( Color2 )
  367.             Color = Color2;
  368.         end,
  369.  
  370.         setColorRGBA = function ( r, g, b, a )
  371.             Color = tocolor( r, g, b, a )
  372.         end,
  373.  
  374.         getColorRGBA = function (  )
  375.            
  376.         end,
  377.  
  378.         setOfset = function ( ofx, ofy )
  379.             xOfset = ofx;
  380.             yOfset = ofy;
  381.         end,
  382.  
  383.         setX = function (x2) x = x2 end,
  384.         getX = function () return x; end,
  385.  
  386.         setY = function (y2) y = y2 end,
  387.         getY = function () return y; end,
  388.  
  389.         setW = function (w2) w = w2 end,
  390.         getW = function () return w; end,
  391.  
  392.         setH = function (h2) h = h2 end,
  393.         getH = function () return h; end,
  394.  
  395.  
  396.         Click = function ( button, state )
  397.             if ( not mouseInside  ) then
  398.                 return;
  399.             end
  400.             if ( test == 0 ) then
  401.                 triggerEvent( "onMButtonClicked", getRootElement(), button, state, text, x, y, w, h )
  402.                 test = 1;
  403.                 Color = Color + 30;
  404.                 setTimer( function ()
  405.                     test = 0;
  406.                     Color = Color - 30;
  407.                 end, 150, 1 )
  408.             end
  409.         end,
  410.  
  411.     }
  412.  
  413.  
  414.     local update = function ()
  415.         mouseInside = MButton.isMouseInside();
  416.     end
  417.  
  418.  
  419.     local create = function ()
  420.         MButton.x = x; MButton.y = y;
  421.         MButton.w = w; MButton.h = h;
  422.         MButton.text = text; MButton.Color = Color;
  423.         MButton.textColor = textColor;
  424.         addEventHandler( "onClientClick", getRootElement(), MButton.Click )
  425.         addEventHandler( "onClientRender", getRootElement(), update )
  426.         return MButton;
  427.     end
  428.  
  429.     return create()
  430. end
  431.  
  432.  
  433. local phone;
  434. local panel;
  435.  
  436. local list;
  437.  
  438. local button1;
  439. local button2;
  440.  
  441. local up, down;
  442.  
  443. local buttons = { }
  444.  
  445. function render()
  446.     phone.render();
  447.  
  448.     panel.add(up)
  449.     panel.add(down)
  450.     panel.add(list)
  451.     --panel.add(button1)
  452.  
  453.     for k,v in pairs(buttons) do
  454.         list.addItem(v)
  455.     end
  456.  
  457.     --list.addItem(button1)
  458.     --list.addItem(button2)
  459.     phone.add(panel)
  460. end
  461.  
  462. function init( )
  463.     phone = createThePhone(0, 0, 400, 650 );
  464.  
  465.     list = CreateListView(0, 30, 350, 600)
  466.     panel = createLayOut(25, 30, 350, 600)
  467.     up = createButton(260, 6, 80, 20, "UP", tocolor( 0, 0, 0, 120 ), tocolor( 255, 255, 255, 255 ))
  468.     down = createButton(10, 6, 80, 20, "DOWN", tocolor( 0, 0, 0, 120 ), tocolor( 255, 255, 255, 255 ))
  469.     i = 1;
  470.     -- getElementsByType( "player" )
  471.     tempT = {"Mouamle_",}
  472.     for i = 0, 30 do
  473.         table.insert(tempT, "User"..i )
  474.     end
  475.     for k,v in pairs(tempT) do
  476.         buttons[#buttons+1] = createButton(10, 10 + i, 330, 20, v,  tocolor( 0, 0, 0, 120 ), tocolor( 255, 255, 255, 200 )  )
  477.         i = i + 30
  478.     end
  479.     --button1 = createButton(10, 10, 80, 20, "Fuck",  tocolor( 0, 0, 0, 120 ), tocolor( 255, 255, 255, 200 )  )
  480.     --button2 = createButton(10, 40, 80, 20, "Fuck 2",  tocolor( 0, 0, 0, 120 ), tocolor( 255, 255, 255, 200 )  )
  481.     addEventHandler( "onClientRender", getRootElement(  ), render )
  482.     showChat( true )
  483.     showCursor( true )
  484. end
  485. addEventHandler ( "onClientResourceStart", resourceRoot, init )
  486.  
  487. function handleButtons( button, state, text )
  488.     if ( button == "left" and state == "down" ) then
  489.         if ( text == up.getText() ) then
  490.             list.move("up")
  491.         elseif ( text == down.getText()) then
  492.             list.move("down")
  493.         end
  494.     end
  495. end
  496. addEvent( "onMButtonClicked" )
  497. addEventHandler( "onMButtonClicked", getRootElement(  ), handleButtons )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement