Skip to content

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

Merged
Kenshiin13 merged 6 commits into
esx-framework:devfrom
Kenshiin13:refactor-scaleforms
Jan 4, 2025
Merged

feat(es_extended/client/modules/scaleform): add scaleform util function and refactor existing scaleforms#1581
Kenshiin13 merged 6 commits into
esx-framework:devfrom
Kenshiin13:refactor-scaleforms

Conversation

@Kenshiin13

@Kenshiin13 Kenshiin13 commented Jan 4, 2025

Copy link
Copy Markdown
Contributor

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
@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