Update to include FPS, without changing formatting of anything. (#5)

This commit is contained in:
Cameron Moberg
2017-02-01 19:50:09 -06:00
committed by Adam
parent 971a99b241
commit 5d8396cf59
10 changed files with 234 additions and 13 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@ nbactions.xml
nb-configuration.xml
/nbproject/
project.properties
*.iml
.idea/

View File

@@ -25,6 +25,7 @@
package net.runelite.api;
import java.awt.*;
import java.util.Arrays;
public class Client
@@ -40,22 +41,22 @@ public class Client
{
if (client.getLocalPlayer() == null)
return null;
return new Player(this, client.getLocalPlayer());
}
public NPC[] getNpcs()
{
return Arrays.stream(client.getCachedNPCs())
.map(npc -> npc != null ? new NPC(this, npc) : null)
.toArray(size -> new NPC[size]);
.map(npc -> npc != null ? new NPC(this, npc) : null)
.toArray(size -> new NPC[size]);
}
public Player[] getPlayers()
{
return Arrays.stream(client.getCachedPlayers())
.map(player -> player != null ? new Player(this, player) : null)
.toArray(size -> new Player[size]);
.map(player -> player != null ? new Player(this, player) : null)
.toArray(size -> new Player[size]);
}
public int[] getBoostedSkillLevels()
@@ -82,4 +83,24 @@ public class Client
{
return GameState.of(client.getGameState());
}
public Canvas getCanvas()
{
return client.getCanvas();
}
public int getFPS()
{
return client.getFPS();
}
public int getClientHeight()
{
return client.getCanvas().getHeight();
}
public int getClientWidth()
{
return client.getCanvas().getWidth();
}
}

View File

@@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.List;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.boosts.Boosts;
import net.runelite.client.plugins.fpsinfo.FPS;
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
public class PluginManager
@@ -46,6 +47,7 @@ public class PluginManager
{
load(new Boosts());
load(new OpponentInfo());
load(new FPS());
}
private void load(Plugin plugin)

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Cameron Moberg <moberg@tuta.io>
* 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.plugins.fpsinfo;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay;
public class FPS extends Plugin
{
private final Overlay overlay = new FPSOverlay();
@Override
public Overlay getOverlay()
{
return overlay;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2017, Cameron Moberg <moberg@tuta.io>
* 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.plugins.fpsinfo;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import java.awt.*;
public class FPSOverlay extends Overlay
{
private static Client client = RuneLite.getClient();
public FPSOverlay()
{
super(OverlayPosition.TOP_RIGHT, OverlayPriority.HIGH);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (client.getGameState() != GameState.LOGGED_IN)
return null;
FontMetrics fm = graphics.getFontMetrics();
String str = String.valueOf(client.getFPS());
int x = (int) (client.getClientWidth() - fm.getStringBounds(str, graphics).getWidth());
int y = (fm.getHeight());
//outline
graphics.setColor(Color.black);
graphics.drawString(str, x - 1, y + 1);
graphics.drawString(str, x - 1, y - 1);
graphics.drawString(str, x + 1, y + 1);
graphics.drawString(str, x + 1, y - 1);
//actual text
graphics.setColor(Color.white);
graphics.drawString(str, x, y);
return new Dimension((int) fm.getStringBounds(str, graphics).getWidth(), (int) (fm.getStringBounds(str, graphics).getHeight()));
}
}

View File

@@ -27,5 +27,6 @@ package net.runelite.client.ui.overlay;
public enum OverlayPosition
{
TOP_LEFT;
TOP_LEFT,
TOP_RIGHT;
}

View File

@@ -26,6 +26,7 @@
package net.runelite.client.ui.overlay;
import java.awt.image.BufferedImage;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin;
@@ -33,16 +34,25 @@ public class OverlayRenderer
{
public void render(BufferedImage clientBuffer)
{
TopDownRenderer td = new TopDownRenderer();
TopDownRendererLeft tdl = new TopDownRendererLeft();
TopDownRendererRight tdr = new TopDownRendererRight();
for (Plugin plugin : RuneLite.getRunelite().getPluginManager().getPlugins())
{
Overlay overlay = plugin.getOverlay();
if (overlay.getPosition() == OverlayPosition.TOP_LEFT)
td.add(overlay);
switch (overlay.getPosition())
{
case TOP_RIGHT:
tdr.add(overlay);
break;
case TOP_LEFT:
tdl.add(overlay);
break;
}
}
td.render(clientBuffer);
tdl.render(clientBuffer);
tdr.render(clientBuffer);
}
}

View File

@@ -31,7 +31,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class TopDownRenderer
public class TopDownRendererLeft
{
private static final int BORDER_TOP = 25;
private static final int BORDER_LEFT = 10;
@@ -58,8 +58,8 @@ public class TopDownRenderer
if (dimension == null)
continue;
y += dimension.getHeight() + PADDING;
}
}
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* 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;
import net.runelite.api.Client;
import net.runelite.client.RuneLite;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class TopDownRendererRight
{
private static final int BORDER_TOP = 0;
private static final int BORDER_RIGHT = 0;
private static final int PADDING = 10;
private final List<Overlay> overlays = new ArrayList<>();
public void add(Overlay overlay)
{
overlays.add(overlay);
}
public void render(BufferedImage clientBuffer)
{
Client client = RuneLite.getClient();
overlays.sort((o1, o2) -> o2.getPriority().compareTo(o1.getPriority()));
int y = BORDER_TOP;
for (Overlay overlay : overlays)
{
BufferedImage image = clientBuffer.getSubimage(BORDER_RIGHT, y, client.getClientWidth(), 25);
Graphics2D graphics = image.createGraphics();
Dimension dimension = overlay.render(graphics);
graphics.dispose();
if (dimension == null)
continue;
y += dimension.getHeight() + PADDING;
}
}
}

View File

@@ -27,6 +27,8 @@ package net.runelite.rs.api;
import net.runelite.mapping.Import;
import java.awt.*;
public interface Client extends GameEngine
{
@Import("cameraX")
@@ -209,4 +211,7 @@ public interface Client extends GameEngine
@Import("packetHandler")
void packetHandler();
@Import("canvas")
Canvas getCanvas();
}