PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/Mag-Tools/Views/AccountServerCharacterGUI.cs

#
C# | 305 lines | 235 code | 65 blank | 5 comment | 48 complexity | 5784039f0b3d41703f75422c72a4772c MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Decal.Adapter;
  5. using Mag.Shared;
  6. using VirindiViewService.Controls;
  7. namespace MagTools.Views
  8. {
  9. class AccountServerCharacterGUI : IDisposable
  10. {
  11. private readonly HudTextBox loginText;
  12. private readonly HudList loginList;
  13. private readonly HudTextBox loginCompleteText;
  14. private readonly HudList loginCompleteList;
  15. private readonly HudTextBox periodicCommandText;
  16. private readonly HudTextBox periodicCommandInterval;
  17. private readonly HudTextBox periodicCommandOffset;
  18. private readonly HudList periodicCommandList;
  19. public AccountServerCharacterGUI(MainView mainView)
  20. {
  21. try
  22. {
  23. loginText = mainView.LoginText;
  24. mainView.LoginAdd.Hit += new EventHandler(LoginAdd_Hit);
  25. loginList = mainView.LoginList;
  26. loginList.Click += new HudList.delClickedControl(loginList_Click);
  27. loginCompleteText = mainView.LoginCompleteText;
  28. mainView.LoginCompleteAdd.Hit += new EventHandler(LoginCompleteAdd_Hit);
  29. loginCompleteList = mainView.LoginCompleteList;
  30. loginCompleteList.Click += new HudList.delClickedControl(loginCompleteList_Click);
  31. periodicCommandText = mainView.PeriodicCommandText;
  32. periodicCommandInterval = mainView.PeriodicCommandInterval;
  33. periodicCommandOffset = mainView.PeriodicCommandOffset;
  34. mainView.PeriodicCommandAdd.Hit += new EventHandler(PeriodicCommandAdd_Hit);
  35. periodicCommandList = mainView.PeriodicCommandList;
  36. periodicCommandList.Click += new HudList.delClickedControl(periodicCommandList_Click);
  37. CoreManager.Current.CharacterFilter.Login += new EventHandler<Decal.Adapter.Wrappers.LoginEventArgs>(CharacterFilter_Login);
  38. }
  39. catch (Exception ex) { Debug.LogException(ex); }
  40. }
  41. private bool disposed;
  42. public void Dispose()
  43. {
  44. Dispose(true);
  45. // Use SupressFinalize in case a subclass
  46. // of this type implements a finalizer.
  47. GC.SuppressFinalize(this);
  48. }
  49. protected virtual void Dispose(bool disposing)
  50. {
  51. // If you need thread safety, use a lock around these
  52. // operations, as well as in your methods that use the resource.
  53. if (!disposed)
  54. {
  55. if (disposing)
  56. {
  57. CoreManager.Current.CharacterFilter.Login -= new EventHandler<Decal.Adapter.Wrappers.LoginEventArgs>(CharacterFilter_Login);
  58. }
  59. // Indicate that the instance has been disposed.
  60. disposed = true;
  61. }
  62. }
  63. void CharacterFilter_Login(object sender, Decal.Adapter.Wrappers.LoginEventArgs e)
  64. {
  65. try
  66. {
  67. var loginCommands = Settings.SettingsManager.AccountServerCharacter.GetOnLoginCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  68. foreach (var command in loginCommands)
  69. {
  70. HudList.HudListRowAccessor newRow = loginList.AddRow();
  71. ((HudStaticText)newRow[0]).Text = command;
  72. ((HudPictureBox)newRow[1]).Image = 0x60028FC;
  73. ((HudPictureBox)newRow[2]).Image = 0x60028FD;
  74. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  75. }
  76. var loginCompleteCommands = Settings.SettingsManager.AccountServerCharacter.GetOnLoginCompleteCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  77. foreach (var command in loginCompleteCommands)
  78. {
  79. HudList.HudListRowAccessor newRow = loginCompleteList.AddRow();
  80. ((HudStaticText)newRow[0]).Text = command;
  81. ((HudPictureBox)newRow[1]).Image = 0x60028FC;
  82. ((HudPictureBox)newRow[2]).Image = 0x60028FD;
  83. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  84. }
  85. var periodicCommands = Settings.SettingsManager.AccountServerCharacter.GetPeriodicCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  86. foreach (var command in periodicCommands)
  87. {
  88. HudList.HudListRowAccessor newRow = periodicCommandList.AddRow();
  89. ((HudStaticText)newRow[0]).Text = command.Command;
  90. ((HudStaticText)newRow[1]).Text = command.Interval.TotalMinutes.ToString(CultureInfo.InvariantCulture);
  91. ((HudStaticText)newRow[2]).Text = command.OffsetFromMidnight.TotalMinutes.ToString(CultureInfo.InvariantCulture);
  92. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  93. }
  94. }
  95. catch (Exception ex) { Debug.LogException(ex); }
  96. }
  97. void LoginAdd_Hit(object sender, EventArgs e)
  98. {
  99. try
  100. {
  101. var command = loginText.Text;
  102. if (String.IsNullOrEmpty(command))
  103. return;
  104. loginText.Text = String.Empty;
  105. var commands = Settings.SettingsManager.AccountServerCharacter.GetOnLoginCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  106. commands.Add(command);
  107. Settings.SettingsManager.AccountServerCharacter.SetOnLoginCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  108. HudList.HudListRowAccessor newRow = loginList.AddRow();
  109. ((HudStaticText)newRow[0]).Text = command;
  110. ((HudPictureBox)newRow[1]).Image = 0x60028FC;
  111. ((HudPictureBox)newRow[2]).Image = 0x60028FD;
  112. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  113. }
  114. catch (Exception ex) { Debug.LogException(ex); }
  115. }
  116. void loginList_Click(object sender, int row, int col)
  117. {
  118. try
  119. {
  120. if ((row == 0 && col == 1) || (row == loginList.RowCount - 1 && col == 2))
  121. return;
  122. if (col == 1)
  123. {
  124. string temp = ((HudStaticText)loginList[row][0]).Text;
  125. ((HudStaticText)loginList[row][0]).Text = ((HudStaticText)loginList[row - 1][0]).Text;
  126. ((HudStaticText)loginList[row - 1][0]).Text = temp;
  127. }
  128. else if (col == 2)
  129. {
  130. string temp = ((HudStaticText)loginList[row][0]).Text;
  131. ((HudStaticText)loginList[row][0]).Text = ((HudStaticText)loginList[row + 1][0]).Text;
  132. ((HudStaticText)loginList[row + 1][0]).Text = temp;
  133. }
  134. else if (col == 3)
  135. loginList.RemoveRow(row);
  136. else
  137. return;
  138. var commands = new List<string>();
  139. for (int i = 0 ; i < loginList.RowCount ; i++)
  140. commands.Add(((HudStaticText)loginList[i][0]).Text);
  141. Settings.SettingsManager.AccountServerCharacter.SetOnLoginCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  142. }
  143. catch (Exception ex) { Debug.LogException(ex); }
  144. }
  145. void LoginCompleteAdd_Hit(object sender, EventArgs e)
  146. {
  147. try
  148. {
  149. var command = loginCompleteText.Text;
  150. if (String.IsNullOrEmpty(command))
  151. return;
  152. loginCompleteText.Text = String.Empty;
  153. var commands = Settings.SettingsManager.AccountServerCharacter.GetOnLoginCompleteCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  154. commands.Add(command);
  155. Settings.SettingsManager.AccountServerCharacter.SetOnLoginCompleteCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  156. HudList.HudListRowAccessor newRow = loginCompleteList.AddRow();
  157. ((HudStaticText)newRow[0]).Text = command;
  158. ((HudPictureBox)newRow[1]).Image = 0x60028FC;
  159. ((HudPictureBox)newRow[2]).Image = 0x60028FD;
  160. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  161. }
  162. catch (Exception ex) { Debug.LogException(ex); }
  163. }
  164. void loginCompleteList_Click(object sender, int row, int col)
  165. {
  166. try
  167. {
  168. if ((row == 0 && col == 1) || (row == loginCompleteList.RowCount - 1 && col == 2))
  169. return;
  170. if (col == 1)
  171. {
  172. string temp = ((HudStaticText)loginCompleteList[row][0]).Text;
  173. ((HudStaticText)loginCompleteList[row][0]).Text = ((HudStaticText)loginCompleteList[row - 1][0]).Text;
  174. ((HudStaticText)loginCompleteList[row - 1][0]).Text = temp;
  175. }
  176. else if (col == 2)
  177. {
  178. string temp = ((HudStaticText)loginCompleteList[row][0]).Text;
  179. ((HudStaticText)loginCompleteList[row][0]).Text = ((HudStaticText)loginCompleteList[row + 1][0]).Text;
  180. ((HudStaticText)loginCompleteList[row + 1][0]).Text = temp;
  181. }
  182. else if (col == 3)
  183. loginCompleteList.RemoveRow(row);
  184. else
  185. return;
  186. var commands = new List<string>();
  187. for (int i = 0; i < loginCompleteList.RowCount; i++)
  188. commands.Add(((HudStaticText)loginCompleteList[i][0]).Text);
  189. Settings.SettingsManager.AccountServerCharacter.SetOnLoginCompleteCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  190. }
  191. catch (Exception ex) { Debug.LogException(ex); }
  192. }
  193. void PeriodicCommandAdd_Hit(object sender, EventArgs e)
  194. {
  195. try
  196. {
  197. var command = periodicCommandText.Text;
  198. var intervalText = periodicCommandInterval.Text;
  199. var offsetText = periodicCommandOffset.Text;
  200. if (String.IsNullOrEmpty(command) || String.IsNullOrEmpty(intervalText) || String.IsNullOrEmpty(offsetText))
  201. return;
  202. int interval;
  203. int offset;
  204. if (!int.TryParse(intervalText, out interval) || interval <= 0 || !int.TryParse(offsetText, out offset) || offset < 0)
  205. return;
  206. periodicCommandText.Text = String.Empty;
  207. var commands = Settings.SettingsManager.AccountServerCharacter.GetPeriodicCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name);
  208. commands.Add(new Settings.SettingsManager.AccountServerCharacter.PeriodicCommand(command, TimeSpan.FromMinutes(interval), TimeSpan.FromMinutes(offset)));
  209. Settings.SettingsManager.AccountServerCharacter.SetPeriodicCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  210. HudList.HudListRowAccessor newRow = periodicCommandList.AddRow();
  211. ((HudStaticText)newRow[0]).Text = command;
  212. ((HudStaticText)newRow[1]).Text = interval.ToString(CultureInfo.InvariantCulture);
  213. ((HudStaticText)newRow[2]).Text = offset.ToString(CultureInfo.InvariantCulture);
  214. ((HudPictureBox)newRow[3]).Image = 0x60011F8;
  215. }
  216. catch (Exception ex) { Debug.LogException(ex); }
  217. }
  218. void periodicCommandList_Click(object sender, int row, int col)
  219. {
  220. try
  221. {
  222. if (col == 3)
  223. periodicCommandList.RemoveRow(row);
  224. else
  225. return;
  226. var commands = new List<Settings.SettingsManager.AccountServerCharacter.PeriodicCommand>();
  227. for (int i = 0; i < periodicCommandList.RowCount; i++)
  228. {
  229. int interval;
  230. int offset;
  231. int.TryParse(((HudStaticText)periodicCommandList[i][1]).Text, out interval);
  232. int.TryParse(((HudStaticText)periodicCommandList[i][2]).Text, out offset);
  233. commands.Add(new Settings.SettingsManager.AccountServerCharacter.PeriodicCommand(((HudStaticText)periodicCommandList[i][0]).Text, TimeSpan.FromMinutes(interval), TimeSpan.FromMinutes(offset)));
  234. }
  235. Settings.SettingsManager.AccountServerCharacter.SetPeriodicCommands(CoreManager.Current.CharacterFilter.AccountName, CoreManager.Current.CharacterFilter.Server, CoreManager.Current.CharacterFilter.Name, commands);
  236. }
  237. catch (Exception ex) { Debug.LogException(ex); }
  238. }
  239. }
  240. }