Add ability and config to swap Lookup and Search in wiki plugin (#10690)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Henry Darnell <hjdarnel@gmail.com>
|
||||
* 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.wiki;
|
||||
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
|
||||
@ConfigGroup(WikiPlugin.CONFIG_GROUP_KEY)
|
||||
public interface WikiConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
keyName = "leftClickSearch",
|
||||
name = "Left Click Search",
|
||||
description = "Swap left-click on the Wiki button to Search",
|
||||
position = 1
|
||||
)
|
||||
default boolean leftClickSearch()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.wiki;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
@@ -49,7 +50,9 @@ import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.api.widgets.WidgetPositionMode;
|
||||
import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
@@ -85,6 +88,9 @@ public class WikiPlugin extends Plugin
|
||||
@Inject
|
||||
private SpriteManager spriteManager;
|
||||
|
||||
@Inject
|
||||
private WikiConfig config;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@@ -104,6 +110,14 @@ public class WikiPlugin extends Plugin
|
||||
|
||||
private boolean wikiSelected = false;
|
||||
|
||||
static final String CONFIG_GROUP_KEY = "wiki";
|
||||
|
||||
@Provides
|
||||
WikiConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(WikiConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
@@ -113,29 +127,32 @@ public class WikiPlugin extends Plugin
|
||||
@Override
|
||||
public void shutDown()
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invokeLater(this::removeWidgets);
|
||||
}
|
||||
|
||||
private void removeWidgets()
|
||||
{
|
||||
|
||||
Widget minimapOrbs = client.getWidget(WidgetInfo.MINIMAP_ORBS);
|
||||
if (minimapOrbs == null)
|
||||
{
|
||||
Widget minimapOrbs = client.getWidget(WidgetInfo.MINIMAP_ORBS);
|
||||
if (minimapOrbs == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Widget[] children = minimapOrbs.getChildren();
|
||||
if (children == null || children.length < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
children[0] = null;
|
||||
return;
|
||||
}
|
||||
Widget[] children = minimapOrbs.getChildren();
|
||||
if (children == null || children.length < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
children[0] = null;
|
||||
|
||||
Widget vanilla = client.getWidget(WidgetInfo.MINIMAP_WIKI_BANNER);
|
||||
if (vanilla != null)
|
||||
{
|
||||
vanilla.setHidden(false);
|
||||
}
|
||||
Widget vanilla = client.getWidget(WidgetInfo.MINIMAP_WIKI_BANNER);
|
||||
if (vanilla != null)
|
||||
{
|
||||
vanilla.setHidden(false);
|
||||
}
|
||||
|
||||
onDeselect();
|
||||
client.setSpellSelected(false);
|
||||
});
|
||||
onDeselect();
|
||||
client.setSpellSelected(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -180,16 +197,17 @@ public class WikiPlugin extends Plugin
|
||||
icon.setSpriteId(SpriteID.WIKI_SELECTED);
|
||||
client.setAllWidgetsAreOpTargetable(true);
|
||||
});
|
||||
icon.setAction(5, "Search"); // Start at option 5 so the target op is ontop
|
||||
|
||||
final int searchIndex = config.leftClickSearch() ? 4 : 5;
|
||||
icon.setAction(searchIndex, "Search");
|
||||
icon.setOnOpListener((JavaScriptCallback) ev ->
|
||||
{
|
||||
switch (ev.getOp())
|
||||
if (ev.getOp() == searchIndex + 1)
|
||||
{
|
||||
case 6:
|
||||
openSearchInput();
|
||||
break;
|
||||
openSearchInput();
|
||||
}
|
||||
});
|
||||
|
||||
// This doesn't always run because we cancel the menuop
|
||||
icon.setOnTargetLeaveListener((JavaScriptCallback) ev -> onDeselect());
|
||||
icon.revalidate();
|
||||
@@ -204,6 +222,19 @@ public class WikiPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (event.getGroup().equals(CONFIG_GROUP_KEY))
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
{
|
||||
removeWidgets();
|
||||
addWidgets();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void onDeselect()
|
||||
{
|
||||
client.setAllWidgetsAreOpTargetable(false);
|
||||
|
||||
Reference in New Issue
Block a user