Skip to content

Commit

Permalink
lol i fucked that other pr up royally
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGamerBlue committed Feb 2, 2020
1 parent 6ece2b5 commit 710f45e
Show file tree
Hide file tree
Showing 19 changed files with 1,224 additions and 16 deletions.
33 changes: 33 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/geometry/Cuboid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.runelite.api.geometry;

import net.runelite.api.coords.WorldPoint;

public class Cuboid
{
private WorldPoint southWest;
private WorldPoint northEast;

public Cuboid(int x1, int y1, int z1, int x2, int y2, int z2)
{
this(new WorldPoint(x1, y1, z1), new WorldPoint(x2, y2, z2));
}

public Cuboid(WorldPoint southWest, WorldPoint northEast)
{
this.southWest = southWest;
this.northEast = northEast;
}

public boolean contains(WorldPoint worldPoint)
{
if (worldPoint.getPlane() < southWest.getPlane() || worldPoint.getPlane() > northEast.getPlane())
{
return false;
}
if (worldPoint.getY() < southWest.getY() || worldPoint.getY() > northEast.getY())
{
return false;
}
return worldPoint.getX() >= southWest.getX() && worldPoint.getX() <= northEast.getX();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2020 ThatGamerBlue
* 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.freezetimersv2;

import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
import java.awt.Color;

@ConfigGroup("freezetimersv2")
public interface FreezeTimersV2Config extends Config
{
@ConfigItem(
name = "Show NPCs",
keyName = "showNpcs",
description = "Should we show the overlay on NPCs?",
position = 1
)
default boolean showNpcs()
{
return false;
}

@ConfigItem(
name = "Show Players",
keyName = "showPlayers",
description = "Should we show the overlay on players?",
position = 2
)
default boolean showPlayers()
{
return true;
}

@ConfigItem(
name = "Time Mode",
keyName = "timeMode",
description = "How should we display the time?",
position = 3
)
default TimeMode timeMode()
{
return TimeMode.TICKS;
}

@ConfigItem(
name = "Timer Color",
keyName = "timerColor",
description = "Color for timers not on cooldown",
position = 4
)
default Color timerColor()
{
return Color.CYAN;
}

@ConfigItem(
name = "Cooldown Color",
keyName = "cooldownColor",
description = "Color for timers on cooldown",
position = 5
)
default Color cooldownColor()
{
return Color.ORANGE;
}

@ConfigItem(
name = "Freeze Timers",
keyName = "freezeTimers",
description = "Should we render freeze timers?",
position = 6
)
default boolean freezeTimers()
{
return true;
}

@ConfigItem(
name = "Teleblock Timers",
keyName = "teleblockTimers",
description = "Should we render teleblock timers?",
position = 7
)
default boolean teleblockTimers()
{
return true;
}

@ConfigItem(
name = "Vengeance Timers",
keyName = "vengTimers",
description = "Should we render vengeance timers?",
position = 8
)
default boolean vengTimers()
{
return true;
}

@ConfigItem(
name = "Show Icons",
keyName = "showIcons",
description = "Should we render the icons? Note disabling this will override all colors",
position = 9
)
default boolean showIcons()
{
return true;
}

@ConfigItem(
name = "Debug Keybind",
keyName = "debugKeybind",
description = "Don't press this unless you know what it does :)",
position = 10,
hidden = true
)
default Keybind debugKeybind()
{
return Keybind.NOT_SET;
}

@ConfigItem(
name = "Debug Integer",
keyName = "debugInteger",
description = "Related to the keybind in some way :)",
position = 11,
hidden = true
)
default int debugInteger()
{
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Copyright (c) 2020 ThatGamerBlue
* 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.freezetimersv2;

import com.google.common.annotations.VisibleForTesting;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.Point;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import javax.inject.Inject;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public class FreezeTimersV2Overlay extends Overlay
{
@Inject
private TimerManager timerManager;
@Inject
private Client client;
@Inject
private FreezeTimersV2Config config;
@Inject
private ConfigManager configManager;
private final Font timerFont = FontManager.getRunescapeBoldFont().deriveFont(14.0f);

@Inject
public FreezeTimersV2Overlay()
{
super();
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
}

@Override
public Dimension render(Graphics2D g)
{
Font oldFont = g.getFont();
Color oldColor = g.getColor();
g.setFont(timerFont);

if (config.showNpcs())
{
client.getNpcs().forEach((a) -> renderActor(g, a));
}

if (config.showPlayers())
{
client.getPlayers().forEach((a) -> renderActor(g, a));
}

g.setFont(oldFont);
g.setColor(oldColor);

return null;
}

private void renderActor(Graphics2D g, Actor actor)
{
int offset = 0;
for (TimerType timerType : TimerType.values())
{
if (timerType.shouldRender(configManager))
{
if (timerManager.isTimerValid(actor, timerType) && timerManager.hasTimerActive(actor, timerType))
{
if (renderTimer(g, actor, timerType, offset))
{
offset++;
}
}
}
}
}

private boolean renderTimer(Graphics2D g, Actor actor, TimerType timerType, int offset)
{
String text;
Timer timer = timerManager.getTimerFor(actor, timerType);
switch (config.timeMode())
{
case SECONDS:
long millisRemaining = timer.getMillisForRender();
if (millisRemaining == -1)
{
return false; // this shouldnt happen but just in case
}
text = formatTime(millisRemaining);
break;
case TICKS:
int tfr = timer.getTicksForRender();
if (tfr == -1)
{
return false;
}
text = Integer.toString(tfr);
break;
default:
return false;
}

Point canvasLocation = actor.getCanvasTextLocation(g, text, 0);

if (canvasLocation == null)
{
return false;
}

int yOffset = (offset * (g.getFontMetrics().getHeight() + 2));
Rectangle rect = actor.getConvexHull().getBounds();
int xOffset = (int) rect.getWidth();

BufferedImage image = timer.getIcon();
Point actorCIL = actor.getCanvasImageLocation(image, 0);
Point textLocation = new Point(actorCIL.getX() + xOffset, actorCIL.getY() + yOffset);

if (config.showIcons())
{
g.drawImage(image, textLocation.getX(), textLocation.getY(), null);
xOffset = image.getWidth() + 1;
yOffset = (image.getHeight() - g.getFontMetrics().getHeight());
textLocation = new Point(textLocation.getX() + xOffset, textLocation.getY() + image.getHeight() - yOffset);
}

OverlayUtil.renderTextLocation(g, textLocation, text, timer.determineColor());

return true;
}

@VisibleForTesting
public String formatTime(long time)
{
if (time > 59999)
{
return ((int) time / 60000) + ":" + formatSeconds(((int) (time % 60000) / 1000));
}
else if (time > 9999)
{
return ((int) time / 1000) + "";
}
else if (time > 999)
{
return ((int) time / 1000) + "." + ((int) (time % 1000) / 100);
}
return "0." + ((int) time / 100);
}

private String formatSeconds(int seconds)
{
return String.format("%02d", seconds);
}
}
Loading

0 comments on commit 710f45e

Please sign in to comment.