Add support for configurable infobox size
Add new configuration option to RuneLite settings for setting infobox size. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -56,6 +56,7 @@ import net.runelite.client.ui.ClientUI;
|
|||||||
import net.runelite.client.ui.DrawManager;
|
import net.runelite.client.ui.DrawManager;
|
||||||
import net.runelite.client.ui.TitleToolbar;
|
import net.runelite.client.ui.TitleToolbar;
|
||||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
@@ -120,6 +121,9 @@ public class RuneLite
|
|||||||
@Inject
|
@Inject
|
||||||
private ClanManager clanManager;
|
private ClanManager clanManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
@@ -214,6 +218,7 @@ public class RuneLite
|
|||||||
eventBus.register(commandManager);
|
eventBus.register(commandManager);
|
||||||
eventBus.register(pluginManager);
|
eventBus.register(pluginManager);
|
||||||
eventBus.register(clanManager);
|
eventBus.register(clanManager);
|
||||||
|
eventBus.register(infoBoxManager);
|
||||||
|
|
||||||
if (this.client != null)
|
if (this.client != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -221,4 +221,15 @@ public interface RuneLiteConfig extends Config
|
|||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "infoBoxSize",
|
||||||
|
name = "Infobox size (px)",
|
||||||
|
description = "Configures the size of each infobox in pixels",
|
||||||
|
position = 34
|
||||||
|
)
|
||||||
|
default int infoBoxSize()
|
||||||
|
{
|
||||||
|
return 35;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,13 @@ import java.awt.Point;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.runelite.client.ui.FontManager;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
public class InfoBoxComponent implements LayoutableRenderableEntity
|
public class InfoBoxComponent implements LayoutableRenderableEntity
|
||||||
{
|
{
|
||||||
private static final int SEPARATOR = 3;
|
private static final int SEPARATOR = 3;
|
||||||
|
private static final int DEFAULT_SIZE = 32;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String tooltip;
|
private String tooltip;
|
||||||
@@ -45,6 +47,9 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
@Getter
|
@Getter
|
||||||
private Point preferredLocation = new Point();
|
private Point preferredLocation = new Point();
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Dimension preferredSize = new Dimension(DEFAULT_SIZE, DEFAULT_SIZE);
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
private Color color = Color.WHITE;
|
private Color color = Color.WHITE;
|
||||||
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
@@ -58,13 +63,12 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
return new Dimension();
|
return new Dimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphics.setFont(getSize() < DEFAULT_SIZE ? FontManager.getRunescapeSmallFont() : FontManager.getRunescapeFont());
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
graphics.translate(preferredLocation.x, preferredLocation.y);
|
||||||
|
|
||||||
// Calculate dimensions
|
// Calculate dimensions
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
final int w = image.getWidth(null) + SEPARATOR * 2;
|
final int size = getSize();
|
||||||
final int h = image.getHeight(null) + SEPARATOR * 2;
|
|
||||||
final int size = Math.max(w, h);
|
|
||||||
final Rectangle bounds = new Rectangle(size, size);
|
final Rectangle bounds = new Rectangle(size, size);
|
||||||
|
|
||||||
// Render background
|
// Render background
|
||||||
@@ -93,15 +97,11 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
|
|
||||||
public Dimension getPreferredSize()
|
public Dimension getPreferredSize()
|
||||||
{
|
{
|
||||||
final int w = image.getWidth(null) + SEPARATOR * 2;
|
return new Dimension(getSize(), getSize());
|
||||||
final int h = image.getHeight(null) + SEPARATOR * 2;
|
|
||||||
final int size = Math.max(w, h);
|
|
||||||
return new Dimension(size, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int getSize()
|
||||||
public void setPreferredSize(Dimension dimension)
|
|
||||||
{
|
{
|
||||||
// Just use infobox dimensions for now
|
return Math.max(preferredSize.width, preferredSize.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,23 @@ package net.runelite.client.ui.overlay.infobox;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
|
|
||||||
public abstract class InfoBox
|
public abstract class InfoBox
|
||||||
{
|
{
|
||||||
private static final int SIZE = 24;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Image scaledImage;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private InfoBoxPriority priority;
|
private InfoBoxPriority priority;
|
||||||
@@ -60,21 +62,6 @@ public abstract class InfoBox
|
|||||||
|
|
||||||
public abstract Color getTextColor();
|
public abstract Color getTextColor();
|
||||||
|
|
||||||
public void setImage(final Image image)
|
|
||||||
{
|
|
||||||
if (image == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double width = image.getWidth(null);
|
|
||||||
double height = image.getHeight(null);
|
|
||||||
double scalex = (double) SIZE / width;
|
|
||||||
double scaley = (double) SIZE / height;
|
|
||||||
double scale = Math.min(scalex, scaley);
|
|
||||||
this.image = image.getScaledInstance((int) (width * scale), (int) (height * scale), BufferedImage.TYPE_INT_ARGB);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean render()
|
public boolean render()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -26,13 +26,20 @@ package net.runelite.client.ui.overlay.infobox;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ComparisonChain;
|
import com.google.common.collect.ComparisonChain;
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -40,13 +47,30 @@ import net.runelite.client.plugins.PluginDescriptor;
|
|||||||
public class InfoBoxManager
|
public class InfoBoxManager
|
||||||
{
|
{
|
||||||
private final List<InfoBox> infoBoxes = new ArrayList<>();
|
private final List<InfoBox> infoBoxes = new ArrayList<>();
|
||||||
|
private final RuneLiteConfig runeLiteConfig;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InfoBoxManager(final RuneLiteConfig runeLiteConfig)
|
||||||
|
{
|
||||||
|
this.runeLiteConfig = runeLiteConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onConfigChanged(ConfigChanged event)
|
||||||
|
{
|
||||||
|
if (event.getGroup().equals("runelite") && event.getKey().equals("infoBoxSize"))
|
||||||
|
{
|
||||||
|
infoBoxes.forEach(this::updateInfoBoxImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addInfoBox(InfoBox infoBox)
|
public void addInfoBox(InfoBox infoBox)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(infoBox);
|
Preconditions.checkNotNull(infoBox);
|
||||||
log.debug("Adding InfoBox {}", infoBox);
|
log.debug("Adding InfoBox {}", infoBox);
|
||||||
infoBoxes.add(infoBox);
|
|
||||||
|
|
||||||
|
updateInfoBoxImage(infoBox);
|
||||||
|
infoBoxes.add(infoBox);
|
||||||
refreshInfoBoxes();
|
refreshInfoBoxes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +116,43 @@ public class InfoBoxManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateInfoBoxImage(final InfoBox infoBox)
|
||||||
|
{
|
||||||
|
if (infoBox.getImage() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set scaled InfoBox image
|
||||||
|
final Image image = infoBox.getImage();
|
||||||
|
Image resultImage = image;
|
||||||
|
final double width = image.getWidth(null);
|
||||||
|
final double height = image.getHeight(null);
|
||||||
|
final double size = Math.max(2, runeLiteConfig.infoBoxSize()); // Limit size to 2 as that is minimum size not causing breakage
|
||||||
|
|
||||||
|
if (size < width || size < height)
|
||||||
|
{
|
||||||
|
final double scalex = size / width;
|
||||||
|
final double scaley = size / height;
|
||||||
|
|
||||||
|
if (scalex == 1 && scaley == 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final double scale = Math.min(scalex, scaley);
|
||||||
|
final int newWidth = (int) (width * scale);
|
||||||
|
final int newHeight = (int) (height * scale);
|
||||||
|
final BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
final Graphics g = scaledImage.createGraphics();
|
||||||
|
g.drawImage(image, 0, 0, newWidth, newHeight, null);
|
||||||
|
g.dispose();
|
||||||
|
resultImage = scaledImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
infoBox.setScaledImage(resultImage);
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshInfoBoxes()
|
private void refreshInfoBoxes()
|
||||||
{
|
{
|
||||||
Collections.sort(infoBoxes, (b1, b2) -> ComparisonChain
|
Collections.sort(infoBoxes, (b1, b2) -> ComparisonChain
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.ui.FontManager;
|
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
@@ -81,18 +80,18 @@ public class InfoBoxOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics.setFont(FontManager.getRunescapeSmallFont());
|
|
||||||
panelComponent.getChildren().clear();
|
panelComponent.getChildren().clear();
|
||||||
panelComponent.setWrapping(config.infoBoxWrap());
|
panelComponent.setWrapping(config.infoBoxWrap());
|
||||||
panelComponent.setOrientation(config.infoBoxVertical()
|
panelComponent.setOrientation(config.infoBoxVertical()
|
||||||
? PanelComponent.Orientation.VERTICAL
|
? PanelComponent.Orientation.VERTICAL
|
||||||
: PanelComponent.Orientation.HORIZONTAL);
|
: PanelComponent.Orientation.HORIZONTAL);
|
||||||
|
panelComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize()));
|
||||||
|
|
||||||
infoBoxes.forEach(box ->
|
infoBoxes.forEach(box ->
|
||||||
{
|
{
|
||||||
final InfoBoxComponent infoBoxComponent = new InfoBoxComponent();
|
final InfoBoxComponent infoBoxComponent = new InfoBoxComponent();
|
||||||
infoBoxComponent.setColor(box.getTextColor());
|
infoBoxComponent.setColor(box.getTextColor());
|
||||||
infoBoxComponent.setImage(box.getImage());
|
infoBoxComponent.setImage(box.getScaledImage());
|
||||||
infoBoxComponent.setText(box.getText());
|
infoBoxComponent.setText(box.getText());
|
||||||
infoBoxComponent.setTooltip(box.getTooltip());
|
infoBoxComponent.setTooltip(box.getTooltip());
|
||||||
panelComponent.getChildren().add(infoBoxComponent);
|
panelComponent.getChildren().add(infoBoxComponent);
|
||||||
|
|||||||
Reference in New Issue
Block a user