mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Allow changing the averaging window size on TPSWidget
This commit is contained in:
@@ -65,11 +65,11 @@ public class WidgetsModClient implements ClientModInitializer {
|
|||||||
WidgetManager.register(new MemoryUsageWidget(Identifier.of(WidgetsMod.MOD_ID, "memory")));
|
WidgetManager.register(new MemoryUsageWidget(Identifier.of(WidgetsMod.MOD_ID, "memory")));
|
||||||
WidgetManager.register(new KeyStrokesWidget(Identifier.of(WidgetsMod.MOD_ID, "keystrokes")));
|
WidgetManager.register(new KeyStrokesWidget(Identifier.of(WidgetsMod.MOD_ID, "keystrokes")));
|
||||||
WidgetManager.register(new PlainTextWidget(Identifier.of(WidgetsMod.MOD_ID, "plaintext")));
|
WidgetManager.register(new PlainTextWidget(Identifier.of(WidgetsMod.MOD_ID, "plaintext")));
|
||||||
WidgetManager.register(new TPSWidget(Identifier.of(WidgetsMod.MOD_ID, "tps")));
|
|
||||||
WidgetManager.register(new BiomeWidget(Identifier.of(WidgetsMod.MOD_ID, "biome")));
|
WidgetManager.register(new BiomeWidget(Identifier.of(WidgetsMod.MOD_ID, "biome")));
|
||||||
WidgetManager.register(new SpeedWidget(Identifier.of(WidgetsMod.MOD_ID, "speed")));
|
WidgetManager.register(new SpeedWidget(Identifier.of(WidgetsMod.MOD_ID, "speed")));
|
||||||
WidgetManager.register(new ArmorHudWidget(Identifier.of(WidgetsMod.MOD_ID, "armor")));
|
WidgetManager.register(new ArmorHudWidget(Identifier.of(WidgetsMod.MOD_ID, "armor")));
|
||||||
WidgetManager.register(new InventoryWidget(Identifier.of(WidgetsMod.MOD_ID, "inventory")));
|
WidgetManager.register(new InventoryWidget(Identifier.of(WidgetsMod.MOD_ID, "inventory")));
|
||||||
|
WidgetManager.register(TPSWidget.INSTANCE);
|
||||||
|
|
||||||
ComboWidget comboWidget = new ComboWidget(Identifier.of(WidgetsMod.MOD_ID, "combo"));
|
ComboWidget comboWidget = new ComboWidget(Identifier.of(WidgetsMod.MOD_ID, "combo"));
|
||||||
WidgetManager.register(comboWidget);
|
WidgetManager.register(comboWidget);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package de.shiewk.widgets.widgets;
|
package de.shiewk.widgets.widgets;
|
||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.server.ServerTickManager;
|
import net.minecraft.server.ServerTickManager;
|
||||||
@@ -14,21 +16,20 @@ import static net.minecraft.text.Text.literal;
|
|||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.text.Text.translatable;
|
||||||
|
|
||||||
public class TPSWidget extends BasicTextWidget {
|
public class TPSWidget extends BasicTextWidget {
|
||||||
public TPSWidget(Identifier id) {
|
private TPSWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new ToggleWidgetSetting("show_label", translatable("widgets.widgets.common.showLabel"), true),
|
new ToggleWidgetSetting("show_label", translatable("widgets.widgets.common.showLabel"), true),
|
||||||
new ToggleWidgetSetting("dynamic_color", translatable("widgets.widgets.tps.dynamicColor"), true)
|
new ToggleWidgetSetting("dynamic_color", translatable("widgets.widgets.tps.dynamicColor"), true),
|
||||||
|
new IntSliderWidgetSetting("window_size", translatable("widgets.widgets.tps.windowSize"), 2, 5, 20)
|
||||||
));
|
));
|
||||||
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor && !this.rainbow);
|
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor && !this.rainbow);
|
||||||
getSettings().optionById("rainbow").setShowCondition(() -> !this.dynamicColor);
|
getSettings().optionById("rainbow").setShowCondition(() -> !this.dynamicColor);
|
||||||
getSettings().optionById("rainbow_speed").setShowCondition(() -> !this.dynamicColor && this.rainbow);
|
getSettings().optionById("rainbow_speed").setShowCondition(() -> !this.dynamicColor && this.rainbow);
|
||||||
if (INSTANCE != null) throw new IllegalStateException("Instance already initialized");
|
|
||||||
INSTANCE = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TPSWidget INSTANCE;
|
public static final TPSWidget INSTANCE = new TPSWidget(Identifier.of(WidgetsMod.MOD_ID, "tps"));
|
||||||
|
|
||||||
private static final long[] lastUpdates = new long[5];
|
private static long[] lastUpdates = new long[5];
|
||||||
private static int updatePointer = 0;
|
private static int updatePointer = 0;
|
||||||
private static int updatesSinceWorldChange = 0;
|
private static int updatesSinceWorldChange = 0;
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
float mspt = avgDifference / 20000000f;
|
float mspt = avgDifference / 20000000f;
|
||||||
float ticksPerSecond = 1000f / mspt;
|
float ticksPerSecond = 1000f / mspt;
|
||||||
|
|
||||||
boolean loadingFinished = updatesSinceWorldChange > 5;
|
boolean loadingFinished = updatesSinceWorldChange > lastUpdates.length;
|
||||||
if (client.world != null) {
|
if (client.world != null) {
|
||||||
INSTANCE.updateTPS(ticksPerSecond, client.world.getTickManager().getTickRate(), loadingFinished);
|
INSTANCE.updateTPS(ticksPerSecond, client.world.getTickManager().getTickRate(), loadingFinished);
|
||||||
} else {
|
} else {
|
||||||
@@ -125,5 +126,10 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
super.onSettingsChanged(settings);
|
super.onSettingsChanged(settings);
|
||||||
this.dynamicColor = ((ToggleWidgetSetting) settings.optionById("dynamic_color")).getValue();
|
this.dynamicColor = ((ToggleWidgetSetting) settings.optionById("dynamic_color")).getValue();
|
||||||
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||||
|
|
||||||
|
int windowSize = ((IntSliderWidgetSetting) settings.optionById("window_size")).getValue();
|
||||||
|
updatePointer = 0;
|
||||||
|
updatesSinceWorldChange = 0;
|
||||||
|
lastUpdates = new long[windowSize];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,5 +146,6 @@
|
|||||||
"widgets.widgets.tps": "TPS",
|
"widgets.widgets.tps": "TPS",
|
||||||
"widgets.widgets.tps.description": "Zeigt die TPS im Einzelspielermodus an oder schätzt die TPS im Mehrspielermodus",
|
"widgets.widgets.tps.description": "Zeigt die TPS im Einzelspielermodus an oder schätzt die TPS im Mehrspielermodus",
|
||||||
"widgets.widgets.tps.dynamicColor": "Farbe dynamisch anzeigen",
|
"widgets.widgets.tps.dynamicColor": "Farbe dynamisch anzeigen",
|
||||||
"widgets.widgets.tps.tps": "%s TPS"
|
"widgets.widgets.tps.tps": "%s TPS",
|
||||||
|
"widgets.widgets.tps.windowSize": "Durchschnittsfenstergröße (Sekunden)"
|
||||||
}
|
}
|
||||||
@@ -146,5 +146,6 @@
|
|||||||
"widgets.widgets.tps": "TPS",
|
"widgets.widgets.tps": "TPS",
|
||||||
"widgets.widgets.tps.description": "Shows the current TPS when in singleplayer and estimates server TPS when in multiplayer.",
|
"widgets.widgets.tps.description": "Shows the current TPS when in singleplayer and estimates server TPS when in multiplayer.",
|
||||||
"widgets.widgets.tps.dynamicColor": "Dynamic Color",
|
"widgets.widgets.tps.dynamicColor": "Dynamic Color",
|
||||||
"widgets.widgets.tps.tps": "%s TPS"
|
"widgets.widgets.tps.tps": "%s TPS",
|
||||||
|
"widgets.widgets.tps.windowSize": "Averaging window size (seconds)"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user