-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathSettingsViewModel.cs
More file actions
143 lines (123 loc) · 6.95 KB
/
SettingsViewModel.cs
File metadata and controls
143 lines (123 loc) · 6.95 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Shared.Core.Misc;
using Shared.Core.Services;
using Shared.Core.Settings;
namespace AssetEditor.ViewModels
{
partial class SettingsViewModel : ObservableObject
{
private readonly ApplicationSettingsService _settingsService;
private readonly LocalizationManager _localizationManager;
public ObservableCollection<string> AvailableLangauges { get; set; } = [];
public ObservableCollection<ThemeType> AvailableThemes { get; set; } = [];
public ObservableCollection<BackgroundColour> RenderEngineBackgroundColours { get; set; } = [];
public ObservableCollection<GameTypeEnum> Games { get; set; } = [];
public ObservableCollection<GamePathItem> GameDirectores { get; set; } = [];
public ObservableCollection<CameraControlMode> CameraModes { get; set; } = [];
[ObservableProperty] private string _selectedLanguage;
[ObservableProperty] private ThemeType _currentTheme;
[ObservableProperty] private BackgroundColour _currentRenderEngineBackgroundColour;
[ObservableProperty] private int _visualEditorsGridSize;
[ObservableProperty] private bool _startMaximised;
[ObservableProperty] private GameTypeEnum _currentGame;
[ObservableProperty] private bool _loadCaPacksByDefault;
[ObservableProperty] private bool _showCAWemFiles;
[ObservableProperty] private string _wwisePath;
[ObservableProperty] private bool _onlyLoadLod0ForReferenceMeshes;
[ObservableProperty] private CameraControlMode _selectedCameraMode;
public SettingsViewModel(ApplicationSettingsService settingsService, LocalizationManager localizationManager)
{
_settingsService = settingsService;
_localizationManager = localizationManager;
AvailableLangauges = new ObservableCollection<string>(_localizationManager.GetPossibleLanguages());
SelectedLanguage = _localizationManager.SelectedLangauge;
AvailableThemes = new ObservableCollection<ThemeType>((ThemeType[])Enum.GetValues(typeof(ThemeType)));
CurrentTheme = _settingsService.CurrentSettings.Theme;
RenderEngineBackgroundColours = new ObservableCollection<BackgroundColour>((BackgroundColour[])Enum.GetValues(typeof(BackgroundColour)));
CurrentRenderEngineBackgroundColour = _settingsService.CurrentSettings.RenderEngineBackgroundColour;
VisualEditorsGridSize = _settingsService.CurrentSettings.VisualEditorsGridSize;
CameraModes = new ObservableCollection<CameraControlMode>((CameraControlMode[])Enum.GetValues(typeof(CameraControlMode)));
StartMaximised = _settingsService.CurrentSettings.StartMaximised;
Games = new ObservableCollection<GameTypeEnum>(GameInformationDatabase.Games.Values.OrderBy(game => game.DisplayName).Select(game => game.Type));
CurrentGame = _settingsService.CurrentSettings.CurrentGame;
LoadCaPacksByDefault = _settingsService.CurrentSettings.LoadCaPacksByDefault;
ShowCAWemFiles = _settingsService.CurrentSettings.ShowCAWemFiles;
OnlyLoadLod0ForReferenceMeshes = _settingsService.CurrentSettings.OnlyLoadLod0ForReferenceMeshes;
SelectedCameraMode = _settingsService.CurrentSettings.CameraControlMode;
foreach (var game in GameInformationDatabase.Games.Values.OrderBy(game => game.DisplayName))
{
GameDirectores.Add(
new GamePathItem()
{
GameName = $"{game.DisplayName}",
GameType = game.Type,
Path = _settingsService.CurrentSettings.GameDirectories.FirstOrDefault(x => x.Game == game.Type)?.Path
});
}
WwisePath = _settingsService.CurrentSettings.WwisePath;
}
[RelayCommand]
private void Save()
{
_settingsService.CurrentSettings.Theme = CurrentTheme;
_settingsService.CurrentSettings.RenderEngineBackgroundColour = CurrentRenderEngineBackgroundColour;
_settingsService.CurrentSettings.VisualEditorsGridSize = VisualEditorsGridSize;
_settingsService.CurrentSettings.StartMaximised = StartMaximised;
_settingsService.CurrentSettings.CurrentGame = CurrentGame;
_settingsService.CurrentSettings.LoadCaPacksByDefault = LoadCaPacksByDefault;
_settingsService.CurrentSettings.ShowCAWemFiles = ShowCAWemFiles;
_settingsService.CurrentSettings.SelectedLangauge = SelectedLanguage;
_settingsService.CurrentSettings.OnlyLoadLod0ForReferenceMeshes = OnlyLoadLod0ForReferenceMeshes;
_settingsService.CurrentSettings.GameDirectories.Clear();
_settingsService.CurrentSettings.CameraControlMode = SelectedCameraMode;
foreach (var item in GameDirectores)
_settingsService.CurrentSettings.GameDirectories.Add(new ApplicationSettings.GamePathPair() { Game = item.GameType, Path = item.Path });
_settingsService.CurrentSettings.WwisePath = WwisePath;
_localizationManager.LoadLanguage(SelectedLanguage);
_settingsService.Save();
MessageBox.Show("Please restart the tool after updating settings!");
}
[RelayCommand]
private void Browse()
{
var dialog = new OpenFileDialog();
dialog.Filter = "Executable files (*.exe)|*.exe";
dialog.Multiselect = false;
if (dialog.ShowDialog() == DialogResult.OK)
WwisePath = dialog.FileName;
}
}
class GamePathItem : NotifyPropertyChangedImpl
{
public GameTypeEnum GameType { get; set; }
string _gameName;
public string GameName { get => _gameName; set => SetAndNotify(ref _gameName, value); }
string _path;
public string Path { get => _path; set => SetAndNotify(ref _path, value); }
public ICommand BrowseCommand { get; set; }
public GamePathItem()
{
BrowseCommand = new RelayCommand(OnBrowse);
}
void OnBrowse()
{
var dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
Path = dialog.SelectedPath;
var files = Directory.GetFiles(Path);
var packFiles = files.Count(x => System.IO.Path.GetExtension(x) == ".pack");
var manifest = files.Count(x => x.Contains("manifest.txt"));
if (packFiles == 0 && manifest == 0)
System.Windows.MessageBox.Show($"The selected directory contains {packFiles} packfiles and {manifest} manifest files. It is probably not a game directory");
}
}
}
}