From a829efa7ff5f1b2c88f57726a5aba87e2089f88a Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 14 Apr 2019 15:36:30 +0300 Subject: [PATCH] Rework implant UI commands --- gui/builtinAdditionPanes/implantView.py | 2 +- gui/fitCommands/__init__.py | 8 ++--- gui/fitCommands/guiAddImplant.py | 36 ------------------- gui/fitCommands/guiChangeImplantLocation.py | 30 ---------------- gui/fitCommands/guiToggleImplant.py | 30 ---------------- gui/fitCommands/implant/__init__.py | 0 gui/fitCommands/implant/add.py | 34 ++++++++++++++++++ gui/fitCommands/implant/changeLocation.py | 29 +++++++++++++++ .../remove.py} | 20 +++++------ gui/fitCommands/implant/toggleState.py | 29 +++++++++++++++ 10 files changed, 107 insertions(+), 111 deletions(-) delete mode 100644 gui/fitCommands/guiAddImplant.py delete mode 100644 gui/fitCommands/guiChangeImplantLocation.py delete mode 100644 gui/fitCommands/guiToggleImplant.py create mode 100644 gui/fitCommands/implant/__init__.py create mode 100644 gui/fitCommands/implant/add.py create mode 100644 gui/fitCommands/implant/changeLocation.py rename gui/fitCommands/{guiRemoveImplant.py => implant/remove.py} (50%) create mode 100644 gui/fitCommands/implant/toggleState.py diff --git a/gui/builtinAdditionPanes/implantView.py b/gui/builtinAdditionPanes/implantView.py index 5a6db2ff4..1e80d3db2 100644 --- a/gui/builtinAdditionPanes/implantView.py +++ b/gui/builtinAdditionPanes/implantView.py @@ -218,7 +218,7 @@ class ImplantDisplay(d.Display): col = self.getColumn(event.Position) if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiToggleImplantCommand(fitID, row)) + self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(fitID, row)) def spawnMenu(self, event): sel = self.GetFirstSelected() diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index ea60de870..a8ee6a34b 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -7,14 +7,12 @@ from .guiAddCharge import GuiModuleAddChargeCommand from .guiAddCommand import GuiAddCommandCommand from .guiAddDrone import GuiAddDroneCommand from .guiAddFighter import GuiAddFighterCommand -from .guiAddImplant import GuiAddImplantCommand from .guiAddModule import GuiModuleAddCommand from .guiAddProjected import GuiAddProjectedCommand from .guiCargoToModule import GuiCargoToModuleCommand from .guiChangeCargoQty import GuiChangeCargoQty from .guiChangeDroneQty import GuiChangeDroneQty from .guiChangeFighterQty import GuiChangeFighterQty -from .guiChangeImplantLocation import GuiChangeImplantLocation from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty from .guiChangeProjectedFighterAmount import GuiChangeProjectedFighterAmount from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty @@ -30,7 +28,6 @@ from .guiRemoveCargo import GuiRemoveCargoCommand from .guiRemoveCommand import GuiRemoveCommandCommand from .guiRemoveDrone import GuiRemoveDroneCommand from .guiRemoveFighter import GuiRemoveFighterCommand -from .guiRemoveImplant import GuiRemoveImplantCommand from .guiRemoveModule import GuiModuleRemoveCommand from .guiRemoveProjected import GuiRemoveProjectedCommand from .guiSetMode import GuiSetModeCommand @@ -40,6 +37,9 @@ from .guiToggleCommand import GuiToggleCommandCommand from .guiToggleDrone import GuiToggleDroneCommand from .guiToggleFighter import GuiToggleFighterCommand from .guiToggleFighterAbility import GuiToggleFighterAbilityCommand -from .guiToggleImplant import GuiToggleImplantCommand from .guiToggleModuleState import GuiModuleStateChangeCommand from .guiToggleProjected import GuiToggleProjectedCommand +from .implant.add import GuiAddImplantCommand +from .implant.changeLocation import GuiChangeImplantLocation +from .implant.remove import GuiRemoveImplantCommand +from .implant.toggleState import GuiToggleImplantStateCommand diff --git a/gui/fitCommands/guiAddImplant.py b/gui/fitCommands/guiAddImplant.py deleted file mode 100644 index 24e6e4078..000000000 --- a/gui/fitCommands/guiAddImplant.py +++ /dev/null @@ -1,36 +0,0 @@ -import wx -from service.fit import Fit - -import gui.mainFrame -from eos.const import ImplantLocation -from gui import globalEvents as GE -from gui.fitCommands.helpers import ImplantInfo -from .calcCommands.implant.add import CalcAddImplantCommand -from .calcCommands.implant.changeLocation import CalcChangeImplantLocationCommand - - -class GuiAddImplantCommand(wx.Command): - def __init__(self, fitID, itemID): - wx.Command.__init__(self, True, "Implant Add") - self.mainFrame = gui.mainFrame.MainFrame.getInstance() - self.sFit = Fit.getInstance() - self.internal_history = wx.CommandProcessor() - self.fitID = fitID - self.itemID = itemID - - def Do(self): - if ( - self.internal_history.Submit(CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID))) and - self.internal_history.Submit(CalcChangeImplantLocationCommand(self.fitID, ImplantLocation.FIT)) - ): - 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 diff --git a/gui/fitCommands/guiChangeImplantLocation.py b/gui/fitCommands/guiChangeImplantLocation.py deleted file mode 100644 index 1a5e35d7e..000000000 --- a/gui/fitCommands/guiChangeImplantLocation.py +++ /dev/null @@ -1,30 +0,0 @@ -import wx -from service.fit import Fit - -import gui.mainFrame -from gui import globalEvents as GE -from .calcCommands.implant.changeLocation import CalcChangeImplantLocationCommand - - -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(CalcChangeImplantLocationCommand(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 diff --git a/gui/fitCommands/guiToggleImplant.py b/gui/fitCommands/guiToggleImplant.py deleted file mode 100644 index 80b8053c9..000000000 --- a/gui/fitCommands/guiToggleImplant.py +++ /dev/null @@ -1,30 +0,0 @@ -import wx -from service.fit import Fit - -import gui.mainFrame -from gui import globalEvents as GE -from .calcCommands.implant.toggleState import CalcToggleImplantStateCommand - - -class GuiToggleImplantCommand(wx.Command): - def __init__(self, fitID, position): - wx.Command.__init__(self, True, "") - self.mainFrame = gui.mainFrame.MainFrame.getInstance() - self.sFit = Fit.getInstance() - self.internal_history = wx.CommandProcessor() - self.fitID = fitID - self.position = position - - def Do(self): - if self.internal_history.Submit(CalcToggleImplantStateCommand(self.fitID, self.position)): - 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 diff --git a/gui/fitCommands/implant/__init__.py b/gui/fitCommands/implant/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gui/fitCommands/implant/add.py b/gui/fitCommands/implant/add.py new file mode 100644 index 000000000..7f5e48125 --- /dev/null +++ b/gui/fitCommands/implant/add.py @@ -0,0 +1,34 @@ +import wx + +import gui.mainFrame +from eos.const import ImplantLocation +from gui import globalEvents as GE +from gui.fitCommands.calcCommands.implant.add import CalcAddImplantCommand +from gui.fitCommands.calcCommands.implant.changeLocation import CalcChangeImplantLocationCommand +from gui.fitCommands.helpers import ImplantInfo, InternalCommandHistory +from service.fit import Fit + + +class GuiAddImplantCommand(wx.Command): + + def __init__(self, fitID, itemID): + wx.Command.__init__(self, True, 'Add Implant') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.itemID = itemID + + def Do(self): + if ( + self.internalHistory.submit(CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID))) and + self.internalHistory.submit(CalcChangeImplantLocationCommand(fitID=self.fitID, source=ImplantLocation.FIT)) + ): + Fit.getInstance().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/implant/changeLocation.py b/gui/fitCommands/implant/changeLocation.py new file mode 100644 index 000000000..7f3e08848 --- /dev/null +++ b/gui/fitCommands/implant/changeLocation.py @@ -0,0 +1,29 @@ +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calcCommands.implant.changeLocation import CalcChangeImplantLocationCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit + + +class GuiChangeImplantLocation(wx.Command): + + def __init__(self, fitID, source): + wx.Command.__init__(self, True, 'Change Implant Location') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.source = source + + def Do(self): + if self.internalHistory.submit(CalcChangeImplantLocationCommand(fitID=self.fitID, source=self.source)): + Fit.getInstance().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/guiRemoveImplant.py b/gui/fitCommands/implant/remove.py similarity index 50% rename from gui/fitCommands/guiRemoveImplant.py rename to gui/fitCommands/implant/remove.py index f6d90bb7a..abc1e33f9 100644 --- a/gui/fitCommands/guiRemoveImplant.py +++ b/gui/fitCommands/implant/remove.py @@ -3,28 +3,28 @@ from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from .calcCommands.implant.remove import CalcRemoveImplantCommand +from gui.fitCommands.helpers import InternalCommandHistory +from gui.fitCommands.calcCommands.implant.remove import CalcRemoveImplantCommand class GuiRemoveImplantCommand(wx.Command): + def __init__(self, fitID, position): - wx.Command.__init__(self, True, "") + wx.Command.__init__(self, True, 'Remove Implant') self.mainFrame = gui.mainFrame.MainFrame.getInstance() - self.sFit = Fit.getInstance() - self.internal_history = wx.CommandProcessor() + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.position = position def Do(self): - if self.internal_history.Submit(CalcRemoveImplantCommand(self.fitID, self.position)): - self.sFit.recalc(self.fitID) + if self.internalHistory.submit(CalcRemoveImplantCommand(fitID=self.fitID, position=self.position)): + Fit.getInstance().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) + success = self.internalHistory.undoAll() + Fit.getInstance().recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/implant/toggleState.py b/gui/fitCommands/implant/toggleState.py new file mode 100644 index 000000000..29dad70c8 --- /dev/null +++ b/gui/fitCommands/implant/toggleState.py @@ -0,0 +1,29 @@ +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calcCommands.implant.toggleState import CalcToggleImplantStateCommand +from gui.fitCommands.helpers import InternalCommandHistory +from service.fit import Fit + + +class GuiToggleImplantStateCommand(wx.Command): + + def __init__(self, fitID, position): + wx.Command.__init__(self, True, 'Toggle Implant State') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.position = position + + def Do(self): + if self.internalHistory.submit(CalcToggleImplantStateCommand(fitID=self.fitID, position=self.position)): + Fit.getInstance().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