From 98e834fd30a7e47ccc60588f1c2dfe2455acf3a7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 16 Apr 2019 17:23:25 +0300 Subject: [PATCH] Re-add merge functionality --- gui/builtinAdditionPanes/droneView.py | 23 ++++---- gui/builtinAdditionPanes/projectedView.py | 14 ----- gui/fitCommands/__init__.py | 3 +- .../calc/drone/localChangeAmount.py | 9 ++-- .../{splitStack.py => stackSplit.py} | 0 gui/fitCommands/gui/localDrone/stacksMerge.py | 53 +++++++++++++++++++ service/fitDeprecated.py | 27 ---------- 7 files changed, 72 insertions(+), 57 deletions(-) rename gui/fitCommands/gui/localDrone/{splitStack.py => stackSplit.py} (100%) create mode 100644 gui/fitCommands/gui/localDrone/stacksMerge.py diff --git a/gui/builtinAdditionPanes/droneView.py b/gui/builtinAdditionPanes/droneView.py index 976219fb9..ee5b2a7cf 100644 --- a/gui/builtinAdditionPanes/droneView.py +++ b/gui/builtinAdditionPanes/droneView.py @@ -144,22 +144,21 @@ class DroneView(Display): data[0] is hard-coded str of originating source data[1] is typeID or index of data we want to manipulate """ - if data[0] == "drone": # we want to merge drones - pass - # remove merge functionality, if people complain in the next while, can add it back - # srcRow = int(data[1]) - # dstRow, _ = self.HitTest((x, y)) - # if srcRow != -1 and dstRow != -1: - # self._merge(srcRow, dstRow) + if data[0] == "drone": + srcRow = int(data[1]) + dstRow, _ = self.HitTest((x, y)) + if srcRow != -1 and dstRow != -1: + self._merge(srcRow, dstRow) elif data[0] == "market": wx.PostEvent(self.mainFrame, ItemSelected(itemID=int(data[1]))) - def _merge(self, src, dst): - sFit = Fit.getInstance() + def _merge(self, srcRow, dstRow): fitID = self.mainFrame.getActiveFit() - - if sFit.mergeDrones(fitID, self.drones[src], self.drones[dst]): - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + fit = Fit.getInstance().getFit(fitID) + self.mainFrame.command.Submit(cmd.GuiMergeLocalDroneStacksCommand( + fitID=fitID, + srcPosition=fit.drones.index(self.drones[srcRow]), + dstPosition=fit.drones.index(self.drones[dstRow]))) DRONE_ORDER = ('Light Scout Drones', 'Medium Scout Drones', 'Heavy Attack Drones', 'Sentry Drones', 'Combat Utility Drones', diff --git a/gui/builtinAdditionPanes/projectedView.py b/gui/builtinAdditionPanes/projectedView.py index 69d2ae419..5db0885c7 100644 --- a/gui/builtinAdditionPanes/projectedView.py +++ b/gui/builtinAdditionPanes/projectedView.py @@ -155,20 +155,6 @@ class ProjectedView(d.Display): DragDropHelper.data = dataStr dropSource.DoDragDrop() - def mergeDrones(self, x, y, itemID): - srcRow = self.FindItemData(-1, itemID) - dstRow, _ = self.HitTest((x, y)) - if srcRow != -1 and dstRow != -1: - self._merge(srcRow, dstRow) - - def _merge(self, src, dst): - dstDrone = self.get(dst) - if isinstance(dstDrone, es_Drone): - sFit = Fit.getInstance() - fitID = self.mainFrame.getActiveFit() - if sFit.mergeDrones(fitID, self.get(src), dstDrone, True): - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) - @staticmethod def moduleSort(module): return not module.isExclusiveSystemEffect, module.item.name diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 89557f65e..fa246e808 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -22,7 +22,8 @@ from .gui.localDrone.add import GuiAddLocalDroneCommand from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand from .gui.localDrone.changeMeta import GuiChangeLocalDroneMetaCommand from .gui.localDrone.remove import GuiRemoveLocalDroneCommand -from .gui.localDrone.splitStack import GuiSplitLocalDroneStackCommand +from .gui.localDrone.stackSplit import GuiSplitLocalDroneStackCommand +from .gui.localDrone.stacksMerge import GuiMergeLocalDroneStacksCommand from .gui.localDrone.toggleState import GuiToggleLocalDroneStateCommand from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilityStateCommand from .gui.localFighter.add import GuiAddLocalFighterCommand diff --git a/gui/fitCommands/calc/drone/localChangeAmount.py b/gui/fitCommands/calc/drone/localChangeAmount.py index 471c68b12..3458dbee7 100644 --- a/gui/fitCommands/calc/drone/localChangeAmount.py +++ b/gui/fitCommands/calc/drone/localChangeAmount.py @@ -13,11 +13,12 @@ pyfalog = Logger(__name__) class CalcChangeLocalDroneAmountCommand(wx.Command): - def __init__(self, fitID, position, amount): + def __init__(self, fitID, position, amount, commit=True): wx.Command.__init__(self, True, 'Change Drone Amount') self.fitID = fitID self.position = position self.amount = amount + self.commit = commit self.savedDroneInfo = None def Do(self): @@ -32,7 +33,8 @@ class CalcChangeLocalDroneAmountCommand(wx.Command): difference = self.amount - self.savedDroneInfo.amount drone.amount = self.amount drone.amountActive = max(min(drone.amountActive + difference, drone.amount), 0) - eos.db.commit() + if self.commit: + eos.db.commit() return True def Undo(self): @@ -42,6 +44,7 @@ class CalcChangeLocalDroneAmountCommand(wx.Command): drone = fit.drones[self.position] drone.amount = self.savedDroneInfo.amount drone.amountActive = self.savedDroneInfo.amountActive - eos.db.commit() + if self.commit: + eos.db.commit() return True return False diff --git a/gui/fitCommands/gui/localDrone/splitStack.py b/gui/fitCommands/gui/localDrone/stackSplit.py similarity index 100% rename from gui/fitCommands/gui/localDrone/splitStack.py rename to gui/fitCommands/gui/localDrone/stackSplit.py diff --git a/gui/fitCommands/gui/localDrone/stacksMerge.py b/gui/fitCommands/gui/localDrone/stacksMerge.py new file mode 100644 index 000000000..0677fdb2a --- /dev/null +++ b/gui/fitCommands/gui/localDrone/stacksMerge.py @@ -0,0 +1,53 @@ +import wx + +import eos.db +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.drone.localChangeAmount import CalcChangeLocalDroneAmountCommand +from gui.fitCommands.calc.drone.localRemove import CalcRemoveLocalDroneCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit + + +class GuiMergeLocalDroneStacksCommand(wx.Command): + + def __init__(self, fitID, srcPosition, dstPosition): + wx.Command.__init__(self, True, 'Merge Local Drone Stacks') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.srcPosition = srcPosition + self.dstPosition = dstPosition + + def Do(self): + if self.srcPosition == self.dstPosition: + return False + sFit = Fit.getInstance() + fit = sFit.getFit(self.fitID) + srcDrone = fit.drones[self.srcPosition] + dstDrone = fit.drones[self.dstPosition] + if srcDrone.itemID != dstDrone.itemID: + return False + srcAmount = srcDrone.amount + commands = [] + commands.append(CalcChangeLocalDroneAmountCommand( + fitID=self.fitID, + position=self.dstPosition, + amount=dstDrone.amount + srcAmount, + commit=False)) + commands.append(CalcRemoveLocalDroneCommand( + fitID=self.fitID, + position=self.srcPosition, + amount=srcAmount, + commit=False)) + success = self.internalHistory.submitBatch(*commands) + 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 diff --git a/service/fitDeprecated.py b/service/fitDeprecated.py index b3903d88d..fee1783e7 100644 --- a/service/fitDeprecated.py +++ b/service/fitDeprecated.py @@ -71,33 +71,6 @@ class FitDeprecated(object): self.recalc(fit) return True - @deprecated - def mergeDrones(self, fitID, d1, d2, projected=False): - pyfalog.debug("Merging drones on fit ID: {0}", fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - if d1.item != d2.item: - return False - - if projected: - fit.projectedDrones.remove(d1) - else: - fit.drones.remove(d1) - - d2.amount += d1.amount - d2.amountActive += d1.amountActive - - # If we have less than the total number of drones active, make them all active. Fixes #728 - # This could be removed if we ever add an enhancement to make drone stacks partially active. - if d2.amount > d2.amountActive: - d2.amountActive = d2.amount - - eos.db.commit() - self.recalc(fit) - return True - @deprecated def removeDrone(self, fitID, i, numDronesToRemove=1, recalc=True): pyfalog.debug("Removing {0} drones for fit ID: {1}", numDronesToRemove, fitID)