alec100_94 Posted August 13, 2017 Share Posted August 13, 2017 Hi, I have mentioned this a couple of times to no response, so after spending a long time trying to figure it out, I thought I would make a new topic about it as it's starting to annoy me. Essentially what I am trying to do is have a custom menu item (IGameMenuItem) be hidden or removed when a game that does not meet a criteria is required. I am aware that there is no built in method in the plugin system that will conveniently do this (with Show In Launch Box, only appearing to trigger on startup) and I am also aware this may be deliberate. But I feel like this should be able to work somehow, without modifying launchbox, so I attempted to access the selected games context menus directly, using the built in form features. My problem was I couldn't find where the controls were for the games, I was able to access the view that the games appear in, but this control had no relevant child controls. This has left me a little baffled as to how the primary form window in Launchbox is actually structured, and how to manipulate it. Adding a reference to the control or context menu for each game to the plugin system would be extremely useful for more advanced users, but I feel that there is probably a way to solve my problem under the current system and I'm just missing it. Knowing if this can be achieved and how to achieve it would be much appreciated. And if manipulation of the context menu has indeed been deliberately left out, and not just overlooked, I would like to know why. Launchbox is really really great software, but I have always felt it has always had these small, minor but annoying limitations, that usually make doing certain things cumbersome, and it appears this also extends to coding with the plugin system. Quote Link to comment Share on other sites More sharing options...
Lordmonkus Posted August 13, 2017 Share Posted August 13, 2017 Sorry that I cannot help you with any answers, I simply do not know anything about plugin coding. The best I can offer is a link to the Launchbox Discord channel where we have a sub channel for plugin development and there are usually a couple of very knowledgeable people in such matters that might be able to help you out with it. https://discord.gg/X3Cwsyw Quote Link to comment Share on other sites More sharing options...
eatkinola Posted August 13, 2017 Share Posted August 13, 2017 Would you please provide an example of what you're trying to do, specifically, with your custom IGameMenuItem? What game criteria are you looking to use to determine whether or not to show the menu item? Quote Link to comment Share on other sites More sharing options...
alec100_94 Posted August 13, 2017 Author Share Posted August 13, 2017 (edited) The initial post I made does seem a bit unclear reading it back, so basically all I am trying to do is hide the IGameMenuItem when it is not valid (i.e. greyed out). I want to do something like shown below, however am unsure how to actually go about hiding/showing the Menu Item. I will also check out the discord channel. public bool GetIsValidForGame(IGame selectedGame) { var emulator = PluginHelper.DataManager.GetEmulatorById(selectedGame.EmulatorId); if (emulator != null && emulator.Title == "PCSX2") { // Show Menu Item return true; } // Hide Menu Item return false; } Edited August 13, 2017 by alec100_94 Quote Link to comment Share on other sites More sharing options...
eatkinola Posted August 13, 2017 Share Posted August 13, 2017 Looks like that should work. When your method returns false, the menu item will be hidden in BigBox and disabled (grayed out) in LaunchBox. I don't think you can actually hide the menu item in LaunchBox; only disable it. Yeah check out the discord channel to see if someone has a fix, if what you're trying to do is actually hide the menu item in LB. Quote Link to comment Share on other sites More sharing options...
alec100_94 Posted August 13, 2017 Author Share Posted August 13, 2017 I know the above code works, I am actually trying to hide the item (not just disable). I was trying to do it by accessing the children of the main form, I was able to access the container window (image view), but not the individual games (hence not the context menu). To me no way of manipulating the context menus, if the developer desires, seems like a pretty big omission and could lead to some much cleaner plugins if used properly. I have joined the discord channel and posted in the plugin development section, which seems like an awesome community of LB developers. Hopefully someone on there will at least be able to clarify if it is even possible or not with the current system. Quote Link to comment Share on other sites More sharing options...
eatkinola Posted August 13, 2017 Share Posted August 13, 2017 Yes, I agree -- ideally the plugin system could be updated to allow manipulation of the context menus in LB and the menus in BB. Perhaps at the very least, IGameMenuItem could allow the developer to specify whether they'd want the menu item disabled or just hidden altogether. I hope you find the answer on discord. If you do, please make a quick reply here saying so. Quote Link to comment Share on other sites More sharing options...
alec100_94 Posted August 14, 2017 Author Share Posted August 14, 2017 (edited) Miraculously after spending about six hours trying to figure this out I was able to come up with a solution that appears to mostly work, with the small caveat that you can see the item being hidden/displayed very briefly (if used like described above), this may be possible to fix in the future, but for now this seems to work fine. The solution is quite complex (making use of reflection), but is wrapped up into an easy to use function that can be copy + pasted into virtually any IGameMenuItemPlugin. If there is a bug that I've not discovered yet, report it and it will get fixed. It seems most things with the context menu (and probably other things) can be done if you know what your doing. Though better built in support for this would be nice, I kind of understand why it's not in there. private void HideContextMenuItem(bool hide) { // Gets the context menu from Launchbox Main Form var contextMenuStripField = PluginHelper.LaunchBoxMainForm.GetType().GetField("contextMenuStrip", BindingFlags.NonPublic | BindingFlags.Instance); var contextMenuStrip = (ContextMenuStrip)contextMenuStripField.GetValue(PluginHelper.LaunchBoxMainForm); // Hides or shows the menu item with this plugins caption for (int i = 0; i < contextMenuStrip.Items.Count; ++i) { if (contextMenuStrip.Items[i].Text == Caption) { contextMenuStrip.Items[i].Visible = !hide; break; } } // If all plugins in context menu are hidden, also hide the last seperator for (int i = contextMenuStrip.Items.Count - 1, itemsHidden = 0; i > -1; --i) { if (contextMenuStrip.Items[i].GetType() == typeof(ToolStripSeparator)) { contextMenuStrip.Items[i].Visible = (itemsHidden == contextMenuStrip.Items.Count - i - 1) ? false : true; break; } if (!contextMenuStrip.Items[i].Visible) itemsHidden++; } // Write the changes to the context menu back to Launchbox Main Form contextMenuStripField.SetValue(PluginHelper.LaunchBoxMainForm, contextMenuStrip); } Edited August 15, 2017 by alec100_94 1 Quote Link to comment Share on other sites More sharing options...
eatkinola Posted August 15, 2017 Share Posted August 15, 2017 Very nice! Thanks for sharing your solution. Quote Link to comment Share on other sites More sharing options...
alec100_94 Posted August 15, 2017 Author Share Posted August 15, 2017 I fixed a bug in the above code, where it may not have hidden the separator properly. It should be pretty much ready for plug and play use (with the minor annoyance of sometimes being able to see items hide, if anyone knows a solution that would be great). This got me thinking that there are a lot of really cool things Launchbox has the potential to do, but not really particularly easily through the exposed plugin system. If @Jason Carr is not planning on extending the plugin system any time soon, then I was thinking of starting a community created helper library, primarily focused on reflection (to access non-exposed methods/fields), allowing a less experienced programmer to do some of the more complicated tasks in Launchbox, and ultimately make the plugins they want. Quote Link to comment Share on other sites More sharing options...
UnderwoodNC Posted August 16, 2017 Share Posted August 16, 2017 Are you hiding something in the toolbar menu or right-click context menu for a game? It may be easier to have it hidden by default and then only show it on games that meet the desired criteria. Seeing an option appear may be easier on the user than seeing an option disappear. Quote Link to comment Share on other sites More sharing options...
alec100_94 Posted August 16, 2017 Author Share Posted August 16, 2017 @UnderwoodNC, you could definitely try and implement it like that if you wanted and see what results you get, and the current method isn't as visually jarring as it sounds. I'll mess around with it more when I'm developing my next plugin, as the plugin I am currently working on (PCSX2 Configurator) just has the item hidden all the time with no action. If your confused to how that is useful look for my next release of said plugin, which will be released with full source code. Quote Link to comment Share on other sites More sharing options...
UnderwoodNC Posted August 16, 2017 Share Posted August 16, 2017 No problem, I'm not always around on the forums, but try to keep tabs on Discord, and saw you said you weren't getting a lot of feedback, so I wanted to reach out to help if I could. Sounds like you have it under control, though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.