Java Code Examples for net.runelite.api.Point#getY()

The following examples show how to use net.runelite.api.Point#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverlayUtil.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void renderTextLocation(Graphics2D graphics, Point txtLoc, String text, Color color)
{
	if (Strings.isNullOrEmpty(text))
	{
		return;
	}

	int x = txtLoc.getX();
	int y = txtLoc.getY();

	graphics.setColor(Color.BLACK);
	graphics.drawString(text, x + 1, y + 1);

	graphics.setColor(color);
	graphics.drawString(text, x, y);
}
 
Example 2
Source File: PoisonActorOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void renderOverlayFor(Graphics2D g, Actor actor, int damage, String timeLeft, boolean venomed)
{
	BufferedImage splat = plugin.getSplat(venomed ? SpriteID.HITSPLAT_DARK_GREEN_VENOM : SpriteID.HITSPLAT_GREEN_POISON, damage);

	LocalPoint localLocation = actor.getLocalLocation();
	if (localLocation == null)
	{
		return;
	}

	Point overlayLocation = Perspective.getCanvasImageLocation(client, localLocation, splat, 0);

	if (overlayLocation == null)
	{
		return;
	}

	int textOffset = splat.getHeight() - (splat.getHeight() - fontSize) / 2;

	Point textLocation = new Point(overlayLocation.getX() + splat.getWidth() + 3, overlayLocation.getY() + textOffset);

	g.drawImage(splat, overlayLocation.getX(), overlayLocation.getY(), null);
	OverlayUtil.renderTextLocation(g, textLocation, timeLeft, Color.WHITE);
}
 
Example 3
Source File: WoodcuttingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameObjectDespawned(final GameObjectDespawned event)
{
	final GameObject object = event.getGameObject();

	Tree tree = Tree.findTree(object.getId());
	if (tree != null)
	{
		if (tree.getRespawnTime() != null && !recentlyLoggedIn && currentPlane == object.getPlane())
		{
			Point max = object.getSceneMaxLocation();
			Point min = object.getSceneMinLocation();
			int lenX = max.getX() - min.getX();
			int lenY = max.getY() - min.getY();
			log.debug("Adding respawn timer for {} tree at {}", tree, object.getLocalLocation());

			final int region = client.getLocalPlayer().getWorldLocation().getRegionID();
			TreeRespawn treeRespawn = new TreeRespawn(tree, lenX, lenY, WorldPoint.fromScene(client, min.getX(), min.getY(), client.getPlane()), Instant.now(), (int) tree.getRespawnTime(region).toMillis());
			respawns.add(treeRespawn);
		}

		if (tree == Tree.REDWOOD)
		{
			treeObjects.remove(event.getGameObject());
		}
	}
}
 
Example 4
Source File: ImplingMinimapOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	List<NPC> imps = plugin.getImplings();
	if (imps.isEmpty())
	{
		return null;
	}

	for (NPC imp : imps)
	{
		Point impLocation = imp.getMinimapLocation();
		Color color = plugin.npcToColor(imp);
		if (!plugin.showNpc(imp) || impLocation == null || color == null)
		{
			continue;
		}

		OverlayUtil.renderMinimapLocation(graphics, impLocation, color);

		if (config.showName())
		{
			Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
			OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
		}
	}

	return null;
}
 
Example 5
Source File: OverlayUtil.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void renderImageLocation(Graphics2D graphics, Point imgLoc, BufferedImage image)
{
	int x = imgLoc.getX();
	int y = imgLoc.getY();

	graphics.drawImage(image, x, y, null);
}
 
Example 6
Source File: ScreenshotPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void takeScreenshot(String fileName, String subDir, Image image)
{
	if (!config.includeOverlays())
	{
		overlayRenderer.setShouldRender(false);
	}
	BufferedImage screenshot = config.includeFrame()
		? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
		: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

	Graphics graphics = screenshot.getGraphics();

	int gameOffsetX = 0;
	int gameOffsetY = 0;

	if (config.includeFrame())
	{
		// Draw the client frame onto the screenshot
		try
		{
			SwingUtilities.invokeAndWait(() -> clientUi.paint(graphics));
		}
		catch (InterruptedException | InvocationTargetException e)
		{
			log.warn("unable to paint client UI on screenshot", e);
		}

		// Evaluate the position of the game inside the frame
		final Point canvasOffset = clientUi.getCanvasOffset();
		gameOffsetX = canvasOffset.getX();
		gameOffsetY = canvasOffset.getY();
	}

	// Draw the game onto the screenshot
	graphics.drawImage(image, gameOffsetX, gameOffsetY, null);
	imageCapture.takeScreenshot(screenshot, fileName, subDir, config.notifyWhenTaken(), config.uploadScreenshot());
	overlayRenderer.setShouldRender(true);
}
 
Example 7
Source File: WorldMapOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle)
{
	int clippedX = drawPoint.getX();

	if (drawPoint.getX() < mapDisplayRectangle.getX())
	{
		clippedX = (int) mapDisplayRectangle.getX();
	}

	if (drawPoint.getX() > mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth())
	{
		clippedX = (int) (mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth());
	}

	int clippedY = drawPoint.getY();

	if (drawPoint.getY() < mapDisplayRectangle.getY())
	{
		clippedY = (int) mapDisplayRectangle.getY();
	}

	if (drawPoint.getY() > mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight())
	{
		clippedY = (int) (mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight());
	}

	return new Point(clippedX, clippedY);
}
 
Example 8
Source File: ScreenshotPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void takeScreenshot(String fileName, String subDir, Image image)
{
	BufferedImage screenshot = config.includeFrame()
		? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
		: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

	Graphics graphics = screenshot.getGraphics();

	int gameOffsetX = 0;
	int gameOffsetY = 0;

	if (config.includeFrame())
	{
		// Draw the client frame onto the screenshot
		try
		{
			SwingUtilities.invokeAndWait(() -> clientUi.paint(graphics));
		}
		catch (InterruptedException | InvocationTargetException e)
		{
			log.warn("unable to paint client UI on screenshot", e);
		}

		// Evaluate the position of the game inside the frame
		final Point canvasOffset = clientUi.getCanvasOffset();
		gameOffsetX = canvasOffset.getX();
		gameOffsetY = canvasOffset.getY();
	}

	// Draw the game onto the screenshot
	graphics.drawImage(image, gameOffsetX, gameOffsetY, null);
	imageCapture.takeScreenshot(screenshot, fileName, subDir, config.notifyWhenTaken(), config.uploadScreenshot());
}
 
Example 9
Source File: WorldArea.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Checks whether this area is within melee distance of another.
 * <p>
 * Melee distance is exactly 1 tile, so this method computes and returns
 * whether the shortest distance to the passed area is directly
 * on the outside of this areas edge.
 *
 * @param other the other area
 * @return true if in melee distance, false otherwise
 */
public boolean isInMeleeDistance(WorldArea other)
{
	if (other == null || this.getPlane() != other.getPlane())
	{
		return false;
	}

	Point distances = getAxisDistances(other);
	return distances.getX() + distances.getY() == 1;
}
 
Example 10
Source File: RaidsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Finds the lobby room index in the room array
 * There are 8 rooms per floor in a 4 wide (x) and 2 high (y) rectangle
 * The rooms on plane 3 (the lobby plane) have the following indexes
 *     0 1 2 3
 *     4 5 6 7
 */
private int findLobbyIndex(Point gridBase)
{
	int x;
	int y;

	// the lobby will always be on the top/first floor (plane 3)
	Tile[][] tiles = client.getScene().getTiles()[LOBBY_PLANE];

	/*
	 * if there is no room north the lobby then it is the north most room
	 * The north rooms will have a y value of 0 and the south will have a value of 1
	 * The rooms have the following y values
	 *     0 0 0 0
	 *     1 1 1 1
	 */
	if (tiles[gridBase.getX()][gridBase.getY() + RaidRoom.ROOM_MAX_SIZE] == null)
	{
		y = 0;
	}
	else
	{
		y = 1;
	}

	/*
	 * if there is no room east of the lobby then it is the east most room
	 * The west most room will have a value of 0 and the east most will have a value of 3
	 * The rooms have the following x values
	 *     0 1 2 3
	 *     0 1 2 3
	 */
	if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null)
	{
		x = 3;
	}
	else
	{
		// determine x based on how many rooms are to the west of it.
		for (x = 0; x < 3; x++)
		{
			int sceneX = gridBase.getX() - 1 - RaidRoom.ROOM_MAX_SIZE * x;
			if (sceneX < 0 || tiles[sceneX][gridBase.getY()] == null)
			{
				break;
			}
		}
	}

	// the room index based on its x and y values
	return x + y * AMOUNT_OF_ROOMS_PER_X_AXIS_PER_PLANE;
}
 
Example 11
Source File: WorldMapRegionOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void drawRegionOverlay(Graphics2D graphics)
{
	RenderOverview ro = client.getRenderOverview();
	Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW);
	Float pixelsPerTile = ro.getWorldMapZoom();

	if (map == null)
	{
		return;
	}

	Rectangle worldMapRect = map.getBounds();
	graphics.setClip(worldMapRect);

	int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
	int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);

	Point worldMapPosition = ro.getWorldMapPosition();

	// Offset in tiles from anchor sides
	int yTileMin = worldMapPosition.getY() - heightInTiles / 2;
	int xRegionMin = (worldMapPosition.getX() - widthInTiles / 2) & REGION_TRUNCATE;
	int xRegionMax = ((worldMapPosition.getX() + widthInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int yRegionMin = (yTileMin & REGION_TRUNCATE);
	int yRegionMax = ((worldMapPosition.getY() + heightInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int regionPixelSize = (int) Math.ceil(REGION_SIZE * pixelsPerTile);

	for (int x = xRegionMin; x < xRegionMax; x += REGION_SIZE)
	{
		for (int y = yRegionMin; y < yRegionMax; y += REGION_SIZE)
		{
			graphics.setColor(WHITE_TRANSLUCENT);

			int yTileOffset = -(yTileMin - y);
			int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX();

			int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX();
			int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY();
			// Offset y-position by a single region to correct for drawRect starting from the top
			yPos -= regionPixelSize;

			graphics.drawRect(xPos, yPos, regionPixelSize, regionPixelSize);

			int regionId = ((x >> 6) << 8) | (y >> 6);
			String regionText = String.valueOf(regionId);
			FontMetrics fm = graphics.getFontMetrics();
			Rectangle2D textBounds = fm.getStringBounds(regionText, graphics);
			int labelWidth = (int) textBounds.getWidth() + 2 * LABEL_PADDING;
			int labelHeight = (int) textBounds.getHeight() + 2 * LABEL_PADDING;
			graphics.fillRect(xPos, yPos, labelWidth, labelHeight);
			graphics.setColor(Color.BLACK);
			graphics.drawString(regionText, xPos + LABEL_PADDING, yPos + (int) textBounds.getHeight() + LABEL_PADDING);
		}
	}
}
 
Example 12
Source File: WorldMapOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Get the screen coordinates for a WorldPoint on the world map
 * @param worldPoint WorldPoint to get screen coordinates of
 * @return Point of screen coordinates of the center of the world point
 */
public Point mapWorldPointToGraphicsPoint(WorldPoint worldPoint)
{
	RenderOverview ro = client.getRenderOverview();

	if (!ro.getWorldMapData().surfaceContainsPosition(worldPoint.getX(), worldPoint.getY()))
	{
		return null;
	}

	Float pixelsPerTile = ro.getWorldMapZoom();

	Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW);
	if (map != null)
	{
		Rectangle worldMapRect = map.getBounds();

		int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
		int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);

		Point worldMapPosition = ro.getWorldMapPosition();

		//Offset in tiles from anchor sides
		int yTileMax = worldMapPosition.getY() - heightInTiles / 2;
		int yTileOffset = (yTileMax - worldPoint.getY() - 1) * -1;
		int xTileOffset = worldPoint.getX() + widthInTiles / 2 - worldMapPosition.getX();

		int xGraphDiff = ((int) (xTileOffset * pixelsPerTile));
		int yGraphDiff = (int) (yTileOffset * pixelsPerTile);

		//Center on tile.
		yGraphDiff -= pixelsPerTile - Math.ceil(pixelsPerTile / 2);
		xGraphDiff += pixelsPerTile - Math.ceil(pixelsPerTile / 2);

		yGraphDiff = worldMapRect.height - yGraphDiff;
		yGraphDiff += (int) worldMapRect.getY();
		xGraphDiff += (int) worldMapRect.getX();

		return new Point(xGraphDiff, yGraphDiff);
	}
	return null;
}
 
Example 13
Source File: ClueScrollPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void highlightWidget(Graphics2D graphics, Widget toHighlight, Widget container, Rectangle padding, String text)
{
	padding = MoreObjects.firstNonNull(padding, new Rectangle());

	Point canvasLocation = toHighlight.getCanvasLocation();

	if (canvasLocation == null)
	{
		return;
	}

	Point windowLocation = container.getCanvasLocation();

	if (windowLocation.getY() > canvasLocation.getY() + toHighlight.getHeight()
		|| windowLocation.getY() + container.getHeight() < canvasLocation.getY())
	{
		return;
	}

	// Visible area of widget
	Area widgetArea = new Area(
		new Rectangle(
			canvasLocation.getX() - padding.x,
			Math.max(canvasLocation.getY(), windowLocation.getY()) - padding.y,
			toHighlight.getWidth() + padding.x + padding.width,
			Math.min(
				Math.min(windowLocation.getY() + container.getHeight() - canvasLocation.getY(), toHighlight.getHeight()),
				Math.min(canvasLocation.getY() + toHighlight.getHeight() - windowLocation.getY(), toHighlight.getHeight())) + padding.y + padding.height
		));

	OverlayUtil.renderHoverableArea(graphics, widgetArea, client.getMouseCanvasPosition(),
		HIGHLIGHT_FILL_COLOR, HIGHLIGHT_BORDER_COLOR, HIGHLIGHT_HOVER_BORDER_COLOR);

	if (text == null)
	{
		return;
	}

	FontMetrics fontMetrics = graphics.getFontMetrics();

	textComponent.setPosition(new java.awt.Point(
		canvasLocation.getX() + toHighlight.getWidth() / 2 - fontMetrics.stringWidth(text) / 2,
		canvasLocation.getY() + fontMetrics.getHeight()));
	textComponent.setText(text);
	textComponent.render(graphics);
}
 
Example 14
Source File: XpGlobesOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int startXp, int goalXp, int x, int y, Rectangle bounds)
{
	double radiusCurrentXp = getSkillProgressRadius(startXp, skillToDraw.getCurrentXp(), goalXp);
	double radiusToGoalXp = 360; //draw a circle

	Ellipse2D backgroundCircle = drawEllipse(graphics, x, y);

	drawSkillImage(graphics, skillToDraw, x, y);

	Point mouse = client.getMouseCanvasPosition();
	int mouseX = mouse.getX() - bounds.x;
	int mouseY = mouse.getY() - bounds.y;

	// If mouse is hovering the globe
	if (backgroundCircle.contains(mouseX, mouseY))
	{
		// Fill a darker overlay circle
		graphics.setColor(DARK_OVERLAY_COLOR);
		graphics.fill(backgroundCircle);

		drawProgressLabel(graphics, skillToDraw, startXp, goalXp, x, y);

		if (config.enableTooltips())
		{
			drawTooltip(skillToDraw, goalXp);
		}
	}

	graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_REMAINDER, radiusToGoalXp,
		5,
		config.progressOrbOutLineColor()
	);
	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_START, radiusCurrentXp,
		config.progressArcStrokeWidth(),
		config.enableCustomArcColor() ? config.progressArcColor() : SkillColor.find(skillToDraw.getSkill()).getColor());
}
 
Example 15
Source File: NpcSceneOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void renderNpcRespawn(final MemorizedNpc npc, final Graphics2D graphics)
{
	if (npc.getPossibleRespawnLocations().isEmpty())
	{
		return;
	}

	final WorldPoint respawnLocation = npc.getPossibleRespawnLocations().get(0);
	final LocalPoint lp = LocalPoint.fromWorld(client, respawnLocation.getX(), respawnLocation.getY());

	if (lp == null)
	{
		return;
	}

	final Color color = config.getHighlightColor();

	final LocalPoint centerLp = new LocalPoint(
		lp.getX() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2,
		lp.getY() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2);

	final Polygon poly = Perspective.getCanvasTileAreaPoly(client, centerLp, npc.getNpcSize());

	if (poly != null)
	{
		OverlayUtil.renderPolygon(graphics, poly, color);
	}


	final String timeLeftStr = plugin.formatTime(plugin.getTimeLeftForNpc(npc));

	final int textWidth = graphics.getFontMetrics().stringWidth(timeLeftStr);
	final int textHeight = graphics.getFontMetrics().getAscent();

	final Point canvasPoint = Perspective
		.localToCanvas(client, centerLp, respawnLocation.getPlane());

	if (canvasPoint != null)
	{
		final Point canvasCenterPoint = new Point(
			canvasPoint.getX() - textWidth / 2,
			canvasPoint.getY() + textHeight / 2);

		OverlayUtil.renderTextLocation(graphics, canvasCenterPoint, timeLeftStr, TEXT_COLOR);
	}
}
 
Example 16
Source File: IDAStarMM.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Assumes locBlank is first point for swap and locVal is last point for swap
 * <p>
 * swap(locBlank, loc1);
 * swap(loc1, loc2);
 * swap(loc2, locVal);
 */
private void performSwapPattern(Point locBlank, Point locVal, PuzzleSwapPattern pattern)
{
	int[] offsets;
	switch (pattern)
	{
		case ROTATE_LEFT_UP:
		case ROTATE_RIGHT_UP:
		case ROTATE_RIGHT_DOWN:
		case ROTATE_LEFT_DOWN:
			offsets = ROTATE_LEFT_UP.getPoints();
			break;
		case ROTATE_UP_LEFT:
		case ROTATE_UP_RIGHT:
		case ROTATE_DOWN_LEFT:
		case ROTATE_DOWN_RIGHT:
			offsets = ROTATE_UP_LEFT.getPoints();
			break;
		default:
			offsets = pattern.getPoints();
	}

	if (offsets == null || offsets.length % 2 == 1)
	{
		// This should never happen
		throw new IllegalStateException("Unexpected points given in pattern!");
	}

	int modX = pattern.getModX();
	int modY = pattern.getModY();

	ArrayList<Point> points = new ArrayList<>();

	for (int i = 0; i < offsets.length; i += 2)
	{
		int x = locVal.getX() + modX * offsets[i];
		int y = locVal.getY() + modY * offsets[i + 1];

		points.add(new Point(x, y));
	}

	// Add locVal as last point
	points.add(locVal);

	if (pattern != LAST_PIECE_ROW && pattern != LAST_PIECE_COLUMN)
	{
		Point start = locBlank;
		for (Point p : points)
		{
			swap(start, p);
			start = p;
		}
	}
	else
	{
		Point loc1 = points.get(0);
		Point loc2 = points.get(1);
		Point loc3 = points.get(2);
		Point loc4 = points.get(3);

		swap(locBlank, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, locBlank);
		swap(locBlank, loc4);
		swap(loc4, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
	}
}
 
Example 17
Source File: RaidsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private Raid buildRaid()
{
	Point gridBase = findLobbyBase();

	if (gridBase == null)
	{
		return null;
	}

	Raid raid = new Raid();
	Tile[][] tiles;
	int position, x, y, offsetX;
	int startX = -2;

	for (int plane = 3; plane > 1; plane--)
	{
		tiles = client.getScene().getTiles()[plane];

		if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null)
		{
			position = 1;
		}
		else
		{
			position = 0;
		}

		for (int i = 1; i > -2; i--)
		{
			y = gridBase.getY() + (i * RaidRoom.ROOM_MAX_SIZE);

			for (int j = startX; j < 4; j++)
			{
				x = gridBase.getX() + (j * RaidRoom.ROOM_MAX_SIZE);
				offsetX = 0;

				if (x > SCENE_SIZE && position > 1 && position < 4)
				{
					position++;
				}

				if (x < 0)
				{
					offsetX = Math.abs(x) + 1; //add 1 because the tile at x=0 will always be null
				}

				if (x < SCENE_SIZE && y >= 0 && y < SCENE_SIZE)
				{
					if (tiles[x + offsetX][y] == null)
					{
						if (position == 4)
						{
							position++;
							break;
						}

						continue;
					}

					if (position == 0 && startX != j)
					{
						startX = j;
					}

					Tile base = tiles[offsetX > 0 ? 1 : x][y];
					RaidRoom room = determineRoom(base);
					raid.setRoom(room, position + Math.abs((plane - 3) * 8));
					position++;
				}
			}
		}
	}

	return raid;
}
 
Example 18
Source File: IDAStarMM.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Assumes locBlank is first point for swap and locVal is last point for swap
 *
 * swap(locBlank, loc1);
 * swap(loc1, loc2);
 * swap(loc2, locVal);
 */
private void performSwapPattern(Point locBlank, Point locVal, PuzzleSwapPattern pattern)
{
	int[] offsets;
	switch (pattern)
	{
		case ROTATE_LEFT_UP:
		case ROTATE_RIGHT_UP:
		case ROTATE_RIGHT_DOWN:
		case ROTATE_LEFT_DOWN:
			offsets = ROTATE_LEFT_UP.getPoints();
			break;
		case ROTATE_UP_LEFT:
		case ROTATE_UP_RIGHT:
		case ROTATE_DOWN_LEFT:
		case ROTATE_DOWN_RIGHT:
			offsets = ROTATE_UP_LEFT.getPoints();
			break;
		default:
			offsets = pattern.getPoints();
	}

	if (offsets == null || offsets.length % 2 == 1)
	{
		// This should never happen
		throw new IllegalStateException("Unexpected points given in pattern!");
	}

	int modX = pattern.getModX();
	int modY = pattern.getModY();

	ArrayList<Point> points = new ArrayList<>();

	for (int i = 0; i < offsets.length; i += 2)
	{
		int x = locVal.getX() + modX * offsets[i];
		int y = locVal.getY() + modY * offsets[i + 1];

		points.add(new Point(x, y));
	}

	// Add locVal as last point
	points.add(locVal);

	if (pattern != LAST_PIECE_ROW && pattern != LAST_PIECE_COLUMN)
	{
		Point start = locBlank;
		for (Point p : points)
		{
			swap(start, p);
			start = p;
		}
	}
	else
	{
		Point loc1 = points.get(0);
		Point loc2 = points.get(1);
		Point loc3 = points.get(2);
		Point loc4 = points.get(3);

		swap(locBlank, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, locBlank);
		swap(locBlank, loc4);
		swap(loc4, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
	}
}
 
Example 19
Source File: StatusBarsOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D g)
{
	final Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
	if (widgetBankTitleBar != null && !widgetBankTitleBar.isHidden())
	{
		return null;
	}

	Viewport curViewport = null;
	Widget curWidget = null;

	for (Viewport viewport : Viewport.values())
	{
		final Widget viewportWidget = client.getWidget(viewport.getViewport());
		if (viewportWidget != null && !viewportWidget.isHidden())
		{
			curViewport = viewport;
			curWidget = viewportWidget;
			break;
		}
	}

	if (curViewport == null)
	{
		return null;
	}
	else
	{
		curWidget.isHidden();
	}

	final Point offsetLeft = curViewport.getOffsetLeft();
	final Point offsetRight = curViewport.getOffsetRight();
	final Point location = curWidget.getCanvasLocation();
	final int height, offsetLeftBarX, offsetLeftBarY, offsetRightBarX, offsetRightBarY;

	if (curViewport == Viewport.RESIZED_BOTTOM)
	{
		height = RESIZED_BOTTOM_HEIGHT;
		offsetLeftBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetLeft.getX());
		offsetLeftBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY());
		offsetRightBarX = (location.getX() + RESIZED_BOTTOM_OFFSET_X - offsetRight.getX());
		offsetRightBarY = (location.getY() - RESIZED_BOTTOM_OFFSET_Y - offsetRight.getY());
	}
	else
	{
		height = HEIGHT;
		offsetLeftBarX = (location.getX() - offsetLeft.getX());
		offsetLeftBarY = (location.getY() - offsetLeft.getY());
		offsetRightBarX = (location.getX() - offsetRight.getX()) + curWidget.getWidth();
		offsetRightBarY = (location.getY() - offsetRight.getY());
	}

	BarRenderer left = plugin.getBarRenderers().get(config.leftBarMode());
	BarRenderer right = plugin.getBarRenderers().get(config.rightBarMode());

	if (left != null)
	{
		left.draw(client, this, g, offsetLeftBarX, offsetLeftBarY, height);
	}

	if (right != null)
	{
		right.draw(client, this, g, offsetRightBarX, offsetRightBarY, height);
	}

	return null;
}
 
Example 20
Source File: WorldMapRegionOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void drawRegionOverlay(Graphics2D graphics)
{
	RenderOverview ro = client.getRenderOverview();
	Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW);
	float pixelsPerTile = ro.getWorldMapZoom();

	if (map == null)
	{
		return;
	}

	Rectangle worldMapRect = map.getBounds();
	graphics.setClip(worldMapRect);

	int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
	int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);

	Point worldMapPosition = ro.getWorldMapPosition();

	// Offset in tiles from anchor sides
	int yTileMin = worldMapPosition.getY() - heightInTiles / 2;
	int xRegionMin = (worldMapPosition.getX() - widthInTiles / 2) & REGION_TRUNCATE;
	int xRegionMax = ((worldMapPosition.getX() + widthInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int yRegionMin = (yTileMin & REGION_TRUNCATE);
	int yRegionMax = ((worldMapPosition.getY() + heightInTiles / 2) & REGION_TRUNCATE) + REGION_SIZE;
	int regionPixelSize = (int) Math.ceil(REGION_SIZE * pixelsPerTile);

	for (int x = xRegionMin; x < xRegionMax; x += REGION_SIZE)
	{
		for (int y = yRegionMin; y < yRegionMax; y += REGION_SIZE)
		{
			graphics.setColor(WHITE_TRANSLUCENT);

			int yTileOffset = -(yTileMin - y);
			int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX();

			int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX();
			int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY();
			// Offset y-position by a single region to correct for drawRect starting from the top
			yPos -= regionPixelSize;

			graphics.drawRect(xPos, yPos, regionPixelSize, regionPixelSize);

			int regionId = ((x >> 6) << 8) | (y >> 6);
			String regionText = String.valueOf(regionId);
			FontMetrics fm = graphics.getFontMetrics();
			Rectangle2D textBounds = fm.getStringBounds(regionText, graphics);
			int labelWidth = (int) textBounds.getWidth() + 2 * LABEL_PADDING;
			int labelHeight = (int) textBounds.getHeight() + 2 * LABEL_PADDING;
			graphics.fillRect(xPos, yPos, labelWidth, labelHeight);
			graphics.setColor(Color.BLACK);
			graphics.drawString(regionText, xPos + LABEL_PADDING, yPos + (int) textBounds.getHeight() + LABEL_PADDING);
		}
	}
}