working commit
This commit is contained in:
@@ -29,7 +29,7 @@ from gui.contextMenu import ContextMenu
|
||||
from gui.utils.staticHelpers import DragDropHelper
|
||||
from service.fit import Fit
|
||||
from service.market import Market
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
|
||||
class DroneViewDrop(wx.DropTarget):
|
||||
def __init__(self, dropFn, *args, **kwargs):
|
||||
@@ -213,9 +213,7 @@ class DroneView(Display):
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
trigger = sFit.addDrone(fitID, event.itemID)
|
||||
if trigger:
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
if self.mainFrame.command.Submit(cmd.GuiAddDroneCommand(fitID, event.itemID)):
|
||||
self.mainFrame.additionsPane.select("Drones")
|
||||
|
||||
event.Skip()
|
||||
|
||||
@@ -22,4 +22,5 @@ from .guiRemoveFighter import GuiRemoveFighterCommand
|
||||
from .guiMetaSwap import GuiMetaSwapCommand
|
||||
from .guiToggleFighter import GuiToggleFighterCommand
|
||||
from .guiToggleImplant import GuiToggleImplantCommand
|
||||
from .guiToggleBooster import GuiToggleImplantCommand
|
||||
from .guiToggleBooster import GuiToggleImplantCommand
|
||||
from .guiAddDrone import GuiAddDroneCommand
|
||||
53
gui/fitCommands/calc/fitAddDrone.py
Normal file
53
gui/fitCommands/calc/fitAddDrone.py
Normal file
@@ -0,0 +1,53 @@
|
||||
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__)
|
||||
from eos.saveddata.drone import Drone
|
||||
|
||||
class FitAddDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addDrone
|
||||
"""
|
||||
def __init__(self, fitID, itemID, amount=1, replace=False):
|
||||
wx.Command.__init__(self, True, "Drone add")
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.amount = amount # add x amount. If this goes over amount, removes stack
|
||||
self.replace = replace # if this is false, we increment.
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding {0} drones ({1}) to fit ID: {2}", self.amount, self.itemID, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager=("attributes", "group.category"))
|
||||
|
||||
for d in fit.drones.find(item):
|
||||
if d is not None and d.amountActive == 0 and d.amount < max(5, fit.extraAttributes["maxActiveDrones"]):
|
||||
drone = d
|
||||
break
|
||||
else:
|
||||
try:
|
||||
drone = Drone(item)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid drone: {}", item)
|
||||
return False
|
||||
|
||||
if not drone.fits(fit):
|
||||
return False
|
||||
fit.drones.append(drone)
|
||||
|
||||
drone.amount += self.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitRemoveCargo import FitRemoveCargoCommand # Avoid circular import
|
||||
cmd = FitRemoveCargoCommand(self.fitID, self.itemID, self.amount)
|
||||
cmd.Do()
|
||||
return True
|
||||
30
gui/fitCommands/guiAddDrone.py
Normal file
30
gui/fitCommands/guiAddDrone.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.fitAddDrone import FitAddDroneCommand
|
||||
|
||||
class GuiAddDroneCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Cargo Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
cmd = FitAddDroneCommand(self.fitID, self.itemID)
|
||||
if self.internal_history.Submit(cmd):
|
||||
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()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -37,6 +37,7 @@ from eos.saveddata.fit import Fit as FitType, ImplantLocation
|
||||
from service.character import Character
|
||||
from service.damagePattern import DamagePattern
|
||||
from service.settings import SettingsProvider
|
||||
from utils.deprecated import deprecated
|
||||
import wx
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -427,6 +428,7 @@ class Fit(FitDeprecated):
|
||||
else:
|
||||
return None
|
||||
|
||||
@deprecated
|
||||
def addDrone(self, fitID, itemID, numDronesToAdd=1, recalc=True):
|
||||
pyfalog.debug("Adding {0} drones ({1}) to fit ID: {2}", numDronesToAdd, itemID, fitID)
|
||||
if fitID is None:
|
||||
|
||||
@@ -35,6 +35,34 @@ pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitDeprecated(object):
|
||||
@deprecated
|
||||
def addDrone(self, fitID, itemID, numDronesToAdd=1, recalc=True):
|
||||
pyfalog.debug("Adding {0} drones ({1}) to fit ID: {2}", numDronesToAdd, itemID, fitID)
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if item.category.name == "Drone":
|
||||
drone = None
|
||||
for d in fit.drones.find(item):
|
||||
if d is not None and d.amountActive == 0 and d.amount < max(5, fit.extraAttributes["maxActiveDrones"]):
|
||||
drone = d
|
||||
break
|
||||
|
||||
if drone is None:
|
||||
drone = es_Drone(item)
|
||||
if drone.fits(fit) is True:
|
||||
fit.drones.append(drone)
|
||||
else:
|
||||
return False
|
||||
drone.amount += numDronesToAdd
|
||||
eos.db.commit()
|
||||
if recalc:
|
||||
self.recalc(fit)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@deprecated
|
||||
def addImplant(self, fitID, itemID, recalc=True):
|
||||
|
||||
Reference in New Issue
Block a user