Remove character editor implant set context menu hack as it's no longer needed

This commit is contained in:
DarkPhoenix
2019-07-30 19:20:14 +03:00
parent cd20164d7a
commit 2aa274f56f
2 changed files with 11 additions and 27 deletions

View File

@@ -4,17 +4,17 @@ import wx
import gui.fitCommands as cmd
import gui.globalEvents as GE
import gui.mainFrame
from gui.contextMenu import ContextMenuSingle
from gui.contextMenu import ContextMenuUnconditional
from service.character import Character
from service.implantSet import ImplantSets as s_ImplantSets
class AddImplantSet(ContextMenuSingle):
class AddImplantSet(ContextMenuUnconditional):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, callingWindow, srcContext, mainItem):
def display(self, callingWindow, srcContext):
sIS = s_ImplantSets.getInstance()
implantSets = sIS.getImplantSetList()
@@ -23,24 +23,10 @@ class AddImplantSet(ContextMenuSingle):
return False
return srcContext in ("implantView", "implantEditor")
def getText(self, callingWindow, itmContext, mainItem):
def getText(self, callingWindow, itmContext):
return "Add Implant Set"
def getSubMenu(self, callingWindow, context, mainItem, rootMenu, i, pitem):
"""
A note on the mainItem 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 mainItem 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.
"""
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
m = wx.Menu()
bindmenu = rootMenu if "wxMSW" in wx.PlatformInfo else m
@@ -48,12 +34,12 @@ class AddImplantSet(ContextMenuSingle):
implantSets = sIS.getImplantSetList()
self.context = context
self.mainItem = mainItem # dirty hack here
self.callingWindow = callingWindow
self.idmap = {}
for set in sorted(implantSets, key=lambda i: i.name):
id = ContextMenuSingle.nextID()
id = ContextMenuUnconditional.nextID()
mitem = wx.MenuItem(rootMenu, id, set.name)
bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem)
self.idmap[id] = set
@@ -69,14 +55,15 @@ class AddImplantSet(ContextMenuSingle):
return
if self.context == "implantEditor":
charEditor = self.callingWindow.Parent.Parent
# we are calling from character editor, the implant source is different
sChar = Character.getInstance()
char = self.mainItem.entityEditor.getActiveEntity()
char = charEditor.entityEditor.getActiveEntity()
for implant in set.implants:
sChar.addImplant(char.ID, implant.item.ID)
wx.PostEvent(self.mainItem, GE.CharChanged())
wx.PostEvent(charEditor, GE.CharChanged())
else:
self.mainFrame.command.Submit(cmd.GuiAddImplantSetCommand(
fitID=self.mainFrame.getActiveFit(),

View File

@@ -710,10 +710,7 @@ class ImplantEditorView(BaseImplantEditorView):
def spawnMenu(self, event):
context = (("implantEditor",),)
# fuck good coding practices, passing a pointer to the character editor here for [reasons] =D
# (see implantSets context class for info)
item = self.Parent.Parent
menu = ContextMenu.getMenu(self, item, (item,), *context)
menu = ContextMenu.getMenu(self, None, None, *context)
if menu:
self.PopupMenu(menu)