Save booster state upon deletion for undo
This commit is contained in:
@@ -36,10 +36,5 @@ class Project(ContextMenu):
|
||||
if self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, selection[0].ID, 'item')):
|
||||
self.mainFrame.additionsPane.select("Projected")
|
||||
|
||||
# trigger = sFit.project(fitID, selection[0])
|
||||
# if trigger:
|
||||
# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
# self.mainFrame.additionsPane.select("Projected")
|
||||
|
||||
|
||||
Project.register()
|
||||
|
||||
@@ -9,10 +9,12 @@ class FitAddBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addBooster
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
def __init__(self, fitID, itemID, state=None, sideEffects=None):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.state = state
|
||||
self.sideEffects = sideEffects
|
||||
self.new_index = None
|
||||
self.old_item = None
|
||||
|
||||
@@ -31,6 +33,12 @@ class FitAddBoosterCommand(wx.Command):
|
||||
pyfalog.warning("Invalid item: {0}", self.itemID)
|
||||
return False
|
||||
|
||||
if self.state is not None:
|
||||
booster.active = self.state
|
||||
if self.sideEffects is not None:
|
||||
for sideEffect in booster.sideEffects:
|
||||
sideEffect.active = self.sideEffects.get(sideEffect.effectID, False)
|
||||
|
||||
self.old_item = fit.boosters.makeRoom(booster)
|
||||
fit.boosters.append(booster)
|
||||
self.new_index = fit.boosters.index(booster)
|
||||
|
||||
@@ -12,19 +12,27 @@ class FitRemoveBoosterCommand(wx.Command):
|
||||
wx.Command.__init__(self, True, "Implant remove")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.old = None
|
||||
self.savedItemID = None
|
||||
self.savedState = None
|
||||
self.savedSideEffects = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing booster from position ({0}) for fit ID: {1}", self.position, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
booster = fit.boosters[self.position]
|
||||
self.old = booster.itemID
|
||||
self.savedItemID = booster.itemID
|
||||
self.savedState = booster.active
|
||||
self.savedSideEffects = {se.effectID: se.active for se in booster.sideEffects}
|
||||
fit.boosters.remove(booster)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from .fitAddBooster import FitAddBoosterCommand # Avoid circular import
|
||||
cmd = FitAddBoosterCommand(self.fitID, self.old)
|
||||
cmd = FitAddBoosterCommand(
|
||||
fitID=self.fitID,
|
||||
itemID=self.savedItemID,
|
||||
state=self.savedState,
|
||||
sideEffects=self.savedSideEffects)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -16,7 +16,7 @@ class GuiAddBoosterCommand(wx.Command):
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitAddBoosterCommand(self.fitID, self.itemID)):
|
||||
if self.internal_history.Submit(FitAddBoosterCommand(self.fitID, self.itemID, True, {})):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -37,7 +37,9 @@ class GuiMetaSwapCommand(wx.Command):
|
||||
elif context == 'boosterItem':
|
||||
for x in selection:
|
||||
idx = fit.boosters.index(x)
|
||||
self.data.append(((FitRemoveBoosterCommand, fitID, idx), (FitAddBoosterCommand, fitID, itemID)))
|
||||
state = x.active
|
||||
sideEffects = {se.effectID: se.active for se in x.sideEffects}
|
||||
self.data.append(((FitRemoveBoosterCommand, fitID, idx), (FitAddBoosterCommand, fitID, itemID, state, sideEffects)))
|
||||
elif context == 'cargoItem':
|
||||
for x in selection:
|
||||
self.data.append(((FitRemoveCargoCommand, fitID, x.itemID, 1, True), (FitAddCargoCommand, fitID, itemID, x.amount)))
|
||||
|
||||
Reference in New Issue
Block a user