Skip to content

Commit

Permalink
motherlode: Add overlay for broken water wheel struts
Browse files Browse the repository at this point in the history
* Rename MotherlodeRocksOverlay to MotherlodeSceneOverlay
* When strut is broken, red border with hammer icon will show around it.
  • Loading branch information
Plondrein authored and Nightfirecat committed Oct 25, 2020
1 parent 6457681 commit 1c21d06
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ default boolean showOresFound()
return true;
}

@ConfigItem(
keyName = "showBrokenStruts",
name = "Show broken struts",
description = "Shows broken water wheel struts"
)
default boolean showBrokenStruts()
{
return true;
}

@ConfigItem(
keyName = "showLootIcons",
name = "Show ore icons",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.MenuAction;
import static net.runelite.api.ObjectID.BROKEN_STRUT;
import static net.runelite.api.ObjectID.ORE_VEIN_26661;
import static net.runelite.api.ObjectID.ORE_VEIN_26662;
import static net.runelite.api.ObjectID.ORE_VEIN_26663;
Expand Down Expand Up @@ -109,7 +110,7 @@ public class MotherlodePlugin extends Plugin
private MotherlodeOverlay overlay;

@Inject
private MotherlodeRocksOverlay rocksOverlay;
private MotherlodeSceneOverlay sceneOverlay;

@Inject
private MotherlodeSackOverlay motherlodeSackOverlay;
Expand Down Expand Up @@ -148,6 +149,8 @@ public class MotherlodePlugin extends Plugin
private final Set<WallObject> veins = new HashSet<>();
@Getter(AccessLevel.PACKAGE)
private final Set<GameObject> rocks = new HashSet<>();
@Getter(AccessLevel.PACKAGE)
private final Set<GameObject> brokenStruts = new HashSet<>();

@Provides
MotherlodeConfig getConfig(ConfigManager configManager)
Expand All @@ -159,7 +162,7 @@ MotherlodeConfig getConfig(ConfigManager configManager)
protected void startUp()
{
overlayManager.add(overlay);
overlayManager.add(rocksOverlay);
overlayManager.add(sceneOverlay);
overlayManager.add(motherlodeGemOverlay);
overlayManager.add(motherlodeOreOverlay);
overlayManager.add(motherlodeSackOverlay);
Expand All @@ -176,12 +179,13 @@ protected void startUp()
protected void shutDown()
{
overlayManager.remove(overlay);
overlayManager.remove(rocksOverlay);
overlayManager.remove(sceneOverlay);
overlayManager.remove(motherlodeGemOverlay);
overlayManager.remove(motherlodeOreOverlay);
overlayManager.remove(motherlodeSackOverlay);
veins.clear();
rocks.clear();
brokenStruts.clear();

Widget sack = client.getWidget(WidgetInfo.MOTHERLODE_MINE);

Expand Down Expand Up @@ -345,11 +349,7 @@ public void onGameObjectSpawned(GameObjectSpawned event)
return;
}

GameObject gameObject = event.getGameObject();
if (ROCK_OBSTACLES.contains(gameObject.getId()))
{
rocks.add(gameObject);
}
addGameObject(event.getGameObject());
}

@Subscribe
Expand All @@ -360,15 +360,8 @@ public void onGameObjectChanged(GameObjectChanged event)
return;
}

GameObject previous = event.getPrevious();
GameObject gameObject = event.getGameObject();

rocks.remove(previous);
if (ROCK_OBSTACLES.contains(gameObject.getId()))
{
rocks.add(gameObject);
}

removeGameObject(event.getPrevious());
addGameObject(event.getGameObject());
}

@Subscribe
Expand All @@ -379,8 +372,7 @@ public void onGameObjectDespawned(GameObjectDespawned event)
return;
}

GameObject gameObject = event.getGameObject();
rocks.remove(gameObject);
removeGameObject(event.getGameObject());
}

@Subscribe
Expand All @@ -391,6 +383,7 @@ public void onGameStateChanged(GameStateChanged event)
// on region changes the tiles get set to null
veins.clear();
rocks.clear();
brokenStruts.clear();

inMlm = checkInMlm();
}
Expand Down Expand Up @@ -513,4 +506,23 @@ boolean isUpstairs(LocalPoint localPoint)
{
return Perspective.getTileHeight(client, localPoint, 0) < UPPER_FLOOR_HEIGHT;
}
}

private void addGameObject(GameObject gameObject)
{
if (ROCK_OBSTACLES.contains(gameObject.getId()))
{
rocks.add(gameObject);
}

if (BROKEN_STRUT == gameObject.getId())
{
brokenStruts.add(gameObject);
}
}

private void removeGameObject(GameObject gameObject)
{
rocks.remove(gameObject);
brokenStruts.remove(gameObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.ItemID;
import net.runelite.api.Perspective;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.api.Skill;
import net.runelite.api.WallObject;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SkillIconManager;
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 MotherlodeRocksOverlay extends Overlay
class MotherlodeSceneOverlay extends Overlay
{
private static final int MAX_DISTANCE = 2350;
private static final int IMAGE_Z_OFFSET = 20;

private final Client client;
private final MotherlodePlugin plugin;
private final MotherlodeConfig config;

private final BufferedImage miningIcon;
private final BufferedImage hammerIcon;

@Inject
MotherlodeRocksOverlay(Client client, MotherlodePlugin plugin, MotherlodeConfig config, SkillIconManager iconManager)
MotherlodeSceneOverlay(Client client, MotherlodePlugin plugin, MotherlodeConfig config, SkillIconManager iconManager, ItemManager itemManager)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
Expand All @@ -66,6 +70,7 @@ class MotherlodeRocksOverlay extends Overlay
this.config = config;

miningIcon = iconManager.getSkillImage(Skill.MINING);
hammerIcon = itemManager.getImage(ItemID.HAMMER);
}

@Override
Expand Down Expand Up @@ -115,6 +120,17 @@ private void renderTiles(Graphics2D graphics, Player local)
}
}

if (config.showBrokenStruts())
{
for (GameObject brokenStrut : plugin.getBrokenStruts())
{
LocalPoint location = brokenStrut.getLocalLocation();
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
{
renderBrokenStrut(graphics, brokenStrut);
}
}
}
}

private void renderVein(Graphics2D graphics, WallObject vein)
Expand All @@ -136,4 +152,15 @@ private void renderRock(Graphics2D graphics, GameObject rock)
OverlayUtil.renderPolygon(graphics, poly, Color.red);
}
}

private void renderBrokenStrut(Graphics2D graphics, GameObject brokenStrut)
{
Polygon poly = Perspective.getCanvasTilePoly(client, brokenStrut.getLocalLocation());

if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.red);
OverlayUtil.renderImageLocation(client, graphics, brokenStrut.getLocalLocation(), hammerIcon, IMAGE_Z_OFFSET);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class MotherlodePluginTest

@Mock
@Bind
private MotherlodeRocksOverlay motherlodeRocksOverlay;
private MotherlodeSceneOverlay motherlodeSceneOverlay;

@Mock
@Bind
Expand Down

0 comments on commit 1c21d06

Please sign in to comment.