profilesPanel: fix panel switching (#1332)

* profilesPanel: fix panel switching

* profilesPanel: fix panel switching

* Update ProfilesPlugin.java

* Update ClientUI.java

* Update NavigationButton.java
This commit is contained in:
ST0NEWALL
2019-08-14 21:20:53 -04:00
committed by Kyleeld
parent 03b7254d9b
commit 2525390203
3 changed files with 63 additions and 0 deletions

View File

@@ -28,7 +28,9 @@ import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.GameState;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.plugins.Plugin;
@@ -37,6 +39,7 @@ import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import java.util.concurrent.ScheduledExecutorService;
@PluginDescriptor(
name = "Account Switcher",
@@ -51,11 +54,18 @@ public class ProfilesPlugin extends Plugin
@Inject
private ClientToolbar clientToolbar;
@Inject
private ProfilesConfig config;
@Inject
private EventBus eventBus;
@Inject
private ScheduledExecutorService executorService;
private ProfilesPanel panel;
private NavigationButton navButton;
private boolean switchToPanel;
@Provides
@@ -67,8 +77,15 @@ public class ProfilesPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
updateConfig();
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
if (this.switchToPanel)
{
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
}
panel = injector.getInstance(ProfilesPanel.class);
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "profiles_icon.png");
@@ -78,6 +95,7 @@ public class ProfilesPlugin extends Plugin
.icon(icon)
.priority(8)
.panel(panel)
.onReady(() -> executorService.submit(() -> OpenPanel(true)))
.build();
clientToolbar.addNavigation(navButton);
@@ -91,6 +109,21 @@ public class ProfilesPlugin extends Plugin
clientToolbar.removeNavigation(navButton);
}
private void onGameStateChanged(GameStateChanged event)
{
if (!this.switchToPanel)
{
return;
}
if (event.getGameState().equals(GameState.LOGIN_SCREEN))
{
if (!navButton.isSelected())
{
OpenPanel(true);
}
}
}
private void onConfigChanged(ConfigChanged event) throws Exception
{
if (event.getGroup().equals("profiles") && event.getKey().equals("rememberPassword"))
@@ -98,7 +131,27 @@ public class ProfilesPlugin extends Plugin
panel = injector.getInstance(ProfilesPanel.class);
this.shutDown();
this.startUp();
updateConfig();
}
if (event.getGroup().equals("profiles") && event.getKey().equals("switchPanel"))
{
updateConfig();
}
}
private void OpenPanel(boolean openPanel)
{
if (openPanel && this.switchToPanel)
{
// If we haven't seen the latest feed item,
// open the feed panel.
navButton.getOnSelect().run();
}
}
private void updateConfig()
{
this.switchToPanel = config.switchPanel();
}
}

View File

@@ -248,6 +248,11 @@ public class ClientUI
pluginToolbar.addComponent(event.getButton(), button);
pluginToolbar.revalidate();
}
if (navigationButton.getOnReady() != null)
{
navigationButton.getOnReady().run();
}
});
}

View File

@@ -56,6 +56,11 @@ public class NavigationButton
@Builder.Default
private final String tooltip = "";
/**
* On button having been fully initialized and added to frame.
*/
private Runnable onReady;
/**
* Button selection state
*/