Change command fit state changing command to support multi-selection
This commit is contained in:
@@ -185,7 +185,8 @@ class CommandView(d.Display):
|
||||
col = self.getColumn(event.Position)
|
||||
if col == self.getColIndex(State):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleCommandFitStateCommand(fitID, item.ID))
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleCommandFitStatesCommand(
|
||||
fitID=fitID, mainCommandFitID=item.ID, commandFitIDs=[item.ID]))
|
||||
|
||||
def spawnMenu(self, event):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
|
||||
@@ -9,7 +9,7 @@ from .gui.cargo.changeMeta import GuiChangeCargoMetaCommand
|
||||
from .gui.cargo.remove import GuiRemoveCargosCommand
|
||||
from .gui.commandFit.add import GuiAddCommandFitCommand
|
||||
from .gui.commandFit.remove import GuiRemoveCommandFitsCommand
|
||||
from .gui.commandFit.toggleState import GuiToggleCommandFitStateCommand
|
||||
from .gui.commandFit.toggleStates import GuiToggleCommandFitStatesCommand
|
||||
from .gui.fitRename import GuiRenameFitCommand
|
||||
from .gui.implant.add import GuiAddImplantCommand
|
||||
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
|
||||
|
||||
@@ -28,9 +28,9 @@ class CalcToggleBoosterStatesCommand(wx.Command):
|
||||
self.savedStates = {p: fit.boosters[p].active for p in positions}
|
||||
|
||||
if self.forceStates is not None:
|
||||
for position, active in self.forceStates.items():
|
||||
for position, state in self.forceStates.items():
|
||||
booster = fit.boosters[position]
|
||||
booster.active = active
|
||||
booster.active = state
|
||||
elif fit.boosters[self.mainPosition].active:
|
||||
for position in positions:
|
||||
booster = fit.boosters[position]
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleCommandFitStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID, forceState=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Command Fit State')
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.forceState = forceState
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of command fit {} state for fit {}'.format(self.commandFitID, self.fitID))
|
||||
commandFit = Fit.getInstance().getFit(self.commandFitID)
|
||||
# Command fit could have been deleted if we are redoing
|
||||
if commandFit is None:
|
||||
pyfalog.debug('Command fit is not available')
|
||||
return False
|
||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
||||
if commandInfo is None:
|
||||
pyfalog.warning('Fit command info is not available')
|
||||
return False
|
||||
self.savedState = commandInfo.active
|
||||
commandInfo.active = not commandInfo.active if self.forceState is None else self.forceState
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of command fit {} state for fit {}'.format(self.commandFitID, self.fitID))
|
||||
cmd = CalcToggleCommandFitStateCommand(fitID=self.fitID, commandFitID=self.commandFitID, forceState=self.savedState)
|
||||
return cmd.Do()
|
||||
73
gui/fitCommands/calc/commandFit/toggleStates.py
Normal file
73
gui/fitCommands/calc/commandFit/toggleStates.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcToggleCommandFitStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, mainCommandFitID, commandFitIDs, forceStates=None):
|
||||
wx.Command.__init__(self, True, 'Toggle Command Fit States')
|
||||
self.fitID = fitID
|
||||
self.mainCommandFitID = mainCommandFitID
|
||||
self.commandFitIDs = commandFitIDs
|
||||
self.forceStates = forceStates
|
||||
self.savedStates = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing toggling of command fit {}/{} state for fit {}'.format(self.mainCommandFitID, self.commandFitIDs, self.fitID))
|
||||
sFit = Fit.getInstance()
|
||||
|
||||
commandFitIDs = self.commandFitIDs[:]
|
||||
if self.mainCommandFitID not in commandFitIDs:
|
||||
commandFitIDs.append(self.mainCommandFitID)
|
||||
|
||||
commandInfos = {}
|
||||
for commandFitID in commandFitIDs:
|
||||
commandFit = sFit.getFit(commandFitID)
|
||||
# Command fit could have been deleted if we are redoing
|
||||
if commandFit is None:
|
||||
pyfalog.debug('Command fit is not available')
|
||||
continue
|
||||
commandInfo = commandFit.getCommandInfo(self.fitID)
|
||||
if commandInfo is None:
|
||||
pyfalog.warning('Fit command info is not available')
|
||||
continue
|
||||
commandInfos[commandFitID] = commandInfo
|
||||
|
||||
if len(commandInfos) == 0:
|
||||
return False
|
||||
|
||||
self.savedStates = {cfid: ci.active for cfid, ci in commandInfos.items()}
|
||||
|
||||
mainCommandInfo = commandInfos.get(self.mainCommandFitID)
|
||||
if self.forceStates is not None:
|
||||
for commandFitID, state in self.forceStates.items():
|
||||
commandInfo = commandInfos.get(commandFitID)
|
||||
if commandInfo is None:
|
||||
continue
|
||||
commandInfo.active = state
|
||||
elif mainCommandInfo is not None and mainCommandInfo.active:
|
||||
for commandInfo in commandInfos.values():
|
||||
commandInfo.active = False
|
||||
elif mainCommandInfo is not None and not mainCommandInfo.active:
|
||||
for commandInfo in commandInfos.values():
|
||||
commandInfo.active = True
|
||||
# Bail if we cannot calculate which state to take
|
||||
else:
|
||||
return False
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing toggling of command fit {}/{} state for fit {}'.format(self.mainCommandFitID, self.commandFitIDs, self.fitID))
|
||||
cmd = CalcToggleCommandFitStatesCommand(
|
||||
fitID=self.fitID,
|
||||
mainCommandFitID=self.mainCommandFitID,
|
||||
commandFitIDs=self.commandFitIDs,
|
||||
forceStates=self.savedStates)
|
||||
return cmd.Do()
|
||||
@@ -30,9 +30,9 @@ class CalcToggleFighterStatesCommand(wx.Command):
|
||||
self.savedStates = {p: container[p].active for p in positions}
|
||||
|
||||
if self.forceStates is not None:
|
||||
for position, active in self.forceStates.items():
|
||||
for position, state in self.forceStates.items():
|
||||
fighter = container[position]
|
||||
fighter.active = active
|
||||
fighter.active = state
|
||||
elif container[self.mainPosition].active:
|
||||
for position in positions:
|
||||
fighter = container[position]
|
||||
|
||||
@@ -28,9 +28,9 @@ class CalcToggleImplantStatesCommand(wx.Command):
|
||||
self.savedStates = {p: fit.implants[p].active for p in positions}
|
||||
|
||||
if self.forceStates is not None:
|
||||
for position, active in self.forceStates.items():
|
||||
for position, state in self.forceStates.items():
|
||||
implant = fit.implants[position]
|
||||
implant.active = active
|
||||
implant.active = state
|
||||
elif fit.implants[self.mainPosition].active:
|
||||
for position in positions:
|
||||
implant = fit.implants[position]
|
||||
|
||||
@@ -2,21 +2,25 @@ import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.commandFit.toggleState import CalcToggleCommandFitStateCommand
|
||||
from gui.fitCommands.calc.commandFit.toggleStates import CalcToggleCommandFitStatesCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiToggleCommandFitStateCommand(wx.Command):
|
||||
class GuiToggleCommandFitStatesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True, 'Toggle Command Fit State')
|
||||
def __init__(self, fitID, mainCommandFitID, commandFitIDs):
|
||||
wx.Command.__init__(self, True, 'Toggle Command Fit States')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.mainCommandFitID = mainCommandFitID
|
||||
self.commandFitIDs = commandFitIDs
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcToggleCommandFitStateCommand(fitID=self.fitID, commandFitID=self.commandFitID)
|
||||
cmd = CalcToggleCommandFitStatesCommand(
|
||||
fitID=self.fitID,
|
||||
mainCommandFitID=self.mainCommandFitID,
|
||||
commandFitIDs=self.commandFitIDs)
|
||||
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