Merge remote-tracking branch 'origin/develop' into newDoctor

This commit is contained in:
fabjuuuh
2020-10-16 12:51:42 +02:00
35 changed files with 1269 additions and 113 deletions

View File

@@ -20,14 +20,14 @@ namespace ClientApp.ViewModels
public bool InvertedLoginStatus { get; set; }
private MainWindowViewModel mainWindowViewModel;
private MainWindowViewModel MainWindowViewModel;
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
{
this.mainWindowViewModel = mainWindowViewModel;
this.MainWindowViewModel = mainWindowViewModel;
LoginCommand = new RelayCommand<object>((parameter) =>
{
//TODO send username and password to server
this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
this.MainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password);
});
}
@@ -35,11 +35,11 @@ namespace ClientApp.ViewModels
internal void setLoginStatus(bool status)
{
this.mainWindowViewModel.InfoModel.ConnectedToServer = status;
this.MainWindowViewModel.InfoModel.ConnectedToServer = status;
this.InvertedLoginStatus = !status;
if (status)
{
this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel);
this.MainWindowViewModel.SelectedViewModel = new MainViewModel(MainWindowViewModel);
}
}
}

View File

@@ -1,37 +1,137 @@
using ClientApp.Models;
using ClientApp.MagicCode;
using ClientApp.Models;
using ClientApp.Utils;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using Util;
using System.Windows;
using System.Windows.Input;
namespace ClientApp.ViewModels
{
class MainWindowViewModel : ObservableObject
{
#region private members
private Window mWindow;
private int mOuterMarginSize = 10;
private int mWindowRadius = 10;
#endregion
#region commands
public ICommand MinimizeCommand { get; set; }
public ICommand MaximizeCommand { get; set; }
public ICommand CloseCommand { get; set; }
public ICommand MenuCommand { get; set; }
#endregion
#region public properties
public Info InfoModel { get; set; }
public ObservableObject SelectedViewModel { get; set; }
public Client client { get; }
LoginViewModel loginViewModel;
/// <summary>
/// size of the resize border around the window
/// </summary>
public MainWindowViewModel(Client client)
public double MinimumWidth { get; set; } = 250;
public double MinimumHeight { get; set; } = 250;
public int ResizeBorder { get; set; } = 6;
public Thickness ResizeBorderThickness { get { return new Thickness(ResizeBorder + OuterMarginSize); } }
public Thickness InnerContentPadding { get { return new Thickness(ResizeBorder); } }
public Thickness OuterMarginThickness { get { return new Thickness(OuterMarginSize); } }
public CornerRadius WindowCornerRadius { get { return new CornerRadius(WindowRadius); } }
public int OuterMarginSize
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mOuterMarginSize;
}
set
{
mOuterMarginSize = value;
}
}
public int WindowRadius
{
get
{
return mWindow.WindowState == WindowState.Maximized ? 0 : mWindowRadius;
}
set
{
mWindowRadius = value;
}
}
public int TitleHeight { get; set; } = 42;
public GridLength TitleHeightGridLength { get { return new GridLength(TitleHeight + ResizeBorder); } }
#endregion
public MainWindowViewModel(Window window, Client client)
{
this.mWindow = window;
this.mWindow.StateChanged += (sender, e) =>
{
OnPropertyChanged(nameof(ResizeBorderThickness));
OnPropertyChanged(nameof(OuterMarginThickness));
OnPropertyChanged(nameof(WindowCornerRadius));
OnPropertyChanged(nameof(OuterMarginSize));
OnPropertyChanged(nameof(WindowRadius));
};
this.InfoModel = new Info();
this.client = client;
loginViewModel = new LoginViewModel(this);
SelectedViewModel = loginViewModel;
this.client.SetLoginViewModel(loginViewModel);
App.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing);
this.MinimizeCommand = new RelayCommand(() => this.mWindow.WindowState = WindowState.Minimized);
this.MaximizeCommand = new RelayCommand(() => this.mWindow.WindowState ^= WindowState.Maximized);
this.CloseCommand = new RelayCommand(() => this.mWindow.Close());
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
var resizer = new WindowResizer(this.mWindow);
this.mWindow.Closed += (sender, e) => this.client.Dispose();
}
void MainWindow_Closing(object sender, CancelEventArgs e)
#region helper
private Point GetMousePosition()
{
this.client.sendMessage(DataParser.getDisconnectJson(loginViewModel.Username));
Debug.WriteLine("getmousePosition called");
var p = Mouse.GetPosition(this.mWindow);
return new Point(p.X + this.mWindow.Left, p.Y + this.mWindow.Top);
}
#endregion
}
}