157 lines
5.4 KiB
C#
157 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using BeWoLauncher.Components;
|
|
using BeWoLauncher.Logic.Controller;
|
|
|
|
namespace BeWoLauncher
|
|
{
|
|
public partial class LauncherWindow : Window
|
|
{
|
|
private readonly Stack<Control> _ModalPopUpControls;
|
|
private Control _CurrentModalPopUp;
|
|
private Grid _ModalPopUpBackGround;
|
|
private WaitLayer2 _WaitLayer;
|
|
|
|
public LauncherWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
_ModalPopUpControls = new Stack<Control>();
|
|
|
|
ViewController.InitWindow(this);
|
|
|
|
ViewController.StartView();
|
|
}
|
|
|
|
private void MainWindow_OnClosing(object s, CancelEventArgs e)
|
|
{
|
|
ProcessController.StartLauncherShutdown();
|
|
}
|
|
private void RootGrid_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
double top = (rootGrid.ActualHeight - 400) / 3;
|
|
rootGrid.Margin = new Thickness(0, top, 0, 0);
|
|
}
|
|
|
|
private void ShowModalBackground()
|
|
{
|
|
_ModalPopUpBackGround = new Grid();
|
|
_ModalPopUpBackGround.IsHitTestVisible = true;
|
|
_ModalPopUpBackGround.Background = Brushes.White;
|
|
_ModalPopUpBackGround.Opacity = .5;
|
|
Grid.SetColumnSpan(_ModalPopUpBackGround, 3);
|
|
Grid.SetRowSpan(_ModalPopUpBackGround, 3);
|
|
rootGrid.Children.Add(_ModalPopUpBackGround);
|
|
Panel.SetZIndex(_ModalPopUpBackGround, int.MaxValue - 1);
|
|
}
|
|
public void ShowControlAsModalPopUp(Control control)
|
|
{
|
|
ShowControlAsModalPopUp(control, HorizontalAlignment.Center, VerticalAlignment.Center);
|
|
}
|
|
public void ShowControlAsModalPopUp(Control control, HorizontalAlignment ha, VerticalAlignment va)
|
|
{
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
|
|
(Action)delegate
|
|
{
|
|
if (_CurrentModalPopUp != null)
|
|
{
|
|
rootGrid.Children.Remove(_CurrentModalPopUp);
|
|
_ModalPopUpControls.Push(_CurrentModalPopUp);
|
|
}
|
|
else
|
|
{
|
|
this.ShowModalBackground();
|
|
}
|
|
|
|
_CurrentModalPopUp = control;
|
|
control.HorizontalAlignment = ha;
|
|
control.VerticalAlignment = va;
|
|
Grid.SetColumnSpan(control, 3);
|
|
Grid.SetRowSpan(control, 3);
|
|
this.rootGrid.Children.Add(control);
|
|
Panel.SetZIndex(control, int.MaxValue);
|
|
});
|
|
}
|
|
public void CloseCurrentPopUp()
|
|
{
|
|
if (_ModalPopUpBackGround != null)
|
|
{
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
|
|
(Action)delegate
|
|
{
|
|
rootGrid.Children.Remove(_CurrentModalPopUp);
|
|
_CurrentModalPopUp = null;
|
|
if (_ModalPopUpControls.Count == 0)
|
|
{
|
|
rootGrid.Children.Remove(_ModalPopUpBackGround);
|
|
_ModalPopUpBackGround = null;
|
|
}
|
|
else
|
|
{
|
|
var control = this._ModalPopUpControls.Pop();
|
|
_CurrentModalPopUp = control;
|
|
rootGrid.Children.Add(control);
|
|
Panel.SetZIndex(control, int.MaxValue);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
public void StartWaiting()
|
|
{
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
|
|
(Action)delegate
|
|
{
|
|
if (_WaitLayer == null)
|
|
{
|
|
_WaitLayer = new WaitLayer2();
|
|
_WaitLayer.HorizontalAlignment = HorizontalAlignment.Center;
|
|
_WaitLayer.VerticalAlignment = VerticalAlignment.Center;
|
|
rootGrid2.Children.Add(_WaitLayer);
|
|
Panel.SetZIndex(_WaitLayer, int.MaxValue);
|
|
_WaitLayer.Dispatcher.Invoke(DispatcherPriority.Render, (Action)delegate () { });
|
|
}
|
|
});
|
|
}
|
|
public void EndWaiting()
|
|
{
|
|
Dispatcher.BeginInvoke(
|
|
DispatcherPriority.Normal,
|
|
(Action)delegate
|
|
{
|
|
if (_WaitLayer != null)
|
|
{
|
|
rootGrid2.Children.Remove(_WaitLayer);
|
|
_WaitLayer = null;
|
|
}
|
|
});
|
|
}
|
|
|
|
public void SetMainContent(UserControl main)
|
|
{
|
|
rootGrid.Children.Clear();
|
|
rootGrid.Children.Add(main);
|
|
}
|
|
|
|
private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
|
{
|
|
if (e.Key == System.Windows.Input.Key.Delete)
|
|
{
|
|
ViewController.LaunchBehavior.UninstallMode = true;
|
|
}
|
|
}
|
|
|
|
private void Window_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
|
|
{
|
|
if (e.Key == System.Windows.Input.Key.Delete)
|
|
{
|
|
ViewController.LaunchBehavior.UninstallMode = false;
|
|
}
|
|
}
|
|
}
|
|
}
|