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