Track changes to underlying modules in stats windows

This commit is contained in:
DarkPhoenix
2022-02-05 00:56:39 +03:00
parent 3024ccd176
commit be73ffd929
4 changed files with 49 additions and 5 deletions

View File

@@ -1,16 +1,19 @@
import csv
import config
from enum import IntEnum
# noinspection PyPackageRequirements
import wx
import wx.lib.agw.hypertreelist
import config
import gui
from gui import globalEvents as GE
from gui.bitmap_loader import BitmapLoader
from gui.utils.numberFormatter import formatAmount, roundDec
from enum import IntEnum
from gui.builtinItemStatsViews.attributeGrouping import *
from gui.utils.numberFormatter import formatAmount, roundDec
from service.const import GuiAttrGroup
_t = wx.GetTranslation
@@ -25,6 +28,8 @@ class ItemParams(wx.Panel):
wx.Panel.__init__(self, parent, size=(1000, 1000))
self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE))
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.paramList = wx.lib.agw.hypertreelist.HyperTreeList(self, wx.ID_ANY,
@@ -37,6 +42,8 @@ class ItemParams(wx.Panel):
self.toggleView = AttributeView.NORMAL
self.stuff = stuff
self.item = item
self.isStuffItem = stuff is not None and getattr(stuff, 'item') == item
self.isStuffCharge = stuff is not None and getattr(stuff, 'charge') == item
self.attrInfo = {}
self.attrValues = {}
self._fetchValues()
@@ -71,6 +78,10 @@ class ItemParams(wx.Panel):
self.toggleViewBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleViewMode)
self.exportStatsBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ExportItemStats)
self.mainFrame.Bind(GE.ITEM_CHANGED_INPLACE, self.OnUpdateStuff)
def OnWindowClose(self):
self.mainFrame.Unbind(GE.ITEM_CHANGED_INPLACE)
def _fetchValues(self):
if self.stuff is None:
@@ -78,12 +89,12 @@ class ItemParams(wx.Panel):
self.attrValues.clear()
self.attrInfo.update(self.item.attributes)
self.attrValues.update(self.item.attributes)
elif self.stuff.item == self.item:
elif self.isStuffItem:
self.attrInfo.clear()
self.attrValues.clear()
self.attrInfo.update(self.stuff.item.attributes)
self.attrValues.update(self.stuff.itemModifiedAttributes)
elif self.stuff.charge == self.item:
elif self.isStuffCharge:
self.attrInfo.clear()
self.attrValues.clear()
self.attrInfo.update(self.stuff.charge.attributes)
@@ -171,6 +182,10 @@ class ItemParams(wx.Panel):
]
)
def OnUpdateStuff(self, event):
if self.stuff is event.old:
self.stuff = event.new
def SetupImageList(self):
self.imageList.RemoveAll()
@@ -357,3 +372,4 @@ class ItemParams(wx.Panel):
fvalue = value
unitSuffix = f' {unit}' if unit is not None else ''
return f'{fvalue}{unitSuffix}'

View File

@@ -22,6 +22,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldModMap = self._getPositionMap(fit)
results = []
self.replacedItemIDs = set()
lastSuccessfulCmd = None
@@ -49,6 +50,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
sFit.recalc(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
eos.db.commit()
newModMap = self._getPositionMap(fit)
events = []
if success and self.replacedItemIDs:
events.append(GE.FitChanged(fitIDs=(self.fitID,), action='moddel', typeID=self.replacedItemIDs))
@@ -56,6 +58,12 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
events.append(GE.FitChanged(fitIDs=(self.fitID,), action='modadd', typeID=self.newItemID))
if not events:
events.append(GE.FitChanged(fitIDs=(self.fitID,)))
if success:
for position in self.positions:
oldMod = oldModMap.get(position)
newMod = newModMap.get(position)
if oldMod is not newMod:
events.append(GE.ItemChangedInplace(fitID=self.fitID, old=oldMod, new=newMod))
for event in events:
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
return success
@@ -63,12 +71,16 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldModMap = self._getPositionMap(fit)
for position in self.positions:
oldModMap[position] = fit.modules[position]
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.flush()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
eos.db.commit()
newModMap = self._getPositionMap(fit)
events = []
if success:
events.append(GE.FitChanged(fitIDs=(self.fitID,), action='moddel', typeID=self.newItemID))
@@ -76,6 +88,18 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
events.append(GE.FitChanged(fitIDs=(self.fitID,), action='modadd', typeID=self.replacedItemIDs))
if not events:
events.append(GE.FitChanged(fitIDs=(self.fitID,)))
if success:
for position in self.positions:
oldMod = oldModMap.get(position)
newMod = newModMap.get(position)
if oldMod is not newMod:
events.append(GE.ItemChangedInplace(fitID=self.fitID, old=oldMod, new=newMod))
for event in events:
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
return success
def _getPositionMap(self, fit):
positionMap = {}
for position in self.positions:
positionMap[position] = fit.modules[position]
return positionMap

View File

@@ -11,6 +11,9 @@ GraphOptionChanged, GRAPH_OPTION_CHANGED = wx.lib.newevent.NewEvent()
TargetProfileRenamed, TARGET_PROFILE_RENAMED = wx.lib.newevent.NewEvent()
TargetProfileChanged, TARGET_PROFILE_CHANGED = wx.lib.newevent.NewEvent()
TargetProfileRemoved, TARGET_PROFILE_REMOVED = wx.lib.newevent.NewEvent()
# For events when item is actually replaced under the hood,
# but from user's perspective it's supposed to change/mutate
ItemChangedInplace, ITEM_CHANGED_INPLACE = wx.lib.newevent.NewEvent()
EffectiveHpToggled, EFFECTIVE_HP_TOGGLED = wx.lib.newevent.NewEvent()

View File

@@ -216,3 +216,4 @@ class ItemStatsContainer(wx.Panel):
mutaPanel = getattr(self, 'mutator', None)
if mutaPanel is not None:
mutaPanel.OnWindowClose()
self.params.OnWindowClose()