Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.81 KB | None | 0 0
  1. sW,sH = guiGetScreenSize()
  2. mX, mY = 0, 0
  3. myFont = dxCreateFont( "opensans-light.ttf", 15 )
  4. logoW, logoH = sW/5, sW/10
  5. bgY = 0
  6. function createLoginPanel()
  7. addEventHandler("onClientRender",getRootElement(),renderLoginPanel)
  8. addEventHandler("onClientRender",getRootElement(),renderButtons)
  9. showCursor(true,true)
  10. toggleAllControls(false)
  11. showChat(false)
  12. xml = xmlLoadFile("userdata.xml")
  13. loadXML()
  14. end
  15. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createLoginPanel)
  16.  
  17. function loadXML()
  18. if not xml then
  19. xml = xmlCreateFile("userdata.xml","userdata")
  20. usernameChild = xmlCreateChild(xml,"username")
  21. passwordChild = xmlCreateChild(xml,"password")
  22. checkboxChild = xmlCreateChild(xml,"state")
  23. xmlSaveFile(xml)
  24. else
  25. usernameChild = xmlFindChild(xml,"username",0)
  26. passwordChild = xmlFindChild(xml,"password",0)
  27. checkboxChild = xmlFindChild(xml,"state",0)
  28. end
  29. if xmlNodeGetValue(checkboxChild) == "true" then
  30. checkboxs[1].state = true
  31. end
  32. usernameLoad = xmlNodeGetValue(usernameChild)
  33. passwordLoad = xmlNodeGetValue(passwordChild)
  34. for w in string.gmatch(usernameLoad, ".") do
  35. for i,ebox in ipairs(editbox) do
  36. if ebox.name == "username" then
  37. table.insert(text[i], w)
  38. end
  39. end
  40. end
  41. for w in string.gmatch(passwordLoad, ".") do
  42. for i,ebox in ipairs(editbox) do
  43. if ebox.name == "password" then
  44. table.insert(text[i], w)
  45. end
  46. end
  47. end
  48. end
  49. function saveXML(username,password,checkboxState)
  50. if checkboxs[1].state == true then
  51. xmlNodeSetValue(usernameChild,username)
  52. xmlNodeSetValue(passwordChild,password)
  53. xmlNodeSetValue(checkboxChild,tostring(checkboxState))
  54. xmlSaveFile(xml)
  55. else
  56. xmlNodeSetValue(usernameChild,"")
  57. xmlNodeSetValue(passwordChild,"")
  58. xmlNodeSetValue(checkboxChild,"")
  59. xmlSaveFile(xml)
  60. end
  61. end
  62. addEvent("saveXML",true)
  63. addEventHandler("saveXML",getRootElement(),saveXML)
  64. boxes = {
  65. {x = sW/2-sW/10, y = sH/2-sH/7, w = sW/5, h = sH/20, borderColor = tocolor(224, 224, 224), boxD = "green", text = "Please log in", messageBox = "1"},
  66. {x = sW/2-sW/10, y = sH/2-sH/7.4+sH/18, w = sW/5, h = sW/5, borderColor = tocolor(224, 224, 224)},
  67. {x = sW/2-sW/10, y = sH/2-sH/7 + sH, w = sW/5, h = sH/20, borderColor = tocolor(224, 224, 224), boxD = "green", text = "Write username and password", messageBox = "2"},
  68. {x = sW/2-sW/10, y = sH/2-sH/7.4+sH/18 + sH, w = sW/5, h = sW/5, borderColor = tocolor(224, 224, 224)},
  69. }
  70. buttons = {
  71. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].h - sH/14, w = sW/13, h = boxes[2].w/6.5, color = tocolor(255,255,255), borderColor = tocolor(224, 224, 224), text = "Register", func = "pressRegisterBut"},
  72. {x = boxes[2].x + boxes[2].w - sW/47 - sW/13, y = boxes[2].y + boxes[2].h - sH/14, w = sW/13, h = boxes[2].w/6.5, color = tocolor(255,255,255), borderColor = tocolor(224, 224, 224), text = "Log In", func = "pressLogin"},
  73. {x = boxes[2].x + boxes[2].w - sW/47 - sW/13, y = boxes[2].y + boxes[2].h - sH/14 + sH, w = sW/13, h = boxes[2].w/6.5, color = tocolor(255,255,255), borderColor = tocolor(224, 224, 224), text = "Back", func = "pressBack"},
  74. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].h - sH/14 + sH, w = sW/13, h = boxes[2].w/6.5, color = tocolor(255,255,255), borderColor = tocolor(224, 224, 224), text = "Register", func = "pressRegister"}
  75. }
  76. editbox = {
  77. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].w/6.5, w = sW/13 + sW/13 + (boxes[2].w - sW/47 - sW/13 - sW/47 - sW/13), h = boxes[2].w/6.5, borderColor = tocolor(224, 224, 224), textUp = "Username", text = "", name = "username"},
  78. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].w/6.5 + boxes[2].w/6.5 + boxes[2].w/6.5, w = sW/13 + sW/13 + (boxes[2].w - sW/47 - sW/13 - sW/47 - sW/13), h = boxes[2].w/6.5, borderColor = tocolor(224, 224, 224), textUp = "Password", text = "", hide = true, name = "password"},
  79. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].w/6.5 + sH, w = sW/13 + sW/13 + (boxes[2].w - sW/47 - sW/13 - sW/47 - sW/13), h = boxes[2].w/6.5, borderColor = tocolor(224, 224, 224), textUp = "Username", text = "", name = "usernameReg"},
  80. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].w/6.5 + boxes[2].w/6.5 + boxes[2].w/6.5 + sH, w = sW/13 + sW/13 + (boxes[2].w - sW/47 - sW/13 - sW/47 - sW/13), h = boxes[2].w/6.5, borderColor = tocolor(224, 224, 224), textUp = "Password", text = "", hide = true, name = "passwordReg"},
  81. }
  82. checkboxs = {
  83. {x = boxes[2].x + sW/47, y = boxes[2].y + boxes[2].w/6.5 + boxes[2].w/6.5 + boxes[2].w/6 + boxes[2].w/6, wh = boxes[2].w/25, state = false, text = "Remember me"}
  84. }
  85. text = {}
  86. for i,ebox in ipairs(editbox) do
  87. table.insert(text,{})
  88. end
  89. bindKey("backspace", "down", function ()
  90. table.remove(text[eboxClickI], #text[eboxClickI])
  91. end)
  92. function getCharacter(character)
  93. for i,ebox in ipairs(editbox) do
  94. if eboxClickI == i then
  95. table.insert(text[i], character)
  96. end
  97. end
  98. end
  99. function renderLoginPanel()
  100. dxDrawRectangle(0 , bgY, sW, sH, tocolor(200, 0, 0))
  101. dxDrawImage ( sW/2 - logoW/2 + mX, boxes[1].y - logoH - sH/60 + mY, logoW, logoH, 'logo.png')
  102. dxDrawImage ( sW/2 - logoW/2 + mX, boxes[1].y - logoH - sH/60 + mY + sH, logoW, logoH, 'logo.png')
  103. for i,box in ipairs(boxes) do
  104. dxDrawRectangle(box.x + mX, box.y + mY, box.w, box.h)
  105. dxDrawRectangle(box.x + mX, box.y + mY, box.w, 1, box.borderColor)
  106. dxDrawRectangle(box.x + mX, box.y + mY, 1, box.h, box.borderColor)
  107. dxDrawRectangle(box.x + mX, box.y + box.h + mY, box.w, 1, box.borderColor)
  108. dxDrawRectangle(box.x + box.w + mX, box.y + mY, 1, box.h, box.borderColor)
  109. if box.boxD then
  110. if box.boxD == "green" then
  111. dxDrawRectangle(box.x + mX, box.y + mY, sW/160, box.h, tocolor(125,198,35))
  112. elseif box.boxD == "red" then
  113. dxDrawRectangle(box.x + mX, box.y + mY, sW/160, box.h, tocolor(255,0,0))
  114. end
  115. end
  116. if box.text then
  117. dxDrawText ( box.text, box.x + sW/80 + mX, box.y + mY, box.x + box.w + mX, box.y + box.h + mY, tocolor(31,31,31), sW/1600, myFont, "left", "center")
  118. end
  119. end
  120. for i,ebox in ipairs(editbox) do
  121. dxDrawRectangle(ebox.x + mX, ebox.y + mY, ebox.w, ebox.h)
  122. dxDrawRectangle(ebox.x + mX, ebox.y + mY, ebox.w, 1, ebox.borderColor)
  123. dxDrawRectangle(ebox.x + mX, ebox.y + mY, 1, ebox.h, ebox.borderColor)
  124. dxDrawRectangle(ebox.x + mX, ebox.y + ebox.h + mY, ebox.w, 1, ebox.borderColor)
  125. dxDrawRectangle(ebox.x + ebox.w + mX, ebox.y + mY, 1, ebox.h, ebox.borderColor)
  126. if ebox.textUp then
  127. dxDrawText ( ebox.textUp, ebox.x + mX, ebox.y - ebox.h + mY, ebox.x + ebox.w + mX, ebox.y + mY, tocolor(31,31,31), sW/1600, myFont, "left", "bottom")
  128. end
  129. if isMouseWithinRangeOf(ebox.x + mX, ebox.y + mY, ebox.w, ebox.h) then
  130. ebox.borderColor = tocolor(204,204,204)
  131. else
  132. ebox.borderColor = tocolor(224,224,224)
  133. end
  134. if ebox.text then
  135. ebox.text = table.concat(text[i],"")
  136. if ebox.hide == true then
  137. dxDrawText (string.rep("*",#text[i],""), ebox.x + 10 + mX, ebox.y + mY, ebox.x + ebox.w + mX, ebox.y + ebox.h + mY, tocolor(31,31,31), sW/1600, myFont, "left", "center", true)
  138. else
  139. dxDrawText ( table.concat(text[i],""), ebox.x + 10 + mX, ebox.y + mY, ebox.x + ebox.w + mX, ebox.y + ebox.h + mY, tocolor(31,31,31), sW/1600, myFont, "left", "center",true)
  140. end
  141. end
  142. if eboxClickI == i then
  143. dxDrawRectangle(ebox.x + mX, ebox.y + mY, ebox.w, 1, tocolor(124,198,35))
  144. dxDrawRectangle(ebox.x + mX, ebox.y + mY, 1, ebox.h, tocolor(124,198,35))
  145. dxDrawRectangle(ebox.x + mX, ebox.y + ebox.h + mY, ebox.w, 1, tocolor(124,198,35))
  146. dxDrawRectangle(ebox.x + ebox.w + mX, ebox.y + mY, 1, ebox.h, tocolor(124,198,35))
  147. end
  148. end
  149. for i,cbox in ipairs(checkboxs) do
  150. if cbox.state == true then
  151. dxDrawRectangle(cbox.x + mX, cbox.y + mY, cbox.wh, cbox.wh, tocolor(124,198,35))
  152. else
  153. dxDrawRectangle(cbox.x + mX, cbox.y + mY, cbox.wh, cbox.wh, tocolor(200,200,200))
  154. end
  155. if cbox.text then
  156. dxDrawText (cbox.text, cbox.x + cbox.wh + 5 + mX, cbox.y + mY, cbox.x + cbox.wh*10 + mX, cbox.y + cbox.wh + mY, tocolor(31,31,31), sW/2000, myFont, "left", "center",true)
  157. end
  158. end
  159. end
  160. addEventHandler("onClientCharacter", getRootElement(), getCharacter)
  161. function pressLogin()
  162. for i, ebox in ipairs(editbox) do
  163. if ebox.name == "username" then
  164. gUser = ebox.text
  165. elseif ebox.name == "password" then
  166. gPass = ebox.text
  167. end
  168. end
  169. triggerServerEvent ( "onLogin", getLocalPlayer(), gUser, gPass, checkboxs[1].state)
  170. end
  171. function pressRegister()
  172. for i, ebox in ipairs(editbox) do
  173. if ebox.name == "usernameReg" then
  174. rUser = ebox.text
  175. elseif ebox.name == "passwordReg" then
  176. rPass = ebox.text
  177. end
  178. end
  179. triggerServerEvent ( "onRegister", getLocalPlayer(), rUser, rPass)
  180. end
  181. function pressRegisterBut()
  182. p_Move = {}
  183. p_Move.startTime = getTickCount()
  184. p_Move.endTime = p_Move.startTime + 1200
  185. p_Move.easingFunction = "InOutQuad"
  186. addEventHandler("onClientRender", getRootElement(), movePanelOut)
  187. end
  188. function pressBack()
  189. p_Move = {}
  190. p_Move.startTime = getTickCount()
  191. p_Move.endTime = p_Move.startTime + 1200
  192. p_Move.easingFunction = "InOutQuad"
  193. addEventHandler("onClientRender", getRootElement(), movePanelIn)
  194. end
  195. addEvent("pressBack",true)
  196. addEventHandler("pressBack",getRootElement(),pressBack)
  197. function movePanelOut()
  198. local now = getTickCount()
  199. local elapsedTime = now - p_Move.startTime
  200. local duration = p_Move.endTime - p_Move.startTime
  201. local progress = elapsedTime / duration
  202.  
  203. local fAnimationTime = getEasingValue(progress, p_Move.easingFunction)
  204.  
  205. local move = fAnimationTime*sH
  206. mY = ( -move )
  207. if now > p_Move.endTime then
  208. removeEventHandler("onClientRender", getRootElement(), movePanelOut)
  209. end
  210. end
  211. function movePanelIn()
  212. local now = getTickCount()
  213. local elapsedTime = now - p_Move.startTime
  214. local duration = p_Move.endTime - p_Move.startTime
  215. local progress = elapsedTime / duration
  216.  
  217. local fAnimationTime = getEasingValue(progress, p_Move.easingFunction)
  218.  
  219. local move = fAnimationTime*sH
  220. mY = (-sH + move)
  221. if now > p_Move.endTime then
  222. removeEventHandler("onClientRender", getRootElement(), movePanelIn)
  223. end
  224. end
  225. function renderButtons()
  226. for i,b in ipairs(buttons) do
  227. dxDrawRectangle(b.x + mX,b.y + mY,b.w,b.h,b.color)
  228. dxDrawRectangle(b.x + mX, b.y + mY, b.w, 1, b.borderColor)
  229. dxDrawRectangle(b.x + mX, b.y + mY, 1, b.h, b.borderColor)
  230. dxDrawRectangle(b.x + mX, b.y + b.h + mY, b.w, 1, b.borderColor)
  231. dxDrawRectangle(b.x + b.w + mX, b.y + mY, 1, b.h, b.borderColor)
  232. if b.text then
  233. dxDrawText ( b.text, b.x + mX, b.y + mY, b.x + b.w + mX, b.y + b.h + mY, tocolor(31,31,31), sW/1600, myFont, "center", "center")
  234. end
  235. if isMouseWithinRangeOf(b.x + mX, b.y + mY, b.w, b.h) then
  236. dxDrawRectangle(b.x + mX,b.y + mY,b.w,b.h,tocolor(124,198,35))
  237. if b.text then
  238. dxDrawText ( b.text, b.x + mX, b.y + mY, b.x + b.w + mX, b.y + b.h + mY, tocolor(255,255,255), sW/1600, myFont, "center", "center")
  239. end
  240. end
  241. end
  242. end
  243.  
  244. function changeMessage(mesBox, newMessage, boxColor)
  245. for i,box in ipairs(boxes) do
  246. if box.messageBox == mesBox then
  247. box.text = newMessage
  248. box.boxD = boxColor
  249. end
  250. end
  251. end
  252. addEvent("changeMessage",true)
  253. addEventHandler("changeMessage",getRootElement(),changeMessage)
  254. function onClick(mButton,state,ax,ay)
  255. if not (state == "down" and mButton == "left") then
  256. return false
  257. end
  258. for i,b in pairs(buttons) do
  259. if isMouseWithinRangeOf(b.x + mX, b.y + mY, b.w, b.h) then
  260. outputDebugString("Pressed "..b.text)
  261. if b.func then
  262. loadstring("return "..b.func.."()")()
  263. end
  264. end
  265. end
  266. for i,ebox in pairs(editbox) do
  267. if isMouseWithinRangeOf(ebox.x + mX, ebox.y + mY, ebox.w, ebox.h) then
  268. outputDebugString("Pressed "..ebox.textUp)
  269. eboxClickI = i
  270. return true
  271. end
  272. end
  273. for i,cbox in pairs(checkboxs) do
  274. if isMouseWithinRangeOf(cbox.x + mX, cbox.y + mY, cbox.wh, cbox.wh) then
  275. outputDebugString("Pressed "..i.." checkbox")
  276. if cbox.state == false then
  277. cbox.state = true
  278. else
  279. cbox.state = false
  280. end
  281. end
  282. end
  283. eboxClickI = nil
  284. return false
  285. end
  286.  
  287. addEventHandler("onClientClick",getRootElement(),onClick)
  288.  
  289. function isMouseWithinRangeOf(posX, posY, sizeX, sizeY)
  290. if isCursorShowing() == false then
  291. return false
  292. end
  293. local cx,cy = getCursorPosition()
  294. cx,cy = cx*sW,cy*sH
  295. if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then
  296. return true,cx,cy
  297. else
  298. return false
  299. end
  300. end
  301.  
  302.  
  303. function hideLoginPanel()
  304. p_Move = {}
  305. p_Move.startTime = getTickCount()
  306. p_Move.endTime = p_Move.startTime + 1200
  307. p_Move.easingFunction = "InOutQuad"
  308. addEventHandler("onClientRender", getRootElement(), hidePanelOut)
  309. end
  310. function hidePanelOut()
  311. local now = getTickCount()
  312. local elapsedTime = now - p_Move.startTime
  313. local duration = p_Move.endTime - p_Move.startTime
  314. local progress = elapsedTime / duration
  315.  
  316. local fAnimationTime = getEasingValue(progress, p_Move.easingFunction)
  317.  
  318. local move = fAnimationTime*sH
  319. mY = move
  320. bgY = move
  321.  
  322. if now > p_Move.endTime then
  323. removeEventHandler("onClientRender", getRootElement(), hidePanelOut)
  324. removeEventHandler("onClientRender",getRootElement(),renderLoginPanel)
  325. removeEventHandler("onClientRender",getRootElement(),renderButtons)
  326. showCursor(false,false)
  327. toggleAllControls(true)
  328. showChat(true)
  329. end
  330. end
  331. addEvent("hideLoginPanel",true)
  332. addEventHandler("hideLoginPanel",getRootElement(),hideLoginPanel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement