Allow batch changes of projected module metas

This commit is contained in:
DarkPhoenix
2019-04-29 07:51:13 +03:00
parent dece788f66
commit 698328e335
8 changed files with 51 additions and 29 deletions

View File

@@ -239,11 +239,22 @@ class ChangeItemToVariation(ContextMenuCombined):
def __handleProjectedModule(self, varItem):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
mod = self.mainItem
if mod in fit.projectedModules:
position = fit.projectedModules.index(mod)
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleMetaCommand(
fitID=fitID, position=position, newItemID=varItem.ID))
if wx.GetMouseState().GetModifiers() == wx.MOD_ALT:
positions = getSimilarModPositions(fit.projectedModules, self.mainItem)
else:
sMkt = Market.getInstance()
positions = []
for mod in self.selection:
if mod is self.mainItem:
positions.append(fit.projectedModules.index(mod))
continue
if mod not in fit.projectedModules:
continue
modVariations = sMkt.getVariationsByItems((mod.item,))
if modVariations == self.mainVariations:
positions.append(fit.projectedModules.index(mod))
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleMetasCommand(
fitID=fitID, positions=positions, newItemID=varItem.ID))
def __handleProjectedDrone(self, varItem):
fitID = self.mainFrame.getActiveFit()

View File

@@ -59,7 +59,7 @@ from .gui.projectedFit.add import GuiAddProjectedFitCommand
from .gui.projectedFit.changeAmount import GuiChangeProjectedFitAmountCommand
from .gui.projectedModule.add import GuiAddProjectedModuleCommand
from .gui.projectedModule.changeCharges import GuiChangeProjectedModuleChargesCommand
from .gui.projectedModule.changeMeta import GuiChangeProjectedModuleMetaCommand
from .gui.projectedModule.changeMetas import GuiChangeProjectedModuleMetasCommand
from .gui.projectedModule.changeSpool import GuiChangeProjectedModuleSpoolCommand
from .gui.projectedRemove import GuiRemoveProjectedItemsCommand
from .gui.shipModeChange import GuiChangeShipModeCommand

View File

@@ -30,7 +30,8 @@ class CalcAddProjectedModuleCommand(wx.Command):
fit = Fit.getInstance().getFit(self.fitID)
if not newMod.canHaveState(newMod.state, projectedOnto=fit):
newMod.state = FittingModuleState.OFFLINE
if not newMod.isValidCharge(newMod.charge):
newMod.charge = None
self.oldPosition, self.oldModInfo = fit.projectedModules.makeRoom(newMod)
if self.newPosition is not None:

View File

@@ -18,14 +18,14 @@ class GuiRemoveCargosCommand(wx.Command):
self.itemIDs = itemIDs
def Do(self):
result = []
results = []
for itemID in self.itemIDs:
cmd = CalcRemoveCargoCommand(
fitID=self.fitID,
cargoInfo=CargoInfo(itemID=itemID, amount=math.inf),
commit=False)
result.append(self.internalHistory.submit(cmd))
success = any(result)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -23,7 +23,7 @@ class GuiChangeLocalDroneMetasCommand(wx.Command):
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
result = []
results = []
for position in sorted(self.positions, reverse=True):
drone = fit.drones[position]
if drone.itemID == self.newItemID:
@@ -40,8 +40,8 @@ class GuiChangeLocalDroneMetasCommand(wx.Command):
droneInfo=info,
forceNewStack=True,
commit=False)
result.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(result)
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))

View File

@@ -21,7 +21,7 @@ class GuiChangeLocalFighterMetasCommand(wx.Command):
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
result = []
results = []
for position in sorted(self.positions, reverse=True):
fighter = fit.fighters[position]
if fighter.itemID == self.newItemID:
@@ -36,8 +36,8 @@ class GuiChangeLocalFighterMetasCommand(wx.Command):
fitID=self.fitID,
fighterInfo=info,
commit=False)
result.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(result)
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))

View File

@@ -33,7 +33,11 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
info = ModuleInfo.fromModule(module)
info.itemID = self.newItemID
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID, position=position, newModInfo=info, unloadInvalidCharges=True, commit=False)
fitID=self.fitID,
position=position,
newModInfo=info,
unloadInvalidCharges=True,
commit=False)
commands.append(cmd)
if not commands:
return False

View File

@@ -1,5 +1,6 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.projectedAdd import CalcAddProjectedModuleCommand
@@ -8,32 +9,37 @@ from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiChangeProjectedModuleMetaCommand(wx.Command):
class GuiChangeProjectedModuleMetasCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Projected Module Meta')
def __init__(self, fitID, positions, newItemID):
wx.Command.__init__(self, True, 'Change Projected Module Metas')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.positions = positions
self.newItemID = newItemID
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
module = fit.projectedModules[self.position]
if module.itemID == self.newItemID:
return
info = ModuleInfo.fromModule(module)
info.itemID = self.newItemID
cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
results = []
for position in sorted(self.positions, reverse=True):
module = fit.projectedModules[position]
if module.itemID == self.newItemID:
continue
info = ModuleInfo.fromModule(module)
info.itemID = self.newItemID
cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=position, commit=False)
cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=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