-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
128 lines (106 loc) · 4.89 KB
/
MainWindow.xaml.cs
File metadata and controls
128 lines (106 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Labb3_HES.Dialogs;
using Labb3_HES.ViewModel;
using System.IO;
using System.Windows;
namespace Labb3_HES
{
public partial class MainWindow : Window
{
private MainWindowViewModel mainWindowViewModel = new();
private WindowState stateBeforeFullScreenToggled;
public MainWindow()
{
InitializeComponent();
DataContext = mainWindowViewModel;
playerView.DataContext = mainWindowViewModel.PlayerViewModel;
SubscribeToEvents();
}
private void SubscribeToEvents()
{
mainWindowViewModel.ShouldCreateNewPackMessage += OnShouldCreateNewPackMessageRecieved;
mainWindowViewModel.ShouldDeletePackMessage += OnShouldDeletePackMessageRecieved;
mainWindowViewModel.ShouldToggleFullScreenMessage += OnShouldToggleFullScreenMessageRecieved;
mainWindowViewModel.PlayerViewModel.ActivePackIsNotPlayableMessage += OnActivePackIsNotPlayableMessageRecieved;
mainWindowViewModel.ShouldExitApplicationMessage += OnShouldExitApplicationMessageRecieved;
mainWindowViewModel.ConfigurationViewModel.ShouldOpenPackOptionsMessage += OnShouldOpenPackOptionsMessageRecieved;
mainWindowViewModel.ConfigurationViewModel.ShouldOpenImportQuestionsMessage += OnShouldOpenImportQuestionsMessageRecieved;
}
public void OnShouldCreateNewPackMessageRecieved(object sender, EventArgs args)
{
CreateNewPackDialog createNewPackDialog = new();
var result = createNewPackDialog.ShowDialog();
if (result == true)
{
string name = createNewPackDialog.NewQuestionPackName;
int difficultyIndex = createNewPackDialog.Index;
int timeLimitInSeconds = createNewPackDialog.TimeLimitInSeconds;
mainWindowViewModel.AddNewPack(name, difficultyIndex, timeLimitInSeconds);
}
}
public void OnShouldDeletePackMessageRecieved(object sender, EventArgs args)
{
var result = MessageBox.Show
($"Are you sure you want to delete {mainWindowViewModel.ActivePack.Name}",
"Delete question pack?",
MessageBoxButton.YesNo
);
if (result == MessageBoxResult.Yes) mainWindowViewModel.DeletePackAfterConfirmation();
}
public void OnShouldToggleFullScreenMessageRecieved(object sender, EventArgs args)
{
if (!(this.WindowState == WindowState.Maximized))
{
stateBeforeFullScreenToggled = WindowState;
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
}
else
{
WindowState = stateBeforeFullScreenToggled;
WindowStyle = WindowStyle.SingleBorderWindow;
ResizeMode = ResizeMode.CanResize;
}
}
private void OnActivePackIsNotPlayableMessageRecieved(object? sender, EventArgs e)
{
ActivePackNotPlayableDialog activePackNotPlayableDialog = new();
activePackNotPlayableDialog.ShowDialog();
}
public void OnShouldExitApplicationMessageRecieved(object sender, EventArgs args) => this.Close();
public void OnShouldOpenPackOptionsMessageRecieved(object sender, EventArgs args)
{
PackOptionsDialog packOptionsDialog = new();
packOptionsDialog.ShowDialog();
}
public void OnShouldOpenImportQuestionsMessageRecieved(object sender, EventArgs args)
{
mainWindowViewModel.ConfigurationViewModel.SetDefaultCategoryList();
ImportQuestionsDialog importQuestionsDialog = new();
var result = importQuestionsDialog.ShowDialog();
if (result == true)
{
ImportStatusDialog importStatusDialog = new();
var importStatusDialogResult = importStatusDialog.ShowDialog();
}
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
if (Path.Exists(mainWindowViewModel.pathToJsonFile))
{
await mainWindowViewModel.LoadPacks();
}
else
{
mainWindowViewModel.CreateDirectory();
mainWindowViewModel.CreateDefaultQuestionpack();
}
mainWindowViewModel.ActivePack = mainWindowViewModel.Packs.FirstOrDefault();
mainWindowViewModel.PlayerViewModel.QuestionPackWithRandomizedOrder = mainWindowViewModel.ActivePack.GetQuestionPackWithRandomizedOrderOfQuestions();
mainWindowViewModel.PlayerViewModel.ActiveAnswers = new string[4];
}
private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
await mainWindowViewModel.SavePacks();
}
}
}