diff --git a/gui/builtinAdditionPanes/boosterView.py b/gui/builtinAdditionPanes/boosterView.py index cc1f59215..0613a19f2 100644 --- a/gui/builtinAdditionPanes/boosterView.py +++ b/gui/builtinAdditionPanes/boosterView.py @@ -135,7 +135,7 @@ class BoosterView(d.Display): event.Skip() return - if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID, event.itemID)): + if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID=fitID, itemID=event.itemID)): self.mainFrame.additionsPane.select("Boosters") event.Skip() @@ -149,7 +149,7 @@ class BoosterView(d.Display): def removeBooster(self, booster): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, self.original.index(booster))) + self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID=fitID, position=self.original.index(booster))) def click(self, event): event.Skip() @@ -158,7 +158,8 @@ class BoosterView(d.Display): col = self.getColumn(event.Position) if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiToggleBoosterStateCommand(fitID, row)) + booster = self.boosters[self.GetItemData(row)] + self.mainFrame.command.Submit(cmd.GuiToggleBoosterStateCommand(fitID=fitID, position=self.original.index(booster))) def spawnMenu(self, event): sel = self.GetFirstSelected() diff --git a/gui/builtinAdditionPanes/implantView.py b/gui/builtinAdditionPanes/implantView.py index 3e1eac090..7d4a82954 100644 --- a/gui/builtinAdditionPanes/implantView.py +++ b/gui/builtinAdditionPanes/implantView.py @@ -218,7 +218,8 @@ class ImplantDisplay(d.Display): col = self.getColumn(event.Position) if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(fitID, row)) + implant = self.implants[self.GetItemData(row)] + self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(fitID=fitID, position=self.original.index(implant))) def spawnMenu(self, event): sel = self.GetFirstSelected() diff --git a/gui/builtinContextMenus/metaSwap.py b/gui/builtinContextMenus/metaSwap.py index a1422c8d6..6d61aa7aa 100644 --- a/gui/builtinContextMenus/metaSwap.py +++ b/gui/builtinContextMenus/metaSwap.py @@ -130,23 +130,19 @@ class MetaSwap(ContextMenu): return fitID = self.mainFrame.getActiveFit() + fit = Fit.getInstance().getFit(fitID) - self.mainFrame.command.Submit(cmd.GuiMetaSwapCommand(fitID, context, item.ID, self.selection)) + if context == 'implantItem': + position = fit.implants.index(self.selection[0]) + self.mainFrame.command.Submit(cmd.GuiSwapImplantMetaCommand( + fitID=fitID, position=position, itemID=item.ID)) + if context == 'boosterItem': + position = fit.boosters.index(self.selection[0]) + self.mainFrame.command.Submit(cmd.GuiSwapBoosterMetaCommand( + fitID=fitID, position=position, itemID=item.ID)) + else: + self.mainFrame.command.Submit(cmd.GuiMetaSwapCommand(fitID, context, item.ID, self.selection)) - # for selected_item in self.selection: - - # - # elif isinstance(selected_item, Drone): - # drone_count = None - # - # for idx, drone_stack in enumerate(fit.drones): - # if drone_stack is selected_item: - # drone_count = drone_stack.amount - # sFit.removeDrone(fitID, idx, drone_count, False) - # break - # - # if drone_count: - # sFit.addDrone(fitID, item.ID, drone_count, True) MetaSwap.register() diff --git a/gui/builtinViews/implantEditor.py b/gui/builtinViews/implantEditor.py index d33ff9779..abb3ad3cd 100644 --- a/gui/builtinViews/implantEditor.py +++ b/gui/builtinViews/implantEditor.py @@ -121,7 +121,7 @@ class BaseImplantEditorView(wx.Panel): def update(self): """Updates implant list based off the current context""" - self.implants = self.getImplantsFromContext() + self.implants = self.getImplantsFromContext()[:] self.implants.sort(key=lambda i: int(i.getModifiedItemAttr("implantness"))) self.pluggedImplantsTree.update(self.implants) diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 1aa65ddd8..7cbeef8bc 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -1,4 +1,5 @@ from .gui.booster.add import GuiAddBoosterCommand +from .gui.booster.metaSwap import GuiSwapBoosterMetaCommand from .gui.booster.remove import GuiRemoveBoosterCommand from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand from .gui.booster.toggleState import GuiToggleBoosterStateCommand @@ -15,6 +16,7 @@ from .gui.guiModuleToCargo import GuiModuleToCargoCommand from .gui.guiSwapCloneModule import GuiModuleSwapOrCloneCommand from .gui.implant.add import GuiAddImplantCommand from .gui.implant.changeLocation import GuiChangeImplantLocationCommand +from .gui.implant.metaSwap import GuiSwapImplantMetaCommand from .gui.implant.remove import GuiRemoveImplantCommand from .gui.implant.toggleState import GuiToggleImplantStateCommand from .gui.itemsRebase import GuiRebaseItemsCommand diff --git a/gui/fitCommands/gui/booster/metaSwap.py b/gui/fitCommands/gui/booster/metaSwap.py new file mode 100644 index 000000000..0829ab445 --- /dev/null +++ b/gui/fitCommands/gui/booster/metaSwap.py @@ -0,0 +1,40 @@ +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.booster.add import CalcAddBoosterCommand +from gui.fitCommands.helpers import BoosterInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiSwapBoosterMetaCommand(wx.Command): + + def __init__(self, fitID, position, itemID): + wx.Command.__init__(self, True, 'Swap Booster Meta') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.position = position + self.itemID = itemID + + def Do(self): + sFit = Fit.getInstance() + booster = sFit.getFit(self.fitID).boosters[self.position] + if booster.itemID == self.itemID: + return False + cmd = CalcAddBoosterCommand( + fitID=self.fitID, + boosterInfo=BoosterInfo( + itemID=self.itemID, + state=booster.active, + sideEffects={se.effectID: se.active for se in booster.sideEffects})) + if self.internalHistory.submit(cmd): + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + success = self.internalHistory.undoAll() + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success diff --git a/gui/fitCommands/gui/implant/metaSwap.py b/gui/fitCommands/gui/implant/metaSwap.py new file mode 100644 index 000000000..5f984c58d --- /dev/null +++ b/gui/fitCommands/gui/implant/metaSwap.py @@ -0,0 +1,35 @@ +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calc.implant.add import CalcAddImplantCommand +from gui.fitCommands.helpers import ImplantInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiSwapImplantMetaCommand(wx.Command): + + def __init__(self, fitID, position, itemID): + wx.Command.__init__(self, True, 'Swap Implant Meta') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.position = position + self.itemID = itemID + + def Do(self): + sFit = Fit.getInstance() + implant = sFit.getFit(self.fitID).implants[self.position] + if implant.itemID == self.itemID: + return False + cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID, state=implant.active)) + if self.internalHistory.submit(cmd): + sFit.recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + success = self.internalHistory.undoAll() + Fit.getInstance().recalc(self.fitID) + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success diff --git a/service/character.py b/service/character.py index 7e95c5f82..37103a448 100644 --- a/service/character.py +++ b/service/character.py @@ -411,6 +411,7 @@ class Character(object): return implant = es_Implant(eos.db.getItem(itemID)) + char.implants.makeRoom(implant) char.implants.append(implant) eos.db.commit() diff --git a/service/implantSet.py b/service/implantSet.py index 8d86c816d..b3440de6b 100644 --- a/service/implantSet.py +++ b/service/implantSet.py @@ -55,6 +55,7 @@ class ImplantSets(object): def addImplant(setID, itemID): implant_set = eos.db.getImplantSet(setID) implant = es_Implant(eos.db.getItem(itemID)) + implant_set.implants.makeRoom(implant) implant_set.implants.append(implant) eos.db.commit()