From 7e94914f6591f3d9b631cb2af8716c81ff84803c Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sat, 18 Aug 2018 01:09:37 -0400 Subject: [PATCH] Implement drone toggle command --- gui/builtinAdditionPanes/droneView.py | 4 +- gui/fitCommands/__init__.py | 3 +- gui/fitCommands/calc/fitToggleDrone.py | 35 ++++++++++ gui/fitCommands/guiToggleDrone.py | 30 +++++++++ service/fit.py | 86 ------------------------ service/fitDeprecated.py | 91 ++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 90 deletions(-) create mode 100644 gui/fitCommands/calc/fitToggleDrone.py create mode 100644 gui/fitCommands/guiToggleDrone.py diff --git a/gui/builtinAdditionPanes/droneView.py b/gui/builtinAdditionPanes/droneView.py index 6e236d0fd..e95906ae9 100644 --- a/gui/builtinAdditionPanes/droneView.py +++ b/gui/builtinAdditionPanes/droneView.py @@ -239,10 +239,8 @@ class DroneView(Display): col = self.getColumn(event.Position) if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() - sFit = Fit.getInstance() drone = self.drones[row] - sFit.toggleDrone(fitID, self.original.index(drone)) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiToggleDroneCommand(fitID, self.original.index(drone))) def scheduleMenu(self, event): event.Skip() diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 2fce1e1c6..1c1e3905e 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -29,4 +29,5 @@ from .guiChangeFighterQty import GuiChangeFighterQty from .guiChangeCargoQty import GuiChangeCargoQty from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty from .guiChangeDroneQty import GuiChangeDroneQty -from.guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty \ No newline at end of file +from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty +from .guiToggleDrone import GuiToggleDroneCommand \ No newline at end of file diff --git a/gui/fitCommands/calc/fitToggleDrone.py b/gui/fitCommands/calc/fitToggleDrone.py new file mode 100644 index 000000000..a10796888 --- /dev/null +++ b/gui/fitCommands/calc/fitToggleDrone.py @@ -0,0 +1,35 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +pyfalog = Logger(__name__) + +class FitToggleDroneCommand(wx.Command): + """" + from sFit.toggleDrone + """ + def __init__(self, fitID, position): + wx.Command.__init__(self, True, "Cargo add") + self.fitID = fitID + self.position = position + + def Do(self): + pyfalog.debug("Toggling drones for fit ID: {0}", self.fitID) + fit = eos.db.getFit(self.fitID) + d = fit.drones[self.position] + if d.amount == d.amountActive: + d.amountActive = 0 + else: + d.amountActive = d.amount + + eos.db.commit() + return True + + def Undo(self): + cmd = FitToggleDroneCommand(self.fitID, self.position) + return cmd.Do() diff --git a/gui/fitCommands/guiToggleDrone.py b/gui/fitCommands/guiToggleDrone.py new file mode 100644 index 000000000..3dc8c4cec --- /dev/null +++ b/gui/fitCommands/guiToggleDrone.py @@ -0,0 +1,30 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitToggleDrone import FitToggleDroneCommand + +class GuiToggleDroneCommand(wx.Command): + def __init__(self, fitID, position): + wx.Command.__init__(self, True, "") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + self.position = position + + def Do(self): + if self.internal_history.Submit(FitToggleDroneCommand(self.fitID, self.position)): + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + diff --git a/service/fit.py b/service/fit.py index 6ed79829d..1f4b417dd 100644 --- a/service/fit.py +++ b/service/fit.py @@ -438,92 +438,6 @@ class Fit(FitDeprecated): else: return False - def mergeDrones(self, fitID, d1, d2, projected=False): - pyfalog.debug("Merging drones on fit ID: {0}", fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - if d1.item != d2.item: - return False - - if projected: - fit.projectedDrones.remove(d1) - else: - fit.drones.remove(d1) - - d2.amount += d1.amount - d2.amountActive += d1.amountActive - - # If we have less than the total number of drones active, make them all active. Fixes #728 - # This could be removed if we ever add an enhancement to make drone stacks partially active. - if d2.amount > d2.amountActive: - d2.amountActive = d2.amount - - eos.db.commit() - self.recalc(fit) - return True - - @staticmethod - def splitDrones(fit, d, amount, l): - pyfalog.debug("Splitting drones for fit ID: {0}", fit) - total = d.amount - active = d.amountActive > 0 - d.amount = amount - d.amountActive = amount if active else 0 - - newD = es_Drone(d.item) - newD.amount = total - amount - newD.amountActive = newD.amount if active else 0 - l.append(newD) - eos.db.commit() - - def splitProjectedDroneStack(self, fitID, d, amount): - pyfalog.debug("Splitting projected drone stack for fit ID: {0}", fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - self.splitDrones(fit, d, amount, fit.projectedDrones) - - def splitDroneStack(self, fitID, d, amount): - pyfalog.debug("Splitting drone stack for fit ID: {0}", fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - self.splitDrones(fit, d, amount, fit.drones) - - @deprecated - def removeDrone(self, fitID, i, numDronesToRemove=1, recalc=True): - pyfalog.debug("Removing {0} drones for fit ID: {1}", numDronesToRemove, fitID) - fit = eos.db.getFit(fitID) - d = fit.drones[i] - d.amount -= numDronesToRemove - if d.amountActive > 0: - d.amountActive -= numDronesToRemove - - if d.amount == 0: - del fit.drones[i] - - eos.db.commit() - if recalc: - self.recalc(fit) - return True - - def toggleDrone(self, fitID, i): - pyfalog.debug("Toggling drones for fit ID: {0}", fitID) - fit = eos.db.getFit(fitID) - d = fit.drones[i] - if d.amount == d.amountActive: - d.amountActive = 0 - else: - d.amountActive = d.amount - - eos.db.commit() - self.recalc(fit) - return True - def toggleImplantSource(self, fitID, source): pyfalog.debug("Toggling implant source for fit ID: {0}", fitID) fit = eos.db.getFit(fitID) diff --git a/service/fitDeprecated.py b/service/fitDeprecated.py index 165d929eb..e36014364 100644 --- a/service/fitDeprecated.py +++ b/service/fitDeprecated.py @@ -36,6 +36,97 @@ pyfalog = Logger(__name__) class FitDeprecated(object): + @deprecated + def toggleDrone(self, fitID, i): + pyfalog.debug("Toggling drones for fit ID: {0}", fitID) + fit = eos.db.getFit(fitID) + d = fit.drones[i] + if d.amount == d.amountActive: + d.amountActive = 0 + else: + d.amountActive = d.amount + + eos.db.commit() + self.recalc(fit) + return True + + @deprecated + def mergeDrones(self, fitID, d1, d2, projected=False): + pyfalog.debug("Merging drones on fit ID: {0}", fitID) + if fitID is None: + return False + + fit = eos.db.getFit(fitID) + if d1.item != d2.item: + return False + + if projected: + fit.projectedDrones.remove(d1) + else: + fit.drones.remove(d1) + + d2.amount += d1.amount + d2.amountActive += d1.amountActive + + # If we have less than the total number of drones active, make them all active. Fixes #728 + # This could be removed if we ever add an enhancement to make drone stacks partially active. + if d2.amount > d2.amountActive: + d2.amountActive = d2.amount + + eos.db.commit() + self.recalc(fit) + return True + + @staticmethod + @deprecated + def splitDrones(fit, d, amount, l): + pyfalog.debug("Splitting drones for fit ID: {0}", fit) + total = d.amount + active = d.amountActive > 0 + d.amount = amount + d.amountActive = amount if active else 0 + + newD = es_Drone(d.item) + newD.amount = total - amount + newD.amountActive = newD.amount if active else 0 + l.append(newD) + eos.db.commit() + + @deprecated + def splitProjectedDroneStack(self, fitID, d, amount): + pyfalog.debug("Splitting projected drone stack for fit ID: {0}", fitID) + if fitID is None: + return False + + fit = eos.db.getFit(fitID) + self.splitDrones(fit, d, amount, fit.projectedDrones) + + @deprecated + def splitDroneStack(self, fitID, d, amount): + pyfalog.debug("Splitting drone stack for fit ID: {0}", fitID) + if fitID is None: + return False + + fit = eos.db.getFit(fitID) + self.splitDrones(fit, d, amount, fit.drones) + + @deprecated + def removeDrone(self, fitID, i, numDronesToRemove=1, recalc=True): + pyfalog.debug("Removing {0} drones for fit ID: {1}", numDronesToRemove, fitID) + fit = eos.db.getFit(fitID) + d = fit.drones[i] + d.amount -= numDronesToRemove + if d.amountActive > 0: + d.amountActive -= numDronesToRemove + + if d.amount == 0: + del fit.drones[i] + + eos.db.commit() + if recalc: + self.recalc(fit) + return True + @deprecated def changeAmount(self, fitID, projected_fit, amount): """Change amount of projected fits"""