From 99f4ed6b3350049c2a51b0992751d0103c63c8eb Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 29 Apr 2019 09:17:46 +0300 Subject: [PATCH] Allow batch change of projected fighter variations --- .../itemVariationChange.py | 22 ++++++++++---- gui/fitCommands/__init__.py | 2 +- .../calc/fighter/projectedRemove.py | 6 +++- .../{changeMeta.py => changeMetas.py} | 30 +++++++++++-------- 4 files changed, 41 insertions(+), 19 deletions(-) rename gui/fitCommands/gui/projectedFighter/{changeMeta.py => changeMetas.py} (54%) diff --git a/gui/builtinContextMenus/itemVariationChange.py b/gui/builtinContextMenus/itemVariationChange.py index a909eb998..e992bd7bc 100644 --- a/gui/builtinContextMenus/itemVariationChange.py +++ b/gui/builtinContextMenus/itemVariationChange.py @@ -276,11 +276,23 @@ class ChangeItemToVariation(ContextMenuCombined): def __handleProjectedFighter(self, varItem): fitID = self.mainFrame.getActiveFit() fit = Fit.getInstance().getFit(fitID) - fighter = self.mainItem - if fighter in fit.projectedFighters: - position = fit.projectedFighters.index(fighter) - self.mainFrame.command.Submit(cmd.GuiChangeProjectedFighterMetaCommand( - fitID=fitID, position=position, newItemID=varItem.ID)) + if wx.GetMouseState().GetModifiers() == wx.MOD_ALT: + fighters = getSimilarFighters(fit.projectedFighters, self.mainItem) + else: + fighters = self.selection + sMkt = Market.getInstance() + positions = [] + for fighter in fighters: + if fighter not in fit.projectedFighters: + continue + if fighter is self.mainItem: + positions.append(fit.projectedFighters.index(fighter)) + continue + fighterVariations = sMkt.getVariationsByItems((fighter.item,)) + if fighterVariations == self.mainVariations: + positions.append(fit.projectedFighters.index(fighter)) + self.mainFrame.command.Submit(cmd.GuiChangeProjectedFighterMetasCommand( + fitID=fitID, positions=positions, newItemID=varItem.ID)) ChangeItemToVariation.register() diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index aa83762c8..06ca2f458 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -54,7 +54,7 @@ from .gui.projectedDrone.changeMetas import GuiChangeProjectedDroneMetasCommand from .gui.projectedFighter.abilityToggleState import GuiToggleProjectedFighterAbilityStateCommand from .gui.projectedFighter.add import GuiAddProjectedFighterCommand from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand -from .gui.projectedFighter.changeMeta import GuiChangeProjectedFighterMetaCommand +from .gui.projectedFighter.changeMetas import GuiChangeProjectedFighterMetasCommand from .gui.projectedFit.add import GuiAddProjectedFitCommand from .gui.projectedFit.changeAmount import GuiChangeProjectedFitAmountCommand from .gui.projectedModule.add import GuiAddProjectedModuleCommand diff --git a/gui/fitCommands/calc/fighter/projectedRemove.py b/gui/fitCommands/calc/fighter/projectedRemove.py index 1b9ba783e..1f34af8a0 100644 --- a/gui/fitCommands/calc/fighter/projectedRemove.py +++ b/gui/fitCommands/calc/fighter/projectedRemove.py @@ -31,5 +31,9 @@ class CalcRemoveProjectedFighterCommand(wx.Command): def Undo(self): pyfalog.debug('Undoing removal of projected fighter at position {} from fit {}'.format(self.position, self.fitID)) from .projectedAdd import CalcAddProjectedFighterCommand - cmd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=self.savedFighterInfo, commit=self.commit) + cmd = CalcAddProjectedFighterCommand( + fitID=self.fitID, + fighterInfo=self.savedFighterInfo, + position=self.position, + commit=self.commit) return cmd.Do() diff --git a/gui/fitCommands/gui/projectedFighter/changeMeta.py b/gui/fitCommands/gui/projectedFighter/changeMetas.py similarity index 54% rename from gui/fitCommands/gui/projectedFighter/changeMeta.py rename to gui/fitCommands/gui/projectedFighter/changeMetas.py index 31669efb6..05ee73a84 100644 --- a/gui/fitCommands/gui/projectedFighter/changeMeta.py +++ b/gui/fitCommands/gui/projectedFighter/changeMetas.py @@ -1,5 +1,6 @@ import wx +import eos.db import gui.mainFrame from gui import globalEvents as GE from gui.fitCommands.calc.fighter.projectedAdd import CalcAddProjectedFighterCommand @@ -8,32 +9,37 @@ from gui.fitCommands.helpers import FighterInfo, InternalCommandHistory from service.fit import Fit -class GuiChangeProjectedFighterMetaCommand(wx.Command): +class GuiChangeProjectedFighterMetasCommand(wx.Command): - def __init__(self, fitID, position, newItemID): - wx.Command.__init__(self, True, 'Change Projected Fighter Meta') + def __init__(self, fitID, positions, newItemID): + wx.Command.__init__(self, True, 'Change Projected Fighter 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) - fighter = fit.projectedFighters[self.position] - if fighter.itemID == self.newItemID: - return False - info = FighterInfo.fromFighter(fighter) - info.itemID = self.newItemID - cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position) - cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info) - success = self.internalHistory.submitBatch(cmdRemove, cmdAdd) + results = [] + for position in sorted(self.positions, reverse=True): + fighter = fit.projectedFighters[position] + if fighter.itemID == self.newItemID: + continue + info = FighterInfo.fromFighter(fighter) + info.itemID = self.newItemID + cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=position, commit=False) + cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=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