Set up commands for adding/removing cargo
This commit is contained in:
@@ -5,6 +5,7 @@ import gui.globalEvents as GE
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
from service.settings import ContextMenuSettings
|
||||
import gui.fitCommands as cmd
|
||||
|
||||
|
||||
class Cargo(ContextMenu):
|
||||
@@ -32,13 +33,12 @@ class Cargo(ContextMenu):
|
||||
return "Add {0} to Cargo".format(itmContext)
|
||||
|
||||
def activate(self, fullContext, selection, i):
|
||||
sFit = Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
|
||||
typeID = int(selection[0].ID)
|
||||
sFit.addCargo(fitID, typeID)
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, typeID))
|
||||
self.mainFrame.additionsPane.select("Cargo")
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
|
||||
Cargo.register()
|
||||
|
||||
@@ -49,7 +49,8 @@ class ItemRemove(ContextMenu):
|
||||
elif srcContext == "boosterItem":
|
||||
sFit.removeBooster(fitID, fit.boosters.index(selection[0]))
|
||||
elif srcContext == "cargoItem":
|
||||
sFit.removeCargo(fitID, fit.cargo.index(selection[0]))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCargoCommand(fitID, selection[0].itemID))
|
||||
return # the command takes care of the PostEvent
|
||||
elif srcContext in ("projectedFit", "projectedModule", "projectedDrone", "projectedFighter"):
|
||||
sFit.removeProjected(fitID, selection[0])
|
||||
elif srcContext == "commandFit":
|
||||
|
||||
@@ -2,4 +2,8 @@ from .moduleStateChange import GuiModuleStateChangeCommand
|
||||
from .moduleAdd import GuiModuleAddCommand
|
||||
from .moduleRemove import GuiModuleRemoveCommand
|
||||
from .moduleAddCharge import GuiModuleAddChargeCommand
|
||||
from .moduleSwapOrClone import GuiModuleSwapOrCloneCommand
|
||||
from .moduleSwapOrClone import GuiModuleSwapOrCloneCommand
|
||||
from .guiRemoveCargo import GuiRemoveCargoCommand
|
||||
from .guiAddCargo import GuiAddCargoCommand
|
||||
from .fitAddCargo import FitAddCargoCommand
|
||||
from .fitRemoveCargo import FitRemoveCargoCommand
|
||||
48
gui/fitCommands/fitAddCargo.py
Normal file
48
gui/fitCommands/fitAddCargo.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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__)
|
||||
from eos.saveddata.cargo import Cargo
|
||||
|
||||
class FitAddCargoCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addCargo
|
||||
"""
|
||||
def __init__(self, fitID, itemID, amount=1, replace=False):
|
||||
wx.Command.__init__(self, True, "Cargo add")
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.amount = amount # add x amount. If this goes over amount, removes stack
|
||||
self.replace = replace # if this is false, we increment.
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding cargo {0} (x{1}) for fit {2}", self.itemID, self.amount, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID)
|
||||
|
||||
cargo = next((x for x in fit.cargo if x.itemID == self.itemID), None)
|
||||
|
||||
if cargo is None:
|
||||
cargo = Cargo(item)
|
||||
fit.cargo.append(cargo)
|
||||
|
||||
if self.replace:
|
||||
cargo.amount = self.amount
|
||||
else:
|
||||
cargo.amount += self.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitRemoveCargo import FitRemoveCargoCommand # Avoid circular import
|
||||
cmd = FitRemoveCargoCommand(self.fitID, self.itemID, self.amount)
|
||||
cmd.Do()
|
||||
return True
|
||||
53
gui/fitCommands/fitRemoveCargo.py
Normal file
53
gui/fitCommands/fitRemoveCargo.py
Normal file
@@ -0,0 +1,53 @@
|
||||
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 FitRemoveCargoCommand(wx.Command):
|
||||
""""
|
||||
Fitting command that sets the amount for an item within the cargo.
|
||||
|
||||
from sFit.removeCargo
|
||||
"""
|
||||
def __init__(self, fitID, itemID, amount=1, stack=False):
|
||||
wx.Command.__init__(self, True, "Cargo remove")
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.stack = stack # remove entire stack
|
||||
self.amount = amount # remove x amount. If this goes over amount, removes stack
|
||||
self.old_amount = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing cargo {0} (x{1}) for fit {2}", self.itemID, self.amount, self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
cargo = next((x for x in fit.cargo if x.itemID == self.itemID), None)
|
||||
|
||||
if cargo is None:
|
||||
return False
|
||||
|
||||
self.old_amount = cargo.amount
|
||||
|
||||
if self.amount >= cargo.amount:
|
||||
self.stack = True # set to full stack, this allows easier logic in the Undo function
|
||||
|
||||
if self.stack or self.amount >= cargo.amount:
|
||||
fit.cargo.remove(cargo)
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
cargo.amount -= self.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitAddCargo import FitAddCargoCommand # Avoid circular import
|
||||
cmd = FitAddCargoCommand(self.fitID, self.itemID, self.old_amount, True)
|
||||
cmd.Do()
|
||||
return True
|
||||
@@ -37,7 +37,7 @@ class FitSetChargeCommand(wx.Command):
|
||||
result = False
|
||||
|
||||
for mod in modules:
|
||||
if mod.isValidCharge(ammo):
|
||||
if not mod.isEmpty and mod.isValidCharge(ammo):
|
||||
result = True
|
||||
mod.charge = ammo
|
||||
eos.db.commit()
|
||||
|
||||
29
gui/fitCommands/guiAddCargo.py
Normal file
29
gui/fitCommands/guiAddCargo.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .fitAddCargo import FitAddCargoCommand
|
||||
|
||||
class GuiAddCargoCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Cargo Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitAddCargoCommand(fitID, itemID)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
29
gui/fitCommands/guiRemoveCargo.py
Normal file
29
gui/fitCommands/guiRemoveCargo.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .fitRemoveCargo import FitRemoveCargoCommand
|
||||
|
||||
class GuiRemoveCargoCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Module Charge Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
# can set his up no to not have to set variables on our object
|
||||
self.cmd = FitRemoveCargoCommand(fitID, itemID, stack=True)
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(self.cmd):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for x in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -672,6 +672,7 @@ class Fit(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
@deprecated
|
||||
def moveCargoToModule(self, fitID, moduleIdx, cargoIdx, copyMod=False):
|
||||
"""
|
||||
Moves cargo to fitting window. Can either do a copy, move, or swap with current module
|
||||
@@ -775,6 +776,7 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
|
||||
@deprecated
|
||||
def addCargo(self, fitID, itemID, amount=1, replace=False):
|
||||
"""
|
||||
Adds cargo via typeID of item. If replace = True, we replace amount with
|
||||
@@ -812,6 +814,7 @@ class Fit(object):
|
||||
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def removeCargo(self, fitID, position):
|
||||
pyfalog.debug("Removing cargo from position ({0}) fit ID: {1}", position, fitID)
|
||||
if fitID is None:
|
||||
|
||||
Reference in New Issue
Block a user