Gyrosos Posted July 13 Share Posted July 13 (edited) Írtam egy egyedi gui scriptet, aminél valamiért ha 2 editboxot kreálok akkor az elsőt nem lehet aktiválni, editelni. Aki tud segíthetne, köszi, puszi sx, sy = guiGetScreenSize() createdBoxes = {} hoveredBox = false activeBox = false padding = 5 textCursor = { alpha = 0, targetAlpha = 255, tick = getTickCount(), } addEventHandler('onClientRender', getRootElement(), function() for name, box in pairs(createdBoxes) do local x, y, w, h = box.x, box.y, box.w, box.h if isInSlot(x, y, w, h) then print('@' .. name) hoveredBox = name else hoveredBox = false end dxDrawRectangle(x, y, w, h, hoveredBox == name and tocolor(30, 30, 30, 180) or tocolor(20, 20, 20, 180)) currentText = guiGetText(box.gui) if box.isPw then currentText = string.rep('*', string.len(currentText)) end textWidth = dxGetTextWidth(currentText, 1, box.font) verticalAlign = 'left' if textWidth >= w + padding then verticalAlign = 'right' end dxDrawText(currentText, x + padding, y, x + w - padding * 2, y + h, tocolor(255, 255, 255, 255), 1, box.font, verticalAlign, 'center') cursorColor = {255, 255, 255, textCursor.alpha} if activeBox == name then guiEditSetCaretIndex(box.gui, string.len(currentText)) guiSetInputMode('no_binds_when_editing') dxDrawText('|', math.min(x + padding + textWidth, x + w - padding * 2), y, x + w, y + h, tocolor(unpack(cursorColor)), 1, box.font, 'left', 'center') end local alpha = interpolateBetween(textCursor.alpha, 0, 0, textCursor.targetAlpha, 0, 0, (getTickCount() - textCursor.tick) / 500, 'InQuad') textCursor.alpha = alpha if alpha == textCursor.targetAlpha then textCursor.targetAlpha = alpha == 0 and 255 or 0 textCursor.tick = getTickCount() end end end) addEventHandler('onClientClick', getRootElement(), function(button, state) if button == 'left' and state == 'down' then if hoveredBox then guiBringToFront(createdBoxes[hoveredBox].gui) activeBox = hoveredBox else activeBox = false end end end) function cGuiCreateEdit(name, x, y, w, h, isPw, holder, font) if createdBoxes[name] then return nil end g = guiCreateEdit(-1000, -1000, 0, 0, holder, false, false) createdBoxes[name] = { x = x, y = y, w = w, h = h, isPw = isPw, font = initFont(font, h * 0.4), gui = g, } return createdBoxes[name] end function cGuiDestroyEdit(name) if createdBoxes[name] then if isElement(createdBoxes[name].gui) then destroyElement(createdBoxes[name].gui) end createdBoxes[name] = nil end end function isInSlot(x, y, w, h) if not isCursorShowing() then return false else local mx, my = getCursorPosition() mx, my = mx*sx, my*sy if mx >= x and mx <= x + w and my >= y and my <= y + h then return true else return false end end end fonts = {} function initFont(font, size) tablekey = font..size if fonts[tablekey] then return fonts[tablekey] else f = dxCreateFont('fonts/'..font..'.ttf', size) fonts[tablekey] = f return f end end local username = cGuiCreateEdit('username', sx*0.5, sy*0.5, sx*0.2, 30, false, 'Felhasználónév', 'SpaceMono-Regular') local pw = cGuiCreateEdit('password', sx*0.5, sy*0.6, sx*0.2, 30, true, 'Jelszó', 'SpaceMono-Regular') Edited July 17 by Gyrosos Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now