70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
import wx
|
|
from service.fit import Fit
|
|
|
|
import gui.mainFrame
|
|
from gui import globalEvents as GE
|
|
from .calcCommands.module.projectedRemove import CalcRemoveProjectedModuleCommand
|
|
from .calcCommands.projectedFit.remove import CalcRemoveProjectedFitCommand
|
|
from .calcCommands.fighter.projectedRemove import CalcRemoveProjectedFighterCommand
|
|
from logbook import Logger
|
|
from .calcCommands.drone.projectedRemove import CalcRemoveProjectedDroneCommand
|
|
|
|
from gui.fitCommands.helpers import DroneInfo
|
|
from eos.saveddata.drone import Drone
|
|
from eos.saveddata.module import Module
|
|
from eos.saveddata.fighter import Fighter
|
|
|
|
pyfalog = Logger(__name__)
|
|
|
|
|
|
class GuiRemoveProjectedCommand(wx.Command):
|
|
mapping = {
|
|
'fit': CalcRemoveProjectedFitCommand,
|
|
'module': CalcRemoveProjectedModuleCommand,
|
|
'fighter': CalcRemoveProjectedFighterCommand,
|
|
'drone': CalcRemoveProjectedDroneCommand
|
|
}
|
|
|
|
def __init__(self, fitID, thing):
|
|
wx.Command.__init__(self, True, "Projected Remove")
|
|
self.internalHistory = wx.CommandProcessor()
|
|
self.fitID = fitID
|
|
fit = Fit.getInstance().getFit(fitID)
|
|
|
|
if isinstance(thing, Drone):
|
|
self.data = DroneInfo(itemID=thing.itemID, amount=1, amountActive=1)
|
|
self.type = 'drone'
|
|
elif isinstance(thing, Module):
|
|
self.type = 'module'
|
|
self.data = fit.projectedModules.index(thing)
|
|
elif isinstance(thing, Fighter):
|
|
self.data = fit.projectedFighters.index(thing)
|
|
self.type = 'fighter'
|
|
else:
|
|
# todo: fix!
|
|
self.data = thing.ID
|
|
self.type = 'fit'
|
|
|
|
def Do(self):
|
|
result = False
|
|
# since we can project various types, we need to switch of the fit command. We can't do this switch easily in
|
|
# the fit command since each type might have a different kind of undo, easier to split it out
|
|
|
|
cls = self.mapping.get(self.type, None)
|
|
if cls:
|
|
cmd = cls(self.fitID, self.data)
|
|
result = self.internalHistory.Submit(cmd)
|
|
|
|
if result:
|
|
Fit.getInstance().recalc(self.fitID)
|
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
|
return True
|
|
return False
|
|
|
|
def Undo(self):
|
|
for _ in self.internalHistory.Commands:
|
|
self.internalHistory.Undo()
|
|
Fit.getInstance().recalc(self.fitID)
|
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
|
return True
|