Restore state of removed implants on undo
This commit is contained in:
@@ -9,40 +9,44 @@ class FitAddImplantCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addImplant
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Cargo add")
|
||||
def __init__(self, fitID, itemID, state):
|
||||
wx.Command.__init__(self, True, "Add Implant")
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.old_item = None
|
||||
self.newItemID = itemID
|
||||
self.newState = state
|
||||
self.newIndex = None
|
||||
self.oldItemID = None
|
||||
self.oldState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.itemID)
|
||||
pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.newItemID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager="attributes")
|
||||
item = eos.db.getItem(self.newItemID, eager="attributes")
|
||||
|
||||
if next((x for x in fit.implants if x.itemID == self.itemID), None):
|
||||
if next((x for x in fit.implants if x.itemID == self.newItemID), None):
|
||||
return False # already have item in list of implants
|
||||
|
||||
try:
|
||||
implant = Implant(item)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", self.itemID)
|
||||
pyfalog.warning("Invalid item: {0}", self.newItemID)
|
||||
return False
|
||||
|
||||
self.old_item = fit.implants.makeRoom(implant)
|
||||
implant.active = self.newState
|
||||
|
||||
self.oldItemID, self.oldState = fit.implants.makeRoom(implant)
|
||||
fit.implants.append(implant)
|
||||
self.new_index = fit.implants.index(implant)
|
||||
self.newIndex = fit.implants.index(implant)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
if self.old_item:
|
||||
if self.oldItemID:
|
||||
# If we had an item in the slot previously, add it back.
|
||||
cmd = FitAddImplantCommand(self.fitID, self.old_item)
|
||||
cmd = FitAddImplantCommand(self.fitID, self.oldItemID, self.oldState)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
from .fitRemoveImplant import FitRemoveImplantCommand # Avoid circular import
|
||||
cmd = FitRemoveImplantCommand(self.fitID, self.new_index)
|
||||
cmd = FitRemoveImplantCommand(self.fitID, self.newIndex)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -14,19 +14,21 @@ class FitRemoveImplantCommand(wx.Command):
|
||||
wx.Command.__init__(self, True, "Implant remove")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.old_implant = None
|
||||
self.savedItemID = None
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing implant from position ({0}) for fit ID: {1}", self.position, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
implant = fit.implants[self.position]
|
||||
self.old_implant = implant.itemID
|
||||
self.savedItemID = implant.itemID
|
||||
self.savedState = implant.active
|
||||
fit.implants.remove(implant)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitAddImplant import FitAddImplantCommand # Avoid circular import
|
||||
cmd = FitAddImplantCommand(self.fitID, self.old_implant)
|
||||
cmd = FitAddImplantCommand(self.fitID, self.savedItemID, self.savedState)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -18,7 +18,7 @@ class GuiAddImplantCommand(wx.Command):
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)):
|
||||
if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID, True)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)):
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
@@ -33,7 +33,8 @@ class GuiMetaSwapCommand(wx.Command):
|
||||
elif context == 'implantItem':
|
||||
for x in selection:
|
||||
idx = fit.implants.index(x)
|
||||
self.data.append(((FitRemoveImplantCommand, fitID, idx), (FitAddImplantCommand, fitID, itemID)))
|
||||
state = x.active
|
||||
self.data.append(((FitRemoveImplantCommand, fitID, idx), (FitAddImplantCommand, fitID, itemID, state)))
|
||||
elif context == 'boosterItem':
|
||||
for x in selection:
|
||||
idx = fit.boosters.index(x)
|
||||
|
||||
Reference in New Issue
Block a user