Allow batch changes of projected drone variations
This commit is contained in:
@@ -215,7 +215,7 @@ class ChangeItemToVariation(ContextMenuCombined):
|
||||
cargoVariations = sMkt.getVariationsByItems((cargo.item,))
|
||||
if cargoVariations == self.mainVariations:
|
||||
itemIDs.append(cargo.itemID)
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoMetaCommand(
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeCargoMetasCommand(
|
||||
fitID=fitID, itemIDs=itemIDs, newItemID=varItem.ID))
|
||||
|
||||
def __handleImplant(self, varItem):
|
||||
@@ -258,9 +258,20 @@ class ChangeItemToVariation(ContextMenuCombined):
|
||||
|
||||
def __handleProjectedDrone(self, varItem):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
drone = self.mainItem
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneMetaCommand(
|
||||
fitID=fitID, itemID=drone.itemID, newItemID=varItem.ID))
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
sMkt = Market.getInstance()
|
||||
itemIDs = []
|
||||
for drone in self.selection:
|
||||
if drone not in fit.projectedDrones:
|
||||
continue
|
||||
if drone is self.mainItem:
|
||||
itemIDs.append(drone.itemID)
|
||||
continue
|
||||
droneVariations = sMkt.getVariationsByItems((drone.item,))
|
||||
if droneVariations == self.mainVariations:
|
||||
itemIDs.append(drone.itemID)
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneMetasCommand(
|
||||
fitID=fitID, itemIDs=itemIDs, newItemID=varItem.ID))
|
||||
|
||||
def __handleProjectedFighter(self, varItem):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
|
||||
@@ -5,7 +5,7 @@ from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCo
|
||||
from .gui.booster.toggleStates import GuiToggleBoosterStatesCommand
|
||||
from .gui.cargo.add import GuiAddCargoCommand
|
||||
from .gui.cargo.changeAmount import GuiChangeCargoAmountCommand
|
||||
from .gui.cargo.changeMeta import GuiChangeCargoMetaCommand
|
||||
from .gui.cargo.changeMetas import GuiChangeCargoMetasCommand
|
||||
from .gui.cargo.remove import GuiRemoveCargosCommand
|
||||
from .gui.commandFit.add import GuiAddCommandFitCommand
|
||||
from .gui.commandFit.remove import GuiRemoveCommandFitsCommand
|
||||
@@ -50,7 +50,7 @@ from .gui.localModuleCargo.localModuleToCargo import GuiLocalModuleToCargoComman
|
||||
from .gui.projectedChangeStates import GuiChangeProjectedItemStatesCommand
|
||||
from .gui.projectedDrone.add import GuiAddProjectedDroneCommand
|
||||
from .gui.projectedDrone.changeAmount import GuiChangeProjectedDroneAmountCommand
|
||||
from .gui.projectedDrone.changeMeta import GuiChangeProjectedDroneMetaCommand
|
||||
from .gui.projectedDrone.changeMetas import GuiChangeProjectedDroneMetasCommand
|
||||
from .gui.projectedFighter.abilityToggleState import GuiToggleProjectedFighterAbilityStateCommand
|
||||
from .gui.projectedFighter.add import GuiAddProjectedFighterCommand
|
||||
from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand
|
||||
|
||||
@@ -10,10 +10,10 @@ from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiChangeCargoMetaCommand(wx.Command):
|
||||
class GuiChangeCargoMetasCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemIDs, newItemID):
|
||||
wx.Command.__init__(self, True, 'Change Cargo Meta')
|
||||
wx.Command.__init__(self, True, 'Change Cargo Metas')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemIDs = itemIDs
|
||||
@@ -2,6 +2,7 @@ import math
|
||||
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.projectedAdd import CalcAddProjectedDroneCommand
|
||||
@@ -10,34 +11,39 @@ from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiChangeProjectedDroneMetaCommand(wx.Command):
|
||||
class GuiChangeProjectedDroneMetasCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, newItemID):
|
||||
wx.Command.__init__(self, True, 'Change Projected Drone Meta')
|
||||
def __init__(self, fitID, itemIDs, newItemID):
|
||||
wx.Command.__init__(self, True, 'Change Projected Drone Metas')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.itemIDs = itemIDs
|
||||
self.newItemID = newItemID
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
|
||||
if drone is None:
|
||||
return False
|
||||
if drone.itemID == self.newItemID:
|
||||
return False
|
||||
info = DroneInfo.fromDrone(drone)
|
||||
info.itemID = self.newItemID
|
||||
cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=math.inf)
|
||||
cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
|
||||
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
|
||||
results = []
|
||||
for itemID in self.itemIDs:
|
||||
drone = next((pd for pd in fit.projectedDrones if pd.itemID == itemID), None)
|
||||
if drone is None:
|
||||
continue
|
||||
if drone.itemID == self.newItemID:
|
||||
continue
|
||||
info = DroneInfo.fromDrone(drone)
|
||||
info.itemID = self.newItemID
|
||||
cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=itemID, amount=math.inf, commit=False)
|
||||
cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info, commit=False)
|
||||
results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
|
||||
success = any(results)
|
||||
eos.db.commit()
|
||||
sFit.recalc(fit)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
Reference in New Issue
Block a user