Allow splitting drone stacks again
This commit is contained in:
@@ -3,7 +3,7 @@ import re
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
import gui.globalEvents as GE
|
||||
import gui.fitCommands as cmd
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenu
|
||||
from service.fit import Fit
|
||||
@@ -34,37 +34,21 @@ class DroneSplit(ContextMenu):
|
||||
if dlg.input.GetLineText(0).strip() == '':
|
||||
return
|
||||
|
||||
sFit = Fit.getInstance()
|
||||
cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())
|
||||
|
||||
if srcContext == "droneItem":
|
||||
sFit.splitDroneStack(fitID, drone, int(float(cleanInput)))
|
||||
else:
|
||||
sFit.splitProjectedDroneStack(fitID, drone, int(float(cleanInput)))
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
# if isinstance(thing, es_Cargo):
|
||||
# self.mainFrame.command.Submit(
|
||||
# cmd.GuiAddCargoCommand(fitID, thing.item.ID, int(float(cleanInput)), replace=True))
|
||||
# return # no need for post event here
|
||||
# elif isinstance(thing, es_Fit):
|
||||
# sFit.changeAmount(fitID, thing, int(float(cleanInput)))
|
||||
# elif isinstance(thing, es_Fighter):
|
||||
# sFit.changeActiveFighters(fitID, thing, int(float(cleanInput)))
|
||||
#
|
||||
# wx.PostEvent(mainFrame, GE.FitChanged(fitID=fitID))
|
||||
#
|
||||
# dlg = DroneSpinner(self.mainFrame, selection[0], srcContext)
|
||||
# dlg.ShowModal()
|
||||
# dlg.Destroy()
|
||||
self.mainFrame.command.Submit(cmd.GuiSplitLocalDroneStackCommand(
|
||||
fitID=fitID,
|
||||
position=fit.drones.index(drone),
|
||||
amount=int(cleanInput)))
|
||||
|
||||
|
||||
DroneSplit.register()
|
||||
|
||||
|
||||
class DroneStackSplit(wx.Dialog):
|
||||
|
||||
def __init__(self, parent, value):
|
||||
wx.Dialog.__init__(self, parent, title="Split Drone Stack")
|
||||
self.SetMinSize((346, 156))
|
||||
@@ -111,37 +95,3 @@ class DroneStackSplit(wx.Dialog):
|
||||
return
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class DroneSpinner(wx.Dialog):
|
||||
def __init__(self, parent, drone, context):
|
||||
wx.Dialog.__init__(self, parent, title="Select Amount", size=wx.Size(220, 60))
|
||||
self.drone = drone
|
||||
self.context = context
|
||||
|
||||
bSizer1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
self.spinner = wx.SpinCtrl(self)
|
||||
self.spinner.SetRange(1, drone.amount - 1)
|
||||
self.spinner.SetValue(1)
|
||||
|
||||
bSizer1.Add(self.spinner, 1, wx.ALL, 5)
|
||||
|
||||
self.button = wx.Button(self, wx.ID_OK, "Split")
|
||||
bSizer1.Add(self.button, 0, wx.ALL, 5)
|
||||
|
||||
self.SetSizer(bSizer1)
|
||||
self.Layout()
|
||||
self.Centre(wx.BOTH)
|
||||
self.button.Bind(wx.EVT_BUTTON, self.split)
|
||||
|
||||
def split(self, event):
|
||||
sFit = Fit.getInstance()
|
||||
mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
fitID = mainFrame.getActiveFit()
|
||||
if self.context == "droneItem":
|
||||
sFit.splitDroneStack(fitID, self.drone, self.spinner.GetValue())
|
||||
else:
|
||||
sFit.splitProjectedDroneStack(fitID, self.drone, self.spinner.GetValue())
|
||||
wx.PostEvent(mainFrame, GE.FitChanged(fitID=fitID))
|
||||
event.Skip()
|
||||
|
||||
@@ -211,7 +211,7 @@ from gui.builtinContextMenus import ( # noqa: E402,F401
|
||||
itemStats,
|
||||
damagePattern,
|
||||
marketJump,
|
||||
# droneSplit,
|
||||
droneSplit,
|
||||
itemRemove,
|
||||
fillWithModule,
|
||||
droneRemoveStack,
|
||||
|
||||
@@ -22,6 +22,7 @@ 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.toggleState import GuiToggleLocalDroneStateCommand
|
||||
from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilityStateCommand
|
||||
from .gui.localFighter.add import GuiAddLocalFighterCommand
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import wx
|
||||
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
@@ -13,13 +14,14 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcAddLocalDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, droneInfo, forceNewStack=False):
|
||||
def __init__(self, fitID, droneInfo, forceNewStack=False, commit=True):
|
||||
wx.Command.__init__(self, True, 'Add Drone')
|
||||
self.fitID = fitID
|
||||
self.droneInfo = droneInfo
|
||||
self.forceNewStack = forceNewStack
|
||||
self.commit = commit
|
||||
self.savedDroneInfo = None
|
||||
self.savedPosition = None
|
||||
self.forceNewStack = forceNewStack
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of local drone {} to fit {}'.format(self.droneInfo, self.fitID))
|
||||
@@ -36,7 +38,8 @@ class CalcAddLocalDroneCommand(wx.Command):
|
||||
self.savedDroneInfo = DroneInfo.fromDrone(drone)
|
||||
self.savedPosition = fit.drones.index(drone)
|
||||
drone.amount += self.droneInfo.amount
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
# Do new stack otherwise
|
||||
drone = self.droneInfo.toDrone()
|
||||
@@ -49,9 +52,11 @@ class CalcAddLocalDroneCommand(wx.Command):
|
||||
fit.drones.append(drone)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to append to list')
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
self.savedPosition = fit.drones.index(drone)
|
||||
return True
|
||||
|
||||
@@ -64,5 +69,9 @@ class CalcAddLocalDroneCommand(wx.Command):
|
||||
drone.amountActive = self.savedDroneInfo.amountActive
|
||||
return True
|
||||
from .localRemove import CalcRemoveLocalDroneCommand
|
||||
cmd = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.savedPosition, amount=self.droneInfo.amount)
|
||||
cmd = CalcRemoveLocalDroneCommand(
|
||||
fitID=self.fitID,
|
||||
position=self.savedPosition,
|
||||
amount=self.droneInfo.amount,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -12,11 +12,12 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcRemoveLocalDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
def __init__(self, fitID, position, amount, commit=True):
|
||||
wx.Command.__init__(self, True, 'Remove Drone')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amountToRemove = amount
|
||||
self.commit = commit
|
||||
self.savedDroneInfo = None
|
||||
self.removedStack = None
|
||||
|
||||
@@ -36,7 +37,8 @@ class CalcRemoveLocalDroneCommand(wx.Command):
|
||||
else:
|
||||
self.removedStack = False
|
||||
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
@@ -52,11 +54,13 @@ class CalcRemoveLocalDroneCommand(wx.Command):
|
||||
fit.drones.insert(self.position, drone)
|
||||
except HandledListActionError:
|
||||
pyfalog.warning('Failed to insert to list')
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return False
|
||||
else:
|
||||
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
|
||||
|
||||
52
gui/fitCommands/gui/localDrone/splitStack.py
Normal file
52
gui/fitCommands/gui/localDrone/splitStack.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.localAdd import CalcAddLocalDroneCommand
|
||||
from gui.fitCommands.calc.drone.localRemove import CalcRemoveLocalDroneCommand
|
||||
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiSplitLocalDroneStackCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
wx.Command.__init__(self, True, 'Split Local Drone Stack')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
drone = fit.drones[self.position]
|
||||
if self.amount >= drone.amount:
|
||||
return False
|
||||
info = DroneInfo.fromDrone(drone)
|
||||
info.amount = self.amount
|
||||
info.amountActive = min(self.amount, info.amountActive)
|
||||
commands = []
|
||||
commands.append(CalcRemoveLocalDroneCommand(
|
||||
fitID=self.fitID,
|
||||
position=self.position,
|
||||
amount=self.amount,
|
||||
commit=False))
|
||||
commands.append(CalcAddLocalDroneCommand(
|
||||
fitID=self.fitID,
|
||||
droneInfo=info,
|
||||
forceNewStack=True,
|
||||
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
|
||||
@@ -98,39 +98,6 @@ class FitDeprecated(object):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user