|
1 | 1 | using PropertyModels.ComponentModel.DataAnnotations; |
2 | | -using PropertyModels.Extensions; |
3 | | -using ReactiveUI.Fody.Helpers; |
| 2 | +using System.Collections.ObjectModel; |
4 | 3 | using System.ComponentModel; |
5 | 4 |
|
6 | 5 | namespace Gui.ViewModels; |
7 | 6 |
|
8 | 7 | public class EditorSettingsWindowViewModel : ViewModelBase |
9 | 8 | { |
10 | | - EditorSettings _Settings { get; } |
| 9 | + EditorSettings Model { get; } |
11 | 10 |
|
12 | 11 | public EditorSettingsWindowViewModel() |
13 | 12 | { } |
14 | 13 |
|
15 | 14 | public EditorSettingsWindowViewModel(EditorSettings settings) |
16 | 15 | { |
17 | | - _Settings = settings; |
18 | | - |
19 | | - AllowSavingAsVanillaObject = settings.AllowSavingAsVanillaObject; |
20 | | - AutoObjectDiscoveryAndUpload = settings.AutoObjectDiscoveryAndUpload; |
21 | | - UseHttps = settings.UseHttps; |
22 | | - ServerAddressHttp = settings.ServerAddressHttp; |
23 | | - ServerAddressHttps = settings.ServerAddressHttps; |
24 | | - DownloadFolder = settings.DownloadFolder; |
25 | | - CurrentObjDataFolder = settings.ObjDataDirectory; |
26 | | - ObjDataDirectories = settings.ObjDataDirectories.ToBindingList(); |
27 | | - |
28 | | - AppDataObjDataFolder = settings.AppDataObjDataFolder; |
29 | | - LocomotionObjDataFolder = settings.LocomotionObjDataFolder; |
30 | | - OpenLocoObjDataFolder = settings.OpenLocoObjDataFolder; |
| 16 | + Model = settings; |
| 17 | + ObjDataDirectories = new(settings.ObjDataDirectories); |
31 | 18 | } |
32 | 19 |
|
33 | 20 | public void Commit() |
34 | 21 | { |
35 | | - _Settings.AllowSavingAsVanillaObject = AllowSavingAsVanillaObject; |
36 | | - _Settings.AutoObjectDiscoveryAndUpload = AutoObjectDiscoveryAndUpload; |
37 | | - _Settings.UseHttps = UseHttps; |
38 | | - _Settings.ServerAddressHttp = ServerAddressHttp; |
39 | | - _Settings.ServerAddressHttps = ServerAddressHttps; |
40 | | - _Settings.DownloadFolder = DownloadFolder; |
41 | | - _Settings.ObjDataDirectory = CurrentObjDataFolder; |
42 | | - _Settings.ObjDataDirectories = [.. ObjDataDirectories]; |
43 | | - |
44 | | - _Settings.AppDataObjDataFolder = AppDataObjDataFolder; |
45 | | - _Settings.LocomotionObjDataFolder = LocomotionObjDataFolder; |
46 | | - _Settings.OpenLocoObjDataFolder = OpenLocoObjDataFolder; |
| 22 | + Model.ObjDataDirectories = [.. ObjDataDirectories]; |
47 | 23 | } |
48 | 24 |
|
49 | | - [Reactive, Category("Misc"), DisplayName("Allow saving as vanilla object"), Description("If enabled, the editor will allow saving objects with \"Vanilla\" flag set. If disabled, the object will be forcefully saved as \"Custom\" instead.")] |
50 | | - public bool AllowSavingAsVanillaObject { get; set; } |
| 25 | + [Category("Misc"), DisplayName("Allow saving as vanilla object"), Description("If enabled, the editor will allow saving objects with \"Vanilla\" flag set. If disabled, the object will be forcefully saved as \"Custom\" instead.")] |
| 26 | + public bool AllowSavingAsVanillaObject |
| 27 | + { |
| 28 | + get => Model.AllowSavingAsVanillaObject; |
| 29 | + set => Model.AllowSavingAsVanillaObject = value; |
| 30 | + } |
| 31 | + |
| 32 | + [Category("Misc"), DisplayName("Show Logs window on Error"), Description("When an error occurs, display the Logs window automatically")] |
| 33 | + public bool ShowLogsOnError |
| 34 | + { |
| 35 | + get => Model.ShowLogsOnError; |
| 36 | + set => Model.ShowLogsOnError = value; |
| 37 | + } |
51 | 38 |
|
52 | 39 | #region Object Folders |
53 | 40 |
|
54 | 41 | const string GameObjectFolderCategory = "Folders OpenLoco can use objects from"; |
55 | 42 | const string UserObjectFolderCategory = "Folders where you store custom objects"; |
56 | 43 |
|
57 | | - [Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("AppData ObjData Folder"), Description("The ObjData folder in %AppData%\\OpenLoco\\objects.")] |
58 | | - public string AppDataObjDataFolder { get; set; } = string.Empty; |
| 44 | + [PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("AppData ObjData Folder"), Description("The ObjData folder in %AppData%\\OpenLoco\\objects.")] |
| 45 | + public string AppDataObjDataFolder |
| 46 | + { |
| 47 | + get => Model.AppDataObjDataFolder; |
| 48 | + set => Model.AppDataObjDataFolder = value; |
| 49 | + } |
| 50 | + |
| 51 | + [PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("Locomotion ObjData Folder"), Description("The ObjData folder in your Locomotion installation.")] |
| 52 | + public string LocomotionObjDataFolder |
| 53 | + { |
| 54 | + get => Model.LocomotionObjDataFolder; |
| 55 | + set => Model.LocomotionObjDataFolder = value; |
| 56 | + } |
59 | 57 |
|
60 | | - [Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("Locomotion ObjData Folder"), Description("The ObjData folder in your Locomotion installation.")] |
61 | | - public string LocomotionObjDataFolder { get; set; } = string.Empty; |
62 | | - [Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("OpenLoco ObjData Folder"), Description("The ObjData folder in the OpenLoco\\Objects directory.")] |
63 | | - public string OpenLocoObjDataFolder { get; set; } = string.Empty; |
| 58 | + [PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("OpenLoco ObjData Folder"), Description("The ObjData folder in the OpenLoco\\Objects directory.")] |
| 59 | + public string OpenLocoObjDataFolder |
| 60 | + { |
| 61 | + get => Model.OpenLocoObjDataFolder; |
| 62 | + set => Model.OpenLocoObjDataFolder = value; |
| 63 | + } |
64 | 64 |
|
65 | | - [Reactive, PathBrowsable(PathBrowsableType.Directory), Category(UserObjectFolderCategory), DisplayName("Downloads"), Description("The folder to store downloaded objects.")] |
66 | | - public string DownloadFolder { get; set; } = string.Empty; |
| 65 | + [PathBrowsable(PathBrowsableType.Directory), Category(UserObjectFolderCategory), DisplayName("Downloads"), Description("The folder to store downloaded objects.")] |
| 66 | + public string DownloadFolder |
| 67 | + { |
| 68 | + get => Model.DownloadFolder; |
| 69 | + set => Model.DownloadFolder = value; |
| 70 | + } |
67 | 71 |
|
68 | | - [Reactive, ReadOnly(true), Category(UserObjectFolderCategory), DisplayName("Current ObjectData folder"), Description("The currently-selected ObjectData folder. This is readonly and only used to remember the previous location when you start up the editor.")] |
69 | | - public string CurrentObjDataFolder { get; set; } |
| 72 | + [ReadOnly(true), Category(UserObjectFolderCategory), DisplayName("Current ObjectData folder"), Description("The currently-selected ObjectData folder. This is readonly and only used to remember the previous location when you start up the editor.")] |
| 73 | + public string CurrentObjDataFolder |
| 74 | + { |
| 75 | + get => Model.ObjDataDirectory; |
| 76 | + set => Model.ObjDataDirectory = value; |
| 77 | + } |
70 | 78 |
|
71 | | - [Reactive, Category(UserObjectFolderCategory), DisplayName("ObjectData folders"), Description("The list of all ObjectData folders.")] |
72 | | - public BindingList<string> ObjDataDirectories { get; set; } |
| 79 | + [Category(UserObjectFolderCategory), DisplayName("ObjectData folders"), Description("The list of all ObjectData folders.")] |
| 80 | + public ObservableCollection<string> ObjDataDirectories { get; set; } |
73 | 81 |
|
74 | 82 | #endregion |
75 | 83 |
|
76 | 84 | #region Object Service |
77 | 85 |
|
78 | | - [Reactive, Category("Object Service"), DisplayName("Automatic object discovery and upload"), Description("If enabled, the editor will scan the current object directory for objects and check if there are any that are not known to the object service. If any new objects are discovered they will be automatically uploaded to the service.")] |
79 | | - public bool AutoObjectDiscoveryAndUpload { get; set; } |
| 86 | + [Category("Object Service"), DisplayName("Automatic object discovery and upload"), Description("If enabled, the editor will scan the current object directory for objects and check if there are any that are not known to the object service. If any new objects are discovered they will be automatically uploaded to the service.")] |
| 87 | + public bool AutoObjectDiscoveryAndUpload |
| 88 | + { |
| 89 | + get => Model.AutoObjectDiscoveryAndUpload; |
| 90 | + set => Model.AutoObjectDiscoveryAndUpload = value; |
| 91 | + } |
80 | 92 |
|
81 | | - [Reactive, ConditionTarget, Category("Object Service"), DisplayName("Use HTTPS"), Description("Will use the HTTPS address instead of the HTTP address for Object Service connections.")] |
82 | | - public bool UseHttps { get; set; } |
| 93 | + [ConditionTarget, Category("Object Service"), DisplayName("Use HTTPS"), Description("Will use the HTTPS address instead of the HTTP address for Object Service connections.")] |
| 94 | + public bool UseHttps |
| 95 | + { |
| 96 | + get => Model.UseHttps; |
| 97 | + set => Model.UseHttps = value; |
| 98 | + } |
83 | 99 |
|
84 | | - [Reactive, Category("Object Service"), DisplayName("HTTP"), PropertyVisibilityCondition(nameof(UseHttps), false)] |
85 | | - public string ServerAddressHttp { get; set; } = "http://openloco.leftofzen.dev/"; |
| 100 | + [Category("Object Service"), DisplayName("HTTP"), PropertyVisibilityCondition(nameof(UseHttps), false)] |
| 101 | + public string ServerAddressHttp |
| 102 | + { |
| 103 | + get => Model.ServerAddressHttp; |
| 104 | + set => Model.ServerAddressHttp = value; |
| 105 | + } |
86 | 106 |
|
87 | | - [Reactive, Category("Object Service"), DisplayName("HTTPS"), PropertyVisibilityCondition(nameof(UseHttps), true)] |
88 | | - public string ServerAddressHttps { get; set; } = "https://openloco.leftofzen.dev/"; |
| 107 | + [Category("Object Service"), DisplayName("HTTPS"), PropertyVisibilityCondition(nameof(UseHttps), true)] |
| 108 | + public string ServerAddressHttps |
| 109 | + { |
| 110 | + get; |
| 111 | + set; |
| 112 | + } |
89 | 113 |
|
90 | 114 | #endregion |
91 | 115 | } |
0 commit comments