Advertisement
Guest User

Untitled

a guest
Apr 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. sx,sy = guiGetScreenSize()
  2. x,y = (sx/1366), (sy/768)
  3.  
  4. messages = {}
  5. editBox = {}
  6. editBox.__index = editBox
  7. editBox.instances = {}
  8.  
  9. function onClientResourceStart()
  10. tick = getTickCount()
  11. font = dxCreateFont("gfx/sans-pro-regular.otf", 25)
  12. sound = playSound("sfx/music.mp3",true)
  13. g = {}
  14. g.user = editBox.new()
  15. g.user:setPosition(x*552,y*364,x*263,y*41)
  16. g.user.color = {79,86,94,160}
  17. g.user.font = font
  18. g.user.text = loadLoginFromXML()
  19. g.user.visible = true
  20. g.user.onInput = function()
  21. g.user.color = {87, 95, 104, 160}
  22. end
  23. g.user.onOutput = function()
  24. g.user.color = {79,86,94,160}
  25. end
  26.  
  27. g.pass = editBox.new()
  28. g.pass:setPosition(x*552,y*426,x*263,y*41)
  29. g.pass.color = {79,86,94,160}
  30. g.pass.font = font
  31. g.pass.masked = true
  32. g.pass.visible = true
  33. g.pass.onInput = function()
  34. g.pass.color = {87, 95, 104, 160}
  35. end
  36. g.pass.onOutput = function()
  37. g.pass.color = {79,86,94,160}
  38. end
  39.  
  40. g.rUser = editBox.new()
  41. g.rUser:setPosition(x*552,y*364,x*263,y*41)
  42. g.rUser.color = {79,86,94,160}
  43. g.rUser.font = font
  44. g.rUser.onInput = function()
  45. g.rUser.color = {87, 95, 104, 160}
  46. end
  47. g.rUser.onOutput = function()
  48. g.rUser.color = {79,86,94,160}
  49. end
  50.  
  51. g.rPass = editBox.new()
  52. g.rPass:setPosition(x*552,y*426,x*263,y*41)
  53. g.rPass.color = {79,86,94,160}
  54. g.rPass.font = font
  55. g.rPass.masked = true
  56. g.rPass.onInput = function()
  57. g.rPass.color = {87, 95, 104, 160}
  58. end
  59. g.rPass.onOutput = function()
  60. g.rPass.color = {79,86,94,160}
  61. end
  62.  
  63. guiSetInputMode ( "no_binds" )
  64. showChat(false)
  65. showCursor(true)
  66. addEventHandler("onClientRender", root, paint)
  67. end
  68. addEventHandler("onClientResourceStart",resourceRoot,onClientResourceStart)
  69.  
  70. function paint()
  71. local rh,ry = interpolateBetween(0, (y*559/2)+y*105, 0, y*559, y*105, 0, (getTickCount()-tick)/1, "Linear")
  72. dxDrawImage(0,0,sx,sy,"gfx/wallpaper.png")
  73. dxDrawRectangle(x*0,ry,x*0,rh,tocolor(0,0,0,200))
  74. dxDrawBorder(x*0,ry,x*0,rh,tocolor(0,0,0,240),1.4)
  75. if getTickCount()-tick > 2 then
  76. local bColor = tocolor(0,139,255,200)
  77. if isMouseInPosition(x*552,y*504,x*262,y*44) then
  78. bColor = tocolor(0,154,255,200)
  79. end
  80. dxDrawImage(x*595,y*137,x*170,y*170,"gfx/logo.png",0,0,tocolor(255,255,255,200))
  81. if not inRegisterTab then
  82. dxDrawText("Login",x*150,y*220,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  83. dxDrawText("Haslo",x*150,y*350,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  84.  
  85. dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
  86. dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
  87. dxDrawText("Zaloguj",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*1,font,"center","center")
  88.  
  89. dxDrawText([[Nie masz konta?
  90. - #008BFFZarejestruj#FFFFFF.]],x*588,y*582,x*588+x*192,y*592+y*43,tocolor(0,0,0),y*0.6,font,"center","center",false,false,false,true)
  91. end
  92.  
  93. for k,self in pairs(editBox.instances) do
  94. if self.visible then
  95. local px,py,pw,ph = self:getPosition()
  96. local text = self.masked and string.gsub(self.text,".","•") or self.text
  97. local alignX = dxGetTextWidth(text,self.scale,self.font) <= pw and "left" or "right"
  98. dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
  99. dxDrawText(text,px+x*5, py,px-x*5+pw, py+ph,tocolor(unpack(self.textColor)),self.scale,self.font,alignX,"center",true)
  100. if self.input and dxGetTextWidth(text,self.scale,self.font) <= pw then
  101. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  102. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  103. dxDrawLine(lx, py+y*10, lx, py+ph-y*10, tocolor(255,255,255,math.abs(math.sin(getTickCount()/300))*200), 2)
  104. end
  105. end
  106. end
  107.  
  108. if not inRegisterTab then
  109. dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  110. dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  111. else
  112.  
  113. dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  114. dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  115.  
  116. dxDrawText("Login",x*150,y*220,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  117. dxDrawText("Haslo",x*150,y*350,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  118. dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
  119. dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
  120. dxDrawText("Zarejestruj",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*1,font,"center","center")
  121. end
  122.  
  123. end
  124.  
  125. if getKeyState("backspace") then
  126. for k,self in pairs(editBox.instances) do
  127. if self.visible and self.input then
  128. if not keyState then
  129. keyState = getTickCount() + 400
  130. self.text = string.sub(self.text,1,string.len(self.text)-1)
  131. elseif keyState and keyState < getTickCount() then
  132. keyState = getTickCount()+100
  133. self.text = string.sub(self.text,1,string.len(self.text)-1)
  134. end
  135. return
  136. end
  137. end
  138. keyState = nil
  139. end
  140.  
  141. for i, v in pairs(messages) do
  142. if v.visible then
  143. dxDrawRectangle(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+50, 32,v.color)
  144. dxDrawBorder(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+20, 32,tocolor(255,255,255,200),1.6)
  145. dxDrawText(v.text,sx-dxGetTextWidth(v.text,1,"default-bold")-5, 9+35*i, dxGetTextWidth(v.text, 1, "default-bold"), 32, tocolor(255,255,255,255), 1, "default-bold", "left", "top", false, false ,false, true)
  146. end
  147. end
  148. end
  149.  
  150. function onClientClick(button,state,cX,cY)
  151. if not isCursorShowing() then
  152. return
  153. end
  154. if button == "left" and state == "up" then
  155. for k,self in pairs(editBox.instances) do
  156. if self.visible then
  157. if self.input then
  158. self.input = nil
  159. self.onOutput()
  160. end
  161. local x,y,w,h = self:getPosition()
  162. if isMouseInPosition(x,y,w,h) then
  163. self.input = true
  164. self.onInput()
  165. end
  166. end
  167. end
  168. if not inRegisterTab then
  169. if isMouseInPosition(x*552,y*504,x*262,y*44) then
  170. triggerServerEvent("onRequestLogin",localPlayer,g.user.text,g.pass.text)
  171. elseif isMouseInPosition(x*700,y*609,x*44,y*22) then
  172. g.user.visible = false
  173. g.pass.visible = false
  174.  
  175. inRegisterTab = true
  176. g.rUser.visible = true
  177. g.rPass.visible = true
  178. end
  179. else
  180. if isMouseInPosition(x*552,y*504,x*262,y*44) then
  181. triggerServerEvent("onRequestRegister",localPlayer,g.rUser.text,g.rPass.text)
  182. end
  183. end
  184. end
  185. end
  186. addEventHandler("onClientClick", root, onClientClick)
  187.  
  188. function onClientCharacter(character)
  189. if not isCursorShowing() then
  190. return
  191. end
  192. for k,self in pairs(editBox.instances) do
  193. if self.visible and self.input then
  194. if (string.len(self.text)) < self.maxLength then
  195. self.text = self.text..character
  196. end
  197. end
  198. end
  199. end
  200. addEventHandler("onClientCharacter", root, onClientCharacter)
  201.  
  202. function editBox.new()
  203. local self = setmetatable({}, editBox)
  204. self.text = ""
  205. self.maxLength = 20
  206. self.scale = y*0.8
  207. self.state = "normal"
  208. self.font = "sans"
  209. self.color = {255,255,255,220}
  210. self.textColor = {255,255,255,220}
  211. table.insert(editBox.instances, self)
  212. return self
  213. end
  214.  
  215. function editBox:getPosition()
  216. return self.x, self.y, self.w, self.h
  217. end
  218.  
  219. function editBox:setPosition(x,y,w,h)
  220. self.x, self.y, self.w, self.h = x,y,w,h
  221. return true
  222. end
  223.  
  224. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  225. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  226. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  227. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  228. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  229. end
  230.  
  231. function isMouseInPosition(x,y,width,height)
  232. local cx, cy = getCursorPosition()
  233. local cx, cy = (cx*sx), (cy*sy)
  234. if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
  235. return true
  236. else
  237. return false
  238. end
  239. end
  240.  
  241. function onLogin()
  242. showChat(true)
  243. showCursor(false)
  244. guiSetInputMode ( "allow_binds" )
  245. stopSound(sound)
  246. removeEventHandler("onClientRender", root, paint)
  247. removeEventHandler("onClientClick",root,onClientClick)
  248. removeEventHandler("onClientCharacter",root,onClientCharacter)
  249. end
  250. addEvent("onLogin", true)
  251. addEventHandler("onLogin", localPlayer, onLogin)
  252.  
  253. function onRegister()
  254. g.user.visible = true
  255. g.pass.visible = true
  256. g.user.text = ""
  257. g.pass.text = ""
  258.  
  259. inRegisterTab = false
  260. g.rUser.visible = false
  261. g.rPass.visible = false
  262. g.rUser.text = ""
  263. g.rPass.text = ""
  264. end
  265. addEvent("onRegister", true)
  266. addEventHandler("onRegister", localPlayer, onRegister)
  267.  
  268. function loadLoginFromXML()
  269. local XML = xmlLoadFile ("userdata.xml")
  270. if not XML then
  271. XML = xmlCreateFile("userdata.xml", "login")
  272. end
  273.  
  274. local usernameNode = xmlFindChild (XML, "username", 0)
  275. if usernameNode then
  276. return xmlNodeGetValue(usernameNode)
  277. else
  278. return ""
  279. end
  280. xmlUnloadFile ( XML )
  281. end
  282.  
  283. function saveLoginToXML(username)
  284. local XML = xmlLoadFile ("userdata.xml")
  285. if not XML then
  286. XML = xmlCreateFile("userdata.xml", "login")
  287. end
  288. if (username ~= "") then
  289. local usernameNode = xmlFindChild (XML, "username", 0)
  290. if not usernameNode then
  291. usernameNode = xmlCreateChild(XML, "username")
  292. end
  293. xmlNodeSetValue (usernameNode, tostring(username))
  294. end
  295. xmlSaveFile(XML)
  296. xmlUnloadFile (XML)
  297. end
  298. addEvent("saveLoginToXML", true)
  299. addEventHandler("saveLoginToXML", root, saveLoginToXML)
  300.  
  301.  
  302. function login_text(result, text)
  303. if result == "sucess" then
  304. addNotification(text,1)
  305. elseif result == "error" then
  306. addNotification(text,2)
  307. end
  308. end
  309. addEvent("login_text",true)
  310. addEventHandler("login_text",root,login_text)
  311.  
  312. function addNotification(text, type)
  313. text = string.gsub(text,"#%x%x%x%x%x%x","")
  314. local i = 0
  315. if text == "" or text == nil or not type then
  316. return
  317. else
  318. for i = 0, #messages do
  319. if messages[i] then
  320. i = i+1
  321. else
  322. messages[i] = {}
  323. messages[i].text = text
  324. messages[i].visible = true
  325. if type == 1 then
  326. messages[i].color = tocolor(0,255,0,160)
  327. elseif type == 2 then
  328. messages[i].color = tocolor(255,0,0,160)
  329. end
  330. setTimer(removeNotify,1000,1,i)
  331. end
  332. end
  333. end
  334. end
  335.  
  336. function removeNotify(i)
  337. messages[i].visible = false
  338. messages[i] = nil
  339. end
  340.  
  341. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  342. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  343. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  344. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  345. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  346. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement