Advertisement
Guest User

Untitled

a guest
May 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.20 KB | None | 0 0
  1. --[[
  2.     @author FusioN. | santex.
  3.     @name Internet
  4.     @server America RPG
  5.     @type SERVER
  6. ]]
  7.  
  8. local sW, sH = guiGetScreenSize()
  9.  
  10. local availableWebPages = {
  11.     ["americaweb://main"] = {pageNumber=1},
  12.     ["americaweb://guide"] = {pageNumber=2},
  13.     ["custom"] = {pageNumber=999},
  14. }
  15.  
  16. local webPage = nil
  17.  
  18. local mainPageFont = dxCreateFont(":g_assets/fonts/lato/regular.ttf", sW / 49.2307692308)
  19.  
  20. local taskBarFont = dxCreateFont(":g_assets/fonts/lato/regular.ttf", sW / 116.363636364)
  21.  
  22. local startTick = nil
  23.  
  24. local webHeight = 2.5
  25.  
  26. local searchBarText = ""
  27. local searchBarSelected = false
  28. local backspaceTicks = nil
  29.  
  30. local guideButtonStartTick = nil
  31.  
  32. local browser
  33.  
  34. function isMouseInPosition ( x, y, width, height )
  35.     if ( not isCursorShowing( ) ) then
  36.         return false
  37.     end
  38.     local sx, sy = guiGetScreenSize ( )
  39.     local cx, cy = getCursorPosition ( )
  40.     local cx, cy = ( cx * sx ), ( cy * sy )
  41.     if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
  42.         return true
  43.     else
  44.         return false
  45.     end
  46. end
  47.  
  48. function renderWeb()
  49.     if startTick then
  50.         local animationProgress = (getTickCount() - startTick) / 1500
  51.         webHeight = interpolateBetween(2.5, 0, 0, 0, 0, 0, animationProgress, "InBounce")
  52.                
  53.         if animationProgress >= 1 then
  54.             startTick = nil
  55.         end
  56.     end
  57.    
  58.     dxDrawRectangle(sW * 0, sH * (0+ webHeight), sW * 1, sH * 1, tocolor(255, 255, 255, 255), false)
  59.     dxDrawLine(sW * 0, sH * (0.0694+ webHeight), sW * 1, sH * (0.0694+ webHeight), tocolor(54, 54, 54, 255), 1, false)
  60.     dxDrawRectangle(sW * 0, sH * (0+ webHeight), sW * 1, sH * 0.0694, tocolor(208, 208, 208, 255), false)
  61.     dxDrawImage(sW * -0.0070, sH * (-0.0125+ webHeight), sW * 0.0500, sH * 0.0889, ":arpg_images_global/logoA.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
  62.     dxDrawText("WEB", sW * 0.0313, sH * (0.0139+ webHeight), sW * 0.1391, sH * (0.0583+ webHeight), tocolor(254, 254, 254, 255), 1.00, taskBarFont, "left", "bottom", false, false, false, false, false)
  63.     dxDrawLine((sW * 0.0609) - 1, (sH * (0.0139+ webHeight)) - 1, (sW * 0.0609) - 1, sH * (0.0542+ webHeight), tocolor(0, 0, 0, 255), 1, false)
  64.     dxDrawLine(sW * 0.9516, (sH * (0.0139+ webHeight)) - 1, (sW * 0.0609) - 1, (sH * (0.0139+ webHeight)) - 1, tocolor(0, 0, 0, 255), 1, false)
  65.     dxDrawLine((sW * 0.0609) - 1, sH * (0.0542+ webHeight), sW * 0.9516, sH * (0.0542+ webHeight), tocolor(0, 0, 0, 255), 1, false)
  66.     dxDrawLine(sW * 0.9516, sH * (0.0542+ webHeight), sW * 0.9516, (sH * (0.0139+ webHeight)) - 1, tocolor(0, 0, 0, 255), 1, false)
  67.     dxDrawRectangle(sW * 0.0609, sH * (0.0139+ webHeight), sW * 0.8906, sH * 0.0403, tocolor(241, 241, 241, 255), false)
  68.     dxDrawText(searchBarText, sW * 0.0641, sH * (0.0139+ webHeight), sW * 0.9477, sH * (0.0542+ webHeight), tocolor(0, 0, 0, 255), 1.00, taskBarFont, "left", "bottom", false, false, false, false, false)
  69.     dxDrawImage(sW * 0.9672, sH * (0.0111+ webHeight), sW * 0.0250, sH * 0.0444, ":arpg_images_web/closeWeb.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
  70.  
  71.     if availableWebPages[webPage] then
  72.         if webPage == "americaweb://main" then
  73.             dxDrawImage(sW * 0.4000, sH * (0.0722+ webHeight), sW * 0.2000, sH * 0.3556, ":arpg_images_global/logoA.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
  74.             dxDrawText("WEB", sW * 0.4453, sH * (0.3347+ webHeight), sW * 0.5531, sH * (0.3792+ webHeight), tocolor(127, 127, 127, 255), 1.00, mainPageFont, "center", "center", false, false, false, false, false)
  75.         elseif webPage == "americaweb://guide" then
  76.             dxDrawImage(sW * 0.4000, sH * (0.0322+ webHeight), sW * 0.2000, sH * 0.3556, ":arpg_images_global/logoA.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
  77.             dxDrawText("PRZEWODNIK", sW * 0.4453, sH * (0.2947+ webHeight), sW * 0.5531, sH * (0.3392+ webHeight), tocolor(127, 127, 127, 255), 1.00, mainPageFont, "center", "center", false, false, false, false, false)
  78.        
  79.             local buttonColor = tocolor(0, 131, 255, 255)
  80.            
  81.             if isMouseInPosition(sW * 0.4359, sH *(0.3347 + webHeight), sW * 0.1250, sH * 0.0444) and buttonColor == tocolor(0, 131, 255, 255) and guideButtonStartTick then       
  82.                     local animationProgress = (getTickCount() - guideButtonStartTick) / 1000
  83.                     local buttonColor_r, buttonColor_g, buttonColor_b = interpolateBetween(0, 131, 255, 17, 153, 87, animationProgress, "Linear")
  84.                    
  85.                     buttonColor = tocolor(buttonColor_r, buttonColor_g, buttonColor_b, 255)
  86.                    
  87.                     outputChatBox(animationProgress)
  88.                    
  89.                     if animationProgress >= 1 then
  90.                         animationProgress = nil
  91.                         guideButtonStartTick = nil
  92.                         buttonColor = tocolor(17, 153, 87, 255)
  93.                     end
  94.             end
  95.        
  96.             dxDrawImage(sW * 0.4359, sH *(0.3347 + webHeight), sW * 0.1250, sH * 0.0444, ":arpg_images_global/buttonTemplate.png", 0, 0, 0, buttonColor, false)
  97.         elseif webPage == "custom" then
  98.             dxDrawImage(sW * 0.4000, sH * (0.0722+ webHeight), sW * 0.2000, sH * 0.3556, ":arpg_images_global/logoA.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
  99.             dxDrawText("Loading... ", sW * 0.4453, sH * (0.3347+ webHeight), sW * 0.5531, sH * (0.3792+ webHeight), tocolor(127, 127, 127, 255), 1.00, mainPageFont, "center", "center", false, false, false, false, false)
  100.             dxDrawImage(sW * 0, sH * 0.0694, sW * 1, sH * 0.9306, browser)
  101.         end
  102.     end
  103.    
  104.     if searchBarSelected and backspaceTicks and getTickCount()-backspaceTicks > 75 and getKeyState("backspace") then
  105.         local text = searchBarText
  106.         local result = string.sub(text, 0, string.len(text)-1)
  107.         backspaceTicks = getTickCount()
  108.         searchBarText = result
  109.     end
  110. end
  111.  
  112. function onClick(button, state)
  113.     if button == "left" and state == "down" then
  114.         if isMouseInPosition(sW * -0.0070, sH * (-0.0125+ webHeight), sW * 0.0500, sH * 0.0889) then
  115.             webPage = "americaweb://main"
  116.             searchBarText = webPage
  117.         end
  118.        
  119.         if isMouseInPosition(sW * 0.0609, sH * (0.0139+ webHeight), sW * 0.8906, sH * 0.0403) then
  120.             searchBarSelected = true
  121.         elseif not isMouseInPosition(sW * 0.0609, sH * (0.0139+ webHeight), sW * 0.8906, sH * 0.0403) then
  122.             searchBarSelected = false
  123.         end
  124.     end
  125. end
  126. addEventHandler('onClientClick', root, onClick)
  127.  
  128. function onCharacter(key)
  129.     if searchBarSelected and key then
  130.         local text = tostring(searchBarText)
  131.         local result = text .. key
  132.         searchBarText = result
  133.     end
  134. end
  135. addEventHandler("onClientCharacter", root, onCharacter)
  136.  
  137. function onKey(button, press)
  138.     if searchBarSelected and button == "backspace" and press then
  139.         local text = tostring(searchBarText)
  140.         local result = string.sub(text, 0, string.len(text)-1)
  141.         backspaceTicks = getTickCount()
  142.         searchBarText = result
  143.     elseif searchBarSelected and button == "enter" and press then
  144.         if tostring(searchBarText) ~= "" then
  145.             if searchBarText == "americaweb://main" then
  146.                 webPage = "americaweb://main"
  147.                 searchBarText = webPage
  148.                
  149.                 if browser then browser = nil end
  150.             elseif searchBarText == "americaweb://guide" then
  151.                 webPage = "americaweb://guide"
  152.                 searchBarText = webPage
  153.                
  154.                 guideButtonStartTick = getTickCount()
  155.                
  156.                 if browser then browser = nil end
  157.             else
  158.                 webPage = "custom"
  159.            
  160.                
  161.                 if browser then browser = nil end
  162.                
  163.                 browser = createBrowser(sW * 1, sH * 0.9306, false)
  164.                
  165.                 addEventHandler( "onClientBrowserCreated", browser, function( )
  166.                         loadBrowserURL(source, tostring(searchBarText))
  167.                     end)
  168.             end
  169.         end
  170.     end
  171. end
  172. addEventHandler("onClientKey", root, onKey)
  173.  
  174. function createWeb(page)
  175.     assert(page, "Brakujący argument 'page' w funkcji createWeb.")
  176.    
  177.     if type(page) ~= 'string' then outputDebugString("Zły argument @ 'createWeb' [Powinnien być string w argumencie 1, jest "..type(page).."]", 2) return false end
  178.    
  179.     if not availableWebPages[page] then outputDebugString("nie znaleziono takiej strony.", 1) return false end
  180.    
  181.     webPage = page
  182.     searchBarText = webPage
  183.     startTick = getTickCount()
  184.    
  185.     showCursor(true)
  186.     showChat(false)
  187.    
  188.     addEventHandler('onClientRender', root, renderWeb)
  189. end
  190. addEvent('createWeb', true)
  191. addEventHandler('createWeb', root, createWeb)
  192.  
  193. function changeBrowser(...)
  194.     webPage = "custom"
  195.     searchBarText = link
  196.     browser = createBrowser(sW * 0.9555, sH * 0.9306, false)
  197.     loadBrowserURL(browser, tostring(link))
  198. end
  199. addCommandHandler('browser', changeBrowser)
  200.  
  201. function destroyWeb()
  202.  
  203. end
  204. addEvent('destroyWeb', true)
  205.  
  206. createWeb("americaweb://main")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement