Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended/client/modules/scaleform): add scaleform util function and refactor existing scaleforms #1581

Merged
merged 6 commits into from
Jan 4, 2025

Conversation

Kenshiin13
Copy link
Contributor

@Kenshiin13 Kenshiin13 commented Jan 4, 2025

Description

This utility function streamlines working with scaleform movie methods, allowing for simpler and more readable calls to scaleform functions. With this change, scaleform methods can be invoked in a much cleaner manner, making it easier to work with complex scaleforms that require multiple method calls.


Motivation

Working directly with scaleforms often leads to messy, hard-to-maintain code, especially when dealing with complex scaleforms that require several method calls. This PR introduces a utility function that abstracts the complexity and simplifies interactions with scaleforms, maintaining readability and reducing boilerplate code.


Implementation Details

  • Utility Function: The ESX.Scaleform.Utils.RunMethod abstracts away the repetitive boilerplate involved in invoking scaleform movie methods. It handles method execution, argument passing, and return value handling.
  • Argument Handling: The function can accept multiple arguments of different types (number, string, boolean), automatically determining the appropriate method to pass the arguments to.
  • Return Value Handling: If requested, the function can return the result of the scaleform movie method, enabling further interaction based on the returned data.
  • Scaleform Disposal: The caller is responsible for disposing of the scaleform using SetScaleformMovieAsNoLongerNeeded.

Usage Example

function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
    local scaleform = ESX.Scaleform.Utils.RunMethod("BREAKING_NEWS", "SET_TEXT", false, msg, bottom)
    ESX.Scaleform.Utils.RunMethod(scaleform, "SET_SCROLL_TEXT", false, 0, 0, title)
    ESX.Scaleform.Utils.RunMethod(scaleform, "DISPLAY_SCROLL_TEXT", false, 0, 0)

    while sec > 0 do
        Wait(0)
        sec = sec - 0.01

        DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
    end

    SetScaleformMovieAsNoLongerNeeded(scaleform)
end

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

@Kenshiin13 Kenshiin13 self-assigned this Jan 4, 2025
@Kenshiin13 Kenshiin13 merged commit 003b635 into esx-framework:dev Jan 4, 2025
1 check passed
@Kenshiin13 Kenshiin13 deleted the refactor-scaleforms branch January 4, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for Next Update
Development

Successfully merging this pull request may close these issues.

2 participants