Skip to content
Fridolin Wild edited this page Dec 8, 2023 · 7 revisions

# Dialog

A class for displaying an (animated) dialogue box.

The Dialog instance can be accessed via the RootView instance.

RootView_v2.Instance.dialog

There are three display options for Dialog:

  • Middle

Displays title and description, has a close button, offers only two choices.

The canBeClosedByOutTap parameter indicates whether the window can be closed when tapping outside the dialogue box boundary.

    RootView_v2.Instance.dialog.ShowMiddle(
        "Middle Dialog Test!",
        "description",
        "Left", () => Debug.Log("Left - click!"),
        "Right", () => Debug.Log("Right - click!"),
        isCanBeClosedByOutTap);

This is how it is implemented:

    public void ShowMiddle(string label, string description, string textLeft, Action onClickLeft, string textRight, Action onClickRight, bool canBeClosedByOutTap = true)
    {
        var contents = new List<DialogButtonContent> { new DialogButtonContent(textLeft, onClickLeft), new DialogButtonContent(textRight, onClickRight) };
        Show(DialogType.Middle, label, description, contents, canBeClosedByOutTap);
    }

middle

  • Middle Multiline

Displays multiple choices and highlights them, but does not have a close button nor description.

The canBeClosedByOutTap parameter indicates whether the window can be closed when clicking outside the dialogue box boundary.

The isWarning parameter is used to highlight the answer choice.

    RootView_v2.Instance.dialog.ShowMiddleMultiline(
        "Middle Multiline Dialog Test!",
        isCanBeClosedByOutTap,
        ("Item 1", () => Debug.Log("Item 1 - click!"), false),
        ("Item 2", () => Debug.Log("Item 2 - click!"), false),
        ("Item 3", () => Debug.Log("Item 3 - click!"), true));

This is how it is implemented:

    public void ShowMiddleMultiline(string label, params (string text, Action onClick, bool isWarning)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick, t.isWarning)).ToList();
        Show(DialogType.MiddleMultiline, label, null, contents);
    }

    public void ShowMiddleMultiline(string label, params (string text, Action onClick)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick)).ToList();
        Show(DialogType.MiddleMultiline, label, null, contents);
    }

    public void ShowMiddleMultiline(string label, bool canBeClosedByOutTap, params (string text, Action onClick, bool isWarning)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick, t.isWarning)).ToList();
        Show(DialogType.MiddleMultiline, label, null, contents, canBeClosedByOutTap);
    }

    public void ShowMiddleMultiline(string label, bool canBeClosedByOutTap, params (string text, Action onClick)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick)).ToList();
        Show(DialogType.MiddleMultiline, label, null, contents, canBeClosedByOutTap);
    }

middle_m

  • Bottom Multiline

Display multiple choices and highlights them, but does not have a description.

The canBeClosedByOutTap parameter indicates whether the window can be closed when clicking outside the dialogue box boundary.

The isWarning parameter is used to highlight the answer choice.

    RootView_v2.Instance.dialog.ShowBottomMultiline(
        "Bottom Multiline Dialog Test!",
        isCanBeClosedByOutTap,
        ("Item 1", () => Debug.Log("Item 1 - click!"), false),
        ("Item 2", () => Debug.Log("Item 2 - click!"), false),
        ("Item 3", () => Debug.Log("Item 3 - click!"), true),
        ("Item 4", () => Debug.Log("Item 4 - click!"), true));

This is how it is implemented:

    public void ShowBottomMultiline(string label, params (string text, Action onClick, bool isWarning)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick, t.isWarning)).ToList();
        Show(DialogType.Bottom, label, null, contents);
    }

    public void ShowBottomMultiline(string label, params (string text, Action onClick)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick)).ToList();
        Show(DialogType.Bottom, label, null, contents);
    }

    public void ShowBottomMultiline(string label, bool canBeClosedByOutTap, params (string text, Action onClick, bool isWarning)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick, t.isWarning)).ToList();
        Show(DialogType.Bottom, label, null, contents, canBeClosedByOutTap);
    }

    public void ShowBottomMultiline(string label, bool canBeClosedByOutTap, params (string text, Action onClick)[] buttonContents)
    {
        var contents = buttonContents.Select(t => new DialogButtonContent(t.text, t.onClick)).ToList();
        Show(DialogType.Bottom, label, null, contents, canBeClosedByOutTap);
    }

bottom_m

  • Bottom InputField

Display an input box and two buttons in a bottom curtain.

The description parameter will be displayed as placeholder.

The canBeClosedByOutTap parameter indicates whether the window can be closed when clicking outside the dialogue box boundary.

    RootView_v2.Instance.dialog.ShowBottomInputField(
        "Bottom Multiline Dialog Test!",
        "Description",
        "Left", t => Debug.Log($"Item Left - click! Text: {t}"),
        "Right", t => Debug.Log($"Item Right - click! Text: {t}"));
        isCanBeClosedByOutTap);

This is how it is implemented:

    public void ShowBottomInputField(string label, string description, string textLeft, Action<string> onClickLeft, string textRight, Action<string> onClickRight, bool canBeClosedByOutTap = false)
    {
        var contents = new List<DialogButtonContent> { new DialogButtonContent(textLeft, onClickLeft), new DialogButtonContent(textRight, onClickRight) };
        Show(DialogType.BottomInputField, label, description, contents, canBeClosedByOutTap);
    }

bottom_i

You can see an example of Dialog operation in the DialogTest scene.