Created
May 7, 2017 22:03
-
-
Save TGRHavoc/37c4d10acbe83ffe0cd5a5cc6c8dd22a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _drawSprite(dic, texture, posX, posY, sizeWidth, sizeHeight, heading, colour) | |
-- Make sure sprite dictionary is loaded | |
while not HasStreamedTextureDictLoaded(dic) do | |
Wait(100) | |
RequestStreamedTextureDict(dic, true) | |
end | |
-- NUI Calculations | |
local screenW, screenH = GetScreenResolution() | |
local height = 1080 | |
local ratio = screenW/screenH | |
local width = height*ratio | |
local w = sizeWidth / width -- width of sprite (to render) | |
local h = sizeHeight / height -- height of sprite (to render) | |
local x = (posX / width) + w * 0.5 -- x start | |
local y = (posY / height) + h * 0.5 -- y start | |
-- function DrawSprite(textureDict, textureName, screenX, screenY, scaleX, scaleY, heading, colorR, colorG, colorB, colorA) | |
DrawSprite(dic, texture, x, y, w, h, heading, colour[1], colour[2], colour[3], colour[4]) | |
end | |
function _drawText(text, posX, posY, scale, colour, alignment, dropShadow, outline, wordWrap) | |
-- again, nui magic | |
local screenW, screenH = GetScreenResolution() | |
local height = 1080 | |
local ratio = screenW/screenH | |
local width = height*ratio | |
local x = posX / width | |
local y = posY / height | |
-- 7 = pricedown (font), cba making it a variable | |
SetTextFont(7) | |
SetTextScale(1.0, scale) | |
SetTextColour(colour[1], colour[2], colour[3], colour[4]) | |
if dropShadow then | |
SetTextDropShadow() | |
end | |
if outline then | |
SetTextOutline() | |
end | |
if alignment then | |
if alignment == "center" then | |
SetTextCentre(true) | |
elseif alignment == "right" then | |
SetTextRightJustify(true) | |
SetTextWrap(0, x) | |
else | |
-- Left by default. | |
end | |
end | |
if wordWrap then | |
local size = (posX + wordWrap) / width | |
SetTextWrap(x, size) | |
end | |
SetTextEntry("jamyfafi") | |
-- Add the text | |
local maxSize = 99 | |
for temp=0, string.len(text), maxSize do | |
local subStr = string.sub(text, temp, math.min(maxSize, text:len() - temp)) | |
AddTextComponentString(subStr) | |
Citizen.Trace("add: " .. subStr) | |
end | |
Citizen.Trace("DrawText") | |
DrawText(x, y) | |
end | |
function showWastedText(line1, line2) | |
local screenW, screenH = GetScreenResolution() | |
local height = 1080 | |
local ratio = screenW/screenH | |
local width = height*ratio | |
-- Draw the background | |
_drawSprite("mpentry", "mp_modenotselected_gradient", 0, 30, width, 300, 0, {255, 255, 255, 255}) | |
-- Draw the text | |
--_drawText(text, posX, posY, scale, colour, alignment, dropShadow, outline, wordWrap) | |
_drawText(line1, width/2, 100, 2.5, {255, 148, 27, 255}, "center", false, false, nil) | |
_drawText(line2, width/2, 230, 0.5, {255, 255, 255, 255}, "center") | |
end | |
Citizen.CreateThread(function() | |
while true do | |
Citizen.Wait(1) | |
-- Keeps drawing the text to the screen | |
showWastedText("Hello", "line two") | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment