示例#1
0
    private void AskForSiteName(string title, string text, UnityAction <string> callback)
    {
        var popup = dialogManager.NewPopupDialog();

        popup.ShowInput(title, translator.Get("Site Name"));
        if (text != null)
        {
            popup.input.text = text;
        }
        popup.input.onValidateInput += GuiUtils.ValidateNameInput;
        popup.OnCloseDialog         += (result) => {
            if (result.action == DialogAction.Ok)
            {
                var newSiteName = popup.input.text.Trim();

                if (dataManager.sites.Exists((s) => s.Name.EqualsIgnoreCase(newSiteName) && !s.Name.EqualsIgnoreCase(text)))
                {
                    result.shouldClose = false;
                    dialogManager.Warn(translator.Get("This site already exists") + ":\n\n<b>" + newSiteName + "</b>");
                }
                else
                {
                    callback?.Invoke(newSiteName);
                }
            }
        };
    }
    //
    // Private Methods
    //

    private void AskForItemName(string title, Text name)
    {
        var popup = dialogManager.NewPopupDialog();

        popup.ShowInput(title, LocalizationManager.Instance.Get(LayerName, false));
        if (name != null)
        {
            popup.input.text = name.text;
        }
        popup.input.onValidateInput += GuiUtils.ValidateNameInput;
        popup.OnCloseDialog         += (result) => {
            if (result.action == DialogAction.Ok)
            {
                var newItemName = popup.input.text.Trim();
                name.text = newItemName;
            }
        };
    }