/DND_Monster/Views/AddSavedTrait.cs

https://github.com/FallenWyvern/DnD-Monster-Generator
C# | 319 lines | 285 code | 34 blank | 0 comment | 68 complexity | e5ab501814c984612a2221d9d0a47443 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace DND_Monster
  11. {
  12. public partial class AddSavedTrait : Form
  13. {
  14. public Ability ability = null;
  15. public Ability action = null;
  16. public Ability reaction = null;
  17. public Legendary legendary = null;
  18. public string OGLCreatureAdd = "";
  19. public AddSavedTrait()
  20. {
  21. InitializeComponent();
  22. Translation.Apply(this);
  23. }
  24. void SelectItem(object sender, EventArgs e)
  25. {
  26. }
  27. private void AddSavedTrait_Load(object sender, EventArgs e)
  28. {
  29. comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
  30. comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
  31. comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  32. comboBox2.DropDownStyle = ComboBoxStyle.DropDown;
  33. comboBox2.AutoCompleteSource = AutoCompleteSource.ListItems;
  34. comboBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  35. comboBox3.DropDownStyle = ComboBoxStyle.DropDown;
  36. comboBox3.AutoCompleteSource = AutoCompleteSource.ListItems;
  37. comboBox3.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  38. comboBox4.DropDownStyle = ComboBoxStyle.DropDown;
  39. comboBox4.AutoCompleteSource = AutoCompleteSource.ListItems;
  40. comboBox4.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  41. comboBox5.DropDownStyle = ComboBoxStyle.DropDown;
  42. comboBox5.AutoCompleteSource = AutoCompleteSource.ListItems;
  43. comboBox5.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
  44. foreach (string creature in OGLContent.OGL_Creatures)
  45. {
  46. comboBox5.Items.Add(creature);
  47. }
  48. comboBox1.SelectedIndexChanged += (senders, es) =>
  49. {
  50. foreach (OGL_Ability _ability in OGLContent.OGL_Abilities)
  51. {
  52. if (_ability.OGL_Creature == comboBox5.Text && _ability.Title == comboBox1.Text || comboBox5.Text == "*")
  53. {
  54. richTextBox1.Text = _ability.Description;
  55. }
  56. }
  57. };
  58. comboBox2.SelectedIndexChanged += (senders, es) =>
  59. {
  60. foreach (OGL_Ability _action in OGLContent.OGL_Actions)
  61. {
  62. if (_action.OGL_Creature == comboBox5.Text && _action.Title == comboBox2.Text || comboBox5.Text == "*")
  63. {
  64. try
  65. {
  66. if (String.IsNullOrEmpty(_action.Description))
  67. {
  68. richTextBox2.Text = _action.attack.TextDescribe();
  69. }
  70. else
  71. {
  72. richTextBox2.Text = _action.Description;
  73. }
  74. }
  75. catch { }
  76. }
  77. }
  78. };
  79. comboBox3.SelectedIndexChanged += (senders, es) =>
  80. {
  81. foreach (OGL_Ability _reaction in OGLContent.OGL_Reactions)
  82. {
  83. if (_reaction.OGL_Creature == comboBox5.Text && _reaction.Title == comboBox3.Text)
  84. {
  85. richTextBox3.Text = _reaction.Description;
  86. }
  87. }
  88. };
  89. comboBox4.SelectedIndexChanged += (senders, es) =>
  90. {
  91. foreach (OGL_Legendary trait in OGLContent.OGL_Legendary)
  92. {
  93. if (trait.OGL_Creature == comboBox5.Text)
  94. {
  95. richTextBox4.Text += trait.Title + " : " + trait.WebBoilerplate(Monster.CreatureName) + Environment.NewLine;
  96. }
  97. }
  98. };
  99. }
  100. private void AddSavedTrait_FormClosing(object sender, FormClosingEventArgs e)
  101. {
  102. try
  103. {
  104. switch (tabControl1.SelectedIndex)
  105. {
  106. case 0:
  107. foreach (OGL_Ability _ability in OGLContent.OGL_Abilities)
  108. {
  109. if (_ability.OGL_Creature == comboBox5.Text && _ability.Title == comboBox1.Text)
  110. {
  111. ability = _ability;
  112. }
  113. }
  114. break;
  115. case 1:
  116. foreach (OGL_Ability _action in OGLContent.OGL_Actions)
  117. {
  118. if (_action.OGL_Creature == comboBox5.Text && _action.Title == comboBox2.Text)
  119. {
  120. action = _action;
  121. }
  122. }
  123. break;
  124. case 2:
  125. foreach (OGL_Ability _reaction in OGLContent.OGL_Reactions)
  126. {
  127. if (_reaction.OGL_Creature == comboBox5.Text && _reaction.Title == comboBox3.Text)
  128. {
  129. reaction = _reaction;
  130. }
  131. }
  132. break;
  133. case 3:
  134. foreach (OGL_Legendary _legendary in OGLContent.OGL_Legendary)
  135. {
  136. if (_legendary.OGL_Creature == comboBox5.Text && _legendary.Title == comboBox4.Text)
  137. {
  138. legendary = _legendary;
  139. }
  140. }
  141. break;
  142. }
  143. }
  144. catch { ability = null; action = null; reaction = null; legendary = null; }
  145. }
  146. private void button1_Click(object sender, EventArgs e)
  147. {
  148. ability = null;
  149. action = null;
  150. legendary = null;
  151. reaction = null;
  152. OGLCreatureAdd = comboBox5.Text;
  153. this.Close();
  154. }
  155. private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
  156. {
  157. FilterResults();
  158. }
  159. private void FilterResults()
  160. {
  161. comboBox1.Items.Clear();
  162. comboBox2.Items.Clear();
  163. comboBox3.Items.Clear();
  164. comboBox4.Items.Clear();
  165. comboBox1.Text = "";
  166. comboBox2.Text = "";
  167. comboBox3.Text = "";
  168. comboBox4.Text = "";
  169. richTextBox1.Text = "";
  170. richTextBox2.Text = "";
  171. richTextBox3.Text = "";
  172. richTextBox4.Text = "";
  173. foreach (OGL_Ability _ability in OGLContent.OGL_Abilities)
  174. {
  175. if (_ability.OGL_Creature == comboBox5.Text || comboBox5.Text == "*")
  176. {
  177. comboBox1.Items.Add(_ability.Title);
  178. }
  179. }
  180. foreach (OGL_Ability _action in OGLContent.OGL_Actions)
  181. {
  182. if (_action.OGL_Creature == comboBox5.Text || comboBox5.Text == "*")
  183. {
  184. comboBox2.Items.Add(_action.Title);
  185. }
  186. }
  187. foreach (OGL_Ability _reaction in OGLContent.OGL_Reactions)
  188. {
  189. if (_reaction.OGL_Creature == comboBox5.Text || comboBox5.Text == "*")
  190. {
  191. comboBox3.Items.Add(_reaction.Title);
  192. }
  193. }
  194. foreach (OGL_Legendary _legendary in OGLContent.OGL_Legendary)
  195. {
  196. if (_legendary.OGL_Creature == comboBox5.Text && !comboBox4.Items.Contains(_legendary.Title) || comboBox5.Text == "*")
  197. {
  198. comboBox4.Items.Add(_legendary.Title);
  199. }
  200. }
  201. if (comboBox4.Items.Count > 0)
  202. {
  203. tabControl1.SelectTab(3);
  204. comboBox4.SelectedIndex = 0;
  205. }
  206. if (comboBox3.Items.Count > 0)
  207. {
  208. tabControl1.SelectTab(2);
  209. comboBox3.SelectedIndex = 0;
  210. }
  211. if (comboBox2.Items.Count > 0)
  212. {
  213. tabControl1.SelectTab(1);
  214. comboBox2.SelectedIndex = 0;
  215. }
  216. if (comboBox1.Items.Count > 0)
  217. {
  218. tabControl1.SelectTab(0);
  219. comboBox1.SelectedIndex = 0;
  220. }
  221. }
  222. private void button2_Click(object sender, EventArgs e)
  223. {
  224. this.Close();
  225. }
  226. private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
  227. {
  228. switch (e.TabPageIndex)
  229. {
  230. case 0:
  231. if (!(comboBox1.Items.Count > 0))
  232. {
  233. e.Cancel = true;
  234. }
  235. break;
  236. case 1:
  237. if (!(comboBox2.Items.Count > 0))
  238. {
  239. e.Cancel = true;
  240. }
  241. break;
  242. case 2:
  243. if (!(comboBox3.Items.Count > 0))
  244. {
  245. e.Cancel = true;
  246. }
  247. break;
  248. case 3:
  249. if (!(comboBox4.Items.Count > 0))
  250. {
  251. e.Cancel = true;
  252. }
  253. break;
  254. }
  255. }
  256. private void comboBox5_Click(object sender, EventArgs e)
  257. {
  258. }
  259. private void comboBox5_TextChanged(object sender, EventArgs e)
  260. {
  261. if (comboBox5.Text == "*")
  262. {
  263. FilterResults();
  264. }
  265. else
  266. {
  267. if (comboBox1.Items.Count > 0 || comboBox2.Items.Count > 0 || comboBox3.Items.Count > 0 || comboBox4.Items.Count > 0)
  268. {
  269. comboBox1.Items.Clear();
  270. comboBox2.Items.Clear();
  271. comboBox3.Items.Clear();
  272. comboBox4.Items.Clear();
  273. comboBox1.Text = "";
  274. comboBox2.Text = "";
  275. comboBox3.Text = "";
  276. comboBox4.Text = "";
  277. richTextBox1.Text = "";
  278. richTextBox2.Text = "";
  279. richTextBox3.Text = "";
  280. richTextBox4.Text = "";
  281. }
  282. }
  283. }
  284. }
  285. }