//--------------------// #region Initialize Menu /// <summary> /// Creates the <see cref="_menuPresenter"/> if necessary, sets it as the <see cref="CurrentPresenter"/> and configures the GUI for the main menu /// </summary> private void InitializeMenuMode() { Loading = true; using (new TimedLogEvent("Initialize menu")) { // Switch mode CurrentState = GameState.Menu; // Clean previous presenter //CleanupPresenter(); // Load menu scene if (_menuPresenter == null) { _menuPresenter = new MenuPresenter(Engine, _menuUniverse); } _menuPresenter.Initialize(); CurrentPresenter = _menuPresenter; // Activate new view CurrentPresenter.HookIn(); if (Settings.Current.Graphics.Fading) { Engine.FadeIn(); } // Show game GUI GuiManager.CloseAll(); LoadDialog("MainMenu"); } Loading = false; }
//--------------------// #region Dispose /// <inheritdoc/> protected override void Dispose(bool disposing) { try { if (disposing) { // Dispose presenters _menuPresenter?.Dispose(); CurrentPresenter?.Dispose(); // Shutdown GUI system GuiManager?.Dispose(); // Remove settings update hooks Settings.Current.General.Changed -= Program.UpdateLocale; Settings.Current.Controls.Changed -= ApplyControlsSettings; Settings.Current.Display.Changed -= ResetEngine; Settings.Current.Graphics.Changed -= ApplyGraphicsSettings; Settings.Current.Sound.Changed -= ApplySoundSettings; } } finally { base.Dispose(disposing); } }
/// <summary>Detach the model from the view.</summary> public void Detach() { explorerPresenter.CommandHistory.ModelChanged -= OnGraphModelChanged; if (CurrentPresenter != null) { CurrentPresenter.Detach(); } graphView.OnAxisClick -= OnAxisClick; graphView.OnLegendClick -= OnLegendClick; graphView.OnCaptionClick -= OnCaptionClick; graphView.OnHoverOverPoint -= OnHoverOverPoint; }
/// <summary> /// Toggles <see cref="CurrentState"/> between <see cref="GameState.InGame"/> and <see cref="GameState.Pause"/> /// </summary> /// <remarks>When called while <see cref="CurrentState"/> is neither <see cref="GameState.InGame"/> nor <see cref="GameState.Pause"/> nothing happens</remarks> public void TogglePause() { switch (CurrentState) { case GameState.InGame: case GameState.Modify: // Backup previous state _beforePause = CurrentState; CurrentState = GameState.Pause; // Freeze the mouse interaction var interactivePresenter = CurrentPresenter as InteractivePresenter; if (interactivePresenter != null) { RemoveInputReceiver(interactivePresenter); } // Dim down the screen CurrentPresenter.DimDown(); // Show pause menu GuiManager.Reset(); LoadDialog("PauseMenu"); break; case GameState.Pause: // Restore previous state (usually GameState.InGame) CurrentState = _beforePause; // Dim screen back up CurrentPresenter.DimUp(); // Restore the mouse interaction AddInputReceiver((InteractivePresenter)CurrentPresenter); // Restore the correct HUD GuiManager.Reset(); if (CurrentState == GameState.InGame) { LoadDialog("InGame/HUD"); } else if (CurrentState == GameState.Modify) { LoadDialog("InGame/HUD_Modify"); } break; } }
/// <summary>User has clicked the legend.</summary> /// <param name="sender">Sender of event</param> /// <param name="e">Event arguments</param> private void OnLegendClick(object sender, LegendClickArgs e) { if (CurrentPresenter != null) { CurrentPresenter.Detach(); } LegendPresenter presenter = new LegendPresenter(this); CurrentPresenter = presenter; LegendView view = new LegendView(graphView as GraphView); graphView.ShowEditorPanel(view.MainWidget, "Legend options"); presenter.Attach(graph, view, explorerPresenter); }
/// <summary>User has clicked an axis.</summary> /// <param name="axisType">Type of the axis.</param> private void OnAxisClick(Axis.AxisType axisType) { if (CurrentPresenter != null) { CurrentPresenter.Detach(); } AxisPresenter axisPresenter = new AxisPresenter(); CurrentPresenter = axisPresenter; AxisView a = new AxisView(graphView as GraphView); string dimension = (axisType == Axis.AxisType.Left || axisType == Axis.AxisType.Right) ? "Y" : "X"; graphView.ShowEditorPanel(a.MainWidget, dimension + "-Axis options"); axisPresenter.Attach(GetAxis(axisType), a, explorerPresenter); }
/// <summary>User has clicked a footer.</summary> /// <param name="sender">Sender of event</param> /// <param name="e">Event arguments</param> private void OnCaptionClick(object sender, EventArgs e) { if (CurrentPresenter != null) { CurrentPresenter.Detach(); } TitlePresenter titlePresenter = new TitlePresenter(); CurrentPresenter = titlePresenter; titlePresenter.ShowCaption = true; TitleView t = new TitleView(graphView as GraphView); graphView.ShowEditorPanel(t.MainWidget, "Title options"); titlePresenter.Attach(graph, t, explorerPresenter); }
/// <summary> /// User has clicked on graph annotation. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnAnnotationClick(object sender, EventArgs e) { if (CurrentPresenter != null) { CurrentPresenter.Detach(); } AnnotationPresenter presenter = new AnnotationPresenter(); CurrentPresenter = presenter; //LegendView view = new LegendView(graphView as GraphView); var view = new ViewBase(graphView as ViewBase, "ApsimNG.Resources.Glade.AnnotationView.glade"); graphView.ShowEditorPanel(view.MainWidget, "Stats / Equation options"); presenter.Attach(graph, view, explorerPresenter); }
//--------------------// #region Cleanup /// <summary> /// <see cref="PresenterBase{TUniverse,TCoordinates}.HookOut"/> and disposes the <see cref="CurrentPresenter"/> (unless it is the <see cref="_menuPresenter"/>) /// </summary> private void CleanupPresenter() { if (CurrentPresenter != null) { var interactivePresenter = CurrentPresenter as InteractivePresenter; if (interactivePresenter != null) { RemoveInputReceiver(interactivePresenter); } CurrentPresenter.HookOut(); // Don't dispose the _menuPresenter, since it will be reused for fast switching if (CurrentPresenter != _menuPresenter) { CurrentPresenter.Dispose(); } } }
private void StartBenchmark() { // Prevent unnecessary loading if (CurrentState == GameState.Benchmark) { return; } using (new TimedLogEvent("Start benchmark")) { // Load map CurrentSession = new Session(Universe.FromContent("Benchmark" + Universe.FileExt)) { Lua = NewLua() }; // Switch mode CurrentState = GameState.Benchmark; // Normalize settings for comparable results (don't save to preserve original settings) Settings.AutoSave = false; Settings.Current.Sound.PlayMusic = false; Settings.Current.Graphics.Fading = false; Settings.Current.Graphics.WaterEffects = WaterEffectsType.None; Settings.Current.Graphics.ParticleSystemQuality = Quality.Low; Settings.Current.Display.VSync = false; Settings.Current.Display.Resolution = Settings.Current.Display.WindowSize = new Size(800, 600); #if !DEBUG Settings.Current.Display.Fullscreen = true; #endif // Clean up any old stuff if (CurrentPresenter != null) { var interactivePresenter = CurrentPresenter as InteractivePresenter; if (interactivePresenter != null) { RemoveInputReceiver(interactivePresenter); } CurrentPresenter.HookOut(); if (CurrentPresenter != _menuPresenter) { CurrentPresenter.Dispose(); } } // Load benchmark universe CurrentPresenter = new BenchmarkPresenter(Engine, Universe.FromContent("Benchmark" + Universe.FileExt), path => { // Callback for sumbitting the benchmark results Form.Visible = false; //if (Msg.Ask(Form, Resources.BenchmarkReady, MsgSeverity.Info, Resources.BenchmarkReadyContinue, Resources.BenchmarkReadyCancel)) //{ // // ToDo: new Uri("http://omegaengine.de/benchmark-upload/?app=" + GeneralSettings.AppNameGrid) //} Msg.Inform(null, $"Please upload the file '{path}'.", MsgSeverity.Info); Exit(); }); CurrentPresenter.Initialize(); // Activate new view CurrentPresenter.HookIn(); if (Settings.Current.Graphics.Fading) { Engine.FadeIn(); } // Show benchmark GUI GuiManager.Reset(); LoadDialog("InGame/HUD_Benchmark"); } using (new TimedLogEvent("Clean caches")) { Engine.Cache.Clean(); GC.Collect(); } }