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