diff --git a/gui/builtinContextMenus/commandFits.py b/gui/builtinContextMenus/commandFits.py new file mode 100644 index 000000000..bb26766e8 --- /dev/null +++ b/gui/builtinContextMenus/commandFits.py @@ -0,0 +1,46 @@ +# noinspection PyPackageRequirements +import wx + +from service.fit import Fit +from service.market import Market +import gui.mainFrame +from gui.contextMenu import ContextMenu +from service.settings import ContextMenuSettings + +class CommandFits(ContextMenu): + # Get list of items that define a command fit + sMkt = Market.getInstance() + grp = sMkt.getGroup(1770) # Command burst group + commandTypeIDs = [item.ID for item in grp.items] + commandFits = [] + menu = None + + @classmethod + def populateFits(cls, evt): + if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None) in cls.commandTypeIDs): + # we are adding or removing an item that defines a command fit. Need to refresh fit list + sFit = Fit.getInstance() + cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs) + print (cls.commandFits) + #todo: create menu here. + pass + + def __init__(self): + print (self.__class__.commandTypeIDs) + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.settings = ContextMenuSettings.getInstance() + + def display(self, srcContext, selection): + # todo: the whole thing + return False + + def getText(self, itmContext, selection): + return "Command Fits" + + def getSubMenu(self, context, selection, rootMenu, i, pitem): + if self.__class__.menu is None: + self.__class__.populateFits() + return self.__class__.menu + + +CommandFits.register() diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 496cf4fb8..01eb3ff66 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -334,7 +334,7 @@ class FittingView(d.Display): populate = sFit.appendModule(fitID, itemID) if populate is not None: self.slotsChanged() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID, action="modadd", typeID=itemID)) event.Skip() @@ -355,7 +355,7 @@ class FittingView(d.Display): if populate is not None: self.slotsChanged() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID)) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=module.item.ID)) def addModule(self, x, y, srcIdx): """Add a module from the market browser""" @@ -368,7 +368,8 @@ class FittingView(d.Display): if moduleChanged is None: # the new module doesn't fit in specified slot, try to simply append it wx.PostEvent(self.mainFrame, gui.marketBrowser.ItemSelected(itemID=srcIdx)) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit())) + + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=srcIdx)) def swapCargo(self, x, y, srcIdx): """Swap a module from cargo to fitting window""" @@ -379,10 +380,13 @@ class FittingView(d.Display): module = self.mods[dstRow] sFit = Fit.getInstance() + fit = sFit.getFit(self.activeFitID) + typeID = fit.cargo[srcIdx].item.ID + sFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.modPosition, srcIdx, mstate.CmdDown() and module.isEmpty) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit())) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=typeID)) def swapItems(self, x, y, srcIdx): """Swap two modules in fitting window""" diff --git a/gui/cargoView.py b/gui/cargoView.py index d997afa79..cd560c1c2 100644 --- a/gui/cargoView.py +++ b/gui/cargoView.py @@ -125,7 +125,7 @@ class CargoView(d.Display): if not mstate.CmdDown(): # if not copying, remove module sFit.removeModule(self.mainFrame.getActiveFit(), module.position) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit())) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="moddel", typeID=module.item.ID)) def fitChanged(self, event): sFit = Fit.getInstance() diff --git a/gui/commandView.py b/gui/commandView.py index d32629974..7b79f6b85 100644 --- a/gui/commandView.py +++ b/gui/commandView.py @@ -23,10 +23,11 @@ import gui.display as d import gui.globalEvents as GE import gui.droneView +import gui.marketBrowser as marketBrowser from gui.builtinViewColumns.state import State from gui.contextMenu import ContextMenu +from gui.builtinContextMenus.commandFits import CommandFits from service.fit import Fit -from service.market import Market from eos.saveddata.drone import Drone as es_Drone @@ -64,15 +65,7 @@ class CommandView(d.Display): self.lastFitId = None - # Get list of items that define a command fit - sMkt = Market.getInstance() - grp = sMkt.getGroup(1770) # Command burst group - self.commandTypeIDs = [item.ID for item in grp.items] - - sFit = Fit.getInstance() - commandFits = sFit.getFitsWithModules(self.commandTypeIDs) - print (commandFits) - + self.mainFrame.Bind(GE.FIT_CHANGED, CommandFits.populateFits) self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged) self.Bind(wx.EVT_LEFT_DOWN, self.click) self.Bind(wx.EVT_RIGHT_DOWN, self.click) diff --git a/gui/contextMenu.py b/gui/contextMenu.py index a35c73282..adfeeb324 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -205,4 +205,5 @@ from gui.builtinContextMenus import ( # noqa: E402,F401 metaSwap, implantSets, fighterAbilities, + commandFits, )