Merge branch 'runelite' into question_mark_full_stop
# Conflicts: # runelite-client/src/main/java/com/openosrs/client/game/NPCStats.java # runelite-client/src/main/java/net/runelite/client/plugins/Plugin.java
This commit is contained in:
@@ -138,4 +138,37 @@ public class OverlayUtil extends net.runelite.client.ui.overlay.OverlayUtil
|
||||
graphics.fill(poly);
|
||||
graphics.setStroke(originalStroke);
|
||||
}
|
||||
|
||||
public static void renderAreaTilePolygon(Graphics2D graphics, Shape poly, Color color)
|
||||
{
|
||||
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 10));
|
||||
graphics.fill(poly);
|
||||
}
|
||||
|
||||
public static void renderFullLine(Graphics2D graphics, int[][] line, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
final Stroke originalStroke = graphics.getStroke();
|
||||
graphics.setStroke(new BasicStroke(2));
|
||||
graphics.drawLine(line[0][0], line[0][1], line[1][0], line[1][1]);
|
||||
graphics.setStroke(originalStroke);
|
||||
}
|
||||
|
||||
public static void renderDashedLine(Graphics2D graphics, int[][] line, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
final Stroke originalStroke = graphics.getStroke();
|
||||
graphics.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0));
|
||||
graphics.drawLine(line[0][0], line[0][1], line[1][0], line[1][1]);
|
||||
graphics.setStroke(originalStroke);
|
||||
}
|
||||
|
||||
public static void renderOutlinePolygon(Graphics2D graphics, Shape poly, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
final Stroke originalStroke = graphics.getStroke();
|
||||
graphics.setStroke(new BasicStroke(2));
|
||||
graphics.draw(poly);
|
||||
graphics.setStroke(originalStroke);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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 com.openosrs.client.ui.overlay.components.table;
|
||||
|
||||
public enum TableAlignment
|
||||
{
|
||||
LEFT,
|
||||
CENTER,
|
||||
RIGHT
|
||||
}
|
||||
@@ -0,0 +1,465 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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 com.openosrs.client.ui.overlay.components.table;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.util.Text;
|
||||
import net.runelite.client.ui.overlay.components.ComponentConstants;
|
||||
import net.runelite.client.ui.overlay.components.LayoutableRenderableEntity;
|
||||
import net.runelite.client.ui.overlay.components.TextComponent;
|
||||
|
||||
@Setter
|
||||
public class TableComponent implements LayoutableRenderableEntity
|
||||
{
|
||||
private static final TableElement EMPTY_ELEMENT = TableElement.builder().build();
|
||||
|
||||
@Getter
|
||||
private final List<TableElement> columns = new ArrayList<>();
|
||||
@Getter
|
||||
private final List<TableRow> rows = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private final Rectangle bounds = new Rectangle();
|
||||
|
||||
private TableAlignment defaultAlignment = TableAlignment.LEFT;
|
||||
private Color defaultColor = Color.WHITE;
|
||||
private Dimension gutter = new Dimension(3, 0);
|
||||
private Point preferredLocation = new Point();
|
||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||
|
||||
@Override
|
||||
public Dimension render(final Graphics2D graphics)
|
||||
{
|
||||
final FontMetrics metrics = graphics.getFontMetrics();
|
||||
final TableRow colRow = TableRow.builder().elements(this.columns).build();
|
||||
final int[] columnWidths = getColumnWidths(metrics, colRow);
|
||||
|
||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
||||
|
||||
// Display the columns first
|
||||
int height = displayRow(graphics, colRow, 0, columnWidths, metrics);
|
||||
|
||||
for (TableRow row : this.rows)
|
||||
{
|
||||
height = displayRow(graphics, row, height, columnWidths, metrics);
|
||||
}
|
||||
|
||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
||||
|
||||
final Dimension dimension = new Dimension(preferredSize.width, height);
|
||||
bounds.setLocation(preferredLocation);
|
||||
bounds.setSize(dimension);
|
||||
|
||||
return dimension;
|
||||
}
|
||||
|
||||
private int displayRow(Graphics2D graphics, TableRow row, int height, int[] columnWidths, FontMetrics metrics)
|
||||
{
|
||||
int x = 0;
|
||||
int startingRowHeight = height;
|
||||
|
||||
final List<TableElement> elements = row.getElements();
|
||||
for (int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
int y = startingRowHeight;
|
||||
final TableElement cell = elements.get(i);
|
||||
|
||||
final String content = cell.getContent();
|
||||
if (content == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final String[] lines = lineBreakText(content, columnWidths[i], metrics);
|
||||
final TableAlignment alignment = getCellAlignment(row, i);
|
||||
final Color color = getCellColor(row, i);
|
||||
|
||||
for (String line : lines)
|
||||
{
|
||||
final int alignmentOffset = getAlignedPosition(line, alignment, columnWidths[i], metrics);
|
||||
final TextComponent leftLineComponent = new TextComponent();
|
||||
y += metrics.getHeight();
|
||||
|
||||
leftLineComponent.setPosition(new Point(x + alignmentOffset, y));
|
||||
leftLineComponent.setText(line);
|
||||
leftLineComponent.setColor(color);
|
||||
leftLineComponent.render(graphics);
|
||||
}
|
||||
height = Math.max(height, y);
|
||||
x += columnWidths[i] + gutter.width;
|
||||
}
|
||||
|
||||
return height + gutter.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width that each column should take up
|
||||
* Based on https://stackoverflow.com/questions/22206825/algorithm-for-calculating-variable-column-widths-for-set-table-width
|
||||
*
|
||||
* @param metrics
|
||||
* @return int[] of column width
|
||||
*/
|
||||
private int[] getColumnWidths(final FontMetrics metrics, final TableRow columnRow)
|
||||
{
|
||||
int numCols = columns.size();
|
||||
for (final TableRow r : rows)
|
||||
{
|
||||
numCols = Math.max(r.getElements().size(), numCols);
|
||||
}
|
||||
|
||||
int[] maxtextw = new int[numCols]; // max text width over all rows
|
||||
int[] maxwordw = new int[numCols]; // max width of longest word
|
||||
boolean[] flex = new boolean[numCols]; // is column flexible?
|
||||
boolean[] wrap = new boolean[numCols]; // can column be wrapped?
|
||||
int[] finalcolw = new int[numCols]; // final width of columns
|
||||
|
||||
final List<TableRow> rows = new ArrayList<>(this.rows);
|
||||
rows.add(columnRow);
|
||||
|
||||
for (final TableRow r : rows)
|
||||
{
|
||||
final List<TableElement> elements = r.getElements();
|
||||
for (int col = 0; col < elements.size(); col++)
|
||||
{
|
||||
final TableElement ele = elements.get(col);
|
||||
final String cell = ele.getContent();
|
||||
if (cell == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final int cellWidth = getTextWidth(metrics, cell);
|
||||
|
||||
maxtextw[col] = Math.max(maxtextw[col], cellWidth);
|
||||
for (String word : cell.split(" "))
|
||||
{
|
||||
maxwordw[col] = Math.max(maxwordw[col], getTextWidth(metrics, word));
|
||||
}
|
||||
|
||||
if (maxtextw[col] == cellWidth)
|
||||
{
|
||||
wrap[col] = cell.contains(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int left = preferredSize.width - (numCols - 1) * gutter.width;
|
||||
final double avg = left / numCols;
|
||||
int nflex = 0;
|
||||
|
||||
// Determine whether columns should be flexible and assign width of non-flexible cells
|
||||
for (int col = 0; col < numCols; col++)
|
||||
{
|
||||
// This limit can be adjusted as needed
|
||||
final double maxNonFlexLimit = 1.5 * avg;
|
||||
|
||||
flex[col] = maxtextw[col] > maxNonFlexLimit;
|
||||
if (flex[col])
|
||||
{
|
||||
nflex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
finalcolw[col] = maxtextw[col];
|
||||
left -= finalcolw[col];
|
||||
}
|
||||
}
|
||||
|
||||
// If there is not enough space, make columns that could be word-wrapped flexible too
|
||||
if (left < nflex * avg)
|
||||
{
|
||||
for (int col = 0; col < numCols; col++)
|
||||
{
|
||||
if (!flex[col] && wrap[col])
|
||||
{
|
||||
left += finalcolw[col];
|
||||
finalcolw[col] = 0;
|
||||
flex[col] = true;
|
||||
nflex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate weights for flexible columns. The max width is capped at the table width to
|
||||
// treat columns that have to be wrapped more or less equal
|
||||
int tot = 0;
|
||||
for (int col = 0; col < numCols; col++)
|
||||
{
|
||||
if (flex[col])
|
||||
{
|
||||
maxtextw[col] = Math.min(maxtextw[col], preferredSize.width);
|
||||
tot += maxtextw[col];
|
||||
}
|
||||
}
|
||||
|
||||
// Now assign the actual width for flexible columns. Make sure that it is at least as long
|
||||
// as the longest word length
|
||||
for (int col = 0; col < numCols; col++)
|
||||
{
|
||||
if (flex[col])
|
||||
{
|
||||
finalcolw[col] = left * maxtextw[col] / tot;
|
||||
finalcolw[col] = Math.max(finalcolw[col], maxwordw[col]);
|
||||
left -= finalcolw[col];
|
||||
}
|
||||
}
|
||||
|
||||
// When the sum of column widths is less than the total space available, distribute the
|
||||
// extra space equally across all columns
|
||||
final int extraPerCol = left / numCols;
|
||||
for (int col = 0; col < numCols; col++)
|
||||
{
|
||||
finalcolw[col] += extraPerCol;
|
||||
left -= extraPerCol;
|
||||
}
|
||||
// Add any remainder to the right-most column
|
||||
finalcolw[finalcolw.length - 1] += left;
|
||||
|
||||
return finalcolw;
|
||||
}
|
||||
|
||||
private static int getTextWidth(final FontMetrics metrics, final String cell)
|
||||
{
|
||||
return metrics.stringWidth(Text.removeTags(cell));
|
||||
}
|
||||
|
||||
private static String[] lineBreakText(final String text, final int maxWidth, final FontMetrics metrics)
|
||||
{
|
||||
final String[] words = text.split(" ");
|
||||
|
||||
if (words.length == 0)
|
||||
{
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
final StringBuilder wrapped = new StringBuilder(words[0]);
|
||||
int spaceLeft = maxWidth - getTextWidth(metrics, wrapped.toString());
|
||||
|
||||
for (int i = 1; i < words.length; i++)
|
||||
{
|
||||
final String word = words[i];
|
||||
final int wordLen = getTextWidth(metrics, word);
|
||||
final int spaceWidth = metrics.stringWidth(" ");
|
||||
|
||||
if (wordLen + spaceWidth > spaceLeft)
|
||||
{
|
||||
wrapped.append("\n").append(word);
|
||||
spaceLeft = maxWidth - wordLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
wrapped.append(" ").append(word);
|
||||
spaceLeft -= spaceWidth + wordLen;
|
||||
}
|
||||
}
|
||||
|
||||
return wrapped.toString().split("\n");
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return columns.size() == 0 || rows.size() == 0;
|
||||
}
|
||||
|
||||
private void ensureColumnSize(final int size)
|
||||
{
|
||||
while (size > columns.size())
|
||||
{
|
||||
columns.add(TableElement.builder().build());
|
||||
}
|
||||
}
|
||||
|
||||
private static int getAlignedPosition(final String str, final TableAlignment alignment, final int columnWidth, final FontMetrics metrics)
|
||||
{
|
||||
final int stringWidth = getTextWidth(metrics, str);
|
||||
int offset = 0;
|
||||
|
||||
switch (alignment)
|
||||
{
|
||||
case LEFT:
|
||||
break;
|
||||
case CENTER:
|
||||
offset = (columnWidth / 2) - (stringWidth / 2);
|
||||
break;
|
||||
case RIGHT:
|
||||
offset = columnWidth - stringWidth;
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color for the specified table element.
|
||||
* Priority order: cell->row->column->default
|
||||
*
|
||||
* @param row TableRow element
|
||||
* @param colIndex column index
|
||||
*/
|
||||
private Color getCellColor(final TableRow row, final int colIndex)
|
||||
{
|
||||
final List<TableElement> rowElements = row.getElements();
|
||||
final TableElement cell = colIndex < rowElements.size() ? rowElements.get(colIndex) : EMPTY_ELEMENT;
|
||||
final TableElement column = colIndex < columns.size() ? columns.get(colIndex) : EMPTY_ELEMENT;
|
||||
|
||||
return firstNonNull(
|
||||
cell.getColor(),
|
||||
row.getRowColor(),
|
||||
column.getColor(),
|
||||
defaultColor);
|
||||
}
|
||||
|
||||
private void setColumnAlignment(final int col, final TableAlignment alignment)
|
||||
{
|
||||
assert columns.size() > col;
|
||||
columns.get(col).setAlignment(alignment);
|
||||
}
|
||||
|
||||
public void setColumnAlignments(@Nonnull final TableAlignment... alignments)
|
||||
{
|
||||
ensureColumnSize(alignments.length);
|
||||
for (int i = 0; i < alignments.length; i++)
|
||||
{
|
||||
setColumnAlignment(i, alignments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alignment for the specified table element.
|
||||
* Priority order: cell->row->column->default
|
||||
*
|
||||
* @param row TableRow element
|
||||
* @param colIndex column index
|
||||
*/
|
||||
private TableAlignment getCellAlignment(final TableRow row, final int colIndex)
|
||||
{
|
||||
final List<TableElement> rowElements = row.getElements();
|
||||
final TableElement cell = colIndex < rowElements.size() ? rowElements.get(colIndex) : EMPTY_ELEMENT;
|
||||
final TableElement column = colIndex < columns.size() ? columns.get(colIndex) : EMPTY_ELEMENT;
|
||||
|
||||
return firstNonNull(
|
||||
cell.getAlignment(),
|
||||
row.getRowAlignment(),
|
||||
column.getAlignment(),
|
||||
defaultAlignment);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static <T> T firstNonNull(@Nullable T... elements)
|
||||
{
|
||||
if (elements == null || elements.length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
T cur = elements[0];
|
||||
while (cur == null && i < elements.length)
|
||||
{
|
||||
cur = elements[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
// Helper functions for cleaner overlay code
|
||||
public void addRow(@Nonnull final String... cells)
|
||||
{
|
||||
final List<TableElement> elements = new ArrayList<>();
|
||||
for (final String cell : cells)
|
||||
{
|
||||
elements.add(TableElement.builder().content(cell).build());
|
||||
}
|
||||
|
||||
final TableRow row = TableRow.builder().build();
|
||||
row.setElements(elements);
|
||||
|
||||
this.rows.add(row);
|
||||
}
|
||||
|
||||
private void addRows(@Nonnull final String[]... rows)
|
||||
{
|
||||
for (String[] row : rows)
|
||||
{
|
||||
addRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRows(@NonNull final TableRow... rows)
|
||||
{
|
||||
this.rows.addAll(Arrays.asList(rows));
|
||||
}
|
||||
|
||||
public void setRows(@Nonnull final String[]... elements)
|
||||
{
|
||||
this.rows.clear();
|
||||
addRows(elements);
|
||||
}
|
||||
|
||||
public void setRows(@Nonnull final TableRow... elements)
|
||||
{
|
||||
this.rows.clear();
|
||||
this.rows.addAll(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
private void addColumn(@Nonnull final String col)
|
||||
{
|
||||
this.columns.add(TableElement.builder().content(col).build());
|
||||
}
|
||||
|
||||
public void addColumns(@NonNull final TableElement... columns)
|
||||
{
|
||||
this.columns.addAll(Arrays.asList(columns));
|
||||
}
|
||||
|
||||
public void setColumns(@Nonnull final TableElement... elements)
|
||||
{
|
||||
this.columns.clear();
|
||||
this.columns.addAll(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
public void setColumns(@Nonnull final String... columns)
|
||||
{
|
||||
this.columns.clear();
|
||||
for (String col : columns)
|
||||
{
|
||||
addColumn(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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 com.openosrs.client.ui.overlay.components.table;
|
||||
|
||||
import java.awt.Color;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class TableElement
|
||||
{
|
||||
TableAlignment alignment;
|
||||
Color color;
|
||||
String content;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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 com.openosrs.client.ui.overlay.components.table;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class TableRow
|
||||
{
|
||||
Color rowColor;
|
||||
TableAlignment rowAlignment;
|
||||
@Builder.Default
|
||||
List<TableElement> elements = Collections.emptyList();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Connor <contact@connor-parks.email>
|
||||
* 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 com.openosrs.client.util;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Clipboard
|
||||
{
|
||||
public static String retrieve()
|
||||
{
|
||||
Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
|
||||
|
||||
if (contents == null || !contents.isDataFlavorSupported(DataFlavor.stringFlavor))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (String) contents.getTransferData(DataFlavor.stringFlavor);
|
||||
}
|
||||
catch (UnsupportedFlavorException | IOException ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void store(String contents)
|
||||
{
|
||||
final StringSelection selection = new StringSelection(contents);
|
||||
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.google.inject.Binder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import org.pf4j.ExtensionPoint;
|
||||
import net.runelite.client.RuneLite;
|
||||
|
||||
public abstract class Plugin implements Module, ExtensionPoint
|
||||
{
|
||||
@@ -50,8 +51,20 @@ public abstract class Plugin implements Module, ExtensionPoint
|
||||
{
|
||||
}
|
||||
|
||||
// This should never be null when we are using it
|
||||
public final Injector getInjector()
|
||||
{
|
||||
if (injector == null)
|
||||
{
|
||||
Module pluginModule = (Binder binder) ->
|
||||
{
|
||||
binder.bind((Class<Plugin>) this.getClass()).toInstance(this);
|
||||
binder.install(this);
|
||||
};
|
||||
Injector pluginInjector = RuneLite.getInjector().createChildInjector(pluginModule);
|
||||
pluginInjector.injectMembers(this);
|
||||
injector = pluginInjector;
|
||||
}
|
||||
return injector;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,20 +164,7 @@ public class PluginManager
|
||||
try
|
||||
{
|
||||
Injector injector = plugin.getInjector();
|
||||
if (injector == null)
|
||||
{
|
||||
// Create injector for the module
|
||||
Module pluginModule = (Binder binder) ->
|
||||
{
|
||||
// Since the plugin itself is a module, it won't bind itself, so we'll bind it here
|
||||
binder.bind((Class<Plugin>) plugin.getClass()).toInstance(plugin);
|
||||
binder.install(plugin);
|
||||
};
|
||||
Injector pluginInjector = RuneLite.getInjector().createChildInjector(pluginModule);
|
||||
pluginInjector.injectMembers(plugin);
|
||||
plugin.injector = pluginInjector;
|
||||
injector = pluginInjector;
|
||||
}
|
||||
|
||||
for (Key<?> key : injector.getBindings().keySet())
|
||||
{
|
||||
Class<?> type = key.getTypeLiteral().getRawType();
|
||||
@@ -207,25 +194,7 @@ public class PluginManager
|
||||
plugins = getPlugins();
|
||||
}
|
||||
plugins.forEach(pl ->
|
||||
{
|
||||
//TODO: Not sure why this is necessary but it is. The Injector isn't null when its handed off from our ExternalPluginManager.
|
||||
// Hopefully we can figure out the root cause of the underlying issue.
|
||||
if (pl.injector == null)
|
||||
{
|
||||
// Create injector for the module
|
||||
Module pluginModule = (Binder binder) ->
|
||||
{
|
||||
// Since the plugin itself is a module, it won't bind itself, so we'll bind it here
|
||||
binder.bind((Class<Plugin>) pl.getClass()).toInstance(pl);
|
||||
binder.install(pl);
|
||||
};
|
||||
Injector pluginInjector = RuneLite.getInjector().createChildInjector(pluginModule);
|
||||
pluginInjector.injectMembers(pl);
|
||||
pl.injector = pluginInjector;
|
||||
}
|
||||
|
||||
injectors.add(pl.getInjector());
|
||||
});
|
||||
injectors.add(pl.getInjector()));
|
||||
|
||||
List<Config> list = new ArrayList<>();
|
||||
for (Injector injector : injectors)
|
||||
|
||||
@@ -152,7 +152,7 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
@Getter
|
||||
private boolean configuringShiftClick = false;
|
||||
|
||||
private final Multimap<String, Swap> swaps = LinkedHashMultimap.create();
|
||||
private static final Multimap<String, Swap> swaps = LinkedHashMultimap.create();
|
||||
private final ArrayListMultimap<String, Integer> optionIndexes = ArrayListMultimap.create();
|
||||
|
||||
@Provides
|
||||
@@ -361,7 +361,7 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
swap("eat", "guzzle", config::swapRockCake);
|
||||
}
|
||||
|
||||
private void swap(String option, String swappedOption, Supplier<Boolean> enabled)
|
||||
public static void swap(String option, String swappedOption, Supplier<Boolean> enabled)
|
||||
{
|
||||
swap(option, alwaysTrue(), swappedOption, enabled);
|
||||
}
|
||||
@@ -371,7 +371,7 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
swap(option, equalTo(target), swappedOption, enabled);
|
||||
}
|
||||
|
||||
private void swap(String option, Predicate<String> targetPredicate, String swappedOption, Supplier<Boolean> enabled)
|
||||
private static void swap(String option, Predicate<String> targetPredicate, String swappedOption, Supplier<Boolean> enabled)
|
||||
{
|
||||
swaps.put(option, new Swap(alwaysTrue(), targetPredicate, swappedOption, enabled, true));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user