Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico8340 committed Feb 4, 2024
1 parent a0267f5 commit 6a93923
Showing 1 changed file with 222 additions and 0 deletions.
222 changes: 222 additions & 0 deletions [gameplay]/dialogs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Dialogs

## Description
Create and manage dialogs with callbacks.

## Pictures
![img](https://i.imgur.com/yawOkA6.png)

## Functions

### MessageBeep

**Description**<br>
This function plays a sound from the **messageSounds** table.

**Syntax**
```lua
messageBeep( string soundType, [ int soundVolume ] )
```

**Example**
> This example plays an info sound with the default volume (1)
```lua
messageBeep("INFO")
```

<br>

> This example plays a question sound with specified volume (0.5)
```lua
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)
<br>

**Returns**<br>
Returns the sound element.

### MessageBox

**Description**<br>
This function creates a dialog box with a callback function.

**Syntax**
```lua
messageBox( string messageTitle, string messageContent, function messageCallback, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )
```

**Example**
> This example creates a dialog containing an information.
```lua
messageBox("Welcome", "Multi Theft Auto provides the best online Grand Theft Auto experience there is.",
function(callbackResult)
if callbackResult == "OK" then
print("Read")
end
end,
"INFO", "OK")
```

<br>

> This example creates a dialog containing a question.
```lua
messageBox("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.",
function(callbackResult)
if callbackResult == "YES" then
print("Save")
elseif callbackResult == "NO" then
print("Undo")
else
print("Cancel")
end
end,
"QUESTION", "YESNOCANCEL")
```

<br>

> This example creates a dialog containing a warning.
```lua
messageBox("Mismatch", "The selected file does not exist. Would you like to try the download again?",
function(callbackResult)
if callbackResult == "ABORT" then
print("Abort")
elseif callbackResult == "RETRY" then
print("Retry")
else
print("Ignore")
end
end,
"WARNING", "ABORTRETRYIGNORE")
```

<br>

> This example creates a dialog containing an error.
```lua
messageBox("Your wallet is empty", "You do not have enough money to purchase the selected vehicle.",
function(callbackResult)
if callbackResult == "Ok" then
print("Read")
end
end,
"ERROR", "OK")
```

**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 function that is called when the user presses a button. Use the callbackResult parameter to register the result.
> - 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.
<br>
**Returns**<br>
This function does not contain returns because it uses a callback function.

### MessageBoxEx

**Description**<br>
This function creates a dialog box without a callback function.

**Syntax**
```lua
messageBoxEx( string messageTitle, string messageContent, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )
```

**Example**
> This example creates a dialog containing an information.
```lua
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
)
```

<br>

> This example creates a dialog containing a question.
```lua
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
)
```

<br>

> This example creates a dialog containing a warning.
```lua
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
)
```

<br>

> This example creates a dialog containing an error.
```lua
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.
<br>
**Returns**<br>
Returns as many buttons in order as specified in the messageButton argument.

0 comments on commit 6a93923

Please sign in to comment.