Rework figter amount changer

This commit is contained in:
DarkPhoenix
2019-04-13 21:19:01 +03:00
parent 9e6031edf2
commit c3bffcad34
7 changed files with 54 additions and 39 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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))

View File

@@ -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