Add Tears of Guthix Experience Overlay (#790)

This commit is contained in:
sdburns1998
2019-06-28 08:35:49 +02:00
committed by James
parent 2ace87e467
commit 64cdc9e696
2 changed files with 130 additions and 1 deletions

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2018, Aquivers <https://github.com/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);
}
}

View File

@@ -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<DecorativeObject, Instant> 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;
}
}