Merge pull request #1226 from Adam-/playerindicators2

Refactor playerindicators
This commit is contained in:
Adam
2018-04-01 15:31:04 -04:00
committed by GitHub
34 changed files with 523 additions and 470 deletions

View File

@@ -300,11 +300,6 @@ public class Instructions
add(ITEM_PRICE, "item_price", 1, 0);
add(SEND_BUG_REPORT, "send_bug_report", 1, 0, 2, 0);
add(SET_SHIFT_DROP_ENABLED, "set_shift_drop_enabled", 1, 0);
add(SET_DRAW_FRIEND_NAME, "set_draw_friend_name", 1, 0);
add(SET_DRAW_CLAN_NAME, "set_draw_clan_name", 1, 0);
add(SET_DRAW_ALL_EXCEPT_OWN_NAME, "set_draw_all_except_own_name", 1, 0);
add(SET_DRAW_OWN_NAME, "set_draw_own_name", 1, 0);
add(SET_DRAW_NO_NAMES, "set_draw_no_names", 1, 0);
// 3200-3300
add(PLAY_SOUND_EFFECT, "play_sound_effect", 3, 0);
add(3201, 1, 0);

View File

@@ -238,11 +238,6 @@ public class Opcodes
public static final int ITEM_PRICE = 3115;
public static final int SEND_BUG_REPORT = 3116;
public static final int SET_SHIFT_DROP_ENABLED = 3117;
public static final int SET_DRAW_FRIEND_NAME = 3120;
public static final int SET_DRAW_CLAN_NAME = 3121;
public static final int SET_DRAW_ALL_EXCEPT_OWN_NAME = 3122;
public static final int SET_DRAW_OWN_NAME = 3123;
public static final int SET_DRAW_NO_NAMES = 3124;
public static final int PLAY_SOUND_EFFECT = 3200;
public static final int GET_GAMECYCLE = 3300;
public static final int GET_ITEMCONTAINER_ITEMID = 3301;

View File

@@ -41,6 +41,8 @@ public interface Client extends GameEngine
NPC[] getCachedNPCs();
Player[] getCachedPlayers();
int getBoostedSkillLevel(Skill skill);
int getRealSkillLevel(Skill skill);
@@ -350,8 +352,4 @@ public interface Client extends GameEngine
World createWorld();
SpritePixels drawInstanceMap(int z);
void setPlayerNameMask(int mask);
int getPlayerNameMask();
}

View File

@@ -254,6 +254,9 @@ public enum MenuAction
* Menu action injected by runelite for its menu items.
*/
RUNELITE(1500),
FOLLOW(2046),
TRADE(2047),
/**
* Menu action triggered when the id is not defined in this class.

View File

@@ -31,10 +31,6 @@ public interface Player extends Actor
@Override
int getCombatLevel();
String getCleanName();
void setName(String name);
PlayerComposition getPlayerComposition();
Polygon[] getPolygons();

View File

@@ -1,33 +0,0 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@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.api;
public class PlayerNameMask
{
public static final int DRAW_FRIEND_NAME = 1;
public static final int DRAW_CLAN_NAME = 2;
public static final int DRAW_ALL_EXCEPT_OWN_NAME = 4;
public static final int DRAW_OWN_NAME = 8;
}

View File

@@ -43,6 +43,7 @@ import net.runelite.client.account.SessionManager;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.discord.DiscordService;
import net.runelite.client.game.ClanManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.PluginManager;
@@ -101,6 +102,9 @@ public class RuneLite
@Inject
private ItemManager itemManager;
@Inject
private ClanManager clanManager;
Client client;
public static void main(String[] args) throws Exception
@@ -161,6 +165,7 @@ public class RuneLite
eventBus.register(chatMessageManager);
eventBus.register(pluginManager);
eventBus.register(itemManager);
eventBus.register(clanManager);
// Load user configuration
configManager.load();

View File

@@ -0,0 +1,232 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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 com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.eventbus.Subscribe;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ClanMember;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.events.ClanChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.util.Text;
@Singleton
@Slf4j
public class ClanManager
{
private static final String[] CLANCHAT_IMAGES =
{
"Friend_clan_rank.png", "Recruit_clan_rank.png",
"Corporal_clan_rank.png", "Sergeant_clan_rank.png",
"Lieutenant_clan_rank.png", "Captain_clan_rank.png",
"General_clan_rank.png", "Owner_clan_rank.png"
};
private int modIconsLength;
private final Provider<Client> clientProvider;
private final BufferedImage[] clanChatImages = new BufferedImage[CLANCHAT_IMAGES.length];
private final LoadingCache<String, ClanMemberRank> clanRanksCache = CacheBuilder.newBuilder()
.maximumSize(100)
.expireAfterWrite(1, TimeUnit.MINUTES)
.build(new CacheLoader<String, ClanMemberRank>()
{
@Override
public ClanMemberRank load(String key) throws Exception
{
final Client client = clientProvider.get();
final ClanMember[] clanMembersArr = client.getClanMembers();
if (clanMembersArr == null || clanMembersArr.length == 0)
{
return ClanMemberRank.UNRANKED;
}
return Arrays.stream(clanMembersArr)
.filter(Objects::nonNull)
.filter(clanMember -> sanitize(clanMember.getUsername()).equals(sanitize(key)))
.map(ClanMember::getRank)
.findAny()
.orElse(ClanMemberRank.UNRANKED);
}
});
@Inject
public ClanManager(Provider<Client> clientProvider)
{
this.clientProvider = clientProvider;
int i = 0;
for (String resource : CLANCHAT_IMAGES)
{
try
{
final BufferedImage bufferedImage = rgbaToIndexedBufferedImage(ImageIO
.read(ClanManager.class.getResource(resource)));
clanChatImages[i] = bufferedImage;
}
catch (IOException e)
{
log.warn("unable to load clan image", e);
}
++i;
}
}
public ClanMemberRank getRank(String playerName)
{
return clanRanksCache.getUnchecked(playerName);
}
public BufferedImage getClanImage(final ClanMemberRank clanMemberRank)
{
if (clanMemberRank == ClanMemberRank.UNRANKED)
{
return null;
}
return clanChatImages[clanMemberRank.getValue()];
}
public int getIconNumber(final ClanMemberRank clanMemberRank)
{
return modIconsLength - CLANCHAT_IMAGES.length + clanMemberRank.getValue();
}
@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged)
{
if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN
&& modIconsLength == 0)
{
// this is after "Loading sprites" so we can modify modicons now
loadClanChatIcons();
}
}
@Subscribe
public void onClanChange(ClanChanged clanChanged)
{
clanRanksCache.invalidateAll();
}
private void loadClanChatIcons()
{
try
{
final Client client = clientProvider.get();
final IndexedSprite[] modIcons = client.getModIcons();
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
for (BufferedImage image : clanChatImages)
{
IndexedSprite sprite = createIndexedSprite(client, image);
newModIcons[curPosition++] = sprite;
}
client.setModIcons(newModIcons);
modIconsLength = newModIcons.length;
}
catch (IOException e)
{
log.warn("Failed loading of clan chat icons", e);
}
}
private static String sanitize(String lookup)
{
final String cleaned = Text.removeTags(lookup);
return cleaned.replace('\u00A0', ' ');
}
private static IndexedSprite createIndexedSprite(final Client client, final BufferedImage bufferedImage) throws IOException
{
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel();
final int width = bufferedImage.getWidth();
final int height = bufferedImage.getHeight();
final byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
final int[] palette = new int[indexedCM.getMapSize()];
indexedCM.getRGBs(palette);
final IndexedSprite newIndexedSprite = client.createIndexedSprite();
newIndexedSprite.setPixels(pixels);
newIndexedSprite.setPalette(palette);
newIndexedSprite.setWidth(width);
newIndexedSprite.setHeight(height);
newIndexedSprite.setOriginalWidth(width);
newIndexedSprite.setOriginalHeight(height);
newIndexedSprite.setOffsetX(0);
newIndexedSprite.setOffsetY(0);
return newIndexedSprite;
}
private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage)
{
final BufferedImage indexedImage = new BufferedImage(
sourceBufferedImage.getWidth(),
sourceBufferedImage.getHeight(),
BufferedImage.TYPE_BYTE_INDEXED);
final ColorModel cm = indexedImage.getColorModel();
final IndexColorModel icm = (IndexColorModel) cm;
final int size = icm.getMapSize();
final byte[] reds = new byte[size];
final byte[] greens = new byte[size];
final byte[] blues = new byte[size];
icm.getReds(reds);
icm.getGreens(greens);
icm.getBlues(blues);
final WritableRaster raster = indexedImage.getRaster();
final int pixel = raster.getSample(0, 0, 0);
final IndexColorModel resultIcm = new IndexColorModel(8, size, reds, greens, blues, pixel);
final BufferedImage resultIndexedImage = new BufferedImage(resultIcm, raster, sourceBufferedImage.isAlphaPremultiplied(), null);
resultIndexedImage.getGraphics().drawImage(sourceBufferedImage, 0, 0, null);
return resultIndexedImage;
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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.clanchat;
import com.google.common.eventbus.Subscribe;
import java.time.temporal.ChronoUnit;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.events.SetMessage;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.game.ClanManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
@PluginDescriptor(
name = "Clan Chat"
)
@Slf4j
public class ClanChatPlugin extends Plugin
{
@Inject
private Client client;
@Inject
private ClanManager clanManager;
@Schedule(
period = 600,
unit = ChronoUnit.MILLIS
)
public void updateClanChatTitle()
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
if (clanChatTitleWidget != null)
{
clanChatTitleWidget.setText("Clan Chat (" + client.getClanChatCount() + "/100)");
}
}
@Subscribe
public void onSetMessage(SetMessage setMessage)
{
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
{
return;
}
if (setMessage.getType() == ChatMessageType.CLANCHAT && client.getClanChatCount() > 0)
{
insertClanRankIcon(setMessage);
}
}
private void insertClanRankIcon(final SetMessage message)
{
final ClanMemberRank rank = clanManager.getRank(message.getName());
if (rank != null && rank != ClanMemberRank.UNRANKED)
{
int iconNumber = clanManager.getIconNumber(rank);
message.getMessageNode()
.setSender(message.getMessageNode().getSender() + " <img=" + iconNumber + ">");
client.refreshChat();
}
}
}

View File

@@ -32,7 +32,6 @@ import java.util.concurrent.ScheduledExecutorService;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import net.runelite.api.Text;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.PlayerMenuOptionClicked;
import net.runelite.client.config.ConfigManager;
@@ -139,7 +138,7 @@ public class HiscorePlugin extends Plugin
throw new RuntimeException(e);
}
hiscorePanel.lookup(Text.removeTags(event.getMenuTarget()));
hiscorePanel.lookup(event.getMenuTarget());
});
}
}

View File

@@ -37,7 +37,6 @@ import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemComposition;
import net.runelite.api.MenuEntry;
import net.runelite.api.Text;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.PostItemComposition;
@@ -53,6 +52,7 @@ import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Menu Entry Swapper",

View File

@@ -39,7 +39,7 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.api.Text;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Nightmare Zone"

View File

@@ -45,7 +45,7 @@ import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.BackgroundComponent;
import net.runelite.client.ui.overlay.components.TextComponent;
import net.runelite.api.Text;
import net.runelite.client.util.Text;
class OpponentInfoOverlay extends Overlay
{

View File

@@ -55,7 +55,7 @@ public interface PlayerIndicatorsConfig extends Config
)
default Color getOwnNameColor()
{
return Color.WHITE;
return new Color(0, 184, 212);
}
@ConfigItem(
@@ -110,7 +110,7 @@ public interface PlayerIndicatorsConfig extends Config
)
default boolean drawTeamMemberNames()
{
return false;
return true;
}
@ConfigItem(
@@ -126,11 +126,11 @@ public interface PlayerIndicatorsConfig extends Config
@ConfigItem(
position = 8,
keyName = "drawOthers",
name = "Draw names of others",
description = "Configures whether or not names of everyone except you should be drawn"
keyName = "drawNonClanMemberNames",
name = "Draw non-clan member names",
description = "Configures whether or not names of non-clan members should be drawn"
)
default boolean drawNonOwnNames()
default boolean drawNonClanMemberNames()
{
return false;
}
@@ -141,9 +141,9 @@ public interface PlayerIndicatorsConfig extends Config
name = "Non-clan member color",
description = "Color of non-clan member names"
)
default Color getNonOwnColor()
default Color getNonClanMemberColor()
{
return Color.WHITE;
return Color.RED;
}
@ConfigItem(
@@ -167,15 +167,4 @@ public interface PlayerIndicatorsConfig extends Config
{
return false;
}
@ConfigItem(
position = 12,
keyName = "showClanRankIcons",
name = "Show clan member rank icons next to names",
description = "Configures whether or not icons representing rank are shown next to player names"
)
default boolean showClanRankIcons()
{
return true;
}
}

View File

@@ -55,22 +55,22 @@ public class PlayerIndicatorsMinimapOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
if (config.drawMinimapNames())
{
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
}
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
return null;
}
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color)
{
final String name = actor.getName();
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
final String name = actor.getName().replace('\u00A0', ' ');
if (minimapLocation != null)
if (config.drawMinimapNames())
{
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
}
}
}
}

View File

@@ -28,11 +28,14 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.client.game.ClanManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -42,35 +45,61 @@ public class PlayerIndicatorsOverlay extends Overlay
{
private final PlayerIndicatorsService playerIndicatorsService;
private final PlayerIndicatorsConfig config;
private final ClanManager clanManager;
@Inject
private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService)
private PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService,
ClanManager clanManager)
{
this.config = config;
this.playerIndicatorsService = playerIndicatorsService;
setLayer(OverlayLayer.ABOVE_SCENE);
this.clanManager = clanManager;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.LOW);
setPriority(OverlayPriority.HIGH);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (config.drawTiles())
{
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
}
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
return null;
}
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color)
{
Polygon poly = actor.getCanvasTilePoly();
if (poly != null)
if (config.drawTiles())
{
OverlayUtil.renderPolygon(graphics, poly, color);
Polygon poly = actor.getCanvasTilePoly();
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, color);
}
}
String name = actor.getName().replace('\u00A0', ' ');
int offset = actor.getLogicalHeight() + 40;
Point textLocation = actor.getCanvasTextLocation(graphics, name, offset);
if (textLocation != null)
{
if (actor.isClanMember())
{
ClanMemberRank rank = clanManager.getRank(name);
if (rank != ClanMemberRank.UNRANKED)
{
BufferedImage clanchatImage = clanManager.getClanImage(rank);
if (clanchatImage != null)
{
int width = clanchatImage.getWidth();
Point imageLocation = new Point(textLocation.getX() - width / 2, textLocation.getY() - clanchatImage.getHeight());
OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage);
// move text
textLocation = new Point(textLocation.getX() + width / 2, textLocation.getY());
}
}
}
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
}
}
}

View File

@@ -27,22 +27,31 @@ package net.runelite.client.plugins.playerindicators;
import com.google.common.collect.Sets;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.time.temporal.ChronoUnit;
import java.awt.Color;
import java.util.Collection;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.ClanMemberRank;
import static net.runelite.api.ClanMemberRank.UNRANKED;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.events.ClanChanged;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.SetMessage;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import static net.runelite.api.MenuAction.FOLLOW;
import static net.runelite.api.MenuAction.ITEM_USE_ON_PLAYER;
import static net.runelite.api.MenuAction.PLAYER_EIGTH_OPTION;
import static net.runelite.api.MenuAction.PLAYER_FIFTH_OPTION;
import static net.runelite.api.MenuAction.PLAYER_FIRST_OPTION;
import static net.runelite.api.MenuAction.PLAYER_FOURTH_OPTION;
import static net.runelite.api.MenuAction.PLAYER_SECOND_OPTION;
import static net.runelite.api.MenuAction.PLAYER_SEVENTH_OPTION;
import static net.runelite.api.MenuAction.PLAYER_SIXTH_OPTION;
import static net.runelite.api.MenuAction.PLAYER_THIRD_OPTION;
import static net.runelite.api.MenuAction.SPELL_CAST_ON_PLAYER;
import static net.runelite.api.MenuAction.TRADE;
import net.runelite.api.MenuEntry;
import net.runelite.api.Player;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ClanManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.overlay.Overlay;
@PluginDescriptor(
@@ -51,7 +60,7 @@ import net.runelite.client.ui.overlay.Overlay;
public class PlayerIndicatorsPlugin extends Plugin
{
@Inject
private Client client;
private PlayerIndicatorsConfig config;
@Inject
private PlayerIndicatorsOverlay playerIndicatorsOverlay;
@@ -60,7 +69,10 @@ public class PlayerIndicatorsPlugin extends Plugin
private PlayerIndicatorsMinimapOverlay playerIndicatorsMinimapOverlay;
@Inject
private PlayerIndicatorsService playerIndicatorsService;
private Client client;
@Inject
private ClanManager clanManager;
@Provides
PlayerIndicatorsConfig provideConfig(ConfigManager configManager)
@@ -74,77 +86,87 @@ public class PlayerIndicatorsPlugin extends Plugin
return Sets.newHashSet(playerIndicatorsOverlay, playerIndicatorsMinimapOverlay);
}
@Override
protected void startUp()
{
playerIndicatorsService.invalidatePlayerNames();
playerIndicatorsService.updateConfig();
}
@Override
protected void shutDown()
{
playerIndicatorsService.invalidatePlayerNames();
playerIndicatorsService.invalidateClanRanksCache();
client.setPlayerNameMask(0);
}
@Subscribe
public void onConfigChanged(ConfigChanged event)
public void onMenuEntryAdd(MenuEntryAdded menuEntryAdded)
{
if (event.getGroup().equals("playerindicators"))
int type = menuEntryAdded.getType();
int identifier = menuEntryAdded.getIdentifier();
if (type == FOLLOW.getId() || type == TRADE.getId()
|| type == SPELL_CAST_ON_PLAYER.getId() || type == ITEM_USE_ON_PLAYER.getId()
|| type == PLAYER_FIRST_OPTION.getId()
|| type == PLAYER_SECOND_OPTION.getId()
|| type == PLAYER_THIRD_OPTION.getId()
|| type == PLAYER_FOURTH_OPTION.getId()
|| type == PLAYER_FIFTH_OPTION.getId()
|| type == PLAYER_SIXTH_OPTION.getId()
|| type == PLAYER_SEVENTH_OPTION.getId()
|| type == PLAYER_EIGTH_OPTION.getId())
{
playerIndicatorsService.invalidatePlayerNames();
playerIndicatorsService.updateConfig();
final Player localPlayer = client.getLocalPlayer();
Player[] players = client.getCachedPlayers();
Player player = null;
if (identifier >= 0 && identifier < players.length)
{
player = players[identifier];
}
if (player == null)
{
return;
}
int image = -1;
Color color = null;
if (config.drawFriendNames() && player.isFriend())
{
color = config.getFriendNameColor();
}
else if (config.drawClanMemberNames() && player.isClanMember())
{
color = config.getClanMemberColor();
ClanMemberRank rank = clanManager.getRank(player.getName());
if (rank != UNRANKED)
{
image = clanManager.getIconNumber(rank);
}
}
else if (config.drawTeamMemberNames() && player.getTeam() > 0 && localPlayer.getTeam() == player.getTeam())
{
color = config.getTeamMemberColor();
}
else if (config.drawNonClanMemberNames() && !player.isClanMember())
{
color = config.getNonClanMemberColor();
}
if (image != -1 || color != null)
{
MenuEntry[] menuEntries = client.getMenuEntries();
MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
if (color != null)
{
// strip out existing <col...
String target = lastEntry.getTarget();
int idx = target.indexOf('>');
if (idx != -1)
{
target = target.substring(idx + 1);
}
lastEntry.setTarget("<col=" + Integer.toHexString(color.getRGB() & 0xFFFFFF) + ">" + target);
}
if (image != -1)
{
lastEntry.setTarget("<img=" + image + ">" + lastEntry.getTarget());
}
client.setMenuEntries(menuEntries);
}
}
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
if (event.getGameState() == GameState.LOGGED_IN)
{
playerIndicatorsService.updateConfig();
}
}
@Subscribe
public void onClanChanged(ClanChanged event)
{
playerIndicatorsService.invalidateClanRanksCache();
}
@Subscribe
public void onSetMessage(SetMessage setMessage)
{
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
{
return;
}
if (setMessage.getType() == ChatMessageType.CLANCHAT && client.getClanChatCount() > 0)
{
playerIndicatorsService.insertClanRankIcon(setMessage);
}
}
@Schedule(
period = 1,
unit = ChronoUnit.SECONDS
)
public void updatePlayerNames()
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
if (clanChatTitleWidget != null)
{
clanChatTitleWidget.setText("Clan Chat (" + client.getClanChatCount() + "/100)");
}
playerIndicatorsService.updatePlayers();
}
}

View File

@@ -24,74 +24,18 @@
*/
package net.runelite.client.plugins.playerindicators;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import javax.annotation.Nonnull;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ClanMember;
import net.runelite.api.ClanMemberRank;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.Player;
import net.runelite.api.PlayerNameMask;
import net.runelite.api.events.SetMessage;
import net.runelite.api.Text;
@Singleton
@Slf4j
public class PlayerIndicatorsService
{
private static final String[] CLANCHAT_IMAGES =
{
"Friend_clan_rank.png", "Recruit_clan_rank.png",
"Corporal_clan_rank.png", "Sergeant_clan_rank.png",
"Lieutenant_clan_rank.png", "Captain_clan_rank.png",
"General_clan_rank.png", "Owner_clan_rank.png"
};
private final LoadingCache<String, ClanMemberRank> clanRanksCache = CacheBuilder.newBuilder()
.maximumSize(100)
.expireAfterWrite(1, TimeUnit.MINUTES)
.build(new CacheLoader<String, ClanMemberRank>()
{
@Override
public ClanMemberRank load(@Nonnull String key)
{
final ClanMember[] clanMembersArr = client.getClanMembers();
if (clanMembersArr == null || clanMembersArr.length == 0)
{
return ClanMemberRank.UNRANKED;
}
return Arrays.stream(clanMembersArr)
.filter(Objects::nonNull)
.filter(clanMember -> clanMember.getUsername().equals(key))
.map(ClanMember::getRank)
.findAny()
.orElse(ClanMemberRank.UNRANKED);
}
});
private final Client client;
private final PlayerIndicatorsConfig config;
private int modIconsLength;
@Inject
private PlayerIndicatorsService(Client client, PlayerIndicatorsConfig config)
@@ -100,69 +44,14 @@ public class PlayerIndicatorsService
this.client = client;
}
public void invalidatePlayerNames()
{
// Reset player names
for (Player player : client.getPlayers())
{
if (player != null && player.getName() != null)
{
player.setName(player.getName());
}
}
// Refresh chat box
client.refreshChat();
}
public void invalidateClanRanksCache()
{
// Invalidate clan cache
clanRanksCache.invalidateAll();
}
public void updateConfig()
{
// Update mod icons
if (modIconsLength == 0 && client.getGameState().compareTo(GameState.LOGGED_IN) >= 0)
{
loadClanChatIcons();
}
// Update mask
int baseMask = 0;
if (config.drawFriendNames())
{
baseMask |= PlayerNameMask.DRAW_FRIEND_NAME;
}
if (config.drawClanMemberNames())
{
baseMask |= PlayerNameMask.DRAW_CLAN_NAME;
}
if (config.drawOwnName())
{
baseMask |= PlayerNameMask.DRAW_OWN_NAME;
}
if (config.drawNonOwnNames())
{
baseMask |= PlayerNameMask.DRAW_ALL_EXCEPT_OWN_NAME;
}
client.setPlayerNameMask(baseMask);
}
public void updatePlayers()
{
// Update player names
forEachPlayer(this::injectData);
}
public void forEachPlayer(final BiConsumer<Player, Color> consumer)
{
if (!config.drawOwnName() && !config.drawClanMemberNames()
&& !config.drawFriendNames() && !config.drawNonClanMemberNames())
{
return;
}
final Player localPlayer = client.getLocalPlayer();
for (Player player : client.getPlayers())
@@ -193,135 +82,10 @@ public class PlayerIndicatorsService
{
consumer.accept(player, config.getTeamMemberColor());
}
else if (config.drawNonOwnNames())
else if (config.drawNonClanMemberNames() && !isClanMember)
{
consumer.accept(player, config.getNonOwnColor());
consumer.accept(player, config.getNonClanMemberColor());
}
}
}
public void insertClanRankIcon(final SetMessage message)
{
if (!config.showClanRankIcons())
{
return;
}
final String playerName = Text.removeTags(message.getName());
final ClanMemberRank rank = clanRanksCache.getUnchecked(playerName);
if (rank != null && rank != ClanMemberRank.UNRANKED)
{
int iconNumber = getIconNumber(rank);
message.getMessageNode()
.setSender(message.getMessageNode().getSender() + " <img=" + iconNumber + ">");
client.refreshChat();
}
}
private void injectData(final Player player, final Color color)
{
final StringBuilder stringBuilder = new StringBuilder();
final String playerName = player.getName();
if (config.showClanRankIcons() && player.isClanMember())
{
final ClanMemberRank clanMemberRank = clanRanksCache.getUnchecked(playerName);
if (clanMemberRank != ClanMemberRank.UNRANKED)
{
stringBuilder
.append("<img=")
.append(getIconNumber(clanMemberRank))
.append(">");
}
}
stringBuilder.append("<col=").append(parseColor(color)).append(">");
player.setName(stringBuilder.toString() + playerName);
}
private static String parseColor(final Color color)
{
return String.format("%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
}
private void loadClanChatIcons()
{
try
{
final IndexedSprite[] modIcons = client.getModIcons();
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
for (String resource : CLANCHAT_IMAGES)
{
IndexedSprite sprite = createIndexedSprite(resource);
newModIcons[curPosition++] = sprite;
}
client.setModIcons(newModIcons);
modIconsLength = newModIcons.length;
}
catch (IOException e)
{
log.warn("Failed loading of clan chat icons", e);
}
}
private IndexedSprite createIndexedSprite(final String imagePath) throws IOException
{
final BufferedImage bufferedImage = rgbaToIndexedBufferedImage(ImageIO
.read(this.getClass().getResource(imagePath)));
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel();
final int width = bufferedImage.getWidth();
final int height = bufferedImage.getHeight();
final byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
final int[] palette = new int[indexedCM.getMapSize()];
indexedCM.getRGBs(palette);
final IndexedSprite newIndexedSprite = client.createIndexedSprite();
newIndexedSprite.setPixels(pixels);
newIndexedSprite.setPalette(palette);
newIndexedSprite.setWidth(width);
newIndexedSprite.setHeight(height);
newIndexedSprite.setOriginalWidth(width);
newIndexedSprite.setOriginalHeight(height);
newIndexedSprite.setOffsetX(0);
newIndexedSprite.setOffsetY(0);
return newIndexedSprite;
}
private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage)
{
final BufferedImage indexedImage = new BufferedImage(
sourceBufferedImage.getWidth(),
sourceBufferedImage.getHeight(),
BufferedImage.TYPE_BYTE_INDEXED);
final ColorModel cm = indexedImage.getColorModel();
final IndexColorModel icm = (IndexColorModel) cm;
final int size = icm.getMapSize();
final byte[] reds = new byte[size];
final byte[] greens = new byte[size];
final byte[] blues = new byte[size];
icm.getReds(reds);
icm.getGreens(greens);
icm.getBlues(blues);
final WritableRaster raster = indexedImage.getRaster();
final int pixel = raster.getSample(0, 0, 0);
final IndexColorModel resultIcm = new IndexColorModel(8, size, reds, greens, blues, pixel);
final BufferedImage resultIndexedImage = new BufferedImage(resultIcm, raster, sourceBufferedImage.isAlphaPremultiplied(), null);
resultIndexedImage.getGraphics().drawImage(sourceBufferedImage, 0, 0, null);
return resultIndexedImage;
}
private int getIconNumber(final ClanMemberRank clanMemberRank)
{
return modIconsLength - CLANCHAT_IMAGES.length + clanMemberRank.getValue();
}
}

View File

@@ -70,7 +70,7 @@ import net.runelite.client.plugins.raids.solver.LayoutSolver;
import net.runelite.client.plugins.raids.solver.RotationSolver;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.api.Text;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Chambers Of Xeric"

View File

@@ -78,7 +78,7 @@ import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.TitleToolbar;
import net.runelite.client.ui.overlay.OverlayRenderer;
import net.runelite.api.Text;
import net.runelite.client.util.Text;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
import okhttp3.Callback;

View File

@@ -57,7 +57,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.task.Schedule;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.api.Text;
import net.runelite.client.util.Text;
@PluginDescriptor(
name = "Slayer"

View File

@@ -22,7 +22,7 @@
* (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.api;
package net.runelite.client.util;
/**
* A set of utilities to use when dealing with text.

View File

@@ -24,7 +24,6 @@
*/
package net.runelite.client.util;
import net.runelite.api.Text;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

View File

@@ -30,7 +30,6 @@ import java.util.List;
import net.runelite.api.Model;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.Text;
import net.runelite.api.model.Triangle;
import net.runelite.api.model.Vertex;
import net.runelite.api.mixins.Inject;
@@ -64,35 +63,7 @@ public abstract class RSPlayerMixin implements RSPlayer
return null;
}
return Text.removeTags(name.replace('\u00A0', ' '));
}
@Inject
@Override
public String getCleanName()
{
final RSName rsName = getRsName();
if (rsName == null)
{
return null;
}
return rsName.getCleanName();
}
@Inject
@Override
public void setName(String name)
{
final RSName rsName = getRsName();
if (rsName == null)
{
return;
}
rsName.setName(name);
return name.replace('\u00A0', ' ');
}
@Inject

View File

@@ -163,6 +163,7 @@ public interface RSClient extends RSGameEngine, Client
int[] getPlayerIndices();
@Import("cachedPlayers")
@Override
RSPlayer[] getCachedPlayers();
@Import("localInteractingIndex")
@@ -549,12 +550,4 @@ public interface RSClient extends RSGameEngine, Client
@Import("drawObject")
void drawObject(int z, int x, int y, int randomColor1, int randomColor2);
@Import("playerNameMask")
@Override
void setPlayerNameMask(int mask);
@Import("playerNameMask")
@Override
int getPlayerNameMask();
}

View File

@@ -30,10 +30,4 @@ public interface RSName
{
@Import("name")
String getName();
@Import("cleanName")
String getCleanName();
@Import("name")
void setName(String name);
}