Refactor vetion
This commit is contained in:
@@ -31,14 +31,14 @@ import net.runelite.client.config.ConfigItem;
|
||||
@ConfigGroup("vetion")
|
||||
public interface VetionConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
keyName = "earthquakeTimerActive",
|
||||
name = "Vet'ion Earthquake Timer",
|
||||
description = "Configures whether or not a timer is shown to track the cooldown of Vet'ion's earthquake attack",
|
||||
position = 0
|
||||
)
|
||||
default boolean eartquakeTimerActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ConfigItem(
|
||||
keyName = "earthquakeTimerActive",
|
||||
name = "Vet'ion Earthquake Timer",
|
||||
description = "Configures whether or not a timer is shown to track the cooldown of Vet'ion's earthquake attack",
|
||||
position = 0
|
||||
)
|
||||
default boolean eartquakeTimerActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,12 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.vetion;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
@@ -33,61 +39,57 @@ import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.ProgressPieComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.*;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
public class VetionOverlay extends Overlay
|
||||
{
|
||||
|
||||
public class VetionOverlay extends Overlay{
|
||||
private static final Color RED_ALPHA = new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue(), 100);
|
||||
private static final Duration MAX_TIME = Duration.ofSeconds(9);
|
||||
private final VetionPlugin plugin;
|
||||
private Client client;
|
||||
|
||||
private static final Color RED_ALPHA = new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue(), 100);
|
||||
private static final Duration MAX_TIME = Duration.ofSeconds(9);
|
||||
private final VetionPlugin plugin;
|
||||
private Client client;
|
||||
@Inject
|
||||
private VetionOverlay(Client client, VetionPlugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.client = client;
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private VetionOverlay(Client client, VetionPlugin plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.client = client;
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||
}
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
plugin.getVetions().forEach((actor, timer) ->
|
||||
{
|
||||
LocalPoint localPos = actor.getLocalLocation();
|
||||
if (localPos != null)
|
||||
{
|
||||
Point position = Perspective.localToCanvas(client, localPos, client.getPlane(),
|
||||
actor.getLogicalHeight() + 96);
|
||||
if (position != null)
|
||||
{
|
||||
position = new Point(position.getX(), position.getY());
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
plugin.getVetions().forEach((actor, timer) ->
|
||||
{
|
||||
LocalPoint localPos = actor.getLocalLocation();
|
||||
if (localPos != null)
|
||||
{
|
||||
Point position = Perspective.localToCanvas(client, localPos, client.getPlane(),
|
||||
actor.getLogicalHeight() + 96);
|
||||
if (position != null)
|
||||
{
|
||||
position = new Point(position.getX(), position.getY());
|
||||
final ProgressPieComponent progressPie = new ProgressPieComponent();
|
||||
progressPie.setDiameter(30);
|
||||
progressPie.setFill(RED_ALPHA);
|
||||
progressPie.setBorderColor(Color.RED);
|
||||
progressPie.setPosition(position);
|
||||
|
||||
final ProgressPieComponent progressPie = new ProgressPieComponent();
|
||||
progressPie.setDiameter(30);
|
||||
progressPie.setFill(RED_ALPHA);
|
||||
progressPie.setBorderColor(Color.RED);
|
||||
progressPie.setPosition(position);
|
||||
final Duration duration = Duration.between(timer, Instant.now());
|
||||
progressPie.setProgress(1 - (duration.compareTo(MAX_TIME) < 0
|
||||
? (double) duration.toMillis() / MAX_TIME.toMillis()
|
||||
: 1));
|
||||
|
||||
final Duration duration = Duration.between(timer, Instant.now());
|
||||
progressPie.setProgress(1 - (duration.compareTo(MAX_TIME) < 0
|
||||
? (double) duration.toMillis() / MAX_TIME.toMillis()
|
||||
: 1));
|
||||
progressPie.render(graphics);
|
||||
if (1 - duration.compareTo(MAX_TIME) < 0)
|
||||
{
|
||||
plugin.getVetions().remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
progressPie.render(graphics);
|
||||
if (1 - duration.compareTo(MAX_TIME) < 0)
|
||||
{
|
||||
plugin.getVetions().remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,14 @@
|
||||
package net.runelite.client.plugins.vetion;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.*;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.AnimationChanged;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -35,63 +41,56 @@ import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Vetion Helper",
|
||||
description = "Tracks Vet'ion's special attacks",
|
||||
tags = {"bosses", "combat", "pve", "overlay"},
|
||||
type = PluginType.PVM
|
||||
name = "Vetion Helper",
|
||||
description = "Tracks Vet'ion's special attacks",
|
||||
tags = {"bosses", "combat", "pve", "overlay"},
|
||||
type = PluginType.PVM
|
||||
)
|
||||
public class VetionPlugin extends Plugin {
|
||||
public class VetionPlugin extends Plugin
|
||||
{
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
@Inject
|
||||
private VetionConfig config;
|
||||
|
||||
@Inject
|
||||
private VetionConfig config;
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
@Inject
|
||||
private VetionOverlay overlay;
|
||||
|
||||
@Inject
|
||||
private VetionOverlay overlay;
|
||||
@Getter
|
||||
private Map<Actor, Instant> vetions;
|
||||
|
||||
@Getter
|
||||
private Map<Actor, Instant> vetions;
|
||||
@Provides
|
||||
VetionConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(VetionConfig.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
VetionConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(VetionConfig.class);
|
||||
}
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
vetions = new HashMap<>();
|
||||
overlayManager.add(overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
vetions = new HashMap<>();
|
||||
overlayManager.add(overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
vetions = null;
|
||||
}
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
vetions = null;
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onAnimationChanged(AnimationChanged event)
|
||||
{
|
||||
if (config.eartquakeTimerActive() && event.getActor().getAnimation() == AnimationID.VETION_EARTHQUAKE)
|
||||
{
|
||||
Actor vet = event.getActor();
|
||||
vetions.remove(vet, Instant.now());
|
||||
vetions.put(vet, Instant.now());
|
||||
}
|
||||
}
|
||||
@Subscribe
|
||||
public void onAnimationChanged(AnimationChanged event)
|
||||
{
|
||||
if (config.eartquakeTimerActive() && event.getActor().getAnimation() == AnimationID.VETION_EARTHQUAKE)
|
||||
{
|
||||
Actor vet = event.getActor();
|
||||
vetions.remove(vet, Instant.now());
|
||||
vetions.put(vet, Instant.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user