PanelUnits.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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. Parameters
  18. ----------
  19. selecterId : string
  20. ID of the currently selected unit.
  21. unitList : wx.ListCtrl
  22. Selectable unit list with priorities.
  23. filterNameText : wx.TextCtrl
  24. Text input to filter units names.
  25. filterNameTexts : wx.CheckBox
  26. Checkbox to include or exclude units in storage.
  27. filterNoRunesCheck : wx.CheckBox
  28. Checkbox to include or exclude units without runes.
  29. filterNoTeamsCheck : wx.CheckBox
  30. Checkbox to include or exclude units in no teams.
  31. detailsSizer : wx.BoxSizer
  32. Hold the unit detail elements. Hidden until unit selction.
  33. nameLabel : wx.StaticText
  34. Label for the unit name.
  35. statGrid : wx.Grid.grid
  36. Table with the unit base and current stats.
  37. setLabelList : wx.StaticText[6]
  38. Labels with the set of the runes of the selected unit.
  39. idLabelList : wx.StaticText[6]
  40. Labels with the IDs of the runes of the selected unit.
  41. mainLabelList : wx.StaticText[6]
  42. Labels with the main stats of the runes of the selected unit.
  43. innateLabelList : wx.StaticText[6]
  44. Labels with the innates of the runes of the selected unit.
  45. statLabelList : wx.StaticText[6][4]
  46. Labels with the stats of the runes of the selected unit.
  47. Methods
  48. -------
  49. populateUnitList(event)
  50. Populates the unit list.
  51. goToOptimizer(event)
  52. Prepares the optimizer panel with the selected unit and redirects.
  53. unitSelected(event)
  54. Loads a unit info.
  55. processResults(jsonData)
  56. Processes data obtained from RuneOptimizer.
  57. """
  58. selectedId = None
  59. unitList = None
  60. filterNameText = None
  61. filterStorageCheck = None
  62. filterNoRunesCheck = None
  63. filterNoTeamsCheck = None
  64. detailsSizer = None
  65. nameLabel = None
  66. statGrid = None
  67. setLabelList = None
  68. idLabelList = None
  69. mainLabelList = None
  70. innateLabelList = None
  71. statLabelList = None
  72. def __init__(self, parent, id=wx.ID_ANY):
  73. """Initializes the panel.
  74. Sets upt all the widgets.
  75. Parameters
  76. ----------
  77. parent : wx.*
  78. Panel parent.
  79. id : int, optional
  80. ID for the panel (default wx.ID_ANY).
  81. """
  82. # Parent constructor
  83. wx.Panel.__init__(self, parent=parent, id=id)
  84. # Prepare some fonts
  85. titleFont = wx.Font(
  86. pointSize=14, family=wx.FONTFAMILY_DEFAULT,
  87. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  88. )
  89. monospaceFont = wx.Font(
  90. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  91. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL
  92. )
  93. monospaceFontBold = wx.Font(
  94. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  95. style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
  96. )
  97. monospaceFontItalic = wx.Font(
  98. pointSize=10, family=wx.FONTFAMILY_TELETYPE,
  99. style=wx.FONTSTYLE_ITALIC, weight=wx.FONTWEIGHT_NORMAL
  100. )
  101. # Unit selectable list
  102. wx.StaticText(
  103. parent=self, id=wx.ID_ANY,
  104. label="Name Prio. Sto.",
  105. pos=(10, 10), size=(190, 20)
  106. )
  107. self.unitList = wx.ListCtrl(
  108. parent=self, id=wx.ID_ANY, pos=(10, 30), size=(190, 350),
  109. style=wx.LC_REPORT|wx.LC_NO_HEADER
  110. )
  111. self.unitList.InsertColumn(0, "Name", width=120)
  112. self.unitList.InsertColumn(1, "Prio.", width=40)
  113. self.unitList.InsertColumn(2, "Sto.", width=30)
  114. self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.unitSelected, self.unitList)
  115. # List filters
  116. filterBox = wx.StaticBox(
  117. parent=self, label="Filters:",id=wx.ID_ANY,
  118. pos=(10, 390), size=(190, 150)
  119. )
  120. wx.StaticText(
  121. parent=filterBox, label="Monster name", pos=(5, 5), size=(180, 20)
  122. )
  123. self.filterNameText = wx.TextCtrl(
  124. parent=filterBox, id=wx.ID_ANY, value="", pos=(5, 25),
  125. size=(177, 20), style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB
  126. )
  127. self.Bind(wx.EVT_TEXT, self.populateUnitList, self.filterNameText)
  128. self.filterStorageCheck = wx.CheckBox(
  129. parent=filterBox, id=wx.ID_ANY,
  130. label="Monsters in storage", pos=(5, 55), size=(180, 20)
  131. )
  132. self.filterStorageCheck.SetValue(True)
  133. self.Bind(
  134. wx.EVT_CHECKBOX, self.populateUnitList, self.filterStorageCheck
  135. )
  136. self.filterNoRunesCheck = wx.CheckBox(
  137. parent=filterBox, id=wx.ID_ANY,
  138. label="Monsters without runes", pos=(5, 75), size=(180, 20)
  139. )
  140. self.filterNoRunesCheck.SetValue(True)
  141. self.Bind(
  142. wx.EVT_CHECKBOX, self.populateUnitList, self.filterNoRunesCheck
  143. )
  144. self.filterNoTeamsCheck = wx.CheckBox(
  145. parent=filterBox, id=wx.ID_ANY,
  146. label="Monsters not in teams", pos=(5, 95), size=(180, 20)
  147. )
  148. self.filterNoTeamsCheck.SetValue(True)
  149. self.Bind(
  150. wx.EVT_CHECKBOX, self.populateUnitList, self.filterNoTeamsCheck
  151. )
  152. self.populateUnitList(None)
  153. # Sizer for all the unit details. It will be hidden until a unit is
  154. # selected.
  155. self.detailsSizer = wx.BoxSizer(wx.VERTICAL)
  156. # Unit name
  157. self.nameLabel = wx.StaticText(
  158. parent=self, label="", pos=(220, 0), size=(120, 100)
  159. )
  160. self.detailsSizer.Add(self.nameLabel)
  161. self.nameLabel.SetFont(titleFont)
  162. # Team list
  163. teamBox = wx.StaticBox(
  164. parent=self, label="Teams:",id=wx.ID_ANY,
  165. pos=(390, 0), size=(145, 200)
  166. )
  167. self.detailsSizer.Add(teamBox)
  168. self.teamsLabel = wx.StaticText(
  169. parent=teamBox, label="", pos=(5, 5), size=(135, 190)
  170. )
  171. monospaceFont.PointSize -= 2
  172. self.teamsLabel.SetFont(monospaceFont)
  173. monospaceFont.PointSize += 2
  174. optimizeButton = wx.Button(
  175. parent=self, id=wx.ID_ANY, pos=(230, 120), size=(120, 50),
  176. style=wx.LC_REPORT, label="Optimize"
  177. )
  178. self.detailsSizer.Add(optimizeButton)
  179. self.Bind(wx.EVT_BUTTON, self.goToOptimizer, optimizeButton)
  180. # Stats table
  181. self.statGrid = wx.grid.Grid(
  182. parent=self, id=wx.ID_ANY, pos=(550, 00), size=(165, 220)
  183. )
  184. self.detailsSizer.Add(self.statGrid)
  185. self.statGrid.CreateGrid(
  186. numRows=10, numCols=2
  187. )
  188. self.statGrid.EnableEditing(False)
  189. self.statGrid.SetDefaultCellAlignment(
  190. horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE
  191. )
  192. self.statGrid.SetDefaultCellFont(monospaceFont)
  193. self.statGrid.SetColSize(col=0, width=50)
  194. self.statGrid.SetColLabelValue(col=0, value="Base")
  195. self.statGrid.SetColSize(col=0, width=50)
  196. self.statGrid.SetColLabelValue(col=1, value="Current")
  197. self.statGrid.SetRowLabelSize(width=35)
  198. self.statGrid.SetColLabelSize(height=20)
  199. self.statGrid.SetRowSize(row=0, height=20)
  200. self.statGrid.SetRowSize(row=1, height=20)
  201. self.statGrid.SetRowSize(row=2, height=20)
  202. self.statGrid.SetRowSize(row=3, height=20)
  203. self.statGrid.SetRowSize(row=4, height=20)
  204. self.statGrid.SetRowSize(row=5, height=20)
  205. self.statGrid.SetRowSize(row=6, height=20)
  206. self.statGrid.SetRowSize(row=7, height=20)
  207. self.statGrid.SetRowSize(row=8, height=20)
  208. self.statGrid.SetRowSize(row=9, height=20)
  209. self.statGrid.SetRowLabelValue(row=0, value=" HP")
  210. self.statGrid.SetRowLabelValue(row=1, value="ATK")
  211. self.statGrid.SetRowLabelValue(row=2, value="DEF")
  212. self.statGrid.SetRowLabelValue(row=3, value="SPD")
  213. self.statGrid.SetRowLabelValue(row=4, value="CRR")
  214. self.statGrid.SetRowLabelValue(row=5, value="CRD")
  215. self.statGrid.SetRowLabelValue(row=6, value="RES")
  216. self.statGrid.SetRowLabelValue(row=7, value="ACC")
  217. self.statGrid.SetRowLabelValue(row=8, value="EHP")
  218. self.statGrid.SetRowLabelValue(row=9, value="DMG")
  219. # Rune list
  220. runeBoxList = [
  221. wx.StaticBox(
  222. parent=self, label="Slot1:",id=wx.ID_ANY,
  223. pos=(390, 225), size=(145, 150)
  224. ),
  225. wx.StaticBox(
  226. parent=self, label="Slot2:",id=wx.ID_ANY,
  227. pos=(560, 225), size=(145, 150)
  228. ),
  229. wx.StaticBox(
  230. parent=self, label="Slot3:",id=wx.ID_ANY,
  231. pos=(560, 390), size=(145, 150)
  232. ),
  233. wx.StaticBox(
  234. parent=self, label="Slot4:",id=wx.ID_ANY,
  235. pos=(390, 390), size=(145, 150)
  236. ),
  237. wx.StaticBox(
  238. parent=self, label="Slot5:",id=wx.ID_ANY,
  239. pos=(220, 390), size=(145, 150)
  240. ),
  241. wx.StaticBox(
  242. parent=self, label="Slot6:",id=wx.ID_ANY,
  243. pos=(220, 225), size=(145, 150)
  244. )
  245. ]
  246. for i in range(0, 6):
  247. runeBoxList[i].SetFont(monospaceFont)
  248. self.detailsSizer.Add(runeBoxList[i])
  249. self.setLabelList = [
  250. wx.StaticText(
  251. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  252. pos=(0, 0), size=(145, 10)
  253. ),
  254. wx.StaticText(
  255. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  256. pos=(0, 0), size=(145, 10)
  257. ),
  258. wx.StaticText(
  259. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  260. pos=(0, 0), size=(145, 10)
  261. ),
  262. wx.StaticText(
  263. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  264. pos=(0, 0), size=(145, 10)
  265. ),
  266. wx.StaticText(
  267. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  268. pos=(0, 0), size=(145, 10)
  269. ),
  270. wx.StaticText(
  271. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  272. pos=(0, 0), size=(145, 10)
  273. ),
  274. ]
  275. self.idLabelList = [
  276. wx.StaticText(
  277. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  278. pos=(0, 15), size=(145, 10)
  279. ),
  280. wx.StaticText(
  281. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  282. pos=(0, 15), size=(145, 10)
  283. ),
  284. wx.StaticText(
  285. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  286. pos=(0, 15), size=(145, 10)
  287. ),
  288. wx.StaticText(
  289. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  290. pos=(0, 15), size=(145, 10)
  291. ),
  292. wx.StaticText(
  293. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  294. pos=(0, 15), size=(145, 10)
  295. ),
  296. wx.StaticText(
  297. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  298. pos=(0, 15), size=(145, 10)
  299. )
  300. ]
  301. wx.StaticLine(
  302. parent=runeBoxList[0], id=wx.ID_ANY,
  303. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  304. )
  305. wx.StaticLine(
  306. parent=runeBoxList[1], id=wx.ID_ANY,
  307. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  308. )
  309. wx.StaticLine(
  310. parent=runeBoxList[2], id=wx.ID_ANY,
  311. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  312. )
  313. wx.StaticLine(
  314. parent=runeBoxList[3], id=wx.ID_ANY,
  315. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  316. )
  317. wx.StaticLine(
  318. parent=runeBoxList[4], id=wx.ID_ANY,
  319. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  320. )
  321. wx.StaticLine(
  322. parent=runeBoxList[5], id=wx.ID_ANY,
  323. pos=(0, 30), size=(145, 1), style=wx.LC_REPORT
  324. )
  325. self.mainLabelList = [
  326. wx.StaticText(
  327. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  328. pos=(0, 35), size=(145, 10)
  329. ),
  330. wx.StaticText(
  331. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  332. pos=(0, 35), size=(145, 10)
  333. ),
  334. wx.StaticText(
  335. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  336. pos=(0, 35), size=(145, 10)
  337. ),
  338. wx.StaticText(
  339. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  340. pos=(0, 35), size=(145, 10)
  341. ),
  342. wx.StaticText(
  343. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  344. pos=(0, 35), size=(145, 10)
  345. ),
  346. wx.StaticText(
  347. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  348. pos=(0, 35), size=(145, 10)
  349. )
  350. ]
  351. for i in range(0, 6):
  352. self.mainLabelList[i].SetFont(monospaceFontBold)
  353. self.innateLabelList = [
  354. wx.StaticText(
  355. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  356. pos=(0, 50), size=(145, 10)
  357. ),
  358. wx.StaticText(
  359. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  360. pos=(0, 50), size=(145, 10)
  361. ),
  362. wx.StaticText(
  363. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  364. pos=(0, 50), size=(145, 10)
  365. ),
  366. wx.StaticText(
  367. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  368. pos=(0, 50), size=(145, 10)
  369. ),
  370. wx.StaticText(
  371. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  372. pos=(0, 50), size=(145, 10)
  373. ),
  374. wx.StaticText(
  375. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  376. pos=(0, 50), size=(145, 10)
  377. )
  378. ]
  379. for i in range(0, 6):
  380. self.innateLabelList[i].SetFont(monospaceFontItalic)
  381. self.statLabelList = [
  382. [
  383. wx.StaticText(
  384. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  385. pos=(0, 70), size=(145, 10)
  386. ),
  387. wx.StaticText(
  388. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  389. pos=(0, 85), size=(145, 10)
  390. ),
  391. wx.StaticText(
  392. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  393. pos=(0, 100), size=(145, 10)
  394. ),
  395. wx.StaticText(
  396. parent=runeBoxList[0], id=wx.ID_ANY, label="",
  397. pos=(0, 115), size=(145, 10)
  398. )
  399. ],
  400. [
  401. wx.StaticText(
  402. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  403. pos=(0, 70), size=(145, 10)
  404. ),
  405. wx.StaticText(
  406. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  407. pos=(0, 85), size=(145, 10)
  408. ),
  409. wx.StaticText(
  410. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  411. pos=(0, 100), size=(145, 10)
  412. ),
  413. wx.StaticText(
  414. parent=runeBoxList[1], id=wx.ID_ANY, label="",
  415. pos=(0, 115), size=(145, 10)
  416. )
  417. ],
  418. [
  419. wx.StaticText(
  420. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  421. pos=(0, 70), size=(145, 10)
  422. ),
  423. wx.StaticText(
  424. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  425. pos=(0, 85), size=(145, 10)
  426. ),
  427. wx.StaticText(
  428. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  429. pos=(0, 100), size=(145, 10)
  430. ),
  431. wx.StaticText(
  432. parent=runeBoxList[2], id=wx.ID_ANY, label="",
  433. pos=(0, 115), size=(145, 10)
  434. )
  435. ],
  436. [
  437. wx.StaticText(
  438. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  439. pos=(0, 70), size=(145, 10)
  440. ),
  441. wx.StaticText(
  442. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  443. pos=(0, 85), size=(145, 10)
  444. ),
  445. wx.StaticText(
  446. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  447. pos=(0, 100), size=(145, 10)
  448. ),
  449. wx.StaticText(
  450. parent=runeBoxList[3], id=wx.ID_ANY, label="",
  451. pos=(0, 115), size=(145, 10)
  452. )
  453. ],
  454. [
  455. wx.StaticText(
  456. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  457. pos=(0, 70), size=(145, 10)
  458. ),
  459. wx.StaticText(
  460. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  461. pos=(0, 85), size=(145, 10)
  462. ),
  463. wx.StaticText(
  464. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  465. pos=(0, 100), size=(145, 10)
  466. ),
  467. wx.StaticText(
  468. parent=runeBoxList[4], id=wx.ID_ANY, label="",
  469. pos=(0, 115), size=(145, 10)
  470. )
  471. ],
  472. [
  473. wx.StaticText(
  474. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  475. pos=(0, 70), size=(145, 10)
  476. ),
  477. wx.StaticText(
  478. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  479. pos=(0, 85), size=(145, 10)
  480. ),
  481. wx.StaticText(
  482. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  483. pos=(0, 100), size=(145, 10)
  484. ),
  485. wx.StaticText(
  486. parent=runeBoxList[5], id=wx.ID_ANY, label="",
  487. pos=(0, 115), size=(145, 10)
  488. )
  489. ]
  490. ]
  491. # By default, hide all optimization options
  492. self.detailsSizer.ShowItems(False)
  493. def populateUnitList(self, event=None):
  494. """Populates the unit list.
  495. Uses the filters.
  496. Parameters
  497. ----------
  498. event : wx.Event, optional
  499. The event that triggered the call (default is None).
  500. """
  501. # Get units from db
  502. name = self.filterNameText.GetValue()
  503. query = """
  504. SELECT
  505. id,
  506. name,
  507. (
  508. SELECT cast(total(teams.priority) as int)
  509. FROM teams, units_teams
  510. WHERE teams.id = units_teams.team AND units_teams.unit = units.id
  511. ) as priority,
  512. storage
  513. FROM units
  514. WHERE
  515. name LIKE '%""" + name + """%'
  516. """
  517. if self.filterStorageCheck.GetValue() == False:
  518. query += " AND storage = 0 "
  519. if self.filterNoRunesCheck.GetValue() == False:
  520. query += " AND id IN (SELECT DISTINCT unit FROM runes) "
  521. if self.filterNoTeamsCheck.GetValue() == False:
  522. query += " AND id IN (SELECT DISTINCT unit FROM units_teams) "
  523. query += " ORDER BY priority DESC; ";
  524. cursor = conn.execute(query)
  525. i = 0
  526. self.unitList.DeleteAllItems()
  527. for row in cursor:
  528. self.unitList.InsertItem(i, row[1])
  529. self.unitList.SetItem(i, 1, str(row[2]))
  530. self.unitList.SetItem(i, 2, "")
  531. # Items can't hold too much data in Windows, store the first nine
  532. # digits and rerieve it from database with LIKE
  533. self.unitList.SetItemData(i, int(str(row[0])[0:9]))
  534. if (row[3] == 1):
  535. self.unitList.SetItem(i, 2, "X")
  536. else:
  537. self.unitList.SetItem(i, 2, " ")
  538. i = i + 1
  539. def goToOptimizer(self, event = None):
  540. """Prepares the optimizer panel with the selected unit and redirects.
  541. Parameters
  542. ----------
  543. event : wx.Event, optional
  544. The event that triggered the call (default is None).
  545. """
  546. self.GetParent().frameOptimizer.unitId = self.selectedId
  547. self.GetParent().frameOptimizer.selectUnit(event=None)
  548. self.GetParent().ChangeSelection(2)
  549. def unitSelected(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. unitId = \
  558. str(self.unitList.GetItemData(self.unitList.GetFirstSelected()))
  559. cursor = conn.execute("""
  560. SELECT
  561. base_hp,
  562. base_atk,
  563. base_def,
  564. base_spd,
  565. base_crr,
  566. base_crd,
  567. base_res,
  568. base_acc,
  569. current_hp,
  570. current_atk,
  571. current_def,
  572. current_spd,
  573. current_crr,
  574. current_crd,
  575. current_res,
  576. current_acc,
  577. id,
  578. name,
  579. level
  580. FROM units
  581. WHERE
  582. id LIKE ?;
  583. """, (unitId + "%",))
  584. row = cursor.fetchone()
  585. unitId = row[16]
  586. self.selectedId = row[16]
  587. self.selectedId = unitId
  588. nameLabelText = ""
  589. unitName = row[17][0:15]
  590. if len(unitName) > 8:
  591. nameLabelText = \
  592. unitName + "\n(Lv." + str(row[18]) + ")\n\n#" + row[16]
  593. else:
  594. nameLabelText = \
  595. unitName + " (Lv." + str(row[18]) + ")\n\n#" + row[16]
  596. self.nameLabel.SetLabel(nameLabelText)
  597. self.detailsSizer.ShowItems(True)
  598. for i in range(0, 8):
  599. value = str(row[i])
  600. if i > 3:
  601. value = value + "%"
  602. else:
  603. value = value + " "
  604. self.statGrid.SetCellValue(row=i, col=0, s=value)
  605. for i in range(0, 8):
  606. value = str(row[8 + i])
  607. if i > 3:
  608. value = value + "%"
  609. else:
  610. value = value + " "
  611. self.statGrid.SetCellValue(row=i, col=1, s=value)
  612. # Galculate EHP and DMG
  613. baseHp = int(self.statGrid.GetCellValue(row=0, col=0))
  614. baseDef = int(self.statGrid.GetCellValue(row=2, col=0).replace("%", ""))
  615. baseEhp = math.ceil((((baseDef * 3.5) + 1140) * baseHp) / 1000)
  616. self.statGrid.SetCellValue(row=8, col=0, s=str(baseEhp))
  617. #self.minStatSlid[8].SetMin(baseEhp)
  618. currentHp = int(self.statGrid.GetCellValue(row=0, col=1))
  619. currentDef = \
  620. int(self.statGrid.GetCellValue(row=2, col=1).replace("%", ""))
  621. currentEhp = math.ceil((((currentDef * 3.5) + 1140) * currentHp) / 1000)
  622. self.statGrid.SetCellValue(row=8, col=1, s=str(currentEhp))
  623. baseAtk = int(self.statGrid.GetCellValue(row=1, col=0))
  624. baseCrr = int(self.statGrid.GetCellValue(row=4, col=0).replace("%", ""))
  625. baseCrd = int(self.statGrid.GetCellValue(row=5, col=0).replace("%", ""))
  626. if (baseCrr > 100):
  627. # Dont use crit rate over 100
  628. baseCrr = 100
  629. baseDmg = math.ceil(
  630. (baseAtk * (100 - baseCrr) / 100) +
  631. ((baseAtk + (baseAtk * baseCrd / 100)) * baseCrr / 100)
  632. )
  633. self.statGrid.SetCellValue(row=9, col=0, s=str(baseDmg))
  634. currentAtk = int(self.statGrid.GetCellValue(row=1, col=1))
  635. currentCrr = \
  636. int(self.statGrid.GetCellValue(row=4, col=0).replace("%", ""))
  637. currentCrd = \
  638. int(self.statGrid.GetCellValue(row=5, col=1).replace("%", ""))
  639. if (currentCrr > 100):
  640. currentCrr = 100
  641. currentDmg = math.ceil(
  642. (currentAtk * (100 - currentCrr) / 100) +
  643. ((currentAtk + (currentAtk * currentCrd / 100)) * currentCrr / 100)
  644. )
  645. self.statGrid.SetCellValue(row=9, col=1, s=str(currentDmg))
  646. # Get the team list
  647. cursorTeams = conn.execute("""
  648. SELECT id, name FROM teams
  649. WHERE id IN (SELECT DISTINCT team FROM units_teams WHERE unit = ?)
  650. """,
  651. (self.selectedId,)
  652. )
  653. teamLabelText = ""
  654. for row in cursorTeams:
  655. teamLabelText += "-" + row[1][0:16].ljust(16, " ")
  656. teamLabelText += ("(#" + row[0] + ")").rjust(6) + "\n"
  657. self.teamsLabel.SetLabel(teamLabelText)
  658. # Populate the runes
  659. cursor = conn.execute("""
  660. SELECT
  661. runes.id,
  662. runes.slot,
  663. runes.type,
  664. runes.level,
  665. units.id,
  666. units.name,
  667. runes.efficiency,
  668. runes.max_efficiency
  669. FROM runes LEFT JOIN units ON runes.unit = units.id
  670. WHERE runes.unit = ?
  671. ORDER BY runes.slot;
  672. """, (self.selectedId,))
  673. i = 0
  674. for row in cursor:
  675. # Rows are 18 charactes width
  676. # First line: Powerup level, ID
  677. labelLvId = ("+" + str(row[3])).ljust(3, " ")
  678. labelLvId += ("#" + str(row[0])).rjust(15, " ")
  679. self.setLabelList[i].SetLabel(labelLvId)
  680. # Second line: Set name, efficiency
  681. lvlSetEff = set_names[row[2]][0:6].ljust(6, " ")
  682. effv = str(("{:.2f}".format(row[6])).rjust(5, " "))
  683. eff = (" Eff:" + str(effv) + "%")
  684. lvlSetEff += eff
  685. self.idLabelList[i].SetLabel(lvlSetEff)
  686. # Get all stats
  687. cursorStats = conn.execute("""
  688. SELECT
  689. slot, stat, value, grind, enchant
  690. FROM rune_stats
  691. WHERE
  692. rune = """ + row[0] + """
  693. ORDER BY slot;
  694. """)
  695. j = -1
  696. innateLabel = " "
  697. for rowStats in cursorStats:
  698. slot = rowStats[0]
  699. if rowStats[4] == 1: # if enchanted
  700. name = (
  701. stat_names[rowStats[1]]
  702. .replace("%", "").
  703. replace(" ", "") + "* "
  704. ).rjust(5, " ")
  705. else:
  706. name = (
  707. stat_names[rowStats[1]]
  708. .replace("%", "")
  709. .replace(" ", "") + " "
  710. ).rjust(5, " ")
  711. value = str(rowStats[2])
  712. if rowStats[1] in [2, 4, 6, 9, 10, 11, 23]:
  713. value = value + "%"
  714. else:
  715. value = value + " "
  716. value = value.rjust(5)
  717. if rowStats[3] > 0: # if grinded
  718. value = value + " + " + str(rowStats[3])
  719. if rowStats[1] in [2, 4, 6, 9, 10, 11, 23]:
  720. value = value + "%"
  721. line = name + value
  722. if slot == -1: # main
  723. self.mainLabelList[i].SetLabel(line)
  724. elif slot == 0: # innate
  725. innateLabel = line
  726. else: # normal stats
  727. self.statLabelList[i][slot - 1].SetLabel(line)
  728. self.innateLabelList[i].SetLabel(innateLabel)
  729. i = i + 1