Merge pull request #7704 from deathbeam/add-color-hashes

Recolor party pings and names based on name color hash
This commit is contained in:
Tomas Slusny
2019-02-06 08:03:38 +00:00
committed by GitHub
8 changed files with 50 additions and 7 deletions

View File

@@ -61,7 +61,6 @@ public interface PartyConfig extends Config
return true;
}
@ConfigItem(
keyName = "messages",
name = "Join messages",
@@ -71,4 +70,14 @@ public interface PartyConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "recolorNames",
name = "Recolor names",
description = "Recolor stats overlay names based on unique color hash"
)
default boolean recolorNames()
{
return true;
}
}

View File

@@ -110,6 +110,12 @@ class PartyPingOverlay extends Overlay
return;
}
OverlayUtil.renderPolygon(graphics, poly, new Color(255, 0, 0, ping.getAlpha()));
final Color color = new Color(
ping.getColor().getRed(),
ping.getColor().getGreen(),
ping.getColor().getBlue(),
ping.getAlpha());
OverlayUtil.renderPolygon(graphics, poly, color);
}
}

View File

@@ -26,6 +26,7 @@ package net.runelite.client.plugins.party;
import com.google.inject.Binder;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -71,6 +72,7 @@ import net.runelite.client.task.Schedule;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
import net.runelite.client.ui.overlay.worldmap.WorldMapPointManager;
import net.runelite.client.util.ColorUtil;
import net.runelite.client.ws.PartyMember;
import net.runelite.client.ws.PartyService;
import net.runelite.client.ws.WSClient;
@@ -228,7 +230,9 @@ public class PartyPlugin extends Plugin implements KeyListener
}
event.consume();
wsClient.send(new TilePing(selectedSceneTile.getWorldLocation()));
final TilePing tilePing = new TilePing(selectedSceneTile.getWorldLocation());
tilePing.setMemberId(party.getLocalMember().getMemberId());
wsClient.send(tilePing);
}
@Subscribe
@@ -238,7 +242,9 @@ public class PartyPlugin extends Plugin implements KeyListener
if (config.pings())
{
pendingTilePings.add(new PartyTilePingData(event.getPoint()));
final PartyData partyData = getPartyData(event.getMemberId());
final Color color = partyData != null ? partyData.getColor() : Color.RED;
pendingTilePings.add(new PartyTilePingData(event.getPoint(), color));
}
if (config.sounds())
@@ -470,7 +476,7 @@ public class PartyPlugin extends Plugin implements KeyListener
worldMapManager.add(worldMapPoint);
}
return new PartyData(u, name, worldMapPoint);
return new PartyData(u, name, worldMapPoint, ColorUtil.fromObject(name, true));
});
}

View File

@@ -102,6 +102,7 @@ public class PartyStatsOverlay extends Overlay
final TitleComponent name = TitleComponent.builder()
.text(v.getName())
.color(config.recolorNames() ? v.getColor() : Color.WHITE)
.build();
panel.getChildren().add(name);

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.client.plugins.party.data;
import java.awt.Color;
import java.util.UUID;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -40,6 +41,7 @@ public class PartyData
private final String name;
private final WorldMapPoint worldMapPoint;
private final PanelComponent panel = new PanelComponent();
private final Color color;
private int hitpoints;
private int maxHitpoints;

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.client.plugins.party.data;
import java.awt.Color;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@@ -35,5 +36,6 @@ import net.runelite.api.coords.WorldPoint;
public class PartyTilePingData
{
private final WorldPoint point;
private final Color color;
private int alpha = 255;
}

View File

@@ -26,10 +26,10 @@ package net.runelite.client.plugins.party.messages;
import lombok.Value;
import net.runelite.api.coords.WorldPoint;
import net.runelite.http.api.ws.messages.party.PartyMessage;
import net.runelite.http.api.ws.messages.party.PartyMemberMessage;
@Value
public class TilePing extends PartyMessage
public class TilePing extends PartyMemberMessage
{
private final WorldPoint point;
}

View File

@@ -27,6 +27,7 @@ package net.runelite.client.util;
import com.google.common.primitives.Ints;
import java.awt.Color;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
public class ColorUtil
{
@@ -226,4 +227,20 @@ public class ColorUtil
return null;
}
}
/**
* Creates color from passed object hash code
* @param object object with hashCode
* @param skipAlpha skips alpha
* @return color
*/
public static Color fromObject(@Nonnull final Object object, boolean skipAlpha)
{
int i = object.hashCode();
int r = (i >> 24) & 0xFF;
int g = (i >> 16) & 0xFF;
int b = (i >> 8) & 0xFF;
int a = i & 0xFF;
return new Color(r, g, b, skipAlpha ? 255 : a);
}
}