SingleSequenceAction.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Team.FFFeederService.Enums;
  9. namespace Team.FFFeederService.Models
  10. {
  11. /// <summary>
  12. /// 单个序列动作
  13. /// </summary>
  14. public class SingleSequenceAction : INotifyPropertyChanged
  15. {
  16. private ActionType _Type;
  17. /// <summary>
  18. /// 动作
  19. /// </summary>
  20. public ActionType Type
  21. {
  22. get { return _Type; }
  23. set { SetProperty(ref _Type,value); }
  24. }
  25. private int _ShakeId;
  26. /// <summary>
  27. /// 程序
  28. /// </summary>
  29. public int ShakeId
  30. {
  31. get { return _ShakeId; }
  32. set { SetProperty(ref _ShakeId, value); }
  33. }
  34. private DurationMode _DurationMode;
  35. /// <summary>
  36. /// 持续模式
  37. /// </summary>
  38. public DurationMode DurationMode
  39. {
  40. get { return _DurationMode; }
  41. set {
  42. if (value == DurationMode.震动比)
  43. {
  44. DurationValue = DurationValue > 100 ? 100 : DurationValue;
  45. Format = "{}{0:N0} ms";
  46. Max = 30000;
  47. }
  48. else
  49. {
  50. Format = "{}{0:N0} %";
  51. Max = 100;
  52. }
  53. SetProperty(ref _DurationMode, value);
  54. }
  55. }
  56. private int _DurationValue;
  57. /// <summary>
  58. /// 持续时长
  59. /// </summary>
  60. public int DurationValue
  61. {
  62. get { return _DurationValue; }
  63. set { SetProperty(ref _DurationValue, value); }
  64. }
  65. private string _Format;
  66. public string Format
  67. {
  68. get { return _Format; }
  69. set { SetProperty(ref _Format, value); }
  70. }
  71. private int _Max;
  72. public int Max
  73. {
  74. get { return _Max; }
  75. set { SetProperty(ref _Max, value); }
  76. }
  77. #region 属性更改通知
  78. /// <summary>
  79. /// Occurs when a property value changes.
  80. /// </summary>
  81. public event PropertyChangedEventHandler PropertyChanged;
  82. /// <summary>
  83. /// Checks if a property already matches a desired value. Sets the property and
  84. /// notifies listeners only when necessary.
  85. /// </summary>
  86. /// <typeparam name="T">Type of the property.</typeparam>
  87. /// <param name="storage">Reference to a property with both getter and setter.</param>
  88. /// <param name="value">Desired value for the property.</param>
  89. /// <param name="propertyName">Name of the property used to notify listeners. This
  90. /// value is optional and can be provided automatically when invoked from compilers that
  91. /// support CallerMemberName.</param>
  92. /// <returns>True if the value was changed, false if the existing value matched the
  93. /// desired value.</returns>
  94. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  95. {
  96. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  97. storage = value;
  98. RaisePropertyChanged(propertyName);
  99. return true;
  100. }
  101. /// <summary>
  102. /// Checks if a property already matches a desired value. Sets the property and
  103. /// notifies listeners only when necessary.
  104. /// </summary>
  105. /// <typeparam name="T">Type of the property.</typeparam>
  106. /// <param name="storage">Reference to a property with both getter and setter.</param>
  107. /// <param name="value">Desired value for the property.</param>
  108. /// <param name="propertyName">Name of the property used to notify listeners. This
  109. /// value is optional and can be provided automatically when invoked from compilers that
  110. /// support CallerMemberName.</param>
  111. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  112. /// <returns>True if the value was changed, false if the existing value matched the
  113. /// desired value.</returns>
  114. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  115. {
  116. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  117. storage = value;
  118. onChanged?.Invoke();
  119. RaisePropertyChanged(propertyName);
  120. return true;
  121. }
  122. /// <summary>
  123. /// Raises this object's PropertyChanged event.
  124. /// </summary>
  125. /// <param name="propertyName">Name of the property used to notify listeners. This
  126. /// value is optional and can be provided automatically when invoked from compilers
  127. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  128. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  129. {
  130. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  131. }
  132. /// <summary>
  133. /// Raises this object's PropertyChanged event.
  134. /// </summary>
  135. /// <param name="args">The PropertyChangedEventArgs</param>
  136. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  137. {
  138. PropertyChanged?.Invoke(this, args);
  139. }
  140. #endregion
  141. }
  142. }