work on moving from cargo to modules (including swapping modules)
This commit is contained in:
@@ -130,6 +130,10 @@ class CargoView(d.Display):
|
||||
if mstate.cmdDown: # if copying, append to cargo
|
||||
sFit.addCargo(self.mainFrame.getActiveFit(), module.item.ID if not module.item.isAbyssal else module.baseItemID)
|
||||
else: # else, move / swap
|
||||
# self.mainFrame.command.Submit(cmd.GuiCargoToModuleCommand(
|
||||
# self.mainFrame.getActiveFit(),
|
||||
# module.modPosition,
|
||||
# dstRow))
|
||||
sFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.position, dstRow)
|
||||
else: # dragging to blank spot, append
|
||||
sFit.addCargo(self.mainFrame.getActiveFit(), module.item.ID if not module.item.isAbyssal else module.baseItemID)
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
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.booster import Booster
|
||||
|
||||
class FitAddBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addBooster
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_index = None
|
||||
self.old_item = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.itemID, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager="attributes")
|
||||
|
||||
if next((x for x in fit.boosters if x.itemID == self.itemID), None):
|
||||
return False # already have item in list of boosters
|
||||
|
||||
try:
|
||||
booster = Booster(item)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", self.itemID)
|
||||
return False
|
||||
|
||||
self.old_item = fit.boosters.makeRoom(booster)
|
||||
fit.boosters.append(booster)
|
||||
self.new_index = fit.boosters.index(booster)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
if self.old_item:
|
||||
# If we had an item in the slot previously, add it back.
|
||||
cmd = FitAddBoosterCommand(self.fitID, self.old_item)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
from .fitRemoveBooster import FitRemoveBoosterCommand # Avoid circular import
|
||||
cmd = FitRemoveBoosterCommand(self.fitID, self.new_index)
|
||||
cmd.Do()
|
||||
return True
|
||||
@@ -6,6 +6,7 @@ from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.fitSetCharge import FitSetChargeCommand
|
||||
from gui.fitCommands.calc.fitReplaceModule import FitReplaceModuleCommand
|
||||
from gui.fitCommands.calc.fitRemoveCargo import FitRemoveCargoCommand
|
||||
from .calc.fitAddCargo import FitAddCargoCommand
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -43,12 +44,22 @@ class GuiCargoToModuleCommand(wx.Command):
|
||||
pyfalog.debug("Moving cargo item to module for fit ID: {0}", self.fitID)
|
||||
|
||||
self.addCmd = FitReplaceModuleCommand(self.fitID, module.modPosition, cargo.itemID)
|
||||
|
||||
result = self.internal_history.Submit(self.addCmd)
|
||||
|
||||
if not result:
|
||||
# module failed
|
||||
# creating module failed for whatever reason
|
||||
return False
|
||||
|
||||
if not self.copy:
|
||||
if self.addCmd.old_module is not None:
|
||||
# we're swapping with an existing module, so remove cargo and add module
|
||||
self.removeCmd = FitRemoveCargoCommand(self.fitID, cargo.itemID)
|
||||
result = self.internal_history.Submit(self.removeCmd)
|
||||
|
||||
self.addCargoCmd = FitAddCargoCommand(self.fitID, self.addCmd.old_module.itemID)
|
||||
result = self.internal_history.Submit(self.addCargoCmd)
|
||||
elif not self.copy:
|
||||
# move, not copying, so remove cargo
|
||||
self.removeCmd = FitRemoveCargoCommand(self.fitID, cargo.itemID)
|
||||
result = self.internal_history.Submit(self.removeCmd)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user