diff --git a/gui/builtinContextMenus/implantSets.py b/gui/builtinContextMenus/implantSets.py index c96080983..6ae43039b 100644 --- a/gui/builtinContextMenus/implantSets.py +++ b/gui/builtinContextMenus/implantSets.py @@ -1,6 +1,4 @@ from gui.contextMenu import ContextMenu -from gui.itemStats import ItemStatsDialog -import eos.types import gui.mainFrame import service import gui.globalEvents as GE @@ -11,18 +9,36 @@ class ImplantSets(ContextMenu): self.mainFrame = gui.mainFrame.MainFrame.getInstance() def display(self, srcContext, selection): - return srcContext == "implantView" + return srcContext in ("implantView", "implantEditor") def getText(self, itmContext, selection): return "Add Implant Set" def getSubMenu(self, context, selection, rootMenu, i, pitem): + """ + A note on the selection here: Most context menus act on a fit, so it's easy enough to get the active fit from + the MainFrame instance. There's never been a reason to get info from another window, so there's not common + way of doing this. However, we use this context menu within the Character Editor to apply implant sets to a + character, so we need to access the character editor. + + It is for these reasons that I hijack the selection parameter when calling the menu and pass a pointer to the + Character Editor. This way we can use it to get current editing character ID and apply the implants. + + It would probably be better to have a function on the MainFrame to get the currently open Character Editor (as + we do with the item stats window). Eventually... Until then, this long ass note will remain to remind me why + stupid shit like this is even happening. + """ + m = wx.Menu() bindmenu = rootMenu if "wxMSW" in wx.PlatformInfo else m sIS = service.ImplantSets.getInstance() implantSets = sIS.getImplantSetList() + self.context = context + if len(selection) == 1: + self.selection = selection[0] # dirty hack here + self.idmap = {} for set in implantSets: @@ -41,13 +57,22 @@ class ImplantSets(ContextMenu): event.Skip() return - sFit = service.Fit.getInstance() - fitID = self.mainFrame.getActiveFit() - for implant in set.implants: - print implant.item.ID, implant.item.name - sFit.addImplant(fitID, implant.item.ID) + if self.context == "implantEditor": + # we are calling from character editor, the implant source is different + sChar = service.Character.getInstance() + charID = self.selection.getActiveCharacter() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + for implant in set.implants: + sChar.addImplant(charID, implant.item.ID) + + wx.PostEvent(self.selection, GE.CharChanged()) + else: + sFit = service.Fit.getInstance() + fitID = self.mainFrame.getActiveFit() + for implant in set.implants: + sFit.addImplant(fitID, implant.item.ID, recalc=implant == set.implants[-1]) + + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) ImplantSets.register() diff --git a/gui/builtinContextMenus/itemStats.py b/gui/builtinContextMenus/itemStats.py index 40e94164c..3fde45c97 100644 --- a/gui/builtinContextMenus/itemStats.py +++ b/gui/builtinContextMenus/itemStats.py @@ -9,6 +9,7 @@ class ItemStats(ContextMenu): self.mainFrame = gui.mainFrame.MainFrame.getInstance() def display(self, srcContext, selection): + return srcContext in ("marketItemGroup", "marketItemMisc", "fittingModule", "fittingCharge", "fittingShip", "baseShip", diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 697862146..4be9fc5ee 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -460,6 +460,11 @@ class ImplantEditorView(BaseImplantEditorView): def __init__(self, parent): BaseImplantEditorView.__init__ (self, parent) + if "__WXGTK__" in wx.PlatformInfo: + self.pluggedImplantsTree.Bind(wx.EVT_RIGHT_UP, self.scheduleMenu) + else: + self.pluggedImplantsTree.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu) + def bindContext(self): self.Parent.Parent.Bind(GE.CHAR_CHANGED, self.contextChanged) @@ -481,6 +486,17 @@ class ImplantEditorView(BaseImplantEditorView): sChar.removeImplant(charID, self.implants[pos]) + def scheduleMenu(self, event): + event.Skip() + wx.CallAfter(self.spawnMenu) + + def spawnMenu(self): + context = (("implantEditor",),) + # fuck good coding practices, passing a pointer to the character editor here for [reasons] =D + # (see implantSets context class for info) + menu = ContextMenu.getMenu((self.Parent.Parent,), *context) + self.PopupMenu(menu) + class APIView (wx.Panel): def __init__(self, parent): diff --git a/service/fit.py b/service/fit.py index ae1d4ec40..f2ddd7523 100644 --- a/service/fit.py +++ b/service/fit.py @@ -277,7 +277,7 @@ class Fit(object): fit.timestamp)) return fits - def addImplant(self, fitID, itemID): + def addImplant(self, fitID, itemID, recalc=True): if fitID is None: return False @@ -289,7 +289,8 @@ class Fit(object): return False fit.implants.append(implant) - self.recalc(fit) + if recalc: + self.recalc(fit) return True def removeImplant(self, fitID, position):