protected virtual GameObject createButtonObject(DPrompt data, int buttonIndex, DPrompt.ButtonFlags flag, ref string i18nText) { GameObject prefab = Buttons[buttonIndex].Prefab; if (data.CustomButtons != null) { for (int i = 0; i < data.CustomButtons.Length; i++) { CustomButtonDefinition customButtonDefinition = data.CustomButtons[i]; if ((customButtonDefinition.ButtonFlags & flag) == flag) { if (customButtonDefinition.ButtonDefinition.Prefab != null) { prefab = customButtonDefinition.ButtonDefinition.Prefab; } if (!string.IsNullOrEmpty(customButtonDefinition.ButtonDefinition.i18nText)) { i18nText = customButtonDefinition.ButtonDefinition.i18nText; } } } } GameObject gameObject = UnityEngine.Object.Instantiate(prefab); gameObject.transform.SetParent(ButtonParent, worldPositionStays: false); return(gameObject); }
public void ShowFatal(string type, string format, params object[] args) { DPrompt.ButtonFlags buttons = DPrompt.ButtonFlags.None; DPrompt data = new DPrompt(type, string.Format(format, args), buttons); ShowPrompt(data, null, FatalPrefab); }
private void updateTextFields(DPrompt data) { Localizer localizer = Service.Get <Localizer>(); int num = TextFields.Length; for (int i = 0; i < num; i++) { TextDefinition textDefinition = TextFields[i]; if (data.TextFields.TryGetValue(textDefinition.Key, out var value)) { if (value.IsTranslated) { textDefinition.Text.text = value.I18nText; } else { textDefinition.Text.text = localizer.GetTokenTranslation(value.I18nText); } } bool flag = !string.IsNullOrEmpty(textDefinition.Text.text); OnOffGameObjectSelector component = textDefinition.Text.gameObject.GetComponent <OnOffGameObjectSelector>(); if (component != null) { component.IsOn = flag; } else { textDefinition.Text.gameObject.SetActive(flag); } } }
private static void onOptionalUpgradeIconLoaded(string path, Sprite icon) { DPrompt data = new DPrompt("GlobalUI.Prompts.UpgradeAvailable.Title", "GlobalUI.Prompts.UpgradeAvailable", DPrompt.ButtonFlags.NO | DPrompt.ButtonFlags.YES, icon, isModal: true, autoClose: false); Service.Get <ICPSwrveService>().Action("upgrade_prompt", "view"); Service.Get <PromptManager>().ShowPrompt(data, onOptionalUpgradePromptClosed); }
private static void onBlockPlayerProgressIconLoaded(string path, Sprite icon) { DPrompt data = new DPrompt("GlobalUI.ErrorMessages.QuitGame.Title", "GlobalUI.ErrorMessages.QuitGame.Description\n\n", DPrompt.ButtonFlags.None, icon, isModal: true, autoClose: false); Service.Get <ICPSwrveService>().Error("forcedupgrade_prompt", "block_progress", null, SceneManager.GetActiveScene().name); Service.Get <PromptManager>().ShowPrompt(data, onBlockPlayerProgressPromptClosed); }
private IEnumerator loadPrompt() { DPrompt.ButtonFlags buttonFlags = DPrompt.ButtonFlags.None; for (int j = 0; j < PromptDefinition.Buttons.Length; j++) { buttonFlags |= PromptDefinition.Buttons[j]; } Sprite image = null; if (!string.IsNullOrEmpty(PromptDefinition.SpriteContentKey.Key)) { AssetRequest <Sprite> spriteRequest = Content.LoadAsync(PromptDefinition.SpriteContentKey); yield return(spriteRequest); image = spriteRequest.Asset; } if (!string.IsNullOrEmpty(PromptDefinition.PrefabContentKey.Key)) { AssetRequest <GameObject> prefabRequest = Content.LoadAsync(PromptDefinition.PrefabContentKey); yield return(prefabRequest); if ((bool)prefabRequest.Asset.GetComponent <PromptController>()) { Prefab = prefabRequest.Asset.GetComponent <PromptController>(); } } string titleText2 = PromptDefinition.i18nTitleText; string bodyText2 = PromptDefinition.i18nBodyText; bool translate = !string.IsNullOrEmpty(titleTextInsert) || !string.IsNullOrEmpty(bodyTextInsert); Localizer localizer = Service.Get <Localizer>(); string titleDesktopText = $"{titleText2}.Desktop"; string bodyDesktopText = $"{bodyText2}.Desktop"; titleText2 = (localizer.tokens.ContainsKey(titleDesktopText) ? titleDesktopText : titleText2); bodyText2 = (localizer.tokens.ContainsKey(bodyDesktopText) ? bodyDesktopText : bodyText2); if (translate) { titleText2 = (string.IsNullOrEmpty(titleTextInsert) ? localizer.GetTokenTranslation(titleText2) : string.Format(localizer.GetTokenTranslation(titleText2), titleTextInsert)); bodyText2 = (string.IsNullOrEmpty(bodyTextInsert) ? localizer.GetTokenTranslation(bodyText2) : string.Format(localizer.GetTokenTranslation(bodyText2), bodyTextInsert)); } _promptData = new DPrompt(titleText2, bodyText2, buttonFlags, image, PromptDefinition.IsModal, PromptDefinition.AutoClose, translate, PromptDefinition.UseCloseButton); List <PromptController.CustomButtonDefinition> customButtons = new List <PromptController.CustomButtonDefinition>(PromptDefinition.CustomButtonKeys.Length); for (int i = 0; i < PromptDefinition.CustomButtonKeys.Length; i++) { AssetRequest <CustomButton> request = Content.LoadAsync(PromptDefinition.CustomButtonKeys[i]); yield return(request); if (request.Asset != null) { customButtons.Add(request.Asset.Definition); } } _promptData.CustomButtons = customButtons.ToArray(); if (onCompleteHandler != null) { onCompleteHandler(this); } }
private static void onForcedUpgradeIconLoaded(string path, Sprite icon) { DPrompt data = new DPrompt("LauncherUI.Note.NeedUpdate", "GlobalUI.ErrorMessages.Update", DPrompt.ButtonFlags.OK, icon, isModal: true, autoClose: false); Service.Get <ICPSwrveService>().Error("forcedupgrade_prompt", "upgrade_needed", null, SceneManager.GetActiveScene().name); Service.Get <ICPSwrveService>().Action("upgrade_prompt", "view"); Service.Get <PromptManager>().ShowPrompt(data, onForcedUpgradePromptClosed); }
private void onIconLoaded(string path, Sprite icon) { DPrompt data = new DPrompt("GlobalUI.IAPWarning.Apple.Title", "GlobalUI.IAPWarning.Apple.Body", DPrompt.ButtonFlags.OK, icon); Service.Get <EventDispatcher>().DispatchEvent(default(ShowInAppPurchaseDisclaimerEvent)); Service.Get <PromptManager>().ShowPrompt(data, onButtonClicked); Service.Get <ICPSwrveService>().Action("purchase_disclaimer", "viewed"); }
protected override GameObject createButtonObject(DPrompt data, int buttonIndex, DPrompt.ButtonFlags flag, ref string i18nText) { if (flag == DPrompt.ButtonFlags.CLOSE) { closeButton.SetActive(value: true); return(closeButton); } return(base.createButtonObject(data, buttonIndex, flag, ref i18nText)); }
public void ShowPrompt() { if (UsePromptDefinitionKey != null && !string.IsNullOrEmpty(UsePromptDefinitionKey.Id)) { Service.Get <PromptManager>().ShowPrompt(UsePromptDefinitionKey.Id, onButtonPressed); } else { if (isLoadingPrefab) { return; } isLoadingPrefab = true; DPrompt.ButtonFlags buttonFlags = DPrompt.ButtonFlags.None; if (OkButton) { buttonFlags |= DPrompt.ButtonFlags.OK; } if (CancelButton) { buttonFlags |= DPrompt.ButtonFlags.CANCEL; } if (YesButton) { buttonFlags |= DPrompt.ButtonFlags.YES; } if (NoButton) { buttonFlags |= DPrompt.ButtonFlags.NO; } if (CloseButton) { buttonFlags |= DPrompt.ButtonFlags.CLOSE; } if (!string.IsNullOrEmpty(SwrveLogTier1)) { Service.Get <ICPSwrveService>().Action(SwrveLogTier1, SwrveLogTier2); } DPrompt data = default(DPrompt); ref DPrompt reference = ref data; reference = new DPrompt(TitleToken, BodyToken, buttonFlags, Image, IsModal, AutoClose, IsTranslated); if (PromptPrefabContentKey != null) { Content.LoadAsync(delegate(string path, GameObject prefab) { onPromptLoaded(data, prefab); }, PromptPrefabContentKey); } else { isLoadingPrefab = false; Service.Get <PromptManager>().ShowPrompt(data, onButtonPressed); } }
public void ExecuteImmediate() { DPrompt.ButtonFlags buttonFlags = DPrompt.ButtonFlags.None; for (int i = 0; i < PromptDefinition.Buttons.Length; i++) { buttonFlags |= PromptDefinition.Buttons[i]; } Sprite image = null; if (!string.IsNullOrEmpty(PromptDefinition.SpriteContentKey.Key)) { image = Content.LoadImmediate(PromptDefinition.SpriteContentKey); } if (!string.IsNullOrEmpty(PromptDefinition.PrefabContentKey.Key)) { PromptController component = Content.LoadImmediate(PromptDefinition.PrefabContentKey).GetComponent <PromptController>(); if (component != null) { Prefab = component; } } string i18nTitleText = PromptDefinition.i18nTitleText; string i18nBodyText = PromptDefinition.i18nBodyText; bool flag = !string.IsNullOrEmpty(titleTextInsert) || !string.IsNullOrEmpty(bodyTextInsert); Localizer localizer = Service.Get <Localizer>(); string text = $"{i18nTitleText}.Desktop"; string text2 = $"{i18nBodyText}.Desktop"; i18nTitleText = (localizer.tokens.ContainsKey(text) ? text : i18nTitleText); i18nBodyText = (localizer.tokens.ContainsKey(text2) ? text2 : i18nBodyText); if (flag) { i18nTitleText = (string.IsNullOrEmpty(titleTextInsert) ? localizer.GetTokenTranslation(i18nTitleText) : string.Format(localizer.GetTokenTranslation(i18nTitleText), titleTextInsert)); i18nBodyText = (string.IsNullOrEmpty(bodyTextInsert) ? localizer.GetTokenTranslation(i18nBodyText) : string.Format(localizer.GetTokenTranslation(i18nBodyText), bodyTextInsert)); } _promptData = new DPrompt(i18nTitleText, i18nBodyText, buttonFlags, image, PromptDefinition.IsModal, PromptDefinition.AutoClose, flag, PromptDefinition.UseCloseButton); List <PromptController.CustomButtonDefinition> list = new List <PromptController.CustomButtonDefinition>(PromptDefinition.CustomButtonKeys.Length); for (int i = 0; i < PromptDefinition.CustomButtonKeys.Length; i++) { CustomButton customButton = Content.LoadImmediate(PromptDefinition.CustomButtonKeys[i]); if (customButton != null) { list.Add(customButton.Definition); } } _promptData.CustomButtons = list.ToArray(); if (onCompleteHandler != null) { onCompleteHandler(this); } }
private void updateImages(DPrompt data) { int num = Images.Length; for (int i = 0; i < num; i++) { ImageDefinition imageDefinition = Images[i]; if (data.Images.TryGetValue(imageDefinition.Key, out var value) && value != null) { imageDefinition.Image.sprite = value; imageDefinition.Image.gameObject.SetActive(value: true); } } }
public GameObject ShowPrompt(DPrompt data, Action <DPrompt.ButtonFlags> callback, PromptController prefab = null) { if (prefab == null) { prefab = PromptPrefab; } GameObject gameObject = UnityEngine.Object.Instantiate(prefab.gameObject); gameObject.transform.SetParent(base.transform, worldPositionStays: false); PromptController component = gameObject.GetComponent <PromptController>(); component.ShowPrompt(data, callback); if (PromptCreated != null) { PromptCreated(gameObject); } return(gameObject); }
public override IEnumerator Execute(ScriptableActionPlayer player) { DPrompt.ButtonFlags buttonFlags = DPrompt.ButtonFlags.None; for (int i = 0; i < Options.Length; i++) { buttonFlags = (DPrompt.ButtonFlags)((int)buttonFlags | (1 << (int)Options[i].Button)); } DPrompt data = new DPrompt(i18nTitleText, i18nBodyText, buttonFlags); Action <DPrompt.ButtonFlags> clickHandler = delegate(DPrompt.ButtonFlags pressed) { onClick(pressed, player); }; Service.Get <PromptManager>().ShowPrompt(data, clickHandler); while (!player.ActionIsFinished) { yield return(null); } }
public void ShowPrompt(DPrompt data, Action <DPrompt.ButtonFlags> callback) { localizer = Service.Get <Localizer>(); GameObject gameObject = GameObject.FindGameObjectWithTag(UIConstants.Tags.UI_Tray_Root); if (gameObject != null) { stateMachineContext = gameObject.GetComponent <StateMachineContext>(); if (stateMachineContext != null && stateMachineContext.ContainsStateMachine("Root")) { stateMachineContext.SendEvent(new ExternalEvent("Root", "popup_open")); } } updateTextFields(data); updateImages(data); ModalBackground component = GetComponent <ModalBackground>(); component.enabled = data.IsModal; if (data.UseCloseButton) { if (CloseButton != null) { CloseButton.SetActive(value: true); ButtonClickListener component2 = CloseButton.GetComponent <ButtonClickListener>(); component2.OnClick.AddListener(onButtonClicked); } else { Log.LogError(this, "CloseButton is null, cannot activate it"); } } ButtonClickListener btnAccept = null; ButtonClickListener btnCancel = null; for (int i = 0; i < Buttons.Length; i++) { createButton(data, i, callback, ref btnAccept, ref btnCancel); } inputHandler.Initialize(btnAccept, btnCancel); playAccessibilityText(); }
protected virtual void createButton(DPrompt data, int buttonIndex, Action <DPrompt.ButtonFlags> callback, ref ButtonClickListener btnAccept, ref ButtonClickListener btnCancel) { DPrompt.ButtonFlags flag = (DPrompt.ButtonFlags)(1 << buttonIndex); if ((data.Buttons & flag) != flag) { return; } string i18nText = Buttons[buttonIndex].i18nText; GameObject gameObject = createButtonObject(data, buttonIndex, flag, ref i18nText); if (!string.IsNullOrEmpty(i18nText)) { Text componentInChildren = gameObject.GetComponentInChildren <Text>(); if (componentInChildren != null) { componentInChildren.text = localizer.GetTokenTranslation(i18nText); } } ButtonClickListener component = gameObject.GetComponent <ButtonClickListener>(); if (!(component != null)) { return; } if (isBackButton(flag)) { btnCancel = component; } else { btnAccept = component; } if (callback != null) { component.OnClick.AddListener(delegate { callback(flag); }); } component.OnClick.AddListener(onButtonClicked); }
private void createConfirmationPrompt(string titleText, string bodyText, Action <DPrompt.ButtonFlags> callback) { DPrompt data = new DPrompt(titleText, bodyText, DPrompt.ButtonFlags.NO | DPrompt.ButtonFlags.YES); Service.Get <PromptManager>().ShowPrompt(data, callback); }
public GameObject ShowError(string type, string message, Action <DPrompt.ButtonFlags> callback = null) { DPrompt data = new DPrompt(type, message, DPrompt.ButtonFlags.CLOSE); return(ShowPrompt(data, callback, ErrorPrefab)); }