cannon plugin: add overlay for cannonballs left

This commit is contained in:
semtexerror
2018-02-28 18:22:24 -05:00
committed by Adam
parent d2b496ffd4
commit d747af78b7
3 changed files with 87 additions and 2 deletions

View File

@@ -44,4 +44,14 @@ public interface CannonConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "showOverlay",
name = "Show the cannonballs left overlay",
description = "Configures whether to show the cannonballs in an overlay"
)
default boolean showAmountOnScreen()
{
return false;
}
}

View File

@@ -27,6 +27,8 @@ 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;
@@ -76,6 +78,9 @@ public class CannonPlugin extends Plugin
@Inject
private CannonOverlay cannonOverlay;
@Inject
private CannonUiOverlay cannonUiOverlay;
@Inject
private CannonConfig config;
@@ -89,9 +94,9 @@ public class CannonPlugin extends Plugin
}
@Override
public Overlay getOverlay()
public Collection<Overlay> getOverlays()
{
return cannonOverlay;
return Arrays.asList(cannonOverlay, cannonUiOverlay);
}
@Override

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.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;
class CannonUiOverlay extends Overlay
{
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)
{
setPosition(OverlayPosition.ABOVE_CHATBOX_RIGHT);
this.config = config;
this.plugin = plugin;
}
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
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);
}
}