Make toggling ignore of restrictions undoable
This commit is contained in:
@@ -550,6 +550,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
if not fits and fit.ignoreRestrictions:
|
||||
self.restrictionOverridden = True
|
||||
fits = True
|
||||
elif fits and fit.ignoreRestrictions:
|
||||
self.restrictionOverridden = False
|
||||
|
||||
return fits
|
||||
|
||||
|
||||
@@ -758,21 +758,25 @@ class FittingView(d.Display):
|
||||
self.SetItemBackgroundColour(i, self.GetBackgroundColour())
|
||||
|
||||
# only consider changing color if we're dealing with a Module
|
||||
if type(mod) is Module:
|
||||
hasRestrictionOverriden = getattr(mod, 'restrictionOverridden', None)
|
||||
# If module had broken fitting restrictions but now doesn't,
|
||||
# ensure it is now valid, and remove restrictionOverridden
|
||||
# variable. More in #1519
|
||||
if not fit.ignoreRestrictions and hasRestrictionOverriden:
|
||||
clean = False
|
||||
if mod.fits(fit, False):
|
||||
if not mod.hardpoint:
|
||||
clean = True
|
||||
elif fit.getHardpointsFree(mod.hardpoint) >= 0:
|
||||
clean = True
|
||||
if clean:
|
||||
del mod.restrictionOverridden
|
||||
hasRestrictionOverriden = not hasRestrictionOverriden
|
||||
if isinstance(mod, Module):
|
||||
hasRestrictionOverriden = False
|
||||
if not mod.isEmpty:
|
||||
fits = mod.fits(fit, False)
|
||||
hasRestrictionOverriden = getattr(mod, 'restrictionOverridden', None)
|
||||
# If module had broken fitting restrictions but now doesn't,
|
||||
# ensure it is now valid, and remove restrictionOverridden
|
||||
# variable. More in #1519
|
||||
if not fit.ignoreRestrictions and hasRestrictionOverriden:
|
||||
clean = False
|
||||
if fits:
|
||||
if not mod.hardpoint:
|
||||
clean = True
|
||||
elif fit.getHardpointsFree(mod.hardpoint) >= 0:
|
||||
clean = True
|
||||
if clean:
|
||||
del mod.restrictionOverridden
|
||||
hasRestrictionOverriden = not hasRestrictionOverriden
|
||||
|
||||
|
||||
if slotMap[mod.slot] or hasRestrictionOverriden: # Color too many modules as red
|
||||
self.SetItemBackgroundColour(i, wx.Colour(204, 51, 51))
|
||||
|
||||
@@ -11,6 +11,7 @@ from .gui.commandFit.add import GuiAddCommandFitCommand
|
||||
from .gui.commandFit.remove import GuiRemoveCommandFitsCommand
|
||||
from .gui.commandFit.toggleStates import GuiToggleCommandFitStatesCommand
|
||||
from .gui.fitRename import GuiRenameFitCommand
|
||||
from .gui.fitRestrictionToggle import GuiToggleFittingRestrictionsCommand
|
||||
from .gui.implant.add import GuiAddImplantCommand
|
||||
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
|
||||
from .gui.implant.changeMeta import GuiChangeImplantMetaCommand
|
||||
|
||||
45
gui/fitCommands/gui/fitRestrictionToggle.py
Normal file
45
gui/fitCommands/gui/fitRestrictionToggle.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
|
||||
|
||||
|
||||
class GuiToggleFittingRestrictionsCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID):
|
||||
wx.Command.__init__(self, True, 'Toggle Fitting Restrictions')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
|
||||
def Do(self):
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
fit.ignoreRestrictions = not fit.ignoreRestrictions
|
||||
|
||||
success = True
|
||||
if not fit.ignoreRestrictions:
|
||||
results = []
|
||||
for position, mod in sorted(enumerate(fit.modules), key=lambda i: i[0], reverse=True):
|
||||
if not mod.isEmpty and not mod.fits(fit, hardpointLimit=False):
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[position], commit=False)
|
||||
results.append(self.internalHistory.submit(cmd))
|
||||
if len(results) > 0:
|
||||
success = any(results)
|
||||
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
fit.ignoreRestrictions = not fit.ignoreRestrictions
|
||||
success = self.internalHistory.undoAll()
|
||||
eos.db.commit()
|
||||
sFit.recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
@@ -604,8 +604,7 @@ class MainFrame(wx.Frame):
|
||||
result = dlg.ShowModal() == wx.ID_YES
|
||||
dlg.Destroy()
|
||||
if result:
|
||||
sFit.toggleRestrictionIgnore(fitID)
|
||||
wx.PostEvent(self, GE.FitChanged(fitID=fitID))
|
||||
self.command.Submit(cmd.GuiToggleFittingRestrictionsCommand(fitID=fitID))
|
||||
|
||||
def eveFittings(self, event):
|
||||
dlg = EveFittings(self)
|
||||
|
||||
@@ -346,21 +346,6 @@ class Fit(FitDeprecated):
|
||||
eos.db.commit()
|
||||
return mutator.value
|
||||
|
||||
def toggleRestrictionIgnore(self, fitID):
|
||||
pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID)
|
||||
fit = eos.db.getFit(fitID)
|
||||
fit.ignoreRestrictions = not fit.ignoreRestrictions
|
||||
|
||||
# remove invalid modules when switching back to enabled fitting restrictions
|
||||
if not fit.ignoreRestrictions:
|
||||
for m in fit.modules:
|
||||
if not m.isEmpty and not m.fits(fit, False):
|
||||
self.removeModule(fit.ID, m.modPosition)
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def changeChar(self, fitID, charID):
|
||||
pyfalog.debug("Changing character ({0}) for fit ID: {1}", charID, fitID)
|
||||
if fitID is None or charID is None:
|
||||
|
||||
Reference in New Issue
Block a user