Implement merging of drone stacks via drag'n'drop

This commit is contained in:
cncfanatics
2010-11-02 13:41:42 +01:00
parent 2d01d664c5
commit 412ee42e06
3 changed files with 69 additions and 14 deletions

View File

@@ -26,6 +26,19 @@ import gui.display as d
from gui.builtinViewColumns.droneCheckbox import DroneCheckbox
from gui.contextMenu import ContextMenu
class DroneViewDrop(wx.PyDropTarget):
def __init__(self, dropFn):
wx.PyDropTarget.__init__(self)
self.dropFn = dropFn
# this is really transferring an EvE itemID
self.dropData = wx.PyTextDataObject()
self.SetDataObject(self.dropData)
def OnData(self, x, y, t):
if self.GetData():
self.dropFn(x, y, int(self.dropData.GetText()))
return t
class DroneView(d.Display):
DEFAULT_COLS = ["Drone Checkbox",
"Drone Name/Amount",
@@ -45,6 +58,32 @@ class DroneView(d.Display):
else:
self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu)
self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.startDrag)
self.SetDropTarget(DroneViewDrop(self.mergeDrones))
def startDrag(self, event):
row = event.GetIndex()
if row != -1:
data = wx.PyTextDataObject()
data.SetText(str(self.GetItemData(row)))
dropSource = wx.DropSource(self)
dropSource.SetData(data)
res = 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):
sFit = service.Fit.getInstance()
fitID = self.mainFrame.getActiveFit()
if sFit.mergeDrones(fitID, self.drones[src], self.drones[dst]):
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
DRONE_ORDER = ('Light Scout Drones', 'Medium Scout Drones',
'Heavy Attack Drones', 'Sentry Drones', 'Fighters',
'Fighter Bombers', 'Combat Utility Drones',

View File

@@ -29,6 +29,19 @@ from gui.builtinViewColumns.moduleState import ModuleState
FitChanged, FIT_CHANGED = wx.lib.newevent.NewEvent()
class FittingViewDrop(wx.PyDropTarget):
def __init__(self, dropFn):
wx.PyDropTarget.__init__(self)
self.dropFn = dropFn
# this is really transferring an EvE itemID
self.dropData = wx.PyTextDataObject()
self.SetDataObject(self.dropData)
def OnData(self, x, y, t):
if self.GetData():
self.dropFn(x, y, int(self.dropData.GetText()))
return t
class FittingView(d.Display):
DEFAULT_COLS = ["Module State",
"Module Ammo Icon",
@@ -42,19 +55,6 @@ class FittingView(d.Display):
"Module Ammo",
]
class FittingViewDrop(wx.PyDropTarget):
def __init__(self, dropFn):
wx.PyDropTarget.__init__(self)
self.dropFn = dropFn
# this is really transferring an EvE itemID
self.dropData = wx.PyTextDataObject()
self.SetDataObject(self.dropData)
def OnData(self, x, y, t):
if self.GetData():
self.dropFn(x, y, int(self.dropData.GetText()))
return t
def __init__(self, parent):
d.Display.__init__(self, parent)
self.Show(False)
@@ -66,7 +66,7 @@ class FittingView(d.Display):
else:
self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu)
self.SetDropTarget(self.FittingViewDrop(self.swapItems))
self.SetDropTarget(FittingViewDrop(self.swapItems))
self.activeFitID = None
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
self.Bind(wx.EVT_LEFT_DOWN, self.click)

View File

@@ -304,6 +304,22 @@ class Fit(object):
else:
return False
def mergeDrones(self, fitID, d1, d2):
if fitID == None:
return False
fit = eos.db.getFit(fitID)
if d1.item != d2.item:
return False
fit.drones.remove(d1)
d2.amount += d1.amount
d2.amountActive += d1.amountActive if d1.amountActive > 0 else -d2.amountActive
eos.db.commit()
fit.clear()
fit.calculateModifiedAttributes()
return True
def splitDrones(self, fit, d, amount, l):
total = d.amount
active = d.amountActive > 0