Add ability to clone drones by ctrl-dragging them

This commit is contained in:
DarkPhoenix
2019-04-30 16:16:09 +03:00
parent 4b65662c9f
commit 5a9fd188f0
3 changed files with 55 additions and 3 deletions

View File

@@ -155,9 +155,21 @@ class DroneView(Display):
"""
if data[0] == "drone":
srcRow = int(data[1])
dstRow, _ = self.HitTest((x, y))
if srcRow != -1 and dstRow != -1:
self._merge(srcRow, dstRow)
if srcRow != -1:
if wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL:
try:
srcDrone = self.drones[srcRow]
except IndexError:
return
if srcDrone not in self.original:
return
self.mainFrame.command.Submit(cmd.GuiCloneLocalDroneCommand(
fitID=self.mainFrame.getActiveFit(),
position=self.original.index(srcDrone)))
else:
dstRow, _ = self.HitTest((x, y))
if dstRow != -1:
self._merge(srcRow, dstRow)
elif data[0] == "market":
wx.PostEvent(self.mainFrame, ItemSelected(itemID=int(data[1])))

View File

@@ -22,6 +22,7 @@ from .gui.itemsRebase import GuiRebaseItemsCommand
from .gui.localDrone.add import GuiAddLocalDroneCommand
from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand
from .gui.localDrone.changeMetas import GuiChangeLocalDroneMetasCommand
from .gui.localDrone.clone import GuiCloneLocalDroneCommand
from .gui.localDrone.remove import GuiRemoveLocalDronesCommand
from .gui.localDrone.stackSplit import GuiSplitLocalDroneStackCommand
from .gui.localDrone.stacksMerge import GuiMergeLocalDroneStacksCommand

View File

@@ -0,0 +1,39 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.drone.localAdd import CalcAddLocalDroneCommand
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
from service.fit import Fit
class GuiCloneLocalDroneCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Clone Local Drone')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
try:
drone = fit.drones[self.position]
except IndexError:
return False
info = DroneInfo.fromDrone(drone)
cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True)
success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success