Change the way dragging from cargo to modules is handled

This commit is contained in:
DarkPhoenix
2019-04-16 02:10:02 +03:00
parent 64bba0cfdb
commit bc4c35665e
3 changed files with 48 additions and 27 deletions

View File

@@ -203,10 +203,13 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
@property
def numCharges(self):
if self.charge is None:
return self.getNumCharges(self.charge)
def getNumCharges(self, charge):
if charge is None:
charges = 0
else:
chargeVolume = self.charge.volume
chargeVolume = charge.volume
containerCapacity = self.item.capacity
if chargeVolume is None or containerCapacity is None:
charges = 0

View File

@@ -39,44 +39,62 @@ class GuiCargoToLocalModuleCommand(wx.Command):
dstMod = fit.modules[self.dstModPosition]
# Moving charge from cargo to fit - just attempt to load charge into destination module
if srcCargo.item.isCharge and not dstMod.isEmpty:
cmd = CalcChangeModuleChargesCommand(
newCargoChargeItemID = dstMod.chargeID
newCargoChargeAmount = dstMod.numCharges
newModChargeItemID = self.srcCargoItemID
newModChargeAmount = dstMod.getNumCharges(srcCargo.item)
if newCargoChargeItemID == newModChargeItemID:
return False
commands = []
if not self.copy:
commands.append(CalcRemoveCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=newModChargeItemID, amount=newModChargeAmount),
commit=False))
if newCargoChargeItemID is not None:
commands.append(CalcAddCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=newCargoChargeItemID, amount=newCargoChargeAmount),
commit=False))
commands.append(CalcChangeModuleChargesCommand(
fitID=self.fitID,
projected=False,
chargeMap={dstMod.modPosition: self.srcCargoItemID},
commit=False)
success = self.internalHistory.submit(cmd)
# Copying item to empty slot
elif srcCargo.item.isModule and self.copy and dstMod.isEmpty:
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.dstModPosition,
newModInfo=ModuleInfo(itemID=self.srcCargoItemID),
commit=False)
success = self.internalHistory.submit(cmd)
if success:
self.addedModItemID = self.srcCargoItemID
# Swapping with target module, or moving there if there's no module
elif srcCargo.item.isModule and not self.copy:
commit=False))
success = self.internalHistory.submitBatch(*commands)
elif srcCargo.item.isModule:
dstModItemID = dstMod.itemID
if self.srcCargoItemID == dstModItemID:
return False
newModInfo = ModuleInfo.fromModule(dstMod)
newModInfo.itemID = self.srcCargoItemID
if dstMod.isEmpty:
newCargoItemID = None
newCargoModItemID = None
newCargoChargeItemID = None
newCargoChargeAmount = None
elif dstMod.isMutated:
newCargoItemID = dstMod.baseItemID
newCargoModItemID = dstMod.baseItemID
newCargoChargeItemID = dstMod.chargeID
newCargoChargeAmount = dstMod.numCharges
else:
newCargoItemID = dstMod.itemID
newCargoModItemID = dstMod.itemID
newCargoChargeItemID = dstMod.chargeID
newCargoChargeAmount = dstMod.numCharges
commands = []
commands.append(CalcRemoveCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=self.srcCargoItemID, amount=1),
commit=False))
if newCargoItemID is not None:
if not self.copy:
commands.append(CalcRemoveCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=self.srcCargoItemID, amount=1),
commit=False))
if newCargoModItemID is not None:
commands.append(CalcAddCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=newCargoItemID, amount=1),
cargoInfo=CargoInfo(itemID=newCargoModItemID, amount=1),
commit=False))
if newCargoChargeItemID is not None:
commands.append(CalcAddCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=newCargoChargeItemID, amount=newCargoChargeAmount),
commit=False))
commands.append(CalcReplaceLocalModuleCommand(
fitID=self.fitID,

View File

@@ -110,7 +110,7 @@ class ModuleInfo:
if mod.isValidState(self.state):
mod.state = self.state
else:
mod.state = mod.getMaxState(self.state)
mod.state = mod.getMaxState(proposedState=self.state)
elif fallbackState is not None:
if mod.isValidState(fallbackState):
mod.state = fallbackState