""" 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 . """ class PanelResults(wx.Panel): """ The panel that shows results. Parameters ---------- unitId : string ID of the unit being optimized (default ""). unitName : string Name of the unit being optimized (default ""). data : Python Object Results from RuneOptimizer (default None). unitStats : int[10] The current stats of the unit being optimized. (default is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]). page : int Currently displayed page, 0-index (default 0). totalPages : int Number of pages of results (default 0). linesPerPage : int Number of results to show per page (default 10). selectedResultndex : int Selected result index (default -1). unitNameLabel : wx.StaticText Labels for the unit name. tableSizer : wx.BoxSizer Holds the result list. Hidden until processResults is called. detailsSizer : wx.BoxSizer Holds every widget that is hidden until a result is selected. resultGrid : wx.Grid.grid Table of results. pgPrevButton : wx.Button Button to go to the previous page. pageLabel : wx.StaticText Label to indicate the current and maximum pages. pgPrevButton : wx.Button Button to go to the previous page. statGrid : wx.Grid.grid Table to show the new stats with the selected result. idLabelList : wx.StaticText[6] Labels with the IDs of the runes in the current result. locationLabelList : wx.StaticText[6] Labels with the locations of the runes in the current result. setLabelList : wx.StaticText[6] Labels with the set names of the runes in the current result. mainLabelList : wx.StaticText[6] Labels with the main stats of the runes in the current result. innateLabelList : wx.StaticText[6] Labels with the innates of the runes in the current result. statLabelList : wx.StaticText[6][4] Labels with the stats of the runes in the current result. Methods ------- processResults(jsonData) Processes data obtained from RuneOptimizer. pgPrev(event) Goes to the previous result page. pgNext(event) Goes to the next result page. applyRunes(event) Applies the runes in the currently selected result. printResults() Populates the results table with the results in the currently selected page. resultSelected(event) Populates and shows the runes and effective stats with the currently seleced result. recalculteStatsOfModifiedUnits(): Recalculates the stats of all the units marked as modified. """ unitId = "" unitName = "" data = None unitStats = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] page = 0 totalPages = 0 linesPerPage = 10 selectedResultIndex = -1 unitNameLabel = None tableSizer = None detailsSizer = None resultGrid = None pgPrevButton = None pageLabel = None pgNextButton = None statGrid = None idLabelList = None locationLabelList = None setLabelList = None mainLabelList = None innateLabelList = None statLabelList = 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 titleFont = wx.Font( pointSize=14, family=wx.FONTFAMILY_DEFAULT, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD ) monospaceFont = wx.Font( pointSize=10, family=wx.FONTFAMILY_TELETYPE, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL ) monospaceFontBold = wx.Font( pointSize=8, family=wx.FONTFAMILY_TELETYPE, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_BOLD ) monospaceFontItalic = wx.Font( pointSize=8, family=wx.FONTFAMILY_TELETYPE, style=wx.FONTSTYLE_ITALIC, weight=wx.FONTWEIGHT_NORMAL ) # Unit name and id self.unitNameLabel = wx.StaticText( parent=self, id=wx.ID_ANY, label="Nothing yet. Optimize something!", pos=(0, 0), size=(400, 30) ) self.unitNameLabel.SetFont(titleFont) # Contains the results table. Hidden until they are loaded. self.tableSizer = wx.BoxSizer(wx.VERTICAL) # Contains all thigs to be shown once a result is selected self.detailsSizer = wx.BoxSizer(wx.VERTICAL) # The result list table self.resultGrid = wx.grid.Grid( parent=self, id=wx.ID_ANY, pos=(0, 30), size=(525, 170) ) self.resultGrid.CreateGrid( numRows=10, numCols=11 ) self.resultGrid.EnableEditing(False) self.resultGrid.SetSelectionMode(wx.grid.Grid.GridSelectionModes.SelectRows) self.resultGrid.SetDefaultCellAlignment( horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE ) monospaceFont.PointSize -= 1 self.resultGrid.SetDefaultCellFont(monospaceFont) monospaceFont.PointSize += 1 self.resultGrid.SetRowLabelSize(width=35) self.resultGrid.SetColLabelValue(col=0, value="Rating") self.resultGrid.SetColSize(col=0, width=50) self.resultGrid.SetColLabelValue(col=1, value="HP") self.resultGrid.SetColSize(col=1, width=50) self.resultGrid.SetColLabelValue(col=2, value="ATK") self.resultGrid.SetColSize(col=2, width=40) self.resultGrid.SetColLabelValue(col=3, value="DEF") self.resultGrid.SetColSize(col=3, width=40) self.resultGrid.SetColLabelValue(col=4, value="SPD") self.resultGrid.SetColSize(col=4, width=40) self.resultGrid.SetColLabelValue(col=5, value="CRR") self.resultGrid.SetColSize(col=5, width=40) self.resultGrid.SetColLabelValue(col=6, value="CRD") self.resultGrid.SetColSize(col=6, width=40) self.resultGrid.SetColLabelValue(col=7, value="RES") self.resultGrid.SetColSize(col=7, width=40) self.resultGrid.SetColLabelValue(col=8, value="ACC") self.resultGrid.SetColSize(col=8, width=40) self.resultGrid.SetColLabelValue(col=9, value="EHP") self.resultGrid.SetColSize(col=9, width=60) self.resultGrid.SetColLabelValue(col=10, value="DMG") self.resultGrid.SetColSize(col=10, width=50) self.resultGrid.SetColLabelSize(height=20) self.resultGrid.SetDefaultRowSize(height=15) self.Bind( wx.grid.EVT_GRID_SELECT_CELL, self.resultSelected, self.resultGrid ) self.tableSizer.Add(self.resultGrid) # Paginator self.pgPrevButton = wx.Button( parent=self, id=wx.ID_ANY, pos=(530, 30), size=(40, 50), style=wx.LC_REPORT, label="Prev\npage" ) self.tableSizer.Add(self.pgPrevButton) self.pageLabel = wx.StaticText( parent=self,id=wx.ID_ANY, pos=(530, 80), size=(40, 15), style=wx.ALIGN_CENTRE_HORIZONTAL, label="1/1" ) self.tableSizer.Add(self.pageLabel) self.pgNextButton = wx.Button( parent=self, id=wx.ID_ANY, pos=(530, 100), size=(40, 50), style=wx.LC_REPORT, label="Next\npage" ) self.tableSizer.Add(self.pgNextButton) self.Bind(wx.EVT_BUTTON, self.pgPrev, self.pgPrevButton) self.Bind(wx.EVT_BUTTON, self.pgNext, self.pgNextButton) # Stats table self.statGrid = wx.grid.Grid( parent=self, id=wx.ID_ANY, pos=(0, 210), size=(185, 220), style=wx.LC_REPORT ) self.statGrid.CreateGrid( numRows=10, numCols=2 ) self.statGrid.EnableEditing(False) self.statGrid.SetDefaultCellAlignment( horiz=wx.ALIGN_RIGHT, vert=wx.ALIGN_CENTRE ) self.statGrid.SetDefaultCellFont(monospaceFont) self.statGrid.SetColSize(col=0, width=70) self.statGrid.SetColLabelValue(col=0, value="Value") self.statGrid.SetColLabelValue(col=1, value="Diff") self.statGrid.SetRowLabelSize(width=35) self.statGrid.SetColLabelSize(height=20) self.statGrid.SetRowSize(row=0, height=20) self.statGrid.SetRowSize(row=1, height=20) self.statGrid.SetRowSize(row=2, height=20) self.statGrid.SetRowSize(row=3, height=20) self.statGrid.SetRowSize(row=4, height=20) self.statGrid.SetRowSize(row=5, height=20) self.statGrid.SetRowSize(row=6, height=20) self.statGrid.SetRowSize(row=7, height=20) self.statGrid.SetRowSize(row=8, height=20) self.statGrid.SetRowSize(row=9, height=20) self.statGrid.SetRowLabelValue(row=0, value=" HP") self.statGrid.SetRowLabelValue(row=1, value="ATK") self.statGrid.SetRowLabelValue(row=2, value="DEF") self.statGrid.SetRowLabelValue(row=3, value="SPD") self.statGrid.SetRowLabelValue(row=4, value="CRR") self.statGrid.SetRowLabelValue(row=5, value="CRD") self.statGrid.SetRowLabelValue(row=6, value="RES") self.statGrid.SetRowLabelValue(row=7, value="ACC") self.statGrid.SetRowLabelValue(row=8, value="EHP") self.statGrid.SetRowLabelValue(row=9, value="DMG") self.detailsSizer.Add(self.statGrid) #Rune set list monospaceFont.PointSize -= 2 rubeBoxList = [ wx.StaticBox( parent=self, label="Slot1:",id=wx.ID_ANY, pos=(350, 210), size=(140, 160) ), wx.StaticBox( parent=self, label="Slot2:",id=wx.ID_ANY, pos=(500, 210), size=(140, 160) ), wx.StaticBox( parent=self, label="Slot3:",id=wx.ID_ANY, pos=(500, 375), size=(140, 160) ), wx.StaticBox( parent=self, label="Slot4:",id=wx.ID_ANY, pos=(350, 375), size=(140, 160) ), wx.StaticBox( parent=self, label="Slot5:",id=wx.ID_ANY, pos=(200, 375), size=(140, 160) ), wx.StaticBox( parent=self, label="Slot6:",id=wx.ID_ANY, pos=(200, 210), size=(140, 160) ) ] for i in range(0, 6): rubeBoxList[i].SetFont(monospaceFont) self.detailsSizer.Add(rubeBoxList[i]) self.idLabelList = [ wx.StaticText( rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ), wx.StaticText( rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ), wx.StaticText( rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ), wx.StaticText( rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ), wx.StaticText( rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ), wx.StaticText( rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 0), size=(120, 10) ) ] self.locationLabelList = [ wx.StaticText( rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), wx.StaticText( rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), wx.StaticText( rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), wx.StaticText( rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), wx.StaticText( rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), wx.StaticText( rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 15), size=(120, 10) ), ] self.setLabelList = [ wx.StaticText( rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), wx.StaticText( rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), wx.StaticText( rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), wx.StaticText( rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), wx.StaticText( rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), wx.StaticText( rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 30), size=(120, 10) ), ] wx.StaticLine( parent=rubeBoxList[0], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) wx.StaticLine( parent=rubeBoxList[1], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) wx.StaticLine( parent=rubeBoxList[2], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) wx.StaticLine( parent=rubeBoxList[3], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) wx.StaticLine( parent=rubeBoxList[4], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) wx.StaticLine( parent=rubeBoxList[5], id=wx.ID_ANY, pos=(5, 45), size=(130, 1), style=wx.LC_REPORT ) self.mainLabelList = [ wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 50), size=(120, 10) ), ] for i in range(0, 6): self.mainLabelList[i].SetFont(monospaceFontBold) self.innateLabelList = [ wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 65), size=(120, 10) ) ] for i in range(0, 6): self.innateLabelList[i].SetFont(monospaceFontItalic) self.statLabelList = [ [ wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[0], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], [ wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[1], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], [ wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[2], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], [ wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[3], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], [ wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[4], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], [ wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 80), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 95), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 110), size=(120, 10) ), wx.StaticText( parent=rubeBoxList[5], id=wx.ID_ANY, label="", pos=(5, 125), size=(120, 10) ) ], ] # Action buttons applyButton = wx.Button( parent=self, id=wx.ID_ANY, pos=(10, 450), size=(165, 60), style=wx.LC_REPORT, label="Apply runes" ) self.Bind(wx.EVT_BUTTON, self.applyRunes, applyButton) self.detailsSizer.Add(applyButton) # By default, hide everything TODO self.tableSizer.ShowItems(False) self.detailsSizer.ShowItems(False) def processResults(self, unitId=None, jsonData=""): """Processes data obtained from RuneOptimizer. Reads the JSON data and initializes the property data. Automatically calls printResults(); Parameters ---------- jsonData : str The data, as received from RuneOptimizer. """ if unitId != None: self.unitId = unitId cursor = conn.execute(""" SELECT current_hp, current_atk, current_def, current_spd, current_crr, current_crd, current_res, current_acc, name FROM units WHERE id = '""" + unitId + """'; """) row = cursor.fetchone() self.unitName = row[8] for i in range(0, 8): self.unitStats[i] = row[i] # Calculate EHP and DMG hp = row[0] dfc = row[2] ehp = math.ceil((((dfc * 3.5) + 1140) * hp) / 1000) self.unitStats[8] = ehp atk = row[1] crr = row[4] crd = row[5] dmg = math.ceil( (atk * (100 - crr) / 100) + # Non-crit (atk * ( crr / 100) * crd / 100) # Crit ) self.unitStats[9] = dmg self.data = json.loads( jsonData, object_hook=lambda d: SimpleNamespace(**d) ) self.totalPages = math.ceil(len(self.data.results) / self.linesPerPage) self.page = 0 self.printResults() def pgPrev(self, event): """Goes to the previous page of results. Checks if there is a previous page to go to. If so, it automatically calls printResults(); Parameters ---------- event : wx.Event, optional The event that triggered the call (default is None). """ if self.page > 0: self.page -= 1 self.printResults() def pgNext(self, event): """Goes to the next page of results. Checks if there is a next page to go to. If so, it automatically calls printResults(); Parameters ---------- event : wx.Event, optional The event that triggered the call (default is None). """ if self.page < self.totalPages: self.page += 1 self.printResults() def applyRunes(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.selectedResultIndex < 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.data.results[self.selectedResultIndex].runes[0], self.data.results[self.selectedResultIndex].runes[1], self.data.results[self.selectedResultIndex].runes[2], self.data.results[self.selectedResultIndex].runes[3], self.data.results[self.selectedResultIndex].runes[4], self.data.results[self.selectedResultIndex].runes[5] ) ) # Lastly, assign the runes cursor = conn.execute( """ UPDATE runes SET unit = ? WHERE id IN (?, ?, ?, ?, ?, ?) """, ( self.unitId, self.data.results[self.selectedResultIndex].runes[0], self.data.results[self.selectedResultIndex].runes[1], self.data.results[self.selectedResultIndex].runes[2], self.data.results[self.selectedResultIndex].runes[3], self.data.results[self.selectedResultIndex].runes[4], self.data.results[self.selectedResultIndex].runes[5] ) ) conn.commit() # TODO: Recalculate all modified units stats from the database print("Applied!") recalculteStatsOfModifiedUnits() print("All recalculated!") # Fetch the new values for self.unitStats cursor = conn.execute( """ SELECT current_hp, current_atk, current_def, current_spd, current_crr, current_crd, current_res, current_acc FROM units WHERE id = ? """, ( self.unitId, ) ) row = cursor.fetchone() for i in range(0, 8): self.unitStats[i] = int(row[i]) self.unitStats[9] = math.ceil( (((self.unitStats[2] * 3.5) + 1140) * self.unitStats[0]) / 1000 ) self.unitStats[10] = math.ceil( (self.unitStats[1] * (100 - self.unitStats[4]) / 100) + ( ( self.unitStats[1] + (self.unitStats[1] * self.unitStats[5] / 100) ) * self.unitStats[4] / 100 ) ) self.resultSelected(None) def printResults(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.pgPrevButton.Enable(True) self.pgNextButton.Enable(True) if self.totalPages == 1: self.pgPrevButton.Enable(False) self.pgNextButton.Enable(False) elif self.page == 0: self.pgPrevButton.Enable(False) elif self.page + 1 == self.totalPages: self.pgNextButton.Enable(False) self.pageLabel.SetLabel( str(self.page + 1) + "/" + str(self.totalPages) ) for i in range(0, 10): rindex = i + (self.linesPerPage * self.page) if (len(self.data.results) > rindex): self.resultGrid.SetRowLabelValue(row=i, value=str(rindex + 1)) result = self.data.results[rindex] self.resultGrid.SetCellValue(row=i, col=0, s=str(result.rating)) self.resultGrid.SetCellValue(row=i, col=1, s=str(result.hp)) self.resultGrid.SetCellValue(row=i, col=2, s=str(result.atk)) self.resultGrid.SetCellValue(row=i, col=3, s=str(result.dfc)) self.resultGrid.SetCellValue(row=i, col=4, s=str(result.spd)) self.resultGrid.SetCellValue(row=i, col=5, s=str(result.crr)) self.resultGrid.SetCellValue(row=i, col=6, s=str(result.crd)) self.resultGrid.SetCellValue(row=i, col=7, s=str(result.res)) self.resultGrid.SetCellValue(row=i, col=8, s=str(result.acc)) self.resultGrid.SetCellValue(row=i, col=9, s=str(result.ehp)) self.resultGrid.SetCellValue(row=i, col=10, s=str(result.dmg)) else: self.resultGrid.SetRowLabelValue(row=i, value="") for j in range(0, 11): self.resultGrid.SetCellValue(row=i, col=j, s="") # Display the unit name self.unitNameLabel.SetLabel(self.unitName + " #" + self.unitId) # Make the table visible self.tableSizer.ShowItems(True) def resultSelected(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). """ selectedLine = self.resultGrid.GetSelectedRows()[0] self.selectedResultIndex = \ selectedLine + (self.linesPerPage * self.page) if self.selectedResultIndex >= len(self.data.results): self.selectedResultIndex = -1; self.detailsSizer.ShowItems(False) return self.statGrid.SetCellValue( row=0, col=0, s=str(self.data.results[self.selectedResultIndex].hp) + " " ) diff = \ self.data.results[self.selectedResultIndex].hp - self.unitStats[0] if (diff < 0): self.statGrid.SetCellValue( row=0, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=0, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=0, col=1, s="+ " + str(diff) + " " ) self.statGrid.SetCellTextColour( row=0, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=0, col=1, s="") self.statGrid.SetCellValue( row=1, col=0, s=str(self.data.results[self.selectedResultIndex].atk) + " " ) diff = \ self.data.results[self.selectedResultIndex].atk - self.unitStats[1] if (diff < 0): self.statGrid.SetCellValue( row=1, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=1, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue(row=1, col=1, s="+ " + str(diff) + " ") self.statGrid.SetCellTextColour( row=1, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=1, col=1, s="") self.statGrid.SetCellValue( row=2, col=0, s=str(self.data.results[self.selectedResultIndex].dfc) + " " ) diff = \ self.data.results[self.selectedResultIndex].dfc - self.unitStats[2] if (diff < 0): self.statGrid.SetCellValue( row=2, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=1, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=2, col=1, s="+ " + str(diff) + " " ) self.statGrid.SetCellTextColour( row=2, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=2, col=1, s="") self.statGrid.SetCellValue( row=3, col=0, s=str(self.data.results[self.selectedResultIndex].spd) + " " ) diff = \ self.data.results[self.selectedResultIndex].spd - self.unitStats[3] if (diff < 0): self.statGrid.SetCellValue( row=3, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=3, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=3, col=1, s="+ " + str(diff) + " " ) self.statGrid.SetCellTextColour( row=3, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=3, col=1, s="") self.statGrid.SetCellValue( row=4, col=0, s=str(self.data.results[self.selectedResultIndex].crr) + "%" ) diff = \ self.data.results[self.selectedResultIndex].crr - self.unitStats[4] if (diff < 0): self.statGrid.SetCellValue( row=4, col=1, s="- " + str(abs(diff)) + "%" ) self.statGrid.SetCellTextColour( row=4, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue(row=4, col=1, s="+ " + str(diff) + "%") self.statGrid.SetCellTextColour( row=4, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=4, col=1, s="") self.statGrid.SetCellValue( row=5, col=0, s=str(self.data.results[self.selectedResultIndex].crd) + "%" ) diff = \ self.data.results[self.selectedResultIndex].crd - self.unitStats[5] if (diff < 0): self.statGrid.SetCellValue( row=5, col=1, s="- " + str(abs(diff)) + "%" ) self.statGrid.SetCellTextColour( row=5, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=5, col=1, s="+ " + str(diff) + "%" ) self.statGrid.SetCellTextColour( row=5, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=5, col=1, s="") self.statGrid.SetCellValue( row=6, col=0, s=str(self.data.results[self.selectedResultIndex].res) + "%" ) diff = \ self.data.results[self.selectedResultIndex].res - self.unitStats[6] if (diff < 0): self.statGrid.SetCellValue( row=6, col=1, s="- " + str(abs(diff)) + "%" ) self.statGrid.SetCellTextColour( row=6, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue(row=6, col=1, s="+ " + str(diff) + "%") self.statGrid.SetCellTextColour( row=6, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=6, col=1, s="") self.statGrid.SetCellValue( row=7, col=0, s=str(self.data.results[self.selectedResultIndex].acc) + "%" ) diff = \ self.data.results[self.selectedResultIndex].acc - self.unitStats[7] if (diff < 0): self.statGrid.SetCellValue( row=7, col=1, s="- " + str(abs(diff)) + "%" ) self.statGrid.SetCellTextColour( row=7, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=7, col=1, s="+ " + str(diff) + "%" ) self.statGrid.SetCellTextColour( row=7, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=7, col=1, s="") self.statGrid.SetCellValue( row=8, col=0, s=str(self.data.results[self.selectedResultIndex].ehp) + " " ) diff = \ self.data.results[self.selectedResultIndex].ehp - self.unitStats[8] if (diff < 0): self.statGrid.SetCellValue( row=8, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=8, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue( row=8, col=1, s="+ " + str(diff) + " " ) self.statGrid.SetCellTextColour( row=8, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=8, col=1, s="") self.statGrid.SetCellValue( row=9, col=0, s=str(self.data.results[self.selectedResultIndex].dmg) + " " ) diff = self.data.results[self.selectedResultIndex].dmg - self.unitStats[9] if (diff < 0): self.statGrid.SetCellValue( row=9, col=1, s="- " + str(abs(diff)) + " " ) self.statGrid.SetCellTextColour( row=9, col=1, colour=wx.Colour(red=255, green=0, blue=0) ) elif (diff > 0): self.statGrid.SetCellValue(row=9, col=1, s="+ " + str(diff) + " ") self.statGrid.SetCellTextColour( row=9, col=1, colour=wx.Colour(red=0, green=255, blue=0) ) else: self.statGrid.SetCellValue(row=9, col=1, s="") self.detailsSizer.ShowItems(True) # Clean the runes for i in range(0, 5): self.idLabelList[i].SetLabel("") self.locationLabelList[i].SetLabel("") self.setLabelList[i].SetLabel("") self.mainLabelList[i].SetLabel("") self.innateLabelList[i].SetLabel("") for j in range(0, 3): self.statLabelList[i][j].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.data.results[self.selectedResultIndex].runes[0], self.data.results[self.selectedResultIndex].runes[1], self.data.results[self.selectedResultIndex].runes[2], self.data.results[self.selectedResultIndex].runes[3], self.data.results[self.selectedResultIndex].runes[4], self.data.results[self.selectedResultIndex].runes[5] ) ) i = 0 for row in cursor: # Rows are 21 charactes width self.idLabelList[i].SetLabel(("#" + str(row[0])).rjust(21, " ")) if row[4] == None: self.locationLabelList[i].SetLabel("Storage") else: self.locationLabelList[i].SetLabel( str(row[5])[0:9].ljust(9, " ") + " #" + str(row[4]) + "" ) self.setLabelList[i].SetLabel( set_names[row[2]].ljust(18, " ") + "+" + str(row[3]) ) cursorStats = conn.execute( """ SELECT slot, stat, value, grind, enchant FROM rune_stats WHERE rune = ? ORDER BY slot; """, (self.data.results[self.selectedResultIndex].runes[i],) ) for rowStats in cursorStats: slot = rowStats[0] if rowStats[4] == 1: # if enchanted name = ( stat_names[rowStats[1]] .replace("%", "") .replace(" ", "") + " * " ).rjust(8, " ") else: name = ( stat_names[rowStats[1]] .replace("%", "") .replace(" ", "") + " " ).rjust(8, " ") value = str(rowStats[2]) if rowStats[1] in [2, 4, 6, 9, 10, 11, 23]: value = value + "%" else: value = value + " " value = value.rjust(5) if rowStats[3] > 0: # if grinded value = value + " + " + str(rowStats[3]) if rowStats[1] in [2, 4, 6, 9, 10, 11, 23]: value = value + "%" line = name + value if slot == -1: # main self.mainLabelList[i].SetLabel(line) elif slot == 0: # innate self.innateLabelList[i].SetLabel(line) else: # normal stats self.statLabelList[i][slot - 1].SetLabel(line) i += 1 # Make the info visible self.detailsSizer.ShowItems(True) def recalculteStatsOfModifiedUnits(self): """Recalculates the stats of all the units marked as modified. """ global conn unitCursor = 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 unitRow in unitCursor: runeCursor = 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 = ? """, (unitRow[8],) ) runeRow = runeCursor.fetchone() hp = unitRow[0] + runeRow[1] + math.ceil(unitRow[0] + runeRow[0]) atk = unitRow[1] + runeRow[3] + math.ceil(unitRow[1] + runeRow[2]) dfc = unitRow[2] + runeRow[5] + math.ceil(unitRow[2] + runeRow[4]) spd = unitRow[3] + runeRow[6] crr = unitRow[4] + runeRow[7] crd = unitRow[5] + runeRow[8] res = unitRow[6] + runeRow[9] acc = unitRow[7] + runeRow[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, unitRow[8],) ) conn.commit()