Convert implant location change to a command

This commit is contained in:
blitzmann
2018-10-28 21:59:14 -04:00
parent 50c22c836b
commit 881b92a6ea
7 changed files with 71 additions and 15 deletions

View File

@@ -77,10 +77,7 @@ class ImplantView(wx.Panel):
def OnRadioSelect(self, event):
fitID = self.mainFrame.getActiveFit()
if fitID is not None:
sFit = Fit.getInstance()
sFit.toggleImplantSource(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
self.mainFrame.command.Submit(cmd.GuiChangeImplantLocation(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER))
class ImplantDisplay(d.Display):

View File

@@ -31,4 +31,5 @@ from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
from .guiChangeDroneQty import GuiChangeDroneQty
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
from .guiToggleDrone import GuiToggleDroneCommand
from .guiFitRename import GuiFitRenameCommand
from .guiFitRename import GuiFitRenameCommand
from .guiChangeImplantLocation import GuiChangeImplantLocation

View File

@@ -0,0 +1,25 @@
import wx
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
class FitChangeImplantLocation(wx.Command):
def __init__(self, fitID, source):
wx.Command.__init__(self, True, "Drone add")
self.fitID = fitID
self.source = source
self.old_source = None
def Do(self):
pyfalog.debug("Toggling implant source for fit ID: {0}", self.fitID)
fit = eos.db.getFit(self.fitID)
self.old_source = fit.implantSource
fit.implantSource = self.source
eos.db.commit()
return True
def Undo(self):
cmd = FitChangeImplantLocation(self.fitID, self.old_source)
return cmd.Do()

View File

@@ -3,7 +3,9 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from eos.saveddata.fit import ImplantLocation
from .calc.fitAddImplant import FitAddImplantCommand
from .calc.fitChangeImplantLocation import FitChangeImplantLocation
class GuiAddImplantCommand(wx.Command):
@@ -16,7 +18,7 @@ class GuiAddImplantCommand(wx.Command):
self.itemID = itemID
def Do(self):
if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)):
if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)) 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

View File

@@ -0,0 +1,30 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .calc.fitChangeImplantLocation import FitChangeImplantLocation
class GuiChangeImplantLocation(wx.Command):
def __init__(self, fitID, source):
wx.Command.__init__(self, True, "Implant Source Change")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor()
self.fitID = fitID
self.source = source
def Do(self):
if self.internal_history.Submit(FitChangeImplantLocation(self.fitID, self.source)):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
for _ in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -424,15 +424,6 @@ class Fit(FitDeprecated):
else:
return False
def toggleImplantSource(self, fitID, source):
pyfalog.debug("Toggling implant source for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID)
fit.implantSource = source
eos.db.commit()
self.recalc(fit)
return True
def toggleRestrictionIgnore(self, fitID):
pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID)

View File

@@ -46,6 +46,16 @@ class FitDeprecated(object):
eos.db.commit()
return old_name, newName
@deprecated
def toggleImplantSource(self, fitID, source):
pyfalog.debug("Toggling implant source for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID)
fit.implantSource = source
eos.db.commit()
self.recalc(fit)
return True
@deprecated
def toggleDrone(self, fitID, i):
pyfalog.debug("Toggling drones for fit ID: {0}", fitID)