Fix drawing of player names on minimap

Move drawing player names on minimap to separate overlay, so the minimap
names can be rendered over minimap in resizeable mode.

Fixes #940

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-03-14 10:09:31 +01:00
parent 4c9a3bcea9
commit 2f3dbb2678
4 changed files with 171 additions and 56 deletions

View File

@@ -0,0 +1,73 @@
/*
* 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.client.plugins.playerindicators;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import net.runelite.api.Player;
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;
public class PlayerIndicatorsMinimapOverlay extends Overlay
{
private final PlayerIndicatorsService playerIndicatorsService;
private final PlayerIndicatorsConfig config;
PlayerIndicatorsMinimapOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService)
{
this.config = config;
this.playerIndicatorsService = playerIndicatorsService;
setLayer(OverlayLayer.ABOVE_WIDGETS);
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
}
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
return null;
}
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color)
{
final String name = actor.getName().replace('\u00A0', ' ');
if (config.drawMinimapNames())
{
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
}
}
}
}

View File

@@ -29,24 +29,21 @@ import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
@Slf4j
public class PlayerIndicatorsOverlay extends Overlay
{
private final Client client;
private final PlayerIndicatorsService playerIndicatorsService;
private final PlayerIndicatorsConfig config;
PlayerIndicatorsOverlay(Client client, PlayerIndicatorsConfig config)
PlayerIndicatorsOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService)
{
this.config = config;
this.client = client;
this.playerIndicatorsService = playerIndicatorsService;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
}
@@ -54,42 +51,7 @@ public class PlayerIndicatorsOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
if (!config.drawOwnName() && !config.drawClanMemberNames()
&& !config.drawFriendNames() && !config.drawNonClanMemberNames())
{
return null;
}
for (Player player : client.getPlayers())
{
if (player == null || player.getName() == null)
{
continue;
}
boolean isClanMember = player.isClanMember();
if (player == client.getLocalPlayer())
{
if (config.drawOwnName())
{
renderPlayerOverlay(graphics, player, config.getOwnNameColor());
}
}
else if (config.drawFriendNames() && player.isFriend())
{
renderPlayerOverlay(graphics, player, config.getFriendNameColor());
}
else if (config.drawClanMemberNames() && isClanMember)
{
renderPlayerOverlay(graphics, player, config.getClanMemberColor());
}
else if (config.drawNonClanMemberNames() && !isClanMember)
{
renderPlayerOverlay(graphics, player, config.getNonClanMemberColor());
}
}
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
return null;
}
@@ -112,15 +74,5 @@ public class PlayerIndicatorsOverlay extends Overlay
{
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
}
if (config.drawMinimapNames())
{
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
}
}
}
}

View File

@@ -24,7 +24,9 @@
*/
package net.runelite.client.plugins.playerindicators;
import com.google.common.collect.Sets;
import com.google.inject.Provides;
import java.util.Collection;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.config.ConfigManager;
@@ -43,7 +45,7 @@ public class PlayerIndicatorsPlugin extends Plugin
@Inject
private PlayerIndicatorsConfig config;
PlayerIndicatorsOverlay playerIndicatorsOverlay;
private Collection<Overlay> overlays;
@Provides
PlayerIndicatorsConfig provideConfig(ConfigManager configManager)
@@ -54,12 +56,19 @@ public class PlayerIndicatorsPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
playerIndicatorsOverlay = new PlayerIndicatorsOverlay(client, config);
final PlayerIndicatorsService playerIndicatorsService =
new PlayerIndicatorsService(client, config);
final PlayerIndicatorsOverlay playerIndicatorsOverlay =
new PlayerIndicatorsOverlay(config, playerIndicatorsService);
final PlayerIndicatorsMinimapOverlay playerIndicatorsMinimapOverlay =
new PlayerIndicatorsMinimapOverlay(config, playerIndicatorsService);
overlays = Sets.newHashSet(playerIndicatorsOverlay, playerIndicatorsMinimapOverlay);
}
@Override
public Overlay getOverlay()
public Collection<Overlay> getOverlays()
{
return playerIndicatorsOverlay;
return overlays;
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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.client.plugins.playerindicators;
import java.awt.Color;
import java.util.function.BiConsumer;
import net.runelite.api.Client;
import net.runelite.api.Player;
public class PlayerIndicatorsService
{
private final Client client;
private final PlayerIndicatorsConfig config;
PlayerIndicatorsService(Client client, PlayerIndicatorsConfig config)
{
this.config = config;
this.client = client;
}
public void forEachPlayer(final BiConsumer<Player, Color> consumer)
{
if (!config.drawOwnName() && !config.drawClanMemberNames()
&& !config.drawFriendNames() && !config.drawNonClanMemberNames())
{
return;
}
for (Player player : client.getPlayers())
{
if (player == null || player.getName() == null)
{
continue;
}
boolean isClanMember = player.isClanMember();
if (player == client.getLocalPlayer())
{
if (config.drawOwnName())
{
consumer.accept(player, config.getOwnNameColor());
}
}
else if (config.drawFriendNames() && player.isFriend())
{
consumer.accept(player, config.getFriendNameColor());
}
else if (config.drawClanMemberNames() && isClanMember)
{
consumer.accept(player, config.getClanMemberColor());
}
else if (config.drawNonClanMemberNames() && !isClanMember)
{
consumer.accept(player, config.getNonClanMemberColor());
}
}
}
}