I apologize in advance if this is the wrong forum to post this.
Hello,
I am very very new to plugin development and using APIs in general. I am developing a very simple game randomizer for Big Box. I am using the IGameMenuItemPlugin interface and added an extra menu button on the game detail page on BigBox. So I have the logic that randomly selects an IGame object, and launches the game with the PluginHelper.BigBoxMainViewModel.ShowGame. method
So how it works is:
I would manually choose a game(game 1) and on the game detail page, I will click on the 'random game' menu button. Then the plugin will find a random game and load up the game detail page of the randomly selected game(game 2).
The issue is, if I try to exit out of the game detail page of game 2, it would go back to the game detail page of game 1. And if I try to exit out of game 1, it would send me back to game 2, so it's stuck in this weird loop between the two games.
Is this a bug? Or am I using this method wrong?
using Unbroken.LaunchBox.Plugins;
using Unbroken.LaunchBox.Plugins.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Plugindemo
{
public class DemoPluginMenuItem : IGameMenuItemPlugin
{
public bool SupportsMultipleGames
{
get { return true; }
}
public string Caption
{
get { return "Random Game";}
}
public System.Drawing.Image IconImage
{
get { return null; }
}
public bool ShowInLaunchBox
{
get { return true; }
}
public bool ShowInBigBox
{
get { return true; }
}
public bool GetIsValidForGame(IGame selectedGame)
{
return true;
}
public bool GetIsValidForGames(IGame[] selectedGames)
{
return false;
}
public void OnSelected(IGame selectedGame)
{
IPlatform[] platforms = PluginHelper.DataManager.GetAllPlatforms();
Random rand = new Random();
int index = rand.Next(platforms.Length);
IPlatform randomPlatform = platforms[index];
IGame[] platformAllGames = randomPlatform.GetAllGames(true, true);
Random gameRand = new Random();
int gameIndex = rand.Next(platformAllGames.Length);
PluginHelper.BigBoxMainViewModel.ShowGame(platformAllGames[gameIndex], FilterType.None);
}
public void OnSelected(IGame[] selectedGames)
{
return;
}
}
}