Rework implant state switch command to accept multiple positions
This commit is contained in:
@@ -241,7 +241,7 @@ class ImplantDisplay(d.Display):
|
||||
if implant in self.original:
|
||||
position = self.original.index(implant)
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(
|
||||
fitID=fitID, position=position))
|
||||
fitID=fitID, mainPosition=position, positions=[position]))
|
||||
|
||||
def spawnMenu(self, event):
|
||||
sel = self.GetFirstSelected()
|
||||
|
||||
@@ -16,7 +16,7 @@ from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
|
||||
from .gui.implant.changeMeta import GuiChangeImplantMetaCommand
|
||||
from .gui.implant.remove import GuiRemoveImplantsCommand
|
||||
from .gui.implant.setAdd import GuiAddImplantSetCommand
|
||||
from .gui.implant.toggleState import GuiToggleImplantStateCommand
|
||||
from .gui.implant.toggleStates import GuiToggleImplantStateCommand
|
||||
from .gui.itemsRebase import GuiRebaseItemsCommand
|
||||
from .gui.localDrone.add import GuiAddLocalDroneCommand
|
||||
from .gui.localDrone.changeAmount import GuiChangeLocalDroneAmountCommand
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleImplantStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Implant State')
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of implant state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
implant = fit.implants[self.position]
|
||||
self.savedState = implant.active
|
||||
implant.active = not implant.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of implant state at position {} for fit {}'.format(self.position, self.fitID))
|
||||
cmd = CalcToggleImplantStateCommand(fitID=self.fitID, position=self.position, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
54
gui/fitCommands/calc/implant/toggleStates.py
Normal file
54
gui/fitCommands/calc/implant/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 CalcToggleImplantStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, mainPosition, positions, forceStates=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Implant States')
|
||||
self.fitID = fitID
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
self.forceStates = forceStates
|
||||
self.savedStates = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of implant 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.implants[p].active for p in positions}
|
||||
|
||||
if self.forceStates is not None:
|
||||
for position, active in self.forceStates.items():
|
||||
implant = fit.implants[position]
|
||||
implant.active = active
|
||||
elif fit.implants[self.mainPosition].active:
|
||||
for position in positions:
|
||||
implant = fit.implants[position]
|
||||
if implant.active:
|
||||
implant.active = False
|
||||
else:
|
||||
for position in positions:
|
||||
implant = fit.implants[position]
|
||||
if not implant.active:
|
||||
implant.active = True
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
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,
|
||||
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.implant.toggleState import CalcToggleImplantStateCommand
|
||||
from gui.fitCommands.calc.implant.toggleStates import CalcToggleImplantStatesCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiToggleImplantStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
def __init__(self, fitID, mainPosition, positions):
|
||||
wx.Command.__init__(self, True, 'Toggle Implant State')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.mainPosition = mainPosition
|
||||
self.positions = positions
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcToggleImplantStateCommand(fitID=self.fitID, position=self.position)
|
||||
cmd = CalcToggleImplantStatesCommand(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