diff --git a/gui/builtinContextMenus/amount.py b/gui/builtinContextMenus/amount.py index ba61afa38..34a608a13 100644 --- a/gui/builtinContextMenus/amount.py +++ b/gui/builtinContextMenus/amount.py @@ -34,6 +34,8 @@ class ChangeAmount(ContextMenu): srcContext = fullContext[0] if isinstance(thing, es_Fit): value = thing.getProjectionInfo(fitID).amount + elif isinstance(thing, es_Fighter): + value = thing.amountActive else: value = thing.amount diff --git a/gui/fitCommands/calc/fitChangeCargoAmount.py b/gui/fitCommands/calc/fitChangeCargoAmount.py index c468cd9ce..998951c97 100644 --- a/gui/fitCommands/calc/fitChangeCargoAmount.py +++ b/gui/fitCommands/calc/fitChangeCargoAmount.py @@ -12,7 +12,7 @@ pyfalog = Logger(__name__) class FitChangeCargoAmount(wx.Command): def __init__(self, fitID, cargoInfo): - wx.Command.__init__(self, True, 'Change Cargo Quantity') + wx.Command.__init__(self, True, 'Change Cargo Amount') self.fitID = fitID self.cargoInfo = cargoInfo self.savedCargoInfo = None @@ -26,6 +26,8 @@ class FitChangeCargoAmount(wx.Command): pyfalog.warning('Cannot find cargo item') return False self.savedCargoInfo = CargoInfo.fromCargo(cargo) + if self.cargoInfo.amount == self.savedCargoInfo.amount: + return False if self.cargoInfo.amount > 0: cargo.amount = self.cargoInfo.amount eos.db.commit() diff --git a/gui/fitCommands/calc/fitChangeDroneAmount.py b/gui/fitCommands/calc/fitChangeDroneAmount.py index a0d6fc0dc..492a4559c 100644 --- a/gui/fitCommands/calc/fitChangeDroneAmount.py +++ b/gui/fitCommands/calc/fitChangeDroneAmount.py @@ -14,7 +14,7 @@ pyfalog = Logger(__name__) class FitChangeDroneAmount(wx.Command): def __init__(self, fitID, position, amount): - wx.Command.__init__(self, True, 'Change Drone Quantity') + wx.Command.__init__(self, True, 'Change Drone Amount') self.fitID = fitID self.position = position self.amount = amount @@ -22,11 +22,13 @@ class FitChangeDroneAmount(wx.Command): self.removeCommand = None def Do(self): - pyfalog.debug('Doing change of drone quantity to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) + pyfalog.debug('Doing change of drone amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) + fit = Fit.getInstance().getFit(self.fitID) + drone = fit.drones[self.position] + self.savedDroneInfo = DroneInfo.fromDrone(drone) + if self.amount == self.savedDroneInfo.amount: + return False if self.amount > 0: - fit = Fit.getInstance().getFit(self.fitID) - drone = fit.drones[self.position] - self.savedDroneInfo = DroneInfo.fromDrone(drone) drone.amount = self.amount if drone.amountActive > 0: difference = self.amount - self.savedDroneInfo.amount diff --git a/gui/fitCommands/calc/fitChangeFighterAmount.py b/gui/fitCommands/calc/fitChangeFighterAmount.py new file mode 100644 index 000000000..2fa21c24b --- /dev/null +++ b/gui/fitCommands/calc/fitChangeFighterAmount.py @@ -0,0 +1,40 @@ +import wx +from logbook import Logger + +import eos.db +from service.fit import Fit + + +pyfalog = Logger(__name__) + + +class FitChangeFighterAmount(wx.Command): + + def __init__(self, fitID, position, amount): + wx.Command.__init__(self, True, 'Change Fighter Amount') + self.fitID = fitID + self.position = position + self.amount = amount + self.savedAmount = None + self.removeCommand = None + + def Do(self): + pyfalog.debug('Doing change of fighter amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) + fit = Fit.getInstance().getFit(self.fitID) + fighter = fit.fighters[self.position] + self.savedAmount = fighter.amount + if self.amount > 0 or self.amount == -1: + fighter.amount = min(self.amount, fighter.fighterSquadronMaxSize) + eos.db.commit() + return True + else: + from .fitRemoveFighter import FitRemoveFighterCommand + self.removeCommand = FitRemoveFighterCommand(fitID=self.fitID, position=self.position) + return self.removeCommand.Do() + + def Undo(self): + pyfalog.debug('Undoing change of fighter amount to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID)) + if self.removeCommand is not None: + return self.removeCommand.Undo() + cmd = FitChangeFighterAmount(self.fitID, self.position, self.savedAmount) + return cmd.Do() diff --git a/gui/fitCommands/calc/fitChangeFighterQty.py b/gui/fitCommands/calc/fitChangeFighterQty.py deleted file mode 100644 index 4cef20034..000000000 --- a/gui/fitCommands/calc/fitChangeFighterQty.py +++ /dev/null @@ -1,30 +0,0 @@ -import wx -import eos.db -from logbook import Logger -pyfalog = Logger(__name__) - - -class FitChangeFighterQty(wx.Command): - """" - from sFit.changeActiveFighters - """ - def __init__(self, fitID, position, amount=1): - wx.Command.__init__(self, True, "Drone add") - self.fitID = fitID - self.position = position - self.amount = amount # add x amount. If this goes over amount, removes stack - self.old_amount = None - - def Do(self): - pyfalog.debug("Changing active fighters ({0}) for fit ({1}) to amount: {2}", self.position, self.fitID, self.amount) - fit = eos.db.getFit(self.fitID) - fighter = fit.fighters[self.position] - self.old_amount = fighter.amountActive - fighter.amountActive = self.amount - - eos.db.commit() - return True - - def Undo(self): - cmd = FitChangeFighterQty(self.fitID, self.position, self.old_amount) - return cmd.Do() diff --git a/gui/fitCommands/guiChangeFighterQty.py b/gui/fitCommands/guiChangeFighterQty.py index 280bd1a16..45ab22ab1 100644 --- a/gui/fitCommands/guiChangeFighterQty.py +++ b/gui/fitCommands/guiChangeFighterQty.py @@ -1,7 +1,7 @@ import wx import gui.mainFrame from gui import globalEvents as GE -from .calc.fitChangeFighterQty import FitChangeFighterQty +from .calc.fitChangeFighterAmount import FitChangeFighterAmount from service.fit import Fit from logbook import Logger pyfalog = Logger(__name__) @@ -18,7 +18,7 @@ class GuiChangeFighterQty(wx.Command): self.internal_history = wx.CommandProcessor() def Do(self): - cmd = FitChangeFighterQty(self.fitID, self.position, self.amount) + cmd = FitChangeFighterAmount(self.fitID, self.position, self.amount) if self.internal_history.Submit(cmd): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) diff --git a/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index 9a4f017b6..f16c30141 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -12,7 +12,6 @@ from .calc.fitAddCargo import FitAddCargoCommand from .calc.fitReplaceModule import FitReplaceModuleCommand from .calc.fitAddFighter import FitAddFighterCommand from .calc.fitRemoveFighter import FitRemoveFighterCommand -from .calc.fitChangeDroneVariation import FitChangeDroneVariationCommand from .calc.fitRebaseItem import FitRebaseItemCommand