diff --git a/LoL Assist/App.xaml b/LoL Assist/App.xaml index 1d5e358..b81f350 100644 --- a/LoL Assist/App.xaml +++ b/LoL Assist/App.xaml @@ -5,658 +5,17 @@ xmlns:converters="clr-namespace:LoL_Assist_WAPP.Converters" StartupUri="MainWindow.xaml"> - - - - - - - #7160E8 - #403582 - #A093EF - #303030 - #18191C - White - white - - Silver - Gray - #969284 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/LoL Assist/App.xaml.cs b/LoL Assist/App.xaml.cs index d1740fb..f9556df 100644 --- a/LoL Assist/App.xaml.cs +++ b/LoL Assist/App.xaml.cs @@ -14,9 +14,9 @@ public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { - Global.Config.debug = false; - Console.Title = "LoL Assist - Debug Console"; - ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue)); + Global.Config.debug = true; + //Console.Title = "LoL Assist - Debug Console"; + ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue)); if (!Global.Config.debug) { diff --git a/LoL Assist/BuildEditorWindow.xaml b/LoL Assist/BuildEditorWindow.xaml index 498a039..c665e34 100644 --- a/LoL Assist/BuildEditorWindow.xaml +++ b/LoL Assist/BuildEditorWindow.xaml @@ -39,8 +39,8 @@ Margin="7,0,0,0" FontWeight="DemiBold" HorizontalAlignment="Left" VerticalAlignment="Center"/> - + + + + + + + + + + + + + + + + + + + diff --git a/LoL Assist/View/RoleSelectPanel.xaml.cs b/LoL Assist/View/RoleSelectPanel.xaml.cs new file mode 100644 index 0000000..d980052 --- /dev/null +++ b/LoL Assist/View/RoleSelectPanel.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace LoL_Assist_WAPP.View +{ + /// + /// Interaction logic for RoleSelectPanel.xaml + /// + public partial class RoleSelectPanel : UserControl + { + public RoleSelectPanel() + { + InitializeComponent(); + } + + private void Role_Click(object sender, RoutedEventArgs e) => Utils.Animation.FadeOut(this); + } +} diff --git a/LoL Assist/ViewModel/BuildEditorViewModel.cs b/LoL Assist/ViewModel/BuildEditorViewModel.cs index 71dafef..f11b67b 100644 --- a/LoL Assist/ViewModel/BuildEditorViewModel.cs +++ b/LoL Assist/ViewModel/BuildEditorViewModel.cs @@ -36,12 +36,12 @@ private void SetAsDefaultExecute() { try { - if (!SelectedBuildName.Equals(CreateNewKey)) + if (!SelectedBuildName.Equals(_CreateNewKey)) { var gameMode = gm(); - defaultBuildConfig.setDefaultConfig(gameMode, SelectedBuildName); - writeDefaultBuildConfig(SelectedChampionId, defaultBuildConfig); - SlDefaultConfig = defaultBuildConfig.getDefaultConfig(gameMode); + _DefaultBuildConfig.setDefaultConfig(gameMode, SelectedBuildName); + writeDefaultBuildConfig(_SelectedChampionId, _DefaultBuildConfig); + SlDefaultConfig = _DefaultBuildConfig.getDefaultConfig(gameMode); } } catch { /*ex*/ } @@ -49,29 +49,29 @@ private void SetAsDefaultExecute() public void DeleteConfigExecute() { - if(SelectedBuildName != null && !SelectedBuildName.Equals(CreateNewKey)) + if(SelectedBuildName != null && !SelectedBuildName.Equals(_CreateNewKey)) { var buildName = SelectedBuildName; SelectedBuildName = null; var gameMode = gm(); var _buildsName = new List(); - _buildsName.Add(CreateNewKey); + _buildsName.Add(_CreateNewKey); - Main.localBuild.DeleteData(SelectedChampionId, Path.GetFileNameWithoutExtension(buildName), gameMode); - foreach (var path in Main.localBuild.GetBuildFiles(SelectedChampionId, gameMode)) + Main.localBuild.DeleteData(_SelectedChampionId, Path.GetFileNameWithoutExtension(buildName), gameMode); + foreach (var path in Main.localBuild.GetBuildFiles(_SelectedChampionId, gameMode)) _buildsName.Add(Path.GetFileName(path)); BuildsName = _buildsName; - var customBuildPath = Main.localBuild.BuildsFolder(SelectedChampionId, gameMode); - var fullPath = $"{customBuildPath}\\{defaultBuildConfig.getDefaultConfig(gameMode)}"; + var customBuildPath = Main.localBuild.BuildsFolder(_SelectedChampionId, gameMode); + var fullPath = $"{customBuildPath}\\{_DefaultBuildConfig.getDefaultConfig(gameMode)}"; if (!File.Exists(fullPath)) - defaultBuildConfig.resetDefaultConfig(gameMode); + _DefaultBuildConfig.resetDefaultConfig(gameMode); - writeDefaultBuildConfig(SelectedChampionId, defaultBuildConfig); - SlDefaultConfig = defaultBuildConfig.getDefaultConfig(gameMode); + writeDefaultBuildConfig(_SelectedChampionId, _DefaultBuildConfig); + SlDefaultConfig = _DefaultBuildConfig.getDefaultConfig(gameMode); } } @@ -80,9 +80,9 @@ private void ClearDefaultSourceExecute() if (SelectedChampion != null && SelectedGameMode != null) { var gameMode = gm(); - defaultBuildConfig.resetDefaultConfig(gameMode); - writeDefaultBuildConfig(SelectedChampionId, defaultBuildConfig); - SlDefaultConfig = defaultBuildConfig.getDefaultConfig(gameMode); + _DefaultBuildConfig.resetDefaultConfig(gameMode); + writeDefaultBuildConfig(_SelectedChampionId, _DefaultBuildConfig); + SlDefaultConfig = _DefaultBuildConfig.getDefaultConfig(gameMode); } } @@ -91,21 +91,21 @@ private async void SaveConfigExecute() if(!string.IsNullOrEmpty(FileName) && SelectedChampion != null && SelectedGameMode != null) { var sGM = gm(); - var filePath = Main.localBuild.DataPath(SelectedChampionId, FileName, sGM); + var filePath = Main.localBuild.DataPath(_SelectedChampionId, FileName, sGM); if (File.Exists(filePath)) File.Create(filePath).Dispose(); using(var streaWriter = new StreamWriter(filePath)) { - var json = JsonConvert.SerializeObject(SelectedBuild, Formatting.Indented); + var json = JsonConvert.SerializeObject(_SelectedBuild, Formatting.Indented); streaWriter.Write(json); - ReferenceBuild = json; + _ReferenceBuild = json; } var _buildsName = new List(); - _buildsName.Add(CreateNewKey); - foreach (var path in Main.localBuild.GetBuildFiles(SelectedChampionId, sGM)) + _buildsName.Add(_CreateNewKey); + foreach (var path in Main.localBuild.GetBuildFiles(_SelectedChampionId, sGM)) _buildsName.Add(Path.GetFileName(path)); BuildsName = _buildsName; @@ -259,7 +259,7 @@ public ItemImageModel SelectedSpell1 selectedSpell1 = value; SelectedSpell2 = RemoveDup(SelectedSpell1, SelectedSpell2); if(value != null) - SelectedBuild.spell.Spell0 = Dictionaries.SpellNameToSpellID[value.Text]; + _SelectedBuild.spell.Spell0 = Dictionaries.SpellNameToSpellID[value.Text]; OnPropertyChanged(nameof(SelectedSpell1)); IsChanged(); @@ -278,7 +278,7 @@ public ItemImageModel SelectedSpell2 selectedSpell2 = value; SelectedSpell1 = RemoveDup(SelectedSpell2, SelectedSpell1); if(value != null) - SelectedBuild.spell.Spell1 = Dictionaries.SpellNameToSpellID[value.Text]; + _SelectedBuild.spell.Spell1 = Dictionaries.SpellNameToSpellID[value.Text]; OnPropertyChanged(nameof(SelectedSpell2)); IsChanged(); @@ -299,7 +299,7 @@ public string RuneName runeName = value; if(value != null) - SelectedBuild.rune.Name = value; + _SelectedBuild.rune.Name = value; OnPropertyChanged(nameof(RuneName)); IsChanged(); @@ -332,7 +332,7 @@ public ItemImageModel SelectedPath1 selectedPath1 = value; SelectedPath2 = RemoveDup(SelectedPath1, SelectedPath2); if(value != null) - SelectedBuild.rune.Path0 = DataConverter.PathNameToId(value.Text); + _SelectedBuild.rune.Path0 = DataConverter.PathNameToId(value.Text); OnPropertyChanged(nameof(SelectedPath1)); Path1_Changed(); @@ -341,16 +341,16 @@ public ItemImageModel SelectedPath1 } } - public ObservableCollection keystoneList = new ObservableCollection(); - public ObservableCollection KeystoneList + public ObservableCollection keystones = new ObservableCollection(); + public ObservableCollection Keystones { - get => keystoneList; + get => keystones; set { - if (keystoneList != value) + if (keystones != value) { - keystoneList = value; - OnPropertyChanged(nameof(KeystoneList)); + keystones = value; + OnPropertyChanged(nameof(Keystones)); } } } @@ -365,7 +365,7 @@ public ItemImageModel SelectedKeystone { selectedKeystone = value; if(value != null) - SelectedBuild.rune.Keystone = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Keystone = DataConverter.PerkNameToId(value.Text); OnPropertyChanged(nameof(SelectedKeystone)); IsChanged(); @@ -397,7 +397,7 @@ public ItemImageModel SelectedPerk1 { selectedPerk1 = value; if(value!=null) - SelectedBuild.rune.Slot1 = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Slot1 = DataConverter.PerkNameToId(value.Text); OnPropertyChanged(nameof(SelectedPerk1)); IsChanged(); @@ -429,7 +429,7 @@ public ItemImageModel SelectedPerk2 { selectedPerk2 = value; if(value != null) - SelectedBuild.rune.Slot2 = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Slot2 = DataConverter.PerkNameToId(value.Text); OnPropertyChanged(nameof(SelectedPerk2)); IsChanged(); @@ -461,7 +461,7 @@ public ItemImageModel SelectedPerk3 { selectedPerk3 = value; if(value!=null) - SelectedBuild.rune.Slot3 = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Slot3 = DataConverter.PerkNameToId(value.Text); OnPropertyChanged(nameof(SelectedPerk3)); IsChanged(); @@ -479,7 +479,7 @@ public ItemImageModel SelectedPath2 { selectedPath2 = value; if(value != null) - SelectedBuild.rune.Path1 = DataConverter.PathNameToId(value.Text); + _SelectedBuild.rune.Path1 = DataConverter.PathNameToId(value.Text); SelectedPath1 = RemoveDup(SelectedPath2, SelectedPath1); OnPropertyChanged(nameof(SelectedPath2)); @@ -513,7 +513,7 @@ public ItemImageModel SelectedPerk4 { selectedPerk4 = value; if(value!=null) - SelectedBuild.rune.Slot4 = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Slot4 = DataConverter.PerkNameToId(value.Text); SelectedPerk5 = RemoveDup(value, SelectedPerk5); OnPropertyChanged(nameof(SelectedPerk4)); @@ -547,7 +547,7 @@ public ItemImageModel SelectedPerk5 { selectedPerk5 = value; if(value != null) - SelectedBuild.rune.Slot5 = DataConverter.PerkNameToId(value.Text); + _SelectedBuild.rune.Slot5 = DataConverter.PerkNameToId(value.Text); SelectedPerk4 = RemoveDup(value, SelectedPerk4); OnPropertyChanged(nameof(SelectedPerk5)); @@ -580,7 +580,7 @@ public ItemImageModel SelectedOffense { selectedOffense = value; if (value != null) - SelectedBuild.rune.Shard0 = Dictionaries.ShardDescToShardId[value.Text]; + _SelectedBuild.rune.Shard0 = Dictionaries.ShardDescToShardId[value.Text]; SelectedPerk4 = RemoveDup(SelectedOffense, SelectedPerk4); OnPropertyChanged(nameof(SelectedOffense)); @@ -613,7 +613,7 @@ public ItemImageModel SelectedFlex { selectedFlex = value; if (value != null) - SelectedBuild.rune.Shard1 = Dictionaries.ShardDescToShardId[value.Text]; + _SelectedBuild.rune.Shard1 = Dictionaries.ShardDescToShardId[value.Text]; SelectedPerk4 = RemoveDup(SelectedFlex, SelectedPerk4); OnPropertyChanged(nameof(SelectedFlex)); @@ -646,7 +646,7 @@ public ItemImageModel SelectedDefense { selectedDefense = value; if (value != null) - SelectedBuild.rune.Shard2 = Dictionaries.ShardDescToShardId[value.Text]; + _SelectedBuild.rune.Shard2 = Dictionaries.ShardDescToShardId[value.Text]; SelectedPerk4 = RemoveDup(SelectedDefense, SelectedPerk4); OnPropertyChanged(nameof(SelectedDefense)); @@ -744,20 +744,20 @@ public string SaveInfo #endregion - private string ReferenceBuild; - private string SelectedChampionId; - public DefaultBuildConfig defaultBuildConfig; - private const string CreateNewKey = "Create New*"; - private ChampionBD SelectedBuild = new ChampionBD(); - private Dictionary SecondPath = new Dictionary(); + private string _ReferenceBuild; + private string _SelectedChampionId; + public DefaultBuildConfig _DefaultBuildConfig; + private const string _CreateNewKey = "Create New*"; + private ChampionBD _SelectedBuild = new ChampionBD(); + private Dictionary _SecondPath = new Dictionary(); public BuildEditorViewModel() { Init(); PathModel.Init(); - SaveCommand = new Command(action => { SaveConfigExecute(); }); - SetAsDefaultCommand = new Command(action => { SetAsDefaultExecute(); }); - ClearDefaultSourceCommand = new Command(action => { ClearDefaultSourceExecute(); }); + SaveCommand = new Command(o => { SaveConfigExecute(); }); + SetAsDefaultCommand = new Command(o => { SetAsDefaultExecute(); }); + ClearDefaultSourceCommand = new Command(o => { ClearDefaultSourceExecute(); }); } public async void Init() @@ -801,24 +801,24 @@ private async void Data_Changed() saveInfo = null; var gameMode = gm(); - _buildsName.Add(CreateNewKey); - SelectedChampionId = DataConverter.ChampionNameToId(SelectedChampion); + _buildsName.Add(_CreateNewKey); + _SelectedChampionId = DataConverter.ChampionNameToId(SelectedChampion); // Load in default build config - defaultBuildConfig = new DefaultBuildConfig(); + _DefaultBuildConfig = new DefaultBuildConfig(); - if (File.Exists(defConfigPath(SelectedChampionId))) defaultBuildConfig = getDefaultBuildConfig(SelectedChampionId); + if (File.Exists(defConfigPath(_SelectedChampionId))) _DefaultBuildConfig = getDefaultBuildConfig(_SelectedChampionId); - var customBuildPath = Main.localBuild.BuildsFolder(SelectedChampionId, gameMode); - var fullPath = $"{customBuildPath}\\{defaultBuildConfig.getDefaultConfig(gameMode)}"; + var customBuildPath = Main.localBuild.BuildsFolder(_SelectedChampionId, gameMode); + var fullPath = $"{customBuildPath}\\{_DefaultBuildConfig.getDefaultConfig(gameMode)}"; if(!File.Exists(fullPath)) - defaultBuildConfig.resetDefaultConfig(gameMode); + _DefaultBuildConfig.resetDefaultConfig(gameMode); - SlDefaultConfig = defaultBuildConfig.getDefaultConfig(gameMode); + SlDefaultConfig = _DefaultBuildConfig.getDefaultConfig(gameMode); await Task.Run(() => { - foreach (var path in Main.localBuild.GetBuildFiles(SelectedChampionId, gameMode)) + foreach (var path in Main.localBuild.GetBuildFiles(_SelectedChampionId, gameMode)) _buildsName.Add(Path.GetFileName(path)); foreach (var spell in Dictionaries.SpellNameToSpellKey) @@ -838,7 +838,7 @@ await Task.Run(() => { else { SelectedGameMode = null; - SelectedBuild = null; + _SelectedBuild = null; BuildsName = null; saveInfo = null; ClearSmallInfo(); @@ -848,11 +848,11 @@ await Task.Run(() => { public async void FetchBuild() { if(!string.IsNullOrEmpty(SelectedBuildName) - && !SelectedBuildName.Equals(CreateNewKey)) + && !SelectedBuildName.Equals(_CreateNewKey)) { saveInfo = null; await Task.Run(() => { - foreach (var path in Main.localBuild.GetBuildFiles(SelectedChampionId, gm())) + foreach (var path in Main.localBuild.GetBuildFiles(_SelectedChampionId, gm())) { if (Path.GetFileName(path) == SelectedBuildName) { @@ -862,9 +862,9 @@ await Task.Run(() => { { var jsonContent = sr.ReadToEnd(); FileName = Path.GetFileNameWithoutExtension(path); - SelectedBuild = JsonConvert.DeserializeObject(jsonContent); - ReferenceBuild = jsonContent; - LoadBuild(SelectedBuild); + _SelectedBuild = JsonConvert.DeserializeObject(jsonContent); + _ReferenceBuild = jsonContent; + LoadBuild(_SelectedBuild); } } catch { } @@ -874,7 +874,7 @@ await Task.Run(() => { }); } else if(!string.IsNullOrEmpty(SelectedBuildName) - && SelectedBuildName.Equals(CreateNewKey)) { + && SelectedBuildName.Equals(_CreateNewKey)) { ClearProfile(); saveInfo = "New* Unsaved"; } @@ -886,7 +886,7 @@ private void Path1_Changed() Perk1List = new ObservableCollection(); Perk2List = new ObservableCollection(); Perk3List = new ObservableCollection(); - KeystoneList = new ObservableCollection(); + Keystones = new ObservableCollection(); if (SelectedPath1 != null) { @@ -908,7 +908,7 @@ private void Path1_Changed() switch (i) { case 0: - KeystoneList.Add(model); + Keystones.Add(model); break; case 1: Perk1List.Add(model); @@ -932,11 +932,12 @@ private void Path1_Changed() private void Path2_Changed() { Perk5List = new ObservableCollection(); + Perk4List = new ObservableCollection(); var _perk4list = new ObservableCollection(); if (SelectedPath2 != null) { - secondSlot = SecondPath[SelectedPath2.Text]; + secondSlot = _SecondPath[SelectedPath2.Text]; foreach (var perk in secondSlot) { if(!string.IsNullOrEmpty(perk)) @@ -1005,7 +1006,7 @@ private void LoadBuild(ChampionBD championBuild) { RuneName = championBuild.rune.Name; SelectedPath1 = PathList.SingleOrDefault(p => p.Text == DataConverter.PathIdToName(championBuild.rune.Path0)); - SelectedKeystone = KeystoneList.SingleOrDefault(k => k.Text == DataConverter.PerkIdToName(championBuild.rune.Keystone)); + SelectedKeystone = Keystones.SingleOrDefault(k => k.Text == DataConverter.PerkIdToName(championBuild.rune.Keystone)); SelectedPerk1 = Perk1List.SingleOrDefault(p => p.Text == DataConverter.PerkIdToName(championBuild.rune.Slot1)); SelectedPerk2 = Perk2List.SingleOrDefault(p => p.Text == DataConverter.PerkIdToName(championBuild.rune.Slot2)); SelectedPerk3 = Perk3List.SingleOrDefault(p => p.Text == DataConverter.PerkIdToName(championBuild.rune.Slot3)); @@ -1029,15 +1030,15 @@ private void LoadBuild(ChampionBD championBuild) private void IsChanged() { - var sBuild = JsonConvert.SerializeObject(SelectedBuild, Formatting.Indented); + var sBuild = JsonConvert.SerializeObject(_SelectedBuild, Formatting.Indented); if(SelectedGameMode != null && SelectedBuildName != null) { - if ((!sBuild.Equals(ReferenceBuild) || + if ((!sBuild.Equals(_ReferenceBuild) || !Path.GetFileNameWithoutExtension(SelectedBuildName).Equals(FileName)) - && !SelectedBuildName.Equals(CreateNewKey)) + && !SelectedBuildName.Equals(_CreateNewKey)) saveInfo = "*Unsaved"; - else if (SelectedBuildName.Equals(CreateNewKey)) + else if (SelectedBuildName.Equals(_CreateNewKey)) saveInfo = "New* Unsaved"; else saveInfo = null; } @@ -1045,11 +1046,11 @@ private void IsChanged() private void InitSecondPath() { - SecondPath.Add("Domination", PathModel.Domination); - SecondPath.Add("Sorcery", PathModel.Sorcery); - SecondPath.Add("Precision", PathModel.Precision); - SecondPath.Add("Inspiration", PathModel.Inspiration); - SecondPath.Add("Resolve", PathModel.Resolve); + _SecondPath.Add("Domination", PathModel.Domination); + _SecondPath.Add("Sorcery", PathModel.Sorcery); + _SecondPath.Add("Precision", PathModel.Precision); + _SecondPath.Add("Inspiration", PathModel.Inspiration); + _SecondPath.Add("Resolve", PathModel.Resolve); } private void InitShards() @@ -1084,7 +1085,7 @@ public string RemoveDup(string s1, string s2) { if (s1 == s2) return null; - else return s2; + return s2; } else return s2; } @@ -1095,7 +1096,7 @@ public ItemImageModel RemoveDup(ItemImageModel s1, ItemImageModel s2) { if (s1.Text == s2.Text) return null; - else return s2; + return s2; } else return s2; } @@ -1110,8 +1111,8 @@ public void ClearSmallInfo() public void ClearProfile() { SelectedBuildName = null; - ReferenceBuild = null; - SelectedBuild = new ChampionBD(); + _ReferenceBuild = null; + _SelectedBuild = new ChampionBD(); FileName = null; RuneName = null; SelectedSpell1 = null; diff --git a/LoL Assist/ViewModel/ConfigViewModel.cs b/LoL Assist/ViewModel/ConfigViewModel.cs index 3cbb5f2..ddeb840 100644 --- a/LoL Assist/ViewModel/ConfigViewModel.cs +++ b/LoL Assist/ViewModel/ConfigViewModel.cs @@ -116,8 +116,8 @@ public bool LowSpecMode ConfigModel.config.LowSpecMode = value; if (ConfigModel.config.LowSpecMode) - ConfigModel.config.MonitoringDelay = 550; - else ConfigModel.config.MonitoringDelay = 300; + ConfigModel.config.MonitoringDelay = 300; + else ConfigModel.config.MonitoringDelay = 250; OnPropertyChanged(nameof(LowSpecMode)); } @@ -207,18 +207,14 @@ public bool UpdateOnStartup public ConfigViewModel() { - //themeList.Add("Default"); - //themeList.Add("League of Legends"); Update(); - ShowFolderInExCommand = new Command(action => ShowFolderExecute()); } private void ShowFolderExecute() { var path = Global.libraryFolder; - if(Directory.Exists(path)) - Process.Start(path); + if(Directory.Exists(path)) Process.Start(path); } public void Update() @@ -237,21 +233,6 @@ public void Update() BuildCache = ConfigModel.config.BuildCache; Global.Config.caching = BuildCache; UpdateOnStartup = ConfigModel.config.UpdateOnStartup; - - //bool isThemeFound = false; - //foreach (var item in themeList) - //{ - // if (ConfigModel.config.Theme.Equals(item)) - // { - // isThemeFound = true; - // break; - // } - //} - - //if(isThemeFound) - // SelectedTheme = ConfigModel.config.Theme; - - //Utils.SwitchTheme(ConfigModel.config.Theme); } #region Space junk public event PropertyChangedEventHandler PropertyChanged; diff --git a/LoL Assist/ViewModel/MainViewModel.cs b/LoL Assist/ViewModel/MainViewModel.cs index 57deca0..c1be6a7 100644 --- a/LoL Assist/ViewModel/MainViewModel.cs +++ b/LoL Assist/ViewModel/MainViewModel.cs @@ -26,11 +26,38 @@ namespace LoL_Assist_WAPP.ViewModel { public class MainViewModel : INotifyPropertyChanged { - private const string disconnected = "Disconnected"; + private const string _disconnected = "Disconnected"; #region Miscellaneous + + #region Commands public ICommand DebugCommand { get; } public ICommand ManualImportCommand { get; } + #region Window Commands + public ICommand MoveWindowCommand { get; } + public ICommand ShutdownAppCommand { get; } + public ICommand MinimizeWindowCommand { get; } + public ICommand ShowBuildEditorWindowCommand { get; } + + private bool topmost; + public bool Topmost + { + get => topmost; + set + { + if (topmost != value) + { + topmost = value; + OnPropertyChanged(nameof(Topmost)); + Application.Current.Dispatcher.Invoke(() => { + Application.Current.MainWindow.Activate(); // Fix for topmost issue + }); + } + } + } + #endregion + #endregion + private Visibility manualImportVisibility = Visibility.Collapsed; public Visibility ManualImportVisibility { @@ -45,18 +72,15 @@ public Visibility ManualImportVisibility } } - private SolidColorBrush connectionStatusForeground; - - public SolidColorBrush ConnectionStatusForeground + private object topMostContent = null; + public object TopMostContent { - get => connectionStatusForeground; + get => topMostContent; set { - if (connectionStatusForeground != value) - { - connectionStatusForeground = value; - OnPropertyChanged(nameof(ConnectionStatusForeground)); - } + Console.WriteLine("Content set: " + value); + topMostContent = value; + OnPropertyChanged(nameof(TopMostContent)); } } @@ -90,11 +114,54 @@ public string ChampionName } } } + + private List roles; + public List Roles + { + get => roles; + set + { + if (roles != value) + { + roles = value; + OnPropertyChanged(nameof(Roles)); + } + } + } + + private ItemImageModel selectedRole; + public ItemImageModel SelectedRole + { + get => selectedRole; + set + { + if (selectedRole != value) + { + ReImport(); + selectedRole = value; + OnPropertyChanged(nameof(SelectedRole)); + } + } + } + + private Visibility roleSelectVisibility = Visibility.Collapsed; + public Visibility RoleSelectVisibility + { + get => roleSelectVisibility; + set + { + if (roleSelectVisibility != value) + { + roleSelectVisibility = value; + OnPropertyChanged(nameof(RoleSelectVisibility)); + } + } + } #endregion #region Status - private string gMode; - public string GMode + private GameMode gMode; + public GameMode GMode { get => gMode; set @@ -121,7 +188,21 @@ public string WorkingStatus } } - private string connectionStatus = disconnected; + private Visibility workingStatusVisibility; + public Visibility WorkingStatusVisibility + { + get => workingStatusVisibility; + set + { + if (workingStatusVisibility != value) + { + workingStatusVisibility = value; + OnPropertyChanged(nameof(WorkingStatusVisibility)); + } + } + } + + private string connectionStatus = _disconnected; public string ConnectionStatus { get => connectionStatus; @@ -184,6 +265,19 @@ public Visibility WarningGridVisibility } } + private Visibility championContainerVisibility = Visibility.Collapsed; + public Visibility ChampionContainerVisibility + { + get => championContainerVisibility; + set + { + if (championContainerVisibility != value) + { + championContainerVisibility = value; + OnPropertyChanged(nameof(ChampionContainerVisibility)); + } + } + } private string warningCount; public string WarningCount @@ -203,33 +297,58 @@ public string WarningCount } #endregion - private bool IsBusy = false; - private bool IsLoLMonitoringPuased = false; - private const string ProccName = "LeagueClient"; - private GameMode CurrentGameMode = GameMode.NONE; - private Task CurrentChampionBuild = null; - private StringBuilder Warnings = new StringBuilder(); - private string CurrentTime + private bool _IsBusy = false; + private bool _IsLoLMonitoringPuased = false; + private const string _ProccName = "LeagueClient"; + private GameMode _CurrentGameMode = GameMode.NONE; + private Task _CurrentChampionBuild = null; + private StringBuilder _Warnings = new StringBuilder(); + private string GetCurrentTime { get { return $"[{DateTime.Now:hh:mm:ss}]"; } } public MainViewModel() { - GMode = $"Game Mode: {CurrentGameMode}"; - DebugCommand = new Command(async action => { await DebugExecute(); }); - ManualImportCommand = new Command(ManualImportExecute); - InitLoLA(); - } + InitTrayIcon(); + GMode = _CurrentGameMode; + ManualImportCommand = new Command(o => { ReImport(); }); + DebugCommand = new Command(async o => { await DebugExecute(); }); - private async void InitLoLA() - { - LogService.Clear(); + ShutdownAppCommand = new Command(o => { ShutdownAppExecute(); }); + ShowBuildEditorWindowCommand = new Command(o => { ShowBuildEditorWindow(); }); + MoveWindowCommand = new Command(o => { Application.Current.MainWindow.DragMove(); }); + MinimizeWindowCommand = new Command(o => { Application.Current.MainWindow.WindowState = WindowState.Minimized; }); + + WorkingStatus = $"Clearing old logs..."; + LogService.Clear(); // remove old log file(LoLA.log) WorkingStatus = "Loading in configuration..."; ConfigModel.LoadConfig(); + + ShowPatchNotes(ConfigModel.config.DoNotShowPatch); + + Roles = new List() { // Roles XD + new ItemImageModel(){Text = "Default", Image="pack://application:,,,/Resources/Fill.png"}, + new ItemImageModel(){Text = "Top", Image="pack://application:,,,/Resources/Top.png"}, + new ItemImageModel(){Text = "Jungle", Image="pack://application:,,,/Resources/Jungle.png"}, + new ItemImageModel(){Text = "Mid", Image="pack://application:,,,/Resources/Mid.png"}, + new ItemImageModel(){Text = "ADC", Image="pack://application:,,,/Resources/ADC.png"}, + new ItemImageModel(){Text = "Support", Image="pack://application:,,,/Resources/Support.png"}}; + + InitLoLA(); + } - if(ConfigModel.config.UpdateOnStartup) + private void ShowBuildEditorWindow() + { + var window = new BuildEditorWindow(); + window.Owner = Application.Current.MainWindow; + window.ShowDialog(); + } + + private async void InitLoLA() + { + if (ConfigModel.config.UpdateOnStartup) { WorkingStatus = "Checking for updates..."; await Update.Start(); @@ -249,28 +368,135 @@ private async void InitLoLA() champMonitor.ChampionChanged += Champion_Changed; champMonitor.MonitorDelay = ConfigModel.config.MonitoringDelay; - IsLoLMonitoringPuased = true; + _IsLoLMonitoringPuased = true; var lolMonitorThread = new Thread(LoLMonitor); lolMonitorThread.Start(); phaseMonitor.PhaseChanged += Phase_Changed; ResetStatus(); - await LCUWrapper.GetRunePagesAsync(); + // await LCUWrapper.GetRunePagesAsync(); } + private async void ImportBuilds(string championName) + { + if (!string.IsNullOrEmpty(championName)) + { + ClearChamp(false); + + while (_IsBusy) + Thread.Sleep(ConfigModel.config.MonitoringDelay); + + _IsBusy = true; + bool[] IsErr = { false, false }; + Stopwatch sw = Stopwatch.StartNew(); + ChampionName = championName; + try + { + if (ConfigModel.config.AutoRunes || ConfigModel.config.AutoSpells) + { + List tasks = new List(); + string CurrentRole = string.Empty; + + var gm = _CurrentGameMode; + var cBD = _CurrentChampionBuild; + + if (gm.Equals(GameMode.CLASSIC) || gm.Equals(GameMode.PRACTICETOOL)) + CurrentRole = SelectedRole.Text.Replace("Default", string.Empty).ToLower(); + + var CurrentChampionId = DataConverter.ChampionNameToId(championName); + SetImportStatus("Fetching Runes & Spells..."); + sw.Start(); + + if (!ConfigModel.config.CustomRunesSpells) + tasks.Add(cBD = Main.RequestBuildsData(CurrentChampionId, gm, BuildsProvider.Metasrc, CurrentRole)); + else + { + var buildName = GetLocalBuildName(CurrentChampionId, gm); + + if (buildName == ConfigModel.DefaultSource) + tasks.Add(cBD = Main.RequestBuildsData(CurrentChampionId, gm, BuildsProvider.Metasrc, CurrentRole)); + else + tasks.Add(cBD = Main.RequestBuildsData(CurrentChampionId, gm, + BuildsProvider.Local, Path.GetFileNameWithoutExtension(buildName))); + } + + tasks.Add(Task.Run(() => ChampionImage = DataDragonWrapper.GetChampionImage(CurrentChampionId, Global.Config.dDragonPatch).Result)); + Parallel.ForEach(tasks, task => { Task.Run(() => task).Wait(); }); + + SetImportStatus($"Importing {FixedName(ChampionName)} Runes & Spells..."); + + RuneObj RB = (await cBD)?.rune; + SpellObj SC = (await cBD)?.spell; + + if (cBD != null) + { + var currentPerks = await LCUWrapper.GetCurrentRunePageAsync(); + List ImportTasks = new List(); + if (ConfigModel.config.AutoRunes) + ImportTasks.Add(SetRuneAsync(RB, currentPerks)); + + if (ConfigModel.config.AutoSpells) + ImportTasks.Add(ImportSpellsAsync(SC, gm)); + + int i = 0; + Parallel.ForEach(ImportTasks, async task => { + try { await task; IsErr[i] = false; } + catch { IsErr[i] = true; } + i++; + }); + currentPerks = null; + } + } + } + catch + { + WarningStatus = $"{GetCurrentTime} Failed to import Runes & Spells."; + _Warnings.AppendLine($"{GetCurrentTime} Failed to import {FixedName(ChampionName)} Runes & Spells."); + SetImportStatus("Uh oh, LoL Assist failed to import Runes & Spells", LogType.EROR); + } + finally + { + sw.Stop(); + if (IsErr[0]) + _Warnings.AppendLine($"{GetCurrentTime} Failed to import {FixedName(ChampionName)} Runes."); + else if (IsErr[1]) + _Warnings.AppendLine($"{GetCurrentTime} Failed to import {FixedName(ChampionName)} Spells."); + else if (IsErr[0] && IsErr[1]) + SetImportStatus($"Uh Oh, something went wrong.\ntry deleting {FixedName(ChampionName)} data might fix the issue", LogType.EROR); + else + SetImportStatus($"Runes & Spells has been imported successfully! Elapsed [{sw.ElapsedMilliseconds}ms]"); + WarningStatus = _Warnings.ToString().TrimEnd(Environment.NewLine.ToCharArray()); + } + _IsBusy = false; + } + } private async void Phase_Changed(object sender, PhaseMonitor.PhaseChangedArgs e) { - CurrentGameMode = await LCUWrapper.GetCurrentGameModeAsync(); + Topmost = e.currentPhase == Phase.ChampSelect || e.currentPhase == Phase.ReadyCheck; + _CurrentGameMode = await LCUWrapper.GetCurrentGameModeAsync(); if (e.currentPhase != Phase.InProgress) - GMode = $"Game Mode: {CurrentGameMode}"; + { + GMode = _CurrentGameMode; + DispatcherInvoke(() => { // Needs to be invoke to fix delay issue + if (_CurrentGameMode == GameMode.CLASSIC + || _CurrentGameMode == GameMode.PRACTICETOOL) + { + SelectedRole = Roles[0]; + RoleSelectVisibility = Visibility.Visible; + } + else RoleSelectVisibility = Visibility.Collapsed; + }); + } switch (e.currentPhase) { case Phase.ChampSelect: - ImportStatus = "Selecting a champion..."; - ManualImportVisibility = Visibility.Visible; + DispatcherInvoke(() => { + ImportStatus = "Selecting a champion..."; + ManualImportVisibility = Visibility.Visible; + }); break; case Phase.None: case Phase.Lobby: @@ -282,12 +508,19 @@ private async void Phase_Changed(object sender, PhaseMonitor.PhaseChangedArgs e) ConnectionStatus = await GetSummonerInfo(); break; case Phase.InProgress: - ImportStatus = "Game in progress..."; - ManualImportVisibility = Visibility.Collapsed; + DispatcherInvoke(() => { + ImportStatus = "Game in progress..."; + ManualImportVisibility = Visibility.Collapsed; + }); break; case Phase.Matchmaking: - ClearChamp(); - ImportStatus = "Queueing..."; + DispatcherInvoke(() => { + ClearChamp(); + ImportStatus = "Queueing..."; + }); + break; + case Phase.ReadyCheck: + SetTopMostContent(new MatchFoundViewModel()); break; } //var page = await LCUWrapper.GetCurrentRunePageAsync(); @@ -296,28 +529,33 @@ private async void Phase_Changed(object sender, PhaseMonitor.PhaseChangedArgs e) // Console.WriteLine(string.Format("ID: {0}", pIds)); } - private void Champion_Changed(object sender, ChampionMonitor.ChampionChangedArgs e) => ImportBuilds(e.championName); - private async void ManualImportExecute(object e) => ImportBuilds(await LCUWrapper.GetCurrentChampionAsyncV2()); + private void DispatcherInvoke(Action action) => Application.Current.Dispatcher.Invoke(action); + #region LoL Checker + // Checks for LeagueClient process and get summoner info public void LoLMonitor() { CheckLoL(); while (true) { - if (!IsLoLMonitoringPuased) + if (!_IsLoLMonitoringPuased) { - if (Process.GetProcessesByName(ProccName).Length == 0) + if (Process.GetProcessesByName(_ProccName).Length == 0) { - ConnectionStatus = disconnected; - IsLoLMonitoringPuased = true; + DispatcherInvoke(() => { + WorkingStatusVisibility = Visibility.Visible; + ChampionContainerVisibility = Visibility.Collapsed; + }); + + ConnectionStatus = _disconnected; + _IsLoLMonitoringPuased = true; CheckLoL(); } } Thread.Sleep(ConfigModel.config.MonitoringDelay * 2); } } - public async void CheckLoL() { string summonerInfo; @@ -328,108 +566,123 @@ public async void CheckLoL() Thread.Sleep(ConfigModel.config.MonitoringDelay * 2); } while (string.IsNullOrEmpty(summonerInfo)); + DispatcherInvoke(() => { + WorkingStatusVisibility = Visibility.Collapsed; + ChampionContainerVisibility = Visibility.Visible; + }); + WorkingStatus = string.Empty; ConnectionStatus = summonerInfo; - - IsLoLMonitoringPuased = false; + _IsLoLMonitoringPuased = false; } + #endregion - private async void ImportBuilds(string championName) - { - if (!string.IsNullOrEmpty(championName)) - { - ClearChamp(false); - - while (IsBusy) - Thread.Sleep(ConfigModel.config.MonitoringDelay); - - IsBusy = true; - bool[] IsErr = { false, false }; - Stopwatch sw = Stopwatch.StartNew(); - try - { - if (ConfigModel.config.AutoRunes || ConfigModel.config.AutoSpells) - { - List tasks = new List(); - - ChampionName = championName; - var CurrentChampionId = DataConverter.ChampionNameToId(ChampionName); - - SetImportStatus("Fetching Runes & Spells..."); - - sw.Start(); + private void ShutdownAppExecute() => ShowMsgBox(new Action(() => { Application.Current.MainWindow.Close(); }), + msg: "Are you sure you want to exit LoL Assist?", width: 230, height: 150); + private void ShowPatchNotes(bool doNotShow) { if (!doNotShow) SetTopMostContent(new PatchViewModel()); } + private void Champion_Changed(object sender, ChampionMonitor.ChampionChangedArgs e) => ImportBuilds(e.championName); + private async void ReImport() => await Task.Run(async () => { ImportBuilds(await LCUWrapper.GetCurrentChampionAsyncV2()); }); - if(!ConfigModel.config.CustomRunesSpells) - tasks.Add(CurrentChampionBuild = Main.RequestBuildsData(CurrentChampionId, CurrentGameMode, BuildsProvider.Metasrc)); - else - { - var buildName = GetLocalBuildName(CurrentChampionId, CurrentGameMode); + #region Tray Icon + private void InitTrayIcon() + { + string[] menus = new string[] { "Exit", "Show", "Patch Notes", "Minimize to Tray" }; + var trayIcon = new System.Windows.Forms.NotifyIcon(); + var menuList = new List(); + var menuContainer = new System.Windows.Forms.ContextMenu(); - if (buildName == ConfigModel.DefaultSource) - tasks.Add(CurrentChampionBuild = Main.RequestBuildsData(CurrentChampionId, CurrentGameMode, BuildsProvider.Metasrc)); - else - tasks.Add(CurrentChampionBuild = Main.RequestBuildsData(CurrentChampionId, CurrentGameMode, - BuildsProvider.Local, Path.GetFileNameWithoutExtension(buildName))); - } + for (int i = 0; i < menus.Length; i++) + { + var item = new System.Windows.Forms.MenuItem() { + Index = i, + Text = menus[i] + }; - tasks.Add(Task.Run(() => ChampionImage = DataDragonWrapper.GetChampionImage(CurrentChampionId, Global.Config.dDragonPatch).Result)); - Parallel.ForEach(tasks, task => { Task.Run(() => task).Wait(); }); + item.Click += new EventHandler(menuItem_Click); + menuList.Add(item); + } - SetImportStatus($"Importing {FixedName(ChampionName)} Runes & Spells..."); + menuContainer.MenuItems.AddRange(menuList.ToArray()); - RuneObj RB = (await CurrentChampionBuild)?.rune; - SpellObj SC = (await CurrentChampionBuild)?.spell; + using(var stream = Application.GetResourceStream(new Uri("pack://application:,,,/icon.ico")).Stream) + { + trayIcon.Icon = new System.Drawing.Icon(stream); + } - if (CurrentChampionBuild != null) - { - var currentPerks = await LCUWrapper.GetCurrentRunePageAsync(); - List ImportTasks = new List(); - if (ConfigModel.config.AutoRunes) - ImportTasks.Add(SetRuneAsync(RB, currentPerks)); + trayIcon.Visible = true; + trayIcon.ContextMenu = menuContainer; + trayIcon.DoubleClick += (o, args) => ShowMainWindow(); + trayIcon.Text = $"LoL Assist v{ConfigModel.version}"; + + // Dispose tray icon on closed + Application.Current.MainWindow.Closed += (o, args) => { + trayIcon.Icon = null; + trayIcon.Dispose(); + Environment.Exit(0); + }; + } - if (ConfigModel.config.AutoSpells) - ImportTasks.Add(ImportSpellsAsync(SC, CurrentGameMode)); + private void menuItem_Click(object sender, EventArgs e) + { + var menuItem = sender as System.Windows.Forms.MenuItem; + switch(menuItem.Text) + { + case "Exit": + Application.Current.MainWindow.Close(); + break; + case "Show": + ShowMainWindow(); + break; + case "Patch Notes": + ShowMainWindow(); + ShowPatchNotes(false); + break; + case "Minimize to Tray": + Application.Current.MainWindow.ShowInTaskbar = false; + Application.Current.MainWindow.WindowState = WindowState.Minimized; + break; + } + } - int i = 0; - Parallel.ForEach(ImportTasks, async task => { - try { await task; IsErr[i] = false; } - catch { IsErr[i] = true; } i++; - }); - currentPerks = null; - } - } - } - catch - { - WarningStatus = $"{CurrentTime} Failed to import Runes & Spells."; - Warnings.AppendLine($"{CurrentTime} Failed to import {FixedName(ChampionName)} Runes & Spells."); - SetImportStatus("Uh oh, LoL Assist failed to import Runes & Spells", LogType.EROR); - } - finally - { - sw.Stop(); - if (IsErr[0]) - Warnings.AppendLine($"{CurrentTime} Failed to import {FixedName(ChampionName)} Runes."); - else if (IsErr[1]) - Warnings.AppendLine($"{CurrentTime} Failed to import {FixedName(ChampionName)} Spells."); - else if (IsErr[0] && IsErr[1]) - SetImportStatus($"Uh Oh, something went wrong.\ntry deleting {FixedName(ChampionName)} data might fix the issue", LogType.EROR); - else - SetImportStatus($"Runes & Spells has been imported successfully! Elapsed [{sw.ElapsedMilliseconds}ms]"); + private void ShowMainWindow() + { + Application.Current.MainWindow.Show(); + Application.Current.MainWindow.ShowInTaskbar = true; + Application.Current.MainWindow.WindowState = WindowState.Normal; - WarningStatus = Warnings.ToString().TrimEnd(Environment.NewLine.ToCharArray()); - } - IsBusy = false; - } + Application.Current.MainWindow.Activate(); } + #endregion + #region Debug D: + private int _debugI = 0; public async Task DebugExecute() { - LogService.Log(LogService.Model("clicked", "Debug", LogType.DBUG)); - await Main.RequestBuildsData("Aatrox", GameMode.URF, BuildsProvider.Metasrc); + LogService.Log(LogService.Model($"--------------attempt-{_debugI}", "Debug", LogType.DBUG)); + //* Debug Code *// + //await Main.RequestBuildsData("Aatrox", GameMode.URF, BuildsProvider.Metasrc); + Console.WriteLine(await LCUWrapper.GetCurrentSessionAsync()); + _debugI++; } + #endregion #region Space junk + private async void SetTopMostContent(object obj) + { + TopMostContent = null; + await Task.Delay(1); // Fix + TopMostContent = obj; + } + private void ShowMsgBox(Action action, string msg, double width = 330, double height = 220) + { + SetTopMostContent(new MessageBoxViewModel() + { + message = msg, + width = width, + height = height, + action = () => { action.Invoke(); } + }); + } private async Task GetSummonerInfo() { var summonerInfo = await LCUWrapper.GetCurrentSummonerAsync(); @@ -441,13 +694,11 @@ private async Task GetSummonerInfo() return $"Name: {summonerInfo?.displayName} | Lvl {summonerInfo?.summonerLevel}"; } - private void SetImportStatus(string msg, LogType logType = LogType.INFO) { - ImportStatus = msg; + DispatcherInvoke(() => { ImportStatus = msg; }); Log(msg, logType); } - private void ClearChamp(bool hideManualImport = true) { ChampionImage = null; @@ -456,7 +707,6 @@ private void ClearChamp(bool hideManualImport = true) if (hideManualImport) ManualImportVisibility = Visibility.Hidden; } - private void ResetStatus() { ClearChamp(); diff --git a/LoL Assist/ViewModel/MatchFoundViewModel.cs b/LoL Assist/ViewModel/MatchFoundViewModel.cs new file mode 100644 index 0000000..38afd0e --- /dev/null +++ b/LoL Assist/ViewModel/MatchFoundViewModel.cs @@ -0,0 +1,162 @@ +using System.Windows.Controls; +using System.Threading.Tasks; +using LoL_Assist_WAPP.Model; +using System.ComponentModel; +using System.Windows.Input; +using System.Threading; +using LoLA.LCU.Events; +using LoLA.LCU; +using System; +using System.Windows; + +namespace LoL_Assist_WAPP.ViewModel +{ + public class MatchFoundViewModel : INotifyPropertyChanged + { + #region Commands + public ICommand AcceptMatchCommand { get; } + public ICommand DeclineMatchCommand { get; } + + private ICommand hideUserControlCommand; + public ICommand HideUserControlCommand + { + get + { + if (hideUserControlCommand == null) + { + hideUserControlCommand = new Command(p => HideUserControl(p)); + } + return hideUserControlCommand; + } + } + #endregion + + private string timeoutTimer; + public string TimeoutTimer + { + get => timeoutTimer; + set + { + if (timeoutTimer != value) + { + timeoutTimer = value; + OnPropertyChanged(nameof(TimeoutTimer)); + } + } + } + + private string acceptStatus = "Auto Accept in 5s"; + public string AcceptStatus + { + get => acceptStatus; + set + { + if (acceptStatus != value) + { + acceptStatus = value; + OnPropertyChanged(nameof(AcceptStatus)); + } + } + } + + private double? timeoutValue; + public double? TimeoutValue + { + get => timeoutValue; + set + { + if (timeoutValue != value) + { + timeoutValue = value; + OnPropertyChanged(nameof(TimeoutValue)); + } + } + } + + private Visibility matchfoundVisibility; + public Visibility MatchfoundVisibility + { + get => matchfoundVisibility; + set + { + if (matchfoundVisibility != value) + { + matchfoundVisibility = value; + OnPropertyChanged(nameof(MatchfoundVisibility)); + } + } + } + + private readonly int _autoAcceptTimer = 5; + private bool _isMatchFound = false; + private bool _isDecided = false; + public MatchFoundViewModel() + { + MatchFound(); + AcceptMatchCommand = new Command(o => { Accept(); }); + DeclineMatchCommand = new Command(o => { Decline(); }); + LoLAWrapper.phaseMonitor.PhaseChanged += Phase_Changed; + } + + private void Phase_Changed(object sender, PhaseMonitor.PhaseChangedArgs e) + { + if (e.currentPhase != Phase.ReadyCheck) HideMatchFound(); + } + + private void HideMatchFound() + { + MatchfoundVisibility = Visibility.Collapsed; + _isMatchFound = false; + _isDecided = false; + } + + private async void MatchFound() + { + await Task.Run(async() => { + _isMatchFound = true; + _isDecided = false; + + ConsoleBeep(); + + while (_isMatchFound) + { + var matchInfo = await LCUWrapper.GetMatchmakingInfo(); + var timer = matchInfo?.timer == null ? 0 : (int)matchInfo.timer; + + // update timer UI + TimeoutTimer = $"{10 - timer}s"; + if (!_isDecided) + { + if (ConfigModel.config.AutoAccept) + { + if (_autoAcceptTimer <= timer) Accept(); + else AcceptStatus = $"Auto Accept in {_autoAcceptTimer - timer}s"; + } else AcceptStatus = "Auto Accept is disabled"; + } + + if (matchInfo?.playerResponse != "None") + AcceptStatus = matchInfo.playerResponse; + + TimeoutValue = timer * 10; + + //if (timer == 10) HideMatchFound(); + Thread.Sleep(1000); + } + }); + } + + private async void Accept() => _isDecided = await LCUWrapper.AcceptMatchmakingAsync(); + private async void Decline() => _isDecided = await LCUWrapper.DeclineMatchmakingAsync(); + + private void ConsoleBeep() // Beep sound + { + Console.Beep(); + Console.Beep(); + } + + private void HideUserControl(object p) => Utils.Animation.FadeOut(p as UserControl); + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/LoL Assist/ViewModel/MessageBoxViewModel.cs b/LoL Assist/ViewModel/MessageBoxViewModel.cs new file mode 100644 index 0000000..0187d52 --- /dev/null +++ b/LoL Assist/ViewModel/MessageBoxViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel; + +namespace LoL_Assist_WAPP.ViewModel +{ + internal class MessageBoxViewModel : INotifyPropertyChanged + { + public Action action { get; set; } + public string message { get; set; } + public string title { get; set; } + public double width { get; set; } + public double height { get; set; } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/LoL Assist/ViewModel/PatchViewModel.cs b/LoL Assist/ViewModel/PatchViewModel.cs index 5d0638b..857f814 100644 --- a/LoL Assist/ViewModel/PatchViewModel.cs +++ b/LoL Assist/ViewModel/PatchViewModel.cs @@ -1,11 +1,30 @@ using LoL_Assist_WAPP.Model; using System.ComponentModel; +using System.Windows.Input; using System.Text; +using System; +using System.Windows.Controls; +using System.Diagnostics; namespace LoL_Assist_WAPP.ViewModel { internal class PatchViewModel : INotifyPropertyChanged { + public ICommand RunUrlCommand { get; } + + private ICommand hideUserControlCommand; + public ICommand HideUserControlCommand + { + get + { + if (hideUserControlCommand == null) + { + hideUserControlCommand = new Command(o => HideUserControl(o)); + } + return hideUserControlCommand; + } + } + private bool doNotShowPatchNote; public bool DoNotShowPatchNote { @@ -54,24 +73,27 @@ public string Title public PatchViewModel() { + RunUrlCommand = new Command(o => { Process.Start("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); }); DoNotShowPatchNote = ConfigModel.config.DoNotShowPatch; - SetPatchNotes(); Title = $"What's New in v{ConfigModel.version}"; + SetPatchNotes(); } void SetPatchNotes() { StringBuilder patchNotes = new StringBuilder(); - patchNotes.AppendLine("• Added a What's New panel"); - patchNotes.AppendLine("• Minor improvement for R&P(Runes & Spells) Editor Window UI"); - patchNotes.AppendLine("• Added a reset config button on the settings"); - patchNotes.AppendLine("• Moved the clear cache button to miscellaneous section"); - patchNotes.AppendLine("• Fixed an issue where LoLA failed to fetch rune data"); - patchNotes.AppendLine("• Fixed an issue where LoL Assist shows an error when Auto Spells/Auto Runes are disabled"); + patchNotes.AppendLine("• Added an option for role select (available for a certain game mode only)"); + patchNotes.AppendLine("• Added a system tray menu [Exit, Show, Patch Notes, Minimize to Tray]"); + patchNotes.AppendLine("• Fixed an issue where LoL Assist UI being unresponsive"); + patchNotes.AppendLine("• Minor UI improvements"); + patchNotes.AppendLine("• Better MVVM Bindings"); + patchNotes.AppendLine("• Code clean up"); PatchNotes = patchNotes.ToString(); } + private void HideUserControl(object p) => Utils.Animation.FadeOut(p as UserControl); + public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/LoL Assist/ViewModel/RoleSelectViewModel.cs b/LoL Assist/ViewModel/RoleSelectViewModel.cs new file mode 100644 index 0000000..9199095 --- /dev/null +++ b/LoL Assist/ViewModel/RoleSelectViewModel.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace LoL_Assist_WAPP.ViewModel +{ + public class RoleSelectViewModel : INotifyPropertyChanged + { + private string patchNotes; + public string PatchNotes + { + get => patchNotes; + set + { + if (patchNotes != value) + { + patchNotes = value; + OnPropertyChanged(nameof(PatchNotes)); + } + } + } + + private ICommand selectRoleCommand; + public ICommand SelectRoleCommand + { + get + { + if (selectRoleCommand == null) + selectRoleCommand = new Command(o => SelectRole(o.ToString())); + + return selectRoleCommand; + } + } + + public string Role { get; set; } = string.Empty; + + public string GetRole + { + get { return Role; } + } + + public Action ImportAction { get; set; } + + private async void SelectRole(string role) + { + Role = role; + await Task.Run(() => { ImportAction?.Invoke(); }); + } + + public RoleSelectViewModel() + { + + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/LoLA Config.json b/LoLA Config.json new file mode 100644 index 0000000..f35972b --- /dev/null +++ b/LoLA Config.json @@ -0,0 +1 @@ +{"MonitoringDelay":300,"AutoRunes":true,"AutoAccept":true,"AutoSpells":true,"UseLatestPatch":false,"CustomRunesSpells":true,"FlashPlacementToRight":false,"Logging":false,"LowSpecMode":false,"BuildCache":true,"UpdateOnStartup":true,"DoNotShowPatch":false} \ No newline at end of file