manups4e / ScaleformUI

ScaleformUI is a GTA menu styled API made with custom Scaleforms to be lighter, faster and visually better
Other
141 stars 49 forks source link

[LUA] ShowFloatingHelpNotification Fix #133

Closed hellyet closed 1 year ago

hellyet commented 1 year ago

Sorry for merge commit, it's my mistake

manups4e commented 1 year ago

what if duration is not specified?

manups4e commented 1 year ago

also.. the setTimeout with set to 3000 means it's forced to 3000.. what if i want 5000? i would use duration parameter for that and would set the EndTextCommandDisplayHelp last parameter to -1

in this case we can add a check that if duration is not specified it can be set to a default of 3000

hellyet commented 1 year ago

Sorry, I forgot to remove the debugging code

hellyet commented 1 year ago
---Show a floating help notification
---@param msg string @The message
---@param coords vector3 @The coordinates of the notification
---@param duration number @The display duration in milliseconds
---@return nil
function Notifications:ShowFloatingHelpNotification(msg, coords, duration)
    Citizen.CreateThread(function()
        local display_notification = true
        Citizen.SetTimeout(duration, function() display_notification = false end)
        while display_notification do
            Citizen.Wait(0)
            AddTextEntry("ScaleformUIFloatingHelpText", msg)
            SetFloatingHelpTextWorldPosition(1, coords.x, coords.y, coords.z)
            SetFloatingHelpTextStyle(1, 1, 2, -1, 3, 0)
            BeginTextCommandDisplayHelp("ScaleformUIFloatingHelpText")
            EndTextCommandDisplayHelp(2, false, false, -1)
        end
    end)
end

That is how it must to be.

manups4e commented 1 year ago

tbh 🤔 i would prefer a simpler function to be called per frame instead of a CreateThread inside a function.. 🤔 to make it multi-pourpose compatible.. i would simply revert it to the original and only remove the duration parameter adding -1 to its behalf.. could you make it like that? this way it's more like its ShowHelpNotification counterpart

hellyet commented 1 year ago

Now it's just a function needs to be called every frame.

manups4e commented 1 year ago

thanks <3 this will maintain the same code format as the other functions!

hellyet commented 1 year ago

Can you edit an WIKI section? Remove "duration" param and add example usage:

   local coords = GetEntityCoods(PlayerPedId())
   local duration = 3000 -- In milliseconds

    Citizen.CreateThread(function()
        local display_notification = true
        Citizen.SetTimeout(duration, function() display_notification = false end)
        while display_notification do
            Citizen.Wait(0)
            Notifications:ShowFloatingHelpNotification("This message will be removed in 3 seconds", coords)
        end
    end)
manups4e commented 1 year ago

🤔 wiki should be open to PRs too.. will do when i get back home from office :D

hellyet commented 1 year ago

See it :)

hellyet commented 1 year ago

I've updated wiki.