public OkCancelDialogViewModel(DialogButtonsType dialogButtonsType, string message) { DialogButtonsType = dialogButtonsType; Message = message; }
/// <summary> /// Show the dialog instance substituting in passed values and running any transitions. /// </summary> /// <param name="title"></param> /// <param name="titleKey"></param> /// <param name="text"></param> /// <param name="textKey"></param> /// <param name="text2"></param> /// <param name="text2Key"></param> /// <param name="sprite"></param> /// <param name="doneCallback"></param> /// <param name="destroyOnClose"></param> /// <param name="dialogButtons"></param> public void Show(string title = null, string titleKey = null, string text = null, string textKey = null, string text2 = null, string text2Key = null, Sprite sprite = null, Action <DialogInstance> doneCallback = null, bool destroyOnClose = true, DialogButtonsType dialogButtons = DialogButtonsType.Custom) { GameObject childGameObject; _dialogButtons = dialogButtons; DoneCallback = doneCallback; _destroyOnClose = destroyOnClose; // increase open count - not thread safe, but should be ok! Assert.IsTrue(DialogManager.IsActive, "Ensure that you have added a DialogManager component to your scene before showing a dialog!"); DialogManager.Instance.Count++; IsShown = true; // default result DialogResult = DialogResultType.Ok; if (titleKey != null) { title = LocaliseText.Get(titleKey); } if (title != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Title", title, true); } if (sprite != null) { UIHelper.SetSpriteOnChildGameObject(gameObject, "ph_Image", sprite, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Image", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (textKey != null) { text = LocaliseText.Get(textKey); } if (text != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text", text, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (text2Key != null) { text2 = LocaliseText.Get(text2Key); } if (text2 != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text2", text2, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text2", true); if (childGameObject != null) { childGameObject.SetActive(false); } } switch (_dialogButtons) { case DialogButtonsType.Ok: GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true).SetActive(true); break; case DialogButtonsType.OkCancel: GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true).SetActive(true); GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true).SetActive(true); break; case DialogButtonsType.Cancel: GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true).SetActive(true); break; case DialogButtonsType.YesNo: GameObjectHelper.GetChildNamedGameObject(gameObject, "YesButton", true).SetActive(true); GameObjectHelper.GetChildNamedGameObject(gameObject, "NoButton", true).SetActive(true); break; } // show / transition in and when done call coroutine float transitionTime = 0; Target.SetActive(true); #if BEAUTIFUL_TRANSITIONS //if (TransitionHelper.ContainsTransition(gameObject)) //{ transitionTime = TransitionHelper.GetTransitionInTime(TransitionHelper.TransitionIn(gameObject)); //} #endif StartCoroutine(CoRoutines.DelayedCallback(transitionTime, ShowFinished)); }
///// <summary> ///// Show the dialog instance substituting in passed values and running any transitions. ///// </summary> ///// <param name="title"></param> ///// <param name="text"></param> ///// <param name="text2"></param> ///// <param name="sprite"></param> ///// <param name="doneCallback"></param> ///// <param name="destroyOnClose"></param> ///// <param name="dialogButtons"></param> //public void Show(LocalisableText title, LocalisableText text, LocalisableText text2 = null, Sprite sprite = null, // Action<DialogInstance> doneCallback = null, bool destroyOnClose = true, // DialogButtonsType dialogButtons = DialogButtonsType.Custom) //{ // var tTitle = title == null ? null : title.GetValue(); // var tText = title == null ? null : text.GetValue(); // var tText2 = title == null ? null : text2.GetValue(); // Show(title: tTitle, text: tText, text2: tText2, sprite: sprite, doneCallback: doneCallback, destroyOnClose: destroyOnClose, dialogButtons: dialogButtons); //} /// <summary> /// Show the dialog instance substituting in passed values and running any transitions. /// </summary> /// <param name="title"></param> /// <param name="titleKey"></param> /// <param name="text"></param> /// <param name="textKey"></param> /// <param name="text2"></param> /// <param name="text2Key"></param> /// <param name="sprite"></param> /// <param name="doneCallback"></param> /// <param name="destroyOnClose"></param> /// <param name="dialogButtons"></param> /// <param name="buttonText"></param> public void Show(string title = null, string titleKey = null, string text = null, string textKey = null, string text2 = null, string text2Key = null, Sprite sprite = null, Action <DialogInstance> doneCallback = null, bool destroyOnClose = true, DialogButtonsType dialogButtons = DialogButtonsType.Custom, LocalisableText[] buttonText = null) { GameObject childGameObject; _dialogButtons = dialogButtons; DoneCallback = doneCallback; _destroyOnClose = destroyOnClose; // increase open count - not thread safe, but should be ok! Assert.IsTrue(DialogManager.IsActive, "Ensure that you have added a DialogManager component to your scene before showing a dialog!"); DialogManager.Instance.Count++; IsShown = true; // default result DialogResult = DialogResultType.Ok; if (!string.IsNullOrEmpty(titleKey)) { title = GlobalLocalisation.GetText(titleKey); } if (title != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Title", title, true); } if (sprite != null) { UIHelper.SetSpriteOnChildGameObject(gameObject, "ph_Image", sprite, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Image", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (!string.IsNullOrEmpty(textKey)) { text = GlobalLocalisation.GetText(textKey); } if (text != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text", text, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text", true); if (childGameObject != null) { childGameObject.SetActive(false); } } if (!string.IsNullOrEmpty(text2Key)) { text2 = GlobalLocalisation.GetText(text2Key); } if (text2 != null) { UIHelper.SetTextOnChildGameObject(gameObject, "ph_Text2", text2, true); } else { childGameObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "ph_Text2", true); if (childGameObject != null) { childGameObject.SetActive(false); } } GameObject okButton, cancelButton; switch (_dialogButtons) { case DialogButtonsType.Ok: okButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true); if (okButton != null) { okButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using Ok buttons, ensure the Dialog a GameObject named OkButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Ok")); button.GetComponent <Button>().onClick.AddListener(() => DoneOk()); } break; case DialogButtonsType.OkCancel: okButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "OkButton", true); cancelButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true); if (okButton != null && cancelButton != null) { okButton.SetActive(true); cancelButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using OkCancel buttons, ensure the Dialog has GameObjects named OkButton and CancelButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Ok")); button.GetComponent <Button>().onClick.AddListener(() => DoneOk()); button = CreateTextButton(LocalisableText.CreateLocalised("Button.Cancel")); button.GetComponent <Button>().onClick.AddListener(() => DoneCancel()); } break; case DialogButtonsType.Cancel: cancelButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "CancelButton", true); if (cancelButton != null) { cancelButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using a Cancel button, ensure the Dialog a GameObject named CancelButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Cancel")); button.GetComponent <Button>().onClick.AddListener(() => DoneCancel()); } break; case DialogButtonsType.YesNo: var yesButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "YesButton", true); var noButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "NoButton", true); if (yesButton != null && noButton != null) { yesButton.SetActive(true); noButton.SetActive(true); } else { Assert.IsNotNull(_textTemplateButton, "If using YesNo buttons, ensure the Dialog has GameObjects named YesButton and NoButton or a GameObject named TextButton that is a template for text buttons"); var button = CreateTextButton(LocalisableText.CreateLocalised("Button.Yes")); button.GetComponent <Button>().onClick.AddListener(() => DoneYes()); button = CreateTextButton(LocalisableText.CreateLocalised("Button.No")); button.GetComponent <Button>().onClick.AddListener(() => DoneNo()); } break; case DialogButtonsType.Text: Assert.IsNotNull(_textTemplateButton, "If using Text buttons, ensure the Dialog has a GameObject named TextButton that is a template for text buttons"); Assert.IsNotNull(buttonText, "If using Text buttons, ensure you pass a valid array of localisable texts into the show method."); var counter = 0; foreach (var localisableText in buttonText) { var button = CreateTextButton(localisableText); var counter1 = counter; button.GetComponent <Button>().onClick.AddListener(() => DoneCustom(counter1)); counter++; } break; } // show / transition in and when done call coroutine float transitionTime = 0; Target.SetActive(true); #if BEAUTIFUL_TRANSITIONS //if (TransitionHelper.ContainsTransition(gameObject)) //{ transitionTime = TransitionHelper.GetTransitionInTime(TransitionHelper.TransitionIn(gameObject)); //} #endif StartCoroutine(CoRoutines.DelayedCallback(transitionTime, ShowFinished)); }
public Speak(string Id, string PlayerGameItemId, string content, DialogButtonsType dialogType) : base(Id, PlayerGameItemId) { Content = content; DialogType = dialogType; }