Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</module>

<module name="FileTabCharacter"/>

<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<module name="ArrayTrailingComma"/>
<module name="AvoidNestedBlocks"/>
Expand All @@ -34,6 +34,7 @@
<module name="OneTopLevelClass"/>
<module name="OuterTypeFilename"/>
<module name="RedundantImport"/>
<module name="SuppressWarningsHolder" />
<module name="UnusedImports"/>
</module>
</module>
61 changes: 53 additions & 8 deletions src/main/java/com/attacktimer/AttackTimerBarOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.util.ImageUtil;

@Singleton
class AttackTimerBarOverlay extends Overlay
abstract class AttackTimerBarOverlay extends Overlay
{
private static final Color BAR_FILL_COLOR = new Color(201, 161, 28);
private static final Color BAR_BG_COLOR = Color.black;
Expand All @@ -63,23 +62,21 @@ class AttackTimerBarOverlay extends Overlay

private boolean shouldShowBar = false;

@Inject
private AttackTimerBarOverlay(final Client client, final AttackTimerMetronomeConfig config, final AttackTimerMetronomePlugin plugin)
protected AttackTimerBarOverlay(final Client client, final AttackTimerMetronomeConfig config, final AttackTimerMetronomePlugin plugin, OverlayLayer layer)
{
this.client = client;
this.config = config;
this.plugin = plugin;

setPosition(OverlayPosition.DYNAMIC);
setPriority(Overlay.PRIORITY_HIGH);
setLayer(OverlayLayer.ABOVE_SCENE);
setLayer(layer);
}

@Override
public Dimension render(Graphics2D graphics)
{
onTick();

if (!shouldShowBar)
{
return null;
Expand All @@ -104,7 +101,8 @@ public Dimension render(Graphics2D graphics)

int denomMod = (config.barEmpties()) ? 1 : 0;
int numerMod = (config.barFills()) ? 1 : 0;
float ratio = (float) (plugin.getTicksUntilNextAttack() - numerMod) / (float) (plugin.getWeaponPeriod() - denomMod);
float ratio = (float) (plugin.getTicksUntilNextAttack() - numerMod)
/ (float) (plugin.getWeaponPeriod() - denomMod);
// barDirection:
// true -> drain -> moves right to left each tick
// false -> fills -> move left to right each tick
Expand Down Expand Up @@ -161,7 +159,16 @@ private float clampBetween0and1(float x)

private void onTick()
{
shouldShowBar = true;
// We have a bar per layer as setting getLayer outside the constructor doesn't do anything. Therefore
// this will be true for exactly ONE of the actual implementation classes and never more.
//
// cite: https://discord.com/channels/301497432909414422/419891709883973642/1538366632265519124
// Seebs: "Can I call setPosition and setLayer post constructor?"
// Abex: "iirc no"
// Abex: "you should have 2 overlays"
//
// So for our case we have one per enum we support.
shouldShowBar = config.BarOverlayLayer().ToOverlayLayer() == getLayer();

if (!config.showBar())
{
Expand All @@ -173,4 +180,42 @@ private void onTick()
shouldShowBar = false;
}
}
}

// These classes are very small and don't really deserve a file each.

@SuppressWarnings("checkstyle:OneTopLevelClass")
@Singleton
class AttackTimerBarOverlayAboveScene extends AttackTimerBarOverlay
{
@Inject
private AttackTimerBarOverlayAboveScene(Client client, AttackTimerMetronomeConfig config,
AttackTimerMetronomePlugin plugin)
{
super(client, config, plugin, OverlayLayer.ABOVE_SCENE);
}
}

@SuppressWarnings("checkstyle:OneTopLevelClass")
@Singleton
class AttackTimerBarOverlayUnderWidgets extends AttackTimerBarOverlay
{
@Inject
private AttackTimerBarOverlayUnderWidgets(Client client, AttackTimerMetronomeConfig config,
AttackTimerMetronomePlugin plugin)
{
super(client, config, plugin, OverlayLayer.UNDER_WIDGETS);
}
}

@SuppressWarnings("checkstyle:OneTopLevelClass")
@Singleton
class AttackTimerBarOverlayAboveWidgets extends AttackTimerBarOverlay
{
@Inject
private AttackTimerBarOverlayAboveWidgets(Client client, AttackTimerMetronomeConfig config,
AttackTimerMetronomePlugin plugin)
{
super(client, config, plugin, OverlayLayer.ABOVE_WIDGETS);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/attacktimer/AttackTimerMetronomeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ default int heightOffset()
return 0;
}

@ConfigItem(
position = 21,
keyName = "attackBarOverlayLayer",
name = "Draw",
description = "Change where bar is drawn order. Runelite layer mapping | Below Overheads: ABOVE_SCENE | Above Overheads: UNDER_WIDGETS | Above Widgets: ABOVE_WIDGETS",
section = ATTACK_BAR_SETTINGS
)
default BarOverlayLayer BarOverlayLayer()
{
return BarOverlayLayer.UNDER_WIDGETS;
}

@ConfigItem(
position = 30,
keyName = "attackBarEmpties",
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/attacktimer/AttackTimerMetronomePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ public enum AttackState
private AttackTimerMetronomeTileOverlay overlay;

@Inject
private AttackTimerBarOverlay barOverlay;
private AttackTimerBarOverlayAboveScene barOverlayAboveScene;
@Inject
private AttackTimerBarOverlayUnderWidgets barOverlayUnderWidgets;
@Inject
private AttackTimerBarOverlayAboveWidgets barOverlayAboveWidgets;

@Inject
private AttackTimerMetronomeConfig config;
Expand Down Expand Up @@ -476,14 +480,18 @@ protected void startUp() throws Exception
trackingLostTicks = false;
overlayManager.add(overlay);
overlay.setPreferredSize(DEFAULT_SIZE);
overlayManager.add(barOverlay);
overlayManager.add(barOverlayAboveScene);
overlayManager.add(barOverlayUnderWidgets);
overlayManager.add(barOverlayAboveWidgets);
}

@Override
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
overlayManager.remove(barOverlay);
overlayManager.remove(barOverlayAboveScene);
overlayManager.remove(barOverlayUnderWidgets);
overlayManager.remove(barOverlayAboveWidgets);
attackDelayHoldoffTicks = 0;
trackingLostTicks = false;
}
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/attacktimer/BarOverlayLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.attacktimer;

import net.runelite.client.ui.overlay.OverlayLayer;

/*
* Copyright (c) 2026, Lexer747 <https://github.com/Lexer747>
* 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.
*/

/**
* BarOverlayLayer is a mirror of Runelite's OverlayLayer but with `MANUAL` and `ALWAYS_ON_TOP` removed since
* we don't want to show those options.
*/
public enum BarOverlayLayer
{
ABOVE_SCENE, UNDER_WIDGETS, ABOVE_WIDGETS;

public OverlayLayer ToOverlayLayer()
{
switch (this)
{
case ABOVE_SCENE:
return OverlayLayer.ABOVE_SCENE;
case UNDER_WIDGETS:
return OverlayLayer.UNDER_WIDGETS;
case ABOVE_WIDGETS:
return OverlayLayer.ABOVE_WIDGETS;
}
// unreachable
return OverlayLayer.ABOVE_SCENE;
}

@Override
public String toString()
{
switch (this)
{
case ABOVE_SCENE:
return "Below Overheads";
case UNDER_WIDGETS:
return "Above Overheads";
case ABOVE_WIDGETS:
return "Above Widgets";
}
// unreachable
return "";
}
}
Loading