Skip to content

Commit 855d444

Browse files
committed
add setting to enable/disable error-log popups
1 parent 8ea67da commit 855d444

File tree

3 files changed

+86
-58
lines changed

3 files changed

+86
-58
lines changed

Gui/EditorSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public HashSet<string> ObjDataDirectories
2929
} = [];
3030

3131
public bool AllowSavingAsVanillaObject { get; set; }
32+
public bool ShowLogsOnError { get; set; }
3233
public bool AutoObjectDiscoveryAndUpload { get; set; }
3334

3435
public bool UseHttps { get; set; }
Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,115 @@
11
using PropertyModels.ComponentModel.DataAnnotations;
2-
using PropertyModels.Extensions;
3-
using ReactiveUI.Fody.Helpers;
2+
using System.Collections.ObjectModel;
43
using System.ComponentModel;
54

65
namespace Gui.ViewModels;
76

87
public class EditorSettingsWindowViewModel : ViewModelBase
98
{
10-
EditorSettings _Settings { get; }
9+
EditorSettings Model { get; }
1110

1211
public EditorSettingsWindowViewModel()
1312
{ }
1413

1514
public EditorSettingsWindowViewModel(EditorSettings settings)
1615
{
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);
3118
}
3219

3320
public void Commit()
3421
{
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];
4723
}
4824

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+
}
5138

5239
#region Object Folders
5340

5441
const string GameObjectFolderCategory = "Folders OpenLoco can use objects from";
5542
const string UserObjectFolderCategory = "Folders where you store custom objects";
5643

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+
}
5957

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+
}
6464

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+
}
6771

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+
}
7078

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; }
7381

7482
#endregion
7583

7684
#region Object Service
7785

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+
}
8092

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+
}
8399

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+
}
86106

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+
}
89113

90114
#endregion
91115
}

Gui/ViewModels/MainWindowViewModel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ public MainWindowViewModel()
9898

9999
Model.Logger.LogAdded += (sender, laea) =>
100100
{
101-
// announce to users that something bad happened
102-
var log = laea.Log;
103-
if (log.Level is LogLevel.Error)
101+
if (Model.Settings.ShowLogsOnError)
104102
{
105-
// check if the logs window is already open
106-
if (App.GetOpenWindows().Any(x => x.DataContext is LogWindowViewModel))
103+
// announce to users that something bad happened
104+
var log = laea.Log;
105+
if (log.Level is LogLevel.Error)
107106
{
108-
return;
107+
// check if the logs window is already open
108+
if (App.GetOpenWindows().Any(x => x.DataContext is LogWindowViewModel))
109+
{
110+
return;
111+
}
112+
ShowLogsCommand.Execute();
109113
}
110-
ShowLogsCommand.Execute();
111114
}
112115
};
113116

0 commit comments

Comments
 (0)