mirror of
https://github.com/sp-tarkov/launcher.git
synced 2025-02-12 17:10:44 -05:00
Implement NotifyPropertyChangedBase, optimization (!66)
- NotifyPropertyChangedBase created and implemented in classes that inherit INotifyPropertyChangedBase - Some optimization fixes in models (one of this - `Where(predicate).Count() == 0` to `All(invertedPredicate)` Co-authored-by: Valery Varaksa <varaksav62@gmail.com> Reviewed-on: SPT/Launcher#66 Co-authored-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com> Co-committed-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
5ae20122f7
commit
441fb128fe
@ -13,6 +13,7 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using SPT.Launcher.Utilities;
|
||||
using SPT.Launcher.Controllers;
|
||||
|
||||
namespace SPT.Launcher.Helpers
|
||||
@ -23,7 +24,7 @@ namespace SPT.Launcher.Helpers
|
||||
public static Settings Instance { get; } = Json.Load<Settings>(DefaultSettingsFileLocation) ?? new Settings();
|
||||
}
|
||||
|
||||
public class Settings : INotifyPropertyChanged
|
||||
public class Settings : NotifyPropertyChangedBase
|
||||
{
|
||||
public bool FirstRun { get; set; } = true;
|
||||
|
||||
@ -72,121 +73,65 @@ namespace SPT.Launcher.Helpers
|
||||
|
||||
public string DefaultLocale { get; set; } = "English";
|
||||
|
||||
private bool _IsAddingServer;
|
||||
private bool _isAddingServer;
|
||||
[JsonIgnore]
|
||||
public bool IsAddingServer
|
||||
{
|
||||
get => _IsAddingServer;
|
||||
set
|
||||
{
|
||||
if (_IsAddingServer != value)
|
||||
{
|
||||
_IsAddingServer = value;
|
||||
RaisePropertyChanged(nameof(IsAddingServer));
|
||||
}
|
||||
}
|
||||
get => _isAddingServer;
|
||||
set => SetProperty(ref _isAddingServer, value);
|
||||
}
|
||||
|
||||
private bool _AllowSettings;
|
||||
private bool _allowSettings;
|
||||
[JsonIgnore]
|
||||
public bool AllowSettings
|
||||
{
|
||||
get => _AllowSettings;
|
||||
set
|
||||
{
|
||||
if (_AllowSettings != value)
|
||||
{
|
||||
_AllowSettings = value;
|
||||
RaisePropertyChanged(nameof(AllowSettings));
|
||||
}
|
||||
}
|
||||
get => _allowSettings;
|
||||
set => SetProperty(ref _allowSettings, value);
|
||||
}
|
||||
|
||||
private bool _GameRunning;
|
||||
private bool _gameRunning;
|
||||
[JsonIgnore]
|
||||
public bool GameRunning
|
||||
{
|
||||
get => _GameRunning;
|
||||
set
|
||||
{
|
||||
if (_GameRunning != value)
|
||||
{
|
||||
_GameRunning = value;
|
||||
RaisePropertyChanged(nameof(GameRunning));
|
||||
}
|
||||
}
|
||||
get => _gameRunning;
|
||||
set => SetProperty(ref _gameRunning, value);
|
||||
}
|
||||
|
||||
private LauncherAction _LauncherStartGameAction;
|
||||
private LauncherAction _launcherStartGameAction;
|
||||
public LauncherAction LauncherStartGameAction
|
||||
{
|
||||
get => _LauncherStartGameAction;
|
||||
set
|
||||
{
|
||||
if (_LauncherStartGameAction != value)
|
||||
{
|
||||
_LauncherStartGameAction = value;
|
||||
RaisePropertyChanged(nameof(LauncherStartGameAction));
|
||||
}
|
||||
}
|
||||
get => _launcherStartGameAction;
|
||||
set => SetProperty(ref _launcherStartGameAction, value);
|
||||
}
|
||||
|
||||
private bool _UseAutoLogin;
|
||||
private bool _useAutoLogin;
|
||||
public bool UseAutoLogin
|
||||
{
|
||||
get => _UseAutoLogin;
|
||||
set
|
||||
{
|
||||
if (_UseAutoLogin != value)
|
||||
{
|
||||
_UseAutoLogin = value;
|
||||
RaisePropertyChanged(nameof(UseAutoLogin));
|
||||
}
|
||||
}
|
||||
get => _useAutoLogin;
|
||||
set => SetProperty(ref _useAutoLogin, value);
|
||||
}
|
||||
|
||||
private bool _IsDevMode;
|
||||
private bool _isDevMode;
|
||||
|
||||
public bool IsDevMode
|
||||
{
|
||||
get => _IsDevMode;
|
||||
set
|
||||
{
|
||||
if (_IsDevMode != value)
|
||||
{
|
||||
_IsDevMode = value;
|
||||
RaisePropertyChanged(nameof(IsDevMode));
|
||||
}
|
||||
}
|
||||
get => _isDevMode;
|
||||
set => SetProperty(ref _isDevMode, value);
|
||||
}
|
||||
|
||||
private string _GamePath;
|
||||
private string _gamePath;
|
||||
public string GamePath
|
||||
{
|
||||
get => _GamePath;
|
||||
set
|
||||
{
|
||||
if (_GamePath != value)
|
||||
{
|
||||
_GamePath = value;
|
||||
RaisePropertyChanged(nameof(GamePath));
|
||||
}
|
||||
}
|
||||
get => _gamePath;
|
||||
set => SetProperty(ref _gamePath, value);
|
||||
}
|
||||
|
||||
private string[] _ExcludeFromCleanup;
|
||||
private string[] _excludeFromCleanup = [];
|
||||
|
||||
public string[] ExcludeFromCleanup
|
||||
{
|
||||
get => _ExcludeFromCleanup ??= Array.Empty<string>();
|
||||
set
|
||||
{
|
||||
if (_ExcludeFromCleanup != value)
|
||||
{
|
||||
_ExcludeFromCleanup = value;
|
||||
RaisePropertyChanged(nameof(ExcludeFromCleanup));
|
||||
}
|
||||
}
|
||||
get => _excludeFromCleanup;
|
||||
set => SetProperty(ref _excludeFromCleanup, value);
|
||||
}
|
||||
|
||||
public ServerSetting Server { get; set; } = new ServerSetting();
|
||||
@ -202,18 +147,15 @@ namespace SPT.Launcher.Helpers
|
||||
GamePath = Environment.CurrentDirectory;
|
||||
IsDevMode = false;
|
||||
|
||||
Server = new ServerSetting { Name = "SPT", Url = "http://127.0.0.1:6969" };
|
||||
Server = new ServerSetting
|
||||
{
|
||||
Name = "SPT",
|
||||
Url = "http://127.0.0.1:6969"
|
||||
};
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
LogManager.Instance.Info($"Using launcher config at: {LauncherSettingsProvider.DefaultSettingsFileLocation}");
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,45 +6,24 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class ConnectServerModel : INotifyPropertyChanged
|
||||
public class ConnectServerModel : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _InfoText;
|
||||
private string _infoText;
|
||||
public string InfoText
|
||||
{
|
||||
get => _InfoText;
|
||||
set
|
||||
{
|
||||
if (_InfoText != value)
|
||||
{
|
||||
_InfoText = value;
|
||||
RaisePropertyChanged(nameof(InfoText));
|
||||
}
|
||||
}
|
||||
get => _infoText;
|
||||
set => SetProperty(ref _infoText, value);
|
||||
}
|
||||
|
||||
private bool _ConnectionFailed;
|
||||
private bool _connectionFailed;
|
||||
public bool ConnectionFailed
|
||||
{
|
||||
get => _ConnectionFailed;
|
||||
set
|
||||
{
|
||||
if(_ConnectionFailed != value)
|
||||
{
|
||||
_ConnectionFailed = value;
|
||||
RaisePropertyChanged(nameof(ConnectionFailed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
get => _connectionFailed;
|
||||
set => SetProperty(ref _connectionFailed, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,53 +9,32 @@
|
||||
using SPT.Launcher.Models.SPT;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class EditionCollection : INotifyPropertyChanged
|
||||
public class EditionCollection : NotifyPropertyChangedBase
|
||||
{
|
||||
private bool _HasSelection;
|
||||
private bool _hasSelection;
|
||||
public bool HasSelection
|
||||
{
|
||||
get => _HasSelection;
|
||||
set
|
||||
{
|
||||
if(_HasSelection != value)
|
||||
{
|
||||
_HasSelection = value;
|
||||
RaisePropertyChanged(nameof(HasSelection));
|
||||
get => _hasSelection;
|
||||
set => SetProperty(ref _hasSelection, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private int _SelectedEditionIndex;
|
||||
private int _selectedEditionIndex;
|
||||
public int SelectedEditionIndex
|
||||
{
|
||||
get => _SelectedEditionIndex;
|
||||
set
|
||||
{
|
||||
if (_SelectedEditionIndex != value)
|
||||
{
|
||||
_SelectedEditionIndex = value;
|
||||
RaisePropertyChanged(nameof(SelectedEditionIndex));
|
||||
}
|
||||
}
|
||||
get => _selectedEditionIndex;
|
||||
set => SetProperty(ref _selectedEditionIndex, value);
|
||||
}
|
||||
|
||||
private SPTEdition _SelectedEdition;
|
||||
private SPTEdition _selectedEdition;
|
||||
public SPTEdition SelectedEdition
|
||||
{
|
||||
get => _SelectedEdition;
|
||||
set
|
||||
{
|
||||
if (_SelectedEdition != value)
|
||||
{
|
||||
_SelectedEdition = value;
|
||||
HasSelection = _SelectedEdition != null;
|
||||
RaisePropertyChanged(nameof(SelectedEdition));
|
||||
get => _selectedEdition;
|
||||
set => SetProperty(ref _selectedEdition, value, () => HasSelection = _selectedEdition != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
public ObservableCollection<SPTEdition> AvailableEditions { get; private set; } = new ObservableCollection<SPTEdition>();
|
||||
public ObservableCollection<SPTEdition> AvailableEditions { get; private set; } = [];
|
||||
|
||||
public EditionCollection()
|
||||
{
|
||||
@ -66,12 +45,5 @@ namespace SPT.Launcher.Models.Launcher
|
||||
AvailableEditions.Add(new SPTEdition(edition));
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,38 +11,24 @@ using SPT.Launcher.Helpers;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class LocaleCollection : INotifyPropertyChanged
|
||||
public class LocaleCollection : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _SelectedLocale;
|
||||
private string _selectedLocale;
|
||||
public string SelectedLocale
|
||||
{
|
||||
get => _SelectedLocale;
|
||||
set
|
||||
{
|
||||
if (_SelectedLocale != value)
|
||||
{
|
||||
_SelectedLocale = value;
|
||||
RaisePropertyChanged(nameof(SelectedLocale));
|
||||
LocalizationProvider.LoadLocalByName(value);
|
||||
}
|
||||
}
|
||||
get => _selectedLocale;
|
||||
set => SetProperty(ref _selectedLocale, value, () => LocalizationProvider.LoadLocalByName(value));
|
||||
}
|
||||
|
||||
public ObservableCollection<string> AvailableLocales { get; set; } = LocalizationProvider.GetAvailableLocales();
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public LocaleCollection()
|
||||
{
|
||||
SelectedLocale = LocalizationProvider.LocaleNameDictionary.GetValueOrDefault(LauncherSettingsProvider.Instance.DefaultLocale, "English");
|
||||
}
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,19 @@
|
||||
using SPT.Launcher.Models.Launcher;
|
||||
using System.ComponentModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models
|
||||
{
|
||||
public class LocalizedLauncherAction : INotifyPropertyChanged
|
||||
public class LocalizedLauncherAction : NotifyPropertyChangedBase
|
||||
{
|
||||
public LauncherAction Action { get; set; }
|
||||
|
||||
private string _Name;
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
get => _Name;
|
||||
set
|
||||
{
|
||||
if(_Name != value)
|
||||
{
|
||||
_Name = value;
|
||||
RaisePropertyChanged(nameof(Name));
|
||||
}
|
||||
}
|
||||
get => _name;
|
||||
set => SetProperty(ref _name, value);
|
||||
}
|
||||
|
||||
public void UpdateLocaleName()
|
||||
@ -49,12 +43,5 @@ namespace SPT.Launcher.Models
|
||||
|
||||
UpdateLocaleName();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,44 +6,24 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class LoginModel : INotifyPropertyChanged
|
||||
public class LoginModel : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _Username = "";
|
||||
private string _username = "";
|
||||
public string Username
|
||||
{
|
||||
get => _Username;
|
||||
set
|
||||
{
|
||||
if (_Username != value)
|
||||
{
|
||||
_Username = value;
|
||||
RaisePropertyChanged(nameof(Username));
|
||||
}
|
||||
}
|
||||
get => _username;
|
||||
set => SetProperty(ref _username, value);
|
||||
}
|
||||
|
||||
private string _Password = "";
|
||||
private string _password = "";
|
||||
public string Password
|
||||
{
|
||||
get => _Password;
|
||||
set
|
||||
{
|
||||
if (_Password != value)
|
||||
{
|
||||
_Password = value;
|
||||
RaisePropertyChanged(nameof(Password));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
get => _password;
|
||||
set => SetProperty(ref _password, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,62 +9,35 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class MenuBarItem : INotifyPropertyChanged
|
||||
public class MenuBarItem : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _Name;
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
get => _Name;
|
||||
set
|
||||
{
|
||||
if (_Name != value)
|
||||
{
|
||||
_Name = value;
|
||||
RaisePropertyChanged(nameof(Name));
|
||||
}
|
||||
}
|
||||
get => _name;
|
||||
set => SetProperty(ref _name, value);
|
||||
}
|
||||
|
||||
private bool _IsSelected;
|
||||
private bool _isSelected;
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _IsSelected;
|
||||
set
|
||||
{
|
||||
if (_IsSelected != value)
|
||||
{
|
||||
_IsSelected = value;
|
||||
RaisePropertyChanged(nameof(IsSelected));
|
||||
}
|
||||
}
|
||||
get => _isSelected;
|
||||
set => SetProperty(ref _isSelected, value);
|
||||
}
|
||||
|
||||
private Action _ItemAction;
|
||||
private Action _itemAction;
|
||||
public Action ItemAction
|
||||
{
|
||||
get => _ItemAction;
|
||||
set
|
||||
{
|
||||
if (_ItemAction != value)
|
||||
{
|
||||
_ItemAction = value;
|
||||
RaisePropertyChanged(nameof(ItemAction));
|
||||
}
|
||||
}
|
||||
get => _itemAction;
|
||||
set => SetProperty(ref _itemAction, value);
|
||||
}
|
||||
|
||||
public Func<Task<bool>> CanUseAction = async () => await Task.FromResult(true);
|
||||
|
||||
public Action OnFailedToUseAction = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,55 +2,35 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class ModInfoCollection : INotifyPropertyChanged
|
||||
public class ModInfoCollection : NotifyPropertyChangedBase
|
||||
{
|
||||
private int _serverModsCount;
|
||||
public int ServerModsCount
|
||||
{
|
||||
get => _serverModsCount;
|
||||
set
|
||||
{
|
||||
if (_serverModsCount != value)
|
||||
{
|
||||
_serverModsCount = value;
|
||||
RaisePropertyChanged(nameof(ServerModsCount));
|
||||
}
|
||||
}
|
||||
set => SetProperty(ref _serverModsCount, value);
|
||||
}
|
||||
|
||||
private int _profileModsCount;
|
||||
public int ProfileModsCount
|
||||
{
|
||||
get => _profileModsCount;
|
||||
set
|
||||
{
|
||||
if (_profileModsCount != value)
|
||||
{
|
||||
_profileModsCount = value;
|
||||
RaisePropertyChanged(nameof(ProfileModsCount));
|
||||
}
|
||||
}
|
||||
set => SetProperty(ref _profileModsCount, value);
|
||||
}
|
||||
|
||||
private bool _hasMods;
|
||||
public bool HasMods
|
||||
{
|
||||
get => _hasMods;
|
||||
set
|
||||
{
|
||||
if (_hasMods != value)
|
||||
{
|
||||
_hasMods = value;
|
||||
RaisePropertyChanged(nameof(HasMods));
|
||||
}
|
||||
}
|
||||
set => SetProperty(ref _hasMods, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<SPTMod> ActiveMods { get; private set; } = new ObservableCollection<SPTMod>();
|
||||
public ObservableCollection<SPTMod> InactiveMods { get; private set; } = new ObservableCollection<SPTMod>();
|
||||
public ObservableCollection<SPTMod> ActiveMods { get; private set; } = [];
|
||||
public ObservableCollection<SPTMod> InactiveMods { get; private set; } = [];
|
||||
|
||||
public ModInfoCollection()
|
||||
{
|
||||
@ -68,7 +48,7 @@ namespace SPT.Launcher.Models.Launcher
|
||||
|
||||
foreach (var inactiveMod in profileMods)
|
||||
{
|
||||
var existingMod = ActiveMods.Where(x => x.Name == inactiveMod.Name && x.Version == inactiveMod.Version && x.Author == inactiveMod.Author).FirstOrDefault();
|
||||
var existingMod = ActiveMods.FirstOrDefault(x => x.Name == inactiveMod.Name && x.Version == inactiveMod.Version && x.Author == inactiveMod.Author);
|
||||
|
||||
if (existingMod != null)
|
||||
{
|
||||
@ -82,11 +62,5 @@ namespace SPT.Launcher.Models.Launcher
|
||||
|
||||
HasMods = ActiveMods.Count > 0 || InactiveMods.Count > 0;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,75 +9,48 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher.Notifications
|
||||
{
|
||||
public class NotificationItem : INotifyPropertyChanged
|
||||
public class NotificationItem : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _Message;
|
||||
private string _message;
|
||||
public string Message
|
||||
{
|
||||
get => _Message;
|
||||
set
|
||||
{
|
||||
if (_Message != value)
|
||||
{
|
||||
_Message = value;
|
||||
RaisePropertyChanged(nameof(Message));
|
||||
}
|
||||
}
|
||||
get => _message;
|
||||
set => SetProperty(ref _message, value);
|
||||
}
|
||||
|
||||
private string _ButtonText;
|
||||
private string _buttonText;
|
||||
public string ButtonText
|
||||
{
|
||||
get => _ButtonText;
|
||||
set
|
||||
{
|
||||
if (_ButtonText != value)
|
||||
{
|
||||
_ButtonText = value;
|
||||
RaisePropertyChanged(nameof(ButtonText));
|
||||
}
|
||||
}
|
||||
get => _buttonText;
|
||||
set => SetProperty(ref _buttonText, value);
|
||||
}
|
||||
|
||||
private bool _HasButton;
|
||||
private bool _hasButton;
|
||||
public bool HasButton
|
||||
{
|
||||
get => _HasButton;
|
||||
set
|
||||
{
|
||||
if (_HasButton != value)
|
||||
{
|
||||
_HasButton = value;
|
||||
RaisePropertyChanged(nameof(HasButton));
|
||||
}
|
||||
}
|
||||
get => _hasButton;
|
||||
set => SetProperty(ref _hasButton, value);
|
||||
}
|
||||
|
||||
public Action ItemAction = null;
|
||||
|
||||
public NotificationItem(string Message)
|
||||
public NotificationItem(string message)
|
||||
{
|
||||
this.Message = Message;
|
||||
Message = message;
|
||||
ButtonText = string.Empty;
|
||||
HasButton = false;
|
||||
}
|
||||
|
||||
public NotificationItem(string Message, string ButtonText, Action ItemAction)
|
||||
public NotificationItem(string message, string buttonText, Action itemAction)
|
||||
{
|
||||
this.Message = Message;
|
||||
this.ButtonText = ButtonText;
|
||||
Message = message;
|
||||
ButtonText = buttonText;
|
||||
HasButton = true;
|
||||
this.ItemAction = ItemAction;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
ItemAction = itemAction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,35 +13,29 @@ using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Timers;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher.Notifications
|
||||
{
|
||||
public class NotificationQueue : INotifyPropertyChanged, IDisposable
|
||||
public class NotificationQueue : NotifyPropertyChangedBase, IDisposable
|
||||
{
|
||||
public Timer queueTimer = new Timer();
|
||||
private Timer animateChangeTimer = new Timer(230);
|
||||
private Timer animateCloseTimer = new Timer(230);
|
||||
|
||||
public ObservableCollection<NotificationItem> queue { get; set; } = new ObservableCollection<NotificationItem>();
|
||||
public ObservableCollection<NotificationItem> queue { get; set; } = [];
|
||||
|
||||
private bool _ShowBanner;
|
||||
private bool _showBanner;
|
||||
public bool ShowBanner
|
||||
{
|
||||
get => _ShowBanner;
|
||||
set
|
||||
{
|
||||
if (_ShowBanner != value)
|
||||
{
|
||||
_ShowBanner = value;
|
||||
RaisePropertyChanged(nameof(ShowBanner));
|
||||
}
|
||||
}
|
||||
get => _showBanner;
|
||||
set => SetProperty(ref _showBanner, value);
|
||||
}
|
||||
|
||||
public NotificationQueue(int ShowTimeInMiliseconds)
|
||||
public NotificationQueue(int showTimeInMilliseconds)
|
||||
{
|
||||
ShowBanner = false;
|
||||
queueTimer.Interval = ShowTimeInMiliseconds;
|
||||
queueTimer.Interval = showTimeInMilliseconds;
|
||||
queueTimer.Elapsed += QueueTimer_Elapsed;
|
||||
|
||||
animateChangeTimer.Elapsed += AnimateChange_Elapsed;
|
||||
@ -71,43 +65,43 @@ namespace SPT.Launcher.Models.Launcher.Notifications
|
||||
}
|
||||
}
|
||||
|
||||
public void Enqueue(string Message, bool AutowNext = false, bool NoDefaultButton = false)
|
||||
public void Enqueue(string message, bool autoNext = false, bool noDefaultButton = false)
|
||||
{
|
||||
if (queue.Where(x => x.Message == Message).Count() == 0)
|
||||
if (queue.All(x => x.Message != message))
|
||||
{
|
||||
if (NoDefaultButton)
|
||||
if (noDefaultButton)
|
||||
{
|
||||
queue.Add(new NotificationItem(Message));
|
||||
queue.Add(new NotificationItem(message));
|
||||
}
|
||||
else
|
||||
{
|
||||
queue.Add(new NotificationItem(Message, LocalizationProvider.Instance.ok, () => { }));
|
||||
queue.Add(new NotificationItem(message, LocalizationProvider.Instance.ok, () => { }));
|
||||
}
|
||||
|
||||
CheckAndShowNotifications();
|
||||
|
||||
if (AutowNext && queue.Count == 2)
|
||||
if (autoNext && queue.Count == 2)
|
||||
{
|
||||
Next(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Enqueue(string Message, string ButtonText, Action ButtonAction, bool AllowNext = false)
|
||||
public void Enqueue(string message, string buttonText, Action buttonAction, bool allowNext = false)
|
||||
{
|
||||
if (queue.Where(x => x.Message == Message && x.ButtonText == ButtonText).Count() == 0)
|
||||
if (queue.All(x=>x.Message != message && x.ButtonText != buttonText))
|
||||
{
|
||||
queue.Add(new NotificationItem(Message, ButtonText, ButtonAction));
|
||||
queue.Add(new NotificationItem(message, buttonText, buttonAction));
|
||||
CheckAndShowNotifications();
|
||||
|
||||
if (AllowNext && queue.Count == 2)
|
||||
if (allowNext && queue.Count == 2)
|
||||
{
|
||||
Next(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Next(bool ResetTimer = false)
|
||||
public void Next(bool resetTimer = false)
|
||||
{
|
||||
if (queue.Count - 1 <= 0)
|
||||
{
|
||||
@ -115,7 +109,7 @@ namespace SPT.Launcher.Models.Launcher.Notifications
|
||||
return;
|
||||
}
|
||||
|
||||
if (ResetTimer)
|
||||
if (resetTimer)
|
||||
{
|
||||
queueTimer.Stop();
|
||||
queueTimer.Start();
|
||||
@ -142,13 +136,6 @@ namespace SPT.Launcher.Models.Launcher.Notifications
|
||||
ShowBanner = true;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
queueTimer.Dispose();
|
||||
|
@ -12,210 +12,127 @@ using SPT.Launcher.Models.SPT;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class ProfileInfo : INotifyPropertyChanged
|
||||
public class ProfileInfo : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _Username;
|
||||
private string _username;
|
||||
public string Username
|
||||
{
|
||||
get => _Username;
|
||||
set
|
||||
{
|
||||
if(_Username != value)
|
||||
{
|
||||
_Username = value;
|
||||
RaisePropertyChanged(nameof(Username));
|
||||
}
|
||||
}
|
||||
get => _username;
|
||||
set => SetProperty(ref _username, value);
|
||||
}
|
||||
|
||||
private string _Nickname;
|
||||
private string _nickname;
|
||||
public string Nickname
|
||||
{
|
||||
get => _Nickname;
|
||||
set
|
||||
{
|
||||
if (_Nickname != value)
|
||||
{
|
||||
_Nickname = value;
|
||||
RaisePropertyChanged(nameof(Nickname));
|
||||
}
|
||||
}
|
||||
get => _nickname;
|
||||
set => SetProperty(ref _nickname, value);
|
||||
}
|
||||
|
||||
private string _SideImage;
|
||||
private string _sideImage;
|
||||
public string SideImage
|
||||
{
|
||||
get => _SideImage;
|
||||
set
|
||||
{
|
||||
if (_SideImage != value)
|
||||
{
|
||||
_SideImage = value;
|
||||
RaisePropertyChanged(nameof(SideImage));
|
||||
}
|
||||
}
|
||||
get => _sideImage;
|
||||
set => SetProperty(ref _sideImage, value);
|
||||
}
|
||||
|
||||
private string _Side;
|
||||
private string _side;
|
||||
public string Side
|
||||
{
|
||||
get => _Side;
|
||||
set
|
||||
{
|
||||
if (_Side != value)
|
||||
{
|
||||
_Side = value;
|
||||
RaisePropertyChanged(nameof(Side));
|
||||
}
|
||||
}
|
||||
get => _side;
|
||||
set => SetProperty(ref _side, value);
|
||||
}
|
||||
|
||||
private string _Level;
|
||||
private string _level;
|
||||
public string Level
|
||||
{
|
||||
get => _Level;
|
||||
set
|
||||
{
|
||||
if (_Level != value)
|
||||
{
|
||||
_Level = value;
|
||||
RaisePropertyChanged(nameof(Level));
|
||||
}
|
||||
}
|
||||
get => _level;
|
||||
set => SetProperty(ref _level, value);
|
||||
}
|
||||
|
||||
private int _XPLevelProgress;
|
||||
public int XPLevelProgress
|
||||
{
|
||||
get => _XPLevelProgress;
|
||||
set
|
||||
{
|
||||
if (_XPLevelProgress != value)
|
||||
{
|
||||
_XPLevelProgress = value;
|
||||
RaisePropertyChanged(nameof(XPLevelProgress));
|
||||
}
|
||||
}
|
||||
set => SetProperty(ref _XPLevelProgress, value);
|
||||
}
|
||||
|
||||
private long _CurrentXP;
|
||||
private long _currentXP;
|
||||
public long CurrentExp
|
||||
{
|
||||
get => _CurrentXP;
|
||||
set
|
||||
{
|
||||
if (_CurrentXP != value)
|
||||
{
|
||||
_CurrentXP = value;
|
||||
RaisePropertyChanged(nameof(CurrentExp));
|
||||
}
|
||||
}
|
||||
get => _currentXP;
|
||||
set => SetProperty(ref _currentXP, value);
|
||||
}
|
||||
|
||||
private long _RemainingExp;
|
||||
private long _remainingExp;
|
||||
public long RemainingExp
|
||||
{
|
||||
get => _RemainingExp;
|
||||
set
|
||||
{
|
||||
if (_RemainingExp != value)
|
||||
{
|
||||
_RemainingExp = value;
|
||||
RaisePropertyChanged(nameof(RemainingExp));
|
||||
}
|
||||
}
|
||||
get => _remainingExp;
|
||||
set => SetProperty(ref _remainingExp, value);
|
||||
}
|
||||
|
||||
private long _NextLvlExp;
|
||||
private long _nextLvlExp;
|
||||
public long NextLvlExp
|
||||
{
|
||||
get => _NextLvlExp;
|
||||
set
|
||||
{
|
||||
if (_NextLvlExp != value)
|
||||
{
|
||||
_NextLvlExp = value;
|
||||
RaisePropertyChanged(nameof(NextLvlExp));
|
||||
}
|
||||
}
|
||||
get => _nextLvlExp;
|
||||
set => SetProperty(ref _nextLvlExp, value);
|
||||
}
|
||||
|
||||
private bool _HasData;
|
||||
private bool _hasData;
|
||||
public bool HasData
|
||||
{
|
||||
get => _HasData;
|
||||
set
|
||||
{
|
||||
if (_HasData != value)
|
||||
{
|
||||
_HasData = value;
|
||||
RaisePropertyChanged(nameof(HasData));
|
||||
}
|
||||
}
|
||||
get => _hasData;
|
||||
set => SetProperty(ref _hasData, value);
|
||||
}
|
||||
|
||||
public string MismatchMessage => VersionMismatch ? LocalizationProvider.Instance.profile_version_mismath : null;
|
||||
|
||||
private bool _VersionMismatch;
|
||||
private bool _versionMismatch;
|
||||
public bool VersionMismatch
|
||||
{
|
||||
get => _VersionMismatch;
|
||||
set
|
||||
{
|
||||
if(_VersionMismatch != value)
|
||||
{
|
||||
_VersionMismatch = value;
|
||||
RaisePropertyChanged(nameof(VersionMismatch));
|
||||
}
|
||||
}
|
||||
get => _versionMismatch;
|
||||
set => SetProperty(ref _versionMismatch, value);
|
||||
}
|
||||
|
||||
private SPTData _SPT;
|
||||
private SPTData _spt;
|
||||
public SPTData SPT
|
||||
{
|
||||
get => _SPT;
|
||||
set
|
||||
{
|
||||
if(_SPT != value)
|
||||
{
|
||||
_SPT = value;
|
||||
RaisePropertyChanged(nameof(SPT));
|
||||
}
|
||||
}
|
||||
get => _spt;
|
||||
set => SetProperty(ref _spt, value);
|
||||
}
|
||||
|
||||
public void UpdateDisplayedProfile(ProfileInfo PInfo)
|
||||
public void UpdateDisplayedProfile(ProfileInfo pInfo)
|
||||
{
|
||||
if (PInfo.Side == null || string.IsNullOrWhiteSpace(PInfo.Side) || PInfo.Side == "unknown") return;
|
||||
if (pInfo.Side == null || string.IsNullOrWhiteSpace(pInfo.Side) || pInfo.Side == "unknown") return;
|
||||
|
||||
HasData = true;
|
||||
Nickname = PInfo.Nickname;
|
||||
Side = PInfo.Side;
|
||||
SideImage = PInfo.SideImage;
|
||||
Level = PInfo.Level;
|
||||
CurrentExp = PInfo.CurrentExp;
|
||||
NextLvlExp = PInfo.NextLvlExp;
|
||||
RemainingExp = PInfo.RemainingExp;
|
||||
XPLevelProgress = PInfo.XPLevelProgress;
|
||||
Nickname = pInfo.Nickname;
|
||||
Side = pInfo.Side;
|
||||
SideImage = pInfo.SideImage;
|
||||
Level = pInfo.Level;
|
||||
CurrentExp = pInfo.CurrentExp;
|
||||
NextLvlExp = pInfo.NextLvlExp;
|
||||
RemainingExp = pInfo.RemainingExp;
|
||||
XPLevelProgress = pInfo.XPLevelProgress;
|
||||
|
||||
SPT = PInfo.SPT;
|
||||
SPT = pInfo.SPT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the SPT versions are compatible (non-major changes)
|
||||
/// </summary>
|
||||
/// <param name="CurrentVersion"></param>
|
||||
/// <param name="ExpectedVersion"></param>
|
||||
/// <param name="currentVersion"></param>
|
||||
/// <param name="expectedVersion"></param>
|
||||
/// <returns></returns>
|
||||
private bool CompareVersions(string CurrentVersion, string ExpectedVersion)
|
||||
private bool CompareVersions(string currentVersion, string expectedVersion)
|
||||
{
|
||||
if (ExpectedVersion == "") return false;
|
||||
if (expectedVersion == "") return false;
|
||||
|
||||
SPTVersion v1 = new SPTVersion(CurrentVersion);
|
||||
SPTVersion v2 = new SPTVersion(ExpectedVersion);
|
||||
var v1 = new SPTVersion(currentVersion);
|
||||
var v2 = new SPTVersion(expectedVersion);
|
||||
|
||||
// check 'X'.x.x
|
||||
if (v1.Major != v2.Major) return false;
|
||||
@ -242,14 +159,7 @@ namespace SPT.Launcher.Models.Launcher
|
||||
|
||||
SideImage = Path.Combine(ImageRequest.ImageCacheFolder, $"side_{Side.ToLower()}.png");
|
||||
|
||||
if (Side != null && !string.IsNullOrWhiteSpace(Side) && Side != "unknown")
|
||||
{
|
||||
HasData = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
HasData = false;
|
||||
}
|
||||
HasData = Side != null && !string.IsNullOrWhiteSpace(Side) && Side != "unknown";
|
||||
|
||||
Level = serverProfileInfo.currlvl.ToString();
|
||||
CurrentExp = serverProfileInfo.currexp;
|
||||
@ -269,12 +179,5 @@ namespace SPT.Launcher.Models.Launcher
|
||||
|
||||
XPLevelProgress = (int)Math.Floor((((double)currentLvlTotal) - RemainingExp) / currentLvlTotal * 100);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,47 +6,27 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
using SPT.Launcher.Models.Launcher;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
namespace SPT.Launch.Models.Launcher
|
||||
{
|
||||
public class RegisterModel : INotifyPropertyChanged
|
||||
public class RegisterModel : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _Username;
|
||||
private string _username;
|
||||
public string Username
|
||||
{
|
||||
get => _Username;
|
||||
set
|
||||
{
|
||||
if (_Username != value)
|
||||
{
|
||||
_Username = value;
|
||||
RaisePropertyChanged(nameof(Username));
|
||||
}
|
||||
}
|
||||
get => _username;
|
||||
set => SetProperty(ref _username, value);
|
||||
}
|
||||
|
||||
private string _Password;
|
||||
private string _password;
|
||||
public string Password
|
||||
{
|
||||
get => _Password;
|
||||
set
|
||||
{
|
||||
if (_Password != value)
|
||||
{
|
||||
_Password = value;
|
||||
RaisePropertyChanged(nameof(Password));
|
||||
}
|
||||
}
|
||||
get => _password;
|
||||
set => SetProperty(ref _password, value);
|
||||
}
|
||||
|
||||
public EditionCollection EditionsCollection { get; set; } = new EditionCollection();
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,47 +7,26 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.Launcher
|
||||
{
|
||||
public class ServerSetting : INotifyPropertyChanged
|
||||
public class ServerSetting : NotifyPropertyChangedBase
|
||||
{
|
||||
public LoginModel AutoLoginCreds { get; set; } = null;
|
||||
|
||||
private string _Name;
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
get => _Name;
|
||||
set
|
||||
{
|
||||
if (_Name != value)
|
||||
{
|
||||
_Name = value;
|
||||
RaisePropertyChanged(nameof(Name));
|
||||
}
|
||||
}
|
||||
get => _name;
|
||||
set => SetProperty(ref _name, value);
|
||||
}
|
||||
|
||||
private string _Url;
|
||||
private string _url;
|
||||
public string Url
|
||||
{
|
||||
get => _Url;
|
||||
set
|
||||
{
|
||||
if (_Url != value)
|
||||
{
|
||||
_Url = value;
|
||||
RaisePropertyChanged(nameof(Url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
get => _url;
|
||||
set => SetProperty(ref _url, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +1,34 @@
|
||||
using System.ComponentModel;
|
||||
using SPT.Launcher.Utilities;
|
||||
|
||||
namespace SPT.Launcher.Models.SPT
|
||||
{
|
||||
public class SPTVersion : INotifyPropertyChanged
|
||||
public class SPTVersion : NotifyPropertyChangedBase
|
||||
{
|
||||
public int Major;
|
||||
public int Minor;
|
||||
public int Build;
|
||||
|
||||
public bool HasTag => Tag != null;
|
||||
public bool HasTag => Tag != string.Empty;
|
||||
|
||||
private string _Tag = null;
|
||||
private string _tag = string.Empty;
|
||||
public string Tag
|
||||
{
|
||||
get => _Tag;
|
||||
set
|
||||
{
|
||||
if(_Tag != value)
|
||||
{
|
||||
_Tag = value;
|
||||
RaisePropertyChanged(nameof(Tag));
|
||||
RaisePropertyChanged(nameof(HasTag));
|
||||
}
|
||||
}
|
||||
get => _tag;
|
||||
set => SetProperty(ref _tag, value, () => RaisePropertyChanged(nameof(HasTag)));
|
||||
}
|
||||
|
||||
public void ParseVersionInfo(string SPTVersion)
|
||||
public void ParseVersionInfo(string sptVersion)
|
||||
{
|
||||
if (SPTVersion.Contains('-'))
|
||||
if (sptVersion.Contains('-'))
|
||||
{
|
||||
string[] versionInfo = SPTVersion.Split('-');
|
||||
string[] versionInfo = sptVersion.Split('-');
|
||||
|
||||
SPTVersion = versionInfo[0];
|
||||
sptVersion = versionInfo[0];
|
||||
|
||||
Tag = versionInfo[1];
|
||||
}
|
||||
|
||||
string[] splitVersion = SPTVersion.Split('.');
|
||||
string[] splitVersion = sptVersion.Split('.');
|
||||
|
||||
if (splitVersion.Length >= 3)
|
||||
{
|
||||
@ -48,16 +40,9 @@ namespace SPT.Launcher.Models.SPT
|
||||
|
||||
public SPTVersion() { }
|
||||
|
||||
public SPTVersion(string SPTVersion)
|
||||
public SPTVersion(string sptVersion)
|
||||
{
|
||||
ParseVersionInfo(SPTVersion);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void RaisePropertyChanged(string property)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
ParseVersionInfo(sptVersion);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace SPT.Launcher.Utilities;
|
||||
|
||||
public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void RaisePropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected void SetProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (!EqualityComparer<T>.Default.Equals(field, value))
|
||||
{
|
||||
field = value;
|
||||
RaisePropertyChanged(propertyName);
|
||||
afterSetAction?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetNotNullableProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (value is not null)
|
||||
{
|
||||
SetProperty(ref field, value, afterSetAction, propertyName );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user