Improved on drag/drop for cargo and fitting views. Can now copy rather than swap
This commit is contained in:
@@ -24,7 +24,7 @@ class Cargo(ContextMenu):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
|
||||
typeID = int(selection[0].ID)
|
||||
sFit.addCargo(fitID, typeID, 1)
|
||||
sFit.addCargo(fitID, typeID)
|
||||
self.mainFrame.additionsPane.select("Cargo")
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
|
||||
@@ -346,13 +346,14 @@ class FittingView(d.Display):
|
||||
|
||||
def swapCargo(self, x, y, srcIdx):
|
||||
'''Swap a module from cargo to fitting window'''
|
||||
mstate = wx.GetMouseState()
|
||||
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
module = self.mods[dstRow]
|
||||
|
||||
cFit = service.Fit.getInstance()
|
||||
cFit.swapModuleWithCargo(self.mainFrame.getActiveFit(), module.position, srcIdx)
|
||||
cFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.position, srcIdx, mstate.CmdDown() and module.isEmpty)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
|
||||
|
||||
|
||||
@@ -102,17 +102,26 @@ class CargoView(d.Display):
|
||||
|
||||
def swapModule(self, x, y, modIdx):
|
||||
'''Swap a module from fitting window with cargo'''
|
||||
|
||||
sFit = service.Fit.getInstance()
|
||||
fit = sFit.getFit(self.mainFrame.getActiveFit())
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
if dstRow != -1:
|
||||
# Gather module information to get position
|
||||
sFit = service.Fit.getInstance()
|
||||
fit = sFit.getFit(self.mainFrame.getActiveFit())
|
||||
module = fit.modules[modIdx]
|
||||
mstate = wx.GetMouseState()
|
||||
|
||||
sFit.swapModuleWithCargo(self.mainFrame.getActiveFit(), module.position, dstRow)
|
||||
# Gather module information to get position
|
||||
module = fit.modules[modIdx]
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
|
||||
if dstRow != -1: # we're swapping with cargo
|
||||
if mstate.CmdDown(): # if copying, append to cargo
|
||||
sFit.addCargo(self.mainFrame.getActiveFit(), module.item.ID)
|
||||
else: # else, move / swap
|
||||
sFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.position, dstRow)
|
||||
else: # dragging to blank spot, append
|
||||
sFit.addCargo(self.mainFrame.getActiveFit(), module.item.ID)
|
||||
|
||||
if not mstate.CmdDown(): # if not copying, remove module
|
||||
sFit.removeModule(self.mainFrame.getActiveFit(), module.position)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
|
||||
|
||||
def fitChanged(self, event):
|
||||
#Clear list and get out if current fitId is None
|
||||
|
||||
@@ -396,9 +396,10 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
return numSlots != len(fit.modules)
|
||||
|
||||
def swapModuleWithCargo(self, fitID, moduleIdx, cargoIdx):
|
||||
def moveCargoToModule(self, fitID, moduleIdx, cargoIdx, copy = False):
|
||||
'''
|
||||
This swaps a module from the cargo with a module from fit.
|
||||
Moves cargo to fitting window. Can either do a copy, move, or swap with current module
|
||||
If we try to copy/move into a spot with a non-empty module, we swap instead.
|
||||
|
||||
To avoid redundancy in converting Cargo item, this function does the
|
||||
sanity checks as opposed to the GUI View. This is different than how the
|
||||
@@ -406,30 +407,41 @@ class Fit(object):
|
||||
'''
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
module = fit.modules[moduleIdx]
|
||||
|
||||
# Gather modules and convert Cargo item to Module, silently return if not a module
|
||||
try:
|
||||
cargoP = Module(fit.cargo[cargoIdx].item)
|
||||
cargoP.owner = fit
|
||||
if cargoP.isValidState(State.ACTIVE):
|
||||
cargoP.state = State.ACTIVE
|
||||
module = fit.modules[moduleIdx]
|
||||
except:
|
||||
return
|
||||
|
||||
if cargoP.slot != module.slot: # can't swap modules to different racks
|
||||
return
|
||||
|
||||
# remove module that we are trying to move cargo to
|
||||
fit.modules.remove(module)
|
||||
|
||||
if not cargoP.fits(fit): #if cargo doesn't fit, rollback and return
|
||||
fit.modules.insert(moduleIdx, module)
|
||||
return
|
||||
|
||||
fit.modules.insert(moduleIdx, cargoP)
|
||||
|
||||
if not copy: # remove existing cargo if not cloning
|
||||
fit.cargo.remove(fit.cargo[cargoIdx])
|
||||
|
||||
if not module.isEmpty: # if module is placeholder, we don't want to convert/add it
|
||||
moduleP = Cargo(module.item)
|
||||
moduleP.amount = 1
|
||||
except Exception, e:
|
||||
return
|
||||
|
||||
# can't swap modules to different racks
|
||||
if cargoP.slot != module.slot:
|
||||
return
|
||||
|
||||
# To swap, we simply remove mod and insert at destination.
|
||||
fit.modules.remove(module)
|
||||
fit.modules.insert(moduleIdx, cargoP)
|
||||
fit.cargo.remove(fit.cargo[cargoIdx])
|
||||
fit.cargo.insert(cargoIdx, moduleP)
|
||||
fit.cargo.insert(cargoIdx, moduleP)
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
|
||||
|
||||
def swapModules(self, fitID, src, dst):
|
||||
fit = eos.db.getFit(fitID)
|
||||
# Gather modules
|
||||
@@ -466,7 +478,7 @@ class Fit(object):
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
|
||||
def addCargo(self, fitID, itemID, amount):
|
||||
def addCargo(self, fitID, itemID, amount=1):
|
||||
if fitID == None:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user