cannon plugin: use infobox counter instead of overlay
This commit is contained in:
@@ -47,11 +47,11 @@ public interface CannonConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showOverlay",
|
||||
name = "Show the cannonballs left overlay",
|
||||
description = "Configures whether to show the cannonballs in an overlay"
|
||||
keyName = "showInfobox",
|
||||
name = "Show Cannonball infobox",
|
||||
description = "Configures whether to show the cannonballs in an infobox"
|
||||
)
|
||||
default boolean showAmountOnScreen()
|
||||
default boolean showInfobox()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,47 +24,29 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.cannon;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.runelite.client.ui.overlay.infobox.Counter;
|
||||
|
||||
class CannonUiOverlay extends Overlay
|
||||
public class CannonCounter extends Counter
|
||||
{
|
||||
private static final int COMPONENT_WIDTH = 40;
|
||||
|
||||
private final CannonConfig config;
|
||||
private final CannonPlugin plugin;
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
|
||||
@Inject
|
||||
CannonUiOverlay(CannonConfig config, CannonPlugin plugin)
|
||||
public CannonCounter(BufferedImage img, CannonPlugin plugin)
|
||||
{
|
||||
setPosition(OverlayPosition.ABOVE_CHATBOX_RIGHT);
|
||||
this.config = config;
|
||||
super(img, String.valueOf(plugin.getCballsLeft()));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics, Point parent)
|
||||
public String getText()
|
||||
{
|
||||
if (!plugin.isCannonPlaced() || plugin.getCannonPosition() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!config.showAmountOnScreen())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
panelComponent.setTitleColor(plugin.getStateColor());
|
||||
panelComponent.setTitle(String.valueOf(plugin.getCballsLeft()));
|
||||
panelComponent.setWidth(COMPONENT_WIDTH);
|
||||
|
||||
return panelComponent.render(graphics, parent);
|
||||
return String.valueOf(plugin.getCballsLeft());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getTextColor()
|
||||
{
|
||||
return plugin.getStateColor();
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,6 @@ package net.runelite.client.plugins.cannon;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
@@ -37,6 +35,7 @@ import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.ItemID;
|
||||
import static net.runelite.api.ObjectID.CANNON_BASE;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Player;
|
||||
@@ -44,13 +43,16 @@ import net.runelite.api.Projectile;
|
||||
import static net.runelite.api.ProjectileID.CANNONBALL;
|
||||
import static net.runelite.api.ProjectileID.GRANITE_CANNONBALL;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.GameObjectSpawned;
|
||||
import net.runelite.api.events.ProjectileMoved;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Cannon"
|
||||
@@ -60,6 +62,8 @@ public class CannonPlugin extends Plugin
|
||||
private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)");
|
||||
private static final int MAX_CBALLS = 30;
|
||||
|
||||
private CannonCounter counter;
|
||||
|
||||
@Getter
|
||||
private int cballsLeft;
|
||||
|
||||
@@ -72,15 +76,18 @@ public class CannonPlugin extends Plugin
|
||||
@Getter
|
||||
private GameObject cannon;
|
||||
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
@Inject
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@Inject
|
||||
private Notifier notifier;
|
||||
|
||||
@Inject
|
||||
private CannonOverlay cannonOverlay;
|
||||
|
||||
@Inject
|
||||
private CannonUiOverlay cannonUiOverlay;
|
||||
|
||||
@Inject
|
||||
private CannonConfig config;
|
||||
|
||||
@@ -94,9 +101,9 @@ public class CannonPlugin extends Plugin
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Overlay> getOverlays()
|
||||
public Overlay getOverlay()
|
||||
{
|
||||
return Arrays.asList(cannonOverlay, cannonUiOverlay);
|
||||
return cannonOverlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,6 +112,27 @@ public class CannonPlugin extends Plugin
|
||||
cannonPlaced = false;
|
||||
cannonPosition = null;
|
||||
cballsLeft = 0;
|
||||
removeCounter();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (event.getGroup().equals("cannon"))
|
||||
{
|
||||
if (!config.showInfobox())
|
||||
{
|
||||
removeCounter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cannonPlaced)
|
||||
{
|
||||
addCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -152,6 +180,7 @@ public class CannonPlugin extends Plugin
|
||||
if (event.getMessage().equals("You add the furnace."))
|
||||
{
|
||||
cannonPlaced = true;
|
||||
addCounter();
|
||||
cballsLeft = 0;
|
||||
}
|
||||
|
||||
@@ -159,6 +188,7 @@ public class CannonPlugin extends Plugin
|
||||
{
|
||||
cannonPlaced = false;
|
||||
cballsLeft = 0;
|
||||
removeCounter();
|
||||
}
|
||||
|
||||
if (event.getMessage().startsWith("You load the cannon with"))
|
||||
@@ -228,4 +258,28 @@ public class CannonPlugin extends Plugin
|
||||
|
||||
return Color.red;
|
||||
}
|
||||
|
||||
private void addCounter()
|
||||
{
|
||||
if (!config.showInfobox() || counter != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
counter = new CannonCounter(itemManager.getImage(ItemID.CANNONBALL), this);
|
||||
counter.setTooltip("Cannonballs");
|
||||
|
||||
infoBoxManager.addInfoBox(counter);
|
||||
}
|
||||
|
||||
private void removeCounter()
|
||||
{
|
||||
if (counter == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
infoBoxManager.removeInfoBox(counter);
|
||||
counter = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user