kourendlibrary: Make hiding the navbutton optional

This commit is contained in:
Max Weber
2018-06-21 12:36:15 -06:00
parent d60b395d5c
commit ef9bc957cb
2 changed files with 98 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018 Abex
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.kourendlibrary;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup(
keyName = "kourendLibrary",
name = "Kourend Library",
description = "Configuration for the KourendLibrary plugin"
)
public interface KourendLibraryConfig extends Config
{
String GROUP_KEY = "kourendLibrary";
@ConfigItem(
keyName = "hideButton",
name = "Hide when outside of the library",
description = "Don't show the button in the sidebar when your not in the library"
)
default boolean hideButton()
{
return true;
}
}

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.kourendlibrary;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,13 +37,16 @@ import net.runelite.api.AnimationID;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -75,6 +79,9 @@ public class KourendLibraryPlugin extends Plugin
@Inject
private KourendLibraryOverlay overlay;
@Inject
private KourendLibraryConfig config;
@Inject
private ItemManager itemManager;
@@ -85,6 +92,12 @@ public class KourendLibraryPlugin extends Plugin
private WorldPoint lastBookcaseClick = null;
private WorldPoint lastBookcaseAnimatedOn = null;
@Provides
KourendLibraryConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(KourendLibraryConfig.class);
}
@Override
protected void startUp() throws Exception
{
@@ -106,6 +119,41 @@ public class KourendLibraryPlugin extends Plugin
.icon(icon)
.panel(panel)
.build();
if (!config.hideButton())
{
pluginToolbar.addNavigation(navButton);
}
}
@Subscribe
public void onConfigChanged(ConfigChanged ev)
{
if (!KourendLibraryConfig.GROUP_KEY.equals(ev.getGroup()))
{
return;
}
SwingUtilities.invokeLater(() ->
{
if (!config.hideButton())
{
pluginToolbar.addNavigation(navButton);
}
else
{
Player lp = client.getLocalPlayer();
boolean inRegion = lp != null && lp.getWorldLocation().getRegionID() == REGION;
if (inRegion)
{
pluginToolbar.addNavigation(navButton);
}
else
{
pluginToolbar.removeNavigation(navButton);
}
}
});
}
@Override
@@ -155,7 +203,7 @@ public class KourendLibraryPlugin extends Plugin
void onTick(GameTick tick)
{
boolean inRegion = client.getLocalPlayer().getWorldLocation().getRegionID() == REGION;
if (inRegion != buttonAttached)
if (config.hideButton() && inRegion != buttonAttached)
{
SwingUtilities.invokeLater(() ->
{