Popular Post NeXuS™ Posted March 19, 2017 Popular Post Share Posted March 19, 2017 (edited) NeXuS™ presents dxScrollText Introduction Do you want to make a scrollable text? It's easy with just a helper. Status IN DEVELOPMENT It's still IN DEVELOPMENT but it's published. Screenshot Usage Go ingame, put the file inside resources, start it, and press F7. After it, create your panel, by left clicking and dragging, and press enter. If you are done with that, start typing, and press enter. Voala, it's done. Download MTA:SA Community Link(At the moment, the download link is unavaible, because the resource got suspended by sbx320. I'm talking with him in PMs, to sort this out. If you need the ready resource, hit me up here with a PM, and I'll send it to you.) Syntax - Source code Spoiler local sX, sY = guiGetScreenSize() local panelState = false local maxLinePerScrollText = 30 local lineNumber = 1 local creatingSession = "createPanel" local scrollTexts = {} outputDebugString("dxScrollText Alpha 0.1 loaded.") outputChatBox("[INFO] dxScrollText Alpha 0.1 loaded. Press F7 to create texts.", 255, 255, 255, true) _getCursorPosition = getCursorPosition function getCursorPosition() local cX, cY = _getCursorPosition() if cX and cY then return cX*sX, cY*sY end return -1, -1 end function inBox(x, y, w, h) local cX, cY = getCursorPosition() if (cX > x and cX < x + w and cY > y and cY < y + h) then return true end return false end addEventHandler("onClientClick", getRootElement(), function(cB, cS) if cB == "left" and panelState then if creatingSession == "createPanel" then if cS == "down" then startX, startY = getCursorPosition() if endX then endX, endY = nil end else local cX, cY = getCursorPosition() if (cX-startX > 0) and (cY-startY > 0) then endX, endY = cX, cY else if cX-startX < 0 then outputChatBox("#4183D7[INFO]#FFFFFF Invalid size.", 255, 255, 255, true) end startX, startY = nil, nil end end end end end) addEventHandler("onClientKey", getRootElement(), function(kB, kS) if kB == "mouse_wheel_up" then for i, k in ipairs(scrollTexts) do if inBox(k[1], k[2], k[3], k[4]) then if k[6] < 0 then k[6] = k[6] + 1 end return end end elseif kB == "mouse_wheel_down" then for i, k in ipairs(scrollTexts) do if inBox(k[1], k[2], k[3], k[4]) then if k[6] > -(k[7]-1)*15 then k[6] = k[6] - 1 end return end end end if kS then if kB == "F7" then panelState = not panelState showCursor(not isCursorShowing()) return end end if kS and panelState then if kB == "backspace" then if creatingSession == "createPanel" then panelState = false elseif creatingSession == "writeText" then tempTable[5][lineNumber] = tempTable[5][lineNumber]:sub(1, -2) end elseif kB == "mouse2" then if creatingSession == "writeText" then tempTable = nil lineNumber = 1 creatingSession = "createPanel" startX, startY = nil, nil endX, endY = nil, nil end end if creatingSession == "createPanel" then cancelEvent() if kB == "enter" and endX then creatingSession = "writeText" tempTable = {startX, startY, endX-startX, endY-startY, {""}, 0} end elseif creatingSession == "writeText" then cancelEvent() if kB == "enter" then table.insert(tempTable, lineNumber) table.insert(tempTable, dxCreateRenderTarget(endX-startX, endY-startY, true)) triggerServerEvent("doStartup", getRootElement(), "createScrollText(" .. tempTable[1] .. ", " .. tempTable[2] .. ", " .. tempTable[3] .. ", " .. tempTable[4] .. ", " .. table.tostring(tempTable[5]) .. ", " .. tempTable[7] .. ")") scrollTexts[#scrollTexts+1] = tempTable creatingSession = "createPanel" lineNumber = 1 tempTable = nil startX, startY = nil, nil endX, endY = nil, nil end end end end) addEventHandler("onClientCharacter", getRootElement(), function(clickedChar) if panelState and creatingSession == "writeText" then if dxGetTextWidth(tempTable[5][lineNumber] .. "" .. clickedChar) < endX-startX then tempTable[5][lineNumber] = tempTable[5][lineNumber] .. "" .. clickedChar else lineNumber = lineNumber + 1 tempTable[5][lineNumber] = "" tempTable[5][lineNumber] = tempTable[5][lineNumber] .. "" .. clickedChar end end end) addEventHandler("onClientRender", getRootElement(), function() if panelState then dxDrawRectangle(0, 0, sX, sY, tocolor(0, 0, 0, 150)) if startX then if not endX then local cX, cY = getCursorPosition() dxDrawRectangle(startX, startY, cX-startX, cY-startY, tocolor(128, 128, 0, 200)) else dxDrawRectangle(startX, startY, endX-startX, endY-startY, tocolor(128, 128, 0, (creatingSession == "createPanel" and 200 or 50))) end end if creatingSession == "createPanel" then dxDrawText("If you are done positioning the panel, press #4183D7ENTER#FFFFFF.", 0, sY-30, sX, sY, tocolor(255, 255, 255, 255), 1.2, "default-bold", "center", "center", false, false, false, true) elseif creatingSession == "writeText" then dxDrawRectangle((sX-(endX-startX))/2, (sY-(maxLinePerScrollText*15))/2, endX-startX, maxLinePerScrollText*15, tocolor(0, 0, 0, 200)) for i, k in ipairs(tempTable[5]) do dxDrawText(k, (sX-(endX-startX))/2, (sY-(maxLinePerScrollText*15))/2+(i-1)*15) end dxDrawText("If you are done with the text, press #4183D7ENTER#FFFFFF.", 0, sY-30, sX, sY, tocolor(255, 255, 255, 255), 1.2, "default-bold", "center", "center", false, false, false, true) end end for i, k in ipairs(scrollTexts) do if k[8] then dxSetRenderTarget(k[8], true) for i = 0, k[7]-1 do dxDrawText(k[5][i+1], 0, i*15+k[6]) end dxSetRenderTarget() dxDrawRectangle(k[1], k[2], k[3], k[4], tocolor(0, 0, 0, 150)) dxDrawImage(k[1], k[2], k[3], k[4], k[8]) local scrollProgress = k[6]/(-(k[7]-1)*15) if scrollProgress >= 0 and scrollProgress <= 1 then dxDrawRectangle(k[1]+k[3], k[2]+(k[4]-k[4]/k[7])*scrollProgress, 10, k[4]/k[7], tocolor(128, 128, 0, 150)) end end end end) function createScrollText(x, y, width, height, text, linec) outputChatBox(x .. " " .. y .. " " .. width .. " " .. height) local tempTable = {x, y, width, height, text, 0, linec, dxCreateRenderTarget(width, height, true)} table.insert(scrollTexts, tempTable) end function table.val_to_str ( v ) if "string" == type( v ) then v = string.gsub( v, "\n", "\\n" ) if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then return "'" .. v .. "'" end return '"' .. string.gsub(v,'"', '\\"' ) .. '"' else return "table" == type( v ) and table.tostring( v ) or tostring( v ) end end function table.key_to_str ( k ) if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then return k else return "[" .. table.val_to_str( k ) .. "]" end end function table.tostring( tbl ) local result, done = {}, {} for k, v in ipairs( tbl ) do table.insert( result, table.val_to_str( v ) ) done[ k ] = true end for k, v in pairs( tbl ) do if not done[ k ] then table.insert( result, table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) end end return "{" .. table.concat( result, "," ) .. "}" end Spoiler local fileO = fileOpen("startUp.lua") fileSetPos(fileO, fileGetSize(fileO)) addEvent("doStartup", true) addEventHandler("doStartup", getRootElement(), function(startupText) fileWrite(fileO, startupText) fileFlush(fileO) end) addEventHandler("onResourceStop", getResourceRootElement(), function() fileClose(fileO) end) Edited March 20, 2017 by NeXuS™ 4 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