use of net.runelite.api.widgets.Widget in project runelite by runelite.
the class ScreenshotPluginTest method testFiremaking.
@Test
public void testFiremaking() {
Widget widget = mock(Widget.class);
when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
Widget skillChild = mock(Widget.class);
when(client.getWidget(Matchers.eq(LEVEL_UP_SKILL))).thenReturn(skillChild);
Widget levelChild = mock(Widget.class);
when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
when(skillChild.getText()).thenReturn("Congratulations, you just advanced a Firemaking level.");
when(levelChild.getText()).thenReturn("Your Firemaking level is now 9.");
assertEquals("Firemaking(9)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_SKILL, LEVEL_UP_LEVEL));
WidgetHiddenChanged event = new WidgetHiddenChanged();
event.setWidget(widget);
screenshotPlugin.hideWidgets(event);
verify(overlayRenderer).requestScreenshot(Matchers.any(Consumer.class));
}
use of net.runelite.api.widgets.Widget in project runelite by runelite.
the class ScreenshotPluginTest method testHunter.
@Test
public void testHunter() {
Widget widget = mock(Widget.class);
when(widget.getId()).thenReturn(PACK(DIALOG_SPRITE_GROUP_ID, 0));
Widget skillChild = mock(Widget.class);
when(client.getWidget(Matchers.eq(DIALOG_SPRITE_SPRITE))).thenReturn(skillChild);
Widget levelChild = mock(Widget.class);
when(client.getWidget(Matchers.eq(DIALOG_SPRITE_TEXT))).thenReturn(levelChild);
when(skillChild.getText()).thenReturn("Congratulations, you just advanced a Hunter level.");
when(levelChild.getText()).thenReturn("Your Hunter level is now 2.");
assertEquals("Hunter(2)", screenshotPlugin.parseLevelUpWidget(DIALOG_SPRITE_SPRITE, DIALOG_SPRITE_TEXT));
WidgetHiddenChanged event = new WidgetHiddenChanged();
event.setWidget(widget);
screenshotPlugin.hideWidgets(event);
verify(overlayRenderer).requestScreenshot(Matchers.any(Consumer.class));
}
use of net.runelite.api.widgets.Widget in project runelite by runelite.
the class PuzzleSolverOverlay method render.
@Override
public Dimension render(Graphics2D graphics) {
if ((!config.displaySolution() && !config.displayRemainingMoves()) || client.getGameState() != GameState.LOGGED_IN) {
return null;
}
ItemContainer container = client.getItemContainer(InventoryID.PUZZLE_BOX);
if (container == null) {
return null;
}
Widget puzzleBox = client.getWidget(WidgetInfo.PUZZLE_BOX);
if (puzzleBox == null) {
return null;
}
net.runelite.api.Point puzzleBoxLocation = puzzleBox.getCanvasLocation();
String infoString = "Solving..";
int[] itemIds = getItemIds(container);
boolean shouldCache = false;
if (solver != null) {
if (solver.hasFailed()) {
infoString = "The puzzle could not be solved";
} else {
if (solver.hasSolution()) {
boolean foundPosition = false;
// Find the current state by looking at the current step and then the next 5 steps
for (int i = 0; i < 6; i++) {
int j = solver.getPosition() + i;
if (j == solver.getStepCount()) {
break;
}
PuzzleState currentState = solver.getStep(j);
// If this is false, player has moved the empty tile
if (currentState != null && currentState.hasPieces(itemIds)) {
foundPosition = true;
solver.setPosition(j);
if (i > 0) {
shouldCache = true;
}
break;
}
}
// see if we can find the current state in the 5 previous steps
if (!foundPosition) {
for (int i = 1; i < 6; i++) {
int j = solver.getPosition() - i;
if (j < 0) {
break;
}
PuzzleState currentState = solver.getStep(j);
if (currentState != null && currentState.hasPieces(itemIds)) {
foundPosition = true;
shouldCache = true;
solver.setPosition(j);
break;
}
}
}
if (foundPosition) {
int stepsLeft = solver.getStepCount() - solver.getPosition() - 1;
if (stepsLeft == 0) {
infoString = "Solved!";
} else if (config.displayRemainingMoves()) {
infoString = "Moves left: " + stepsLeft;
} else {
infoString = null;
}
if (config.displaySolution()) {
if (config.drawDots()) {
graphics.setColor(Color.YELLOW);
// Display the next 4 steps
for (int i = 1; i < 5; i++) {
int j = solver.getPosition() + i;
if (j >= solver.getStepCount()) {
break;
}
PuzzleState futureMove = solver.getStep(j);
if (futureMove == null) {
break;
}
int blankX = futureMove.getEmptyPiece() % DIMENSION;
int blankY = futureMove.getEmptyPiece() / DIMENSION;
int markerSize = DOT_MARKER_SIZE - i * 3;
int x = puzzleBoxLocation.getX() + blankX * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - markerSize / 2;
int y = puzzleBoxLocation.getY() + blankY * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - markerSize / 2;
graphics.fillOval(x, y, markerSize, markerSize);
}
} else {
// Find the current blank tile position
PuzzleState currentMove = solver.getStep(solver.getPosition());
int lastBlankX = currentMove.getEmptyPiece() % DIMENSION;
int lastBlankY = currentMove.getEmptyPiece() / DIMENSION;
// Display the next 3 steps
for (int i = 1; i < 4; i++) {
int j = solver.getPosition() + i;
if (j >= solver.getStepCount()) {
break;
}
PuzzleState futureMove = solver.getStep(j);
if (futureMove == null) {
break;
}
int blankX = futureMove.getEmptyPiece() % DIMENSION;
int blankY = futureMove.getEmptyPiece() / DIMENSION;
int xDelta = blankX - lastBlankX;
int yDelta = blankY - lastBlankY;
BufferedImage arrow;
if (xDelta > 0) {
arrow = getRightArrow();
} else if (xDelta < 0) {
arrow = getLeftArrow();
} else if (yDelta > 0) {
arrow = getDownArrow();
} else {
arrow = getUpArrow();
}
int x = puzzleBoxLocation.getX() + blankX * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - arrow.getWidth() / 2;
int y = puzzleBoxLocation.getY() + blankY * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - arrow.getHeight() / 2;
OverlayUtil.renderImageLocation(graphics, new net.runelite.api.Point(x, y), arrow);
lastBlankX = blankX;
lastBlankY = blankY;
}
}
}
}
}
}
}
// Draw info box
if (infoString != null) {
int x = puzzleBoxLocation.getX() + puzzleBox.getWidth() / 2 - INFO_BOX_WIDTH / 2;
int y = puzzleBoxLocation.getY() - INFO_BOX_OFFSET_Y;
FontMetrics fm = graphics.getFontMetrics();
int height = INFO_BOX_TOP_BORDER + fm.getHeight() + INFO_BOX_BOTTOM_BORDER;
BackgroundComponent backgroundComponent = new BackgroundComponent();
backgroundComponent.setRectangle(new Rectangle(x, y, INFO_BOX_WIDTH, height));
backgroundComponent.render(graphics);
int textOffsetX = (INFO_BOX_WIDTH - fm.stringWidth(infoString)) / 2;
int textOffsetY = fm.getHeight();
TextComponent textComponent = new TextComponent();
textComponent.setPosition(new Point(x + textOffsetX, y + textOffsetY));
textComponent.setText(infoString);
textComponent.render(graphics);
}
// Solve the puzzle if we don't have an up to date solution
if (solver == null || cachedItems == null || (!shouldCache && !Arrays.equals(cachedItems, itemIds))) {
solve(itemIds);
shouldCache = true;
}
if (shouldCache) {
cacheItems(itemIds);
}
return null;
}
use of net.runelite.api.widgets.Widget in project runelite by runelite.
the class PestControlOverlay method renderWidgetOverlay.
private void renderWidgetOverlay(Graphics2D graphics, Portal portal, String text, Color color) {
Widget shield = client.getWidget(portal.getShield());
Widget icon = client.getWidget(portal.getIcon());
Widget hp = client.getWidget(portal.getHitpoints());
Widget bar = client.getWidget(WidgetInfo.PESTCONTROL_ACTIVITY_BAR).getChild(0);
Rectangle2D barBounds = bar.getBounds().getBounds2D();
// create one rectangle from two different widget bounds
Rectangle2D bounds = union(shield.getBounds().getBounds2D(), icon.getBounds().getBounds2D());
bounds = union(bounds, hp.getBounds().getBounds2D());
graphics.setColor(color);
graphics.draw(new Rectangle2D.Double(bounds.getX(), bounds.getY() - 2, bounds.getWidth(), bounds.getHeight() - 3));
FontMetrics fm = graphics.getFontMetrics();
Rectangle2D textBounds = fm.getStringBounds(text, graphics);
int x = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
int y = (int) (bounds.getY() + bounds.getHeight() + textBounds.getHeight() + barBounds.getHeight());
graphics.setColor(Color.BLACK);
graphics.drawString(text, x + 1, y + 1);
graphics.setColor(color);
graphics.drawString(text, x, y);
}
use of net.runelite.api.widgets.Widget in project runelite by runelite.
the class MinimapPlugin method shutDown.
@Override
protected void shutDown() throws Exception {
Widget minimapWidget = client.getWidget(WidgetInfo.MINIMAP_WIDGET);
if (minimapWidget != null) {
minimapWidget.setHidden(false);
}
restoreOriginalDots();
}
Aggregations