fishing plugin: move minimap overlay to own overlay

To render above the minimap in resizable, it must be above widgets
This commit is contained in:
Adam
2018-02-09 15:15:58 -05:00
parent c18afb58f5
commit 5c6a205a8a
4 changed files with 169 additions and 71 deletions

View File

@@ -25,23 +25,32 @@
package net.runelite.client.plugins.fishing;
import com.google.common.eventbus.Subscribe;
import com.google.common.primitives.Ints;
import com.google.inject.Binder;
import com.google.inject.Provides;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.ChatMessageType;
import net.runelite.client.config.ConfigManager;
import net.runelite.api.NPC;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.config.ConfigManager;
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;
import net.runelite.client.util.QueryRunner;
@PluginDescriptor(
name = "Fishing plugin"
@@ -49,6 +58,14 @@ import net.runelite.client.ui.overlay.Overlay;
@Singleton
public class FishingPlugin extends Plugin
{
private final List<Integer> spotIds = new ArrayList<>();
@Getter(AccessLevel.PACKAGE)
private NPC[] fishingSpots;
@Inject
private QueryRunner queryRunner;
@Inject
private FishingConfig config;
@@ -58,6 +75,9 @@ public class FishingPlugin extends Plugin
@Inject
private FishingSpotOverlay spotOverlay;
@Inject
private FishingSpotMinimapOverlay fishingSpotMinimapOverlay;
private final FishingSession session = new FishingSession();
@Override
@@ -76,13 +96,13 @@ public class FishingPlugin extends Plugin
protected void startUp() throws Exception
{
// Initialize overlay config
spotOverlay.updateConfig();
updateConfig();
}
@Override
public Collection<Overlay> getOverlays()
{
return Arrays.asList(overlay, spotOverlay);
return Arrays.asList(overlay, spotOverlay, fishingSpotMinimapOverlay);
}
public FishingSession getSession()
@@ -107,7 +127,56 @@ public class FishingPlugin extends Plugin
@Subscribe
public void updateConfig(ConfigChanged event)
{
spotOverlay.updateConfig();
updateConfig();
}
private void updateConfig()
{
spotIds.clear();
if (config.showShrimp())
{
spotIds.addAll(Ints.asList(FishingSpot.SHRIMP.getIds()));
}
if (config.showLobster())
{
spotIds.addAll(Ints.asList(FishingSpot.LOBSTER.getIds()));
}
if (config.showShark())
{
spotIds.addAll(Ints.asList(FishingSpot.SHARK.getIds()));
}
if (config.showMonkfish())
{
spotIds.addAll(Ints.asList(FishingSpot.MONKFISH.getIds()));
}
if (config.showSalmon())
{
spotIds.addAll(Ints.asList(FishingSpot.SALMON.getIds()));
}
if (config.showBarb())
{
spotIds.addAll(Ints.asList(FishingSpot.BARB_FISH.getIds()));
}
if (config.showAngler())
{
spotIds.addAll(Ints.asList(FishingSpot.ANGLERFISH.getIds()));
}
if (config.showMinnow())
{
spotIds.addAll(Ints.asList(FishingSpot.MINNOW.getIds()));
}
if (config.showInfernalEel())
{
spotIds.addAll(Ints.asList(FishingSpot.INFERNAL_EEL.getIds()));
}
}
@Subscribe
public void checkSpots(GameTick event)
{
NPCQuery query = new NPCQuery()
.idEquals(Ints.toArray(spotIds));
fishingSpots = queryRunner.runQuery(query);
}
@Schedule(

View File

@@ -0,0 +1,86 @@
/*
* 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.plugins.fishing;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.inject.Inject;
import net.runelite.api.NPC;
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.OverlayUtil;
class FishingSpotMinimapOverlay extends Overlay
{
private final FishingPlugin plugin;
private final FishingConfig config;
@Inject
public FishingSpotMinimapOverlay(FishingPlugin plugin, FishingConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.plugin = plugin;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
if (!config.enabled())
{
return null;
}
NPC[] fishingSpots = plugin.getFishingSpots();
if (fishingSpots == null)
{
return null;
}
for (NPC npc : fishingSpots)
{
FishingSpot spot = FishingSpot.getSpot(npc.getId());
if (spot == null)
{
continue;
}
Color color = npc.getId() == FishingSpot.FLYING_FISH ? Color.RED : Color.CYAN;
net.runelite.api.Point minimapLocation = npc.getMinimapLocation();
if (minimapLocation != null)
{
OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker());
}
}
return null;
}
}

View File

@@ -24,40 +24,33 @@
*/
package net.runelite.client.plugins.fishing;
import com.google.common.primitives.Ints;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.game.ItemManager;
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.OverlayUtil;
import net.runelite.client.util.QueryRunner;
class FishingSpotOverlay extends Overlay
{
private final List<Integer> ids = new ArrayList<>();
private final QueryRunner queryRunner;
private final FishingPlugin plugin;
private final FishingConfig config;
@Inject
ItemManager itemManager;
@Inject
public FishingSpotOverlay(QueryRunner queryRunner, FishingConfig config)
public FishingSpotOverlay(FishingPlugin plugin, FishingConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.queryRunner = queryRunner;
this.plugin = plugin;
this.config = config;
}
@@ -69,11 +62,13 @@ class FishingSpotOverlay extends Overlay
return null;
}
NPCQuery query = new NPCQuery()
.idEquals(Ints.toArray(ids));
NPC[] npcs = queryRunner.runQuery(query);
NPC[] fishingSpots = plugin.getFishingSpots();
if (fishingSpots == null)
{
return null;
}
for (NPC npc : npcs)
for (NPC npc : fishingSpots)
{
FishingSpot spot = FishingSpot.getSpot(npc.getId());
@@ -81,6 +76,7 @@ class FishingSpotOverlay extends Overlay
{
continue;
}
Color color = npc.getId() == FishingSpot.FLYING_FISH ? Color.RED : Color.CYAN;
if (config.showIcons())
{
@@ -105,45 +101,4 @@ class FishingSpotOverlay extends Overlay
BufferedImage fishImage = itemManager.getImage(spot.getFishSpriteId());
return fishImage;
}
public void updateConfig()
{
ids.clear();
if (config.showShrimp())
{
ids.addAll(Ints.asList(FishingSpot.SHRIMP.getIds()));
}
if (config.showLobster())
{
ids.addAll(Ints.asList(FishingSpot.LOBSTER.getIds()));
}
if (config.showShark())
{
ids.addAll(Ints.asList(FishingSpot.SHARK.getIds()));
}
if (config.showMonkfish())
{
ids.addAll(Ints.asList(FishingSpot.MONKFISH.getIds()));
}
if (config.showSalmon())
{
ids.addAll(Ints.asList(FishingSpot.SALMON.getIds()));
}
if (config.showBarb())
{
ids.addAll(Ints.asList(FishingSpot.BARB_FISH.getIds()));
}
if (config.showAngler())
{
ids.addAll(Ints.asList(FishingSpot.ANGLERFISH.getIds()));
}
if (config.showMinnow())
{
ids.addAll(Ints.asList(FishingSpot.MINNOW.getIds()));
}
if (config.showInfernalEel())
{
ids.addAll(Ints.asList(FishingSpot.INFERNAL_EEL.getIds()));
}
}
}

View File

@@ -244,12 +244,6 @@ public class OverlayUtil
renderPolygon(graphics, poly, color);
}
Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
renderMinimapLocation(graphics, minimapLocation, color);
}
Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight() + 40);
if (textLocation != null)
{
@@ -265,12 +259,6 @@ public class OverlayUtil
renderPolygon(graphics, poly, color);
}
Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
renderMinimapLocation(graphics, minimapLocation, color);
}
Point imageLocation = actor.getCanvasImageLocation(graphics, image, actor.getLogicalHeight());
if (imageLocation != null)
{