Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2021-08-22, 14:52


Janusz_GRA

NO NAME






Wiek: 26
Na forum: 3857 dni
Posty: 223
Nick w MP: michalMonster

Piwa: 175

Respekt: 85,8

Siemka, robi sw?j system notyfikacji ale mam problem z nimi. Gdy tworze notyfikacje jedna po drugiej to one si? resetuj? w sensie, ?e animacja zaczyna si? od pocz?tku, ale czas zostaje dalej. Bardziej ukazane mam to na filmiku. Kto? wie jak to naprawi?? Za pomoc stawiam R*
Film: https://streamable.com/1vmuvo
Kod:
local sx, sy = guiGetScreenSize()

local tick

local font = dxCreateFont('medium.ttf', 13/1920*sx, true);

local colors = {
    error = tocolor(252, 3, 3),
    info = tocolor(252, 186, 3),
    success = tocolor(69, 219, 46),
}

local notifications = {};

function anim(startTick, startValue, stopValue, time, type)
    local anim = interpolateBetween(startValue, 0, 0, stopValue, 0, 0, (getTickCount() - startTick) / time, type)

    if (getTickCount() - startTick) > time then
        return anim, false
    else
        return anim, true
    end
end

function renderNoti()
    for index, value in pairs(notifications) do
        
        noti = anim(tick, 1800, 1493, 2000, 'Linear')
        line = anim(tick, 417, 0, value[4] + 500, 'Linear')

        if getTickCount() > value[3] + (value[4] + 500) then
            table.remove(notifications, 1)
            if (#notifications == 0) then
                removeEventHandler('onClientRender', root, renderNoti);
            end
        end

        local addY = 100 * (index - 1);
        dxDrawRectangle(noti, 340 + addY, 417, 93, tocolor(34, 35, 66, 255), false)
        dxDrawRectangle(noti, 430 + addY, line, 3, colors[value[1]], false)
        dxDrawText(value[2], noti, 339 + addY, 1910, 430 + addY, tocolor(255, 255, 255, 255), 1, font, 'center', 'center', false, true, true);
    end
end 

function createAlert(type, text)
    if not type then type = 'info' end

    tick = getTickCount()
    table.insert(notifications, { type, text, getTickCount(), 5000});
    outputConsole('['..type..'] '..text);
    if (#notifications == 1) then
        addEventHandler('onClientRender', root, renderNoti);
    end
    if (#notifications > 5) then
        table.remove(notifications, 1);
    end
end

addEvent("createAlert", true)
addEventHandler("createAlert", resourceRoot, 
    function(...)
        createAlert(...)
    end
)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-08-28, 12:15


MeeShuffle

Programista/Grafik






Wiek: 33
Na forum: 4536 dni
Posty: 2758
Nick w MP: Shuffle

Piwa: 8578

Respekt: 535,3
Respekt: 535,3

Potrzebujesz wstawi? do tabeli a potem sprawdzi? to w p?tli dla ka?dego elementu osobno, przyk?ad z moich notyfikacji :



table.insert(msg,{txt=txt,start=getTickCount(),theDuration=(string.len(txt)*100),width=p["bg"][3],icon=icons[type][1]})


Postaw piwo autorowi tego posta
 

 
Tagi: notyfikacje
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Notyfikacje Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku