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
63 changes: 60 additions & 3 deletions src/main/java/top/fpsmaster/features/impl/InterfaceModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,79 @@
import top.fpsmaster.features.settings.impl.NumberSetting;

import java.awt.*;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Set;

/**
* Base for HUD modules.
*
* <p>The shared appearance settings below are consumed by {@code Component.drawRect} and
* {@code Component.drawString} — by the base class, never by the subclass that inherits them.
* Registration therefore belongs here too. Subclasses used to call {@code addSettings(...)} for them
* by hand, which drifted badly: some registered none (the settings still took effect but were
* invisible in the ClickGUI and never persisted), several registered the same setting twice
* (duplicate rows bound to one value), and none of it changed behaviour either way.
*
* <p>Subclasses now declare their {@link Trait}s and register only their own settings;
* {@link #registerCommonSettings()} is applied centrally once every module is constructed.
*/
public class InterfaceModule extends Module {
/** What a HUD module draws, which decides the shared settings that apply to it. */
public enum Trait {
/** Draws a background panel: {@code bg}, {@code backgroundColor}, {@code rounded}, {@code roundRadius}. */
BACKGROUND,
/** Draws text: {@code betterFont}, {@code fontShadow}. */
TEXT,
/** Lays out repeated items and honours {@code spacing}. */
SPACING
}

public BooleanSetting rounded = new BooleanSetting("Round", true);
public NumberSetting roundRadius = new NumberSetting("RoundRadius", 3, 0, 30, 1, () -> rounded.getValue());
public BooleanSetting betterFont = new BooleanSetting("BetterFont", false);
public BooleanSetting fontShadow = new BooleanSetting("FontShadow", true);
public BooleanSetting bg = new BooleanSetting("Background", true);
public ColorSetting backgroundColor = new ColorSetting("BackgroundColor", new Color(0, 0, 0, 0), () -> bg.getValue());
public NumberSetting spacing = new NumberSetting("Spacing",0,0,3,1);
public NumberSetting spacing = new NumberSetting("Spacing", 0, 0, 3, 1);

/** For modules that draw neither a panel nor text — pass this rather than an empty arg list,
* which would resolve to the two-arg constructor and silently pick up the defaults. */
public static final Trait[] NONE = new Trait[0];

private final Set<Trait> traits;

/** Most HUD modules draw a background panel with text on it. */
public InterfaceModule(String name, Category category) {
super(name, category);
this(name, category, Trait.BACKGROUND, Trait.TEXT);
}
}

public InterfaceModule(String name, Category category, Trait... traits) {
super(name, category);
this.traits = traits.length == 0
? EnumSet.noneOf(Trait.class)
: EnumSet.copyOf(Arrays.asList(traits));
}

public boolean has(Trait trait) {
return traits.contains(trait);
}

/**
* Appends the shared settings this module's traits call for. Called once from
* {@code ModuleManager.init()} after every module is constructed, so a module's own settings stay
* at the top of its ClickGUI panel and the shared appearance ones follow. Idempotent —
* {@code addSettings} ignores anything already registered.
*/
public void registerCommonSettings() {
if (has(Trait.BACKGROUND)) {
addSettings(bg, backgroundColor, rounded, roundRadius);
}
if (has(Trait.TEXT)) {
addSettings(betterFont, fontShadow);
}
if (has(Trait.SPACING)) {
addSettings(spacing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ public class ArmorDisplay extends InterfaceModule {
public static ModeSetting mode = new ModeSetting("Mode", 0, "SimpleHoriz", "SimpleVertical", "Vertical");

public ArmorDisplay() {
super("ArmorDisplay", Category.Interface);
addSettings(rounded, backgroundColor, fontShadow, betterFont, spacing, mode, bg, rounded, roundRadius);
super("ArmorDisplay", Category.Interface, Trait.BACKGROUND, Trait.TEXT, Trait.SPACING);
addSettings(mode);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public class BetterChat extends InterfaceModule {
private static java.lang.reflect.Field chatLinesField;
private static java.lang.reflect.Field drawnChatLinesField;


public BetterChat() {
super("BetterChat", Category.Interface);
addSettings(foldMessage, copyMessage, backgroundColor, fontShadow, betterFont, bg);
addSettings(foldMessage, copyMessage);
}

@Override
Expand Down Expand Up @@ -109,5 +108,3 @@ private static java.util.List<ChatLine> getDrawnChatLines(GuiNewChat chat) {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class BlockIndicator extends InterfaceModule {
public BlockIndicator() {
super("BlockIndicator", Category.Interface);
backgroundColor.setColor(new Color(18, 20, 26, 190));
addSettings(showId, showCoords, yOffset, bg, rounded, roundRadius, backgroundColor, panelColor, accentColor);
addSettings(showId, showCoords, yOffset, panelColor, accentColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.LinkedList;

public class CPSDisplay extends InterfaceModule {

private static final LinkedList<Key> KEYS = new LinkedList<>();
private static final CPSCounterListener COUNTER_LISTENER = new CPSCounterListener();
private static boolean trackingRegistered = false;
Expand All @@ -21,7 +20,6 @@ public CPSDisplay() {
super("CPSDisplay", Category.Interface);
ensureTracking();
addSettings(textColor);
addSettings(backgroundColor, fontShadow, betterFont, bg, rounded, roundRadius);
}

public static void ensureTracking() {
Expand Down Expand Up @@ -69,5 +67,3 @@ private static class Key {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class ClockDisplay extends InterfaceModule {
public ClockDisplay() {
super("ClockDisplay", Category.Interface);
backgroundColor.setColor(new Color(18, 20, 26, 160));
addSettings(showSeconds, hour24Mode, label, textColor, betterFont, fontShadow, bg, rounded, roundRadius, backgroundColor);
addSettings(showSeconds, hour24Mode, label, textColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
import java.awt.*;

public class ComboDisplay extends InterfaceModule {

private Entity target = null;

public static int combo = 0;
public static ColorSetting textColor = new ColorSetting("TextColor", new Color(255, 255, 255));

public ComboDisplay() {
super("ComboDisplay", Category.Interface);
addSettings(textColor, backgroundColor, betterFont, fontShadow, rounded, bg, rounded, roundRadius);
addSettings(textColor);
}

@Subscribe
public void onTick(EventTick e) {
if (net.minecraft.client.Minecraft.getMinecraft().thePlayer == null) return;
net.minecraft.entity.player.EntityPlayer rawPlayer =
net.minecraft.client.Minecraft.getMinecraft().thePlayer;

if (rawPlayer.hurtTime == 1 || (target != null && rawPlayer.getDistanceToEntity(target) > 7)) {
combo = 0;
}
Expand All @@ -42,5 +41,3 @@ public void attack(EventAttack e) {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import top.fpsmaster.features.settings.impl.NumberSetting;

public class CoordsDisplay extends InterfaceModule {

public BooleanSetting limitDisplay = new BooleanSetting("LimitDisplay", false);
public NumberSetting limitDisplayY = new NumberSetting("LimitDisplayY", 92, 0, 255, 1);

public CoordsDisplay() {
super("CoordsDisplay", Category.Interface);
addSettings(rounded, backgroundColor, fontShadow, betterFont, bg, rounded, roundRadius);

addSettings(limitDisplay, limitDisplayY);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
import java.awt.*;

public class FPSDisplay extends InterfaceModule {

public static ColorSetting textColor = new ColorSetting("TextColor", new Color(255, 255, 255));

public FPSDisplay() {
super("FPSDisplay", Category.Interface);
addSettings(textColor);
addSettings(rounded, backgroundColor, fontShadow, betterFont, bg, rounded, roundRadius);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
public class InventoryDisplay extends InterfaceModule {
public InventoryDisplay() {
super("InventoryDisplay", Category.Interface);
addSettings(backgroundColor, bg, rounded, roundRadius);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import top.fpsmaster.features.settings.impl.MultipleItemSetting;

public class ItemCountDisplay extends InterfaceModule {

//TODO: Custom 自定义物品数量,建议添加MultipleSetting,便于让用户自动添加,暂未实现
public ModeSetting modes = new ModeSetting("mode", 0, "potpvp", "uhc", "custom");

public MultipleItemSetting itemsSetting = new MultipleItemSetting("items",() -> modes.getValue() == 2);

public ItemCountDisplay() {
super("ItemCountDisplay", Category.Interface);
addSettings(bg, backgroundColor ,rounded, roundRadius, betterFont, fontShadow, spacing, modes, itemsSetting);
super("ItemCountDisplay", Category.Interface, Trait.BACKGROUND, Trait.TEXT, Trait.SPACING);
addSettings(modes, itemsSetting);
}

}



Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,10 @@ public class Keystrokes extends InterfaceModule {
public static ModeSetting spaceStyle = new ModeSetting("SpaceStyle", 0, () -> showSpace.getValue(), "Text", "Bar");

public Keystrokes() {
super("Keystrokes", Category.Interface);
super("Keystrokes", Category.Interface, Trait.BACKGROUND, Trait.TEXT, Trait.SPACING);
CPSDisplay.ensureTracking();
roundRadius.setValue(2);
addSettings(
fontShadow, betterFont,
pressedColor, fontColor, pressedFontColor,
borderColor, borderWidth,
pressAnimMode, pressAnimColor, pressAnimDuration,
showSpace, cpsMode, wasdStyle, spaceStyle, spacing, bg, backgroundColor, rounded, roundRadius
);
addSettings(pressedColor, fontColor, pressedFontColor, borderColor, borderWidth, pressAnimMode, pressAnimColor, pressAnimDuration, showSpace, cpsMode, wasdStyle, spaceStyle);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class MiniMap extends InterfaceModule {
public MiniMap() {
super("MiniMap", Category.Interface);
super("MiniMap", Category.Interface, InterfaceModule.NONE);
}

public static boolean using = false;
Expand All @@ -34,5 +34,3 @@ public void onDisable() {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.awt.*;

public class ModsList extends InterfaceModule {

public BooleanSetting showLogo = new BooleanSetting("ShowText", true);
public BooleanSetting english = new BooleanSetting("English", true);
public BooleanSetting rainbow = new BooleanSetting("Rainbow", true);
Expand All @@ -18,9 +17,7 @@ public class ModsList extends InterfaceModule {

public ModsList() {
super("ModsList", Category.Interface);
addSettings(showLogo, text, english, color, rainbow, betterFont, spacing, backgroundColor, bg);
addSettings(showLogo, text, english, color, rainbow);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ public class PingDisplay extends InterfaceModule {
public PingDisplay() {
super("PingDisplay", Category.Interface);
addSettings(textColor);
addSettings(rounded, backgroundColor, fontShadow, betterFont, bg, rounded, roundRadius);
}

public static ColorSetting textColor = new ColorSetting("TextColor", new Color(255, 255, 255));
}



Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class PlayTime extends InterfaceModule {
public PlayTime() {
super("PlayTime", Category.Interface);
backgroundColor.setColor(new Color(18, 20, 26, 160));
addSettings(displayMode, label, textColor, betterFont, fontShadow, bg, rounded, roundRadius, backgroundColor);
addSettings(displayMode, label, textColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import top.fpsmaster.features.impl.InterfaceModule;
import top.fpsmaster.features.manager.Category;
import top.fpsmaster.features.settings.impl.ColorSetting;

import java.awt.*;

public class PlayerDisplay extends InterfaceModule {
public PlayerDisplay() {
super("PlayerDisplay", Category.Interface);
addSettings(betterFont, rounded, fontShadow, backgroundColor, bg, rounded, roundRadius);
// This HUD used to paint a hard-coded translucent black panel instead of going through
// drawRect, so its background ignored every appearance setting. Now that it uses drawRect,
// seed the shared setting with that same colour so the look is unchanged but adjustable.
backgroundColor = new ColorSetting("BackgroundColor", new Color(0, 0, 0, 60), () -> bg.getValue());
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class PotionDisplay extends InterfaceModule {
public static NumberSetting reminderTime = new NumberSetting("ReminderTime", 20, 1, 120, 1, () -> noticeableReminder.getValue());

public PotionDisplay() {
super("PotionDisplay", Category.Interface);
addSettings(backgroundColor, fontShadow, betterFont, betterAnimation, noticeableReminder, reminderTime, spacing, bg, rounded, roundRadius);
super("PotionDisplay", Category.Interface, Trait.BACKGROUND, Trait.TEXT, Trait.SPACING);
addSettings(betterAnimation, noticeableReminder, reminderTime);
}

@Override
Expand All @@ -29,5 +29,3 @@ public void onDisable() {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ReachDisplay extends InterfaceModule {

public ReachDisplay() {
super("ReachDisplay", Category.Interface);
addSettings(rounded, backgroundColor, fontShadow, betterFont, textColor, bg, rounded, roundRadius);
addSettings(textColor);
}

@Subscribe
Expand All @@ -33,5 +33,3 @@ public void onAttack(EventAttack e) {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Scoreboard extends InterfaceModule {

public Scoreboard() {
super("Scoreboard", Category.Interface);
addSettings(rounded, backgroundColor, fontShadow, betterFont, score, bg, rounded, roundRadius);
addSettings(score);
}

@Override
Expand All @@ -26,5 +26,3 @@ public void onDisable() {
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class ServerAddressDisplay extends InterfaceModule {
public ServerAddressDisplay() {
super("ServerAddressDisplay", Category.Interface);
backgroundColor.setColor(new Color(18, 20, 26, 160));
addSettings(label, textColor, betterFont, fontShadow, bg, rounded, roundRadius, backgroundColor);
addSettings(label, textColor);
}
}
Loading
Loading