Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self hiding panel button #188

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/botdetector/BotDetectorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface BotDetectorConfig extends Config
String ANONYMOUS_UUID_KEY = "anonymousUUID";
String ACKNOWLEDGED_HARASSMENT_WARNING_KEY = "acknowledgedHarassmentWarning";

String HIDE_PANEL_NAVIGATION_BUTTON_KEY = "hidePanelNavigationButton";

int AUTO_SEND_MINIMUM_MINUTES = 5;
int AUTO_SEND_MAXIMUM_MINUTES = 360;

Expand Down Expand Up @@ -222,6 +224,21 @@ default PanelFontType panelFontType()
return PanelFontType.NORMAL;
}

@ConfigItem(
position = 6,
keyName = HIDE_PANEL_NAVIGATION_BUTTON_KEY,
name = "Hide Panel Navigation Button",
description = "Hides the panel navigation button on the Runelite sidebar when not in use.",
warning = "<html><span style='color:red'>WARNING:</span> This feature is experimental, please report any issues on our github!" +
"<br><br>If the panel navigation button is hidden, the only way to use the plugin side panel is to use some variation" +
"<br>of the right-click 'Predict' option or to input the <b>::BDOpenPanel</b> or <b>::BDOpen</b> command in chat.</html>",
section = panelSection
)
default boolean hidePanelNavigationButton()
{
return false;
}

@ConfigItem(
position = 1,
keyName = ADD_PREDICT_PLAYER_OPTION_KEY,
Expand Down
54 changes: 48 additions & 6 deletions src/main/java/com/botdetector/BotDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
package com.botdetector;

import com.botdetector.events.BotDetectorPanelDeactivated;
import com.botdetector.http.BotDetectorClient;
import com.botdetector.http.UnauthorizedTokenException;
import com.botdetector.http.ValidationException;
Expand Down Expand Up @@ -167,6 +168,8 @@ public class BotDetectorPlugin extends Plugin
private static final String CLEAR_AUTH_TOKEN_COMMAND = COMMAND_PREFIX + "ClearToken";
private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND = COMMAND_PREFIX + "ToggleShowDiscordVerificationErrors";
private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS = COMMAND_PREFIX + "ToggleDVE";
private static final String OPEN_PANEL_COMMAND = COMMAND_PREFIX + "OpenPanel";
private static final String OPEN_PANEL_COMMAND_ALIAS = COMMAND_PREFIX + "Open";

/** Command to method map to be used in {@link #onCommandExecuted(CommandExecuted)}. **/
private final ImmutableMap<CaseInsensitiveString, Consumer<String[]>> commandConsumerMap =
Expand All @@ -180,6 +183,8 @@ public class BotDetectorPlugin extends Plugin
.put(wrap(CLEAR_AUTH_TOKEN_COMMAND), s -> clearAuthTokenCommand())
.put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND), s -> toggleShowDiscordVerificationErrors())
.put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS), s -> toggleShowDiscordVerificationErrors())
.put(wrap(OPEN_PANEL_COMMAND), s -> openSidePanel())
.put(wrap(OPEN_PANEL_COMMAND_ALIAS), s -> openSidePanel())
.build();

private static final int MANUAL_FLUSH_COOLDOWN_SECONDS = 60;
Expand Down Expand Up @@ -350,7 +355,10 @@ protected void startUp()
.priority(90)
.build();

clientToolbar.addNavigation(navButton);
if (!config.hidePanelNavigationButton())
{
clientToolbar.addNavigation(navButton);
}

if (config.addPredictPlayerOption() && client != null)
{
Expand Down Expand Up @@ -587,6 +595,15 @@ private void onBotDetectorPanelActivated(BotDetectorPanelActivated event)
}
}

@Subscribe
private void onBotDetectorPanelDeactivated(BotDetectorPanelDeactivated event)
{
if (config.hidePanelNavigationButton())
{
clientToolbar.removeNavigation(navButton);
}
}

@Subscribe
private void onConfigChanged(ConfigChanged event)
{
Expand Down Expand Up @@ -632,6 +649,16 @@ private void onConfigChanged(ConfigChanged event)
case BotDetectorConfig.ONLY_SEND_AT_LOGOUT_KEY:
updateTimeToAutoSend();
break;
case BotDetectorConfig.HIDE_PANEL_NAVIGATION_BUTTON_KEY:
if (config.hidePanelNavigationButton())
{
clientToolbar.removeNavigation(navButton);
}
else
{
clientToolbar.addNavigation(navButton);
}
break;
}
}

Expand Down Expand Up @@ -1088,11 +1115,8 @@ private void onWorldChanged(WorldChanged event)
*/
public void predictPlayer(String playerName)
{
SwingUtilities.invokeLater(() ->
{
clientToolbar.openPanel(navButton);
panel.predictPlayer(playerName);
});
openSidePanel();
SwingUtilities.invokeLater(() -> panel.predictPlayer(playerName));
}

/**
Expand Down Expand Up @@ -1393,6 +1417,24 @@ private void toggleShowDiscordVerificationErrors()
}
}

/**
* Opens the side panel if it's not already open
*/
private void openSidePanel()
{
if (panel.isActive())
{
return;
}

if (config.hidePanelNavigationButton())
{
clientToolbar.addNavigation(navButton);
}

SwingUtilities.invokeLater(() -> clientToolbar.openPanel(navButton));
}

//endregion


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, Ferrariic, Seltzer Bro, Cyborger1
* 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 HOLDER 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 com.botdetector.events;

/**s
* Event for when the {@link com.botdetector.ui.BotDetectorPanel} is deactivated.
*/
public class BotDetectorPanelDeactivated
{
}
4 changes: 3 additions & 1 deletion src/main/java/com/botdetector/ui/BotDetectorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.botdetector.BotDetectorPlugin;
import static com.botdetector.BotDetectorPlugin.normalizeAndWrapPlayerName;
import com.botdetector.events.BotDetectorPanelActivated;
import com.botdetector.events.BotDetectorPanelDeactivated;
import com.botdetector.http.BotDetectorClient;
import com.botdetector.model.CaseInsensitiveString;
import com.botdetector.model.FeedbackValue;
Expand Down Expand Up @@ -297,14 +298,15 @@ public void shutdown()
@Override
public void onActivate()
{
eventBus.post(new BotDetectorPanelActivated());
isActive = true;
eventBus.post(new BotDetectorPanelActivated());
}

@Override
public void onDeactivate()
{
isActive = false;
eventBus.post(new BotDetectorPanelDeactivated());
}

/**
Expand Down