Make drone additions pane multi-selectable, change all related commands to support it too
This commit is contained in:
@@ -21,10 +21,10 @@ from .gui.itemsRebase import GuiRebaseItemsCommand
|
||||
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.remove import GuiRemoveLocalDronesCommand
|
||||
from .gui.localDrone.stackSplit import GuiSplitLocalDroneStackCommand
|
||||
from .gui.localDrone.stacksMerge import GuiMergeLocalDroneStacksCommand
|
||||
from .gui.localDrone.toggleState import GuiToggleLocalDroneStateCommand
|
||||
from .gui.localDrone.toggleStates import GuiToggleLocalDroneStatesCommand
|
||||
from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilityStateCommand
|
||||
from .gui.localFighter.add import GuiAddLocalFighterCommand
|
||||
from .gui.localFighter.changeAmount import GuiChangeLocalFighterAmountCommand
|
||||
|
||||
@@ -15,7 +15,7 @@ pyfalog = Logger(__name__)
|
||||
class CalcAddLocalDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, droneInfo, forceNewStack=False, commit=True):
|
||||
wx.Command.__init__(self, True, 'Add Drone')
|
||||
wx.Command.__init__(self, True, 'Add Local Drone')
|
||||
self.fitID = fitID
|
||||
self.droneInfo = droneInfo
|
||||
self.forceNewStack = forceNewStack
|
||||
|
||||
@@ -12,7 +12,7 @@ pyfalog = Logger(__name__)
|
||||
class CalcChangeLocalDroneAmountCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount, commit=True):
|
||||
wx.Command.__init__(self, True, 'Change Drone Amount')
|
||||
wx.Command.__init__(self, True, 'Change Local Drone Amount')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
|
||||
@@ -13,7 +13,7 @@ pyfalog = Logger(__name__)
|
||||
class CalcRemoveLocalDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount, commit=True):
|
||||
wx.Command.__init__(self, True, 'Remove Drone')
|
||||
wx.Command.__init__(self, True, 'Remove Local Drone')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amountToRemove = amount
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleLocalDroneStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceAmountActive=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Drone State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceAmountActive = forceAmountActive
|
||||
self.savedAmountActive = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of local drone state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = fit.drones[self.position]
|
||||
self.savedAmountActive = drone.amountActive
|
||||
if self.forceAmountActive is not None:
|
||||
drone.amountActive = self.forceAmountActive
|
||||
elif drone.amountActive > 0:
|
||||
drone.amountActive = 0
|
||||
else:
|
||||
drone.amountActive = drone.amount
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of local drone state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = CalcToggleLocalDroneStateCommand(fitID=self.fitID, position=self.position, forceAmountActive=self.savedAmountActive)
|
||||
return cmd.Do()
|
||||
55
gui/fitCommands/calc/drone/localToggleStates.py
Normal file
55
gui/fitCommands/calc/drone/localToggleStates.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleLocalDroneStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, mainPosition, positions, forceActiveAmounts=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Local Drone States')
|
||||
self.fitID = fitID
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
self.forceActiveAmounts = forceActiveAmounts
|
||||
self.savedActiveAmounts = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of local drone state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
|
||||
positions = self.positions[:]
|
||||
if self.mainPosition not in positions:
|
||||
positions.append(self.mainPosition)
|
||||
self.savedActiveAmounts = {p: fit.drones[p].amountActive for p in positions}
|
||||
|
||||
if self.forceActiveAmounts is not None:
|
||||
for position, amountActive in self.forceActiveAmounts.items():
|
||||
drone = fit.drones[position]
|
||||
drone.amountActive = amountActive
|
||||
elif fit.drones[self.mainPosition].amountActive > 0:
|
||||
for position in positions:
|
||||
drone = fit.drones[position]
|
||||
if drone.amountActive > 0:
|
||||
drone.amountActive = 0
|
||||
else:
|
||||
for position in positions:
|
||||
drone = fit.drones[position]
|
||||
if drone.amountActive == 0:
|
||||
drone.amountActive = drone.amount
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of local drone state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
|
||||
cmd = CalcToggleLocalDroneStatesCommand(
|
||||
fitID=self.fitID,
|
||||
mainPosition=self.mainPosition,
|
||||
positions=self.positions,
|
||||
forceActiveAmounts=self.savedActiveAmounts)
|
||||
return cmd.Do()
|
||||
@@ -29,6 +29,8 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
|
||||
if mainMod.isEmpty:
|
||||
return False
|
||||
positions = [pos for pos in self.positions if not fit.modules[pos].isEmpty]
|
||||
if self.mainPosition not in positions:
|
||||
positions.append(self.mainPosition)
|
||||
self.savedStates = {pos: fit.modules[pos].state for pos in positions}
|
||||
|
||||
changed = False
|
||||
|
||||
@@ -15,8 +15,8 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
wx.Command.__init__(self, True, 'Remove Module')
|
||||
self.fitID = fitID
|
||||
self.positions = positions
|
||||
self.savedModInfos = {}
|
||||
self.commit = commit
|
||||
self.savedModInfos = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
@@ -24,6 +24,7 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
|
||||
self.savedModInfos = {}
|
||||
for position in self.positions:
|
||||
mod = fit.modules[position]
|
||||
if not mod.isEmpty:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.localRemove import CalcRemoveLocalDroneCommand
|
||||
@@ -7,24 +8,33 @@ from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiRemoveLocalDroneCommand(wx.Command):
|
||||
class GuiRemoveLocalDronesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
wx.Command.__init__(self, True, 'Remove Local Drone')
|
||||
def __init__(self, fitID, positions, amount):
|
||||
wx.Command.__init__(self, True, 'Remove Local Drones')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.positions = positions
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=self.amount)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
results = []
|
||||
for position in self.positions:
|
||||
cmd = CalcRemoveLocalDroneCommand(
|
||||
fitID=self.fitID,
|
||||
position=position,
|
||||
amount=self.amount,
|
||||
commit=False)
|
||||
results.append(self.internalHistory.submit(cmd))
|
||||
success = any(results)
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
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
|
||||
|
||||
@@ -2,21 +2,25 @@ import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.localToggleState import CalcToggleLocalDroneStateCommand
|
||||
from gui.fitCommands.calc.drone.localToggleStates import CalcToggleLocalDroneStatesCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiToggleLocalDroneStateCommand(wx.Command):
|
||||
class GuiToggleLocalDroneStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, 'Toggle Local Drone State')
|
||||
def __init__(self, fitID, mainPosition, positions):
|
||||
wx.Command.__init__(self, True, 'Toggle Local Drone States')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcToggleLocalDroneStateCommand(fitID=self.fitID, position=self.position)
|
||||
cmd = CalcToggleLocalDroneStatesCommand(
|
||||
fitID=self.fitID,
|
||||
mainPosition=self.mainPosition,
|
||||
positions=self.positions)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
Reference in New Issue
Block a user