Change booster state changing command to support multi-selection
This commit is contained in:
@@ -179,9 +179,10 @@ class BoosterView(d.Display):
|
||||
return
|
||||
if booster in self.original:
|
||||
position = self.original.index(booster)
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleBoosterStateCommand(
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleBoosterStatesCommand(
|
||||
fitID=fitID,
|
||||
position=position))
|
||||
mainPosition=position,
|
||||
positions=[position]))
|
||||
|
||||
def spawnMenu(self, event):
|
||||
sel = self.GetFirstSelected()
|
||||
|
||||
@@ -2,7 +2,7 @@ from .gui.booster.add import GuiAddBoosterCommand
|
||||
from .gui.booster.changeMeta import GuiChangeBoosterMetaCommand
|
||||
from .gui.booster.remove import GuiRemoveBoostersCommand
|
||||
from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand
|
||||
from .gui.booster.toggleState import GuiToggleBoosterStateCommand
|
||||
from .gui.booster.toggleStates import GuiToggleBoosterStatesCommand
|
||||
from .gui.cargo.add import GuiAddCargoCommand
|
||||
from .gui.cargo.changeAmount import GuiChangeCargoAmountCommand
|
||||
from .gui.cargo.changeMeta import GuiChangeCargoMetaCommand
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleBoosterStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of booster state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
booster = fit.boosters[self.position]
|
||||
self.savedState = booster.active
|
||||
booster.active = not booster.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of booster state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = CalcToggleBoosterStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
54
gui/fitCommands/calc/booster/toggleStates.py
Normal file
54
gui/fitCommands/calc/booster/toggleStates.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleBoosterStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, mainPosition, positions, forceStates=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster States')
|
||||
self.fitID = fitID
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
self.forceStates = forceStates
|
||||
self.savedStates = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of booster 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.savedStates = {p: fit.boosters[p].active for p in positions}
|
||||
|
||||
if self.forceStates is not None:
|
||||
for position, active in self.forceStates.items():
|
||||
booster = fit.boosters[position]
|
||||
booster.active = active
|
||||
elif fit.boosters[self.mainPosition].active:
|
||||
for position in positions:
|
||||
booster = fit.boosters[position]
|
||||
if booster.active:
|
||||
booster.active = False
|
||||
else:
|
||||
for position in positions:
|
||||
booster = fit.boosters[position]
|
||||
if not booster.active:
|
||||
booster.active = True
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of booster state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
|
||||
cmd = CalcToggleBoosterStatesCommand(
|
||||
fitID=self.fitID,
|
||||
mainPosition=self.mainPosition,
|
||||
positions=self.positions,
|
||||
forceStates=self.savedStates)
|
||||
return cmd.Do()
|
||||
@@ -48,7 +48,7 @@ class CalcToggleImplantStatesCommand(wx.Command):
|
||||
pyfalog.debug('Undoing toggling of implant state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
|
||||
cmd = CalcToggleImplantStatesCommand(
|
||||
fitID=self.fitID,
|
||||
positions=self.positions,
|
||||
mainPosition=self.mainPosition,
|
||||
positions=self.positions,
|
||||
forceStates=self.savedStates)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -2,21 +2,22 @@ import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.booster.toggleState import CalcToggleBoosterStateCommand
|
||||
from gui.fitCommands.calc.booster.toggleStates import CalcToggleBoosterStatesCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiToggleBoosterStateCommand(wx.Command):
|
||||
class GuiToggleBoosterStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster State')
|
||||
def __init__(self, fitID, mainPosition, positions):
|
||||
wx.Command.__init__(self, True, 'Toggle Booster States')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcToggleBoosterStateCommand(fitID=self.fitID, position=self.position)
|
||||
cmd = CalcToggleBoosterStatesCommand(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