Implement drone toggle command
This commit is contained in:
@@ -239,10 +239,8 @@ class DroneView(Display):
|
||||
col = self.getColumn(event.Position)
|
||||
if col == self.getColIndex(State):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
sFit = Fit.getInstance()
|
||||
drone = self.drones[row]
|
||||
sFit.toggleDrone(fitID, self.original.index(drone))
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleDroneCommand(fitID, self.original.index(drone)))
|
||||
|
||||
def scheduleMenu(self, event):
|
||||
event.Skip()
|
||||
|
||||
@@ -29,4 +29,5 @@ from .guiChangeFighterQty import GuiChangeFighterQty
|
||||
from .guiChangeCargoQty import GuiChangeCargoQty
|
||||
from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
|
||||
from .guiChangeDroneQty import GuiChangeDroneQty
|
||||
from.guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiToggleDrone import GuiToggleDroneCommand
|
||||
35
gui/fitCommands/calc/fitToggleDrone.py
Normal file
35
gui/fitCommands/calc/fitToggleDrone.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
class FitToggleDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.toggleDrone
|
||||
"""
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "Cargo add")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Toggling drones for fit ID: {0}", self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
d = fit.drones[self.position]
|
||||
if d.amount == d.amountActive:
|
||||
d.amountActive = 0
|
||||
else:
|
||||
d.amountActive = d.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
cmd = FitToggleDroneCommand(self.fitID, self.position)
|
||||
return cmd.Do()
|
||||
30
gui/fitCommands/guiToggleDrone.py
Normal file
30
gui/fitCommands/guiToggleDrone.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calc.fitToggleDrone import FitToggleDroneCommand
|
||||
|
||||
class GuiToggleDroneCommand(wx.Command):
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitToggleDroneCommand(self.fitID, self.position)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -438,92 +438,6 @@ class Fit(FitDeprecated):
|
||||
else:
|
||||
return False
|
||||
|
||||
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
|
||||
|
||||
@staticmethod
|
||||
def splitDrones(fit, d, amount, l):
|
||||
pyfalog.debug("Splitting drones for fit ID: {0}", fit)
|
||||
total = d.amount
|
||||
active = d.amountActive > 0
|
||||
d.amount = amount
|
||||
d.amountActive = amount if active else 0
|
||||
|
||||
newD = es_Drone(d.item)
|
||||
newD.amount = total - amount
|
||||
newD.amountActive = newD.amount if active else 0
|
||||
l.append(newD)
|
||||
eos.db.commit()
|
||||
|
||||
def splitProjectedDroneStack(self, fitID, d, amount):
|
||||
pyfalog.debug("Splitting projected drone stack for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
self.splitDrones(fit, d, amount, fit.projectedDrones)
|
||||
|
||||
def splitDroneStack(self, fitID, d, amount):
|
||||
pyfalog.debug("Splitting drone stack for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
self.splitDrones(fit, d, amount, fit.drones)
|
||||
|
||||
@deprecated
|
||||
def removeDrone(self, fitID, i, numDronesToRemove=1, recalc=True):
|
||||
pyfalog.debug("Removing {0} drones for fit ID: {1}", numDronesToRemove, fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
d.amount -= numDronesToRemove
|
||||
if d.amountActive > 0:
|
||||
d.amountActive -= numDronesToRemove
|
||||
|
||||
if d.amount == 0:
|
||||
del fit.drones[i]
|
||||
|
||||
eos.db.commit()
|
||||
if recalc:
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def toggleDrone(self, fitID, i):
|
||||
pyfalog.debug("Toggling drones for fit ID: {0}", fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
if d.amount == d.amountActive:
|
||||
d.amountActive = 0
|
||||
else:
|
||||
d.amountActive = d.amount
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def toggleImplantSource(self, fitID, source):
|
||||
pyfalog.debug("Toggling implant source for fit ID: {0}", fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
|
||||
@@ -36,6 +36,97 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class FitDeprecated(object):
|
||||
|
||||
@deprecated
|
||||
def toggleDrone(self, fitID, i):
|
||||
pyfalog.debug("Toggling drones for fit ID: {0}", fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
if d.amount == d.amountActive:
|
||||
d.amountActive = 0
|
||||
else:
|
||||
d.amountActive = d.amount
|
||||
|
||||
eos.db.commit()
|
||||
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
|
||||
|
||||
@staticmethod
|
||||
@deprecated
|
||||
def splitDrones(fit, d, amount, l):
|
||||
pyfalog.debug("Splitting drones for fit ID: {0}", fit)
|
||||
total = d.amount
|
||||
active = d.amountActive > 0
|
||||
d.amount = amount
|
||||
d.amountActive = amount if active else 0
|
||||
|
||||
newD = es_Drone(d.item)
|
||||
newD.amount = total - amount
|
||||
newD.amountActive = newD.amount if active else 0
|
||||
l.append(newD)
|
||||
eos.db.commit()
|
||||
|
||||
@deprecated
|
||||
def splitProjectedDroneStack(self, fitID, d, amount):
|
||||
pyfalog.debug("Splitting projected drone stack for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
self.splitDrones(fit, d, amount, fit.projectedDrones)
|
||||
|
||||
@deprecated
|
||||
def splitDroneStack(self, fitID, d, amount):
|
||||
pyfalog.debug("Splitting drone stack for fit ID: {0}", fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
self.splitDrones(fit, d, amount, fit.drones)
|
||||
|
||||
@deprecated
|
||||
def removeDrone(self, fitID, i, numDronesToRemove=1, recalc=True):
|
||||
pyfalog.debug("Removing {0} drones for fit ID: {1}", numDronesToRemove, fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
d.amount -= numDronesToRemove
|
||||
if d.amountActive > 0:
|
||||
d.amountActive -= numDronesToRemove
|
||||
|
||||
if d.amount == 0:
|
||||
del fit.drones[i]
|
||||
|
||||
eos.db.commit()
|
||||
if recalc:
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
@deprecated
|
||||
def changeAmount(self, fitID, projected_fit, amount):
|
||||
"""Change amount of projected fits"""
|
||||
|
||||
Reference in New Issue
Block a user