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

Dialogs #467

Merged
merged 13 commits into from
May 23, 2024
Merged

Dialogs #467

merged 13 commits into from
May 23, 2024

Conversation

Nico8340
Copy link
Contributor

@Nico8340 Nico8340 commented Feb 4, 2024

Description

This pull request was created to replace the existing msgbox resource. (Successor of #464)

Tasks

  • Add new resource
  • Add documentation
  • Add deprecated warning to the old 'msgbox' resource
  • Replace old syntax in resources

Preview

img

Functions

MessageBeep

Description

This function plays a sound from the messageSounds table.

Syntax

messageBeep( string soundType, [ int soundVolume ] )

Example

This example plays an info sound with the default volume (1)

messageBeep("INFO")

This example plays a question sound with specified volume (0.5)

messageBeep("QUESTION", 0.5)

Arguments

  • soundType: A string specifying the sound data, which is in the messageSounds table.
  • soundVolume: An integer between 1 and 0 that specifies the volume. (optional)

Returns

Returns the sound element.

MessageBox

Description

This function creates a dialog box with a callback function.

Syntax

messageBox( string messageTitle, string messageContent, string messageCallback, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )

Example

This example creates a dialog containing an information.

messageBox("Welcome", "Multi Theft Auto provides the best online Grand Theft Auto experience there is.", "callbackFunction", "INFO", "OK")
function callbackFunction(callbackResult)
    if callbackResult == "OK" then
        print("Read")
    end
end

This example creates a dialog containing a question.

messageBox("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "callbackFunction", "QUESTION", "YESNOCANCEL")
function callbackFunction(callbackResult)
    if callbackResult == "YES" then
        print("Save")
    elseif callbackResult == "NO" then
        print("Undo")
    else
        print("Cancel")
    end
end

This example creates a dialog containing a warning.

messageBox("Mismatch", "The selected file does not exist. Would you like to try the download again?", "callbackFunction", "WARNING", "ABORTRETRYIGNORE")
function callbackFunction(callbackResult)
    if callbackResult == "ABORT" then
        print("Abort")
    elseif callbackResult == "RETRY" then
        print("Retry")
    else
        print("Ignore")
    end
end

This example creates a dialog containing an error.

messageBox("Your wallet is empty", "You do not have enough money to purchase the selected vehicle.", "callbackFunction", "ERROR", "OK")
function callbackFunction(callbackResult)
    if callbackResult == "OK" then
        print("Read")
    end
end

Arguments

  • messageTitle: A string specifing the title of the message (note that it will be always uppercase)
  • messageContent: A string specifing the content of the message
  • messageCallback: A string specifying the name of the function that will be exported when a button is pressed. (Note that you must specify the function name as a string and specify the function as exportable in the meta.xml of the source.)
  • messageIcon: A string specifing the icon of the message, which is in the messageIcons table.
  • messageButton: A string specifing the button(s) of the message, which is in the messageButtons table.
  • messageButtonDefault: An integer specifing the default button (note that it will receive a bolder font)
  • messageSound: A string specifing the sound of the message, which is in the messageSounds table.
  • messageSoundVolume: An integer between 1 and 0 specifing the volume of the sound.

Returns

This function does not contain returns because it uses a callback function.

MessageBoxEx

Description

This function creates a dialog box without a callback function.

Syntax

messageBoxEx( string messageTitle, string messageContent, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )

Example

This example creates a dialog containing an information.

local buttonOK = messageBoxEx("Welcome", "Multi Theft Auto provides the best online Grand Theft Auto experience there is.", "INFO", "OK")

addEventHandler("onClientGUIClick", buttonOK,
    function()
        print("Read")
    end
)

This example creates a dialog containing a question.

local buttonYes, buttonNo, buttonCancel = messageBoxEx("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "QUESTION", "YESNOCANCEL")

addEventHandler("onClientGUIClick", buttonYes,
    function()
        print("Save")
    end
)

addEventHandler("onClientGUIClick", buttonNo,
    function()
        print("Undo")
    end
)

addEventHandler("onClientGUIClick", buttonCancel,
    function()
        print("Cancel")
    end
)

This example creates a dialog containing a warning.

local buttonAbort, buttonRetry, buttonIgnore = messageBoxEx("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "QUESTION", "YESNOCANCEL")

addEventHandler("onClientGUIClick", buttonAbort,
    function()
        print("Abort")
    end
)

addEventHandler("onClientGUIClick", buttonRetry,
    function()
        print("Retry")
    end
)

addEventHandler("onClientGUIClick", buttonIgnore,
    function()
        print("Ignore")
    end
)

This example creates a dialog containing an error.

local buttonOK = messageBoxEx("Your wallet is empty", "You do not have enough money to purchase the selected vehicle.", "ERROR", "OK")

addEventHandler("onClientGUIClick", buttonOK,
    function()
        print("Read")
    end
)

Arguments

  • messageTitle: A string specifing the title of the message (note that it will be always uppercase)
  • messageContent: A string specifing the content of the message
  • messageIcon: A string specifing the icon of the message, which is in the messageIcons table.
  • messageButton: A string specifing the button(s) of the message, which is in the messageButtons table.
  • messageButtonDefault: An integer specifing the default button (note that it will receive a bolder font)
  • messageSound: A string specifing the sound of the message, which is in the messageSounds table.
  • messageSoundVolume: An integer between 1 and 0 specifing the volume of the sound.

Returns

Returns as many buttons in order as specified in the messageButton argument.

@Nico8340 Nico8340 marked this pull request as ready for review February 5, 2024 00:09
Copy link
Contributor

@Fernando-A-Rocha Fernando-A-Rocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done Nico! There's even documentation :-)

@Nico8340 Nico8340 closed this Apr 27, 2024
@Nico8340 Nico8340 reopened this Apr 27, 2024
Copy link
Contributor

@jlillis jlillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, excellent documentation. Just one minor note about the code. I think it's also worth noting that while this is an improvement for all the resources that were using msgbox previously, it won't work well for admin and admin2 since those message boxes use coroutines rather than callback functions.

[gameplay]/dialogs/sourceC.lua Show resolved Hide resolved
@jlillis
Copy link
Contributor

jlillis commented May 10, 2024

If nobody else has comments after a week or two I'll just send it.

@Dutchman101
Copy link
Member

If nobody else has comments after a week or two I'll just send it.

Nobody did, and it's been called excellent by more than 1 person, so let's merge.
Thanks @Nico8340

@Dutchman101 Dutchman101 merged commit de18c6f into multitheftauto:master May 23, 2024
1 check passed
@Nico8340 Nico8340 deleted the dialogs branch July 11, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants