# SDialogues

**الأعضاء** 5

|      |                                 |                                                                               |
| ---- | ------------------------------- | ----------------------------------------------------------------------------- |
| دالة | [ColorPicker](#colorpicker)     | Opens a color picker dialogue.                                                |
| دالة | [YesNoInput](#yesnoinput)       | Opens a simple Yes/No dialogue.                                               |
| دالة | [TextInput](#textinput)         | Opens a text entry window with room for a single multi-line text field.       |
| دالة | [OpenURL](#openurl)             | Opens the specified URL in the in-app web browser, or the system web browser. |
| دالة | [SendLocalChat](#sendlocalchat) | Sends a message into the 'Script' chat channel.                               |

## الدوال

### ColorPicker

void ColorPicker(string title, string okbutton, Action< SColor > onChange, Action< SColor > onSelect, Action onCancel, SColor defaultColor)

Opens a color picker dialogue.

المعاملات

| المعامل      | النوع                        | الوصف                                                                                                    |
| ------------ | ---------------------------- | -------------------------------------------------------------------------------------------------------- |
| title        | string                       | The title of the color picker window. Choose something brief and appropriate like 'Select a wall color'. |
| okbutton     | string                       | The title of the 'OK' button. Should indicate the action e.g. 'Adjust Wall'.                             |
| onChange     | Action\\\<SColor> or Closure | Any color change while the color picker is open will trigger onChange(SColor).                           |
| onSelect     | Action\\\<SColor> or Closure | Triggers onSelect(SColor) once the "ok" button is pressed.                                               |
| onCancel     | Action\\\<SColor> or Closure | The title of the 'OK' button. Should indicate the action e.g. 'Adjust Wall'.                             |
| defaultColor | SColor                       | The color to open the colour picker with.                                                                |

القيم المرجعة

`void`

مثال

**Lua**

```lua
--clicking the object will open a color picker that changes the object's color
thisGameObject = Space.Host.ExecutingObject
originalColor = thisGameObject.Renderer.Material.GetColor("_Color")

OnChange = function(SColor) 
  thisGameObject.Renderer.Material.SetColor("_Color",SColor)
end

OnSelect = function(SColor)
  thisGameObject.Renderer.Material.SetColor("_Color",SColor)
end

OnCancel = function()
  thisGameObject.Renderer.Material.SetColor("_Color",originalColor)
end

OnClick = function()
  Space.Dialogues.ColorPicker("title","okbutton", OnChange, OnSelect, OnCancel, originalColor)
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### YesNoInput

void YesNoInput(string title, string okbutton, string cancelButton, Action< bool > result)

Opens a simple Yes/No dialogue<strong>.</strong>

المعاملات

| المعامل      | النوع           | الوصف                                                                                         |
| ------------ | --------------- | --------------------------------------------------------------------------------------------- |
| title        | string          | The question to be asked of the user. Should be a simple statement, e.g. "Save room changes?" |
| okbutton     | string          | The text on the OK button, should indicate the action, e.g. "Save Room"                       |
| cancelButton | string          | The text on the cancel button, should indicate the action, e.g. "Not now"                     |
| result       | Action\\\<bool> | Will fire a callback event depending on the status of the users actions                       |

القيم المرجعة

`void`

مثال

**Lua**

```lua
hostObject = Space.Host.ExecutingObject
local deltaPos = Vector.New(0,100,0)
local teleportTo = hostObject.WorldPosition + deltaPos

function teleportMeUp (b)
  if b then
    Space.Scene.PlayerAvatar.Teleport(teleportTo)
  end
end

function openDialogue ()
  Space.Dialogues.YesNoInput ("Ready for a teleport?", "Yes", "No", teleportMeUp)
end

hostObject.SubscribeToEvents()
hostObject.OnMouseDown(openDialogue)

```

### TextInput

void TextInput(string title, string okButton, Action< string > result)

Opens a text entry window with room for a single multi-line text field.

المعاملات

| المعامل  | النوع            | الوصف                                                                               |
| -------- | ---------------- | ----------------------------------------------------------------------------------- |
| title    | string           | The accompanying text. Should be something ala "Enter your username".               |
| okButton | string           | The text displayed on the OK button, should be descriptive, e.g. "Change Username". |
| result   | Action< string > | Triggers result(string) once the "Ok" button is pressed.                            |

القيم المرجعة

`void`

مثال

**Lua**

```lua
hostObject = Space.Host.ExecutingObject

printToLog = function (s)
  Space.Log(s)
end

function openDialogue ()
  Space.Dialogues.TextInput ("Write anything.", "Done", printToLog)
end

hostObject.OnMouseDown(openDialogue)

```

### OpenURL

void OpenURL(string url, bool newTab = true)

Opens the specified URL in the in-app web browser, or the system web browser. In some environments the user may be prompted before this is opened.

المعاملات

| المعامل | النوع  | الوصف                                   |
| ------- | ------ | --------------------------------------- |
| url     | string | The web address to open.                |
| newTab  | bool   | Does the URL open in a new browser tab? |

القيم المرجعة

`void`

مثال

**Lua**

```lua
-- when the object is clicked, the "sine.space" website is opened
hostObject = Space.Host.ExecutingObject

function openTheWebsite ()
  Space.Dialogues.OpenURL("http://sine.space/")
end

hostObject.OnMouseDown(openTheWebsite)

```

### SendLocalChat

void SendLocalChat(string message, string from)

Sends a message into the 'Script' chat channel.

المعاملات

| المعامل | النوع  | الوصف                                 |
| ------- | ------ | ------------------------------------- |
| message | string | The message to appear in the channel. |
| from    | string | The 'from' username for the message.  |

القيم المرجعة

`void`

مثال

**Lua**

```lua
hostObject = Space.Host.ExecutingObject

function chatMessage ()
  Space.Dialogues.SendLocalChat ("I've been clicked", "Clickable Object")
end

hostObject.OnMouseDown(chatMessage)

```
