Allow batch toggling of fighters

This commit is contained in:
DarkPhoenix
2019-04-24 16:49:39 +03:00
parent 81da217a09
commit 6e4ec54ac6
6 changed files with 80 additions and 35 deletions

View File

@@ -310,19 +310,31 @@ class FighterDisplay(d.Display):
self.mainFrame.command.Submit(cmd.GuiRemoveLocalFightersCommand(fitID=fitID, positions=positions))
def click(self, event):
event.Skip()
row, _ = self.HitTest(event.Position)
if row != -1:
mainRow, _ = self.HitTest(event.Position)
if mainRow != -1:
col = self.getColumn(event.Position)
if col == self.getColIndex(State):
fitID = self.mainFrame.getActiveFit()
try:
fighter = self.fighters[row]
mainFighter = self.fighters[mainRow]
except IndexError:
return
if fighter in self.original:
position = self.original.index(fighter)
self.mainFrame.command.Submit(cmd.GuiToggleLocalFighterStateCommand(fitID=fitID, position=position))
if mainFighter in self.original:
mainPosition = self.original.index(mainFighter)
positions = []
for row in self.getSelectedRows():
try:
fighter = self.fighters[row]
except IndexError:
continue
if fighter in self.original:
positions.append(self.original.index(fighter))
self.mainFrame.command.Submit(cmd.GuiToggleLocalFighterStatesCommand(
fitID=fitID,
mainPosition=mainPosition,
positions=positions))
return
event.Skip()
def spawnMenu(self, event):
selection = self.getSelectedFighters()

View File

@@ -280,8 +280,8 @@ class ProjectedView(d.Display):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedFighters:
position = fit.projectedFighters.index(thing)
self.mainFrame.command.Submit(cmd.GuiToggleProjectedFighterStateCommand(
fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiToggleProjectedFighterStatesCommand(
fitID=fitID, mainPosition=position, positions=[position]))
def spawnMenu(self, event):
fitID = self.mainFrame.getActiveFit()

View File

@@ -30,7 +30,7 @@ from .gui.localFighter.add import GuiAddLocalFighterCommand
from .gui.localFighter.changeAmount import GuiChangeLocalFighterAmountCommand
from .gui.localFighter.changeMetas import GuiChangeLocalFighterMetasCommand
from .gui.localFighter.remove import GuiRemoveLocalFightersCommand
from .gui.localFighter.toggleState import GuiToggleLocalFighterStateCommand
from .gui.localFighter.toggleStates import GuiToggleLocalFighterStatesCommand
from .gui.localModule.add import GuiAddLocalModuleCommand
from .gui.localModule.changeCharges import GuiChangeLocalModuleChargesCommand
from .gui.localModule.changeMetas import GuiChangeLocalModuleMetasCommand
@@ -57,7 +57,7 @@ from .gui.projectedFighter.add import GuiAddProjectedFighterCommand
from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand
from .gui.projectedFighter.changeMeta import GuiChangeProjectedFighterMetaCommand
from .gui.projectedFighter.remove import GuiRemoveProjectedFighterCommand
from .gui.projectedFighter.toggleState import GuiToggleProjectedFighterStateCommand
from .gui.projectedFighter.toggleStates import GuiToggleProjectedFighterStatesCommand
from .gui.projectedFit.add import GuiAddProjectedFitCommand
from .gui.projectedFit.changeAmount import GuiChangeProjectedFitAmountCommand
from .gui.projectedFit.remove import GuiRemoveProjectedFitCommand

View File

@@ -8,27 +8,50 @@ from service.fit import Fit
pyfalog = Logger(__name__)
class CalcToggleFighterStateCommand(wx.Command):
class CalcToggleFighterStatesCommand(wx.Command):
def __init__(self, fitID, projected, position, forceState=None):
wx.Command.__init__(self, True, 'Toggle Fighter State')
def __init__(self, fitID, projected, mainPosition, positions, forceStates=None):
wx.Command.__init__(self, True, 'Toggle Fighter States')
self.fitID = fitID
self.projected = projected
self.position = position
self.forceState = forceState
self.savedState = None
self.mainPosition = mainPosition
self.positions = positions
self.forceStates = forceStates
self.savedStates = None
def Do(self):
pyfalog.debug('Doing toggling of fighter state at position {} for fit {}'.format(self.position, self.fitID))
pyfalog.debug('Doing toggling of fighter state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
fit = Fit.getInstance().getFit(self.fitID)
container = fit.projectedFighters if self.projected else fit.fighters
fighter = container[self.position]
self.savedState = fighter.active
fighter.active = not fighter.active if self.forceState is None else self.forceState
positions = self.positions[:]
if self.mainPosition not in positions:
positions.append(self.mainPosition)
self.savedStates = {p: container[p].active for p in positions}
if self.forceStates is not None:
for position, active in self.forceStates.items():
fighter = container[position]
fighter.active = active
elif container[self.mainPosition].active:
for position in positions:
fighter = container[position]
if fighter.active:
fighter.active = False
else:
for position in positions:
fighter = container[position]
if not fighter.active:
fighter.active = True
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing toggling of fighter state at position {} for fit {}'.format(self.position, self.fitID))
cmd = CalcToggleFighterStateCommand(fitID=self.fitID, projected=self.projected, position=self.position, forceState=self.savedState)
pyfalog.debug('Undoing toggling of fighter state at position {}/{} for fit {}'.format(self.mainPosition, self.positions, self.fitID))
cmd = CalcToggleFighterStatesCommand(
fitID=self.fitID,
projected=self.projected,
mainPosition=self.mainPosition,
positions=self.positions,
forceStates=self.savedStates)
return cmd.Do()

View File

@@ -2,21 +2,26 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.toggleState import CalcToggleFighterStateCommand
from gui.fitCommands.calc.fighter.toggleState import CalcToggleFighterStatesCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiToggleLocalFighterStateCommand(wx.Command):
class GuiToggleLocalFighterStatesCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Toggle Local Fighter State')
def __init__(self, fitID, mainPosition, positions):
wx.Command.__init__(self, True, 'Toggle Local Fighter States')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.mainPosition = mainPosition
self.positions = positions
def Do(self):
cmd = CalcToggleFighterStateCommand(fitID=self.fitID, projected=False, position=self.position)
cmd = CalcToggleFighterStatesCommand(
fitID=self.fitID,
projected=False,
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))

View File

@@ -2,21 +2,26 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.toggleState import CalcToggleFighterStateCommand
from gui.fitCommands.calc.fighter.toggleState import CalcToggleFighterStatesCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiToggleProjectedFighterStateCommand(wx.Command):
class GuiToggleProjectedFighterStatesCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Toggle Projected Fighter State')
def __init__(self, fitID, mainPosition, positions):
wx.Command.__init__(self, True, 'Toggle Projected Fighter States')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.mainPosition = mainPosition
self.positions = positions
def Do(self):
cmd = CalcToggleFighterStateCommand(fitID=self.fitID, projected=True, position=self.position)
cmd = CalcToggleFighterStatesCommand(
fitID=self.fitID,
projected=True,
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))