mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 04:01:22 +00:00
fix:progressbar - fully working :)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
local InProgress = false
|
||||
local CurrentProgress = nil
|
||||
local function Progressbar(message,length,Options)
|
||||
local Canceled = false
|
||||
if not InProgress then
|
||||
if not CurrentProgress then
|
||||
CurrentProgress = Options
|
||||
if Options.animation then
|
||||
if Options.animation.type == "anim" then
|
||||
ESX.Streaming.RequestAnimDict(Options.animation.dict, function()
|
||||
@@ -18,30 +19,32 @@ local function Progressbar(message,length,Options)
|
||||
length = length or 3000,
|
||||
message = message or "ESX-Framework"
|
||||
}))
|
||||
local le = length or 3000
|
||||
while le > 0 do
|
||||
Wait(0)
|
||||
le -= 1
|
||||
if IsControlJustPressed(0, 194) and Options.onCancel then
|
||||
SendNuiMessage(json.encode({
|
||||
type = "Close"
|
||||
}))
|
||||
Canceled = true
|
||||
ClearPedTasksImmediately(ESX.PlayerData.ped)
|
||||
CurrentProgress.length = length or 3000
|
||||
while CurrentProgress ~= nil do
|
||||
if CurrentProgress.length > 0 then
|
||||
CurrentProgress.length -= 1000
|
||||
else
|
||||
ClearPedTasks(ESX.PlayerData.ped)
|
||||
if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end
|
||||
InProgress = false
|
||||
le = 0
|
||||
Options.onCancel()
|
||||
if Options.onFinish then Options.onFinish() end
|
||||
CurrentProgress = nil
|
||||
end
|
||||
end
|
||||
if not Canceled then
|
||||
ClearPedTasks(ESX.PlayerData.ped)
|
||||
if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end
|
||||
if Options.onFinish then Options.onFinish() end
|
||||
InProgress = false
|
||||
Wait(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
exports('Progressbar', Progressbar)
|
||||
|
||||
ESX.RegisterInput("cancelprog", "[ProgressBar] Cancel Progressbar", "keyboard", "BACK", function()
|
||||
if not CurrentProgress then return end
|
||||
if not CurrentProgress.onCancel then return end
|
||||
SendNuiMessage(json.encode({
|
||||
type = "Close"
|
||||
}))
|
||||
ClearPedTasks(ESX.PlayerData.ped)
|
||||
if CurrentProgress.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end
|
||||
CurrentProgress.canceled = true
|
||||
CurrentProgress.length = 0
|
||||
CurrentProgress.onCancel()
|
||||
CurrentProgress = nil
|
||||
end)
|
||||
exports('Progressbar', Progressbar)
|
||||
@@ -40,7 +40,7 @@ $(function () {
|
||||
$(".text").text(message)
|
||||
doc.getElementById("notifyInfo").style.display = "block";
|
||||
const start = new Date();
|
||||
const maxTime = e.data.length
|
||||
const maxTime = e.data.length;
|
||||
const timeoutValue = Math.floor(maxTime/100);
|
||||
animUpdate();
|
||||
|
||||
@@ -54,13 +54,16 @@ $(function () {
|
||||
const prc = Math.round((timeoutDiff/maxTime)*100);
|
||||
if (prc <= 100) {
|
||||
updateProg(prc);
|
||||
setTimeout(animUpdate, timeoutValue);
|
||||
this.timeoutID = setTimeout(animUpdate, timeoutValue);
|
||||
} else {
|
||||
doc.getElementById('notifyInfo').style.display = "none";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doc.getElementById("notifyInfo").style.display = "none"
|
||||
clearTimeout(this.timeoutID);
|
||||
timeoutValue = 0;
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user