Merge pull request #6708 from Abextm/wiki-plugin

Wiki plugin
This commit is contained in:
Adam
2019-02-12 18:01:33 -05:00
committed by GitHub
21 changed files with 910 additions and 40 deletions

View File

@@ -1569,4 +1569,9 @@ public interface Client extends GameEngine
int getRasterizer3D_clipMidY2();
void checkClickbox(Model model, int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z, long hash);
/**
* Sets if a widget is in target mode
*/
void setSpellSelected(boolean selected);
}

View File

@@ -1172,7 +1172,7 @@ public final class SpriteID
public static final int MINIMAP_ORB_XP_ACTIVATED = 1197;
public static final int MINIMAP_ORB_XP_HOVERED = 1198;
public static final int MINIMAP_ORB_XP_ACTIVATED_HOVERED = 1199;
public static final int UNKNOWN_BLACK_BLOBS = 1200;
public static final int MINIMAP_CLICK_MASK = 1200;
public static final int OPTIONS_ZOOM_SLIDER_THUMB = 1201;
public static final int EMOTE_SIT_UP = 1202;
public static final int EMOTE_STAR_JUMP = 1203;

View File

@@ -79,6 +79,7 @@ public interface Widget
/**
* Gets the current click configuration of the widget.
* @see WidgetConfig
*
* @see WidgetConfig
*/
@@ -551,6 +552,13 @@ public interface Widget
*/
void setOnMouseOverListener(Object... args);
/**
* Sets a script to be ran every frame when the mouse is in the widget bounds
*
* @param args A ScriptID, then the args for the script
*/
void setOnMouseRepeatListener(Object... args);
/**
* Sets a script to be ran when the mouse leaves the widget bounds
*
@@ -565,6 +573,20 @@ public interface Widget
*/
void setOnTimerListener(Object... args);
/**
* Sets a script to be ran when the target mode has been activated for this widget
*
* @param args A ScriptID, then the args for the script
*/
void setOnTargetEnterListener(Object... args);
/**
* Sets a script to be ran when the target mode has been deactivated for this widget
*
* @param args A ScriptID, then the args for the script
*/
void setOnTargetLeaveListener(Object... args);
/**
* If this widget has any listeners on it
*/
@@ -769,4 +791,34 @@ public interface Widget
* Sets if the rectangle is filled or just stroked
*/
void setFilled(boolean filled);
/**
* Verb for spell targets
*/
String getTargetVerb();
/**
* Verb for spell targets
*/
void setTargetVerb(String targetVerb);
/**
* Can widgets under this widgets be clicked in this widgets bounding box
*/
boolean getNoClickThrough();
/**
* Can widgets under this widgets be clicked in this widgets bounding box
*/
void setNoClickThrough(boolean noClickThrough);
/**
* Can widgets under this widgets be scrolled in this widgets bounding box
*/
boolean getNoScrollThrough();
/**
* Can widgets under this widgets be scrolled in this widgets bounding box
*/
void setNoScrollThrough(boolean noScrollThrough);
}

View File

@@ -24,6 +24,8 @@
*/
package net.runelite.api.widgets;
import net.runelite.api.MenuAction;
/**
* Utility class used for defining options to be used on the click mask
* of a {@link Widget}.
@@ -36,12 +38,61 @@ public class WidgetConfig
* Enables displaying a ninth option on a menu.
*/
public static final int SHOW_MENU_OPTION_NINE = 1 << 9;
/**
* Can this widget be used on a item on the floor
*/
public static final int USE_GROUND_ITEM = 1 << 11;
/**
* Can this widget be used on a NPC
*/
public static final int USE_NPC = 2 << 11;
/**
* Can this widget be used on a game object
*/
public static final int USE_OBJECT = 4 << 11;
/**
* Can this widget be used on a player
*/
public static final int USE_PLAYER = 8 << 11;
/**
* Can this widget be used on a item in your inventory
*/
public static final int USE_ITEM = 16 << 11;
/**
* Can this widget be used on a widget with the WIDGET_USE_TARGET flag
*/
public static final int USE_WIDGET = 32 << 11;
/**
* Controls whether or not a widget can have another dragged onto it.
*/
public static final int DRAG_ON = 1 << 17;
/**
* Controls whether or not a widget can be dragged around.
*/
public static final int DRAG = 1 << 20;
/**
* Can widgets with USE_WIDGET be used on this widget
*/
public static final int WIDGET_USE_TARGET = 1 << 21;
/**
* Is the widget an (inventory?) item
*/
public static final int ITEM = 1 << 30;
/**
* Add a USE option
*
* @see MenuAction#ITEM_USE
*/
public static final int ITEM_USE_OP = 1 << 31;
}

View File

@@ -125,6 +125,7 @@ public class WidgetID
public static final int SKOTIZO_GROUP_ID = 308;
public static final int ENTERING_HOUSE_GROUP_ID = 71;
public static final int FULLSCREEN_MAP_GROUP_ID = 165;
public static final int QUESTLIST_GROUP_ID = 399;
static class WorldMap
{
@@ -292,6 +293,7 @@ public class WidgetID
static final int TOGGLE_RUN_ORB = 22; // Has the "Toggle run" name
static final int RUN_ORB_TEXT = 23;
static final int SPEC_ORB = 28;
static final int WORLDMAP_ORB = 40;
}
static class LoginClickToPlayScreen
@@ -747,4 +749,11 @@ public class WidgetID
{
static final int ROOT = 25;
}
static class QuestList
{
static final int FREE_CONTAINER = 9;
static final int MEMBERS_CONTAINER = 10;
static final int MINIQUEST_CONTAINER = 11;
}
}

View File

@@ -159,6 +159,7 @@ public enum WidgetInfo
MINIMAP_RUN_ORB_TEXT(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.RUN_ORB_TEXT),
MINIMAP_HEALTH_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.HEALTH_ORB),
MINIMAP_SPEC_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.SPEC_ORB),
MINIMAP_WORLDMAP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.WORLDMAP_ORB),
LOGIN_CLICK_TO_PLAY_SCREEN(WidgetID.LOGIN_CLICK_TO_PLAY_GROUP_ID, 0),
LOGIN_CLICK_TO_PLAY_SCREEN_MESSAGE_OF_THE_DAY(WidgetID.LOGIN_CLICK_TO_PLAY_GROUP_ID, WidgetID.LoginClickToPlayScreen.MESSAGE_OF_THE_DAY),
@@ -463,7 +464,11 @@ public enum WidgetInfo
SKOTIZO_CONTAINER(WidgetID.SKOTIZO_GROUP_ID, WidgetID.Skotizo.CONTAINER),
FULLSCREEN_MAP_ROOT(WidgetID.FULLSCREEN_MAP_GROUP_ID, WidgetID.FullScreenMap.ROOT);
FULLSCREEN_MAP_ROOT(WidgetID.FULLSCREEN_MAP_GROUP_ID, WidgetID.FullScreenMap.ROOT),
QUESTLIST_FREE_CONTAINER(WidgetID.QUESTLIST_GROUP_ID, WidgetID.QuestList.FREE_CONTAINER),
QUESTLIST_MEMBERS_CONTAINER(WidgetID.QUESTLIST_GROUP_ID, WidgetID.QuestList.MEMBERS_CONTAINER),
QUESTLIST_MINIQUEST_CONTAINER(WidgetID.QUESTLIST_GROUP_ID, WidgetID.QuestList.MINIQUEST_CONTAINER);
private final int groupId;
private final int childId;

View File

@@ -28,6 +28,7 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject;
import java.awt.image.BufferedImage;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import javax.annotation.Nullable;
@@ -36,11 +37,14 @@ import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.SpritePixels;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.util.ImageUtil;
@Slf4j
@Singleton
public class SpriteManager
{
@@ -127,4 +131,36 @@ public class SpriteManager
});
});
}
public void addSpriteOverrides(SpriteOverride[] add)
{
if (add.length <= 0)
{
return;
}
clientThread.invokeLater(() ->
{
Map<Integer, SpritePixels> overrides = client.getSpriteOverrides();
Class<?> owner = add[0].getClass();
for (SpriteOverride o : add)
{
BufferedImage image = ImageUtil.getResourceStreamFromClass(owner, o.getFileName());
SpritePixels sp = ImageUtil.getImageSpritePixels(image, client);
overrides.put(o.getSpriteId(), sp);
}
});
}
public void removeSpriteOverrides(SpriteOverride[] remove)
{
clientThread.invokeLater(() ->
{
Map<Integer, SpritePixels> overrides = client.getSpriteOverrides();
for (SpriteOverride o : remove)
{
overrides.remove(o.getSpriteId());
}
});
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.game;
import net.runelite.api.SpriteID;
public interface SpriteOverride
{
/**
* An ID for a sprite. Negative numbers are used by RuneLite specific sprites
*
* @see SpriteID
*/
int getSpriteId();
/**
* The file name for the resource to be loaded, relative to the implementing class
*/
String getFileName();
}

View File

@@ -95,12 +95,13 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
@Getter
private int fontID = FontID.QUILL_8;
@Getter
private boolean built = false;
// This is a lambda so I can have atomic updates for it's captures
private ToIntFunction<MouseEvent> getCharOffset = null;
private Predicate<MouseEvent> isInBounds = null;
private boolean built = false;
@Inject
protected ChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread)
{
@@ -209,7 +210,6 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
protected void update()
{
this.built = true;
Widget container = chatboxPanelManager.getContainerWidget();
container.deleteAllChildren();
@@ -369,6 +369,7 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
@Override
protected void open()
{
this.built = true;
update();
}

View File

@@ -60,6 +60,7 @@ import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.input.KeyListener;
import net.runelite.client.input.KeyManager;
@@ -125,6 +126,9 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
@Inject
private KeyManager keyManager;
@Inject
private SpriteManager spriteManager;
private boolean shiftPressed = false;
@Provides
@@ -139,7 +143,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
keyManager.registerKeyListener(this);
mouseManager.registerMouseWheelListener(this);
clientThread.invokeLater(tabInterface::init);
client.getSpriteOverrides().putAll(TabSprites.toMap(client));
spriteManager.addSpriteOverrides(TabSprites.values());
}
@Override
@@ -148,11 +152,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis
keyManager.unregisterKeyListener(this);
mouseManager.unregisterMouseWheelListener(this);
clientThread.invokeLater(tabInterface::destroy);
for (TabSprites value : TabSprites.values())
{
client.getSpriteOverrides().remove(value.getSpriteId());
}
spriteManager.removeSpriteOverrides(TabSprites.values());
shiftPressed = false;
}

View File

@@ -25,17 +25,12 @@
*/
package net.runelite.client.plugins.banktags.tabs;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.SpritePixels;
import net.runelite.client.util.ImageUtil;
import lombok.RequiredArgsConstructor;
import net.runelite.client.game.SpriteOverride;
@Slf4j
public enum TabSprites
@RequiredArgsConstructor
public enum TabSprites implements SpriteOverride
{
INCINERATOR(-200, "incinerator.png"),
TAB_BACKGROUND(-201, "tag-tab.png"),
@@ -46,23 +41,7 @@ public enum TabSprites
@Getter
private final int spriteId;
private final BufferedImage image;
TabSprites(final int spriteId, final String imageName)
{
this.spriteId = spriteId;
this.image = ImageUtil.getResourceStreamFromClass(this.getClass(), imageName);
}
public static Map<Integer, SpritePixels> toMap(Client client)
{
final Map<Integer, SpritePixels> map = new HashMap<>();
for (TabSprites value : values())
{
map.put(value.spriteId, ImageUtil.getImageSpritePixels(value.image, client));
}
return map;
}
@Getter
private final String fileName;
}

View File

@@ -183,6 +183,9 @@ public class WidgetInfoTableModel extends AbstractTableModel
out.add(new WidgetField<>("ScrollHeight", Widget::getScrollHeight, Widget::setScrollHeight, Integer.class));
out.add(new WidgetField<>("DragDeadZone", Widget::getDragDeadZone, Widget::setDragDeadZone, Integer.class));
out.add(new WidgetField<>("DragDeadTime", Widget::getDragDeadTime, Widget::setDragDeadTime, Integer.class));
out.add(new WidgetField<>("NoClickThrough", Widget::getNoClickThrough, Widget::setNoClickThrough, Boolean.class));
out.add(new WidgetField<>("NoScrollThrough", Widget::getNoScrollThrough, Widget::setNoScrollThrough, Boolean.class));
out.add(new WidgetField<>("TargetVerb", Widget::getTargetVerb, Widget::setTargetVerb, String.class));
return out;
}

View File

@@ -0,0 +1,289 @@
/*
* 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.wiki;
import com.google.common.primitives.Ints;
import java.net.URLEncoder;
import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Provider;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.JavaScriptCallback;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetConfig;
import net.runelite.api.widgets.WidgetID;
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.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.LinkBrowser;
import net.runelite.client.util.Text;
import okhttp3.HttpUrl;
@Slf4j
@PluginDescriptor(
name = "Wiki",
description = "Adds a Wiki button that takes you to the OSRS Wiki"
)
public class WikiPlugin extends Plugin
{
private static final int[] QUESTLIST_WIDGET_IDS = new int[]
{
WidgetInfo.QUESTLIST_FREE_CONTAINER.getId(),
WidgetInfo.QUESTLIST_MEMBERS_CONTAINER.getId(),
WidgetInfo.QUESTLIST_MINIQUEST_CONTAINER.getId(),
};
static final String WIKI_BASE = "https://oldschool.runescape.wiki";
static final HttpUrl WIKI_RSLOOKUP = HttpUrl.parse(WIKI_BASE + "/w/Special:Lookup");
static final HttpUrl WIKI_API = HttpUrl.parse(WIKI_BASE + "/api.php");
static final String UTM_SORUCE_KEY = "utm_source";
static final String UTM_SORUCE_VALUE = "runelite";
static final String UTM_PARAMS = UTM_SORUCE_KEY + "=" + UTM_SORUCE_VALUE;
private static final String MENUOP_GUIDE = "Guide";
private static final String MENUOP_QUICKGUIDE = "Quick Guide";
@Inject
private SpriteManager spriteManager;
@Inject
private ClientThread clientThread;
@Inject
private Client client;
@Inject
private ChatboxPanelManager chatboxPanelManager;
@Inject
private ItemManager itemManager;
@Inject
private Provider<WikiSearchChatboxTextInput> wikiSearchChatboxTextInputProvider;
private Widget icon;
private boolean wikiSelected = false;
@Override
public void startUp()
{
spriteManager.addSpriteOverrides(WikiSprite.values());
clientThread.invokeLater(this::addWidgets);
}
@Override
public void shutDown()
{
spriteManager.removeSpriteOverrides(WikiSprite.values());
clientThread.invokeLater(() ->
{
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;
});
}
@Subscribe
private void onWidgetLoaded(WidgetLoaded l)
{
if (l.getGroupId() == WidgetID.MINIMAP_GROUP_ID)
{
addWidgets();
}
}
private void addWidgets()
{
Widget minimapOrbs = client.getWidget(WidgetInfo.MINIMAP_ORBS);
if (minimapOrbs == null)
{
return;
}
icon = minimapOrbs.createChild(0, WidgetType.GRAPHIC);
icon.setSpriteId(WikiSprite.WIKI_ICON.getSpriteId());
icon.setOriginalX(0);
icon.setOriginalY(2);
icon.setXPositionMode(WidgetPositionMode.ABSOLUTE_RIGHT);
icon.setYPositionMode(WidgetPositionMode.ABSOLUTE_BOTTOM);
icon.setOriginalWidth(42);
icon.setOriginalHeight(16);
icon.setTargetVerb("Lookup");
icon.setName("Wiki");
icon.setClickMask(WidgetConfig.USE_GROUND_ITEM | WidgetConfig.USE_ITEM | WidgetConfig.USE_NPC);
icon.setNoClickThrough(true);
icon.setOnTargetEnterListener((JavaScriptCallback) ev ->
{
wikiSelected = true;
icon.setSpriteId(WikiSprite.WIKI_SELECTED_ICON.getSpriteId());
});
icon.setAction(5, "Search"); // Start at option 5 so the target op is ontop
icon.setOnOpListener((JavaScriptCallback) ev ->
{
switch (ev.getOp())
{
case 6:
openSearchInput();
break;
}
});
// This doesn't always run because we cancel the menuop
icon.setOnTargetLeaveListener((JavaScriptCallback) ev -> onDeselect());
icon.revalidate();
}
private void onDeselect()
{
wikiSelected = false;
icon.setSpriteId(WikiSprite.WIKI_ICON.getSpriteId());
}
@Subscribe
private void onMenuOptionClicked(MenuOptionClicked ev)
{
if (wikiSelected)
{
onDeselect();
client.setSpellSelected(false);
ev.consume();
String type;
int id;
String name;
switch (ev.getMenuAction())
{
case CANCEL:
return;
case ITEM_USE_ON_WIDGET:
case SPELL_CAST_ON_GROUND_ITEM:
{
type = "item";
id = itemManager.canonicalize(ev.getId());
name = itemManager.getItemComposition(id).getName();
break;
}
case SPELL_CAST_ON_NPC:
{
type = "npc";
NPC npc = client.getCachedNPCs()[ev.getId()];
NPCComposition nc = npc.getTransformedComposition();
id = nc.getId();
name = nc.getName();
break;
}
default:
log.info("Unknown menu option: {} {} {}", ev, ev.getMenuAction(), ev.getMenuAction() == MenuAction.CANCEL);
return;
}
HttpUrl url = WIKI_RSLOOKUP.newBuilder()
.addQueryParameter("type", type)
.addQueryParameter("id", "" + id)
.addQueryParameter("name", name)
.addQueryParameter(UTM_SORUCE_KEY, UTM_SORUCE_VALUE)
.build();
LinkBrowser.browse(url.toString());
return;
}
if (ev.getMenuAction() == MenuAction.RUNELITE)
{
String quickguide = "";
switch (ev.getMenuOption())
{
case MENUOP_QUICKGUIDE:
quickguide = "/Quick_guide";
//fallthrough;
case MENUOP_GUIDE:
ev.consume();
String quest = Text.removeTags(ev.getMenuTarget());
LinkBrowser.browse(WIKI_BASE + "/w/" + URLEncoder.encode(quest.replace(' ', '_')) + quickguide + "?" + UTM_PARAMS);
break;
}
}
}
private void openSearchInput()
{
wikiSearchChatboxTextInputProvider.get()
.build();
}
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
int widgetIndex = event.getActionParam0();
int widgetID = event.getActionParam1();
if (!Ints.contains(QUESTLIST_WIDGET_IDS, widgetID) || !"Read Journal:".equals(event.getOption()))
{
return;
}
MenuEntry[] menuEntries = client.getMenuEntries();
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 2);
MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry();
menuEntry.setTarget(event.getTarget());
menuEntry.setOption(MENUOP_GUIDE);
menuEntry.setParam0(widgetIndex);
menuEntry.setParam1(widgetID);
menuEntry.setType(MenuAction.RUNELITE.getId());
menuEntry = menuEntries[menuEntries.length - 2] = new MenuEntry();
menuEntry.setTarget(event.getTarget());
menuEntry.setOption(MENUOP_QUICKGUIDE);
menuEntry.setParam0(widgetIndex);
menuEntry.setParam1(widgetID);
menuEntry.setType(MenuAction.RUNELITE.getId());
client.setMenuEntries(menuEntries);
}
}

View File

@@ -0,0 +1,302 @@
/*
* 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.wiki;
import com.google.common.collect.ImmutableList;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.inject.Inject;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.widgets.JavaScriptCallback;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetPositionMode;
import net.runelite.api.widgets.WidgetSizeMode;
import net.runelite.api.widgets.WidgetTextAlignment;
import net.runelite.api.widgets.WidgetType;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.game.chatbox.ChatboxTextInput;
import net.runelite.client.util.LinkBrowser;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
@Slf4j
public class WikiSearchChatboxTextInput extends ChatboxTextInput
{
private static final int LINE_HEIGHT = 20;
private static final int CHATBOX_HEIGHT = 120;
private static final int MAX_NUM_PREDICTIONS = (CHATBOX_HEIGHT / LINE_HEIGHT) - 2; // 1 title, 1 edit
private static final int PREDICTION_DEBOUNCE_DELAY_MS = 200;
private final ChatboxPanelManager chatboxPanelManager;
private final Gson gson = new Gson();
private Future<?> runningRequest = null;
private List<String> predictions = ImmutableList.of();
private int selectedPrediction = -1;
private String offPrediction = null;
@Inject
public WikiSearchChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread,
ScheduledExecutorService scheduledExecutorService, @Named("developerMode") final boolean developerMode)
{
super(chatboxPanelManager, clientThread);
this.chatboxPanelManager = chatboxPanelManager;
prompt("OSRS Wiki Search");
onDone(string ->
{
if (string != null && string.length() > 0)
{
search(string);
}
});
onChanged(searchString ->
{
selectedPrediction = -1;
Future<?> rr = runningRequest;
if (rr != null)
{
rr.cancel(false);
}
if (searchString.length() <= 1)
{
runningRequest = null;
clientThread.invokeLater(() ->
{
predictions = ImmutableList.of();
update();
});
return;
}
runningRequest = scheduledExecutorService.schedule(() ->
{
HttpUrl url = WikiPlugin.WIKI_API.newBuilder()
.addQueryParameter("action", "opensearch")
.addQueryParameter("search", searchString)
.addQueryParameter("redirects", "resolve")
.addQueryParameter("format", "json")
.addQueryParameter("warningsaserror", Boolean.toString(developerMode))
.build();
Request req = new Request.Builder()
.url(url)
.build();
RuneLiteAPI.CLIENT.newCall(req).enqueue(new Callback()
{
@Override
public void onFailure(Call call, IOException e)
{
log.warn("error searching wiki", e);
}
@Override
public void onResponse(Call call, Response response) throws IOException
{
String body = response.body().string();
try
{
JsonArray jar = new JsonParser().parse(body).getAsJsonArray();
List<String> apredictions = gson.fromJson(jar.get(1), new TypeToken<List<String>>()
{
}.getType());
if (apredictions.size() > MAX_NUM_PREDICTIONS)
{
apredictions = apredictions.subList(0, MAX_NUM_PREDICTIONS);
}
final List<String> bpredictions = apredictions;
clientThread.invokeLater(() ->
{
predictions = bpredictions;
update();
});
}
catch (JsonParseException | IllegalStateException | IndexOutOfBoundsException e)
{
log.warn("error parsing wiki response {}", body, e);
}
finally
{
response.close();
}
}
});
runningRequest = null;
}, PREDICTION_DEBOUNCE_DELAY_MS, TimeUnit.MILLISECONDS);
});
}
@Override
protected void update()
{
Widget container = chatboxPanelManager.getContainerWidget();
container.deleteAllChildren();
Widget promptWidget = container.createChild(-1, WidgetType.TEXT);
promptWidget.setText(getPrompt());
promptWidget.setTextColor(0x800000);
promptWidget.setFontId(getFontID());
promptWidget.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
promptWidget.setOriginalX(0);
promptWidget.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
promptWidget.setOriginalY(5);
promptWidget.setOriginalHeight(LINE_HEIGHT);
promptWidget.setXTextAlignment(WidgetTextAlignment.CENTER);
promptWidget.setYTextAlignment(WidgetTextAlignment.CENTER);
promptWidget.setWidthMode(WidgetSizeMode.MINUS);
promptWidget.revalidate();
buildEdit(0, 5 + LINE_HEIGHT, container.getWidth(), LINE_HEIGHT);
Widget separator = container.createChild(-1, WidgetType.LINE);
separator.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
separator.setOriginalX(0);
separator.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
separator.setOriginalY(4 + (LINE_HEIGHT * 2));
separator.setOriginalHeight(0);
separator.setOriginalWidth(16);
separator.setWidthMode(WidgetSizeMode.MINUS);
separator.revalidate();
for (int i = 0; i < predictions.size(); i++)
{
String pred = predictions.get(i);
int y = 6 + (LINE_HEIGHT * (2 + i));
Widget bg = container.createChild(-1, WidgetType.RECTANGLE);
bg.setTextColor(0x4444DD);
bg.setFilled(true);
bg.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
bg.setOriginalX(1);
bg.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
bg.setOriginalY(y);
bg.setOriginalHeight(LINE_HEIGHT);
bg.setOriginalWidth(16);
bg.setWidthMode(WidgetSizeMode.MINUS);
bg.revalidate();
bg.setName("<col=ff9040>" + pred);
bg.setAction(0, "Open");
bg.setHasListener(true);
bg.setOnOpListener((JavaScriptCallback) ev -> search(pred));
Widget text = container.createChild(-1, WidgetType.TEXT);
text.setText(pred);
text.setFontId(getFontID());
text.setXPositionMode(WidgetPositionMode.ABSOLUTE_CENTER);
text.setOriginalX(0);
text.setYPositionMode(WidgetPositionMode.ABSOLUTE_TOP);
text.setOriginalY(y);
text.setOriginalHeight(LINE_HEIGHT);
text.setXTextAlignment(WidgetTextAlignment.CENTER);
text.setYTextAlignment(WidgetTextAlignment.CENTER);
text.setWidthMode(WidgetSizeMode.MINUS);
text.revalidate();
if (i == selectedPrediction)
{
text.setTextColor(0xFFFFFF);
}
else
{
bg.setOpacity(255);
text.setTextColor(0x000000);
bg.setOnMouseRepeatListener((JavaScriptCallback) ev -> text.setTextColor(0xFFFFFF));
bg.setOnMouseLeaveListener((JavaScriptCallback) ev -> text.setTextColor(0x000000));
}
}
}
@Override
public void keyPressed(KeyEvent ev)
{
switch (ev.getKeyCode())
{
case KeyEvent.VK_UP:
ev.consume();
if (selectedPrediction > -1)
{
selectedPrediction--;
if (selectedPrediction == -1)
{
value(offPrediction);
}
else
{
value(predictions.get(selectedPrediction));
}
}
break;
case KeyEvent.VK_DOWN:
ev.consume();
if (selectedPrediction == -1)
{
offPrediction = getValue();
}
selectedPrediction++;
if (selectedPrediction >= predictions.size())
{
selectedPrediction = predictions.size() - 1;
}
if (selectedPrediction != -1)
{
value(predictions.get(selectedPrediction));
}
break;
default:
super.keyPressed(ev);
}
}
private void search(String search)
{
LinkBrowser.browse(WikiPlugin.WIKI_BASE + "?search=" + URLEncoder.encode(search) + "&" + WikiPlugin.UTM_PARAMS);
chatboxPanelManager.close();
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.wiki;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.runelite.api.SpriteID;
import net.runelite.client.game.SpriteOverride;
@RequiredArgsConstructor
public enum WikiSprite implements SpriteOverride
{
WIKI_ICON(-300, "wiki.png"),
WIKI_SELECTED_ICON(-301, "wiki_selected.png"),
FIXED_MODE_MINIMAP_CLICKMASK(SpriteID.MINIMAP_CLICK_MASK, "fixed_mode_minimap_clickmask.png");
@Getter
private final int spriteId;
@Getter
private final String fileName;
}

View File

@@ -30,6 +30,7 @@ import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.PixelGrabber;
import java.awt.image.RescaleOp;
import java.io.IOException;
@@ -426,8 +427,19 @@ public class ImageUtil
try
{
new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth())
.grabPixels();
PixelGrabber g = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
g.setColorModel(new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000));
g.grabPixels();
// Make any fully transparent pixels fully black, because the sprite draw routines
// check for == 0, not actual transparency
for (int i = 0; i < pixels.length; i++)
{
if ((pixels[i] & 0xFF000000) == 0)
{
pixels[i] = 0;
}
}
}
catch (InterruptedException ex)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -921,4 +921,8 @@ public interface RSClient extends RSGameEngine, Client
@Import("endY")
int getEndY();
@Import("spellSelected")
@Override
void setSpellSelected(boolean selected);
}

View File

@@ -328,6 +328,10 @@ public interface RSWidget extends Widget
@Override
void setOnMouseOverListener(Object... args);
@Import("onMouseRepeatListener")
@Override
void setOnMouseRepeatListener(Object... args);
@Import("onMouseLeaveListener")
@Override
void setOnMouseLeaveListener(Object... args);
@@ -336,6 +340,14 @@ public interface RSWidget extends Widget
@Override
void setOnTimerListener(Object... args);
@Import("onTargetEnterListener")
@Override
void setOnTargetEnterListener(Object... args);
@Import("onTargetLeaveListener")
@Override
void setOnTargetLeaveListener(Object... args);
@Import("fontId")
@Override
int getFontId();
@@ -435,4 +447,28 @@ public interface RSWidget extends Widget
@Import("filled")
@Override
void setFilled(boolean filled);
@Import("targetVerb")
@Override
String getTargetVerb();
@Import("targetVerb")
@Override
void setTargetVerb(String targetVerb);
@Import("noClickThrough")
@Override
boolean getNoClickThrough();
@Import("noClickThrough")
@Override
void setNoClickThrough(boolean noClickThrough);
@Import("noScrollThrough")
@Override
boolean getNoScrollThrough();
@Import("noScrollThrough")
@Override
void setNoScrollThrough(boolean noScrollThrough);
}