From 031cb6fcfbc4ddc2abbbcb1bd3296e8e4ca5ec99 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 21 Apr 2019 21:22:57 +0300 Subject: [PATCH] Change projected fits behavior - now addition adds 1 fit in any case (even if fit is already projected), and removal via double-click works like with drones --- gui/builtinAdditionPanes/projectedView.py | 8 +++-- .../fitAddCurrentlyOpen.py | 2 +- gui/builtinContextMenus/itemRemove.py | 2 +- gui/builtinShipBrowser/fitItem.py | 3 +- gui/fitCommands/calc/projectedFit/add.py | 22 +++++++++----- .../calc/projectedFit/changeAmount.py | 9 ++++-- gui/fitCommands/calc/projectedFit/remove.py | 29 ++++++++++++++----- gui/fitCommands/gui/projectedFit/add.py | 5 ++-- gui/fitCommands/gui/projectedFit/remove.py | 5 ++-- 9 files changed, 58 insertions(+), 27 deletions(-) diff --git a/gui/builtinAdditionPanes/projectedView.py b/gui/builtinAdditionPanes/projectedView.py index 04d815d96..d2fe5bd64 100644 --- a/gui/builtinAdditionPanes/projectedView.py +++ b/gui/builtinAdditionPanes/projectedView.py @@ -126,7 +126,7 @@ class ProjectedView(d.Display): thing = self.get(row) if isinstance(thing, es_Fit): self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand( - fitID=fitID, projectedFitID=thing.ID)) + fitID=fitID, projectedFitID=thing.ID, amount=math.inf)) elif isinstance(thing, es_Module): fit = Fit.getInstance().getFit(fitID) if thing in fit.projectedModules: @@ -148,7 +148,8 @@ class ProjectedView(d.Display): if type == "fit": activeFit = self.mainFrame.getActiveFit() if activeFit: - self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand( + fitID=activeFit, projectedFitID=fitID, amount=1)) def startDrag(self, event): row = event.GetIndex() @@ -335,8 +336,9 @@ class ProjectedView(d.Display): fitID = self.mainFrame.getActiveFit() thing = self.get(row) if isinstance(thing, es_Fit): + amount = math.inf if wx.GetMouseState().altDown else 1 self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand( - fitID=fitID, projectedFitID=thing.ID)) + fitID=fitID, projectedFitID=thing.ID, amount=amount)) elif isinstance(thing, es_Module): fit = Fit.getInstance().getFit(fitID) if thing in fit.projectedModules: diff --git a/gui/builtinContextMenus/fitAddCurrentlyOpen.py b/gui/builtinContextMenus/fitAddCurrentlyOpen.py index 9db0c4f3e..f812aedef 100644 --- a/gui/builtinContextMenus/fitAddCurrentlyOpen.py +++ b/gui/builtinContextMenus/fitAddCurrentlyOpen.py @@ -56,7 +56,7 @@ class AddCurrentlyOpenFit(ContextMenu): if self.context == 'commandView': self.mainFrame.command.Submit(cmd.GuiAddCommandFitCommand(fitID=fitID, commandFitID=fit.ID)) elif self.context == 'projected': - self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=fitID, projectedFitID=fit.ID)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=fitID, projectedFitID=fit.ID, amount=1)) AddCurrentlyOpenFit.register() diff --git a/gui/builtinContextMenus/itemRemove.py b/gui/builtinContextMenus/itemRemove.py index 6bf27414a..baa531398 100644 --- a/gui/builtinContextMenus/itemRemove.py +++ b/gui/builtinContextMenus/itemRemove.py @@ -70,7 +70,7 @@ class RemoveItem(ContextMenu): elif srcContext == "projectedFit": projectedFit = selection[0] self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand( - fitID=fitID, projectedFitID=projectedFit.ID)) + fitID=fitID, projectedFitID=projectedFit.ID, amount=math.inf)) elif srcContext == "projectedModule": mod = selection[0] if mod in fit.projectedModules: diff --git a/gui/builtinShipBrowser/fitItem.py b/gui/builtinShipBrowser/fitItem.py index 77c4f36ea..5823e4007 100644 --- a/gui/builtinShipBrowser/fitItem.py +++ b/gui/builtinShipBrowser/fitItem.py @@ -185,7 +185,8 @@ class FitItem(SFItem.SFBrowserItem): if activeFit: sFit = Fit.getInstance() projectedFit = sFit.getFit(self.fitID) - if self.mainFrame.command.Submit(cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=projectedFit.ID)): + command = cmd.GuiAddProjectedFitCommand(fitID=activeFit, projectedFitID=projectedFit.ID, amount=1) + if self.mainFrame.command.Submit(command): self.mainFrame.additionsPane.select("Projected") def OnAddCommandFit(self, event): diff --git a/gui/fitCommands/calc/projectedFit/add.py b/gui/fitCommands/calc/projectedFit/add.py index 90b3bf083..35041bad7 100644 --- a/gui/fitCommands/calc/projectedFit/add.py +++ b/gui/fitCommands/calc/projectedFit/add.py @@ -10,12 +10,13 @@ pyfalog = Logger(__name__) class CalcAddProjectedFitCommand(wx.Command): - def __init__(self, fitID, projectedFitID, amount=None, state=None): + def __init__(self, fitID, projectedFitID, amount, state=None): wx.Command.__init__(self, True, 'Add Projected Fit') self.fitID = fitID self.projectedFitID = projectedFitID self.amount = amount self.state = state + self.changeAmountCommand = None def Do(self): pyfalog.debug('Doing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) @@ -28,13 +29,16 @@ class CalcAddProjectedFitCommand(wx.Command): pyfalog.debug('Projected fit is not available') return False - if projectedFit in fit.projectedFits: - pyfalog.debug('Projected fit had been applied already') - return False + # If we already have info about projection - means that fit is already projected + # and we just need to increase amount of fits + if projectedFit in fit.projectedFits and projectedFit.ID in fit.projectedFitDict: + from .changeAmount import CalcChangeProjectedFitAmountCommand + self.changeAmountCommand = CalcChangeProjectedFitAmountCommand( + fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount, relative=True) + return self.changeAmountCommand.Do() + else: + self.changeAmountCommand = None - if projectedFit.ID in fit.projectedFitDict: - pyfalog.debug('Projected fit is in projected dict already') - return False fit.projectedFitDict[projectedFit.ID] = projectedFit # This bit is required, see issue #83 eos.db.saveddata_session.flush() @@ -56,11 +60,13 @@ class CalcAddProjectedFitCommand(wx.Command): def Undo(self): pyfalog.debug('Undoing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) + if self.changeAmountCommand is not None: + return self.changeAmountCommand.Undo() # Can't find the projected fit, it must have been deleted. Just skip, as deleted fit # means that someone else just did exactly what we wanted to do projectedFit = Fit.getInstance().getFit(self.projectedFitID, projected=True) if projectedFit is None: return True from .remove import CalcRemoveProjectedFitCommand - cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) + cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount) return cmd.Do() diff --git a/gui/fitCommands/calc/projectedFit/changeAmount.py b/gui/fitCommands/calc/projectedFit/changeAmount.py index ceb1bfe76..4a2b92994 100644 --- a/gui/fitCommands/calc/projectedFit/changeAmount.py +++ b/gui/fitCommands/calc/projectedFit/changeAmount.py @@ -10,11 +10,12 @@ pyfalog = Logger(__name__) class CalcChangeProjectedFitAmountCommand(wx.Command): - def __init__(self, fitID, projectedFitID, amount): + def __init__(self, fitID, projectedFitID, amount, relative=False): wx.Command.__init__(self, True, 'Change Projected Fit Amount') self.fitID = fitID self.projectedFitID = projectedFitID self.amount = amount + self.relative = relative self.savedAmount = None def Do(self): @@ -29,8 +30,12 @@ class CalcChangeProjectedFitAmountCommand(wx.Command): pyfalog.warning('Fit projection info is not available') return False self.savedAmount = projectionInfo.amount + if self.relative: + amount = projectionInfo.amount + self.amount + else: + amount = self.amount # Limit to [1, 20] - confinedAmount = min(20, max(1, self.amount)) + confinedAmount = min(20, max(1, amount)) if confinedAmount == self.savedAmount: return False projectionInfo.amount = confinedAmount diff --git a/gui/fitCommands/calc/projectedFit/remove.py b/gui/fitCommands/calc/projectedFit/remove.py index 3a342fa07..ff7f812dc 100644 --- a/gui/fitCommands/calc/projectedFit/remove.py +++ b/gui/fitCommands/calc/projectedFit/remove.py @@ -10,12 +10,14 @@ pyfalog = Logger(__name__) class CalcRemoveProjectedFitCommand(wx.Command): - def __init__(self, fitID, projectedFitID): + def __init__(self, fitID, projectedFitID, amount): wx.Command.__init__(self, True, 'Add Projected Fit') self.fitID = fitID self.projectedFitID = projectedFitID + self.amount = amount self.savedState = None self.savedAmount = None + self.changeAmountCommand = None def Do(self): pyfalog.debug('Doing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) @@ -34,15 +36,28 @@ class CalcRemoveProjectedFitCommand(wx.Command): self.savedState = projectionInfo.active self.savedAmount = projectionInfo.amount - if projectedFit.ID not in fit.projectedFitDict: - pyfalog.warning('Unable to find projected fit in projected dict') - return False - del fit.projectedFitDict[projectedFit.ID] - eos.db.commit() - return True + + remainingAmount = projectionInfo.amount - self.amount + + # Change amount if more than 0 remaining, remove otherwise + if remainingAmount > 0: + from .changeAmount import CalcChangeProjectedFitAmountCommand + self.changeAmountCommand = CalcChangeProjectedFitAmountCommand( + fitID=self.fitID, projectedFitID=self.projectedFitID, amount=remainingAmount) + return self.changeAmountCommand.Do() + else: + self.changeAmountCommand = None + if projectedFit.ID not in fit.projectedFitDict: + pyfalog.warning('Unable to find projected fit in projected dict') + return False + del fit.projectedFitDict[projectedFit.ID] + eos.db.commit() + return True def Undo(self): pyfalog.debug('Undoing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID)) + if self.changeAmountCommand is not None: + return self.changeAmountCommand.Undo() from .add import CalcAddProjectedFitCommand cmd = CalcAddProjectedFitCommand( fitID=self.fitID, diff --git a/gui/fitCommands/gui/projectedFit/add.py b/gui/fitCommands/gui/projectedFit/add.py index c36e712f4..87ec79587 100644 --- a/gui/fitCommands/gui/projectedFit/add.py +++ b/gui/fitCommands/gui/projectedFit/add.py @@ -9,14 +9,15 @@ from service.fit import Fit class GuiAddProjectedFitCommand(wx.Command): - def __init__(self, fitID, projectedFitID): + def __init__(self, fitID, projectedFitID, amount): wx.Command.__init__(self, True, 'Add Projected Fit') self.internalHistory = InternalCommandHistory() self.fitID = fitID self.projectedFitID = projectedFitID + self.amount = amount def Do(self): - cmd = CalcAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) + cmd = CalcAddProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount) success = self.internalHistory.submit(cmd) Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) diff --git a/gui/fitCommands/gui/projectedFit/remove.py b/gui/fitCommands/gui/projectedFit/remove.py index 2f611dd65..39959541e 100644 --- a/gui/fitCommands/gui/projectedFit/remove.py +++ b/gui/fitCommands/gui/projectedFit/remove.py @@ -9,14 +9,15 @@ from service.fit import Fit class GuiRemoveProjectedFitCommand(wx.Command): - def __init__(self, fitID, projectedFitID): + def __init__(self, fitID, projectedFitID, amount): wx.Command.__init__(self, True, 'Remove Projected Fit') self.internalHistory = InternalCommandHistory() self.fitID = fitID self.projectedFitID = projectedFitID + self.amount = amount def Do(self): - cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID) + cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount) success = self.internalHistory.submit(cmd) Fit.getInstance().recalc(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))