runelite-client: Add fairy ring search to fairy ring plugin
This commit is contained in:
@@ -26,6 +26,16 @@ package net.runelite.api;
|
|||||||
|
|
||||||
public final class ScriptID
|
public final class ScriptID
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Updates the scrollbar handle and container to the new height of the content container
|
||||||
|
* <ul>
|
||||||
|
* <li> int (WidgetID) Scrollbar's widget ID </li>
|
||||||
|
* <li> int (WidgetID) Container widget ID </li>
|
||||||
|
* <li> int how far down to scroll </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public static final int UPDATE_SCROLLBAR = 72;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat message
|
* Sends a chat message
|
||||||
* <ul>
|
* <ul>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.fairyring;
|
||||||
|
|
||||||
|
import net.runelite.client.config.Config;
|
||||||
|
import net.runelite.client.config.ConfigGroup;
|
||||||
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
|
@ConfigGroup("fairyrings")
|
||||||
|
public interface FairyRingConfig extends Config
|
||||||
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "autoOpen",
|
||||||
|
name = "Open search automatically",
|
||||||
|
description = "Open the search widget every time you enter a fairy ring"
|
||||||
|
)
|
||||||
|
default boolean autoOpen()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2018 Abex
|
||||||
|
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
|
||||||
* Copyright (c) 2018, Yoav Ram <https://github.com/yoyo421>
|
* Copyright (c) 2018, Yoav Ram <https://github.com/yoyo421>
|
||||||
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@@ -26,20 +28,38 @@
|
|||||||
|
|
||||||
package net.runelite.client.plugins.fairyring;
|
package net.runelite.client.plugins.fairyring;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.ScriptID;
|
||||||
|
import net.runelite.api.SoundEffectID;
|
||||||
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
|
import net.runelite.api.WidgetType;
|
||||||
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
import net.runelite.api.events.VarbitChanged;
|
import net.runelite.api.events.VarbitChanged;
|
||||||
import net.runelite.api.events.WidgetLoaded;
|
import net.runelite.api.events.WidgetLoaded;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.api.widgets.WidgetID;
|
import net.runelite.api.widgets.WidgetID;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.game.ChatboxInputManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.util.Text;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Fairy Ring Helper",
|
name = "Fairy Rings",
|
||||||
description = "Show the location of the fairy ring teleport",
|
description = "Show the location of the fairy ring teleport",
|
||||||
tags = {"teleportation"}
|
tags = {"teleportation"}
|
||||||
)
|
)
|
||||||
@@ -49,9 +69,44 @@ public class FairyRingPlugin extends Plugin
|
|||||||
private static final String[] middleDial = new String[]{"I", "L", "K", "J"};
|
private static final String[] middleDial = new String[]{"I", "L", "K", "J"};
|
||||||
private static final String[] rightDial = new String[]{"P", "S", "R", "Q"};
|
private static final String[] rightDial = new String[]{"P", "S", "R", "Q"};
|
||||||
|
|
||||||
|
private static final int ENTRY_PADDING = 3;
|
||||||
|
|
||||||
|
private static final String MENU_OPEN = "Open";
|
||||||
|
private static final String MENU_CLOSE = "Close";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private FairyRingConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ChatboxInputManager chatboxInputManager;
|
||||||
|
|
||||||
|
private Widget searchBtn;
|
||||||
|
private boolean chatboxOpenLastTick = false;
|
||||||
|
private boolean clearFilter = false;
|
||||||
|
private Collection<CodeWidgets> codes = null;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class CodeWidgets
|
||||||
|
{
|
||||||
|
// The fairy hideout has both of these null, because its not the same as the rest of them
|
||||||
|
@Nullable
|
||||||
|
private Widget favorite;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Widget code;
|
||||||
|
|
||||||
|
private Widget description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
FairyRingConfig getConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(FairyRingConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onVarbitChanged(VarbitChanged event)
|
public void onVarbitChanged(VarbitChanged event)
|
||||||
{
|
{
|
||||||
@@ -64,6 +119,52 @@ public class FairyRingPlugin extends Plugin
|
|||||||
if (widgetLoaded.getGroupId() == WidgetID.FAIRY_RING_PANEL_GROUP_ID)
|
if (widgetLoaded.getGroupId() == WidgetID.FAIRY_RING_PANEL_GROUP_ID)
|
||||||
{
|
{
|
||||||
setWidgetTextToDestination();
|
setWidgetTextToDestination();
|
||||||
|
|
||||||
|
Widget header = client.getWidget(WidgetInfo.FAIRY_RING_HEADER);
|
||||||
|
if (header != null)
|
||||||
|
{
|
||||||
|
searchBtn = header.createChild(-1, WidgetType.GRAPHIC);
|
||||||
|
searchBtn.setSpriteId(SpriteID.GE_SEARCH);
|
||||||
|
searchBtn.setOriginalWidth(17);
|
||||||
|
searchBtn.setOriginalHeight(17);
|
||||||
|
searchBtn.setOriginalX(11);
|
||||||
|
searchBtn.setOriginalY(11);
|
||||||
|
searchBtn.setOnOpListener(ScriptID.NULL);
|
||||||
|
searchBtn.setHasListener(true);
|
||||||
|
searchBtn.setAction(1, MENU_OPEN);
|
||||||
|
searchBtn.setName("Search");
|
||||||
|
searchBtn.revalidate();
|
||||||
|
|
||||||
|
codes = null;
|
||||||
|
|
||||||
|
if (config.autoOpen())
|
||||||
|
{
|
||||||
|
openSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onMenuOptionClicked(MenuOptionClicked ev)
|
||||||
|
{
|
||||||
|
if (searchBtn != null && searchBtn.getId() == ev.getWidgetId())
|
||||||
|
{
|
||||||
|
switch (ev.getMenuOption())
|
||||||
|
{
|
||||||
|
case MENU_OPEN:
|
||||||
|
ev.consume();
|
||||||
|
openSearch();
|
||||||
|
client.playSoundEffect(SoundEffectID.UI_BOOP);
|
||||||
|
break;
|
||||||
|
case MENU_CLOSE:
|
||||||
|
ev.consume();
|
||||||
|
updateFilter("");
|
||||||
|
searchBtn.setAction(1, MENU_OPEN);
|
||||||
|
chatboxInputManager.closeInputWindow();
|
||||||
|
client.playSoundEffect(SoundEffectID.UI_BOOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,4 +193,178 @@ public class FairyRingPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
return FairyRings.valueOf(leftDial[varbitValueDialLeft] + middleDial[varbitValueDialMiddle] + rightDial[varbitValueDialRight]);
|
return FairyRings.valueOf(leftDial[varbitValueDialLeft] + middleDial[varbitValueDialMiddle] + rightDial[varbitValueDialRight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openSearch()
|
||||||
|
{
|
||||||
|
updateFilter("");
|
||||||
|
searchBtn.setAction(1, MENU_CLOSE);
|
||||||
|
chatboxInputManager.openInputWindow("Filter fairy rings", "", ChatboxInputManager.NO_LIMIT, this::updateFilter, s ->
|
||||||
|
{
|
||||||
|
// We can't run it right now because scripts can't run other scripts in their callbacks
|
||||||
|
clearFilter = true;
|
||||||
|
searchBtn.setAction(1, MENU_OPEN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameTick(GameTick t)
|
||||||
|
{
|
||||||
|
if (clearFilter)
|
||||||
|
{
|
||||||
|
updateFilter("");
|
||||||
|
clearFilter = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This has to happen because the only widget that gets hidden is the tli one
|
||||||
|
Widget fairyRingTeleportButton = client.getWidget(WidgetInfo.FAIRY_RING_TELEPORT_BUTTON);
|
||||||
|
boolean fairyRingWidgetOpen = fairyRingTeleportButton != null && !fairyRingTeleportButton.isHidden();
|
||||||
|
boolean chatboxOpen = chatboxInputManager.isOpen();
|
||||||
|
|
||||||
|
if (!fairyRingWidgetOpen && chatboxOpen && chatboxOpenLastTick)
|
||||||
|
{
|
||||||
|
searchBtn.setAction(1, MENU_OPEN);
|
||||||
|
chatboxInputManager.closeInputWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
chatboxOpenLastTick = chatboxOpen && fairyRingWidgetOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFilter(String filter)
|
||||||
|
{
|
||||||
|
filter = filter.toLowerCase();
|
||||||
|
final Widget list = client.getWidget(WidgetInfo.FAIRY_RING_LIST);
|
||||||
|
final Widget favorites = client.getWidget(WidgetInfo.FAIRY_RING_FAVORITES);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codes != null)
|
||||||
|
{
|
||||||
|
// Check to make sure the list hasn't been rebuild since we were last her
|
||||||
|
// Do this by making sure the list's dynamic children are the same as when we last saw them
|
||||||
|
if (codes.stream().noneMatch(w ->
|
||||||
|
{
|
||||||
|
Widget codeWidget = w.getCode();
|
||||||
|
if (codeWidget == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return list.getChild(codeWidget.getIndex()) == codeWidget;
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
codes = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codes == null)
|
||||||
|
{
|
||||||
|
// Find all of the widgets that we care about, grouping by their Y value
|
||||||
|
Map<Integer, CodeWidgets> codeMap = new TreeMap<>();
|
||||||
|
|
||||||
|
for (Widget w : list.getStaticChildren())
|
||||||
|
{
|
||||||
|
if (w.isSelfHidden())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w.getSpriteId() != -1)
|
||||||
|
{
|
||||||
|
codeMap.computeIfAbsent(w.getRelativeY(), k -> new CodeWidgets()).setFavorite(w);
|
||||||
|
}
|
||||||
|
else if (!Strings.isNullOrEmpty(w.getText()))
|
||||||
|
{
|
||||||
|
codeMap.computeIfAbsent(w.getRelativeY(), k -> new CodeWidgets()).setDescription(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Widget w : list.getDynamicChildren())
|
||||||
|
{
|
||||||
|
if (w.isSelfHidden())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeWidgets c = codeMap.computeIfAbsent(w.getRelativeY(), k -> new CodeWidgets());
|
||||||
|
c.setCode(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
codes = codeMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relayout the panel
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
if (favorites != null)
|
||||||
|
{
|
||||||
|
boolean hide = !filter.isEmpty();
|
||||||
|
favorites.setHidden(hide);
|
||||||
|
if (!hide)
|
||||||
|
{
|
||||||
|
y += favorites.getOriginalHeight() + ENTRY_PADDING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CodeWidgets c : codes)
|
||||||
|
{
|
||||||
|
String code = Text.removeTags(c.getDescription().getName()).replaceAll(" ", "");
|
||||||
|
String tags = null;
|
||||||
|
|
||||||
|
if (code.length() > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FairyRings ring = FairyRings.valueOf(code);
|
||||||
|
tags = ring.getTags();
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
log.warn("Unable to find ring with code '{}'", code, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hidden = !(filter.isEmpty()
|
||||||
|
|| Text.removeTags(c.getDescription().getText()).toLowerCase().contains(filter)
|
||||||
|
|| code.toLowerCase().contains(filter)
|
||||||
|
|| tags != null && tags.contains(filter));
|
||||||
|
|
||||||
|
if (c.getCode() != null)
|
||||||
|
{
|
||||||
|
c.getCode().setHidden(hidden);
|
||||||
|
c.getCode().setOriginalY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getFavorite() != null)
|
||||||
|
{
|
||||||
|
c.getFavorite().setHidden(hidden);
|
||||||
|
c.getFavorite().setOriginalY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.getDescription().setHidden(hidden);
|
||||||
|
c.getDescription().setOriginalY(y);
|
||||||
|
|
||||||
|
if (!hidden)
|
||||||
|
{
|
||||||
|
y += c.getDescription().getHeight() + ENTRY_PADDING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y -= ENTRY_PADDING;
|
||||||
|
|
||||||
|
if (y < 0)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.setScrollHeight(y);
|
||||||
|
list.revalidateScroll();
|
||||||
|
client.runScript(
|
||||||
|
ScriptID.UPDATE_SCROLLBAR,
|
||||||
|
WidgetInfo.FAIRY_RING_LIST_SCROLLBAR.getId(),
|
||||||
|
WidgetInfo.FAIRY_RING_LIST.getId(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,8 @@
|
|||||||
|
|
||||||
package net.runelite.client.plugins.fairyring;
|
package net.runelite.client.plugins.fairyring;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum FairyRings
|
public enum FairyRings
|
||||||
{
|
{
|
||||||
// A
|
// A
|
||||||
@@ -50,7 +48,7 @@ public enum FairyRings
|
|||||||
BIQ("Kalphite Hive"),
|
BIQ("Kalphite Hive"),
|
||||||
BIS("Ardougne Zoo - Unicorns"),
|
BIS("Ardougne Zoo - Unicorns"),
|
||||||
BJR("Realm of the Fisher King"),
|
BJR("Realm of the Fisher King"),
|
||||||
BJS("(Island) Near Zul-Andra"),
|
BJS("(Island) Near Zul-Andra", "zulrah"),
|
||||||
BKP("South of Castle Wars"),
|
BKP("South of Castle Wars"),
|
||||||
BKQ("Enchanted Valley"),
|
BKQ("Enchanted Valley"),
|
||||||
BKR("Mort Myre Swamp, south of Canifis"),
|
BKR("Mort Myre Swamp, south of Canifis"),
|
||||||
@@ -73,7 +71,7 @@ public enum FairyRings
|
|||||||
// D
|
// D
|
||||||
DIP("(Sire Boss) Abyssal Nexus"),
|
DIP("(Sire Boss) Abyssal Nexus"),
|
||||||
DIR("Gorak's Plane"),
|
DIR("Gorak's Plane"),
|
||||||
DIQ("Player-owned house"),
|
DIQ("Player-owned house", "poh home"),
|
||||||
DIS("Wizards' Tower"),
|
DIS("Wizards' Tower"),
|
||||||
DJP("Tower of Life"),
|
DJP("Tower of Life"),
|
||||||
DJR("Chasm of Fire"),
|
DJR("Chasm of Fire"),
|
||||||
@@ -86,4 +84,19 @@ public enum FairyRings
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String destination;
|
private final String destination;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String tags;
|
||||||
|
|
||||||
|
FairyRings(String destination)
|
||||||
|
{
|
||||||
|
this(destination, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
FairyRings(String destination, String tags)
|
||||||
|
{
|
||||||
|
this.destination = destination;
|
||||||
|
this.tags = tags.toLowerCase() + " " + destination.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user