| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249 |
- """
- This file is part of RuneOptimizer.
- RuneOptimizer is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the Free
- Software Foundation, either version 3 of the License, or (at your option)
- any later version.
- RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
- You should have received a copy of the GNU General Public License along with
- RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
- """
- class PanelResults(wx.Panel):
- """
- The panel that shows results.
- Methods
- -------
- process_results(jsonData)
- Processes data obtained from RuneOptimizer.
- """
- _unit = None
- _results = None
- _data = None
- _page = 0
- _total_pages = 0
- _lines_per_page = 10
- _selected_result_index = -1
- _unit_name_label = None
- _table_sizer = None
- _details_sizer = None
- _result_grid = None
- _page_prev_button = None
- _page_label = None
- _page_next_button = None
- _stat_grid = None
- _id_label_list = None
- _location_label_list = None
- _set_label_list = None
- _main_label_list = None
- _innate_label_list = None
- _stat_label_list = None
- def __init__(self, parent, id=wx.ID_ANY):
- """Initializes the panel.
- Sets upt all the widgets.
- Parameters
- ----------
- parent : wx.*
- Panel parent.
- id : int, optional
- ID for the panel (default wx.ID_ANY).
- """
- # Parent constructor
- wx.Panel.__init__(self, parent=parent, id=id)
- # Prepare some fonts
- title_font = wx.Font(
- pointSize=14, family=wx.FONTFAMILY_DEFAULT,
- style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
- )
- subtitle_font = wx.Font(
- pointSize=12, family=wx.FONTFAMILY_DEFAULT,
- style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
- )
- monospace_font = wx.Font(
- pointSize=9, family=wx.FONTFAMILY_TELETYPE,
- style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL
- )
- monospace_font_bold = wx.Font(
- pointSize=9, family=wx.FONTFAMILY_TELETYPE,
- style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD
- )
- monospace_font_italic = wx.Font(
- pointSize=9, family=wx.FONTFAMILY_TELETYPE,
- style=wx.FONTSTYLE_ITALIC, weight=wx.FONTWEIGHT_NORMAL
- )
- # Contains the results table and unit details. Hidden until they are
- # loaded.
- self._table_sizer = wx.BoxSizer(wx.VERTICAL)
- # Contains all thigs to be shown once a result is selected
- self._details_sizer = wx.BoxSizer(wx.VERTICAL)
- # Unit name, or placeholder message
- self._unit_name_label = wx.StaticText(
- parent=self, id=wx.ID_ANY, label="Nothing yet.\nOptimize something!",
- pos=(10, 0), size=(400, 50)
- )
- self._unit_name_label.SetFont(title_font)
- #Unit details
- self._stars_label = wx.StaticText(
- parent=self, label="", pos=(20, 30), size=(120, 100)
- )
- self._stars_label.SetFont(title_font)
- self._table_sizer.Add(self._stars_label)
- self._level_label = wx.StaticText(
- parent=self, label="", pos=(20, 60), size=(120, 100)
- )
- self._table_sizer.Add(self._level_label)
- self._level_label.SetFont(subtitle_font)
- self._priority_label = wx.StaticText(
- parent=self, label="", pos=(20, 90), size=(120, 100)
- )
- self._priority_label.SetFont(subtitle_font)
- self._table_sizer.Add(self._priority_label)
- self._id_label = wx.StaticText(
- parent=self, label="", pos=(20, 120), size=(120, 100)
- )
- self._id_label.SetFont(subtitle_font)
- self._table_sizer.Add(self._id_label)
- # The result list table
- self._result_grid = wx.grid.Grid(
- parent=self, id=wx.ID_ANY, pos=(275, 0), size=(525, 170)
- )
- self._result_grid.CreateGrid(
- numRows=10, numCols=11
- )
- self._result_grid.EnableEditing(False)
- self._result_grid.SetSelectionMode(wx.grid.Grid.GridSelectionModes.SelectRows)
- self._result_grid.SetDefaultCellAlignment(
- horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE
- )
- monospace_font.PointSize -= 1
- self._result_grid.SetDefaultCellFont(monospace_font)
- monospace_font.PointSize += 1
- self._result_grid.SetRowLabelSize(width=35)
- self._result_grid.SetColLabelValue(col=0, value="Rating")
- self._result_grid.SetColSize(col=0, width=50)
- self._result_grid.SetColLabelValue(col=1, value="HP")
- self._result_grid.SetColSize(col=1, width=50)
- self._result_grid.SetColLabelValue(col=2, value="ATK")
- self._result_grid.SetColSize(col=2, width=40)
- self._result_grid.SetColLabelValue(col=3, value="DEF")
- self._result_grid.SetColSize(col=3, width=40)
- self._result_grid.SetColLabelValue(col=4, value="SPD")
- self._result_grid.SetColSize(col=4, width=40)
- self._result_grid.SetColLabelValue(col=5, value="CRR")
- self._result_grid.SetColSize(col=5, width=40)
- self._result_grid.SetColLabelValue(col=6, value="CRD")
- self._result_grid.SetColSize(col=6, width=40)
- self._result_grid.SetColLabelValue(col=7, value="RES")
- self._result_grid.SetColSize(col=7, width=40)
- self._result_grid.SetColLabelValue(col=8, value="ACC")
- self._result_grid.SetColSize(col=8, width=40)
- self._result_grid.SetColLabelValue(col=9, value="EHP")
- self._result_grid.SetColSize(col=9, width=60)
- self._result_grid.SetColLabelValue(col=10, value="DMG")
- self._result_grid.SetColSize(col=10, width=50)
- self._result_grid.SetColLabelSize(height=20)
- self._result_grid.SetDefaultRowSize(height=15)
- self._result_grid.Bind(
- wx.grid.EVT_GRID_SELECT_CELL, self._result_selected
- )
- self._table_sizer.Add(self._result_grid)
- # Paginator
- self._page_prev_button = wx.Button(
- parent=self, id=wx.ID_ANY, pos=(805, 0), size=(40, 50),
- style=wx.LC_REPORT, label="Prev\npage"
- )
- self._page_prev_button.Bind(wx.EVT_BUTTON, self._page_prev)
- self._table_sizer.Add(self._page_prev_button)
- self._page_label = wx.StaticText(
- parent=self,id=wx.ID_ANY, pos=(805, 50), size=(40, 15),
- style=wx.ALIGN_CENTRE_HORIZONTAL, label="1/1"
- )
- self._table_sizer.Add(self._page_label)
- self._page_next_button = wx.Button(
- parent=self, id=wx.ID_ANY, pos=(805, 70), size=(40, 50),
- style=wx.LC_REPORT, label="Next\npage"
- )
- self._page_next_button.Bind(wx.EVT_BUTTON, self._page_next)
- self._table_sizer.Add(self._page_next_button)
- # Stats table
- self._stat_grid = wx.grid.Grid(
- parent=self, id=wx.ID_ANY, pos=(40, 210),
- size=(275, 220), style=wx.LC_REPORT
- )
- self._stat_grid.CreateGrid(numRows=10, numCols=4)
- self._stat_grid.EnableEditing(False)
- self._stat_grid.SetDefaultCellAlignment(
- horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE
- )
- self._stat_grid.SetDefaultCellFont(monospace_font)
- self._stat_grid.SetColSize(col=0, width=60)
- self._stat_grid.SetColSize(col=1, width=60)
- self._stat_grid.SetColSize(col=2, width=60)
- self._stat_grid.SetColSize(col=3, width=60)
- self._stat_grid.SetColLabelValue(col=0, value="Base")
- self._stat_grid.SetColLabelValue(col=1, value="Curr.")
- self._stat_grid.SetColLabelValue(col=2, value="After")
- self._stat_grid.SetColLabelValue(col=3, value="Diff.")
- self._stat_grid.SetRowLabelSize(width=35)
- self._stat_grid.SetColLabelSize(height=20)
- self._stat_grid.SetRowSize(row=0, height=20)
- self._stat_grid.SetRowSize(row=1, height=20)
- self._stat_grid.SetRowSize(row=2, height=20)
- self._stat_grid.SetRowSize(row=3, height=20)
- self._stat_grid.SetRowSize(row=4, height=20)
- self._stat_grid.SetRowSize(row=5, height=20)
- self._stat_grid.SetRowSize(row=6, height=20)
- self._stat_grid.SetRowSize(row=7, height=20)
- self._stat_grid.SetRowSize(row=8, height=20)
- self._stat_grid.SetRowSize(row=9, height=20)
- self._stat_grid.SetRowLabelValue(row=0, value=" HP")
- self._stat_grid.SetRowLabelValue(row=1, value="ATK")
- self._stat_grid.SetRowLabelValue(row=2, value="DEF")
- self._stat_grid.SetRowLabelValue(row=3, value="SPD")
- self._stat_grid.SetRowLabelValue(row=4, value="CRR")
- self._stat_grid.SetRowLabelValue(row=5, value="CRD")
- self._stat_grid.SetRowLabelValue(row=6, value="RES")
- self._stat_grid.SetRowLabelValue(row=7, value="ACC")
- self._stat_grid.SetRowLabelValue(row=8, value="EHP")
- self._stat_grid.SetRowLabelValue(row=9, value="DMG")
- self._details_sizer.Add(self._stat_grid)
- #Rune set list
- rune_box_list = [
- wx.StaticBox(
- parent=self, label="Slot1:",id=wx.ID_ANY,
- pos=(530, 210), size=(130, 185)
- ),
- wx.StaticBox(
- parent=self, label="Slot2:",id=wx.ID_ANY,
- pos=(680, 210), size=(130, 185)
- ),
- wx.StaticBox(
- parent=self, label="Slot3:",id=wx.ID_ANY,
- pos=(680, 400), size=(130, 185)
- ),
- wx.StaticBox(
- parent=self, label="Slot4:",id=wx.ID_ANY,
- pos=(530, 400), size=(130, 185)
- ),
- wx.StaticBox(
- parent=self, label="Slot5:",id=wx.ID_ANY,
- pos=(380, 400), size=(130, 185)
- ),
- wx.StaticBox(
- parent=self, label="Slot6:",id=wx.ID_ANY,
- pos=(380, 210), size=(130, 185)
- )
- ]
- self._set_label_list = [
- wx.StaticText(
- rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 0), size=(130, 10)
- ),
- ]
- self._id_label_list = [
- wx.StaticText(
- rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- ),
- wx.StaticText(
- rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 15), size=(130, 10)
- )
- ]
- self._main_label_list = [
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 35), size=(130, 10)
- ),
- ]
- self._innate_label_list = [
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 50), size=(130, 10)
- )
- ]
- self._stat_label_list = [
- [
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- [
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- [
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- [
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- [
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- [
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 70), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 85), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 100), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 115), size=(130, 10)
- )
- ],
- ]
- self._eff_label_list = [
- wx.StaticText(
- parent=rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- wx.StaticText(
- parent=rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 133), size=(130, 10)
- ),
- ]
- self._location_label_list = [
- wx.StaticText(
- rune_box_list[0], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- wx.StaticText(
- rune_box_list[1], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- wx.StaticText(
- rune_box_list[2], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- wx.StaticText(
- rune_box_list[3], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- wx.StaticText(
- rune_box_list[4], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- wx.StaticText(
- rune_box_list[5], id=wx.ID_ANY, label="",
- pos=(5, 150), size=(130, 30)
- ),
- ]
- for i in range(0, 6):
- self._details_sizer.Add(rune_box_list[i])
- # Separators
- wx.StaticLine(
- parent=rune_box_list[i], id=wx.ID_ANY,
- pos=(0, 30), size=(130, 1), style=wx.LC_REPORT
- )
- wx.StaticLine(
- parent=rune_box_list[i], id=wx.ID_ANY,
- pos=(0, 130), size=(130, 1), style=wx.LC_REPORT
- )
- wx.StaticLine(
- parent=rune_box_list[i], id=wx.ID_ANY,
- pos=(0, 150), size=(130, 1), style=wx.LC_REPORT
- )
- # Set fonts
- rune_box_list[i].SetFont(monospace_font)
- self._innate_label_list[i].SetFont(monospace_font_italic)
- self._main_label_list[i].SetFont(monospace_font_bold)
- self._eff_label_list[i].SetFont(monospace_font_italic)
- self._location_label_list[i].SetFont(monospace_font_bold)
- # Rune apply button
- apply_button = wx.Button(
- parent=self, id=wx.ID_ANY, pos=(100, 500), size=(165, 60),
- style=wx.LC_REPORT, label="Apply runes"
- )
- apply_button.Bind(wx.EVT_BUTTON, self._apply_runes)
- self._details_sizer.Add(apply_button)
- # By default, hide everything TODO
- self._table_sizer.ShowItems(False)
- self._details_sizer.ShowItems(False)
- def _update_base_and_current_stats(self):
- """
- Populates the first two columns of stats.
- Populates the base and current stats columnt in the stats table
- with the stats of the optimized unit
- """
- stat_base_values = self._unit.base_stats.values()
- stat_curr_values = self._unit.stats.values()
- for i in range (0, 10):
- stat_str = str(stat_base_values[i])
- if i in [4, 5, 6, 7]: # CRR, CRD, RES, ACC
- stat_str = stat_str + "%"
- else:
- stat_str = stat_str + " "
- self._stat_grid.SetCellValue(row=i, col=0, s=stat_str)
- stat_str = str(stat_curr_values[i])
- if i in [4, 5, 6, 7]: # CRR, CRD, RES, ACC
- stat_str = stat_str + "%"
- else:
- stat_str = stat_str + " "
- self._stat_grid.SetCellValue(row=i, col=1, s=stat_str)
- def process_results(self, unit_id=None, json_data=""):
- """
- Processes data obtained from RuneOptimizer.
- Reads the JSON data and initializes the property data.
- Automatically calls _print_results();
- Parameters
- ----------
- json_data : str
- The data, as received from RuneOptimizer.
- """
- if unit_id != None:
- self._unit = units[unit_id]
- self._update_base_and_current_stats()
- # Read results
- self._results = json.loads(
- json_data,
- object_hook=lambda d: SimpleNamespace(**d)
- )
- self._total_pages = math.ceil(len(self._results.results) / self._lines_per_page)
- self._page = 0
- self._print_results()
- def _page_prev(self, event):
- """
- Goes to the previous page of results.
- Checks if there is a previous page to go to. If so, it
- automatically calls _print_results();
- Parameters
- ----------
- event : wx.Event, optional
- The event that triggered the call (default is None).
- """
- if self._page > 0:
- self._page -= 1
- self._print_results()
- def _page_next(self, event):
- """
- Goes to the next page of results.
- Checks if there is a next page to go to. If so, it
- automatically calls _print_results();
- Parameters
- ----------
- event : wx.Event, optional
- The event that triggered the call (default is None).
- """
- if self._page < self._total_pages:
- self._page += 1
- self._print_results()
- def _apply_runes(self, event):
- """
- Applies the selected results and saves data to the database.
- Parameters
- ----------
- event : wx.Event, optional
- The event that triggered the call (default is None).
- """
- global conn
- if (self._selected_result_index < 0):
- # TODO: Show error
- return;
- # First, unassign all runes currently assigned to the unit
- cursor = conn.execute(
- """
- UPDATE runes SET unit = null
- WHERE unit = ?
- """,
- (
- self.unitId,
- )
- )
- # Next, mark units as modified
- cursor = conn.execute(
- """
- UPDATE units SET modified = 1
- WHERE
- id = ? OR
- id IN (SELECT unit FROM runes WHERE id IN (?, ?, ?, ?, ?, ?))
- """,
- (
- self.unitId,
- self._results.results[self._selected_result_index].runes[0],
- self._results.results[self._selected_result_index].runes[1],
- self._results.results[self._selected_result_index].runes[2],
- self._results.results[self._selected_result_index].runes[3],
- self._results.results[self._selected_result_index].runes[4],
- self._results.results[self._selected_result_index].runes[5]
- )
- )
- # Lastly, assign the runes
- cursor = conn.execute(
- """
- UPDATE runes SET unit = ?
- WHERE id IN (?, ?, ?, ?, ?, ?)
- """,
- (
- self.unitId,
- self._results.results[self._selected_result_index].runes[0],
- self._results.results[self._selected_result_index].runes[1],
- self._results.results[self._selected_result_index].runes[2],
- self._results.results[self._selected_result_index].runes[3],
- self._results.results[self._selected_result_index].runes[4],
- self._results.results[self._selected_result_index].runes[5]
- )
- )
- conn.commit()
- # TODO: Recalculate all modified units stats from the database
- print("Applied!")
- self._recalculte_stats_of_modified_units()
- reload_units()
- self._unit = units[self._unit.id]
- self._update_base_and_current_stats()
- print("All recalculated!")
- self._result_selected(None)
- def _print_results(self):
- """
- Populates the results table with the results in the currently
- selected page.
- It doesn't change the selcted result. Automaticcaly called
- after changing pages or processing data.
- """
- self._page_prev_button.Enable(True)
- self._page_next_button.Enable(True)
- if self._total_pages == 1:
- self._page_prev_button.Enable(False)
- self._page_next_button.Enable(False)
- elif self._page == 0:
- self._page_prev_button.Enable(False)
- elif self._page + 1 == self._total_pages:
- self._page_next_button.Enable(False)
- self._page_label.SetLabel(
- str(self._page + 1) + "/" + str(self._total_pages)
- )
- for i in range(0, 10):
- rindex = i + (self._lines_per_page * self._page)
- if (len(self._results.results) > rindex):
- self._result_grid.SetRowLabelValue(
- row=i, value=str(rindex + 1)
- )
- result = self._results.results[rindex]
- self._result_grid.SetCellValue(
- row=i, col=0, s=str(result.rating)
- )
- self._result_grid.SetCellValue(row=i, col=1, s=str(result.hp))
- self._result_grid.SetCellValue(row=i, col=2, s=str(result.atk))
- self._result_grid.SetCellValue(row=i, col=3, s=str(result.dfc))
- self._result_grid.SetCellValue(row=i, col=4, s=str(result.spd))
- self._result_grid.SetCellValue(row=i, col=5, s=str(result.crr))
- self._result_grid.SetCellValue(row=i, col=6, s=str(result.crd))
- self._result_grid.SetCellValue(row=i, col=7, s=str(result.res))
- self._result_grid.SetCellValue(row=i, col=8, s=str(result.acc))
- self._result_grid.SetCellValue(row=i, col=9, s=str(result.ehp))
- self._result_grid.SetCellValue(
- row=i, col=10, s=str(result.dmg)
- )
- else:
- self._result_grid.SetRowLabelValue(row=i, value="")
- for j in range(0, 11):
- self._result_grid.SetCellValue(row=i, col=j, s="")
- # Display the unit name and details
- self._unit_name_label.SetLabel(self._unit.name)
- stars_label_text = ""
- for i in range(0, self._unit.stars):
- stars_label_text += "\u272D"
- self._stars_label.SetLabel(stars_label_text)
- self._level_label.SetLabel("Lv. " + str(self._unit.level))
- self._priority_label.SetLabel(
- "Priority: " + str(self._unit.priority)
- )
- self._id_label.SetLabel("#" + self._unit.id)
- # Make the table visible
- self._table_sizer.ShowItems(True)
- def _result_selected(self, event):
- """
- Populates and shows the runes and effective stats with the
- currently seleced result.
- It also enables the apply button.
- Parameters
- ----------
- event : wx.Event, optional
- The event that triggered the call (default is None).
- """
- selected_line = self._result_grid.GetSelectedRows()[0]
- self._selected_result_index = \
- selected_line + (self._lines_per_page * self._page)
- if self._selected_result_index >= len(self._results.results):
- self._selected_result_index = -1;
- self._details_sizer.ShowItems(False)
- return
- self._stat_grid.SetCellValue(
- row=0, col=2,
- s=str(self._results.results[self._selected_result_index].hp) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].hp
- - self._unit.stats.hp
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=0, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=0, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=0, col=3, s="+ " + str(diff) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=0, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=0, col=3, s="")
- self._stat_grid.SetCellValue(
- row=1, col=2,
- s=str(self._results.results[self._selected_result_index].atk) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].atk
- - self._unit.stats.atk
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=1, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=1, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(row=1, col=3, s="+ " + str(diff) + " ")
- self._stat_grid.SetCellTextColour(
- row=1, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=1, col=3, s="")
- self._stat_grid.SetCellValue(
- row=2, col=2,
- s=str(self._results.results[self._selected_result_index].dfc) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].dfc
- - self._unit.stats.dfc
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=2, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=1, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=2, col=3, s="+ " + str(diff) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=2, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=2, col=3, s="")
- self._stat_grid.SetCellValue(
- row=3, col=2,
- s=str(self._results.results[self._selected_result_index].spd) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].spd
- - self._unit.stats.spd
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=3, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=3, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=3, col=3, s="+ " + str(diff) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=3, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=3, col=3, s="")
- self._stat_grid.SetCellValue(
- row=4, col=2,
- s=str(self._results.results[self._selected_result_index].crr) + "%"
- )
- diff = (
- self._results.results[self._selected_result_index].crr
- - self._unit.stats.crr
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=4, col=3, s="- " + str(abs(diff)) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=4, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=4, col=3, s="+ " + str(diff) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=4, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=4, col=3, s="")
- self._stat_grid.SetCellValue(
- row=5, col=2,
- s=str(self._results.results[self._selected_result_index].crd) + "%"
- )
- diff = (
- self._results.results[self._selected_result_index].crd
- - self._unit.stats.crd
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=5, col=3, s="- " + str(abs(diff)) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=5, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=5, col=3, s="+ " + str(diff) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=5, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=5, col=3, s="")
- self._stat_grid.SetCellValue(
- row=6, col=2,
- s=str(self._results.results[self._selected_result_index].res) + "%"
- )
- diff = (
- self._results.results[self._selected_result_index].res
- - self._unit.stats.res
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=6, col=3, s="- " + str(abs(diff)) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=6, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=6, col=3, s="+ " + str(diff) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=6, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=6, col=3, s="")
- self._stat_grid.SetCellValue(
- row=7, col=2,
- s=str(self._results.results[self._selected_result_index].acc) + "%"
- )
- diff = (
- self._results.results[self._selected_result_index].acc
- - self._unit.stats.acc
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=7, col=3, s="- " + str(abs(diff)) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=7, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=7, col=3, s="+ " + str(diff) + "%"
- )
- self._stat_grid.SetCellTextColour(
- row=7, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=7, col=3, s="")
- self._stat_grid.SetCellValue(
- row=8, col=2,
- s=str(self._results.results[self._selected_result_index].ehp) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].ehp
- - self._unit.stats.ehp
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=8, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=8, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=8, col=3, s="+ " + str(diff) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=8, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=8, col=3, s="")
- self._stat_grid.SetCellValue(
- row=9, col=2,
- s=str(self._results.results[self._selected_result_index].dmg) + " "
- )
- diff = (
- self._results.results[self._selected_result_index].dmg
- - self._unit.stats.dmg
- )
- if (diff < 0):
- self._stat_grid.SetCellValue(
- row=9, col=3, s="- " + str(abs(diff)) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=9, col=3, colour=wx.Colour(red=255, green=0, blue=0)
- )
- elif (diff > 0):
- self._stat_grid.SetCellValue(
- row=9, col=3, s="+ " + str(diff) + " "
- )
- self._stat_grid.SetCellTextColour(
- row=9, col=3, colour=wx.Colour(red=0, green=255, blue=0)
- )
- else:
- self._stat_grid.SetCellValue(row=9, col=3, s="")
- self._details_sizer.ShowItems(True)
- # Clean the runes
- for i in range(0, 5):
- self._set_label_list[i].SetLabel("")
- self._id_label_list[i].SetLabel("")
- self._main_label_list[i].SetLabel("")
- self._innate_label_list[i].SetLabel("")
- for j in range(0, 3):
- self._stat_label_list[i][j].SetLabel("")
- self._eff_label_list[i].SetLabel("")
- self._location_label_list[i].SetLabel("")
- # Display the runes
- cursor = conn.execute(
- """
- SELECT
- runes.id,
- runes.slot,
- runes.type,
- runes.level,
- units.id,
- units.name
- FROM runes LEFT JOIN units ON runes.unit = units.id
- WHERE runes.id IN (?, ?, ?, ?, ?, ?)
- ORDER BY runes.slot;
- """,
- (
- self._results.results[self._selected_result_index].runes[0],
- self._results.results[self._selected_result_index].runes[1],
- self._results.results[self._selected_result_index].runes[2],
- self._results.results[self._selected_result_index].runes[3],
- self._results.results[self._selected_result_index].runes[4],
- self._results.results[self._selected_result_index].runes[5]
- )
- )
- i = 0
- for \
- rune_id in self._results.results[self._selected_result_index].runes:
- rune = Rune(rune_id)
- # Rows are 18 charactes width
- # First line: Set name, level
- self._set_label_list[rune.slot - 1].SetLabel(
- rune.type_name[0:9].ljust(12, " ") + \
- "+" + str(rune.level).ljust(3, " ")
- )
- # Second line: ID
- lvl_set_eff = rune.type_name[0:6].ljust(6, " ")
- effv = str(("{:.2f}".format(rune.efficiency)).rjust(5, " "))
- eff = (" Eff:" + str(effv) + "%")
- lvl_set_eff += eff
- self._id_label_list[rune.slot - 1].SetLabel(
- ("#" + rune.id).rjust(15, " ")
- )
- # Efficiency
- label_eff_text = \
- "Eff.: " + ("{:.1f}".format(rune.efficiency)).rjust(4, " ") + \
- "/" + ("{:.1f}".format(rune.max_efficiency)).rjust(4, " ")
- self._eff_label_list[rune.slot - 1].SetLabel(label_eff_text)
- # Source
- label_source = ""
- if rune.unit is not None:
- label_source = units[rune.unit].name
- else:
- label_source = "In storage"
- self._location_label_list[rune.slot - 1].SetLabel(label_source)
- # Write all stats
- innate_label = " "
- for stat in rune.stats:
- if stat == None:
- continue
- slot = stat.slot
- if stat.is_enchanted:
- name = (
- stat.name
- .replace("%", "").
- replace(" ", "") + "* "
- ).rjust(5, " ")
- else:
- name = (
- stat.name
- .replace("%", "")
- .replace(" ", "") + " "
- ).rjust(5, " ")
- value = str(stat.value)
- if stat.stat in [2, 4, 6, 9, 10, 11, 23]:
- value = value + "%"
- else:
- value = value + " "
- value = value.rjust(5)
- if stat.grind > 0: # if grinded
- value = value + " +" + str(stat.grind).rjust(2)
- if stat.stat in [2, 4, 6, 9, 10, 11, 23]:
- value = value + "%"
- line = name + value
- if slot == -1: # main
- self._main_label_list[rune.slot - 1].SetLabel(line)
- elif slot == 0: # innate
- innate_label = line
- self._innate_label_list[rune.slot - 1].SetLabel(
- innate_label
- )
- else: # normal stats
- self._stat_label_list[rune.slot - 1][slot - 1].SetLabel(
- line
- )
- i = i + 1
- # Make the info visible
- self._details_sizer.ShowItems(True)
- def _recalculte_stats_of_modified_units(self):
- """
- Recalculates the stats of all the units marked as modified.
- It doen't remove the modified flag.
- """
- global conn
- unit_cursor = conn.execute("""
- SELECT
- base_hp,
- base_atk,
- base_def,
- base_spd,
- base_crr,
- base_crd,
- base_res,
- base_acc,
- id
- FROM units
- WHERE modified = 1
- """)
- i = 0
- for unit_row in unit_cursor:
- rune_cursor = conn.execute(
- """
- SELECT
- sum(current_hp_percent) AS hp,
- sum(current_hp_flat) AS hp_flat,
- sum(current_atk_percent) AS atk,
- sum(current_atk_flat) AS atk_flat,
- sum(current_def_percent) AS def,
- sum(current_def_flat) AS def_flat,
- sum(current_spd) AS spd,
- sum(current_crr) AS crr,
- sum(current_crd) AS crd,
- sum(current_res) AS res,
- sum(current_acc) AS acc
- FROM runes
- WHERE unit = ?
- """,
- (unit_row[8],)
- )
- rune_row = rune_cursor.fetchone()
- hp = (
- unit_row[0] + rune_row[1] + math.ceil(unit_row[0] + rune_row[0])
- )
- atk = (
- unit_row[1] + rune_row[3] + math.ceil(unit_row[1] + rune_row[2])
- )
- dfc = (
- unit_row[2] + rune_row[5] + math.ceil(unit_row[2] + rune_row[4])
- )
- spd = unit_row[3] + rune_row[6]
- crr = unit_row[4] + rune_row[7]
- crd = unit_row[5] + rune_row[8]
- res = unit_row[6] + rune_row[9]
- acc = unit_row[7] + rune_row[10]
- conn.execute(
- """
- UPDATE units SET
- current_hp = ?,
- current_atk = ?,
- current_def = ?,
- current_spd = ?,
- current_crr = ?,
- current_crd = ?,
- current_res = ?,
- current_acc = ?
- WHERE id = ?
- """,
- (hp, atk, dfc, spd, crr, crd, res, acc, unit_row[8],)
- )
- conn.commit()
|