using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DS4Windows; using DS4WinWPF.DS4Forms.ViewModels.Util; namespace DS4WinWPF.DS4Forms.ViewModels.SpecialActions { public class MultiActButtonViewModel : NotifyDataErrorBase { private List tapMacro = new List(); private List holdMacro = new List(); private List doubleTapMacro = new List(); private List[] loadAccessArray; public List TapMacro { get => tapMacro; } public List HoldMacro { get => holdMacro; } public List DoubleTapMacro { get => doubleTapMacro; } public string TapMacroText { get { string result = Properties.Resources.SelectMacro; if (tapMacro.Count > 0) { result = Properties.Resources.MacroRecorded; } return result; } } public event EventHandler TapMacroTextChanged; public string HoldMacroText { get { string result = Properties.Resources.SelectMacro; if (holdMacro.Count > 0) { result = Properties.Resources.MacroRecorded; } return result; } } public event EventHandler HoldMacroTextChanged; public string DoubleTapMacroText { get { string result = Properties.Resources.SelectMacro; if (doubleTapMacro.Count > 0) { result = Properties.Resources.MacroRecorded; } return result; } } public event EventHandler DoubleTapMacroTextChanged; public MultiActButtonViewModel() { loadAccessArray = new List[3] { tapMacro, holdMacro, doubleTapMacro }; } public void LoadAction(SpecialAction action) { string[] dets = action.details.Split(','); for (int i = 0; i < 3; i++) { string[] macs = dets[i].Split('/'); foreach (string s in macs) { if (int.TryParse(s, out int v)) loadAccessArray[i].Add(v); } } } public void UpdateTapDisplayText() { TapMacroTextChanged?.Invoke(this, EventArgs.Empty); } public void UpdateHoldDisplayText() { HoldMacroTextChanged?.Invoke(this, EventArgs.Empty); } public void UpdateDoubleTapDisplayText() { DoubleTapMacroTextChanged?.Invoke(this, EventArgs.Empty); } public DS4ControlSettings PrepareTapSettings() { DS4ControlSettings settings = new DS4ControlSettings(DS4Controls.None); settings.action = tapMacro.ToArray(); settings.actionType = DS4ControlSettings.ActionType.Macro; settings.keyType = DS4KeyType.Macro; return settings; } public DS4ControlSettings PrepareHoldSettings() { DS4ControlSettings settings = new DS4ControlSettings(DS4Controls.None); settings.action = holdMacro.ToArray(); settings.actionType = DS4ControlSettings.ActionType.Macro; settings.keyType = DS4KeyType.Macro; return settings; } public DS4ControlSettings PrepareDoubleTapSettings() { DS4ControlSettings settings = new DS4ControlSettings(DS4Controls.None); settings.action = doubleTapMacro.ToArray(); settings.actionType = DS4ControlSettings.ActionType.Macro; settings.keyType = DS4KeyType.Macro; return settings; } public void SaveAction(SpecialAction action, bool edit = false) { string details = string.Join("/", tapMacro) + "," + string.Join("/", holdMacro) + "," + string.Join("/", doubleTapMacro); Global.SaveAction(action.name, action.controls, 7, details, edit); } public override bool IsValid(SpecialAction action) { ClearOldErrors(); bool valid = true; List tapMacroErrors = new List(); List holdMacroErrors = new List(); List doubleTapMacroErrors = new List(); if (tapMacro.Count == 0) { tapMacroErrors.Add("No tap macro defined"); errors["TapMacro"] = tapMacroErrors; RaiseErrorsChanged("TapMacro"); } if (holdMacro.Count == 0) { holdMacroErrors.Add("No hold macro defined"); errors["HoldMacro"] = holdMacroErrors; RaiseErrorsChanged("HoldMacro"); } if (doubleTapMacro.Count == 0) { doubleTapMacroErrors.Add("No double tap macro defined"); errors["DoubleTapMacro"] = doubleTapMacroErrors; RaiseErrorsChanged("DoubleTapMacro"); } return valid; } public override void ClearOldErrors() { if (errors.Count > 0) { errors.Clear(); RaiseErrorsChanged("TapMacro"); RaiseErrorsChanged("HoldMacro"); RaiseErrorsChanged("DoubleTapMacro"); } } } }