PanelUnits.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. """
  2. This file is part of RuneOptimizer.
  3. RuneOptimizer is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation, either version 3 of the License, or (at your option)
  6. any later version.
  7. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  13. """
  14. class PanelUnits(wx.Panel):
  15. """
  16. The unit list and details Panel.
  17. Methods
  18. -------
  19. populate_unit_list(event)
  20. Populates the unit list.
  21. """
  22. _selected_unit = None
  23. _unit_list = None
  24. _filter_name_text = None
  25. _filter_torage_check = None
  26. _filter_no_runes_check = None
  27. _filterNoTeamsCheck = None
  28. _details_sizer = None
  29. _name_label = None
  30. _stat_grid = None
  31. _set_label_list = None
  32. _id_label_list = None
  33. _main_label_list = None
  34. _innate_label_list = None
  35. _stat_label_list = None
  36. _eff_label_List = None
  37. def __init__(self, parent, id=wx.ID_ANY):
  38. """Initializes the panel.
  39. Sets upt all the widgets.
  40. Parameters
  41. ----------
  42. parent : wx.*
  43. Panel parent.
  44. id : int, optional
  45. ID for the panel (default wx.ID_ANY).
  46. """
  47. # Parent constructor
  48. wx.Panel.__init__(self, parent=parent, id=id)
  49. # Prepare some fonts
  50. title_font = wx.Font(
  51. pointSize=16, family=wx.FONTFAMILY_DEFAULT,
  52. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  53. )
  54. subtitle_font = wx.Font(
  55. pointSize=14, family=wx.FONTFAMILY_DEFAULT,
  56. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  57. )
  58. bold_font = wx.Font(
  59. pointSize=10, family=wx.FONTFAMILY_DEFAULT,
  60. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  61. )
  62. monospace_font = wx.Font(
  63. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  64. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL
  65. )
  66. monospace_font_bold = wx.Font(
  67. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  68. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  69. )
  70. monospace_font_italic = wx.Font(
  71. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  72. style=wx.FONTSTYLE_ITALIC, weight=wx.FONTWEIGHT_NORMAL
  73. )
  74. # Unit selectable list
  75. unit_list_box = wx.StaticBox(
  76. self, label="Select unit:", id=wx.ID_ANY, pos=(0, 0), size=(210, 590)
  77. )
  78. wx.StaticText(
  79. parent=unit_list_box, id=wx.ID_ANY,
  80. label="Name Prio. Sto.",
  81. pos=(10, 10), size=(190, 20)
  82. ).SetFont(bold_font)
  83. self._unit_list = wx.ListCtrl(
  84. parent=unit_list_box, id=wx.ID_ANY, pos=(10, 30), size=(190, 380),
  85. style=wx.LC_REPORT|wx.LC_NO_HEADER
  86. )
  87. self._unit_list.InsertColumn(0, "Name", width=120)
  88. self._unit_list.InsertColumn(1, "Prio.", width=40)
  89. self._unit_list.InsertColumn(2, "Sto.", width=30)
  90. self._unit_list.Bind(wx.EVT_LIST_ITEM_SELECTED, self._unit_selected)
  91. # List filters
  92. filterBox = wx.StaticBox(
  93. parent=self, label="Filters:", id=wx.ID_ANY,
  94. pos=(10, 430), size=(190, 150)
  95. )
  96. wx.StaticText(
  97. parent=filterBox, label="Monster name", pos=(5, 5), size=(180, 20)
  98. )
  99. self._filter_name_text = wx.TextCtrl(
  100. parent=filterBox, id=wx.ID_ANY, value="", pos=(5, 25),
  101. size=(177, 20), style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB
  102. )
  103. self._filter_name_text.Bind(wx.EVT_TEXT, self.populate_unit_list)
  104. self._filter_storage_check = wx.CheckBox(
  105. parent=filterBox, id=wx.ID_ANY,
  106. label="Monsters in storage", pos=(5, 55), size=(180, 20)
  107. )
  108. self._filter_storage_check.SetValue(True)
  109. self._filter_storage_check.Bind(
  110. wx.EVT_CHECKBOX, self.populate_unit_list
  111. )
  112. self.filterNoRunesCheck = wx.CheckBox(
  113. parent=filterBox, id=wx.ID_ANY,
  114. label="Monsters without runes", pos=(5, 75), size=(180, 20)
  115. )
  116. self.filterNoRunesCheck.SetValue(True)
  117. self.filterNoRunesCheck.Bind(
  118. wx.EVT_CHECKBOX, self.populate_unit_list
  119. )
  120. self._filter_no_teams_check = wx.CheckBox(
  121. parent=filterBox, id=wx.ID_ANY,
  122. label="Monsters not in teams", pos=(5, 95), size=(180, 20)
  123. )
  124. self._filter_no_teams_check.SetValue(True)
  125. self._filter_no_teams_check.Bind(
  126. wx.EVT_CHECKBOX, self.populate_unit_list
  127. )
  128. self.populate_unit_list(None)
  129. # Sizer for all the unit details. It will be hidden until a unit is
  130. # selected.
  131. self._details_sizer = wx.BoxSizer(wx.VERTICAL)
  132. # Unit name
  133. self._name_label = wx.StaticText(
  134. parent=self, label="", pos=(240, 0), size=(120, 30)
  135. )
  136. self._details_sizer.Add(self._name_label)
  137. self._name_label.SetFont(title_font)
  138. #Unit details
  139. self._stars_label = wx.StaticText(
  140. parent=self, label="", pos=(250, 30), size=(120, 100)
  141. )
  142. self._stars_label.SetFont(title_font)
  143. self._details_sizer.Add(self._stars_label)
  144. self._level_label = wx.StaticText(
  145. parent=self, label="", pos=(250, 60), size=(120, 100)
  146. )
  147. self._details_sizer.Add(self._level_label)
  148. self._level_label.SetFont(subtitle_font)
  149. self._priority_label = wx.StaticText(
  150. parent=self, label="", pos=(250, 90), size=(120, 100)
  151. )
  152. self._priority_label.SetFont(subtitle_font)
  153. self._details_sizer.Add(self._priority_label)
  154. self._id_label = wx.StaticText(
  155. parent=self, label="", pos=(250, 120), size=(120, 100)
  156. )
  157. self._id_label.SetFont(subtitle_font)
  158. self._details_sizer.Add(self._id_label)
  159. # Button to go to the ptimizer
  160. optimize_button = wx.Button(
  161. parent=self, id=wx.ID_ANY, pos=(700, 520), size=(120, 50),
  162. style=wx.LC_REPORT, label="Optimize"
  163. )
  164. self._details_sizer.Add(optimize_button)
  165. optimize_button.Bind(wx.EVT_BUTTON, self._go_to_optimizer)
  166. # Stats table
  167. self._stat_grid = wx.grid.Grid(
  168. parent=self, id=wx.ID_ANY, pos=(520, 00), size=(195, 220)
  169. )
  170. self._details_sizer.Add(self._stat_grid)
  171. self._stat_grid.CreateGrid(
  172. numRows=10, numCols=2
  173. )
  174. self._stat_grid.EnableEditing(False)
  175. self._stat_grid.SetDefaultCellAlignment(
  176. horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE
  177. )
  178. self._stat_grid.SetDefaultCellFont(monospace_font)
  179. self._stat_grid.SetColSize(col=0, width=80)
  180. self._stat_grid.SetColLabelValue(col=0, value="Base")
  181. self._stat_grid.SetColSize(col=1, width=80)
  182. self._stat_grid.SetColLabelValue(col=1, value="Current")
  183. self._stat_grid.SetRowLabelSize(width=35)
  184. self._stat_grid.SetColLabelSize(height=20)
  185. self._stat_grid.SetRowSize(row=0, height=20)
  186. self._stat_grid.SetRowSize(row=1, height=20)
  187. self._stat_grid.SetRowSize(row=2, height=20)
  188. self._stat_grid.SetRowSize(row=3, height=20)
  189. self._stat_grid.SetRowSize(row=4, height=20)
  190. self._stat_grid.SetRowSize(row=5, height=20)
  191. self._stat_grid.SetRowSize(row=6, height=20)
  192. self._stat_grid.SetRowSize(row=7, height=20)
  193. self._stat_grid.SetRowSize(row=8, height=20)
  194. self._stat_grid.SetRowSize(row=9, height=20)
  195. self._stat_grid.SetRowLabelValue(row=0, value=" HP")
  196. self._stat_grid.SetRowLabelValue(row=1, value="ATK")
  197. self._stat_grid.SetRowLabelValue(row=2, value="DEF")
  198. self._stat_grid.SetRowLabelValue(row=3, value="SPD")
  199. self._stat_grid.SetRowLabelValue(row=4, value="CRR")
  200. self._stat_grid.SetRowLabelValue(row=5, value="CRD")
  201. self._stat_grid.SetRowLabelValue(row=6, value="RES")
  202. self._stat_grid.SetRowLabelValue(row=7, value="ACC")
  203. self._stat_grid.SetRowLabelValue(row=8, value="EHP")
  204. self._stat_grid.SetRowLabelValue(row=9, value="DMG")
  205. # Team list
  206. team_box = wx.StaticBox(
  207. parent=self, label="Teams:",id=wx.ID_ANY,
  208. pos=(730, 0), size=(160, 220)
  209. )
  210. self._details_sizer.Add(team_box)
  211. self._teams_label = wx.StaticText(
  212. parent=team_box, label="", pos=(5, 5), size=(135, 190)
  213. )
  214. monospace_font.PointSize -= 2
  215. self._teams_label.SetFont(monospace_font)
  216. monospace_font.PointSize += 2
  217. # Rune list
  218. rune_box_list = [
  219. wx.StaticBox(
  220. parent=self, label="Slot1:",id=wx.ID_ANY,
  221. pos=(365, 225), size=(130, 170)
  222. ),
  223. wx.StaticBox(
  224. parent=self, label="Slot2:",id=wx.ID_ANY,
  225. pos=(510, 225), size=(130, 170)
  226. ),
  227. wx.StaticBox(
  228. parent=self, label="Slot3:",id=wx.ID_ANY,
  229. pos=(510, 400), size=(130, 170)
  230. ),
  231. wx.StaticBox(
  232. parent=self, label="Slot4:",id=wx.ID_ANY,
  233. pos=(365, 400), size=(130, 170)
  234. ),
  235. wx.StaticBox(
  236. parent=self, label="Slot5:",id=wx.ID_ANY,
  237. pos=(220, 400), size=(130, 170)
  238. ),
  239. wx.StaticBox(
  240. parent=self, label="Slot6:",id=wx.ID_ANY,
  241. pos=(220, 225), size=(130, 170)
  242. )
  243. ]
  244. self._set_label_list = [
  245. wx.StaticText(
  246. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  247. pos=(5, 0), size=(130, 10)
  248. ),
  249. wx.StaticText(
  250. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  251. pos=(5, 0), size=(130, 10)
  252. ),
  253. wx.StaticText(
  254. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  255. pos=(5, 0), size=(130, 10)
  256. ),
  257. wx.StaticText(
  258. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  259. pos=(5, 0), size=(130, 10)
  260. ),
  261. wx.StaticText(
  262. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  263. pos=(5, 0), size=(130, 10)
  264. ),
  265. wx.StaticText(
  266. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  267. pos=(5, 0), size=(130, 10)
  268. ),
  269. ]
  270. self._id_label_list = [
  271. wx.StaticText(
  272. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  273. pos=(5, 15), size=(130, 10)
  274. ),
  275. wx.StaticText(
  276. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  277. pos=(5, 15), size=(130, 10)
  278. ),
  279. wx.StaticText(
  280. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  281. pos=(5, 15), size=(130, 10)
  282. ),
  283. wx.StaticText(
  284. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  285. pos=(5, 15), size=(130, 10)
  286. ),
  287. wx.StaticText(
  288. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  289. pos=(5, 15), size=(130, 10)
  290. ),
  291. wx.StaticText(
  292. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  293. pos=(5, 15), size=(130, 10)
  294. )
  295. ]
  296. self._main_label_list = [
  297. wx.StaticText(
  298. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  299. pos=(5, 35), size=(130, 10)
  300. ),
  301. wx.StaticText(
  302. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  303. pos=(5, 35), size=(130, 10)
  304. ),
  305. wx.StaticText(
  306. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  307. pos=(5, 35), size=(130, 10)
  308. ),
  309. wx.StaticText(
  310. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  311. pos=(5, 35), size=(130, 10)
  312. ),
  313. wx.StaticText(
  314. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  315. pos=(5, 35), size=(130, 10)
  316. ),
  317. wx.StaticText(
  318. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  319. pos=(5, 35), size=(130, 10)
  320. )
  321. ]
  322. self._innate_label_list = [
  323. wx.StaticText(
  324. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  325. pos=(5, 50), size=(130, 10)
  326. ),
  327. wx.StaticText(
  328. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  329. pos=(5, 50), size=(130, 10)
  330. ),
  331. wx.StaticText(
  332. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  333. pos=(5, 50), size=(130, 10)
  334. ),
  335. wx.StaticText(
  336. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  337. pos=(5, 50), size=(130, 10)
  338. ),
  339. wx.StaticText(
  340. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  341. pos=(5, 50), size=(130, 10)
  342. ),
  343. wx.StaticText(
  344. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  345. pos=(5, 50), size=(130, 10)
  346. )
  347. ]
  348. self._stat_label_list = [
  349. [
  350. wx.StaticText(
  351. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  352. pos=(5, 70), size=(130, 10)
  353. ),
  354. wx.StaticText(
  355. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  356. pos=(5, 85), size=(130, 10)
  357. ),
  358. wx.StaticText(
  359. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  360. pos=(5, 100), size=(130, 10)
  361. ),
  362. wx.StaticText(
  363. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  364. pos=(5, 115), size=(130, 10)
  365. )
  366. ],
  367. [
  368. wx.StaticText(
  369. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  370. pos=(5, 70), size=(130, 10)
  371. ),
  372. wx.StaticText(
  373. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  374. pos=(5, 85), size=(130, 10)
  375. ),
  376. wx.StaticText(
  377. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  378. pos=(5, 100), size=(130, 10)
  379. ),
  380. wx.StaticText(
  381. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  382. pos=(5, 115), size=(130, 10)
  383. )
  384. ],
  385. [
  386. wx.StaticText(
  387. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  388. pos=(5, 70), size=(130, 10)
  389. ),
  390. wx.StaticText(
  391. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  392. pos=(5, 85), size=(130, 10)
  393. ),
  394. wx.StaticText(
  395. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  396. pos=(5, 100), size=(130, 10)
  397. ),
  398. wx.StaticText(
  399. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  400. pos=(5, 115), size=(130, 10)
  401. )
  402. ],
  403. [
  404. wx.StaticText(
  405. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  406. pos=(5, 70), size=(130, 10)
  407. ),
  408. wx.StaticText(
  409. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  410. pos=(5, 85), size=(130, 10)
  411. ),
  412. wx.StaticText(
  413. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  414. pos=(5, 100), size=(130, 10)
  415. ),
  416. wx.StaticText(
  417. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  418. pos=(5, 115), size=(130, 10)
  419. )
  420. ],
  421. [
  422. wx.StaticText(
  423. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  424. pos=(5, 70), size=(130, 10)
  425. ),
  426. wx.StaticText(
  427. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  428. pos=(5, 85), size=(130, 10)
  429. ),
  430. wx.StaticText(
  431. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  432. pos=(5, 100), size=(130, 10)
  433. ),
  434. wx.StaticText(
  435. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  436. pos=(5, 115), size=(130, 10)
  437. )
  438. ],
  439. [
  440. wx.StaticText(
  441. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  442. pos=(5, 70), size=(130, 10)
  443. ),
  444. wx.StaticText(
  445. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  446. pos=(5, 85), size=(130, 10)
  447. ),
  448. wx.StaticText(
  449. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  450. pos=(5, 100), size=(130, 10)
  451. ),
  452. wx.StaticText(
  453. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  454. pos=(5, 115), size=(130, 10)
  455. )
  456. ]
  457. ]
  458. self._eff_label_list = [
  459. wx.StaticText(
  460. parent=rune_box_list[0], id=wx.ID_ANY, label="",
  461. pos=(5, 135), size=(130, 10)
  462. ),
  463. wx.StaticText(
  464. parent=rune_box_list[1], id=wx.ID_ANY, label="",
  465. pos=(5, 135), size=(130, 10)
  466. ),
  467. wx.StaticText(
  468. parent=rune_box_list[2], id=wx.ID_ANY, label="",
  469. pos=(5, 135), size=(130, 10)
  470. ),
  471. wx.StaticText(
  472. parent=rune_box_list[3], id=wx.ID_ANY, label="",
  473. pos=(5, 135), size=(130, 10)
  474. ),
  475. wx.StaticText(
  476. parent=rune_box_list[4], id=wx.ID_ANY, label="",
  477. pos=(5, 135), size=(130, 10)
  478. ),
  479. wx.StaticText(
  480. parent=rune_box_list[5], id=wx.ID_ANY, label="",
  481. pos=(5, 135), size=(130, 10)
  482. ),
  483. ]
  484. for i in range(0, 6):
  485. # Separators
  486. wx.StaticLine(
  487. parent=rune_box_list[i], id=wx.ID_ANY,
  488. pos=(0, 30), size=(130, 1), style=wx.LC_REPORT
  489. )
  490. wx.StaticLine(
  491. parent=rune_box_list[i], id=wx.ID_ANY,
  492. pos=(0, 135), size=(130, 1), style=wx.LC_REPORT
  493. )
  494. # Set fonts
  495. rune_box_list[i].SetFont(monospace_font)
  496. self._eff_label_list[i].SetFont(monospace_font_italic)
  497. self._main_label_list[i].SetFont(monospace_font_bold)
  498. self._innate_label_list[i].SetFont(monospace_font_italic)
  499. # Add boxes to sizer
  500. self._details_sizer.Add(rune_box_list[i])
  501. # By default, hide all optimization options
  502. self._details_sizer.ShowItems(False)
  503. def populate_unit_list(self, event=None):
  504. """Populates the unit list.
  505. Uses the filters.
  506. Parameters
  507. ----------
  508. event : wx.Event, optional
  509. The event that triggered the call (default is None).
  510. """
  511. # Loop all units
  512. i = 0
  513. filter_name = self._filter_name_text.GetValue()
  514. opt_storage = self._filter_storage_check.GetValue()
  515. opt_no_runes = self._filter_storage_check.GetValue()
  516. opt_no_teams = self._filter_no_teams_check.GetValue()
  517. self._unit_list.DeleteAllItems()
  518. for unit in units.values():
  519. if opt_storage == False and unit.in_storage == True:
  520. continue
  521. if opt_no_runes == False and unit.has_runes == False:
  522. continue
  523. if opt_no_teams == False and unit.in_teams == False:
  524. continue
  525. if len(filter_name) > 0:
  526. if filter_name.upper() not in unit.name.upper():
  527. continue
  528. self._unit_list.InsertItem(i, unit.name)
  529. self._unit_list.SetItem(i, 1, str(unit.priority))
  530. if (unit.in_storage):
  531. self._unit_list.SetItem(i, 2, "X")
  532. else:
  533. self._unit_list.SetItem(i, 2, " ")
  534. # TODO Items can't hold too much data in Windows, store the first
  535. # nine digits and rerieve it from database with LIKE
  536. self._unit_list.SetItemData(i, int(unit.id))
  537. i = i + 1
  538. def _go_to_optimizer(self, event = None):
  539. """Prepares the optimizer panel with the selected unit and redirects.
  540. Parameters
  541. ----------
  542. event : wx.Event, optional
  543. The event that triggered the call (default is None).
  544. """
  545. self.GetParent().panel_optimizer.select_unit(
  546. event=None, unit_id=self._selected_unit.id
  547. )
  548. self.GetParent().ChangeSelection(2)
  549. def _unit_selected(self, event):
  550. """Loads a unit info and enables optimizaton options.
  551. Called when a unit is selected from the list.
  552. Parameters
  553. ----------
  554. event : wx.Event, optional
  555. The event that triggered the call (default is None).
  556. """
  557. unit_id = \
  558. str(self._unit_list.GetItemData(self._unit_list.GetFirstSelected()))
  559. self._selected_unit = units[unit_id]
  560. # Set label
  561. self._name_label.SetLabel(self._selected_unit.name)
  562. stars_label_text = ""
  563. for i in range(0, self._selected_unit.stars):
  564. stars_label_text += "\u272D"
  565. self._stars_label.SetLabel(stars_label_text)
  566. self._level_label.SetLabel("Lv. " + str(self._selected_unit.level))
  567. self._priority_label.SetLabel(
  568. "Priority: " + str(self._selected_unit.priority)
  569. )
  570. self._id_label.SetLabel("#" + self._selected_unit.id)
  571. self._details_sizer.ShowItems(True)
  572. # Populate stats
  573. self._stat_grid.SetCellValue(
  574. row=0, col=0, s=str(self._selected_unit.base_stats.hp)
  575. )
  576. self._stat_grid.SetCellValue(
  577. row=0, col=1, s=str(self._selected_unit.stats.hp)
  578. )
  579. self._stat_grid.SetCellValue(
  580. row=1, col=0, s=str(self._selected_unit.base_stats.atk)
  581. )
  582. self._stat_grid.SetCellValue(
  583. row=1, col=1, s=str(self._selected_unit.stats.atk)
  584. )
  585. self._stat_grid.SetCellValue(
  586. row=2, col=0, s=str(self._selected_unit.base_stats.dfc)
  587. )
  588. self._stat_grid.SetCellValue(
  589. row=2, col=1, s=str(self._selected_unit.stats.dfc)
  590. )
  591. self._stat_grid.SetCellValue(
  592. row=3, col=0, s=str(self._selected_unit.base_stats.spd)
  593. )
  594. self._stat_grid.SetCellValue(
  595. row=3, col=1, s=str(self._selected_unit.stats.spd)
  596. )
  597. self._stat_grid.SetCellValue(
  598. row=4, col=0, s=str(self._selected_unit.base_stats.crr)
  599. )
  600. self._stat_grid.SetCellValue(
  601. row=4, col=1, s=str(self._selected_unit.stats.crr)
  602. )
  603. self._stat_grid.SetCellValue(
  604. row=5, col=0, s=str(self._selected_unit.base_stats.crd)
  605. )
  606. self._stat_grid.SetCellValue(
  607. row=5, col=1, s=str(self._selected_unit.stats.crd)
  608. )
  609. self._stat_grid.SetCellValue(
  610. row=6, col=0, s=str(self._selected_unit.base_stats.res)
  611. )
  612. self._stat_grid.SetCellValue(
  613. row=6, col=1, s=str(self._selected_unit.stats.res)
  614. )
  615. self._stat_grid.SetCellValue(
  616. row=7, col=0, s=str(self._selected_unit.base_stats.acc)
  617. )
  618. self._stat_grid.SetCellValue(
  619. row=7, col=1, s=str(self._selected_unit.stats.acc)
  620. )
  621. self._stat_grid.SetCellValue(
  622. row=8, col=0, s=str(self._selected_unit.base_stats.ehp)
  623. )
  624. self._stat_grid.SetCellValue(
  625. row=8, col=1, s=str(self._selected_unit.stats.ehp)
  626. )
  627. self._stat_grid.SetCellValue(
  628. row=9, col=0, s=str(self._selected_unit.base_stats.dmg)
  629. )
  630. self._stat_grid.SetCellValue(
  631. row=9, col=1, s=str(self._selected_unit.stats.dmg)
  632. )
  633. # Write the team list
  634. team_label_text = ""
  635. for team in self._selected_unit.teams:
  636. team_label_text += "-" + team.name[0:16].ljust(16, " ")
  637. team_label_text += ("(#" + team.id + ")").rjust(6) + "\n"
  638. self._teams_label.SetLabel(team_label_text)
  639. # Populate the runes
  640. i = 0
  641. for rune in self._selected_unit.runes:
  642. # Rows are 18 charactes width
  643. # First line: Set name, level
  644. self._set_label_list[rune.slot - 1].SetLabel(
  645. rune.type_name[0:9].ljust(12, " ") + \
  646. "+" + str(rune.level).ljust(3, " ")
  647. )
  648. # Second line: ID
  649. lvl_set_eff = rune.type_name[0:6].ljust(6, " ")
  650. effv = str(("{:.2f}".format(rune.efficiency)).rjust(5, " "))
  651. eff = (" Eff:" + str(effv) + "%")
  652. lvl_set_eff += eff
  653. self._id_label_list[i].SetLabel(("#" + rune.id).rjust(15, " "))
  654. # Efficiency
  655. label_eff_text = \
  656. "Eff.: " + ("{:.1f}".format(rune.efficiency)).rjust(4, " ") + \
  657. "/" + ("{:.1f}".format(rune.max_efficiency)).rjust(4, " ")
  658. self._eff_label_list[rune.slot - 1].SetLabel(label_eff_text)
  659. # Write all stats
  660. innate_label = " "
  661. for stat in rune.stats:
  662. if stat == None:
  663. continue
  664. slot = stat.slot
  665. if stat.is_enchanted:
  666. name = (
  667. stat.name
  668. .replace("%", "").
  669. replace(" ", "") + "* "
  670. ).rjust(5, " ")
  671. else:
  672. name = (
  673. stat.name
  674. .replace("%", "")
  675. .replace(" ", "") + " "
  676. ).rjust(5, " ")
  677. value = str(stat.value)
  678. if stat.stat in [2, 4, 6, 9, 10, 11, 23]:
  679. value = value + "%"
  680. else:
  681. value = value + " "
  682. value = value.rjust(5)
  683. if stat.grind > 0: # if grinded
  684. value = value + " +" + str(stat.grind).rjust(2)
  685. if stat.stat in [2, 4, 6, 9, 10, 11, 23]:
  686. value = value + "%"
  687. line = name + value
  688. if slot == -1: # main
  689. self._main_label_list[i].SetLabel(line)
  690. elif slot == 0: # innate
  691. innate_label = line
  692. else: # normal stats
  693. self._stat_label_list[i][slot - 1].SetLabel(line)
  694. self._innate_label_list[i].SetLabel(innate_label)
  695. i = i + 1