Merge pull request #2440 from deathbeam/infobox-new-system

More customization of component system
This commit is contained in:
Adam
2018-05-07 11:59:42 -04:00
committed by GitHub
28 changed files with 211 additions and 170 deletions

View File

@@ -31,6 +31,7 @@ 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 net.runelite.client.ui.overlay.components.TitleComponent;
public class AttackStylesOverlay extends Overlay
{
@@ -49,13 +50,18 @@ public class AttackStylesOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
panelComponent.getChildren().clear();
boolean warnedSkillSelected = plugin.isWarnedSkillSelected();
if (warnedSkillSelected || config.alwaysShowStyle())
{
final String attackStyleString = plugin.getAttackStyle().getName();
panelComponent.setTitleColor(warnedSkillSelected ? Color.RED : Color.WHITE);
panelComponent.setTitle(attackStyleString);
panelComponent.getChildren().add(TitleComponent.builder()
.text(attackStyleString)
.color(warnedSkillSelected ? Color.RED : Color.WHITE)
.build());
panelComponent.setPreferredSize(new Dimension(
graphics.getFontMetrics().stringWidth(attackStyleString) + 10,
0));

View File

@@ -47,9 +47,9 @@ class BlastFurnaceOverlay extends Overlay
@Inject
BlastFurnaceOverlay(Client client, BlastFurnacePlugin plugin)
{
setPosition(OverlayPosition.TOP_LEFT);
this.plugin = plugin;
this.client = client;
setPosition(OverlayPosition.TOP_LEFT);
imagePanelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL);
}

View File

@@ -49,6 +49,7 @@ public class CerberusOverlay extends Overlay
this.plugin = plugin;
this.iconManager = iconManager;
setPosition(OverlayPosition.BOTTOM_RIGHT);
panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL);
}
@Override
@@ -60,8 +61,6 @@ public class CerberusOverlay extends Overlay
}
panelComponent.getChildren().clear();
panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL);
panelComponent.setTitle("Ghost order");
// Ghosts are already sorted
plugin.getGhosts().stream()

View File

@@ -38,6 +38,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class AnagramClue extends ClueScroll implements TextClueScroll, NpcClueScroll, LocationClueScroll
@@ -167,7 +168,7 @@ public class AnagramClue extends ClueScroll implements TextClueScroll, NpcClueSc
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Anagram Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Anagram Clue").build());
panelComponent.getChildren().add(LineComponent.builder().left("NPC:").build());
panelComponent.getChildren().add(LineComponent.builder()
.left(getNpc())

View File

@@ -38,6 +38,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class CipherClue extends ClueScroll implements TextClueScroll, NpcClueScroll, LocationClueScroll
@@ -76,7 +77,7 @@ public class CipherClue extends ClueScroll implements TextClueScroll, NpcClueScr
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Cipher Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Cipher Clue").build());
panelComponent.getChildren().add(LineComponent.builder().left("NPC:").build());
panelComponent.getChildren().add(LineComponent.builder()
.left(getNpc())

View File

@@ -35,6 +35,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
@AllArgsConstructor
@@ -46,7 +47,7 @@ public class CoordinateClue extends ClueScroll implements TextClueScroll, Locati
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Coordinate Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Coordinate Clue").build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Travel to the marked out destination to see a marker for where you should dig.")
.build());

View File

@@ -46,6 +46,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueScroll, ObjectClueScroll
@@ -338,7 +339,7 @@ public class CrypticClue extends ClueScroll implements TextClueScroll, NpcClueSc
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Cryptic Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Cryptic Clue").build());
panelComponent.getChildren().add(LineComponent.builder().left("Clue:").build());
panelComponent.getChildren().add(LineComponent.builder()
.left(getText())

View File

@@ -415,6 +415,7 @@ import net.runelite.client.plugins.cluescrolls.clues.emote.SlotLimitationRequire
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class EmoteClue extends ClueScroll implements TextClueScroll, LocationClueScroll
@@ -582,8 +583,7 @@ public class EmoteClue extends ClueScroll implements TextClueScroll, LocationClu
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Emote Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Emote Clue").build());
panelComponent.getChildren().add(LineComponent.builder().left("Emotes:").build());
panelComponent.getChildren().add(LineComponent.builder()
.left(getFirstEmote().getName())

View File

@@ -37,6 +37,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollPlugin.SPADE_IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class FairyRingClue extends ClueScroll implements TextClueScroll, LocationClueScroll
@@ -66,7 +67,7 @@ public class FairyRingClue extends ClueScroll implements TextClueScroll, Locatio
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Fairy Ring Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Fairy Ring Clue").build());
panelComponent.getChildren().add(LineComponent.builder().left("Code:").build());
panelComponent.getChildren().add(LineComponent.builder()
.left(getText().substring(0, 5))

View File

@@ -48,6 +48,7 @@ import static net.runelite.client.plugins.cluescrolls.ClueScrollWorldOverlay.IMA
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
@Getter
public class MapClue extends ClueScroll implements ObjectClueScroll
@@ -103,7 +104,7 @@ public class MapClue extends ClueScroll implements ObjectClueScroll
@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
panelComponent.setTitle("Map Clue");
panelComponent.getChildren().add(TitleComponent.builder().text("Map Clue").build());
if (objectId != -1)
{

View File

@@ -69,7 +69,6 @@ public class FightCaveOverlay extends Overlay
return null;
}
BufferedImage prayerImage = getPrayerImage(attack);
imagePanelComponent.setTitle("TzTok-Jad");
imagePanelComponent.getChildren().add(new ImageComponent(prayerImage));
if (!client.isPrayerActive(attack.getPrayer()))

View File

@@ -37,6 +37,7 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
class FishingOverlay extends Overlay
{
@@ -86,13 +87,17 @@ class FishingOverlay extends Overlay
if (client.getLocalPlayer().getInteracting() != null && client.getLocalPlayer().getInteracting().getName()
.contains(FISHING_SPOT))
{
panelComponent.setTitle("Fishing");
panelComponent.setTitleColor(Color.GREEN);
panelComponent.getChildren().add(TitleComponent.builder()
.text("Fishing")
.color(Color.GREEN)
.build());
}
else
{
panelComponent.setTitle("NOT fishing");
panelComponent.setTitleColor(Color.RED);
panelComponent.getChildren().add(TitleComponent.builder()
.text("NOT fishing")
.color(Color.RED)
.build());
}
int actions = xpTrackerService.getActions(Skill.FISHING);

View File

@@ -33,6 +33,7 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
public class MotherlodeGemOverlay extends Overlay
{
@@ -72,8 +73,7 @@ public class MotherlodeGemOverlay extends Overlay
int sapphiresFound = session.getSapphiresFound();
panelComponent.getChildren().clear();
panelComponent.setTitle("Gems found");
panelComponent.getChildren().add(TitleComponent.builder().text("Gems found").build());
if (diamondsFound > 0)
{

View File

@@ -32,21 +32,13 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Set;
import javax.inject.Inject;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_ADAMANT;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BLACK;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BRONZE;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_DRAGON;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_DRAGON_ORN;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_INFERNAL;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_IRON;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_MITHRIL;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_RUNE;
import static net.runelite.api.AnimationID.MINING_MOTHERLODE_STEEL;
import static net.runelite.api.AnimationID.*;
import net.runelite.api.Client;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
class MotherlodeOverlay extends Overlay
{
@@ -100,19 +92,19 @@ class MotherlodeOverlay extends Overlay
{
if (MINING_ANIMATION_IDS.contains(client.getLocalPlayer().getAnimation()))
{
panelComponent.setTitle("You are mining");
panelComponent.setTitleColor(Color.GREEN);
panelComponent.getChildren().add(TitleComponent.builder()
.text("Mining")
.color(Color.GREEN)
.build());
}
else
{
panelComponent.setTitle("You are NOT mining");
panelComponent.setTitleColor(Color.RED);
panelComponent.getChildren().add(TitleComponent.builder()
.text("NOT mining")
.color(Color.RED)
.build());
}
}
else
{
panelComponent.setTitle(null);
}
panelComponent.getChildren().add(LineComponent.builder()
.left("Pay-dirt mined:")

View File

@@ -36,7 +36,7 @@ import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.BackgroundComponent;
import net.runelite.client.ui.overlay.components.ComponentConstants;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
@@ -69,7 +69,7 @@ class MotherlodeSackOverlay extends Overlay
Widget sack = client.getWidget(WidgetInfo.MOTHERLODE_MINE);
panelComponent.getChildren().clear();
panelComponent.setBackgroundColor(BackgroundComponent.DEFAULT_BACKGROUND_COLOR);
panelComponent.setBackgroundColor(ComponentConstants.STANDARD_BACKGROUND_COLOR);
if (sack != null)
{

View File

@@ -35,6 +35,7 @@ import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
public class RaidsOverlay extends Overlay
{
@@ -66,13 +67,17 @@ public class RaidsOverlay extends Overlay
if (plugin.getRaid() == null || plugin.getRaid().getLayout() == null)
{
panelComponent.setTitleColor(Color.RED);
panelComponent.setTitle("Unable to scout this raid!");
panelComponent.getChildren().add(TitleComponent.builder()
.text("Unable to scout this raid!")
.color(Color.RED)
.build());
return panelComponent.render(graphics);
}
panelComponent.setTitleColor(Color.WHITE);
panelComponent.setTitle("Raid scouter");
panelComponent.getChildren().add(TitleComponent.builder()
.text("Raid scouter")
.build());
Color color = Color.WHITE;
String layout = plugin.getRaid().getLayout().toCode().replaceAll("#", "").replaceAll("¤", "");

View File

@@ -47,6 +47,7 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
class WoodcuttingOverlay extends Overlay
{
@@ -100,13 +101,17 @@ class WoodcuttingOverlay extends Overlay
if (IntStream.of(animationIds).anyMatch(x -> x == client.getLocalPlayer().getAnimation()))
{
panelComponent.setTitle("Woodcutting");
panelComponent.setTitleColor(Color.GREEN);
panelComponent.getChildren().add(TitleComponent.builder()
.text("Woodcutting")
.color(Color.GREEN)
.build());
}
else
{
panelComponent.setTitle("NOT woodcutting");
panelComponent.setTitleColor(Color.RED);
panelComponent.getChildren().add(TitleComponent.builder()
.text("NOT woodcutting")
.color(Color.RED)
.build());
}
int actions = xpTrackerService.getActions(Skill.WOODCUTTING);

View File

@@ -231,7 +231,7 @@ public class XpGlobesOverlay extends Overlay
String skillCurrentXp = decimalFormat.format(mouseOverSkill.getCurrentXp());
xpTooltip.getChildren().clear();
xpTooltip.setPosition(new java.awt.Point(x, y));
graphics.translate(x, y);
xpTooltip.setPreferredSize(new Dimension(TOOLTIP_RECT_SIZE_X, 0));
xpTooltip.getChildren().add(LineComponent.builder()
@@ -281,5 +281,6 @@ public class XpGlobesOverlay extends Overlay
}
xpTooltip.render(graphics);
graphics.translate(-x, -y);
}
}

View File

@@ -35,10 +35,9 @@ import net.runelite.client.ui.overlay.RenderableEntity;
@NoArgsConstructor
@AllArgsConstructor
@Setter
public class BackgroundComponent implements RenderableEntity
{
public static final Color DEFAULT_BACKGROUND_COLOR = new Color(70, 61, 50, 156);
private static final int BORDER_OFFSET = 2;
private static final int OUTSIDE_STROKE_RED_OFFSET = 14;
@@ -51,13 +50,8 @@ public class BackgroundComponent implements RenderableEntity
private static final int INSIDE_STROKE_BLUE_OFFSET = 19;
private static final int INSIDE_STROKE_ALPHA = 255;
@Setter
private Color backgroundColor = DEFAULT_BACKGROUND_COLOR;
@Setter
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
private Rectangle rectangle = new Rectangle();
@Setter
private boolean fill = true;
@Override

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
* 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.ui.overlay.components;
import java.awt.Color;
public class ComponentConstants
{
public static final int STANDARD_BORDER = 4;
public static final int STANDARD_WIDTH = 129;
public static final Color STANDARD_BACKGROUND_COLOR = new Color(70, 61, 50, 156);
}

View File

@@ -32,29 +32,19 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.Objects;
import javax.annotation.Nullable;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;
@Setter
public class InfoBoxComponent implements RenderableEntity
{
private static final int BOX_SIZE = 35;
private static final int SEPARATOR = 2;
@Setter
private String text;
@Setter
private Color color = Color.WHITE;
@Setter
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
@Setter
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
private Point position = new Point();
@Setter
@Nullable
private BufferedImage image;
@Override

View File

@@ -38,8 +38,6 @@ import lombok.Setter;
@Builder
public class LineComponent implements LayoutableRenderableEntity
{
private static final int SEPARATOR = 1;
private String left;
private String right;
@@ -50,7 +48,7 @@ public class LineComponent implements LayoutableRenderableEntity
private Color rightColor = Color.WHITE;
@Builder.Default
private Dimension preferredSize = new Dimension();
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
@Override
public Dimension render(Graphics2D graphics)
@@ -107,7 +105,7 @@ public class LineComponent implements LayoutableRenderableEntity
rightLineComponent.setText(rightText);
rightLineComponent.setColor(rightColor);
rightLineComponent.render(graphics);
y += metrics.getHeight() + SEPARATOR;
y += metrics.getHeight();
}
return new Dimension(preferredSize.width, y);
@@ -124,7 +122,7 @@ public class LineComponent implements LayoutableRenderableEntity
rightLineComponent.setText(right);
rightLineComponent.setColor(rightColor);
rightLineComponent.render(graphics);
y += metrics.getHeight() + SEPARATOR;
y += metrics.getHeight();
return new Dimension(preferredSize.width, y);
}

View File

@@ -24,7 +24,6 @@
*/
package net.runelite.client.ui.overlay.components;
import com.google.common.base.Strings;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
@@ -44,26 +43,11 @@ public class PanelComponent implements LayoutableRenderableEntity
VERTICAL;
}
private static final int TOP_BORDER = 4;
private static final int LEFT_BORDER = 4;
private static final int RIGHT_BORDER = 4;
private static final int BOTTOM_BORDER = 4;
private static final int SEPARATOR = 1;
@Setter
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
@Setter
private String title;
@Setter
private Color titleColor = Color.WHITE;
@Setter
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
@Setter
private Point position = new Point();
@Setter
private Dimension preferredSize = new Dimension(129, 0);
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
@Getter
private List<LayoutableRenderableEntity> children = new ArrayList<>();
@@ -71,55 +55,52 @@ public class PanelComponent implements LayoutableRenderableEntity
@Setter
private Orientation orientation = Orientation.VERTICAL;
private final Dimension savedChildrenSize = new Dimension();
@Setter
private Rectangle border = new Rectangle(
ComponentConstants.STANDARD_BORDER,
ComponentConstants.STANDARD_BORDER,
ComponentConstants.STANDARD_BORDER,
ComponentConstants.STANDARD_BORDER);
@Setter
private Point gap = new Point(0, 0);
private final Dimension childDimensions = new Dimension();
@Override
public Dimension render(Graphics2D graphics)
{
if (Strings.isNullOrEmpty(title) && children.isEmpty())
if (children.isEmpty())
{
return null;
}
final FontMetrics metrics = graphics.getFontMetrics();
// Calculate panel dimensions
int width = preferredSize.width;
int height = preferredSize.height;
int x = LEFT_BORDER;
int y = TOP_BORDER + metrics.getHeight();
// Set graphics offset at correct position
graphics.translate(position.x, position.y);
// Render background
final Dimension dimension = new Dimension(
savedChildrenSize.width + RIGHT_BORDER,
savedChildrenSize.height + BOTTOM_BORDER);
border.x + childDimensions.width + border.width,
border.y + childDimensions.height + border.height);
final BackgroundComponent backgroundComponent = new BackgroundComponent();
backgroundComponent.setRectangle(new Rectangle(dimension));
backgroundComponent.setBackgroundColor(backgroundColor);
backgroundComponent.render(graphics);
if (!Strings.isNullOrEmpty(title))
{
// Render title
final TextComponent titleComponent = new TextComponent();
titleComponent.setText(title);
titleComponent.setColor(titleColor);
titleComponent.setPosition(new Point((dimension.width - metrics.stringWidth(title)) / 2, y));
titleComponent.render(graphics);
// Offset children
final int baseX = border.x;
final int baseY = border.y + metrics.getHeight();
int width = 0;
int height = 0;
int x = baseX;
int y = baseY;
// Move children a bit
height = y += metrics.getHeight() + SEPARATOR;
}
// Create child preferred size
final Dimension childPreferredSize = new Dimension(
preferredSize.width - border.x - border.width,
preferredSize.height - border.y - border.height);
// Render all children
final Dimension childPreferredSize = new Dimension(
preferredSize.width - RIGHT_BORDER,
preferredSize.height - BOTTOM_BORDER);
for (final LayoutableRenderableEntity child : children)
{
child.setPreferredSize(childPreferredSize);
@@ -130,24 +111,25 @@ public class PanelComponent implements LayoutableRenderableEntity
switch (orientation)
{
case VERTICAL:
height = y += childDimension.height + SEPARATOR;
width = Math.max(width, x + childDimension.width);
height += childDimension.height + gap.y;
y = baseY + height;
width = Math.max(width, childDimension.width);
break;
case HORIZONTAL:
width = x += childDimension.width + SEPARATOR;
height = Math.max(height, y + childDimension.height);
width += childDimension.width + gap.x;
x = baseX + width;
height = Math.max(height, childDimension.height);
break;
}
}
// Reset the padding
height -= metrics.getHeight();
// Remove last child gap
width -= gap.x;
height -= gap.y;
// Save children size
savedChildrenSize.setSize(width, height);
// Cache children bounds
childDimensions.setSize(width, height);
// Reset graphics position
graphics.translate(-position.x, -position.y);
return dimension;
}
}

View File

@@ -33,28 +33,16 @@ import java.awt.Point;
import java.text.DecimalFormat;
import lombok.Setter;
@Setter
public class ProgressBarComponent implements LayoutableRenderableEntity
{
@Setter
private String text;
@Setter
private double progress;
@Setter
private Point position = new Point();
@Setter
private Color foregroundColor = new Color(82, 161, 82);
@Setter
private Color backgroundColor = new Color(255, 255, 255, 127);
@Setter
private Color fontColor = Color.WHITE;
@Setter
private Dimension preferredSize = new Dimension(129, 16);
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 16);
@Override
public Dimension render(Graphics2D graphics)

View File

@@ -34,25 +34,14 @@ import lombok.Setter;
import net.runelite.api.Point;
import net.runelite.client.ui.overlay.RenderableEntity;
@Setter
public class ProgressPieComponent implements RenderableEntity
{
@Setter
private int diameter = 25;
@Setter
private Color borderColor = Color.WHITE;
@Setter
private Color fill = Color.WHITE;
@Setter
private Stroke stroke = new BasicStroke(1);
@Setter
private double progress;
@Setter
private Point position;
@Override

View File

@@ -33,19 +33,15 @@ import java.util.regex.Pattern;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;
@Setter
public class TextComponent implements RenderableEntity
{
private static final String COL_TAG_REGEX = "(<col=([0-9a-fA-F]){2,6}>)";
private static final Pattern COL_TAG_PATTERN_W_LOOKAHEAD = Pattern.compile("(?=" + COL_TAG_REGEX + ")");
private static final Pattern COL_TAG_PATTERN = Pattern.compile(COL_TAG_REGEX);
@Setter
private String text;
@Setter
private Point position = new Point();
@Setter
private Color color = Color.WHITE;
public static String textWithoutColTags(String text)

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
* 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.ui.overlay.components;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import lombok.Builder;
import lombok.Setter;
@Setter
@Builder
public class TitleComponent implements LayoutableRenderableEntity
{
private String text;
@Builder.Default
private Color color = Color.WHITE;
@Builder.Default
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
@Override
public Dimension render(Graphics2D graphics)
{
final FontMetrics metrics = graphics.getFontMetrics();
final TextComponent titleComponent = new TextComponent();
titleComponent.setText(text);
titleComponent.setColor(color);
titleComponent.setPosition(new Point((preferredSize.width - metrics.stringWidth(text)) / 2, 0));
final Dimension dimension = titleComponent.render(graphics);
return new Dimension(Math.max(preferredSize.width, dimension.width), Math.max(preferredSize.height, dimension.height));
}
}

View File

@@ -35,22 +35,16 @@ import lombok.Setter;
import net.runelite.api.IndexedSprite;
import net.runelite.client.ui.overlay.RenderableEntity;
@Setter
public class TooltipComponent implements RenderableEntity
{
private static final Pattern BR = Pattern.compile("</br>");
private static final int OFFSET = 4;
private static final int MOD_ICON_WIDTH = 13; // they are generally 13px wide
@Setter
private String text;
@Setter
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
@Setter
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
private Point position = new Point();
@Setter
private IndexedSprite[] modIcons;
@Override