Re-add merge functionality
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
53
gui/fitCommands/gui/localDrone/stacksMerge.py
Normal file
53
gui/fitCommands/gui/localDrone/stacksMerge.py
Normal file
@@ -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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user