sw,sh = guiGetScreenSize()
screenW, screenH = guiGetScreenSize()
mx, my = sw * 0.122, sw * 0.244
sy = 0
ssy = sh
myy = 0
font = dxCreateFont( "Img/font.ttf", 17 )
time = getTickCount()
x = -1472.30
y = -2126.25
z = 135.37
x2 = -1444.44
y2 = -2188.25
z2 = 127.37
function anim()
y = y+0.4
setCameraMatrix(x,y,z, x2, y2, z2)
if (getTickCount() - time >= 35000) then
removeEventHandler("onClientPreRender", getRootElement(), anim)
end
end
logopanel = false
local data={ misc=nil, }
function createLoginPanel()
addEventHandler("onClientRender",getRootElement(),renderLoginPanel)
addEventHandler("onClientRender",getRootElement(),renderLoginContent)
addEventHandler("onClientPreRender", getRootElement(), anim)
czas = getTickCount()
setPlayerHudComponentVisible ("all", false)
showCursor(true,true)
--guiSetInputMode("no_binds_when_editing")
showChat(false)
fadeCamera(true)
setElementAlpha(localPlayer,255)
logopanel = true
xml = xmlLoadFile("userdata.xml")
loadXML()
data.misc = playSound("Muzyka/muzaaa.mp3",true)
setSoundVolume(data.misc , 1.0)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createLoginPanel)
function loadXML()
if not xml then
xml = xmlCreateFile("userdata.xml","login")
usernameChild = xmlCreateChild(xml,"login")
passwordChild = xmlCreateChild(xml,"pass")
checkboxChild = xmlCreateChild(xml,"state")
xmlSaveFile(xml)
else
usernameChild = xmlFindChild(xml,"login",0)
passwordChild = xmlFindChild(xml,"pass",0)
checkboxChild = xmlFindChild(xml,"state",0)
end
if xmlNodeGetValue(checkboxChild) == "true" then
checkboxs[1].state = true
end
usernameLoad = xmlNodeGetValue(usernameChild)
passwordLoad = xmlNodeGetValue(passwordChild)
for w in string.gmatch(usernameLoad, ".") do
for i,ebox in ipairs(editbox) do
if ebox.name == "Loglogin" then
table.insert(text[i], w)
end
end
end
for w in string.gmatch(passwordLoad, ".") do
for i,ebox in ipairs(editbox) do
if ebox.name == "Logpass" then
table.insert(text[i], w)
end
end
end
end
function saveXML(login,pass,checkboxState)
if checkboxs[1].state == true then
xmlNodeSetValue(usernameChild,login)
xmlNodeSetValue(passwordChild,pass)
xmlNodeSetValue(checkboxChild,tostring(checkboxState))
xmlSaveFile(xml)
else
xmlNodeSetValue(usernameChild,"")
xmlNodeSetValue(passwordChild,"")
xmlNodeSetValue(checkboxChild,"")
xmlSaveFile(xml)
end
end
addEvent("saveXML",true)
addEventHandler("saveXML",getRootElement(),saveXML)
field = {
{ typ = "login", x = sw * 0.5, y = sh * 0.5 - ( sh * 0.400)/2, w = 0, h = sw * 0.244, colorS = tocolor(0, 0, 0), erbox = "bialy", text = "Panel Logowania!", messageBox = "1"}
}
buttons = {
{ typ = "login", x = sw * 0.5 + sw * 0.0290, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.0854 + sw * 0.0530 + sw * 0.0244 + sw * 0.0122 + sw * 0.0244 + sw * 0.244 * 0.02, w = sw * 0.370 * 0.3, h = sw * 0.0290, color = tocolor( 0, 0, 0, AlphaButton), text = "Zaloguj si?!", func = "pressLogin"},
{ typ = "login", x = sw * 0.5 - sw * 0.1400 + sw * 0.0005, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.1145 + sw * 0.0244 + sw * 0.0122 + sw * 0.0244 + sw * 0.0244 + sw * 0.244 * 0.02, w = sw * 0.370 * 0.3, h = sw * 0.0290, color = tocolor( 0, 0, 0, AlphaButton), text = "Rejestruj si?!", func = "pressRegisterBut"},
{ typ = "register", x = sw * 0.5 + sw * 0.0290, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.0854 + sw * 0.0530 + sw * 0.0244 + sw * 0.0122 + sw * 0.0244 + sw * 0.244 * 0.02, w = sw * 0.370 * 0.3, h = sw * 0.0290, color = tocolor( 0, 0, 0, 160), text = "Rejestruj si?!", func = "pressRegister"},
{ typ = "register", x = sw * 0.5 - sw * 0.1400 + sw * 0.0005, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.1145 + sw * 0.0244 + sw * 0.0122 + sw * 0.0244 + sw * 0.0244 + sw * 0.244 * 0.02, w = sw * 0.370 * 0.3, h = sw * 0.0290, color = tocolor( 0, 0, 0, 160), text = "Cofnij", func = "pressBack"},
}
editbox = {
{ typ = "login", x = sw * 0.5 - sw * 0.244 + sw * 0.545 * 0.3, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.244 * 0.34, w = sw * 0.270 * 0.6, h = sw * 0.0270, image = "Img/ebox.png", color = tocolor( 25, 25, 25, AlphaEditBox), text = "", textup = "Login:", name = "Loglogin"},
{ typ = "login", x = sw * 0.5 - sw * 0.244 + sw * 0.545 * 0.3, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.270 * 0.34 + sw * 0.0244 + sw * 0.0122, w = sw * 0.270 * 0.6, h = sw * 0.0270, image = "Img/ebox.png", color = tocolor( 25, 25, 25, AlphaEditBox), text = "", textup = "Has?o:", name = "Logpass", hide = true},
{ typ = "register", x = sw * 0.5 - sw * 0.244 + sw * 0.545 * 0.3, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.244 * 0.34, w = sw * 0.270 * 0.6, h = sw * 0.0270, image = "Img/ebox.png", color = tocolor( 25, 25, 25, AlphaEditBox), text = "", textup = "Login:", name = "loginRej"},
{ typ = "register", x = sw * 0.5 - sw * 0.244 + sw * 0.545 * 0.3, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.270 * 0.34 + sw * 0.0244 + sw * 0.0122, w = sw * 0.270 * 0.6, h = sw * 0.0270, image = "Img/ebox.png", color = tocolor( 25, 25, 25, AlphaEditBox), text = "", textup = "Has?o:", name = "passRej", hide = true}
}
checkboxs = {
{ x = sw * 0.6 + sw * 0.900 * 0.06, y = sh * 0.5 - ( sh * 0.405)/2 + sw * 0.320 * 0.34 + sw * 0.0244 + sw * 0.0122 + sw * 0.0244 + sw * 0.0122, wh = sw * 0.244 * 0.05, state = false, text = "Zapami?taj" }
}
text = {}
for i,ebox in ipairs(editbox) do
table.insert(text,{})
end
bindKey("backspace", "down", function ()
table.remove(text[eboxClickI], #text[eboxClickI])
end)
function getCharacter(character)
for i,ebox in ipairs(editbox) do
if eboxClickI == i then
table.insert(text[i], character)
end
end
end
function renderLoginPanel()
local Alpha, Alpha2 = interpolateBetween(0, 0, 0, 158, 255, 0, ((getTickCount() - czas) / 2500), "Linear")
dxDrawImage(screenW * 0.2262, screenH * 0.1823, screenW * 0.5483, screenH * 0.6549, "Img/okn.png", 0, 0, 0, tocolor(0, 0, 0, Alpha), false)
dxDrawImage(screenW * 0.2387, screenH * 0.090, screenW * 0.4219, screenH * 0.2418, "Img/Logo.png", 0, 0, 0, tocolor(255, 255, 255, Alpha2), false)
for index, login in ipairs ( field ) do
if login.typ then
if (login.typ == "login") then
if login.erbox then
if (login.erbox == "green") then
login.colorS = tocolor ( 0, 200, 0, 210 )
elseif ( login.erbox == "red") then
login.colorS = tocolor( 200, 0, 0, 210 )
elseif ( login.erbox == "bialy") then
login.colorS = tocolor( 255, 255, 255, 210 )
end
end
if login.text then
dxDrawText( login.text, login.x, login.y + login.h * 0.2 , login.x + login.w, login.y + login.h , login.colorS, sw/1700, font, "center")
end
end
end
end
end
function renderLoginContent()
AlphaEditBox, AlphaButton = interpolateBetween(0, 0, 0, 190, 160, 0, ((getTickCount() - czas) / 2500), "Linear")
if logopanel == true then
for i,ebox in ipairs(editbox) do
if ebox.typ then
if ( ebox.typ == "login" ) then
dxDrawImage( ebox.x, ebox.y + sy , ebox.w, ebox.h, ebox.image, 0, 0, 0, ebox.color )
if ebox.textup then
dxDrawText( ebox.textup, ebox.x - ebox.x * 0.12, ebox.y + ebox.h * 0.25 + sy , ebox.x + ebox.w, ebox.y + ebox.h , tocolor( 230,230,230), sw/1600, font)
end
if isMouseWithinRangeOf(ebox.x, ebox.y + sy , ebox.w, ebox.h) then
ebox.color = tocolor(25, 25, 25, 240)
else
ebox.color = tocolor(25, 25, 25, 170)
end
if ebox.text then
ebox.text = table.concat(text[i],"")
if ebox.hide == true then
dxDrawText (string.rep("•",#text[i],""), ebox.x + 10, ebox.y + sy , ebox.x + ebox.w, ebox.y + ebox.h + sy , tocolor( 230,230,230), sw/1700, font, "left", "center", true)
else
dxDrawText ( table.concat(text[i],""), ebox.x + 10, ebox.y + sy , ebox.x + ebox.w, ebox.y + ebox.h + sy , tocolor( 230,230,230), sw/1600, font, "left", "center",true)
end
end
if eboxClickI == i then
dxDrawImage( ebox.x, ebox.y , ebox.w, ebox.h, "Img/border.png", 0, 0, 0, tocolor(0, 0, 0))
end
elseif ( ebox.typ == "register" ) then
dxDrawImage( ebox.x, ebox.y + ssy , ebox.w, ebox.h, ebox.image, 0, 0, 0, ebox.color )
if ebox.textup then
dxDrawText( ebox.textup, ebox.x - ebox.x * 0.12, ebox.y + ebox.h * 0.25 + ssy , ebox.x + ebox.w, ebox.y + ebox.h , tocolor( 230,230,230), sw/1600, font)
end
if isMouseWithinRangeOf(ebox.x, ebox.y + ssy , ebox.w, ebox.h) then
ebox.color = tocolor( 25, 25, 25, 240)
else
ebox.color = tocolor( 25, 25, 25, 170)
end
if ebox.text then
ebox.text = table.concat(text[i],"")
if ebox.hide == true then
dxDrawText (string.rep("•",#text[i],""), ebox.x + 10, ebox.y + ssy , ebox.x + ebox.w, ebox.y + ebox.h + ssy , tocolor( 230,230,230), sw/1600, font, "left", "center", true)
else
dxDrawText ( table.concat(text[i],""), ebox.x + 10, ebox.y + ssy , ebox.x + ebox.w, ebox.y + ebox.h + ssy , tocolor( 230,230,230), sw/1600, font, "left", "center",true)
end
end
if eboxClickI == i then
dxDrawImage( ebox.x, ebox.y , ebox.w, ebox.h, "Img/border.png", 0, 0, 0, tocolor(0, 0, 0 ))
end
end
end
end
for index, cbox in ipairs ( checkboxs ) do
if ( cbox.state == true ) then
dxDrawImage(cbox.x , cbox.y + sy , cbox.wh, cbox.wh, "Img/accept.png")
else
dxDrawImage(cbox.x , cbox.y + sy , cbox.wh, cbox.wh, "Img/decline.png")
end
if cbox.text then
dxDrawText (cbox.text, cbox.x + cbox.wh + 5, cbox.y + sy , cbox.x + cbox.wh*10, cbox.y + cbox.wh + sy , tocolor( 230,230,230), sw/2000, font, "left", "center",true)
end
end
for index, but in ipairs ( buttons ) do
if but.typ then
if ( but.typ == "login" ) then
dxDrawImage( but.x, but.y + sy , but.w, but.h, "Img/ebox.png", 0, 0, 0, but.color)
if isMouseWithinRangeOf(but.x, but.y + sy , but.w, but.h) then
but.color = tocolor( 0, 0, 0, 240)
else
but.color = tocolor( 0, 0, 0, 170)
end
if but.text then
dxDrawText( but.text, but.x, but.y + sy , but.x + but.w, but.y + but.h + sy , tocolor( 230,230,230), sw/1600, font, "center", "center")
end
elseif ( but.typ == "register" ) then
dxDrawImage( but.x, but.y + ssy , but.w, but.h, "Img/ebox.png", 0, 0, 0, but.color)
if isMouseWithinRangeOf(but.x, but.y + ssy , but.w, but.h) then
but.color = tocolor( 0, 0, 0, 240)
else
but.color = tocolor( 0, 0, 0, 170)
end
if but.text then
dxDrawText( but.text, but.x, but.y + ssy , but.x + but.w, but.y + but.h + ssy , tocolor( 230,230,230), sw/1600, font, "center", "center")
end
end
end
end
end
end
addEventHandler("onClientCharacter", getRootElement(), getCharacter)
function pressLogin()
for i, ebox in ipairs(editbox) do
if ebox.name == "Loglogin" then
login = ebox.text
elseif ebox.name == "Logpass" then
pass = ebox.text
end
end
triggerServerEvent ( "onLogin", getLocalPlayer(), login, pass, checkboxs[1].state)
end
function pressRegister()
for i, ebox in ipairs(editbox) do
if ebox.name == "loginRej" then
rejlogin = ebox.text
elseif ebox.name == "passRej" then
rejpass = ebox.text
end
end
triggerServerEvent ( "onRegister", getLocalPlayer(), rejlogin, rejpass)
end
function pressRegisterBut()
p_Move = {}
p_Move.startTime = getTickCount()
p_Move.endTime = p_Move.startTime + 450
p_Move.easingFunction = "InOutQuad"
addEventHandler("onClientRender", getRootElement(), movePanelOut)
end
function pressBack()
p_Move = {}
p_Move.startTime = getTickCount()
p_Move.endTime = p_Move.startTime + 450
p_Move.easingFunction = "InOutQuad"
addEventHandler("onClientRender", getRootElement(), movePanelIn)
end
addEvent("pressBack",true)
addEventHandler("pressBack",getRootElement(),pressBack)
function movePanelOut()
local now = getTickCount()
local elapsedTime = now - p_Move.startTime
local duration = p_Move.endTime - p_Move.startTime
local progress = elapsedTime / duration
local fAnimationTime = getEasingValue(progress, p_Move.easingFunction)
local move = fAnimationTime*sw * 0.122
removeEventHandler("onClientRender", getRootElement(), renderLoginContent)
setTimer( function() addEventHandler("onClientRender", getRootElement(), renderLoginContent) end, 1200, 1 )
removeEventHandler("onClientClick",getRootElement(),onClick)
for i,v in ipairs ( field ) do
if v.text then
v.text = ""
v.erbox = "bialy"
end
end
setTimer( function()
for i,v in ipairs ( field ) do
if v.text then
v.text = "Panel Rejestracji!"
end
end
end, 1200, 1 )
mx = move
my = move * 2
sy = sh
ssy = 0
if now > p_Move.endTime then
removeEventHandler("onClientRender", getRootElement(), movePanelOut)
addEventHandler("onClientClick",getRootElement(),onClick)
end
end
function movePanelIn()
local now = getTickCount()
local elapsedTime = now - p_Move.startTime
local duration = p_Move.endTime - p_Move.startTime
local progress = elapsedTime / duration
local fAnimationTime = getEasingValue(progress, p_Move.easingFunction)
local move = fAnimationTime* sw * 0.122
removeEventHandler("onClientRender", getRootElement(), renderLoginContent)
setTimer( function() addEventHandler("onClientRender", getRootElement(), renderLoginContent) end, 1200, 1 )
removeEventHandler("onClientClick",getRootElement(),onClick)
for i,v in ipairs ( field ) do
if v.text then
v.text = ""
v.erbox = "bialy"
end
end
setTimer( function()
for i,v in ipairs ( field ) do
if v.text then
v.text = "Panel Logowania!"
end
end
end, 1200, 1 )
mx = -move
my = -move * 2
sy = 0
ssy = sh
if now > p_Move.endTime then
removeEventHandler("onClientRender", getRootElement(), movePanelIn)
addEventHandler("onClientClick",getRootElement(),onClick)
end
end
function changeMessage(mesBox, newMessage, boxColor)
for i,box in ipairs(field) do
if box.messageBox == mesBox then
box.text = newMessage
box.erbox = boxColor
end
end
end
addEvent("changeMessage",true)
addEventHandler("changeMessage",getRootElement(),changeMessage)
function onClick(mButton,state,ax,ay)
if logopanel == true then
if not (state == "down" and mButton == "left") then
return false
end
for i,b in pairs(buttons) do
if b.typ then
if ( b.typ == "login" ) then
if isMouseWithinRangeOf(b.x, b.y + sy, b.w, b.h) then
outputDebugString("Pressed "..b.text)
if b.func then
loadstring("return "..b.func.."()")()
end
end
elseif ( b.typ == "register" ) then
if isMouseWithinRangeOf(b.x, b.y + ssy, b.w, b.h) then
outputDebugString("Pressed "..b.text)
if b.func then
loadstring("return "..b.func.."()")()
end
end
end
end
end
for i,ebox in pairs(editbox) do
if ebox.typ then
if ( ebox.typ == "login" ) then
if isMouseWithinRangeOf(ebox.x, ebox.y + sy, ebox.w, ebox.h) then
outputDebugString("Pressed "..ebox.textup)
eboxClickI = i
return true
end
elseif ( ebox.typ == "register" ) then
if isMouseWithinRangeOf(ebox.x, ebox.y + ssy, ebox.w, ebox.h) then
outputDebugString("Pressed "..ebox.textup)
eboxClickI = i
return true
end
end
end
end
for i,cbox in pairs(checkboxs) do
if isMouseWithinRangeOf(cbox.x, cbox.y + sy, cbox.wh, cbox.wh) then
outputDebugString("Pressed "..i.." checkbox")
if cbox.state == false then
cbox.state = true
else
cbox.state = false
end
end
end
eboxClickI = nil
return false
end
end
addEventHandler("onClientClick",getRootElement(),onClick)
function isMouseWithinRangeOf(posX, posY, sizeX, sizeY)
if isCursorShowing() == false then
return false
end
local cx,cy = getCursorPosition()
cx,cy = cx*sw,cy*sh
if cx >= posX and cx <= posX+sizeX and cy >= posY and cy <= posY+sizeY then
return true,cx,cy
else
return false
end
end
function hideLoginPanel()
addEventHandler("onClientRender", getRootElement(), hidePanelOut)
end
function hidePanelOut()
setTimer( function()
--removeEventHandler("onClientRender", getRootElement(), onClick)
--removeEventHandler("onClientRender", getRootElement(), hidePanelOut)
--removeEventHandler("onClientRender", getRootElement(), getCharacter)
removeEventHandler("onClientRender",getRootElement(),renderLoginPanel)
removeEventHandler("onClientRender",getRootElement(),renderLoginContent)
if (getTickCount() - time >= 2000) then
removeEventHandler("onClientPreRender", getRootElement(), anim)
end
logopanel = false
end, 2000, 1 )
end
addEvent("hideLoginPanel",true)
addEventHandler("hideLoginPanel",getRootElement(),hideLoginPanel)
function muzaoff()
stopSound(data.misc)
end
addEvent("stop:muzaLogin",true)
addEventHandler("stop:muzaLogin",getRootElement(),muzaoff)
function apagarScript()
if fileExists("client.lua") then
fileDelete("client.lua")
end
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), apagarScript)
addEventHandler("onClientPlayerQuit", getRootElement(), apagarScript)
addEventHandler("onClientPlayerJoin", getRootElement(), apagarScript)