private void VmTheme_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedAccentColor" || e.PropertyName == "SelectedThemeMode") { tm.Apply(SelectedAccentColor, SelectedThemeMode); SelectedAccentColor = (Color)Application.Current.Resources["AccentColor"]; //AsyncSaveTheme(); } }
public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container) : base(container) { regionManager.RegisterViewWithRegion("TopbarRegion", () => container.Resolve(typeof(TopBar))); regionManager.RegisterViewWithRegion("ToolbarStripRegion", () => container.Resolve(typeof(ToolbarStrip))); EventAggregator.GetEvent <NotificationMessageEvent>().Subscribe(OnNotificationMessage, ThreadOption.UIThread); EventAggregator.GetEvent <ShowBusyIndicatorEvent>().Subscribe(OnShowBusyIndicator, ThreadOption.UIThread); EventAggregator.GetEvent <ShowBusyIndicatorWithProgressEvent>().Subscribe(OnShowBusyIndicatorWithProgress, ThreadOption.UIThread); EventAggregator.GetEvent <UpdateProgressEvent>().Subscribe(OnUpdateProgress, ThreadOption.UIThread); EventAggregator.GetEvent <ShowNotificationCenterEvent>().Subscribe(OnShowNotificationCenter, ThreadOption.UIThread); EventAggregator.GetEvent <PopupActiveEvent>().Subscribe(OnPopupActive, ThreadOption.UIThread); var eventAggregator = container.Resolve <IEventAggregator>(); eventAggregator.GetEvent <ThemeChangedEvent>().Subscribe(OnColorThemeChanged, ThreadOption.UIThread); _themeManager = new ThemeManager(); _themeManager.Apply("Cyan"); regionManager.RegisterViewWithRegion("ContentRegion", typeof(PlcView)); regionManager.RegisterViewWithRegion("ToolbarStripContentRegion", typeof(ToolbarStripContent)); EventAggregator.GetEvent <InitializeViewModelEvent>().Publish(typeof(PlcViewModel)); }
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(); }
protected override void OnInitialized(EventArgs eventArgs) { base.OnInitialized(eventArgs); try { instance = this; // Update the position and size of the window. UpdatePosition(); // Set the window as NO_ACTIVATE, TOOLWINDOW and TOPMOST, WindowStyles.SetExtended(this, WindowStyles.GetExtended(this) | ExtendedWindowStyle.WS_EX_NOACTIVATE | ExtendedWindowStyle.WS_EX_TOOLWINDOW | ExtendedWindowStyle.WS_EX_TOPMOST); // Apply the user-selected locale. IntlManager.Apply(new CultureInfo(AppState.Current.UserSettings.Locale)); // Apply the user-selected theme. ThemeManager.Apply(AppState.Current.UserSettings.Theme); // Initialize the drop shadow. _dropShadow = new WindowDropShadow(this) { Radius = 15.0, Strength = 2.0, Opacity = 0.0, }; // Set the window's view-model. _viewModel = new OverviewViewModel(); InitializeQuickInfoWindow(); // Request the needed window permissions. (>= Windows 8) _clipboardPermission = new UIPermission(PermissionState.Unrestricted) { Clipboard = UIPermissionClipboard.AllClipboard }; // Setup the clipboard manager and the according event listeners. _clipboardManager = new ClipboardManager(this); _clipboardManager.StateChanged += OnClipboardStateChanged; // Initially hidden. _isVisible = false; _transitions = new TaskChain(); // Initialize the window message receiver with a name. _wmr = new WindowMessageReceiver("MULTICLIP_IPC", null); // Setup the IPC handler. _wmr.MessageReceived += OnMessageReceived; // Initialize and set the low-level mouse hook. _mouseHook = new LowLevelMouseHook(); _mouseHook.LButtonDown += OnMouseHookButtonDown; _mouseHook.RButtonDown += OnMouseHookButtonDown; _mouseHook.XButtonDown += OnMouseHookButtonDown; _mouseHook.SetHook(); // Initialize and register the overview hotkey. _overviewHotkey = new GlobalHotkey(HotkeyModfier.Ctrl, Keys.Space); _overviewHotkey.Pressed += OnOverviewHotkeyPressed; _overviewHotkey.Register(); // Initialize and register the secure-copy hotkey. _secureCopyHotkey = new GlobalHotkey(HotkeyModfier.Ctrl | HotkeyModfier.Alt, Keys.C); _secureCopyHotkey.Pressed += OnSecureCopyHotkeyPressed; _secureCopyHotkey.Register(); // Show the help window on the first run of the app. if ((bool)Properties.Settings.Default["IsFirstRun"] == true) { Properties.Settings.Default["IsFirstRun"] = false; Properties.Settings.Default.Save(); HelpWindow helpWindow = new HelpWindow(); helpWindow.Show(); } ClipboardList.ItemsSource = _viewModel.ClipboardItems; // When a file-drop item is about to open a subwindow, // hide the main window. FileDropItem.PreviewShellExecute += delegate { if (_isVisible) { HideAsync().GetAwaiter(); } }; } catch (Exception e) { _logger.LogCritical(LogEvents.FatalErr, "Failed to initialize the main window!", e); Exceptions.NotifyCritical(e); } }