From 64cdc9e696145a16cdb51cec214fcc7e59b3b227 Mon Sep 17 00:00:00 2001 From: sdburns1998 <49877861+sdburns1998@users.noreply.github.com> Date: Fri, 28 Jun 2019 08:35:49 +0200 Subject: [PATCH] Add Tears of Guthix Experience Overlay (#790) --- .../TearsOfGuthixExperienceOverlay.java | 77 +++++++++++++++++++ .../tearsofguthix/TearsOfGuthixPlugin.java | 54 ++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixExperienceOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixExperienceOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixExperienceOverlay.java new file mode 100644 index 0000000000..b702556f5f --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixExperienceOverlay.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018, Aquivers + * 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.tearsofguthix; + +import net.runelite.api.Client; +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.components.PanelComponent; +import javax.inject.Inject; +import java.awt.Dimension; +import java.awt.Graphics2D; +import net.runelite.client.ui.overlay.components.table.TableAlignment; +import net.runelite.client.ui.overlay.components.table.TableComponent; + +class TearsOfGuthixExperienceOverlay extends Overlay +{ + private final TearsOfGuthixPlugin plugin; + private final PanelComponent panelComponent = new PanelComponent(); + + @Inject + private Client client; + + @Inject + private TearsOfGuthixExperienceOverlay(final TearsOfGuthixPlugin plugin) + { + setPosition(OverlayPosition.ABOVE_CHATBOX_RIGHT); + setPriority(OverlayPriority.LOW); + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (plugin.getPlayerLowestSkill() == null) + { + return null; + } + + panelComponent.getChildren().clear(); + + TableComponent tableComponent = new TableComponent(); + tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT); + + tableComponent.addRow(plugin.getPlayerLowestSkill().getName(), "Lvl - " + client.getRealSkillLevel(plugin.getPlayerLowestSkill()) + ""); + + if (!tableComponent.isEmpty()) + { + panelComponent.getChildren().add(tableComponent); + } + + return panelComponent.render(graphics); + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixPlugin.java index 6567c15e24..9d2f1100aa 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/tearsofguthix/TearsOfGuthixPlugin.java @@ -28,10 +28,13 @@ import java.time.Instant; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; +import lombok.AccessLevel; import lombok.Getter; import net.runelite.api.Client; import net.runelite.api.DecorativeObject; +import net.runelite.api.GameState; import net.runelite.api.ObjectID; +import net.runelite.api.Skill; import net.runelite.api.events.DecorativeObjectDespawned; import net.runelite.api.events.DecorativeObjectSpawned; import net.runelite.api.events.GameStateChanged; @@ -58,20 +61,29 @@ public class TearsOfGuthixPlugin extends Plugin @Inject private TearsOfGuthixOverlay overlay; - @Getter + @Inject + private TearsOfGuthixExperienceOverlay experienceOverlay; + + @Getter(AccessLevel.PACKAGE) private final Map streams = new HashMap<>(); + @Getter(AccessLevel.PACKAGE) + private Skill playerLowestSkill = null; + @Override protected void startUp() { overlayManager.add(overlay); + overlayManager.add(experienceOverlay); } @Override protected void shutDown() { overlayManager.remove(overlay); + overlayManager.remove(experienceOverlay); streams.clear(); + playerLowestSkill = null; } @Subscribe @@ -84,6 +96,26 @@ public class TearsOfGuthixPlugin extends Plugin case HOPPING: streams.clear(); } + + if (event.getGameState() == GameState.LOGGED_IN) + { + if (client.getLocalPlayer().getWorldLocation().getRegionID() == TOG_REGION) + { + if (playerLowestSkill != null) + { + return; + } + + if (client.getSkillExperience(Skill.HITPOINTS) > 0) + { + playerLowestSkill = getLowestPlayerSkill(); + } + } + else + { + playerLowestSkill = null; + } + } } @Subscribe @@ -112,4 +144,24 @@ public class TearsOfGuthixPlugin extends Plugin DecorativeObject object = event.getDecorativeObject(); streams.remove(object); } + + private Skill getLowestPlayerSkill() + { + final Skill[] playerSkills = Skill.values(); + Skill lowestExperienceSkill = null; + int lowestExperienceAmount = Integer.MAX_VALUE; + + for (Skill skill : playerSkills) + { + int currentSkillExp = client.getSkillExperience(skill); + + if (currentSkillExp < lowestExperienceAmount) + { + lowestExperienceAmount = currentSkillExp; + lowestExperienceSkill = skill; + } + } + + return lowestExperienceSkill; + } }