コード例 #1
0
        public new void Show()
        {
            #region THEME SETUP
            Themes.Theme theme = ThemeManager.Themes.ContainsKey(AppConfig.Instance.currentTheme ?? "") ? ThemeManager.Themes[AppConfig.Instance.currentTheme] : ThemeManager.Themes["Metro/LightGreen"];
            ThemeManager.Apply(theme);
            #endregion

            ImportAssetsForm iaf = new ImportAssetsForm();
            iaf.ShowDialog();

            Width     *= AppConfig.Instance.scale;
            Height    *= AppConfig.Instance.scale;
            MinWidth  *= AppConfig.Instance.scale;
            MinHeight *= AppConfig.Instance.scale;
            #region OPEN_WITH
            string[] args = Environment.GetCommandLineArgs();
            App.Logger.Log($"Command Line Args: {string.Join(";", args)}");
            if (args?.Length >= 2)
            {
                for (int k = 1; k < args.Length; k++)
                {
                    try
                    {
                        CurrentProject.file = args[k];
                        if (CurrentProject.Load(new NPCProject()))
                        {
                            App.NotificationManager.Clear();
                            App.NotificationManager.Notify(LocalizationManager.Current.Notification["Project_Loaded"]);
                            AddToRecentList(CurrentProject.file);
                            break;
                        }
                        else
                        {
                            CurrentProject.file = "";
                        }
                    }
                    catch { }
                }
            }
            #endregion
            #region APPAREL SETUP
            faceImageIndex.Maximum  = faceAmount - 1;
            beardImageIndex.Maximum = beardAmount - 1;
            hairImageIndex.Maximum  = haircutAmount - 1;
            //(CharacterEditor as CharacterEditor).FaceImageIndex_Changed(null, new RoutedPropertyChangedEventArgs<double?>(0, 0));
            //(CharacterEditor as CharacterEditor).HairImageIndex_Changed(null, new RoutedPropertyChangedEventArgs<double?>(0, 0));
            //(CharacterEditor as CharacterEditor).BeardImageIndex_Changed(null, new RoutedPropertyChangedEventArgs<double?>(0, 0));
            #endregion
            RefreshRecentList();
            #region AFTER UPDATE
            try
            {
                string updaterPath = Path.Combine(AppConfig.Directory, "updater.exe");
                if (File.Exists(updaterPath))
                {
                    OpenPatchNotes();
                    File.Delete(updaterPath);
                    App.Logger.Log("Updater deleted.");
                }
            }
            catch { App.Logger.Log("Can't delete updater.", ELogLevel.WARNING); }
            #endregion
            #region AUTOSAVE INIT
            if (AppConfig.Instance.autosaveOption > 0)
            {
                AutosaveTimer = new DispatcherTimer();
                switch (AppConfig.Instance.autosaveOption)
                {
                case 1:
                    AutosaveTimer.Interval = new TimeSpan(0, 5, 0);
                    break;

                case 2:
                    AutosaveTimer.Interval = new TimeSpan(0, 10, 0);
                    break;

                case 3:
                    AutosaveTimer.Interval = new TimeSpan(0, 15, 0);
                    break;

                case 4:
                    AutosaveTimer.Interval = new TimeSpan(0, 30, 0);
                    break;

                case 5:
                    AutosaveTimer.Interval = new TimeSpan(1, 0, 0);
                    break;
                }
                AutosaveTimer.Tick += AutosaveTimer_Tick;
                AutosaveTimer.Start();
            }
            #endregion
            #region AppUpdate
            AppUpdateTimer = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 1)
            };
            AppUpdateTimer.Tick += AppUpdateTimer_Tick;
            AppUpdateTimer.Start();
            #endregion
            #region VERSION SPECIFIC CODE
#if !DEBUG
            debugOverlayText.Visibility = Visibility.Collapsed;
#endif
#if PREVIEW
            previewOverlayText.Visibility = Visibility.Visible;
#endif
            #endregion
            #region DISCORD
            DiscordManager = new DiscordRPC.DiscordManager(1000)
            {
                descriptive = AppConfig.Instance.enableDiscord
            };
            DiscordManager?.Initialize();
            MainWindowViewModel.TabControl_SelectionChanged(mainTabControl, null);
            #endregion
            #region ENABLE EXPERIMENTAL
            if (AppConfig.Instance.experimentalFeatures)
            {
            }
            #endregion
            #region CONTEXT MENUS

            #endregion
            HolidayManager.Check();
            if (App.Package.Guides.Count > 0)
            {
                foreach (KeyValuePair <string, string> guide in App.Package.Guides)
                {
                    guidesMenuItem.Items.Add(new MenuItem()
                    {
                        Header  = guide.Key,
                        Command = new BaseCommand(() =>
                        {
                            System.Diagnostics.Process.Start(guide.Value);
                        })
                    });
                }
            }
            else
            {
                guidesMenuItem.IsEnabled = false;
            }

            if (string.IsNullOrEmpty(App.Package.GetTemplatesURL))
            {
                getTemplatesMenuItem.IsEnabled = false;
            }
            else
            {
                getTemplatesMenuItem.Click += (sender, e) =>
                {
                    Process.Start(App.Package.GetTemplatesURL);
                };
            }

            if (App.Package.FeedbackLinks.Length > 0)
            {
                foreach (Data.AppPackage.FeedbackLink link in App.Package.FeedbackLinks)
                {
                    MenuItem newItem = new MenuItem()
                    {
                        Header  = link.Localize ? LocalizationManager.Current.Interface[link.Text] : link.Text,
                        Command = new BaseCommand(() =>
                        {
                            System.Diagnostics.Process.Start(link.URL);
                        })
                    };
                    if (!string.IsNullOrEmpty(link.Icon))
                    {
                        try
                        {
                            newItem.Icon = new Image()
                            {
                                Width  = 16,
                                Height = 16,
                                Source = new BitmapImage(new Uri(link.Icon))
                            };
                        }
                        catch (Exception ex)
                        {
                            App.Logger.LogException("Could not load feedback icon", ex: ex);
                        }
                    }
                    commMenuItem.Items.Add(newItem);
                }
            }
            else
            {
                commMenuItem.IsEnabled = false;
            }

            try
            {
                foreach (Data.AppPackage.Notification n in App.Package.Notifications)
                {
                    string text = n.Localize ? LocalizationManager.Current.Notification.Translate(n.Text) : n.Text;

                    List <Button> _buttons = new List <Button>();

                    foreach (Data.AppPackage.Notification.Button b in n.Buttons)
                    {
                        string bText = b.Localize ? LocalizationManager.Current.Notification.Translate(b.Text) : b.Text;

                        Button elem = new Button()
                        {
                            Content = new TextBlock()
                            {
                                Text = bText
                            }
                        };
                        elem.Click += (_, __) => b.GetButtonAction().Invoke();

                        _buttons.Add(elem);
                    }

                    App.NotificationManager.Notify(text, buttons: _buttons.ToArray());
                }
            }
            catch (Exception ex)
            {
                App.Logger.LogException("Could not display notification(s)", ex: ex);
            }

            if (App.Package.Patrons.Length > 0)
            {
                var pList = App.Package.Patrons.ToList();
                pList.Shuffle();
                string pjoined = string.Join(", ", pList.Take(5));

                App.NotificationManager.Notify(LocalizationManager.Current.Notification.Translate("StartUp_Patreon_Patrons", pjoined));
            }

            ConsoleLogger.StartWaitForInput();

            Loaded += (sender, e) =>
            {
                var scr = ScreenHelper.GetCurrentScreen(this);

                var sz = scr.Size;

                if (sz.Width < MinWidth || sz.Height < MinHeight)
                {
                    var res = MessageBox.Show(LocalizationManager.Current.Interface["Warning_Scale"], Title, MessageBoxButton.YesNo);

                    if (res == MessageBoxResult.Yes)
                    {
                        MinWidth  /= AppConfig.Instance.scale;
                        MinHeight /= AppConfig.Instance.scale;
                        Width     /= AppConfig.Instance.scale;
                        Height    /= AppConfig.Instance.scale;

                        this.Left = (sz.Width - Width) / 2 + sz.Left;
                        this.Top  = (sz.Height - Height) / 2 + sz.Top;

                        Application.Current.Resources["Scale"] = 1.0;

                        AppConfig.Instance.scale = 1.0;

                        AppConfig.Instance.Save();
                    }
                }

                if (GameAssetManager.HasImportedAssets)
                {
                    if (!File.Exists(Path.Combine(AppConfig.Instance.unturnedDir, "Extras", "Icons", "Bag_MRE_81.png")))
                    {
                        MessageBox.Show(LocalizationManager.Current.Notification["StartUp_IconsNotGenerated"], Title, MessageBoxButton.OK);
                    }
                }
            };

            base.Show();
        }