Example #1
0
        public void SafeWrite <T>(T obj, string path)
        {
#if UNITY_EDITOR
            Debug.Log($"SafeWrite {obj:GetType()} {path}");
#endif

            try
            {
                var oldPath = path + ".old";
                if (File.Exists(path))
                {
                    File.Delete(oldPath);     // no exception if not exist
                    File.Move(path, oldPath); // exception if exists
                }

                using (var fs = File.OpenWrite(path)) // overwrite if needed
                {
                    Write(obj, fs);                   // May be interrupted
                }

                File.Delete(oldPath);
            }
            catch (Exception e)
            {
                // If there is some problem with Alert.Show, we need to avoid infinite recursion
                if (alertOnSafeWriteFail)
                {
                    alertOnSafeWriteFail = false;
                    Alert.Show(I18n.__("bookmark.save.fail"), e.Message);
                }

                throw;
            }
        }
Example #2
0
        public override void Show(Action onFinish)
        {
            base.Show(() =>
            {
                viewManager.dialoguePanel.SetActive(false);
                viewManager.StopAllAnimations();
                gameState.ResetGameState();

                if (bgmController != null && !string.IsNullOrEmpty(bgmName))
                {
                    bgmController.scriptVolume = bgmVolume;
                    bgmController.Play(bgmName);
                }

                var reachedChapterCount = gameState.GetAllStartupNodeNames()
                                          .Count(name => checkpointManager.IsReachedForAnyVariables(name, 0) != null);
                if (reachedChapterCount > 1 && configManager.GetInt(ChapterFirstUnlockedKey) == 0)
                {
                    Alert.Show(I18n.__("title.first.selectchapter"));
                    configManager.SetInt(ChapterFirstUnlockedKey, 1);
                }

                onFinish?.Invoke();
            });
        }
Example #3
0
 private void LoadBookmark(int saveId)
 {
     alertController.Alert(
         null,
         I18n.__("bookmark.load.confirm", SaveIdToDisplayId(saveId)),
         () => _loadBookmark(saveId)
         );
 }
Example #4
0
 private void DeleteBookmark(int saveId)
 {
     alertController.Alert(
         null,
         I18n.__("bookmark.delete.confirm", SaveIdToDisplayId(saveId)),
         () => _deleteBookmark(saveId)
         );
 }
Example #5
0
 private void SaveBookmark(int saveId)
 {
     alertController.Alert(
         null,
         I18n.__("bookmark.overwrite.confirm", SaveIdToDisplayId(saveId)),
         () => _saveBookmark(saveId)
         );
 }
Example #6
0
        private DialogueDisplayData GetPreviewDisplayData()
        {
            var displayNames =
                I18n.SupportedLocales.ToDictionary(x => x, x => I18n.__(x, "config.textpreview.name"));
            var dialogues =
                I18n.SupportedLocales.ToDictionary(x => x, x => I18n.__(x, TextPreviewKeys[textPreviewIndex]));

            return(new DialogueDisplayData("Preview", displayNames, dialogues));
        }
Example #7
0
 private void ShowPreviewScreen()
 {
     ShowPreview(screenSprite, I18n.__(
                     "bookmark.summary",
                     DateTime.Now.ToString(dateTimeFormat),
                     currentNodeName,
                     currentDialogueText
                     ));
 }
Example #8
0
 public static void QuitWithConfirm()
 {
     Alert.Show(
         null,
         I18n.__("ingame.exit.confirm"),
         Quit,
         null,
         "QuitConfirm"
         );
 }
 private void UpdateText()
 {
     if (!inited)
     {
         return;
     }
     contentBox.pageToDisplay = 1;
     content       = I18n.__(displayData.dialogues);
     characterName = I18n.__(displayData.displayNames);
 }
Example #10
0
        private void ShowPreviewBookmark(int saveId)
        {
            Bookmark bookmark = checkpointManager[saveId];

            ShowPreview(GetThumbnailSprite(saveId), I18n.__(
                            "bookmark.summary",
                            checkpointManager.SaveSlotsMetadata[saveId].ModifiedTime.ToString(dateTimeFormat),
                            bookmark.NodeHistory.Last(),
                            bookmark.Description
                            ));
        }
Example #11
0
 private void ResetDefault()
 {
     Alert.Show(null, I18n.__("config.alert.resetdefault"), () =>
     {
         configManager.ResetToDefault();
         inputMappingController.ResetDefault();
         configManager.Apply();
         inputMappingController.Apply();
         I18n.CurrentLocale = Application.systemLanguage;
     });
 }
Example #12
0
        private void UpdateFullScreenStatus(bool to)
        {
            if (Application.isMobilePlatform)
            {
                return;
            }

            // Debug.LogFormat("Full screen status changing from {0} (logical {1}) to {2}", Screen.fullScreen, isLogicalFullScreen, to);
            if (isLogicalFullScreen == to)
            {
                return;
            }

            isLogicalFullScreen = to;
            if (to)
            {
                configManager.SetInt(LastWindowedWidthKey, Screen.width);
                configManager.SetInt(LastWindowedHeightKey, Screen.height);
                Screen.SetResolution(
                    Screen.currentResolution.width,
                    Screen.currentResolution.height,
                    FullScreenMode.FullScreenWindow
                    );
            }
            else
            {
                var targetW = configManager.GetInt(LastWindowedWidthKey);
                var targetH = configManager.GetInt(LastWindowedHeightKey);
                if (targetW == 0 || targetH == 0)
                {
                    if (Screen.resolutions.Length == 0)
                    {
                        targetW = 1280;
                        targetH = 720;
                    }
                    else
                    {
                        var defaultResolution = Screen.resolutions[Screen.resolutions.Length / 2];
                        targetW = defaultResolution.width;
                        targetH = defaultResolution.height;
                    }
                }

                Screen.SetResolution(targetW, targetH, FullScreenMode.Windowed);

                if (configManager.GetInt(ChangeWindowSizeFirstShownKey) == 0)
                {
                    Alert.Show(I18n.__("config.changewindowsize"));
                    configManager.SetInt(ChangeWindowSizeFirstShownKey, 1);
                }
            }
        }
Example #13
0
        protected override void OnActivatedUpdate()
        {
            base.OnActivatedUpdate();

            if (Utils.GetKeyDownInEditor(KeyCode.LeftShift))
            {
                foreach (var chapter in buttons)
                {
                    chapter.Value.GetComponent <Button>().enabled = true;
                    chapter.Value.GetComponent <Text>().text      = I18n.__(gameState.GetNode(chapter.Key).displayNames);
                }
            }
        }
Example #14
0
        /// <summary>
        /// Show log panel
        /// </summary>
        public override void Show(Action onFinish)
        {
            if (configManager.GetInt(LogViewFirstShownKey) == 0)
            {
                Alert.Show(I18n.__("log.first.hint"));
                configManager.SetInt(LogViewFirstShownKey, 1);
            }

            scrollRect.verticalNormalizedPosition = 0.0f;
            base.Show(onFinish);
            scrollRect.verticalNormalizedPosition = 0.0f;
            lastClickedLogIndex = -1;
        }
Example #15
0
 private void ResetDefault()
 {
     Alert.Show(null, I18n.__("config.alert.resetdefault"), () =>
     {
         configManager.ResetToDefault();
         inputMappingController.ResetDefault();
         configManager.Apply();
         // error will occur if reset default button is clicked before the InputMappingController starts
         // as the InputMappingController will reload data from current InputMapping, which will not get
         // updated unless the apply method get called.
         inputMappingController.Apply();
     });
 }
Example #16
0
 public void QuickLoadBookmark()
 {
     if (checkpointManager.SaveSlotsMetadata.Values.Where(
             m => m.SaveId >= (int)BookmarkType.QuickSave && m.SaveId < (int)BookmarkType.QuickSave + maxSaveEntry
             ).Any())
     {
         alertController.Alert(null, I18n.__("bookmark.quickload.confirm"), () => _quickLoadBookmark());
     }
     else
     {
         alertController.Alert(null, I18n.__("bookmark.quickload.nosave"));
     }
 }
Example #17
0
        public string FormatNameDialogue()
        {
            var name     = I18n.__(displayNames);
            var dialogue = I18n.__(dialogues);

            if (string.IsNullOrEmpty(name))
            {
                return(dialogue);
            }
            else
            {
                return(string.Format(I18n.__("format.namedialogue"), name, dialogue));
            }
        }
Example #18
0
 /// <summary>
 /// Execute the action stored in this dialogue entry
 /// </summary>
 public void ExecuteAction()
 {
     if (action != null)
     {
         try
         {
             action.Call();
         }
         catch (LuaException ex)
         {
             throw new Exceptions.ScriptActionException(
                       $"Nova: Exception occurred when executing action: {I18n.__(dialogues)}", ex);
         }
     }
 }
Example #19
0
 /// <summary>
 /// Execute the action stored in this dialogue entry.
 /// </summary>
 public void ExecuteAction(DialogueActionStage stage, bool isRestoring)
 {
     if (actions.TryGetValue(stage, out var action))
     {
         LuaRuntime.Instance.UpdateExecutionContext(new ExecutionContext(ExecutionMode.Lazy, stage, isRestoring));
         try
         {
             action.Call();
         }
         catch (LuaException e)
         {
             throw new ScriptActionException(
                       $"Nova: Exception occurred when executing action: {I18n.__(dialogues)}", e);
         }
     }
 }
Example #20
0
 private void UpdateAllButtons()
 {
     foreach (var chapter in buttons)
     {
         if (unlockAllChaptersForDebug || checkpointManager.IsReachedForAnyVariables(chapter.Key, 0) != null)
         {
             chapter.Value.GetComponent <Button>().enabled = true;
             chapter.Value.GetComponent <Text>().text      = I18nHelper.NodeNames.Get(chapter.Key);
         }
         else
         {
             chapter.Value.GetComponent <Button>().enabled = false;
             chapter.Value.GetComponent <Text>().text      = I18n.__("title.selectchapter.locked");
         }
     }
 }
Example #21
0
 private void UpdateAllButtons()
 {
     foreach (var chapter in buttons)
     {
         if (IsUnlocked(chapter.Key))
         {
             chapter.Value.GetComponent <Button>().enabled = true;
             chapter.Value.GetComponent <Text>().text      = I18n.__(gameState.GetNode(chapter.Key).displayNames);
         }
         else
         {
             chapter.Value.GetComponent <Button>().enabled = false;
             chapter.Value.GetComponent <Text>().text      = I18n.__("title.selectchapter.locked");
         }
     }
 }
Example #22
0
 private void OnGoBackButtonClicked(string nodeName, int dialogueIndex, int logEntryIndex, string variablesHash)
 {
     if (logEntryIndex == lastClickedLogIndex)
     {
         Alert.Show(
             null,
             I18n.__("log.back.confirm"),
             () => _onGoBackButtonClicked(nodeName, dialogueIndex, logEntryIndex, variablesHash),
             null,
             "LogBack"
             );
     }
     else
     {
         lastClickedLogIndex = logEntryIndex;
     }
 }
Example #23
0
 private void ReturnTitle()
 {
     if (fromTitle)
     {
         _returnTitle();
     }
     else
     {
         Alert.Show(
             null,
             I18n.__("ingame.title.confirm"),
             _returnTitle,
             null,
             "ReturnTitle"
             );
     }
 }
Example #24
0
 private void OnGoBackButtonClicked(NodeHistoryEntry nodeHistoryEntry, int dialogueIndex, int logEntryIndex)
 {
     if (logEntryIndex == lastClickedLogIndex)
     {
         Alert.Show(
             null,
             I18n.__("log.back.confirm"),
             () => _onGoBackButtonClicked(nodeHistoryEntry, dialogueIndex),
             null,
             "LogBack"
             );
     }
     else
     {
         lastClickedLogIndex = logEntryIndex;
     }
 }
Example #25
0
        private void UpdateText()
        {
            string str = I18n.__(inflateTextKey);

            if (textProxy != null)
            {
                textProxy.text = str;
            }
            else if (textPro != null)
            {
                textPro.text = str;
            }
            else
            {
                text.text = str;
            }
        }
Example #26
0
        private string GetDescription()
        {
            switch (controller.mode)
            {
            case MusicListMode.Sequential:
                return(I18n.__("bgmgallery.mode.seq"));

            case MusicListMode.SingleLoop:
                return(I18n.__("bgmgallery.mode.loop"));

            case MusicListMode.Random:
                return(I18n.__("bgmgallery.mode.rand"));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #27
0
        private void UpdateText()
        {
            if (displayTexts == null)
            {
                text.text = "";
            }
            else
            {
                text.text = I18n.__(displayTexts);
            }

            if (imageInfo != null)
            {
                // TODO: preload
                image.sprite = AssetLoader.Load <Sprite>(System.IO.Path.Combine(imageFolder, imageInfo.name));
                image.SetNativeSize();
            }
        }
Example #28
0
 private static string AbstractKeyDisplayName(AbstractKey key) =>
 I18n.__($"config.key.{Enum.GetName(typeof(AbstractKey), key)}");
Example #29
0
 private void ApplyInvalidMusicEntry()
 {
     audioSource.clip         = null;
     titleLabel.text          = I18n.__("musicgallery.title");
     progressBar.interactable = false;
 }
Example #30
0
 // Use this for initialization
 void Awake()
 {
     GetComponent <Text>().text = I18n.__(InflateTextKey);
 }