Rework "change drone/cargo amount" commands
This commit is contained in:
@@ -148,9 +148,9 @@ class CargoView(d.Display):
|
||||
return
|
||||
|
||||
self.original = fit.cargo if fit is not None else None
|
||||
self.cargo = stuff = fit.cargo[:] if fit is not None else None
|
||||
if stuff is not None:
|
||||
stuff.sort(key=lambda c: (c.item.group.category.name, c.item.group.name, c.item.name))
|
||||
self.cargo = fit.cargo[:] if fit is not None else None
|
||||
if self.cargo is not None:
|
||||
self.cargo.sort(key=lambda c: (c.item.group.category.name, c.item.group.name, c.item.name))
|
||||
|
||||
if event.fitID != self.lastFitId:
|
||||
self.lastFitId = event.fitID
|
||||
@@ -162,8 +162,8 @@ class CargoView(d.Display):
|
||||
|
||||
self.deselectItems()
|
||||
|
||||
self.populate(stuff)
|
||||
self.refresh(stuff)
|
||||
self.populate(self.cargo)
|
||||
self.refresh(self.cargo)
|
||||
event.Skip()
|
||||
|
||||
def removeItem(self, event):
|
||||
@@ -180,7 +180,7 @@ class CargoView(d.Display):
|
||||
if sel != -1:
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.mainFrame.getActiveFit())
|
||||
cargo = fit.cargo[sel]
|
||||
cargo = self.cargo[sel]
|
||||
|
||||
sMkt = Market.getInstance()
|
||||
sourceContext = "cargoItem"
|
||||
|
||||
@@ -184,10 +184,10 @@ class DroneView(Display):
|
||||
return
|
||||
|
||||
self.original = fit.drones if fit is not None else None
|
||||
self.drones = stuff = fit.drones[:] if fit is not None else None
|
||||
self.drones = fit.drones[:] if fit is not None else None
|
||||
|
||||
if stuff is not None:
|
||||
stuff.sort(key=self.droneKey)
|
||||
if self.drones is not None:
|
||||
self.drones.sort(key=self.droneKey)
|
||||
|
||||
if event.fitID != self.lastFitId:
|
||||
self.lastFitId = event.fitID
|
||||
@@ -199,7 +199,7 @@ class DroneView(Display):
|
||||
|
||||
self.deselectItems()
|
||||
|
||||
self.update(stuff)
|
||||
self.update(self.drones)
|
||||
event.Skip()
|
||||
|
||||
def addItem(self, event):
|
||||
|
||||
@@ -156,9 +156,9 @@ class ImplantDisplay(d.Display):
|
||||
return
|
||||
|
||||
self.original = fit.implants if fit is not None else None
|
||||
self.implants = stuff = fit.appliedImplants[:] if fit is not None else None
|
||||
if stuff is not None:
|
||||
stuff.sort(key=lambda implant: implant.slot)
|
||||
self.implants = fit.appliedImplants[:] if fit is not None else None
|
||||
if self.implants is not None:
|
||||
self.implants.sort(key=lambda implant: implant.slot)
|
||||
|
||||
if event.fitID != self.lastFitId:
|
||||
self.lastFitId = event.fitID
|
||||
@@ -170,7 +170,7 @@ class ImplantDisplay(d.Display):
|
||||
|
||||
self.deselectItems()
|
||||
|
||||
self.update(stuff)
|
||||
self.update(self.implants)
|
||||
event.Skip()
|
||||
|
||||
def addItem(self, event):
|
||||
|
||||
@@ -48,7 +48,7 @@ class ChangeAmount(ContextMenu):
|
||||
cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())
|
||||
|
||||
if isinstance(thing, es_Cargo):
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoQty(fitID, fit.cargo.index(thing), int(float(cleanInput))))
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoQty(fitID, thing.itemID, int(float(cleanInput))))
|
||||
return # no need for post event here
|
||||
elif isinstance(thing, Drone):
|
||||
if srcContext == "droneItem":
|
||||
|
||||
@@ -38,10 +38,7 @@ class FitAddBoosterCommand(wx.Command):
|
||||
fit.boosters.insert(self.newPosition, newBooster)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
cmd = FitAddBoosterCommand(
|
||||
fitID=self.fitID,
|
||||
boosterInfo=self.oldBoosterInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
||||
cmd.Do()
|
||||
return False
|
||||
else:
|
||||
@@ -49,10 +46,7 @@ class FitAddBoosterCommand(wx.Command):
|
||||
fit.boosters.append(newBooster)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
cmd = FitAddBoosterCommand(
|
||||
fitID=self.fitID,
|
||||
boosterInfo=self.oldBoosterInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
||||
cmd.Do()
|
||||
return False
|
||||
self.newPosition = fit.boosters.index(newBooster)
|
||||
@@ -63,10 +57,7 @@ class FitAddBoosterCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undo addition of booster {} to fit {}'.format(self.newBoosterInfo, self.fitID))
|
||||
if self.oldBoosterInfo and self.oldPosition:
|
||||
cmd = FitAddBoosterCommand(
|
||||
fitID=self.fitID,
|
||||
boosterInfo=self.oldBoosterInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
||||
return cmd.Do()
|
||||
from .fitRemoveBooster import FitRemoveBoosterCommand
|
||||
cmd = FitRemoveBoosterCommand(fitID=self.fitID, position=self.newPosition)
|
||||
|
||||
@@ -20,7 +20,9 @@ class FitAddCargoCommand(wx.Command):
|
||||
pyfalog.debug('Doing addition of cargo {} to fit {}'.format(self.cargoInfo, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
cargo = next((c for c in fit.cargo if c.itemID == self.cargoInfo.itemID), None)
|
||||
if cargo is None:
|
||||
if cargo is not None:
|
||||
cargo.amount += self.cargoInfo.amount
|
||||
else:
|
||||
cargo = self.cargoInfo.toCargo()
|
||||
try:
|
||||
fit.cargo.append(cargo)
|
||||
@@ -28,8 +30,6 @@ class FitAddCargoCommand(wx.Command):
|
||||
pyfalog.warning('Failed to append to list')
|
||||
eos.db.commit()
|
||||
return False
|
||||
else:
|
||||
cargo.amount += self.cargoInfo.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
|
||||
@@ -38,10 +38,7 @@ class FitAddImplantCommand(wx.Command):
|
||||
fit.implants.insert(self.newPosition, newImplant)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
cmd = FitAddImplantCommand(
|
||||
fitID=self.fitID,
|
||||
implantInfo=self.oldImplantInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddImplantCommand(fitID=self.fitID, implantInfo=self.oldImplantInfo, position=self.oldPosition)
|
||||
cmd.Do()
|
||||
return False
|
||||
else:
|
||||
@@ -49,10 +46,7 @@ class FitAddImplantCommand(wx.Command):
|
||||
fit.implants.append(newImplant)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
cmd = FitAddImplantCommand(
|
||||
fitID=self.fitID,
|
||||
implantInfo=self.oldImplantInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddImplantCommand(fitID=self.fitID, implantInfo=self.oldImplantInfo, position=self.oldPosition)
|
||||
cmd.Do()
|
||||
return False
|
||||
self.newPosition = fit.implants.index(newImplant)
|
||||
@@ -62,10 +56,7 @@ class FitAddImplantCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undo addition of implant {} to fit {}'.format(self.newImplantInfo, self.fitID))
|
||||
if self.oldImplantInfo and self.oldPosition:
|
||||
cmd = FitAddImplantCommand(
|
||||
fitID=self.fitID,
|
||||
implantInfo=self.oldImplantInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddImplantCommand(fitID=self.fitID, implantInfo=self.oldImplantInfo, position=self.oldPosition)
|
||||
return cmd.Do()
|
||||
from .fitRemoveImplant import FitRemoveImplantCommand
|
||||
cmd = FitRemoveImplantCommand(fitID=self.fitID, position=self.newPosition)
|
||||
|
||||
@@ -33,10 +33,7 @@ class FitAddModuleCommand(wx.Command):
|
||||
for oldMod in fit.modules:
|
||||
if oldMod.getModifiedItemAttr('subSystemSlot') == newMod.getModifiedItemAttr('subSystemSlot') and newMod.slot == oldMod.slot:
|
||||
from .fitReplaceModule import FitReplaceModuleCommand
|
||||
self.subsystemCmd = FitReplaceModuleCommand(
|
||||
fitID=self.fitID,
|
||||
position=oldMod.modPosition,
|
||||
newModInfo=self.newModInfo)
|
||||
self.subsystemCmd = FitReplaceModuleCommand(fitID=self.fitID, position=oldMod.modPosition, newModInfo=self.newModInfo)
|
||||
return self.subsystemCmd.Do()
|
||||
|
||||
if not newMod.fits(fit):
|
||||
|
||||
@@ -52,14 +52,8 @@ class FitAddProjectedModuleCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing addition of projected module {} onto: {}'.format(self.newModInfo, self.fitID))
|
||||
if self.oldPosition is not None and self.oldModInfo is not None:
|
||||
cmd = FitAddProjectedModuleCommand(
|
||||
fitID=self.fitID,
|
||||
modInfo=self.oldModInfo,
|
||||
position=self.oldPosition)
|
||||
cmd = FitAddProjectedModuleCommand(fitID=self.fitID, modInfo=self.oldModInfo, position=self.oldPosition)
|
||||
return cmd.Do()
|
||||
if self.newPosition is None:
|
||||
return False
|
||||
from gui.fitCommands.calc.fitRemoveProjectedModule import FitRemoveProjectedModuleCommand
|
||||
cmd = FitRemoveProjectedModuleCommand(self.fitID, self.newPosition)
|
||||
cmd.Do()
|
||||
return True
|
||||
return cmd.Do()
|
||||
|
||||
43
gui/fitCommands/calc/fitChangeCargoAmount.py
Normal file
43
gui/fitCommands/calc/fitChangeCargoAmount.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import CargoInfo
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitChangeCargoAmount(wx.Command):
|
||||
|
||||
def __init__(self, fitID, cargoInfo):
|
||||
wx.Command.__init__(self, True, 'Change Cargo Quantity')
|
||||
self.fitID = fitID
|
||||
self.cargoInfo = cargoInfo
|
||||
self.savedCargoInfo = None
|
||||
self.removeCommand = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing change of cargo {} for fit {}'.format(self.cargoInfo, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
cargo = next((c for c in fit.cargo if c.itemID == self.cargoInfo.itemID), None)
|
||||
if cargo is None:
|
||||
pyfalog.warning('Cannot find cargo item')
|
||||
return False
|
||||
self.savedCargoInfo = CargoInfo.fromCargo(cargo)
|
||||
if self.cargoInfo.amount > 0:
|
||||
cargo.amount = self.cargoInfo.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
else:
|
||||
from .fitRemoveCargo import FitRemoveCargoCommand
|
||||
self.removeCommand = FitRemoveCargoCommand(fitID=self.fitID, cargoInfo=self.savedCargoInfo)
|
||||
return self.removeCommand.Do()
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing change of cargo {} for fit {}'.format(self.cargoInfo, self.fitID))
|
||||
if self.removeCommand is not None:
|
||||
return self.removeCommand.Undo()
|
||||
cmd = FitChangeCargoAmount(self.fitID, self.savedCargoInfo)
|
||||
return cmd.Do()
|
||||
@@ -1,27 +0,0 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitChangeCargoQty(wx.Command):
|
||||
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 cargo ({0}) for fit ({1}) to amount: {2}", self.position, self.fitID, self.amount)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
cargo = fit.cargo[self.position]
|
||||
self.old_amount = cargo.amount
|
||||
cargo.amount = self.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitChangeCargoQty(self.fitID, self.position, self.old_amount)
|
||||
return cmd.Do()
|
||||
53
gui/fitCommands/calc/fitChangeDroneAmount.py
Normal file
53
gui/fitCommands/calc/fitChangeDroneAmount.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import math
|
||||
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import DroneInfo
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitChangeDroneAmount(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
wx.Command.__init__(self, True, 'Change Drone Quantity')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
self.savedDroneInfo = None
|
||||
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))
|
||||
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
|
||||
drone.amount = self.amount
|
||||
drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0)
|
||||
eos.db.commit()
|
||||
return True
|
||||
else:
|
||||
from .fitRemoveDrone import FitRemoveDroneCommand
|
||||
self.removeCommand = FitRemoveDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf)
|
||||
return self.removeCommand.Do()
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing change of drone quantity to {} at position {} on fit {}'.format(self.amount, self.position, self.fitID))
|
||||
if self.removeCommand is not None:
|
||||
return self.removeCommand.Undo()
|
||||
if self.savedDroneInfo is not None:
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = fit.drones[self.position]
|
||||
drone.amount = self.savedDroneInfo.amount
|
||||
drone.amountActive = self.savedDroneInfo.amountActive
|
||||
eos.db.commit()
|
||||
return True
|
||||
return False
|
||||
@@ -1,27 +0,0 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitChangeDroneQty(wx.Command):
|
||||
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)
|
||||
drone = fit.drones[self.position]
|
||||
self.old_amount = drone.amount
|
||||
drone.amount = self.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitChangeDroneQty(self.fitID, self.position, self.old_amount)
|
||||
return cmd.Do()
|
||||
@@ -26,9 +26,9 @@ class FitRemoveDroneCommand(wx.Command):
|
||||
drone = fit.drones[self.position]
|
||||
self.savedDroneInfo = DroneInfo.fromDrone(drone)
|
||||
|
||||
drone.amount -= self.amountToRemove
|
||||
drone.amount = max(drone.amount - self.amountToRemove, 0)
|
||||
if drone.amountActive > 0:
|
||||
drone.amountActive -= self.amountToRemove
|
||||
drone.amountActive = min(drone.amountActive, drone.amount)
|
||||
|
||||
if drone.amount == 0:
|
||||
fit.drones.remove(drone)
|
||||
|
||||
@@ -18,9 +18,7 @@ class GuiAddBoosterCommand(wx.Command):
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitAddBoosterCommand(
|
||||
fitID=self.fitID,
|
||||
boosterInfo=BoosterInfo(itemID=self.itemID))):
|
||||
if self.internal_history.Submit(FitAddBoosterCommand(fitID=self.fitID, boosterInfo=BoosterInfo(itemID=self.itemID))):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import wx
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitChangeCargoQty import FitChangeCargoQty
|
||||
from .calc.fitChangeCargoAmount import FitChangeCargoAmount
|
||||
from service.fit import Fit
|
||||
from gui.fitCommands.helpers import CargoInfo
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiChangeCargoQty(wx.Command):
|
||||
def __init__(self, fitID, position, amount=1):
|
||||
|
||||
def __init__(self, fitID, itemID, amount):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.itemID = itemID
|
||||
self.amount = amount
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
cmd = FitChangeCargoQty(self.fitID, self.position, self.amount)
|
||||
cmd = FitChangeCargoAmount(self.fitID, CargoInfo(itemID=self.itemID, amount=self.amount))
|
||||
if self.internal_history.Submit(cmd):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import wx
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitChangeDroneQty import FitChangeDroneQty
|
||||
from .calc.fitChangeDroneAmount import FitChangeDroneAmount
|
||||
from service.fit import Fit
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -18,7 +18,7 @@ class GuiChangeDroneQty(wx.Command):
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
cmd = FitChangeDroneQty(self.fitID, self.position, self.amount)
|
||||
cmd = FitChangeDroneAmount(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))
|
||||
|
||||
@@ -233,6 +233,15 @@ class CargoInfo:
|
||||
self.itemID = itemID
|
||||
self.amount = amount
|
||||
|
||||
@classmethod
|
||||
def fromCargo(cls, cargo):
|
||||
if cargo is None:
|
||||
return None
|
||||
info = cls(
|
||||
itemID=cargo.itemID,
|
||||
amount=cargo.amount)
|
||||
return info
|
||||
|
||||
def toCargo(self):
|
||||
item = Market.getInstance().getItem(self.itemID)
|
||||
cargo = Cargo(item)
|
||||
|
||||
Reference in New Issue
Block a user