Files
pyfa/gui/fitCommands/guiToggleProjected.py
2019-04-14 11:37:58 +03:00

57 lines
2.3 KiB
Python

import wx
import gui.mainFrame
from eos.saveddata.drone import Drone as DroneType
from eos.saveddata.fighter import Fighter as FighterType
from eos.saveddata.fit import Fit as FitType
from eos.saveddata.module import Module as ModuleType
from gui import globalEvents as GE
from service.fit import Fit
from .calc.fitToggleProjectedDrone import FitToggleProjectedDroneCommand
from .calc.fitToggleProjectedFighter import FitToggleProjectedFighterStateCommand
from .calc.fitToggleProjectedFit import FitToggleProjectedFitCommand
from .calc.fitChangeProjectedModuleState import FitChangeProjectedModuleStateCommand
class GuiToggleProjectedCommand(wx.Command):
def __init__(self, fitID, thing, click):
wx.Command.__init__(self, True, "Toggle Projected Item")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.internal_history = wx.CommandProcessor()
self.fitID = fitID
fit = Fit.getInstance().getFit(self.fitID)
if isinstance(thing, FitType):
self.commandType = FitToggleProjectedFitCommand
self.args = (self.fitID, thing.ID)
elif isinstance(thing, ModuleType):
position = fit.projectedModules.index(thing)
self.commandType = FitChangeProjectedModuleStateCommand
self.args = (self.fitID, position, click)
elif isinstance(thing, DroneType):
self.commandType = FitToggleProjectedDroneCommand
self.args = (self.fitID, thing.itemID)
elif isinstance(thing, FighterType):
position = fit.projectedFighters.index(thing)
self.commandType = FitToggleProjectedFighterStateCommand
self.args = (self.fitID, position)
else:
self.commandType = None
self.args = ()
def Do(self):
if self.commandType is None:
return False
if not self.internal_history.Submit(self.commandType(*self.args)):
return False
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
def Undo(self):
for _ in self.internal_history.Commands:
self.internal_history.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True