mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Support Minecraft 26.1
This commit is contained in:
+7
-16
@@ -1,6 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.14-SNAPSHOT'
|
id 'net.fabricmc.fabric-loom' version "${loom_version}"
|
||||||
id 'maven-publish'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "${project.mod_version}-${project.minecraft_version}"
|
version = "${project.mod_version}-${project.minecraft_version}"
|
||||||
@@ -11,7 +10,7 @@ base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
accessWidenerPath = file("src/main/resources/widgets.accesswidener")
|
accessWidenerPath = file("src/main/resources/widgets.classtweaker")
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -34,21 +33,17 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
implementation "maven.modrinth:modmenu:${project.modmenu_version}"
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
|
||||||
modImplementation "maven.modrinth:modmenu:${project.modmenu_version}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
inputs.property "minecraft_version", project.minecraft_version
|
inputs.property "minecraft_version", project.minecraft_version
|
||||||
inputs.property "loader_version", project.loader_version
|
inputs.property "loader_version", project.loader_version
|
||||||
filteringCharset "UTF-8"
|
filteringCharset = "UTF-8"
|
||||||
|
|
||||||
filesMatching("fabric.mod.json") {
|
filesMatching("fabric.mod.json") {
|
||||||
expand "version": project.version,
|
expand "version": project.version,
|
||||||
@@ -57,7 +52,7 @@ processResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 21
|
def targetJavaVersion = 25
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||||
// this fixes some edge cases with special characters not displaying correctly
|
// this fixes some edge cases with special characters not displaying correctly
|
||||||
@@ -74,10 +69,6 @@ java {
|
|||||||
if (JavaVersion.current() < javaVersion) {
|
if (JavaVersion.current() < javaVersion) {
|
||||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
}
|
}
|
||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
|
||||||
// if it is present.
|
|
||||||
// If you remove this line, sources will not be generated.
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
|||||||
+7
-7
@@ -1,15 +1,15 @@
|
|||||||
# Done to increase the memory available to Gradle.
|
# Done to increase the memory available to Gradle.
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://fabricmc.net/develop/
|
||||||
minecraft_version=1.21.11
|
minecraft_version=26.1
|
||||||
yarn_mappings=1.21.11+build.4
|
loader_version=0.18.4
|
||||||
loader_version=0.17.3
|
loom_version=1.15-SNAPSHOT
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=2.4.0
|
mod_version=2.4.0
|
||||||
maven_group=de.shiewk
|
maven_group=de.shiewk
|
||||||
archives_base_name=Widgets
|
archives_base_name=Widgets
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# check this on https://modmuss50.me/fabric.html
|
# check this on https://fabricmc.net/develop/
|
||||||
fabric_version=0.139.4+1.21.11
|
fabric_version=0.144.0+26.1
|
||||||
modmenu_version=17.0.0-beta.1
|
modmenu_version=18.0.0-alpha.8
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package de.shiewk.widgets;
|
package de.shiewk.widgets;
|
||||||
|
|
||||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public abstract class ModWidget {
|
public abstract class ModWidget {
|
||||||
|
|
||||||
@@ -31,10 +30,10 @@ public abstract class ModWidget {
|
|||||||
public final WidgetSettings getSettings() {
|
public final WidgetSettings getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
public abstract void render(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY);
|
public abstract void render(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY);
|
||||||
public abstract void tick();
|
public abstract void tick();
|
||||||
public abstract Text getName();
|
public abstract Component getName();
|
||||||
public abstract Text getDescription();
|
public abstract Component getDescription();
|
||||||
public abstract void onSettingsChanged(WidgetSettings settings);
|
public abstract void onSettingsChanged(WidgetSettings settings);
|
||||||
|
|
||||||
public void onSettingsChanged() {
|
public void onSettingsChanged() {
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import com.google.gson.JsonSyntaxException;
|
|||||||
import de.shiewk.widgets.client.WidgetManager;
|
import de.shiewk.widgets.client.WidgetManager;
|
||||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static de.shiewk.widgets.WidgetsMod.LOGGER;
|
import static de.shiewk.widgets.WidgetsMod.LOGGER;
|
||||||
import static de.shiewk.widgets.client.WidgetManager.gson;
|
import static de.shiewk.widgets.client.WidgetManager.gson;
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.WidgetsMod;
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -17,6 +15,8 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public class WidgetManager {
|
public class WidgetManager {
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class WidgetManager {
|
|||||||
enabled.remove(widget);
|
enabled.remove(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Function<Identifier, File> saveFileFactory = id -> new File(MinecraftClient.getInstance().runDirectory.getPath() + "/config/widgets/" + id.getNamespace() + "/" + id.getPath() + ".json");
|
static Function<Identifier, File> saveFileFactory = id -> new File(Minecraft.getInstance().gameDirectory.getPath() + "/config/widgets/" + id.getNamespace() + "/" + id.getPath() + ".json");
|
||||||
public static final Gson gson = new Gson();
|
public static final Gson gson = new Gson();
|
||||||
|
|
||||||
public static void saveWidgets(List<ModWidget> widgets) {
|
public static void saveWidgets(List<ModWidget> widgets) {
|
||||||
|
|||||||
@@ -8,19 +8,20 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
|
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.DeltaTracker;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.render.RenderTickCounter;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.profiler.Profiler;
|
import net.minecraft.util.profiling.Profiler;
|
||||||
import net.minecraft.util.profiler.Profilers;
|
import net.minecraft.util.profiling.ProfilerFiller;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public class WidgetRenderer implements ClientTickEvents.StartTick, ClientLifecycleEvents.ClientStarted {
|
public class WidgetRenderer implements ClientTickEvents.StartTick, ClientLifecycleEvents.ClientStarted {
|
||||||
|
|
||||||
public static final Identifier LAYER_ID = Identifier.of(WidgetsMod.MOD_ID, "widgets-hud-layer");
|
public static final Identifier LAYER_ID = Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "widgets-hud-layer");
|
||||||
private static MinecraftClient client;
|
private static Minecraft client;
|
||||||
public static int guiScale = 1;
|
public static int guiScale = 1;
|
||||||
|
|
||||||
public WidgetRenderer(){
|
public WidgetRenderer(){
|
||||||
@@ -30,15 +31,15 @@ public class WidgetRenderer implements ClientTickEvents.StartTick, ClientLifecyc
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderWidgets(DrawContext drawContext, RenderTickCounter tickCounter) {
|
public void renderWidgets(GuiGraphicsExtractor drawContext, DeltaTracker tickCounter) {
|
||||||
if (client.options.hudHidden) return;
|
if (client.options.hideGui) return;
|
||||||
if (client.currentScreen instanceof WidgetVisibilityToggle vt && !vt.shouldRenderWidgets()) return;
|
if (client.screen instanceof WidgetVisibilityToggle vt && !vt.shouldRenderWidgets()) return;
|
||||||
final Profiler profiler = Profilers.get();
|
final ProfilerFiller profiler = Profiler.get();
|
||||||
profiler.push("widgets");
|
profiler.push("widgets");
|
||||||
final TextRenderer textRenderer = client.textRenderer;
|
final Font textRenderer = client.font;
|
||||||
final long timeNano = Util.getMeasuringTimeNano();
|
final long timeNano = Util.getNanos();
|
||||||
final int windowWidth = drawContext.getScaledWindowWidth();
|
final int windowWidth = drawContext.guiWidth();
|
||||||
final int windowHeight = drawContext.getScaledWindowHeight();
|
final int windowHeight = drawContext.guiHeight();
|
||||||
|
|
||||||
final ObjectArrayList<ModWidget> enabled = WidgetManager.enabled;
|
final ObjectArrayList<ModWidget> enabled = WidgetManager.enabled;
|
||||||
for (int i = 0, enabledSize = enabled.size(); i < enabledSize; i++) {
|
for (int i = 0, enabledSize = enabled.size(); i < enabledSize; i++) {
|
||||||
@@ -57,11 +58,11 @@ public class WidgetRenderer implements ClientTickEvents.StartTick, ClientLifecyc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartTick(MinecraftClient client) {
|
public void onStartTick(Minecraft client) {
|
||||||
WidgetRenderer.client = client;
|
WidgetRenderer.client = client;
|
||||||
final Profiler profiler = Profilers.get();
|
final ProfilerFiller profiler = Profiler.get();
|
||||||
profiler.push("widgets");
|
profiler.push("widgets");
|
||||||
guiScale = client.getWindow().getScaleFactor();
|
guiScale = client.getWindow().getGuiScale();
|
||||||
|
|
||||||
final ObjectArrayList<ModWidget> enabled = WidgetManager.enabled;
|
final ObjectArrayList<ModWidget> enabled = WidgetManager.enabled;
|
||||||
for (int i = 0, enabledSize = enabled.size(); i < enabledSize; i++) {
|
for (int i = 0, enabledSize = enabled.size(); i < enabledSize; i++) {
|
||||||
@@ -73,13 +74,13 @@ public class WidgetRenderer implements ClientTickEvents.StartTick, ClientLifecyc
|
|||||||
|
|
||||||
profiler.pop();
|
profiler.pop();
|
||||||
|
|
||||||
if (WidgetsModClient.configKeyBinding.wasPressed()){
|
if (WidgetsModClient.configKeyBinding.consumeClick()){
|
||||||
client.setScreen(new WidgetConfigScreen(client.currentScreen));
|
client.setScreen(new WidgetConfigScreen(client.screen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClientStarted(MinecraftClient client) {
|
public void onClientStarted(@NonNull Minecraft client) {
|
||||||
for (ModWidget widget : WidgetManager.getAllWidgets()) {
|
for (ModWidget widget : WidgetManager.getAllWidgets()) {
|
||||||
widget.onSettingsChanged();
|
widget.onSettingsChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
package de.shiewk.widgets.client;
|
package de.shiewk.widgets.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import de.shiewk.widgets.WidgetsMod;
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
import de.shiewk.widgets.client.screen.WidgetConfigScreen;
|
import de.shiewk.widgets.client.screen.WidgetConfigScreen;
|
||||||
import de.shiewk.widgets.widgets.*;
|
import de.shiewk.widgets.widgets.*;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommands;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
|
||||||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
public class WidgetsModClient implements ClientModInitializer {
|
public class WidgetsModClient implements ClientModInitializer {
|
||||||
|
|
||||||
static KeyBinding configKeyBinding;
|
static KeyMapping configKeyBinding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
@@ -28,52 +28,52 @@ public class WidgetsModClient implements ClientModInitializer {
|
|||||||
ClientLifecycleEvents.CLIENT_STARTED.register(widgetRenderer);
|
ClientLifecycleEvents.CLIENT_STARTED.register(widgetRenderer);
|
||||||
|
|
||||||
// manage widgets keybind
|
// manage widgets keybind
|
||||||
configKeyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
configKeyBinding = KeyMappingHelper.registerKeyMapping(new KeyMapping(
|
||||||
"widgets.key.config",
|
"widgets.key.config",
|
||||||
InputUtil.Type.KEYSYM,
|
InputConstants.Type.KEYSYM,
|
||||||
GLFW.GLFW_KEY_RIGHT_SHIFT,
|
GLFW.GLFW_KEY_RIGHT_SHIFT,
|
||||||
KeyBinding.Category.create(Identifier.of(WidgetsMod.MOD_ID, "main"))
|
KeyMapping.Category.register(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "main"))
|
||||||
));
|
));
|
||||||
|
|
||||||
// in-game /widgetsmod command
|
// in-game /widgetsmod command
|
||||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
|
ClientCommandRegistrationCallback.EVENT.register((dispatcher, _) ->
|
||||||
dispatcher.register(ClientCommandManager.literal("widgetsmod").executes(ctx -> {
|
dispatcher.register(ClientCommands.literal("widgetsmod").executes(ctx -> {
|
||||||
WidgetsMod.LOGGER.info("Ran in-game command");
|
WidgetsMod.LOGGER.info("Ran in-game command");
|
||||||
final MinecraftClient client = ctx.getSource().getClient();
|
final Minecraft client = ctx.getSource().getClient();
|
||||||
client.send(() -> client.setScreen(new WidgetConfigScreen(client.currentScreen)));
|
client.schedule(() -> client.setScreen(new WidgetConfigScreen(client.screen)));
|
||||||
return 0;
|
return 0;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
ClientEntityEvents.ENTITY_LOAD.register((entity, clientWorld) -> {
|
ClientEntityEvents.ENTITY_LOAD.register((entity, _) -> {
|
||||||
if (entity == MinecraftClient.getInstance().player){
|
if (entity == Minecraft.getInstance().player){
|
||||||
// player switched world
|
// player switched world
|
||||||
TPSWidget.worldChanged();
|
TPSWidget.worldChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
WidgetManager.register(new FPSWidget(Identifier.of(WidgetsMod.MOD_ID, "fps")));
|
WidgetManager.register(new FPSWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "fps")));
|
||||||
WidgetManager.register(new ClockWidget(Identifier.of(WidgetsMod.MOD_ID, "clock")));
|
WidgetManager.register(new ClockWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "clock")));
|
||||||
WidgetManager.register(new CoordinatesWidget(Identifier.of(WidgetsMod.MOD_ID, "coordinates")));
|
WidgetManager.register(new CoordinatesWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "coordinates")));
|
||||||
WidgetManager.register(new BandwidthWidget(Identifier.of(WidgetsMod.MOD_ID, "bandwidth")));
|
WidgetManager.register(new BandwidthWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "bandwidth")));
|
||||||
WidgetManager.register(new PingWidget(Identifier.of(WidgetsMod.MOD_ID, "ping")));
|
WidgetManager.register(new PingWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "ping")));
|
||||||
WidgetManager.register(new ServerIPWidget(Identifier.of(WidgetsMod.MOD_ID, "server_ip")));
|
WidgetManager.register(new ServerIPWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "server_ip")));
|
||||||
WidgetManager.register(new PlayerCountWidget(Identifier.of(WidgetsMod.MOD_ID, "player_count")));
|
WidgetManager.register(new PlayerCountWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "player_count")));
|
||||||
WidgetManager.register(new CPSWidget(Identifier.of(WidgetsMod.MOD_ID, "cps")));
|
WidgetManager.register(new CPSWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "cps")));
|
||||||
WidgetManager.register(new PlayTimeWidget(Identifier.of(WidgetsMod.MOD_ID, "playtime")));
|
WidgetManager.register(new PlayTimeWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "playtime")));
|
||||||
WidgetManager.register(new MemoryUsageWidget(Identifier.of(WidgetsMod.MOD_ID, "memory")));
|
WidgetManager.register(new MemoryUsageWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "memory")));
|
||||||
WidgetManager.register(new KeyStrokesWidget(Identifier.of(WidgetsMod.MOD_ID, "keystrokes")));
|
WidgetManager.register(new KeyStrokesWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "keystrokes")));
|
||||||
WidgetManager.register(new PlainTextWidget(Identifier.of(WidgetsMod.MOD_ID, "plaintext")));
|
WidgetManager.register(new PlainTextWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "plaintext")));
|
||||||
WidgetManager.register(new BiomeWidget(Identifier.of(WidgetsMod.MOD_ID, "biome")));
|
WidgetManager.register(new BiomeWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "biome")));
|
||||||
WidgetManager.register(new SpeedWidget(Identifier.of(WidgetsMod.MOD_ID, "speed")));
|
WidgetManager.register(new SpeedWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "speed")));
|
||||||
WidgetManager.register(new ArmorHudWidget(Identifier.of(WidgetsMod.MOD_ID, "armor")));
|
WidgetManager.register(new ArmorHudWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "armor")));
|
||||||
WidgetManager.register(new InventoryWidget(Identifier.of(WidgetsMod.MOD_ID, "inventory")));
|
WidgetManager.register(new InventoryWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "inventory")));
|
||||||
WidgetManager.register(new WorldTimeWidget(Identifier.of(WidgetsMod.MOD_ID, "worldtime")));
|
WidgetManager.register(new WorldTimeWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "worldtime")));
|
||||||
WidgetManager.register(new DirectionWidget(Identifier.of(WidgetsMod.MOD_ID, "direction")));
|
WidgetManager.register(new DirectionWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "direction")));
|
||||||
WidgetManager.register(TPSWidget.INSTANCE);
|
WidgetManager.register(TPSWidget.INSTANCE);
|
||||||
|
|
||||||
ComboWidget comboWidget = new ComboWidget(Identifier.of(WidgetsMod.MOD_ID, "combo"));
|
ComboWidget comboWidget = new ComboWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "combo"));
|
||||||
WidgetManager.register(comboWidget);
|
WidgetManager.register(comboWidget);
|
||||||
AttackEntityCallback.EVENT.register(comboWidget);
|
AttackEntityCallback.EVENT.register(comboWidget);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,42 @@
|
|||||||
package de.shiewk.widgets.client.screen;
|
package de.shiewk.widgets.client.screen;
|
||||||
|
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public abstract class AnimatedScreen extends Screen {
|
public abstract class AnimatedScreen extends Screen {
|
||||||
protected final Screen parent;
|
protected final Screen parent;
|
||||||
private final int animationDurationMs;
|
private final int animationDurationMs;
|
||||||
private final long creationTime = Util.getMeasuringTimeNano();
|
private final long creationTime = Util.getNanos();
|
||||||
protected AnimatedScreen(Text title, Screen parent, int animationDurationMs) {
|
protected AnimatedScreen(Component title, Screen parent, int animationDurationMs) {
|
||||||
super(title);
|
super(title);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.animationDurationMs = animationDurationMs;
|
this.animationDurationMs = animationDurationMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
double timeMs = (Util.getMeasuringTimeNano() - creationTime) / 1000000d;
|
double timeMs = (Util.getNanos() - creationTime) / 1000000d;
|
||||||
final boolean shouldAnimate = timeMs < animationDurationMs;
|
final boolean shouldAnimate = timeMs < animationDurationMs;
|
||||||
if (shouldAnimate){
|
if (shouldAnimate){
|
||||||
double translation = WidgetUtils.computeEasing(timeMs / animationDurationMs) * this.width;
|
double translation = WidgetUtils.computeEasing(timeMs / animationDurationMs) * this.width;
|
||||||
Matrix3x2fStack stack = context.getMatrices().pushMatrix();
|
Matrix3x2fStack stack = context.pose().pushMatrix();
|
||||||
|
|
||||||
stack.translate((float) -translation, 0, stack);
|
stack.translate((float) -translation, 0, stack);
|
||||||
parent.render(context, -67, -67, delta);
|
parent.extractRenderState(context, -67, -67, delta);
|
||||||
stack.translate(this.width, 0, stack);
|
stack.translate(this.width, 0, stack);
|
||||||
mouseX -= (int) translation;
|
mouseX -= (int) translation;
|
||||||
}
|
}
|
||||||
super.render(context, mouseX, mouseY, delta);
|
super.extractRenderState(context, mouseX, mouseY, delta);
|
||||||
this.renderScreenContents(context, mouseX, mouseY, delta);
|
this.renderScreenContents(context, mouseX, mouseY, delta);
|
||||||
if (shouldAnimate){
|
if (shouldAnimate){
|
||||||
context.getMatrices().popMatrix();
|
context.pose().popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void renderScreenContents(DrawContext context, int mouseX, int mouseY, float delta);
|
public abstract void renderScreenContents(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
package de.shiewk.widgets.client.screen;
|
package de.shiewk.widgets.client.screen;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle {
|
public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle {
|
||||||
|
|
||||||
public record Option(Text title, boolean highlighted, Runnable action){
|
public record Option(Component title, boolean highlighted, Runnable action){
|
||||||
|
|
||||||
public Option(Text title, Runnable action){
|
public Option(Component title, Runnable action){
|
||||||
this(title, false, action);
|
this(title, false, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
private int menuWidth;
|
private int menuWidth;
|
||||||
private int menuHeight;
|
private int menuHeight;
|
||||||
|
|
||||||
public ContextMenuScreen(Text title, Screen parent, int menuX, int menuY, List<Option> options) {
|
public ContextMenuScreen(Component title, Screen parent, int menuX, int menuY, List<Option> options) {
|
||||||
super(title);
|
super(title);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.menuX = menuX;
|
this.menuX = menuX;
|
||||||
@@ -56,7 +57,7 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
private int computeMenuWidth() {
|
private int computeMenuWidth() {
|
||||||
int max = 0;
|
int max = 0;
|
||||||
for (Option option : options) {
|
for (Option option : options) {
|
||||||
int width = textRenderer.getWidth(option.title);
|
int width = font.width(option.title);
|
||||||
if (width > max){
|
if (width > max){
|
||||||
max = width;
|
max = width;
|
||||||
}
|
}
|
||||||
@@ -70,21 +71,21 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void onClose() {
|
||||||
client.setScreen(parent);
|
minecraft.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
if (!isInBounds(click.x(), click.y())){
|
if (!isInBounds(click.x(), click.y())){
|
||||||
close();
|
onClose();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int opt = (int) (click.y() - menuY - 1) / 15;
|
int opt = (int) (click.y() - menuY - 1) / 15;
|
||||||
if (opt < options.size()){
|
if (opt < options.size()){
|
||||||
Option option = options.get(opt);
|
Option option = options.get(opt);
|
||||||
close();
|
onClose();
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_OFF);
|
WidgetUtils.playSound(SoundEvents.COPPER_BULB_TURN_OFF);
|
||||||
option.action.run();
|
option.action.run();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -95,10 +96,10 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
super.render(context, mouseX, mouseY, deltaTicks);
|
super.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
parent.render(context, -67, -67, deltaTicks);
|
parent.extractRenderState(context, -67, -67, deltaTicks);
|
||||||
context.drawStrokedRectangle(
|
context.outline(
|
||||||
menuX,
|
menuX,
|
||||||
menuY,
|
menuY,
|
||||||
menuWidth,
|
menuWidth,
|
||||||
@@ -115,7 +116,7 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
renderMenu(context, mouseX, mouseY);
|
renderMenu(context, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderMenu(DrawContext context, int mouseX, int mouseY){
|
public void renderMenu(GuiGraphicsExtractor context, int mouseX, int mouseY){
|
||||||
int y = menuY + 1;
|
int y = menuY + 1;
|
||||||
for (Option option : options) {
|
for (Option option : options) {
|
||||||
boolean hover = isInBounds(mouseX, mouseY) && mouseY >= y && mouseY < y + 15;
|
boolean hover = isInBounds(mouseX, mouseY) && mouseY >= y && mouseY < y + 15;
|
||||||
@@ -127,9 +128,9 @@ public class ContextMenuScreen extends Screen implements WidgetVisibilityToggle
|
|||||||
y + 15,
|
y + 15,
|
||||||
0x30_ff_ff_ff
|
0x30_ff_ff_ff
|
||||||
);
|
);
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
}
|
}
|
||||||
context.drawText(textRenderer, option.title, menuX + 5, y + 3, option.highlighted ? 0xff_00_ff_ff : 0xff_ff_ff_ff, false);
|
context.text(font, option.title, menuX + 5, y + 3, option.highlighted ? 0xff_00_ff_ff : 0xff_ff_ff_ff, false);
|
||||||
y += 15;
|
y += 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package de.shiewk.widgets.client.screen;
|
package de.shiewk.widgets.client.screen;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.Anchor;
|
import de.shiewk.widgets.Anchor;
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.client.WidgetManager;
|
import de.shiewk.widgets.client.WidgetManager;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.gui.components.Tooltip;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -29,15 +29,14 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
private final Consumer<ModWidget> onEdit;
|
private final Consumer<ModWidget> onEdit;
|
||||||
|
|
||||||
public EditWidgetPositionsScreen(Screen parent, Consumer<ModWidget> onEdit) {
|
public EditWidgetPositionsScreen(Screen parent, Consumer<ModWidget> onEdit) {
|
||||||
super(Text.translatable("widgets.ui.editPositions"), parent, 500);
|
super(Component.translatable("widgets.ui.editPositions"), parent, 500);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.onEdit = onEdit;
|
this.onEdit = onEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void onClose() {
|
||||||
assert client != null;
|
minecraft.setScreen(parent);
|
||||||
client.setScreen(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,21 +57,21 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
private int scaledWindowHeight = 1080;
|
private int scaledWindowHeight = 1080;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScreenContents(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void renderScreenContents(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
this.scaledWindowWidth = context.getScaledWindowWidth();
|
this.scaledWindowWidth = context.guiWidth();
|
||||||
this.scaledWindowHeight = context.getScaledWindowHeight();
|
this.scaledWindowHeight = context.guiHeight();
|
||||||
long mt = Util.getMeasuringTimeNano();
|
long mt = Util.getNanos();
|
||||||
renderAnchorArea(context, mouseX, mouseY);
|
renderAnchorArea(context, mouseX, mouseY);
|
||||||
|
|
||||||
for (ModWidget widget : WidgetManager.getEnabledWidgets()) {
|
for (ModWidget widget : WidgetManager.getEnabledWidgets()) {
|
||||||
final int ww = (int) (widget.width() * widget.getScaleFactor());
|
final int ww = (int) (widget.width() * widget.getScaleFactor());
|
||||||
int wx = MathHelper.clamp(widget.getX(scaledWindowWidth), 0, this.width - ww);
|
int wx = Mth.clamp(widget.getX(scaledWindowWidth), 0, this.width - ww);
|
||||||
final int wh = (int) (widget.height() * widget.getScaleFactor());
|
final int wh = (int) (widget.height() * widget.getScaleFactor());
|
||||||
int wy = MathHelper.clamp(widget.getY(scaledWindowHeight), 0, this.height - wh);
|
int wy = Mth.clamp(widget.getY(scaledWindowHeight), 0, this.height - wh);
|
||||||
if (selectedWidget == widget){
|
if (selectedWidget == widget){
|
||||||
AlignResult alignedX = alignX(widget);
|
AlignResult alignedX = alignX(widget);
|
||||||
if (alignedX != null){
|
if (alignedX != null){
|
||||||
context.drawVerticalLine(
|
context.verticalLine(
|
||||||
(int) Math.round(alignedX.result),
|
(int) Math.round(alignedX.result),
|
||||||
0,
|
0,
|
||||||
scaledWindowHeight,
|
scaledWindowHeight,
|
||||||
@@ -81,7 +80,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
AlignResult alignedY = alignY(widget);
|
AlignResult alignedY = alignY(widget);
|
||||||
if (alignedY != null){
|
if (alignedY != null){
|
||||||
context.drawHorizontalLine(
|
context.horizontalLine(
|
||||||
0,
|
0,
|
||||||
scaledWindowWidth,
|
scaledWindowWidth,
|
||||||
(int) Math.round(alignedY.result),
|
(int) Math.round(alignedY.result),
|
||||||
@@ -99,14 +98,14 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selectedWidget == null ? hoveredWidget == widget : selectedWidget == widget){
|
if (selectedWidget == null ? hoveredWidget == widget : selectedWidget == widget){
|
||||||
context.drawStrokedRectangle(wx-1,wy-1, ww+2, wh+2, SELECT_COLOR);
|
context.outline(wx-1,wy-1, ww+2, wh+2, SELECT_COLOR);
|
||||||
context.drawStrokedRectangle(wx, wy, ww, wh, SELECT_COLOR);
|
context.outline(wx, wy, ww, wh, SELECT_COLOR);
|
||||||
}
|
}
|
||||||
widget.render(context, mt, textRenderer, wx, wy);
|
widget.render(context, mt, font, wx, wy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hoveredWidget != null){
|
if (hoveredWidget != null){
|
||||||
context.setCursor(StandardCursors.RESIZE_ALL);
|
context.requestCursor(CursorTypes.RESIZE_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +205,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderAnchorArea(DrawContext context, int mouseX, int mouseY) {
|
private void renderAnchorArea(GuiGraphicsExtractor context, int mouseX, int mouseY) {
|
||||||
Anchor anchor = Anchor.getAnchor(
|
Anchor anchor = Anchor.getAnchor(
|
||||||
scaledWindowWidth,
|
scaledWindowWidth,
|
||||||
scaledWindowHeight,
|
scaledWindowHeight,
|
||||||
@@ -226,7 +225,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(MouseButtonEvent click) {
|
||||||
if (click.button() == 0 && selectedWidget != null){
|
if (click.button() == 0 && selectedWidget != null){
|
||||||
if (align){
|
if (align){
|
||||||
AlignResult alignedX = alignX(selectedWidget);
|
AlignResult alignedX = alignX(selectedWidget);
|
||||||
@@ -253,7 +252,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
if (click.button() == 0 && hoveredWidget != null){
|
if (click.button() == 0 && hoveredWidget != null){
|
||||||
selectedWidget = hoveredWidget;
|
selectedWidget = hoveredWidget;
|
||||||
focusedExtraX = (int) (click.x() - hoveredWidget.getX(scaledWindowWidth));
|
focusedExtraX = (int) (click.x() - hoveredWidget.getX(scaledWindowWidth));
|
||||||
@@ -262,30 +261,29 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
int x = (int) click.x();
|
int x = (int) click.x();
|
||||||
int y = (int) click.y();
|
int y = (int) click.y();
|
||||||
ModWidget hovered = hoveredWidget;
|
ModWidget hovered = hoveredWidget;
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
WidgetUtils.playSound(SoundEvents.COPPER_BULB_TURN_ON);
|
||||||
assert client != null;
|
|
||||||
if (hovered != null){
|
if (hovered != null){
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
Text.empty(),
|
Component.empty(),
|
||||||
this,
|
this,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
List.of(
|
List.of(
|
||||||
new ContextMenuScreen.Option(
|
new ContextMenuScreen.Option(
|
||||||
Text.translatable("widgets.ui.editPositions.menu.widgetSettings"),
|
Component.translatable("widgets.ui.editPositions.menu.widgetSettings"),
|
||||||
() -> client.setScreen(new WidgetSettingsScreen(
|
() -> minecraft.setScreen(new WidgetSettingsScreen(
|
||||||
this,
|
this,
|
||||||
hovered,
|
hovered,
|
||||||
this.onEdit
|
this.onEdit
|
||||||
))
|
))
|
||||||
),
|
),
|
||||||
new ContextMenuScreen.Option(
|
new ContextMenuScreen.Option(
|
||||||
Text.translatable("widgets.ui.editPositions.menu.setAnchor"),
|
Component.translatable("widgets.ui.editPositions.menu.setAnchor"),
|
||||||
() -> {
|
() -> {
|
||||||
List<ContextMenuScreen.Option> options = new ObjectArrayList<>(Anchor.values().length);
|
List<ContextMenuScreen.Option> options = new ObjectArrayList<>(Anchor.values().length);
|
||||||
for (Anchor anchor : Anchor.values()) {
|
for (Anchor anchor : Anchor.values()) {
|
||||||
options.add(new ContextMenuScreen.Option(
|
options.add(new ContextMenuScreen.Option(
|
||||||
Text.translatable("widgets.ui.anchor." + anchor.name().toLowerCase(Locale.ROOT)),
|
Component.translatable("widgets.ui.anchor." + anchor.name().toLowerCase(Locale.ROOT)),
|
||||||
hovered.getSettings().anchor == anchor,
|
hovered.getSettings().anchor == anchor,
|
||||||
() -> {
|
() -> {
|
||||||
hovered.setPos(
|
hovered.setPos(
|
||||||
@@ -298,8 +296,8 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Add widget context menu
|
// Add widget context menu
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
Text.empty(),
|
Component.empty(),
|
||||||
this,
|
this,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@@ -308,7 +306,7 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
new ContextMenuScreen.Option(
|
new ContextMenuScreen.Option(
|
||||||
Text.translatable("widgets.ui.editPositions.menu.removeWidget"),
|
Component.translatable("widgets.ui.editPositions.menu.removeWidget"),
|
||||||
() -> {
|
() -> {
|
||||||
hovered.getSettings().toggleEnabled(hovered);
|
hovered.getSettings().toggleEnabled(hovered);
|
||||||
onEdit.accept(hovered);
|
onEdit.accept(hovered);
|
||||||
@@ -317,14 +315,14 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
Text.empty(),
|
Component.empty(),
|
||||||
this,
|
this,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
List.of(
|
List.of(
|
||||||
new ContextMenuScreen.Option(
|
new ContextMenuScreen.Option(
|
||||||
Text.translatable("widgets.ui.editPositions.menu.addWidget"),
|
Component.translatable("widgets.ui.editPositions.menu.addWidget"),
|
||||||
() -> {
|
() -> {
|
||||||
List<ContextMenuScreen.Option> options = new ObjectArrayList<>();
|
List<ContextMenuScreen.Option> options = new ObjectArrayList<>();
|
||||||
for (ModWidget widget : WidgetManager.getAllWidgets()) {
|
for (ModWidget widget : WidgetManager.getAllWidgets()) {
|
||||||
@@ -340,8 +338,8 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add widget context menu
|
// Add widget context menu
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
Text.empty(),
|
Component.empty(),
|
||||||
this,
|
this,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@@ -357,16 +355,15 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged(Click click, double deltaX, double deltaY) {
|
public boolean mouseDragged(MouseButtonEvent click, double deltaX, double deltaY) {
|
||||||
if (click.button() == 0){
|
if (click.button() == 0){
|
||||||
assert client != null;
|
|
||||||
final ModWidget widget = selectedWidget;
|
final ModWidget widget = selectedWidget;
|
||||||
if (widget != null){
|
if (widget != null){
|
||||||
final WidgetSettings settings = widget.getSettings();
|
final WidgetSettings settings = widget.getSettings();
|
||||||
final int ww = (int) (widget.width() * widget.getScaleFactor());
|
final int ww = (int) (widget.width() * widget.getScaleFactor());
|
||||||
int wx = MathHelper.clamp(widget.getX(scaledWindowWidth), 0, this.width - ww);
|
int wx = Mth.clamp(widget.getX(scaledWindowWidth), 0, this.width - ww);
|
||||||
final int wh = (int) (widget.height() * widget.getScaleFactor());
|
final int wh = (int) (widget.height() * widget.getScaleFactor());
|
||||||
int wy = MathHelper.clamp(widget.getY(scaledWindowHeight), 0, this.height - wh);
|
int wy = Mth.clamp(widget.getY(scaledWindowHeight), 0, this.height - wh);
|
||||||
if (click.x() <= wx + ww + deltaX && click.x() >= wx + deltaX){
|
if (click.x() <= wx + ww + deltaX && click.x() >= wx + deltaX){
|
||||||
if (click.y() <= wy + wh + deltaY && click.y() >= wy + deltaY){
|
if (click.y() <= wy + wh + deltaY && click.y() >= wy + deltaY){
|
||||||
Anchor anchor = Anchor.getAnchor(scaledWindowWidth, scaledWindowHeight, (int) click.x(), (int) click.y());
|
Anchor anchor = Anchor.getAnchor(scaledWindowWidth, scaledWindowHeight, (int) click.x(), (int) click.y());
|
||||||
@@ -407,28 +404,28 @@ public class EditWidgetPositionsScreen extends AnimatedScreen implements WidgetV
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
this.addDrawableChild(
|
this.addRenderableWidget(
|
||||||
new ButtonWidget.Builder(
|
new Button.Builder(
|
||||||
Text.translatable(
|
Component.translatable(
|
||||||
"widgets.ui.editPositions.snap",
|
"widgets.ui.editPositions.snap",
|
||||||
align ?
|
align ?
|
||||||
Text.translatable("gui.yes") :
|
Component.translatable("gui.yes") :
|
||||||
Text.translatable("gui.no")
|
Component.translatable("gui.no")
|
||||||
), button -> {
|
), button -> {
|
||||||
align = !align;
|
align = !align;
|
||||||
button.setMessage(
|
button.setMessage(
|
||||||
Text.translatable(
|
Component.translatable(
|
||||||
"widgets.ui.editPositions.snap",
|
"widgets.ui.editPositions.snap",
|
||||||
align ?
|
align ?
|
||||||
Text.translatable("gui.yes")
|
Component.translatable("gui.yes")
|
||||||
: Text.translatable("gui.no")
|
: Component.translatable("gui.no")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}).position(
|
}).pos(
|
||||||
this.width / 2 - 75,
|
this.width / 2 - 75,
|
||||||
this.height / 2 - 10
|
this.height / 2 - 10
|
||||||
).tooltip(
|
).tooltip(
|
||||||
Tooltip.of(Text.translatable("widgets.ui.editPositions.snap.help"))
|
Tooltip.create(Component.translatable("widgets.ui.editPositions.snap.help"))
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import de.shiewk.widgets.client.WidgetManager;
|
|||||||
import de.shiewk.widgets.client.screen.components.ScaledTextWidget;
|
import de.shiewk.widgets.client.screen.components.ScaledTextWidget;
|
||||||
import de.shiewk.widgets.client.screen.components.WidgetListWidget;
|
import de.shiewk.widgets.client.screen.components.WidgetListWidget;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
import net.minecraft.client.gui.widget.GridWidget;
|
import net.minecraft.client.gui.layouts.FrameLayout;
|
||||||
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
import net.minecraft.client.gui.layouts.GridLayout;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -21,27 +22,26 @@ import java.util.function.Consumer;
|
|||||||
public class WidgetConfigScreen extends Screen {
|
public class WidgetConfigScreen extends Screen {
|
||||||
|
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
private final long creationTime = Util.getMeasuringTimeNano();
|
private final long creationTime = Util.getNanos();
|
||||||
private final ArrayList<ModWidget> widgetsEdited = new ArrayList<>();
|
private final ArrayList<ModWidget> widgetsEdited = new ArrayList<>();
|
||||||
private final Consumer<ModWidget> onWidgetEdit = this::changedSettings;
|
private final Consumer<ModWidget> onWidgetEdit = this::changedSettings;
|
||||||
|
|
||||||
private double getScreenTimeMs(){
|
private double getScreenTimeMs(){
|
||||||
return (Util.getMeasuringTimeNano() - creationTime) / 1000000d;
|
return (Util.getNanos() - creationTime) / 1000000d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WidgetConfigScreen(Screen parent) {
|
public WidgetConfigScreen(Screen parent) {
|
||||||
super(Text.translatable("widgets.ui.config"));
|
super(Component.translatable("widgets.ui.config"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void onClose() {
|
||||||
WidgetManager.saveWidgets(widgetsEdited);
|
WidgetManager.saveWidgets(widgetsEdited);
|
||||||
for (ModWidget widget : widgetsEdited) {
|
for (ModWidget widget : widgetsEdited) {
|
||||||
widget.onSettingsChanged();
|
widget.onSettingsChanged();
|
||||||
}
|
}
|
||||||
assert client != null;
|
minecraft.setScreen(parent);
|
||||||
client.setScreen(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int widgetListWidth;
|
int widgetListWidth;
|
||||||
@@ -54,55 +54,53 @@ public class WidgetConfigScreen extends Screen {
|
|||||||
widgetListWidth = widgetColumns * WidgetListWidget.COLUMN_SIZE;
|
widgetListWidth = widgetColumns * WidgetListWidget.COLUMN_SIZE;
|
||||||
|
|
||||||
// Right side
|
// Right side
|
||||||
final WidgetListWidget widgetList = new WidgetListWidget(width - widgetListWidth - 4, 0, widgetListWidth, height - 24, client, textRenderer, onWidgetEdit);
|
final WidgetListWidget widgetList = new WidgetListWidget(width - widgetListWidth - 4, 0, widgetListWidth, height - 24, minecraft, font, onWidgetEdit);
|
||||||
|
|
||||||
final TextFieldWidget searchField = new TextFieldWidget(textRenderer, widgetListWidth, 20, Text.empty());
|
final EditBox searchField = new EditBox(font, widgetListWidth, 20, Component.empty());
|
||||||
searchField.setPlaceholder(Text.translatable("widgets.ui.search"));
|
searchField.setHint(Component.translatable("widgets.ui.search"));
|
||||||
searchField.setChangedListener(widgetList::search);
|
searchField.setResponder(widgetList::search);
|
||||||
searchField.setX(width - widgetListWidth - 4);
|
searchField.setX(width - widgetListWidth - 4);
|
||||||
searchField.setY(height - 24);
|
searchField.setY(height - 24);
|
||||||
|
|
||||||
this.addDrawableChild(widgetList);
|
this.addRenderableWidget(widgetList);
|
||||||
this.addDrawableChild(searchField);
|
this.addRenderableWidget(searchField);
|
||||||
setInitialFocus(searchField);
|
setInitialFocus(searchField);
|
||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
GridWidget gw = new GridWidget(0, 0);
|
GridLayout gw = new GridLayout(0, 0);
|
||||||
gw.getMainPositioner().margin(4, 4, 4, 4);
|
gw.defaultCellSetting().padding(4, 4, 4, 4);
|
||||||
GridWidget.Adder adder = gw.createAdder(1);
|
GridLayout.RowHelper adder = gw.createRowHelper(1);
|
||||||
{
|
{
|
||||||
ScaledTextWidget title = new ScaledTextWidget(0, 0, Text.literal("ᴡɪᴅɢᴇᴛѕ"), textRenderer, width < 600 ? 4 : 6);
|
ScaledTextWidget title = new ScaledTextWidget(0, 0, Component.literal("ᴡɪᴅɢᴇᴛѕ"), font, width < 600 ? 4 : 6);
|
||||||
adder.add(title);
|
adder.addChild(title);
|
||||||
|
|
||||||
ButtonWidget editPosButton = ButtonWidget.builder(Text.translatable("widgets.ui.editPositions"), this::switchToEditPositions).build();
|
Button editPosButton = Button.builder(Component.translatable("widgets.ui.editPositions"), this::switchToEditPositions).build();
|
||||||
adder.add(editPosButton);
|
adder.addChild(editPosButton);
|
||||||
}
|
}
|
||||||
gw.refreshPositions();
|
gw.arrangeElements();
|
||||||
SimplePositioningWidget.setPos(gw, 0, 0, width - widgetListWidth, height, .5f, .5f);
|
FrameLayout.alignInRectangle(gw, 0, 0, width - widgetListWidth, height, .5f, .5f);
|
||||||
gw.forEachChild(c -> c.setX((width - widgetListWidth) / 2 - (c.getWidth() / 2)));
|
gw.visitWidgets(c -> c.setX((width - widgetListWidth) / 2 - (c.getWidth() / 2)));
|
||||||
gw.forEachChild(this::addDrawableChild);
|
gw.visitWidgets(this::addRenderableWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchToEditPositions(ButtonWidget widget) {
|
private void switchToEditPositions(Button widget) {
|
||||||
widget.active = false;
|
widget.active = false;
|
||||||
assert client != null;
|
minecraft.setScreen(new EditWidgetPositionsScreen(this, this.onWidgetEdit));
|
||||||
client.setScreen(new EditWidgetPositionsScreen(this, this.onWidgetEdit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
assert client != null;
|
|
||||||
final double time = getScreenTimeMs();
|
final double time = getScreenTimeMs();
|
||||||
if (time < 400){
|
if (time < 400){
|
||||||
Matrix3x2fStack stack = context.getMatrices().pushMatrix();
|
Matrix3x2fStack stack = context.pose().pushMatrix();
|
||||||
final float v = (float) WidgetUtils.computeEasing(time / 400d);
|
final float v = (float) WidgetUtils.computeEasing(time / 400d);
|
||||||
stack.translate((float) (width / 2d - (width * v / 2d)), (float) (height / 2d - (height * v / 2d)), stack);
|
stack.translate((float) (width / 2d - (width * v / 2d)), (float) (height / 2d - (height * v / 2d)), stack);
|
||||||
stack.scale(v, v, stack);
|
stack.scale(v, v, stack);
|
||||||
}
|
}
|
||||||
super.render(context, mouseX, mouseY, delta);
|
super.extractRenderState(context, mouseX, mouseY, delta);
|
||||||
|
|
||||||
if (time < 400){
|
if (time < 400){
|
||||||
context.getMatrices().popMatrix();
|
context.pose().popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,23 @@ package de.shiewk.widgets.client.screen;
|
|||||||
|
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.client.screen.components.WidgetSettingsEditWidget;
|
import de.shiewk.widgets.client.screen.components.WidgetSettingsEditWidget;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class WidgetSettingsScreen extends AnimatedScreen implements WidgetVisibilityToggle {
|
public class WidgetSettingsScreen extends AnimatedScreen implements WidgetVisibilityToggle {
|
||||||
private static final Text previewText = Text.translatable("widgets.ui.preview");
|
private static final Component previewText = Component.translatable("widgets.ui.preview");
|
||||||
private final ModWidget widget;
|
private final ModWidget widget;
|
||||||
private final Runnable onChange;
|
private final Runnable onChange;
|
||||||
public WidgetSettingsScreen(Screen parent, ModWidget widget, Consumer<ModWidget> changedWidgetConsumer) {
|
public WidgetSettingsScreen(Screen parent, ModWidget widget, Consumer<ModWidget> changedWidgetConsumer) {
|
||||||
super(Text.translatable("widgets.ui.widgetSettings", widget.getName()), parent, 500);
|
super(Component.translatable("widgets.ui.widgetSettings", widget.getName()), parent, 500);
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
onChange = () -> {
|
onChange = () -> {
|
||||||
widget.onSettingsChanged();
|
widget.onSettingsChanged();
|
||||||
@@ -28,19 +29,19 @@ public class WidgetSettingsScreen extends AnimatedScreen implements WidgetVisibi
|
|||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
addDrawableChild(new WidgetSettingsEditWidget(0, 0, this.width / 2 - 8, this.height, textRenderer, widget, this.onChange));
|
addRenderableWidget(new WidgetSettingsEditWidget(0, 0, this.width / 2 - 8, this.height, font, widget, this.onChange));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScreenContents(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void renderScreenContents(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
context.drawText(textRenderer, previewText, this.width * 3 / 4 - textRenderer.getWidth(previewText) / 2, this.height / 50, 0xffffffff, false);
|
context.text(font, previewText, this.width * 3 / 4 - font.width(previewText) / 2, this.height / 50, 0xffffffff, false);
|
||||||
widget.render(context, Util.getMeasuringTimeNano(), textRenderer, (int) ((float) (this.width * 3) / 4 - (widget.width() * widget.getScaleFactor()) / 2), (int) ((float) this.height / 2 - (widget.height() * widget.getScaleFactor()) / 2));
|
widget.render(context, Util.getNanos(), font, (int) ((float) (this.width * 3) / 4 - (widget.width() * widget.getScaleFactor()) / 2), (int) ((float) this.height / 2 - (widget.height() * widget.getScaleFactor()) / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(@NonNull MouseButtonEvent click) {
|
||||||
for (Element child : children()) {
|
for (GuiEventListener child : children()) {
|
||||||
if (child instanceof ClickableWidget s){
|
if (child instanceof AbstractWidget s){
|
||||||
s.mouseReleased(click);
|
s.mouseReleased(click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,9 +49,8 @@ public class WidgetSettingsScreen extends AnimatedScreen implements WidgetVisibi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void onClose() {
|
||||||
assert client != null;
|
minecraft.setScreen(parent);
|
||||||
client.setScreen(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,42 +1,43 @@
|
|||||||
package de.shiewk.widgets.client.screen.components;
|
package de.shiewk.widgets.client.screen.components;
|
||||||
|
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public class ScaledTextWidget extends ClickableWidget {
|
public class ScaledTextWidget extends AbstractWidget {
|
||||||
|
|
||||||
private final TextRenderer textRenderer;
|
private final Font textRenderer;
|
||||||
private final float scale;
|
private final float scale;
|
||||||
|
|
||||||
public ScaledTextWidget(int x, int y, Text message, TextRenderer textRenderer, float scale) {
|
public ScaledTextWidget(int x, int y, Component message, Font textRenderer, float scale) {
|
||||||
super(x, y, 0, (int) (textRenderer.fontHeight * scale), message);
|
super(x, y, 0, (int) (textRenderer.lineHeight * scale), message);
|
||||||
this.textRenderer = textRenderer;
|
this.textRenderer = textRenderer;
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return (int) (textRenderer.getWidth(getMessage()) * scale);
|
return (int) (textRenderer.width(getMessage()) * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
protected void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
Matrix3x2fStack stack = context.getMatrices().pushMatrix();
|
Matrix3x2fStack stack = context.pose().pushMatrix();
|
||||||
stack.scale(scale);
|
stack.scale(scale);
|
||||||
context.drawText(textRenderer, getMessage(), (int) (getX() / scale), (int) (getY() / scale), 0xffffffff, true);
|
context.text(textRenderer, getMessage(), (int) (getX() / scale), (int) (getY() / scale), 0xffffffff, true);
|
||||||
stack.popMatrix();
|
stack.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
|
protected void updateWidgetNarration(@NonNull NarrationElementOutput builder) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
package de.shiewk.widgets.client.screen.components;
|
package de.shiewk.widgets.client.screen.components;
|
||||||
|
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationPart;
|
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public class WidgetDisplayWidget extends ClickableWidget {
|
public class WidgetDisplayWidget extends AbstractWidget {
|
||||||
|
|
||||||
protected final ModWidget widget;
|
protected final ModWidget widget;
|
||||||
protected final TextRenderer textRenderer;
|
protected final Font textRenderer;
|
||||||
protected final int centerX;
|
protected final int centerX;
|
||||||
protected final int centerY;
|
protected final int centerY;
|
||||||
|
|
||||||
public WidgetDisplayWidget(ModWidget widget, TextRenderer textRenderer, int centerX, int centerY) {
|
public WidgetDisplayWidget(ModWidget widget, Font textRenderer, int centerX, int centerY) {
|
||||||
super(0, 0, (int) widget.scaledWidth(), (int) widget.scaledHeight(), widget.getName());
|
super(0, 0, (int) widget.scaledWidth(), (int) widget.scaledHeight(), widget.getName());
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
this.textRenderer = textRenderer;
|
this.textRenderer = textRenderer;
|
||||||
@@ -44,12 +45,12 @@ public class WidgetDisplayWidget extends ClickableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
protected void extractWidgetRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
widget.render(context, Util.getMeasuringTimeNano(), textRenderer, getX(), getY());
|
widget.render(context, Util.getNanos(), textRenderer, getX(), getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
protected void updateWidgetNarration(NarrationElementOutput builder) {
|
||||||
builder.put(NarrationPart.HINT, widget.getName());
|
builder.add(NarratedElementType.HINT, widget.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package de.shiewk.widgets.client.screen.components;
|
|||||||
|
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.client.WidgetManager;
|
import de.shiewk.widgets.client.WidgetManager;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.AbstractScrollArea;
|
||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
import net.minecraft.client.gui.layouts.FrameLayout;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationPart;
|
import net.minecraft.client.gui.layouts.GridLayout;
|
||||||
import net.minecraft.client.gui.widget.GridWidget;
|
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||||
import net.minecraft.client.gui.widget.ScrollableWidget;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -23,13 +24,13 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class WidgetListWidget extends ScrollableWidget {
|
public class WidgetListWidget extends AbstractScrollArea {
|
||||||
|
|
||||||
public static final int COLUMN_SIZE = 208;
|
public static final int COLUMN_SIZE = 208;
|
||||||
private final MinecraftClient client;
|
private final Minecraft client;
|
||||||
private List<ModWidget> widgets;
|
private List<ModWidget> widgets;
|
||||||
private final List<WidgetWidget> elements = new ArrayList<>();
|
private final List<WidgetWidget> elements = new ArrayList<>();
|
||||||
private final TextRenderer textRenderer;
|
private final Font textRenderer;
|
||||||
private final Consumer<ModWidget> onEdit;
|
private final Consumer<ModWidget> onEdit;
|
||||||
|
|
||||||
public static boolean searchQueryMatches(String search, ModWidget widget) {
|
public static boolean searchQueryMatches(String search, ModWidget widget) {
|
||||||
@@ -37,8 +38,8 @@ public class WidgetListWidget extends ScrollableWidget {
|
|||||||
return widget.getName().getString().contains(search) || widget.getDescription().getString().contains(search) || widget.getId().toString().contains(search);
|
return widget.getName().getString().contains(search) || widget.getDescription().getString().contains(search) || widget.getId().toString().contains(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WidgetListWidget(int x, int y, int width, int height, MinecraftClient client, TextRenderer textRenderer, Consumer<ModWidget> onEdit) {
|
public WidgetListWidget(int x, int y, int width, int height, Minecraft client, Font textRenderer, Consumer<ModWidget> onEdit) {
|
||||||
super(x, y, width, height, Text.empty());
|
super(x, y, width, height, Component.empty(), AbstractScrollArea.defaultSettings(35));
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.widgets = loadWidgets(null);
|
this.widgets = loadWidgets(null);
|
||||||
this.textRenderer = textRenderer;
|
this.textRenderer = textRenderer;
|
||||||
@@ -55,16 +56,16 @@ public class WidgetListWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init(){
|
private void init(){
|
||||||
GridWidget gw = new GridWidget();
|
GridLayout gw = new GridLayout();
|
||||||
gw.getMainPositioner().margin(4, 4, 4, 4);
|
gw.defaultCellSetting().padding(4, 4, 4, 4);
|
||||||
final GridWidget.Adder adder = gw.createAdder(getColumns());
|
final GridLayout.RowHelper adder = gw.createRowHelper(getColumns());
|
||||||
for (ModWidget widget : widgets) {
|
for (ModWidget widget : widgets) {
|
||||||
adder.add(new WidgetWidget(0, 0, 200, 100, client, widget, textRenderer, onEdit));
|
adder.addChild(new WidgetWidget(0, 0, 200, 100, client, widget, textRenderer, onEdit));
|
||||||
}
|
}
|
||||||
SimplePositioningWidget.setPos(gw, getX(), getY(), this.getWidth(), this.getContentsHeightWithPadding(), 0, 0);
|
FrameLayout.alignInRectangle(gw, getX(), getY(), this.getWidth(), this.contentHeight(), 0, 0);
|
||||||
gw.refreshPositions();
|
gw.arrangeElements();
|
||||||
this.elements.clear();
|
this.elements.clear();
|
||||||
gw.forEachChild(w -> this.addWidget((WidgetWidget) w));
|
gw.visitWidgets(w -> this.addWidget((WidgetWidget) w));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addWidget(WidgetWidget drawableElement) {
|
protected void addWidget(WidgetWidget drawableElement) {
|
||||||
@@ -72,7 +73,7 @@ public class WidgetListWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getContentsHeightWithPadding() {
|
protected int contentHeight() {
|
||||||
final int columns = getColumns();
|
final int columns = getColumns();
|
||||||
final int rows = (int) Math.ceil((double) widgets.size() / columns);
|
final int rows = (int) Math.ceil((double) widgets.size() / columns);
|
||||||
return 10 + (rows * 108);
|
return 10 + (rows * 108);
|
||||||
@@ -87,47 +88,42 @@ public class WidgetListWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double getDeltaYPerScroll() {
|
protected void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
return 35;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
||||||
context.enableScissor(getX(), getY(), getX()+width, getY()+height);
|
context.enableScissor(getX(), getY(), getX()+width, getY()+height);
|
||||||
Matrix3x2fStack stack = context.getMatrices().pushMatrix();
|
Matrix3x2fStack stack = context.pose().pushMatrix();
|
||||||
stack.translate(0, (float) -getScrollY(), stack);
|
stack.translate(0, (float) -scrollAmount(), stack);
|
||||||
for (WidgetWidget element : elements) {
|
for (WidgetWidget element : elements) {
|
||||||
element.render(context, mouseX, (int) (mouseY + getScrollY()), delta);
|
element.extractRenderState(context, mouseX, (int) (mouseY + scrollAmount()), delta);
|
||||||
}
|
}
|
||||||
stack.popMatrix();
|
stack.popMatrix();
|
||||||
context.disableScissor();
|
context.disableScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
double mouseY = click.y();
|
double mouseY = click.y();
|
||||||
double mouseX = click.x();
|
double mouseX = click.x();
|
||||||
mouseY += getScrollY();
|
mouseY += scrollAmount();
|
||||||
Click newClick = new Click(mouseX, mouseY, click.buttonInfo());
|
MouseButtonEvent newClick = new MouseButtonEvent(mouseX, mouseY, click.buttonInfo());
|
||||||
for (Element element : elements) {
|
for (GuiEventListener element : elements) {
|
||||||
if (element.mouseClicked(newClick, doubled)){
|
if (element.mouseClicked(newClick, doubled)){
|
||||||
client.getSoundManager().play(PositionedSoundInstance.ui(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
client.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.checkScrollbarDragged(newClick);
|
return super.updateScrolling(newClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
protected void updateWidgetNarration(@NonNull NarrationElementOutput builder) {
|
||||||
for (ModWidget widget : widgets) {
|
for (ModWidget widget : widgets) {
|
||||||
builder.put(NarrationPart.HINT, widget.getName());
|
builder.add(NarratedElementType.HINT, widget.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void search(String query) {
|
public void search(String query) {
|
||||||
widgets = this.loadWidgets(query);
|
widgets = this.loadWidgets(query);
|
||||||
setScrollY(0);
|
setScrollAmount(0);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-38
@@ -2,28 +2,29 @@ package de.shiewk.widgets.client.screen.components;
|
|||||||
|
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.AbstractScrollArea;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.widget.ScrollableWidget;
|
import net.minecraft.client.input.CharacterEvent;
|
||||||
import net.minecraft.client.input.CharInput;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
import net.minecraft.client.input.KeyInput;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class WidgetSettingsEditWidget extends ScrollableWidget {
|
public class WidgetSettingsEditWidget extends AbstractScrollArea {
|
||||||
private static final int COLOR_FG = Color.WHITE.getRGB(), COLOR_BG = new Color(0, 0, 0, 60).getRGB();
|
private static final int COLOR_FG = Color.WHITE.getRGB(), COLOR_BG = new Color(0, 0, 0, 60).getRGB();
|
||||||
private final TextRenderer textRenderer;
|
private final Font textRenderer;
|
||||||
private final ModWidget widget;
|
private final ModWidget widget;
|
||||||
private final Runnable onChange;
|
private final Runnable onChange;
|
||||||
private WidgetSettingOption<?> focus = null;
|
private WidgetSettingOption<?> focus = null;
|
||||||
private int contentsHeight = 10;
|
private int contentsHeight = 10;
|
||||||
|
|
||||||
public WidgetSettingsEditWidget(int x, int y, int width, int height, TextRenderer textRenderer, ModWidget widget, Runnable onChange) {
|
public WidgetSettingsEditWidget(int x, int y, int width, int height, Font textRenderer, ModWidget widget, Runnable onChange) {
|
||||||
super(x, y, width, height, Text.empty());
|
super(x, y, width, height, Component.empty(), AbstractScrollArea.defaultSettings(20));
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
this.textRenderer = textRenderer;
|
this.textRenderer = textRenderer;
|
||||||
this.onChange = onChange;
|
this.onChange = onChange;
|
||||||
@@ -43,39 +44,34 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getContentsHeightWithPadding() {
|
protected int contentHeight() {
|
||||||
return this.contentsHeight;
|
return this.contentsHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double getDeltaYPerScroll() {
|
protected void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
return 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
||||||
context.fill(getX(), getY(), getX()+width, getY()+height, COLOR_BG);
|
context.fill(getX(), getY(), getX()+width, getY()+height, COLOR_BG);
|
||||||
Matrix3x2fStack matrices = context.getMatrices().pushMatrix();
|
Matrix3x2fStack matrices = context.pose().pushMatrix();
|
||||||
matrices.translate(0, (float) -getScrollY(), matrices);
|
matrices.translate(0, (float) -scrollAmount(), matrices);
|
||||||
matrices.pushMatrix();
|
matrices.pushMatrix();
|
||||||
matrices.scale(2, 2, matrices);
|
matrices.scale(2, 2, matrices);
|
||||||
matrices.translate(0, (float) -getScrollY(), matrices);
|
matrices.translate(0, (float) -scrollAmount(), matrices);
|
||||||
context.drawText(textRenderer, widget.getName(), this.width / 4 - textRenderer.getWidth(widget.getName()) / 2, this.height / 100, COLOR_FG, true);
|
context.text(textRenderer, widget.getName(), this.width / 4 - textRenderer.width(widget.getName()) / 2, this.height / 100, COLOR_FG, true);
|
||||||
matrices.popMatrix();
|
matrices.popMatrix();
|
||||||
int y = textRenderer.fontHeight * 2 + this.height / 50 + 5;
|
int y = textRenderer.lineHeight * 2 + this.height / 50 + 5;
|
||||||
for (WidgetSettingOption<?> setting : widget.getSettings().getCustomSettings()) {
|
for (WidgetSettingOption<?> setting : widget.getSettings().getCustomSettings()) {
|
||||||
if (!setting.shouldShow()) continue;
|
if (!setting.shouldShow()) continue;
|
||||||
if (this.width - setting.getWidth() > textRenderer.getWidth(setting.getName()) + 20){
|
if (this.width - setting.getWidth() > textRenderer.width(setting.getName()) + 20){
|
||||||
setting.setX(this.getX() + this.width - setting.getWidth() - 5);
|
setting.setX(this.getX() + this.width - setting.getWidth() - 5);
|
||||||
setting.setY(y);
|
setting.setY(y);
|
||||||
context.drawText(textRenderer, setting.getName(), getX() + 10, y + (setting.getHeight() / 2), COLOR_FG, true);
|
context.text(textRenderer, setting.getName(), getX() + 10, y + (setting.getHeight() / 2), COLOR_FG, true);
|
||||||
} else {
|
} else {
|
||||||
setting.setX(this.getX() + this.width / 2 - setting.getWidth() / 2);
|
setting.setX(this.getX() + this.width / 2 - setting.getWidth() / 2);
|
||||||
setting.setY(y + 9 + 5);
|
setting.setY(y + 9 + 5);
|
||||||
context.drawText(textRenderer, setting.getName(), getX() + getWidth() / 2 - textRenderer.getWidth(setting.getName()) / 2, y, COLOR_FG, true);
|
context.text(textRenderer, setting.getName(), getX() + getWidth() / 2 - textRenderer.width(setting.getName()) / 2, y, COLOR_FG, true);
|
||||||
y += 9 + 5;
|
y += 9 + 5;
|
||||||
}
|
}
|
||||||
setting.render(context, mouseX, (int) (mouseY + getScrollY()), delta);
|
setting.extractRenderState(context, mouseX, (int) (mouseY + scrollAmount()), delta);
|
||||||
y += setting.getHeight();
|
y += setting.getHeight();
|
||||||
y += 5;
|
y += 5;
|
||||||
}
|
}
|
||||||
@@ -84,16 +80,16 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
double mouseY = click.y();
|
double mouseY = click.y();
|
||||||
double mouseX = click.x();
|
double mouseX = click.x();
|
||||||
mouseY += getScrollY();
|
mouseY += scrollAmount();
|
||||||
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
||||||
if (!customSetting.shouldShow()) continue;
|
if (!customSetting.shouldShow()) continue;
|
||||||
if (customSetting.isHovered(mouseX, mouseY)){
|
if (customSetting.isHovered(mouseX, mouseY)){
|
||||||
focus = customSetting;
|
focus = customSetting;
|
||||||
customSetting.setFocused(true);
|
customSetting.setFocused(true);
|
||||||
if (customSetting.mouseClicked(new Click(mouseX, mouseY + getScrollY(), click.buttonInfo()), doubled)){
|
if (customSetting.mouseClicked(new MouseButtonEvent(mouseX, mouseY + scrollAmount(), click.buttonInfo()), doubled)){
|
||||||
onChange.run();
|
onChange.run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -101,14 +97,14 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
customSetting.setFocused(false);
|
customSetting.setFocused(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return checkScrollbarDragged(click);
|
return updateScrolling(click);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(@NonNull MouseButtonEvent click) {
|
||||||
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
for (WidgetSettingOption<?> customSetting : widget.getSettings().getCustomSettings()) {
|
||||||
if (!customSetting.shouldShow()) continue;
|
if (!customSetting.shouldShow()) continue;
|
||||||
if (customSetting.mouseReleased(new Click(click.x(), click.y() + getScrollY(), click.buttonInfo()))){
|
if (customSetting.mouseReleased(new MouseButtonEvent(click.x(), click.y() + scrollAmount(), click.buttonInfo()))){
|
||||||
onChange.run();
|
onChange.run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -117,7 +113,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean charTyped(CharInput input) {
|
public boolean charTyped(@NonNull CharacterEvent input) {
|
||||||
if (this.focus != null){
|
if (this.focus != null){
|
||||||
if (this.focus.charTyped(input)){
|
if (this.focus.charTyped(input)){
|
||||||
onChange.run();
|
onChange.run();
|
||||||
@@ -128,7 +124,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(KeyInput input) {
|
public boolean keyPressed(@NonNull KeyEvent input) {
|
||||||
if (this.focus != null){
|
if (this.focus != null){
|
||||||
if (this.focus.keyPressed(input)){
|
if (this.focus.keyPressed(input)){
|
||||||
onChange.run();
|
onChange.run();
|
||||||
@@ -139,7 +135,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyReleased(KeyInput input) {
|
public boolean keyReleased(@NonNull KeyEvent input) {
|
||||||
if (this.focus != null){
|
if (this.focus != null){
|
||||||
if (this.focus.keyReleased(input)){
|
if (this.focus.keyReleased(input)){
|
||||||
onChange.run();
|
onChange.run();
|
||||||
@@ -150,7 +146,7 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
protected void updateWidgetNarration(@NonNull NarrationElementOutput builder) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
package de.shiewk.widgets.client.screen.components;
|
package de.shiewk.widgets.client.screen.components;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.ModWidget;
|
import de.shiewk.widgets.ModWidget;
|
||||||
import de.shiewk.widgets.client.screen.WidgetSettingsScreen;
|
import de.shiewk.widgets.client.screen.WidgetSettingsScreen;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.text.OrderedText;
|
import net.minecraft.util.FormattedCharSequence;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class WidgetWidget extends ClickableWidget {
|
public class WidgetWidget extends AbstractWidget {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected static final int COLOR_BG = new Color(0, 0, 0, 80).getRGB(),
|
protected static final int COLOR_BG = new Color(0, 0, 0, 80).getRGB(),
|
||||||
COLOR_BG_HOVER = new Color(40, 40, 40, 80).getRGB(),
|
COLOR_BG_HOVER = new Color(40, 40, 40, 80).getRGB(),
|
||||||
@@ -32,14 +31,14 @@ public class WidgetWidget extends ClickableWidget {
|
|||||||
COLOR_ENABLED_HOVER = new Color(0, 255, 0, 200).getRGB(),
|
COLOR_ENABLED_HOVER = new Color(0, 255, 0, 200).getRGB(),
|
||||||
COLOR_BORDER = 0x80_ff_ff_ff;
|
COLOR_BORDER = 0x80_ff_ff_ff;
|
||||||
|
|
||||||
private final MinecraftClient client;
|
private final Minecraft client;
|
||||||
private final ModWidget widget;
|
private final ModWidget widget;
|
||||||
private final TextRenderer textRenderer;
|
private final Font textRenderer;
|
||||||
private final Consumer<ModWidget> onEdit;
|
private final Consumer<ModWidget> onEdit;
|
||||||
|
|
||||||
private long toggleTime = 0;
|
private long toggleTime = 0;
|
||||||
|
|
||||||
public WidgetWidget(int x, int y, int width, int height, MinecraftClient client, ModWidget widget, TextRenderer textRenderer, Consumer<ModWidget> onEdit) {
|
public WidgetWidget(int x, int y, int width, int height, Minecraft client, ModWidget widget, Font textRenderer, Consumer<ModWidget> onEdit) {
|
||||||
super(x, y, width, height, widget.getName());
|
super(x, y, width, height, widget.getName());
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
@@ -53,36 +52,36 @@ public class WidgetWidget extends ClickableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
protected void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
boolean hover = this.isMouseOver(mouseX, mouseY);
|
boolean hover = this.isMouseOver(mouseX, mouseY);
|
||||||
boolean widgetEnabled = widget.getSettings().isEnabled();
|
boolean widgetEnabled = widget.getSettings().isEnabled();
|
||||||
context.fill(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight(), hover ? COLOR_BG_HOVER : COLOR_BG);
|
context.fill(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight(), hover ? COLOR_BG_HOVER : COLOR_BG);
|
||||||
Matrix3x2fStack stack = context.getMatrices().pushMatrix();
|
Matrix3x2fStack stack = context.pose().pushMatrix();
|
||||||
stack.scale(2, 2, stack);
|
stack.scale(2, 2, stack);
|
||||||
int titleSize = textRenderer.getWidth(widget.getName());
|
int titleSize = textRenderer.width(widget.getName());
|
||||||
context.drawText(textRenderer, widget.getName(), getX() / 2 + getWidth() / 4 - titleSize / 2, getY() / 2 + 4, COLOR_FG, false);
|
context.text(textRenderer, widget.getName(), getX() / 2 + getWidth() / 4 - titleSize / 2, getY() / 2 + 4, COLOR_FG, false);
|
||||||
stack.popMatrix();
|
stack.popMatrix();
|
||||||
int y = this.getY() + 12 + textRenderer.fontHeight * 2;
|
int y = this.getY() + 12 + textRenderer.lineHeight * 2;
|
||||||
for (Iterator<OrderedText> it = textRenderer.wrapLines(widget.getDescription(), this.getWidth() - 10).iterator(); it.hasNext(); y += 9) {
|
for (Iterator<FormattedCharSequence> it = textRenderer.split(widget.getDescription(), this.getWidth() - 10).iterator(); it.hasNext(); y += 9) {
|
||||||
OrderedText t = it.next();
|
FormattedCharSequence t = it.next();
|
||||||
context.drawText(textRenderer, t, getX() + 5 + ((getWidth() - 5) / 2) - (textRenderer.getWidth(t) / 2), y, COLOR_FG, false);
|
context.text(textRenderer, t, getX() + 5 + ((getWidth() - 5) / 2) - (textRenderer.width(t) / 2), y, COLOR_FG, false);
|
||||||
}
|
}
|
||||||
this.renderToggleButton(context, mouseX, mouseY, widgetEnabled);
|
this.renderToggleButton(context, mouseX, mouseY, widgetEnabled);
|
||||||
|
|
||||||
if (hover || isMouseOverToggle(mouseX, mouseY)){
|
if (hover || isMouseOverToggle(mouseX, mouseY)){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.drawHorizontalLine(getX(), getX() + getWidth() - 1, getY(), COLOR_BORDER);
|
context.horizontalLine(getX(), getX() + getWidth() - 1, getY(), COLOR_BORDER);
|
||||||
context.drawHorizontalLine(getX() + 1, getX() + getWidth() - 1, getY() + getHeight() - 1, COLOR_BORDER);
|
context.horizontalLine(getX() + 1, getX() + getWidth() - 1, getY() + getHeight() - 1, COLOR_BORDER);
|
||||||
context.drawVerticalLine(getX(), getY(), getY() + getHeight(), COLOR_BORDER);
|
context.verticalLine(getX(), getY(), getY() + getHeight(), COLOR_BORDER);
|
||||||
context.drawVerticalLine(getX() + getWidth() - 1, getY(), getY() + getHeight() - 1, COLOR_BORDER);
|
context.verticalLine(getX() + getWidth() - 1, getY(), getY() + getHeight() - 1, COLOR_BORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
if (isMouseOver(click.x(), click.y())){
|
if (isMouseOver(click.x(), click.y())){
|
||||||
client.setScreen(new WidgetSettingsScreen(client.currentScreen, widget, onEdit));
|
client.setScreen(new WidgetSettingsScreen(client.screen, widget, onEdit));
|
||||||
return true;
|
return true;
|
||||||
} else if (isMouseOverToggle(click.x(), click.y())){
|
} else if (isMouseOverToggle(click.x(), click.y())){
|
||||||
this.toggleWidget();
|
this.toggleWidget();
|
||||||
@@ -93,11 +92,11 @@ public class WidgetWidget extends ClickableWidget {
|
|||||||
|
|
||||||
private void toggleWidget() {
|
private void toggleWidget() {
|
||||||
widget.getSettings().toggleEnabled(widget);
|
widget.getSettings().toggleEnabled(widget);
|
||||||
toggleTime = Util.getMeasuringTimeNano();
|
toggleTime = Util.getNanos();
|
||||||
onEdit.accept(widget);
|
onEdit.accept(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderToggleButton(DrawContext context, int mouseX, int mouseY, boolean widgetEnabled){
|
private void renderToggleButton(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean widgetEnabled){
|
||||||
boolean hoverToggle = this.isMouseOverToggle(mouseX, mouseY);
|
boolean hoverToggle = this.isMouseOverToggle(mouseX, mouseY);
|
||||||
final int toggleColor;
|
final int toggleColor;
|
||||||
final int toggleColorInvert;
|
final int toggleColorInvert;
|
||||||
@@ -118,13 +117,13 @@ public class WidgetWidget extends ClickableWidget {
|
|||||||
toggleColorInvert = COLOR_ENABLED;
|
toggleColorInvert = COLOR_ENABLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toggleTime > Util.getMeasuringTimeNano() - 250000000){
|
if (toggleTime > Util.getNanos() - 250000000){
|
||||||
context.fill(this.getX(), this.getY() + this.getHeight() - 24, this.getX() + this.getWidth(), this.getY() + this.getHeight(), toggleColorInvert);
|
context.fill(this.getX(), this.getY() + this.getHeight() - 24, this.getX() + this.getWidth(), this.getY() + this.getHeight(), toggleColorInvert);
|
||||||
context.fill(this.getX(), this.getY() + this.getHeight() - 24, (int) (WidgetUtils.computeEasing((Util.getMeasuringTimeNano() - toggleTime) / 250000000d) * this.getWidth() + this.getX()), this.getY() + this.getHeight(), toggleColor);
|
context.fill(this.getX(), this.getY() + this.getHeight() - 24, (int) (WidgetUtils.computeEasing((Util.getNanos() - toggleTime) / 250000000d) * this.getWidth() + this.getX()), this.getY() + this.getHeight(), toggleColor);
|
||||||
} else {
|
} else {
|
||||||
context.fill(this.getX(), this.getY() + this.getHeight() - 24, this.getX() + this.getWidth(), this.getY() + this.getHeight(), toggleColor);
|
context.fill(this.getX(), this.getY() + this.getHeight() - 24, this.getX() + this.getWidth(), this.getY() + this.getHeight(), toggleColor);
|
||||||
}
|
}
|
||||||
context.drawCenteredTextWithShadow(textRenderer, Text.translatable(widgetEnabled ? "widgets.ui.enabled" : "widgets.ui.disabled"), this.getX() + (this.getWidth() / 2), this.getY() + this.getHeight() - 16, COLOR_FG);
|
context.centeredText(textRenderer, Component.translatable(widgetEnabled ? "widgets.ui.enabled" : "widgets.ui.disabled"), this.getX() + (this.getWidth() / 2), this.getY() + this.getHeight() - 16, COLOR_FG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMouseOverToggle(double mouseX, double mouseY) {
|
private boolean isMouseOverToggle(double mouseX, double mouseY) {
|
||||||
@@ -132,7 +131,7 @@ public class WidgetWidget extends ClickableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
protected void updateWidgetNarration(@NonNull NarrationElementOutput builder) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+42
-41
@@ -1,42 +1,43 @@
|
|||||||
package de.shiewk.widgets.client.screen.gradienteditor;
|
package de.shiewk.widgets.client.screen.gradienteditor;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.WidgetsMod;
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gl.RenderPipelines;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.IntSupplier;
|
import java.util.function.IntSupplier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.empty;
|
import static net.minecraft.network.chat.Component.empty;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<GradientEditorColorSection.ListEntry> {
|
public class GradientEditorColorSection extends ObjectSelectionList<GradientEditorColorSection.ListEntry> {
|
||||||
|
|
||||||
private final GradientEditorScreen editor;
|
private final GradientEditorScreen editor;
|
||||||
private static final Identifier TEXTURE_BUTTON_PLUS = Identifier.of(WidgetsMod.MOD_ID, "textures/gui/button_plus.png"),
|
private static final Identifier TEXTURE_BUTTON_PLUS = Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "textures/gui/button_plus.png"),
|
||||||
TEXTURE_ARROW_DOWN = Identifier.of(WidgetsMod.MOD_ID, "textures/gui/arrow_down.png");
|
TEXTURE_ARROW_DOWN = Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "textures/gui/arrow_down.png");
|
||||||
|
|
||||||
private final List<ColorEntry> colorEntries;
|
private final List<ColorEntry> colorEntries;
|
||||||
|
|
||||||
public GradientEditorColorSection(GradientEditorScreen editor, MinecraftClient client, int x, int y, int width, int height, int focusedIndex) {
|
public GradientEditorColorSection(GradientEditorScreen editor, Minecraft client, int x, int y, int width, int height, int focusedIndex) {
|
||||||
super(client, width, height, y, 64);
|
super(client, width, height, y, 64);
|
||||||
setX(x);
|
setX(x);
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
colorEntries = new ObjectArrayList<>(editor.colors.size());
|
colorEntries = new ObjectArrayList<>(editor.colors.size());
|
||||||
addEntry(new HeadingEntry(client.textRenderer), 18);
|
addEntry(new HeadingEntry(client.font), 18);
|
||||||
|
|
||||||
IntArrayList colors = editor.colors;
|
IntArrayList colors = editor.colors;
|
||||||
for (int i = 0; i < colors.size(); i++) {
|
for (int i = 0; i < colors.size(); i++) {
|
||||||
@@ -57,26 +58,26 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawSelectionHighlight(DrawContext context, ListEntry entry, int color) {}
|
protected void extractSelection(@NonNull GuiGraphicsExtractor context, @NonNull ListEntry entry, int color) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawMenuListBackground(DrawContext context) {
|
protected void extractListBackground(GuiGraphicsExtractor context) {
|
||||||
context.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), 0x50_00_00_00);
|
context.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), 0x50_00_00_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawHeaderAndFooterSeparators(DrawContext context) {}
|
protected void extractListSeparators(@NonNull GuiGraphicsExtractor context) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawScrollbar(DrawContext context, int mouseX, int mouseY) {}
|
protected void extractScrollbar(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFocused(@Nullable Element focused) {
|
public void setFocused(@Nullable GuiEventListener focused) {
|
||||||
if (focused == null) return;
|
if (focused == null) return;
|
||||||
if (focused instanceof ListEntry se && !se.canFocus()) return;
|
if (focused instanceof ListEntry se && !se.canFocus()) return;
|
||||||
|
|
||||||
if (super.getFocused() != focused){
|
if (super.getFocused() != focused){
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
WidgetUtils.playSound(SoundEvents.COPPER_BULB_TURN_ON);
|
||||||
}
|
}
|
||||||
if (focused instanceof ColorEntry color){
|
if (focused instanceof ColorEntry color){
|
||||||
editor.setCurrentColorIndex(colorEntries.indexOf(color));
|
editor.setCurrentColorIndex(colorEntries.indexOf(color));
|
||||||
@@ -88,14 +89,14 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
setFocused(colorEntries.getLast());
|
setFocused(colorEntries.getLast());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class ListEntry extends AlwaysSelectedEntryListWidget.Entry<ListEntry> {
|
public abstract static class ListEntry extends ObjectSelectionList.Entry<ListEntry> {
|
||||||
|
|
||||||
public boolean canFocus(){
|
public boolean canFocus(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getNarration() {
|
public @NonNull Component getNarration() {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,13 +110,13 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
int color = this.color.getAsInt();
|
int color = this.color.getAsInt();
|
||||||
int x = this.getX();
|
int x = this.getX();
|
||||||
int y = this.getContentY();
|
int y = this.getContentY();
|
||||||
|
|
||||||
if (hovered && !isFocused()){
|
if (hovered && !isFocused()){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
context.fill(x, y, x+getWidth(), y+getHeight(), 0x30_ff_ff_ff);
|
context.fill(x, y, x+getWidth(), y+getHeight(), 0x30_ff_ff_ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +145,8 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
private static class ArrowDownEntry extends ListEntry {
|
private static class ArrowDownEntry extends ListEntry {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
context.drawTexture(
|
context.blit(
|
||||||
RenderPipelines.GUI_TEXTURED,
|
RenderPipelines.GUI_TEXTURED,
|
||||||
TEXTURE_ARROW_DOWN,
|
TEXTURE_ARROW_DOWN,
|
||||||
getX() + 16,
|
getX() + 16,
|
||||||
@@ -163,29 +164,29 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
|
|
||||||
private static class HeadingEntry extends ListEntry {
|
private static class HeadingEntry extends ListEntry {
|
||||||
|
|
||||||
private final TextRenderer textRenderer;
|
private final Font textRenderer;
|
||||||
|
|
||||||
private HeadingEntry(TextRenderer textRenderer) {
|
private HeadingEntry(Font textRenderer) {
|
||||||
this.textRenderer = textRenderer;
|
this.textRenderer = textRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
Text text = translatable("widgets.ui.gradientEditor.colors");
|
Component text = translatable("widgets.ui.gradientEditor.colors");
|
||||||
|
|
||||||
int y = this.getContentY() + 2;
|
int y = this.getContentY() + 2;
|
||||||
int rowWidth = 64;
|
int rowWidth = 64;
|
||||||
|
|
||||||
int textWidth = textRenderer.getWidth(text);
|
int textWidth = textRenderer.width(text);
|
||||||
int textX = getX() + (rowWidth - textWidth) / 2;
|
int textX = getX() + (rowWidth - textWidth) / 2;
|
||||||
context.drawText(textRenderer, text, textX, y, 0xffffffff, true);
|
context.text(textRenderer, text, textX, y, 0xffffffff, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AddButtonEntry extends ListEntry {
|
private class AddButtonEntry extends ListEntry {
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
context.drawTexture(
|
context.blit(
|
||||||
RenderPipelines.GUI_TEXTURED,
|
RenderPipelines.GUI_TEXTURED,
|
||||||
TEXTURE_BUTTON_PLUS,
|
TEXTURE_BUTTON_PLUS,
|
||||||
getX(),
|
getX(),
|
||||||
@@ -199,8 +200,8 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
hovered ? 0xff_cf_cf_cf : 0xff_8d_8d_8d
|
hovered ? 0xff_cf_cf_cf : 0xff_8d_8d_8d
|
||||||
);
|
);
|
||||||
if (hovered){
|
if (hovered){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
context.drawTooltip(client.textRenderer, List.of(
|
context.setComponentTooltipForNextFrame(minecraft.font, List.of(
|
||||||
translatable("widgets.ui.gradientEditor.colors.add.tooltip.0"),
|
translatable("widgets.ui.gradientEditor.colors.add.tooltip.0"),
|
||||||
translatable("widgets.ui.gradientEditor.colors.add.tooltip.1")
|
translatable("widgets.ui.gradientEditor.colors.add.tooltip.1")
|
||||||
), mouseX, mouseY);
|
), mouseX, mouseY);
|
||||||
@@ -208,7 +209,7 @@ public class GradientEditorColorSection extends AlwaysSelectedEntryListWidget<Gr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
editor.addNewColor(editor.getCurrentColor());
|
editor.addNewColor(editor.getCurrentColor());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-26
@@ -7,13 +7,14 @@ import de.shiewk.widgets.color.GradientMode;
|
|||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class GradientEditorScreen extends Screen implements WidgetVisibilityToggle {
|
public class GradientEditorScreen extends Screen implements WidgetVisibilityToggle {
|
||||||
|
|
||||||
@@ -54,35 +55,35 @@ public class GradientEditorScreen extends Screen implements WidgetVisibilityTogg
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getTopBarHeight() {
|
private int getTopBarHeight() {
|
||||||
return 8 + this.textRenderer.fontHeight * 2;
|
return 8 + this.font.lineHeight * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
super.render(context, mouseX, mouseY, deltaTicks);
|
super.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
|
|
||||||
Matrix3x2fStack matrices = context.getMatrices();
|
Matrix3x2fStack matrices = context.pose();
|
||||||
long timeNanos = Util.getMeasuringTimeNano();
|
long timeNanos = Util.getNanos();
|
||||||
|
|
||||||
// Render top bar
|
// Render top bar
|
||||||
topBarGradient.fillHorizontal(context, timeNanos, 0, 0, this.width, this.getTopBarHeight());
|
topBarGradient.fillHorizontal(context, timeNanos, 0, 0, this.width, this.getTopBarHeight());
|
||||||
|
|
||||||
Text topBarText = translatable("widgets.ui.gradientEditor");
|
Component topBarText = translatable("widgets.ui.gradientEditor");
|
||||||
int width = textRenderer.getWidth(topBarText);
|
int width = font.width(topBarText);
|
||||||
|
|
||||||
matrices.pushMatrix().translate(this.width / 2f - width, 5).scale(2);
|
matrices.pushMatrix().translate(this.width / 2f - width, 5).scale(2);
|
||||||
context.drawText(textRenderer, topBarText, 0, 0, 0xff_ff_ff_ff, true);
|
context.text(font, topBarText, 0, 0, 0xff_ff_ff_ff, true);
|
||||||
matrices.popMatrix();
|
matrices.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadComponents(){
|
public void reloadComponents(){
|
||||||
clearChildren();
|
clearWidgets();
|
||||||
|
|
||||||
double colorScrollY = 0;
|
double colorScrollY = 0;
|
||||||
double settingsScrollY = 0;
|
double settingsScrollY = 0;
|
||||||
if (this.colorSection != null){
|
if (this.colorSection != null){
|
||||||
colorScrollY = colorSection.getScrollY();
|
colorScrollY = colorSection.scrollAmount();
|
||||||
settingsScrollY = settingsSection.getScrollY();
|
settingsScrollY = settingsSection.scrollAmount();
|
||||||
}
|
}
|
||||||
int topBarHeight = getTopBarHeight();
|
int topBarHeight = getTopBarHeight();
|
||||||
|
|
||||||
@@ -93,29 +94,29 @@ public class GradientEditorScreen extends Screen implements WidgetVisibilityTogg
|
|||||||
int mainAreaHeight = this.height - topBarHeight;
|
int mainAreaHeight = this.height - topBarHeight;
|
||||||
|
|
||||||
// sidebar
|
// sidebar
|
||||||
this.colorSection = new GradientEditorColorSection(this, this.client, 0, topBarHeight, colorSectionWidth, mainAreaHeight, this.getCurrentColorIndex());
|
this.colorSection = new GradientEditorColorSection(this, this.minecraft, 0, topBarHeight, colorSectionWidth, mainAreaHeight, this.getCurrentColorIndex());
|
||||||
this.settingsSection = new GradientEditorSettingsSection(this, this.client, colorSectionWidth, topBarHeight, settingsSectionWidth, mainAreaHeight);
|
this.settingsSection = new GradientEditorSettingsSection(this, this.minecraft, colorSectionWidth, topBarHeight, settingsSectionWidth, mainAreaHeight);
|
||||||
addDrawableChild(this.colorSection);
|
addRenderableWidget(this.colorSection);
|
||||||
addDrawableChild(this.settingsSection);
|
addRenderableWidget(this.settingsSection);
|
||||||
colorSection.setScrollY(colorScrollY);
|
colorSection.setScrollAmount(colorScrollY);
|
||||||
settingsSection.setScrollY(settingsScrollY);
|
settingsSection.setScrollAmount(settingsScrollY);
|
||||||
|
|
||||||
// main area
|
// main area
|
||||||
int mainAreaX = colorSectionWidth + settingsSectionWidth;
|
int mainAreaX = colorSectionWidth + settingsSectionWidth;
|
||||||
int mainAreaCenterX = mainAreaX + (mainAreaWidth / 2);
|
int mainAreaCenterX = mainAreaX + (mainAreaWidth / 2);
|
||||||
|
|
||||||
addDrawable(new WidgetDisplayWidget(this.widget, this.textRenderer, mainAreaCenterX, (mainAreaHeight) / 2 + topBarHeight));
|
addRenderableOnly(new WidgetDisplayWidget(this.widget, this.font, mainAreaCenterX, (mainAreaHeight) / 2 + topBarHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderBackground(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
public void extractBackground(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
super.renderBackground(context, mouseX, mouseY, deltaTicks);
|
super.extractBackground(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void onClose() {
|
||||||
refreshSettingValue();
|
refreshSettingValue();
|
||||||
client.setScreen(parent);
|
minecraft.setScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshSettingValue() {
|
private void refreshSettingValue() {
|
||||||
|
|||||||
+120
-122
@@ -1,30 +1,28 @@
|
|||||||
package de.shiewk.widgets.client.screen.gradienteditor;
|
package de.shiewk.widgets.client.screen.gradienteditor;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.WidgetsMod;
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
import de.shiewk.widgets.client.WidgetManager;
|
import de.shiewk.widgets.client.WidgetManager;
|
||||||
import de.shiewk.widgets.client.screen.ContextMenuScreen;
|
import de.shiewk.widgets.client.screen.ContextMenuScreen;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.color.GradientPreset;
|
import de.shiewk.widgets.color.GradientPreset;
|
||||||
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gl.RenderPipelines;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.components.*;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.input.CharacterEvent;
|
||||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
import net.minecraft.client.gui.widget.SliderWidget;
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.client.input.CharInput;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.client.input.KeyInput;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.client.texture.NativeImage;
|
|
||||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -32,16 +30,16 @@ import java.util.function.IntConsumer;
|
|||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
import static de.shiewk.widgets.utils.WidgetUtils.colorARGBToHexRGBA;
|
import static de.shiewk.widgets.utils.WidgetUtils.colorARGBToHexRGBA;
|
||||||
import static net.minecraft.text.Text.empty;
|
import static net.minecraft.network.chat.Component.empty;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget<GradientEditorSettingsSection.ListEntry> {
|
public class GradientEditorSettingsSection extends ObjectSelectionList<GradientEditorSettingsSection.ListEntry> {
|
||||||
|
|
||||||
private final GradientEditorScreen editor;
|
private final GradientEditorScreen editor;
|
||||||
private final HexValueInputEntry hexInput;
|
private final HexValueInputEntry hexInput;
|
||||||
private final ColorPickerHueSliderEntry hueSlider;
|
private final ColorPickerHueSliderEntry hueSlider;
|
||||||
|
|
||||||
public GradientEditorSettingsSection(GradientEditorScreen editor, MinecraftClient client, int x, int y, int width, int height) {
|
public GradientEditorSettingsSection(GradientEditorScreen editor, Minecraft client, int x, int y, int width, int height) {
|
||||||
super(client, width, height, y, 110);
|
super(client, width, height, y, 110);
|
||||||
setX(x);
|
setX(x);
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
@@ -77,18 +75,18 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawMenuListBackground(DrawContext context) {
|
protected void extractListBackground(GuiGraphicsExtractor context) {
|
||||||
context.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), 0x20_00_00_00);
|
context.fill(getX(), getY(), getX()+getWidth(), getY()+getHeight(), 0x20_00_00_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void drawHeaderAndFooterSeparators(DrawContext context) {}
|
@Override protected void extractListSeparators(@NonNull GuiGraphicsExtractor context) {}
|
||||||
@Override protected void drawSelectionHighlight(DrawContext context, ListEntry entry, int color) {}
|
@Override protected void extractSelection(@NonNull GuiGraphicsExtractor context, @NonNull ListEntry entry, int color) {}
|
||||||
@Override protected void drawScrollbar(DrawContext context, int mouseX, int mouseY) {}
|
@Override protected void extractScrollbar(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY) {}
|
||||||
|
|
||||||
public abstract static class ListEntry extends Entry<ListEntry> {
|
public abstract static class ListEntry extends Entry<ListEntry> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getNarration() {
|
public @NonNull Component getNarration() {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,59 +109,59 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
|
|
||||||
private class HeadingEntry extends ListEntry {
|
private class HeadingEntry extends ListEntry {
|
||||||
|
|
||||||
private final Text text;
|
private final Component text;
|
||||||
|
|
||||||
private HeadingEntry(Text text) {
|
private HeadingEntry(Component text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
int y = this.getContentY() + 2;
|
int y = this.getContentY() + 2;
|
||||||
int rowWidth = 110;
|
int rowWidth = 110;
|
||||||
|
|
||||||
int textWidth = client.textRenderer.getWidth(text);
|
int textWidth = minecraft.font.width(text);
|
||||||
int textX = getX() + (rowWidth - textWidth) / 2;
|
int textX = getX() + (rowWidth - textWidth) / 2;
|
||||||
context.drawText(client.textRenderer, text, textX, y, 0xffffffff, true);
|
context.text(minecraft.font, text, textX, y, 0xffffffff, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SliderEntry extends ListEntry {
|
private class SliderEntry extends ListEntry {
|
||||||
|
|
||||||
private final SliderWidget slider;
|
private final AbstractSliderButton slider;
|
||||||
|
|
||||||
private SliderEntry(int min, int max, int initial, IntFunction<Text> textGetter, IntConsumer onUpdateValue) {
|
private SliderEntry(int min, int max, int initial, IntFunction<Component> textGetter, IntConsumer onUpdateValue) {
|
||||||
double value = (double) (initial - min) / (max - min);
|
double value = (double) (initial - min) / (max - min);
|
||||||
slider = new Slider(textGetter, value, onUpdateValue, min, max);
|
slider = new Slider(textGetter, value, onUpdateValue, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
slider.active = editor.colors.size() > 1;
|
slider.active = editor.colors.size() > 1;
|
||||||
slider.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
slider.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
slider.render(context, mouseX, mouseY, deltaTicks);
|
slider.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
if (hovered && !slider.active) {
|
if (hovered && !slider.active) {
|
||||||
context.setCursor(StandardCursors.NOT_ALLOWED);
|
context.requestCursor(CursorTypes.NOT_ALLOWED);
|
||||||
slider.setTooltip(Tooltip.of(translatable("widgets.ui.gradientEditor.gradientSettings.addMoreColors")));
|
slider.setTooltip(Tooltip.create(translatable("widgets.ui.gradientEditor.gradientSettings.addMoreColors")));
|
||||||
} else {
|
} else {
|
||||||
slider.setTooltip(null);
|
slider.setTooltip(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean mouseClicked(Click click, boolean doubled) { return slider.mouseClicked(click, doubled); }
|
@Override public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) { return slider.mouseClicked(click, doubled); }
|
||||||
@Override public boolean mouseDragged(Click click, double offsetX, double offsetY) { return slider.mouseDragged(click, offsetX, offsetY); }
|
@Override public boolean mouseDragged(@NonNull MouseButtonEvent click, double offsetX, double offsetY) { return slider.mouseDragged(click, offsetX, offsetY); }
|
||||||
@Override public boolean mouseReleased(Click click) { return slider.mouseReleased(click); }
|
@Override public boolean mouseReleased(@NonNull MouseButtonEvent click) { return slider.mouseReleased(click); }
|
||||||
@Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { return slider.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); }
|
@Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { return slider.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); }
|
||||||
@Override public void mouseMoved(double mouseX, double mouseY) { slider.mouseMoved(mouseX, mouseY); }
|
@Override public void mouseMoved(double mouseX, double mouseY) { slider.mouseMoved(mouseX, mouseY); }
|
||||||
|
|
||||||
private static class Slider extends SliderWidget {
|
private static class Slider extends AbstractSliderButton {
|
||||||
|
|
||||||
private final IntFunction<Text> textGetter;
|
private final IntFunction<Component> textGetter;
|
||||||
private final IntConsumer onUpdateValue;
|
private final IntConsumer onUpdateValue;
|
||||||
private final int min;
|
private final int min;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
||||||
public Slider(IntFunction<Text> textGetter, double value, IntConsumer onUpdateValue, int min, int max) {
|
public Slider(IntFunction<Component> textGetter, double value, IntConsumer onUpdateValue, int min, int max) {
|
||||||
super(0, 0, 0, 0, empty(), value);
|
super(0, 0, 0, 0, empty(), value);
|
||||||
this.textGetter = textGetter;
|
this.textGetter = textGetter;
|
||||||
this.onUpdateValue = onUpdateValue;
|
this.onUpdateValue = onUpdateValue;
|
||||||
@@ -191,13 +189,13 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
|
|
||||||
private class ToggleModeButtonEntry extends ListEntry {
|
private class ToggleModeButtonEntry extends ListEntry {
|
||||||
|
|
||||||
private final ButtonWidget button = new ButtonWidget.Builder(empty(), this::press).build();
|
private final Button button = new Button.Builder(empty(), this::press).build();
|
||||||
|
|
||||||
public ToggleModeButtonEntry() {
|
public ToggleModeButtonEntry() {
|
||||||
refreshButtonValues();
|
refreshButtonValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void press(ButtonWidget button) {
|
private void press(Button button) {
|
||||||
editor.cycleMode();
|
editor.cycleMode();
|
||||||
refreshButtonValues();
|
refreshButtonValues();
|
||||||
}
|
}
|
||||||
@@ -205,34 +203,34 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
private void refreshButtonValues() {
|
private void refreshButtonValues() {
|
||||||
button.setMessage(translatable("widgets.ui.gradientEditor.mode", editor.mode.name));
|
button.setMessage(translatable("widgets.ui.gradientEditor.mode", editor.mode.name));
|
||||||
if (editor.colors.size() > 1){
|
if (editor.colors.size() > 1){
|
||||||
button.setTooltip(Tooltip.of(editor.mode.description));
|
button.setTooltip(Tooltip.create(editor.mode.description));
|
||||||
} else {
|
} else {
|
||||||
button.setTooltip(Tooltip.of(translatable("widgets.ui.gradientEditor.gradientSettings.addMoreColors")));
|
button.setTooltip(Tooltip.create(translatable("widgets.ui.gradientEditor.gradientSettings.addMoreColors")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
button.active = editor.colors.size() > 1;
|
button.active = editor.colors.size() > 1;
|
||||||
button.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
button.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
button.render(context, mouseX, mouseY, deltaTicks);
|
button.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return button.mouseClicked(click, doubled);
|
return button.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ImportButtonEntry extends ListEntry {
|
private class ImportButtonEntry extends ListEntry {
|
||||||
|
|
||||||
private final ButtonWidget button = new ButtonWidget.Builder(translatable("widgets.ui.gradientEditor.importOther"), this::press).build();
|
private final Button button = new Button.Builder(translatable("widgets.ui.gradientEditor.importOther"), this::press).build();
|
||||||
|
|
||||||
private void press(ButtonWidget button) {
|
private void press(Button button) {
|
||||||
Screen currentScreen = client.currentScreen;
|
Screen currentScreen = minecraft.screen;
|
||||||
int menuX = (int) client.mouse.getScaledX(client.getWindow());
|
int menuX = (int) minecraft.mouseHandler.getScaledXPos(minecraft.getWindow());
|
||||||
int menuY = (int) client.mouse.getScaledY(client.getWindow());
|
int menuY = (int) minecraft.mouseHandler.getScaledYPos(minecraft.getWindow());
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
button.getMessage(),
|
button.getMessage(),
|
||||||
currentScreen,
|
currentScreen,
|
||||||
menuX, menuY,
|
menuX, menuY,
|
||||||
@@ -240,7 +238,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
.stream()
|
.stream()
|
||||||
.map(widget -> new ContextMenuScreen.Option(
|
.map(widget -> new ContextMenuScreen.Option(
|
||||||
widget.getName(),
|
widget.getName(),
|
||||||
() -> client.setScreen(new ContextMenuScreen(
|
() -> minecraft.setScreen(new ContextMenuScreen(
|
||||||
widget.getName(),
|
widget.getName(),
|
||||||
currentScreen,
|
currentScreen,
|
||||||
menuX,
|
menuX,
|
||||||
@@ -258,26 +256,26 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
button.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
button.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
button.render(context, mouseX, mouseY, deltaTicks);
|
button.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return button.mouseClicked(click, doubled);
|
return button.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UsePresetButtonEntry extends ListEntry {
|
private class UsePresetButtonEntry extends ListEntry {
|
||||||
|
|
||||||
private final ButtonWidget button = new ButtonWidget.Builder(translatable("widgets.ui.gradientEditor.usePreset"), this::press).build();
|
private final Button button = new Button.Builder(translatable("widgets.ui.gradientEditor.usePreset"), this::press).build();
|
||||||
|
|
||||||
private void press(ButtonWidget button) {
|
private void press(Button button) {
|
||||||
Screen currentScreen = client.currentScreen;
|
Screen currentScreen = minecraft.screen;
|
||||||
int menuX = (int) client.mouse.getScaledX(client.getWindow());
|
int menuX = (int) minecraft.mouseHandler.getScaledXPos(minecraft.getWindow());
|
||||||
int menuY = (int) client.mouse.getScaledY(client.getWindow());
|
int menuY = (int) minecraft.mouseHandler.getScaledYPos(minecraft.getWindow());
|
||||||
client.setScreen(new ContextMenuScreen(
|
minecraft.setScreen(new ContextMenuScreen(
|
||||||
translatable("widgets.ui.gradientEditor.usePreset"),
|
translatable("widgets.ui.gradientEditor.usePreset"),
|
||||||
currentScreen,
|
currentScreen,
|
||||||
menuX, menuY,
|
menuX, menuY,
|
||||||
@@ -289,13 +287,13 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
button.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
button.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
button.render(context, mouseX, mouseY, deltaTicks);
|
button.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return button.mouseClicked(click, doubled);
|
return button.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +314,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
double sliderProg = getComponentValue() / 255d;
|
double sliderProg = getComponentValue() / 255d;
|
||||||
|
|
||||||
GradientOptions bg = new GradientOptions(100, 0, new int[]{getBackgroundStartColor(), getBackgroundEndColor()});
|
GradientOptions bg = new GradientOptions(100, 0, new int[]{getBackgroundStartColor(), getBackgroundEndColor()});
|
||||||
@@ -327,14 +325,14 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
|
|
||||||
bg.fillHorizontal(context, 0, contentX, contentY + 1, contentX + contentWidth, contentY + contentHeight - 1);
|
bg.fillHorizontal(context, 0, contentX, contentY + 1, contentX + contentWidth, contentY + contentHeight - 1);
|
||||||
|
|
||||||
context.drawVerticalLine((int) (contentX + (contentWidth * sliderProg)), contentY - 1, contentY + contentHeight, 0xff_ff_ff_ff);
|
context.verticalLine((int) (contentX + (contentWidth * sliderProg)), contentY - 1, contentY + contentHeight, 0xff_ff_ff_ff);
|
||||||
if (showLabel){
|
if (showLabel){
|
||||||
String label = getLabelWithValue();
|
String label = getLabelWithValue();
|
||||||
int w = client.textRenderer.getWidth(label);
|
int w = minecraft.font.width(label);
|
||||||
context.drawText(client.textRenderer, label, contentX + (contentWidth - w) / 2, contentY + 5, 0xffffffff, true);
|
context.text(minecraft.font, label, contentX + (contentWidth - w) / 2, contentY + 5, 0xffffffff, true);
|
||||||
}
|
}
|
||||||
if (hovered){
|
if (hovered){
|
||||||
context.setCursor(StandardCursors.RESIZE_EW);
|
context.requestCursor(CursorTypes.RESIZE_EW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +348,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
public boolean mouseDragged(MouseButtonEvent click, double offsetX, double offsetY) {
|
||||||
double mouseX = click.x();
|
double mouseX = click.x();
|
||||||
int newComponentValue = (int) ((mouseX - getContentX()) / getContentWidth() * 255);
|
int newComponentValue = (int) ((mouseX - getContentX()) / getContentWidth() * 255);
|
||||||
setComponentValue(newComponentValue);
|
setComponentValue(newComponentValue);
|
||||||
@@ -358,12 +356,12 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return mouseDragged(click, 0, 0);
|
return mouseDragged(click, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(KeyInput input) {
|
public boolean keyPressed(KeyEvent input) {
|
||||||
if (input.isLeft()) {
|
if (input.isLeft()) {
|
||||||
setComponentValue(getComponentValue() - 1);
|
setComponentValue(getComponentValue() - 1);
|
||||||
} else if (input.isRight()) {
|
} else if (input.isRight()) {
|
||||||
@@ -373,7 +371,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setComponentValue(int val) {
|
private void setComponentValue(int val) {
|
||||||
val = MathHelper.clamp(val, 0, 255);
|
val = Mth.clamp(val, 0, 255);
|
||||||
final int currentColor = editor.getCurrentColor();
|
final int currentColor = editor.getCurrentColor();
|
||||||
int newColor = switch (component){
|
int newColor = switch (component){
|
||||||
case 0 -> (currentColor & 0xff_00_ff_ff) | val << 16;
|
case 0 -> (currentColor & 0xff_00_ff_ff) | val << 16;
|
||||||
@@ -420,29 +418,29 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
|
|
||||||
private class RemoveColorButtonEntry extends ListEntry {
|
private class RemoveColorButtonEntry extends ListEntry {
|
||||||
|
|
||||||
private final ButtonWidget button = new ButtonWidget.Builder(translatable("widgets.ui.gradientEditor.removeColor"), this::press).build();
|
private final Button button = new Button.Builder(translatable("widgets.ui.gradientEditor.removeColor"), this::press).build();
|
||||||
|
|
||||||
private void press(ButtonWidget button) {
|
private void press(Button button) {
|
||||||
button.active = false;
|
button.active = false;
|
||||||
editor.removeCurrentColor();
|
editor.removeCurrentColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
button.active = editor.colors.size() > 1;
|
button.active = editor.colors.size() > 1;
|
||||||
button.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
button.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
button.render(context, mouseX, mouseY, deltaTicks);
|
button.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return button.mouseClicked(click, doubled);
|
return button.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HexValueInputEntry extends ListEntry {
|
private class HexValueInputEntry extends ListEntry {
|
||||||
|
|
||||||
private final TextFieldWidget inputField = new TextFieldWidget(client.textRenderer, 0, 0, empty());
|
private final EditBox inputField = new EditBox(minecraft.font, 0, 0, empty());
|
||||||
|
|
||||||
public HexValueInputEntry() {
|
public HexValueInputEntry() {
|
||||||
this.refreshText();
|
this.refreshText();
|
||||||
@@ -470,21 +468,21 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputField.setEditableColor(valid ? 0xffffffff : 0xffff0000);
|
inputField.setTextColor(valid ? 0xffffffff : 0xffff0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
inputField.setDimensionsAndPosition(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
inputField.setRectangle(getContentWidth(), getContentHeight(), getContentX(), getContentY());
|
||||||
inputField.render(context, mouseX, mouseY, deltaTicks);
|
inputField.extractRenderState(context, mouseX, mouseY, deltaTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshText(){
|
public void refreshText(){
|
||||||
inputField.setChangedListener(null);
|
inputField.setResponder(_ -> {});
|
||||||
inputField.setText('#' + colorARGBToHexRGBA(editor.getCurrentColor()));
|
inputField.setValue('#' + colorARGBToHexRGBA(editor.getCurrentColor()));
|
||||||
inputField.setCursorToStart(false);
|
inputField.moveCursorToStart(false);
|
||||||
inputField.setEditableColor(0xffffffff);
|
inputField.setTextColor(0xffffffff);
|
||||||
inputField.setChangedListener(this::onChangeInputField);
|
inputField.setResponder(this::onChangeInputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -492,20 +490,20 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
inputField.setFocused(focused);
|
inputField.setFocused(focused);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean mouseClicked(Click click, boolean doubled) { return inputField.mouseClicked(click, doubled); }
|
@Override public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) { return inputField.mouseClicked(click, doubled); }
|
||||||
@Override public boolean mouseDragged(Click click, double offsetX, double offsetY) { return inputField.mouseDragged(click, offsetX, offsetY); }
|
@Override public boolean mouseDragged(@NonNull MouseButtonEvent click, double offsetX, double offsetY) { return inputField.mouseDragged(click, offsetX, offsetY); }
|
||||||
@Override public boolean mouseReleased(Click click) { return inputField.mouseReleased(click); }
|
@Override public boolean mouseReleased(@NonNull MouseButtonEvent click) { return inputField.mouseReleased(click); }
|
||||||
@Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { return inputField.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); }
|
@Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { return inputField.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); }
|
||||||
@Override public void mouseMoved(double mouseX, double mouseY) { inputField.mouseMoved(mouseX, mouseY); }
|
@Override public void mouseMoved(double mouseX, double mouseY) { inputField.mouseMoved(mouseX, mouseY); }
|
||||||
@Override public boolean charTyped(CharInput input) { return inputField.charTyped(input); }
|
@Override public boolean charTyped(@NonNull CharacterEvent input) { return inputField.charTyped(input); }
|
||||||
@Override public boolean keyReleased(KeyInput input) { return inputField.keyReleased(input); }
|
@Override public boolean keyReleased(@NonNull KeyEvent input) { return inputField.keyReleased(input); }
|
||||||
@Override public boolean keyPressed(KeyInput input) { return inputField.keyPressed(input); }
|
@Override public boolean keyPressed(@NonNull KeyEvent input) { return inputField.keyPressed(input); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ColorPickerEntry extends ListEntry {
|
private class ColorPickerEntry extends ListEntry {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
context.fill(
|
context.fill(
|
||||||
getContentX(),
|
getContentX(),
|
||||||
getContentY(),
|
getContentY(),
|
||||||
@@ -513,7 +511,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
getContentY() + getContentHeight(),
|
getContentY() + getContentHeight(),
|
||||||
getBackgroundFillColor()
|
getBackgroundFillColor()
|
||||||
);
|
);
|
||||||
context.drawTexture(
|
context.blit(
|
||||||
RenderPipelines.GUI_TEXTURED,
|
RenderPipelines.GUI_TEXTURED,
|
||||||
getOverlayTextureIdentifier(),
|
getOverlayTextureIdentifier(),
|
||||||
getContentX(), getContentY(),
|
getContentX(), getContentY(),
|
||||||
@@ -537,12 +535,12 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (hovered){
|
if (hovered){
|
||||||
context.setCursor(StandardCursors.ARROW);
|
context.requestCursor(CursorTypes.ARROW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
public boolean mouseDragged(MouseButtonEvent click, double offsetX, double offsetY) {
|
||||||
double x = click.x() - getContentX();
|
double x = click.x() - getContentX();
|
||||||
double y = click.y() - getContentY();
|
double y = click.y() - getContentY();
|
||||||
float saturation = (float) Math.clamp(x / getContentWidth(), 0d, 1d);
|
float saturation = (float) Math.clamp(x / getContentWidth(), 0d, 1d);
|
||||||
@@ -556,7 +554,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return mouseDragged(click, 0, 0);
|
return mouseDragged(click, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,16 +566,16 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
|
|
||||||
public Identifier getOverlayTextureIdentifier(){
|
public Identifier getOverlayTextureIdentifier(){
|
||||||
if (OVERLAY_TEXTURE_ID == null){
|
if (OVERLAY_TEXTURE_ID == null){
|
||||||
NativeImageBackedTexture texture = generateOverlayTexture();
|
DynamicTexture texture = generateOverlayTexture();
|
||||||
OVERLAY_TEXTURE_ID = Identifier.of(WidgetsMod.MOD_ID, "textures/gui/generated/color-picker-overlay");
|
OVERLAY_TEXTURE_ID = Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "textures/gui/generated/color-picker-overlay");
|
||||||
client.getTextureManager().registerTexture(OVERLAY_TEXTURE_ID, texture);
|
minecraft.getTextureManager().register(OVERLAY_TEXTURE_ID, texture);
|
||||||
}
|
}
|
||||||
return OVERLAY_TEXTURE_ID;
|
return OVERLAY_TEXTURE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NativeImageBackedTexture generateOverlayTexture() {
|
private DynamicTexture generateOverlayTexture() {
|
||||||
NativeImageBackedTexture texture = new NativeImageBackedTexture("widgets:textures/gui/generated/color-picker-overlay", 256, 256, false);
|
DynamicTexture texture = new DynamicTexture("widgets:textures/gui/generated/color-picker-overlay", 256, 256, false);
|
||||||
NativeImage image = texture.getImage();
|
NativeImage image = texture.getPixels();
|
||||||
|
|
||||||
for (int x = 0; x < 256; x++) {
|
for (int x = 0; x < 256; x++) {
|
||||||
for (int y = 0; y < 256; y++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
@@ -588,7 +586,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
int rgb = (int) Math.round(outAlpha > 0 ? (255d * alphaWhite * (1d - alphaBlack)) / outAlpha : 0);
|
int rgb = (int) Math.round(outAlpha > 0 ? (255d * alphaWhite * (1d - alphaBlack)) / outAlpha : 0);
|
||||||
int a = (int) Math.round(outAlpha * 255.0);
|
int a = (int) Math.round(outAlpha * 255.0);
|
||||||
|
|
||||||
image.setColorArgb(x, y, new Color(rgb, rgb, rgb, a).getRGB());
|
image.setPixel(x, y, new Color(rgb, rgb, rgb, a).getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,17 +610,17 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
public void extractContent(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) {
|
||||||
sliderGradient.fillHorizontal(context, 0, getContentX(), getContentY() + 1, getContentX() + getContentWidth(), getContentY() + getContentHeight() - 1);
|
sliderGradient.fillHorizontal(context, 0, getContentX(), getContentY() + 1, getContentX() + getContentWidth(), getContentY() + getContentHeight() - 1);
|
||||||
context.drawVerticalLine((int) (getContentX() + (getContentWidth() * sliderProgress)), getContentY() - 1, getContentY() + getContentHeight(), 0xff_ff_ff_ff);
|
context.verticalLine( (int) (getContentX() + (getContentWidth() * sliderProgress)), getContentY() - 1, getContentY() + getContentHeight(), 0xff_ff_ff_ff);
|
||||||
|
|
||||||
if (hovered){
|
if (hovered){
|
||||||
context.setCursor(StandardCursors.RESIZE_EW);
|
context.requestCursor(CursorTypes.RESIZE_EW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
public boolean mouseDragged(MouseButtonEvent click, double offsetX, double offsetY) {
|
||||||
double x = click.x() - getContentX();
|
double x = click.x() - getContentX();
|
||||||
float newHue = (float) Math.clamp(x / getContentWidth(), 0, 1);
|
float newHue = (float) Math.clamp(x / getContentWidth(), 0, 1);
|
||||||
this.sliderProgress = newHue;
|
this.sliderProgress = newHue;
|
||||||
@@ -639,7 +637,7 @@ public class GradientEditorSettingsSection extends AlwaysSelectedEntryListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(@NonNull MouseButtonEvent click, boolean doubled) {
|
||||||
return this.mouseDragged(click, 0, 0);
|
return this.mouseDragged(click, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package de.shiewk.widgets.color;
|
package de.shiewk.widgets.color;
|
||||||
|
|
||||||
import net.minecraft.text.Text;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
public enum GradientMode {
|
public enum GradientMode {
|
||||||
SWEEP(translatable("widgets.gradient.sweep"), translatable("widgets.gradient.sweep.description")),
|
SWEEP(translatable("widgets.gradient.sweep"), translatable("widgets.gradient.sweep.description")),
|
||||||
PULSE(translatable("widgets.gradient.pulse"), translatable("widgets.gradient.pulse.description"));
|
PULSE(translatable("widgets.gradient.pulse"), translatable("widgets.gradient.pulse.description"));
|
||||||
|
|
||||||
public final Text name;
|
public final Component name;
|
||||||
public final Text description;
|
public final Component description;
|
||||||
|
|
||||||
GradientMode(Text name, Text description) {
|
GradientMode(Component name, Component description) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package de.shiewk.widgets.color;
|
package de.shiewk.widgets.color;
|
||||||
|
|
||||||
import de.shiewk.widgets.render.state.HorizontalGradientGuiRenderState;
|
import de.shiewk.widgets.render.state.HorizontalGradientGuiRenderState;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -23,7 +23,7 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
this(GradientMode.SWEEP, gradientSize, gradientSpeed, colors);
|
this(GradientMode.SWEEP, gradientSize, gradientSpeed, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillHorizontal(DrawContext context, long timeNanos, int x, int y, int endX, int endY) {
|
public void fillHorizontal(GuiGraphicsExtractor context, long timeNanos, int x, int y, int endX, int endY) {
|
||||||
if (colors.length == 1) {
|
if (colors.length == 1) {
|
||||||
context.fill(x, y, endX, endY, colors[0]);
|
context.fill(x, y, endX, endY, colors[0]);
|
||||||
return;
|
return;
|
||||||
@@ -34,7 +34,7 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillHorizonalSweep(DrawContext context, long timeNanos, int x, int y, int endX, int endY) {
|
private void fillHorizonalSweep(GuiGraphicsExtractor context, long timeNanos, int x, int y, int endX, int endY) {
|
||||||
context.enableScissor(x, y, endX, endY);
|
context.enableScissor(x, y, endX, endY);
|
||||||
|
|
||||||
int width = endX - x;
|
int width = endX - x;
|
||||||
@@ -47,7 +47,7 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
float timeSeconds = timeNanos / 1_000_000_000f;
|
float timeSeconds = timeNanos / 1_000_000_000f;
|
||||||
float offset = gradientSpeed == 0 ? 0 : (timeSeconds * speedPxPerSec + x) % totalGradientCycle;
|
float offset = gradientSpeed == 0 ? 0 : (timeSeconds * speedPxPerSec + x) % totalGradientCycle;
|
||||||
|
|
||||||
Matrix3x2fStack matrices = context.getMatrices().pushMatrix();
|
Matrix3x2fStack matrices = context.pose().pushMatrix();
|
||||||
matrices.translate(-offset, 0);
|
matrices.translate(-offset, 0);
|
||||||
|
|
||||||
int currentPos = 0;
|
int currentPos = 0;
|
||||||
@@ -70,7 +70,7 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
context.disableScissor();
|
context.disableScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillHorizonalPulse(DrawContext context, long timeNanos, int x, int y, int endX, int endY) {
|
private void fillHorizonalPulse(GuiGraphicsExtractor context, long timeNanos, int x, int y, int endX, int endY) {
|
||||||
context.fill(x, y, endX, endY, getCurrentPulseColor(timeNanos));
|
context.fill(x, y, endX, endY, getCurrentPulseColor(timeNanos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,13 +82,13 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
return fadeColor(color1, color2, delta);
|
return fadeColor(color1, color2, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawHorizontalLine(DrawContext context, long mt, int posX, int endX, int posY) {
|
public void drawHorizontalLine(GuiGraphicsExtractor context, long mt, int posX, int endX, int posY) {
|
||||||
this.fillHorizontal(context, mt, posX, posY, endX, posY + 1);
|
this.fillHorizontal(context, mt, posX, posY, endX, posY + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawText(DrawContext context, TextRenderer textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
public void drawText(GuiGraphicsExtractor context, Font textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
||||||
if (colors.length == 1){
|
if (colors.length == 1){
|
||||||
context.drawText(textRenderer, displayText, x, y, colors[0], shadow);
|
context.text(textRenderer, displayText, x, y, colors[0], shadow);
|
||||||
} else {
|
} else {
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case SWEEP -> drawTextSweep(context, textRenderer, timeNanos, displayText, x, y, shadow);
|
case SWEEP -> drawTextSweep(context, textRenderer, timeNanos, displayText, x, y, shadow);
|
||||||
@@ -97,20 +97,20 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawText(DrawContext context, TextRenderer textRenderer, long timeNanos, Text displayText, int x, int y, boolean shadow) {
|
public void drawText(GuiGraphicsExtractor context, Font textRenderer, long timeNanos, Component displayText, int x, int y, boolean shadow) {
|
||||||
if (colors.length == 1){
|
if (colors.length == 1){
|
||||||
context.drawText(textRenderer, displayText, x, y, colors[0], shadow);
|
context.text(textRenderer, displayText, x, y, colors[0], shadow);
|
||||||
}
|
}
|
||||||
this.drawText(context, textRenderer, timeNanos, displayText.getString(), x, y, shadow);
|
this.drawText(context, textRenderer, timeNanos, displayText.getString(), x, y, shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTextSweep(DrawContext context, TextRenderer textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
private void drawTextSweep(GuiGraphicsExtractor context, Font textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 0; i < displayText.length(); i++) {
|
for (int i = 0; i < displayText.length(); i++) {
|
||||||
String s = String.valueOf(displayText.charAt(i));
|
String s = String.valueOf(displayText.charAt(i));
|
||||||
int w = textRenderer.getWidth(s);
|
int w = textRenderer.width(s);
|
||||||
int col = computeSweepTextColorAt(gradientSpeed == 0 ? pos : pos + x, timeNanos);
|
int col = computeSweepTextColorAt(gradientSpeed == 0 ? pos : pos + x, timeNanos);
|
||||||
context.drawText(textRenderer, s, x +pos, y, col, shadow);
|
context.text(textRenderer, s, x +pos, y, col, shadow);
|
||||||
pos += w;
|
pos += w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,15 +128,15 @@ public record GradientOptions(GradientMode mode, float gradientSize, float gradi
|
|||||||
return fadeColor(color1, color2, off);
|
return fadeColor(color1, color2, off);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTextPulse(DrawContext context, TextRenderer textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
private void drawTextPulse(GuiGraphicsExtractor context, Font textRenderer, long timeNanos, String displayText, int x, int y, boolean shadow) {
|
||||||
context.drawText(textRenderer, displayText, x, y, getCurrentPulseColor(timeNanos), shadow);
|
context.text(textRenderer, displayText, x, y, getCurrentPulseColor(timeNanos), shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GradientOptions solidColor(int color) {
|
public static GradientOptions solidColor(int color) {
|
||||||
return new GradientOptions(1, 0, new int[]{color});
|
return new GradientOptions(1, 0, new int[]{color});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawVerticalLine(DrawContext context, long timeNanos, int posX, int posY, int endY) {
|
public void drawVerticalLine(GuiGraphicsExtractor context, long timeNanos, int posX, int posY, int endY) {
|
||||||
fillHorizontal(context, timeNanos, posX, posY, posX + 1, endY);
|
fillHorizontal(context, timeNanos, posX, posY, posX + 1, endY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package de.shiewk.widgets.color;
|
package de.shiewk.widgets.color;
|
||||||
|
|
||||||
import net.minecraft.text.Text;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
public record GradientPreset(Text name, GradientOptions gradient) {
|
public record GradientPreset(Component name, GradientOptions gradient) {
|
||||||
|
|
||||||
public static final GradientPreset[] presets = new GradientPreset[]{
|
public static final GradientPreset[] presets = new GradientPreset[]{
|
||||||
new GradientPreset(
|
new GradientPreset(
|
||||||
|
|||||||
@@ -2,41 +2,41 @@ package de.shiewk.widgets.mixin;
|
|||||||
|
|
||||||
import de.shiewk.widgets.widgets.ComboWidget;
|
import de.shiewk.widgets.widgets.ComboWidget;
|
||||||
import de.shiewk.widgets.widgets.TPSWidget;
|
import de.shiewk.widgets.widgets.TPSWidget;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.network.packet.s2c.play.DamageTiltS2CPacket;
|
import net.minecraft.network.protocol.game.ClientboundDamageEventPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.EntityDamageS2CPacket;
|
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.WorldTimeUpdateS2CPacket;
|
import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(ClientPlayNetworkHandler.class)
|
@Mixin(ClientPacketListener.class)
|
||||||
public class MixinClientPlayNetworkHandler {
|
public class MixinClientPlayNetworkHandler {
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "onWorldTimeUpdate")
|
@Inject(at = @At("HEAD"), method = "handleSetTime")
|
||||||
public void onWorldTimeUpdate(WorldTimeUpdateS2CPacket packet, CallbackInfo ci){
|
public void onWorldTimeUpdate(ClientboundSetTimePacket packet, CallbackInfo ci){
|
||||||
if (MinecraftClient.getInstance().isOnThread()) return; // run this on the networking thread as soon as possible
|
if (Minecraft.getInstance().isSameThread()) return; // run this on the networking thread as soon as possible
|
||||||
// server sends this packet every 20 ticks
|
// server sends this packet every 20 ticks
|
||||||
TPSWidget.worldTimeUpdated(System.nanoTime());
|
TPSWidget.worldTimeUpdated(System.nanoTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "onDamageTilt")
|
@Inject(at = @At("HEAD"), method = "handleHurtAnimation")
|
||||||
public void onDamageTilt(DamageTiltS2CPacket packet, CallbackInfo ci){
|
public void onDamageTilt(ClientboundHurtAnimationPacket packet, CallbackInfo ci){
|
||||||
if (MinecraftClient.getInstance().isOnThread()) return;
|
if (Minecraft.getInstance().isSameThread()) return;
|
||||||
int entityId = packet.id();
|
int entityId = packet.id();
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
int playerId = player == null ? Integer.MIN_VALUE : player.getId();
|
int playerId = player == null ? Integer.MIN_VALUE : player.getId();
|
||||||
ComboWidget.entityTakeDamage(playerId, entityId);
|
ComboWidget.entityTakeDamage(playerId, entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "onEntityDamage")
|
@Inject(at = @At("HEAD"), method = "handleDamageEvent")
|
||||||
public void onEntityDamage(EntityDamageS2CPacket packet, CallbackInfo ci){
|
public void onEntityDamage(ClientboundDamageEventPacket packet, CallbackInfo ci){
|
||||||
if (MinecraftClient.getInstance().isOnThread()) return;
|
if (Minecraft.getInstance().isSameThread()) return;
|
||||||
int entityId = packet.entityId();
|
int entityId = packet.entityId();
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
int playerId = player == null ? Integer.MIN_VALUE : player.getId();
|
int playerId = player == null ? Integer.MIN_VALUE : player.getId();
|
||||||
ComboWidget.entityTakeDamage(playerId, entityId);
|
ComboWidget.entityTakeDamage(playerId, entityId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,29 @@
|
|||||||
package de.shiewk.widgets.mixin;
|
package de.shiewk.widgets.mixin;
|
||||||
|
|
||||||
import de.shiewk.widgets.widgets.CPSWidget;
|
import de.shiewk.widgets.widgets.CPSWidget;
|
||||||
import net.minecraft.client.Mouse;
|
import net.minecraft.client.MouseHandler;
|
||||||
import net.minecraft.client.input.MouseInput;
|
import net.minecraft.client.input.MouseButtonInfo;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(Mouse.class)
|
@Mixin(MouseHandler.class)
|
||||||
public class MixinMouse {
|
public class MixinMouse {
|
||||||
|
|
||||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;leftButtonClicked:Z"), method = "onMouseButton")
|
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MouseHandler;isLeftPressed:Z", opcode = Opcodes.PUTFIELD), method = "onButton")
|
||||||
public void onLeftClick(long window, MouseInput input, int action, CallbackInfo ci){
|
public void onLeftClick(long handle, MouseButtonInfo rawButtonInfo, int action, CallbackInfo ci){
|
||||||
if (action == 1) CPSWidget.clickLeft();
|
if (action == 1) CPSWidget.clickLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;middleButtonClicked:Z"), method = "onMouseButton")
|
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MouseHandler;isMiddlePressed:Z", opcode = Opcodes.PUTFIELD), method = "onButton")
|
||||||
public void onMiddleClick(long window, MouseInput input, int action, CallbackInfo ci){
|
public void onMiddleClick(long handle, MouseButtonInfo rawButtonInfo, int action, CallbackInfo ci){
|
||||||
if (action == 1) CPSWidget.clickMiddle();
|
if (action == 1) CPSWidget.clickMiddle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;rightButtonClicked:Z"), method = "onMouseButton")
|
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/MouseHandler;isRightPressed:Z", opcode = Opcodes.PUTFIELD), method = "onButton")
|
||||||
public void onRightClick(long window, MouseInput input, int action, CallbackInfo ci){
|
public void onRightClick(long handle, MouseButtonInfo rawButtonInfo, int action, CallbackInfo ci){
|
||||||
if (action == 1) CPSWidget.clickRight();
|
if (action == 1) CPSWidget.clickRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-26
@@ -1,25 +1,26 @@
|
|||||||
package de.shiewk.widgets.render.state;
|
package de.shiewk.widgets.render.state;
|
||||||
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.gl.RenderPipelines;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.navigation.ScreenRectangle;
|
||||||
import net.minecraft.client.gui.ScreenRect;
|
import net.minecraft.client.gui.render.TextureSetup;
|
||||||
import net.minecraft.client.gui.render.state.SimpleGuiElementRenderState;
|
import net.minecraft.client.renderer.state.gui.GuiElementRenderState;
|
||||||
import net.minecraft.client.render.VertexConsumer;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
import net.minecraft.client.texture.TextureSetup;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Matrix3x2f;
|
import org.joml.Matrix3x2f;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public final class HorizontalGradientGuiRenderState implements SimpleGuiElementRenderState {
|
public final class HorizontalGradientGuiRenderState implements GuiElementRenderState {
|
||||||
|
|
||||||
private final RenderPipeline pipeline;
|
private final RenderPipeline pipeline;
|
||||||
private final TextureSetup textureSetup;
|
private final TextureSetup textureSetup;
|
||||||
private final Matrix3x2f pose;
|
private final Matrix3x2f pose;
|
||||||
private final ScreenRect scissorArea;
|
private final ScreenRectangle scissorArea;
|
||||||
private final ScreenRect bounds;
|
private final ScreenRectangle bounds;
|
||||||
|
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
@@ -34,7 +35,7 @@ public final class HorizontalGradientGuiRenderState implements SimpleGuiElementR
|
|||||||
RenderPipeline pipeline,
|
RenderPipeline pipeline,
|
||||||
TextureSetup textureSetup,
|
TextureSetup textureSetup,
|
||||||
Matrix3x2f pose,
|
Matrix3x2f pose,
|
||||||
ScreenRect scissorArea,
|
ScreenRectangle scissorArea,
|
||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int endX,
|
int endX,
|
||||||
@@ -54,46 +55,46 @@ public final class HorizontalGradientGuiRenderState implements SimpleGuiElementR
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupVertices(VertexConsumer vertices) {
|
public void buildVertices(VertexConsumer vertices) {
|
||||||
vertices.vertex(pose, x, y).color(colorLeft);
|
vertices.addVertexWith2DPose(pose, x, y).setColor(colorLeft);
|
||||||
vertices.vertex(pose, x, endY).color(colorLeft);
|
vertices.addVertexWith2DPose(pose, x, endY).setColor(colorLeft);
|
||||||
vertices.vertex(pose, endX, endY).color(colorRight);
|
vertices.addVertexWith2DPose(pose, endX, endY).setColor(colorRight);
|
||||||
vertices.vertex(pose, endX, y).color(colorRight);
|
vertices.addVertexWith2DPose(pose, endX, y).setColor(colorRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderPipeline pipeline() {
|
public @NonNull RenderPipeline pipeline() {
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureSetup textureSetup() {
|
public @NonNull TextureSetup textureSetup() {
|
||||||
return textureSetup;
|
return textureSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ScreenRect scissorArea() {
|
public @Nullable ScreenRectangle scissorArea() {
|
||||||
return scissorArea;
|
return scissorArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static ScreenRect createBounds(int x0, int y0, int x1, int y1, Matrix3x2f pose, @Nullable ScreenRect scissorArea) {
|
private static ScreenRectangle createBounds(int x0, int y0, int x1, int y1, Matrix3x2f pose, @Nullable ScreenRectangle scissorArea) {
|
||||||
ScreenRect screenRect = (new ScreenRect(x0, y0, x1 - x0 + 1, y1 - y0)).transformEachVertex(pose);
|
ScreenRectangle screenRect = (new ScreenRectangle(x0, y0, x1 - x0 + 1, y1 - y0)).transformMaxBounds(pose);
|
||||||
return scissorArea != null ? scissorArea.intersection(screenRect) : screenRect;
|
return scissorArea != null ? scissorArea.intersection(screenRect) : screenRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ScreenRect bounds() {
|
public @Nullable ScreenRectangle bounds() {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void draw(DrawContext context, int x, int y, int endX, int endY, int colorLeft, int colorRight) {
|
public static void draw(GuiGraphicsExtractor context, int x, int y, int endX, int endY, int colorLeft, int colorRight) {
|
||||||
context.state.addSimpleElement(
|
context.guiRenderState.addGuiElement(
|
||||||
new HorizontalGradientGuiRenderState(
|
new HorizontalGradientGuiRenderState(
|
||||||
RenderPipelines.GUI,
|
RenderPipelines.GUI,
|
||||||
TextureSetup.empty(),
|
TextureSetup.noTexture(),
|
||||||
new Matrix3x2f(context.getMatrices()),
|
new Matrix3x2f(context.pose()),
|
||||||
context.scissorStack.peekLast(),
|
context.scissorStack.peek(),
|
||||||
x, y, endX, endY,
|
x, y, endX, endY,
|
||||||
colorLeft, colorRight
|
colorLeft, colorRight
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package de.shiewk.widgets.utils;
|
package de.shiewk.widgets.utils;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
|
||||||
import net.minecraft.sound.SoundEvent;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.world.tick.TickManager;
|
|
||||||
|
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.TickRateManager;
|
||||||
|
|
||||||
public class WidgetUtils {
|
public class WidgetUtils {
|
||||||
|
|
||||||
@@ -17,30 +16,30 @@ public class WidgetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInSingleplayer(){
|
public static boolean isInSingleplayer(){
|
||||||
return MinecraftClient.getInstance().isInSingleplayer();
|
return Minecraft.getInstance().isLocalServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getClientTickRate(){
|
public static float getClientTickRate(){
|
||||||
float tickRate = 20f;
|
float tickRate = 20f;
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
Minecraft client = Minecraft.getInstance();
|
||||||
if (client.world != null) {
|
if (client.level != null) {
|
||||||
TickManager tickManager = client.world.getTickManager();
|
TickRateManager tickManager = client.level.tickRateManager();
|
||||||
if (!tickManager.isFrozen()){
|
if (!tickManager.isFrozen()){
|
||||||
tickRate = Math.min(tickManager.getTickRate(), 20);
|
tickRate = Math.min(tickManager.tickrate(), 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tickRate;
|
return tickRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playSound(SoundEvent ev){
|
public static void playSound(SoundEvent ev){
|
||||||
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.ui(ev, 1f, 1f));
|
Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(ev, 1f, 1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int fadeColor(int color1, int color2, double delta) {
|
public static int fadeColor(int color1, int color2, double delta) {
|
||||||
int alpha = (int) MathHelper.lerp(delta, (color1 >> 24) & 0xff, (color2 >> 24) & 0xff);
|
int alpha = (int) Mth.lerp(delta, (color1 >> 24) & 0xff, (color2 >> 24) & 0xff);
|
||||||
int red = (int) MathHelper.lerp(delta, (color1 >> 16) & 0xff, (color2 >> 16) & 0xff);
|
int red = (int) Mth.lerp(delta, (color1 >> 16) & 0xff, (color2 >> 16) & 0xff);
|
||||||
int green = (int) MathHelper.lerp(delta, (color1 >> 8) & 0xff, (color2 >> 8) & 0xff);
|
int green = (int) Mth.lerp(delta, (color1 >> 8) & 0xff, (color2 >> 8) & 0xff);
|
||||||
int blue = (int) MathHelper.lerp(delta, color1 & 0xff, color2 & 0xff);
|
int blue = (int) Mth.lerp(delta, color1 & 0xff, color2 & 0xff);
|
||||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,24 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.*;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class ArmorHudWidget extends ResizableWidget {
|
public class ArmorHudWidget extends ResizableWidget {
|
||||||
|
|
||||||
@@ -39,7 +42,7 @@ public class ArmorHudWidget extends ResizableWidget {
|
|||||||
NUMBER,
|
NUMBER,
|
||||||
PERCENT;
|
PERCENT;
|
||||||
|
|
||||||
public Text getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return translatable("widgets.widgets.armorHud.durabilityStyle." + name().toLowerCase(Locale.ROOT));
|
return translatable("widgets.widgets.armorHud.durabilityStyle." + name().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +59,7 @@ public class ArmorHudWidget extends ResizableWidget {
|
|||||||
protected GradientOptions backgroundColor, textColor;
|
protected GradientOptions backgroundColor, textColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY) {
|
||||||
backgroundColor.fillHorizontal(
|
backgroundColor.fillHorizontal(
|
||||||
context,
|
context,
|
||||||
measuringTimeNano,
|
measuringTimeNano,
|
||||||
@@ -77,29 +80,29 @@ public class ArmorHudWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderItem(DrawContext context, long mt, TextRenderer textRenderer, ItemStack stack, int posX, int posY){
|
private void renderItem(GuiGraphicsExtractor context, long mt, Font textRenderer, ItemStack stack, int posX, int posY){
|
||||||
context.drawItemWithoutEntity(stack, posX, posY);
|
context.fakeItem(stack, posX, posY);
|
||||||
context.drawStackOverlay(textRenderer, stack, posX, posY);
|
context.itemDecorations(textRenderer, stack, posX, posY);
|
||||||
if (showDurability){
|
if (showDurability){
|
||||||
renderDurability(context, mt, textRenderer, stack, posX, posY);
|
renderDurability(context, mt, textRenderer, stack, posX, posY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderDurability(DrawContext context, long mt, TextRenderer textRenderer, ItemStack stack, int posX, int posY) {
|
private void renderDurability(GuiGraphicsExtractor context, long mt, Font textRenderer, ItemStack stack, int posX, int posY) {
|
||||||
Integer maxDamage = stack.get(DataComponentTypes.MAX_DAMAGE);
|
Integer maxDamage = stack.get(DataComponents.MAX_DAMAGE);
|
||||||
if (maxDamage != null) {
|
if (maxDamage != null) {
|
||||||
int damage = stack.getOrDefault(DataComponentTypes.DAMAGE, 0);
|
int damage = stack.getOrDefault(DataComponents.DAMAGE, 0);
|
||||||
String text = switch (durabilityStyle){
|
String text = switch (durabilityStyle){
|
||||||
case NUMBER -> String.valueOf(maxDamage - damage);
|
case NUMBER -> String.valueOf(maxDamage - damage);
|
||||||
case PERCENT -> ((maxDamage - damage) * 100 / maxDamage) + "%";
|
case PERCENT -> ((maxDamage - damage) * 100 / maxDamage) + "%";
|
||||||
};
|
};
|
||||||
switch (textAlignment){
|
switch (textAlignment){
|
||||||
case RIGHT -> {
|
case RIGHT -> {
|
||||||
int width = textRenderer.getWidth(text);
|
int width = textRenderer.width(text);
|
||||||
textColor.drawText(context, textRenderer, mt, text, posX + width() - width - padding * 2, posY + 5, true);
|
textColor.drawText(context, textRenderer, mt, text, posX + width() - width - padding * 2, posY + 5, true);
|
||||||
}
|
}
|
||||||
case CENTER -> {
|
case CENTER -> {
|
||||||
int width = textRenderer.getWidth(text);
|
int width = textRenderer.width(text);
|
||||||
textColor.drawText(context, textRenderer, mt, text, posX + ((preferredWidth + padding*2) - width) / 2 + 8, posY + 5, true);
|
textColor.drawText(context, textRenderer, mt, text, posX + ((preferredWidth + padding*2) - width) / 2 + 8, posY + 5, true);
|
||||||
}
|
}
|
||||||
case LEFT -> {
|
case LEFT -> {
|
||||||
@@ -111,25 +114,25 @@ public class ArmorHudWidget extends ResizableWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerInventory inventory = player.getInventory();
|
Inventory inventory = player.getInventory();
|
||||||
helmet = inventory.getStack(39);
|
helmet = inventory.getItem(39);
|
||||||
chestplate = inventory.getStack(38);
|
chestplate = inventory.getItem(38);
|
||||||
leggings = inventory.getStack(37);
|
leggings = inventory.getItem(37);
|
||||||
boots = inventory.getStack(36);
|
boots = inventory.getItem(36);
|
||||||
} else {
|
} else {
|
||||||
helmet = chestplate = leggings = boots = null;
|
helmet = chestplate = leggings = boots = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.armorHud");
|
return translatable("widgets.widgets.armorHud");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.armorHud.description");
|
return translatable("widgets.widgets.armorHud.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,15 @@ import de.shiewk.widgets.color.GradientOptions;
|
|||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.profiler.MultiValueDebugSampleLogImpl;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.util.debugchart.LocalSampleLogger;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.literal;
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class BandwidthWidget extends BasicTextWidget {
|
public class BandwidthWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -48,9 +47,9 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
|
|
||||||
public BandwidthWidget(Identifier id) {
|
public BandwidthWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new ToggleWidgetSetting("dynamic_color", Text.translatable("widgets.widgets.bandwidth.dynamicColor"), true),
|
new ToggleWidgetSetting("dynamic_color", Component.translatable("widgets.widgets.bandwidth.dynamicColor"), true),
|
||||||
new ToggleWidgetSetting("hide_in_singleplayer", Text.translatable("widgets.widgets.common.hideInSingleplayer"), false),
|
new ToggleWidgetSetting("hide_in_singleplayer", Component.translatable("widgets.widgets.common.hideInSingleplayer"), false),
|
||||||
new EnumWidgetSetting<>("unit", Text.translatable("widgets.widgets.bandwidth.unit"), Unit.class, Unit.KB, unit -> literal(unit.name)),
|
new EnumWidgetSetting<>("unit", Component.translatable("widgets.widgets.bandwidth.unit"), Unit.class, Unit.KB, unit -> literal(unit.name)),
|
||||||
new ToggleWidgetSetting("fastupdate", translatable("widgets.widgets.bandwidth.fastupdate"), false)
|
new ToggleWidgetSetting("fastupdate", translatable("widgets.widgets.bandwidth.fastupdate"), false)
|
||||||
));
|
));
|
||||||
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
||||||
@@ -70,7 +69,7 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
t++;
|
t++;
|
||||||
if (t >= tickRate || fastUpdate){
|
if (t >= tickRate || fastUpdate){
|
||||||
t = 0;
|
t = 0;
|
||||||
long avgBytesPerSecond = getAvgBytesPerSecond(MinecraftClient.getInstance(), tickRate);
|
long avgBytesPerSecond = getAvgBytesPerSecond(Minecraft.getInstance(), tickRate);
|
||||||
formatAndSetRenderText(unit.sizeFormatter.apply(avgBytesPerSecond));
|
formatAndSetRenderText(unit.sizeFormatter.apply(avgBytesPerSecond));
|
||||||
if (this.dynamicColor){
|
if (this.dynamicColor){
|
||||||
if (avgBytesPerSecond < 100000){
|
if (avgBytesPerSecond < 100000){
|
||||||
@@ -84,9 +83,9 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getAvgBytesPerSecond(MinecraftClient client, float tickRate) {
|
private static long getAvgBytesPerSecond(Minecraft client, float tickRate) {
|
||||||
final MultiValueDebugSampleLogImpl packetSizeLog = client.getDebugHud().getPacketSizeLog();
|
final LocalSampleLogger packetSizeLog = client.getDebugOverlay().getBandwidthLogger();
|
||||||
final int logLength = packetSizeLog.getLength();
|
final int logLength = packetSizeLog.size();
|
||||||
final int avgCompileLength = (int) (3 * tickRate);
|
final int avgCompileLength = (int) (3 * tickRate);
|
||||||
long size = 0;
|
long size = 0;
|
||||||
for (int i = logLength-1; i > logLength-avgCompileLength; i--) {
|
for (int i = logLength-1; i > logLength-avgCompileLength; i--) {
|
||||||
@@ -106,12 +105,12 @@ public class BandwidthWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.bandwidth");
|
return Component.translatable("widgets.widgets.bandwidth");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.bandwidth.description");
|
return Component.translatable("widgets.widgets.bandwidth.description");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
package de.shiewk.widgets.widgets;
|
package de.shiewk.widgets.widgets;
|
||||||
|
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
|
||||||
import de.shiewk.widgets.widgets.settings.*;
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.client.WidgetRenderer;
|
import de.shiewk.widgets.client.WidgetRenderer;
|
||||||
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
|
import de.shiewk.widgets.widgets.settings.*;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.*;
|
import static net.minecraft.network.chat.Component.*;
|
||||||
|
|
||||||
public abstract class BasicTextWidget extends ResizableWidget {
|
public abstract class BasicTextWidget extends ResizableWidget {
|
||||||
|
|
||||||
@@ -30,7 +29,7 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
|||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text displayText(){
|
public Component displayText(){
|
||||||
return translatable("widgets.widgets.basictext.alignment." + key);
|
return translatable("widgets.widgets.basictext.alignment." + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,28 +40,28 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
|||||||
PARENTHESES("parentheses", t -> surround("(", t, ")"));
|
PARENTHESES("parentheses", t -> surround("(", t, ")"));
|
||||||
|
|
||||||
public final String key;
|
public final String key;
|
||||||
public final UnaryOperator<Text> operator;
|
public final UnaryOperator<Component> operator;
|
||||||
|
|
||||||
TextStyle(String key, UnaryOperator<Text> operator) {
|
TextStyle(String key, UnaryOperator<Component> operator) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text displayText(){
|
public Component displayText(){
|
||||||
return translatable("widgets.widgets.basictext.style." + key);
|
return translatable("widgets.widgets.basictext.style." + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text surround(String prefix, Text subject, String suffix){
|
public static Component surround(String prefix, Component subject, String suffix){
|
||||||
return literal(prefix).append(subject).append(literal(suffix));
|
return literal(prefix).append(subject).append(literal(suffix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Text renderText = empty();
|
protected Component renderText = empty();
|
||||||
protected boolean shouldRender = true;
|
protected boolean shouldRender = true;
|
||||||
private float textX = 0;
|
private float textX = 0;
|
||||||
private float textY = 0;
|
private float textY = 0;
|
||||||
private int padding = 0;
|
private int padding = 0;
|
||||||
private TextRenderer renderer = null;
|
private Font renderer = null;
|
||||||
private boolean textShadow = true;
|
private boolean textShadow = true;
|
||||||
|
|
||||||
private static ObjectArrayList<WidgetSettingOption<?>> getCustomSettings(List<WidgetSettingOption<?>> otherCustomOptions) {
|
private static ObjectArrayList<WidgetSettingOption<?>> getCustomSettings(List<WidgetSettingOption<?>> otherCustomOptions) {
|
||||||
@@ -102,11 +101,11 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long n, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long n, Font textRenderer, int posX, int posY) {
|
||||||
if (!shouldRender) return;
|
if (!shouldRender) return;
|
||||||
renderer = textRenderer;
|
renderer = textRenderer;
|
||||||
this.backgroundColor.fillHorizontal(context, n, posX, posY, posX + width(), posY + height());
|
this.backgroundColor.fillHorizontal(context, n, posX, posY, posX + width(), posY + height());
|
||||||
Matrix3x2fStack matrices = context.getMatrices()
|
Matrix3x2fStack matrices = context.pose()
|
||||||
.pushMatrix();
|
.pushMatrix();
|
||||||
matrices.translate(posX + textX, posY + textY, matrices);
|
matrices.translate(posX + textX, posY + textY, matrices);
|
||||||
this.textColor.drawText(context, textRenderer, n, renderText, 0, 0, textShadow);
|
this.textColor.drawText(context, textRenderer, n, renderText, 0, 0, textShadow);
|
||||||
@@ -117,7 +116,7 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
|||||||
public final void tick() {
|
public final void tick() {
|
||||||
tickWidget();
|
tickWidget();
|
||||||
if (renderer != null){
|
if (renderer != null){
|
||||||
int textWidth = renderer.getWidth(renderText);
|
int textWidth = renderer.width(renderText);
|
||||||
switch (textAlignment){
|
switch (textAlignment){
|
||||||
case LEFT -> textX = padding;
|
case LEFT -> textX = padding;
|
||||||
case CENTER -> {
|
case CENTER -> {
|
||||||
@@ -138,7 +137,7 @@ public abstract class BasicTextWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void formatAndSetRenderText(Text renderText) {
|
protected void formatAndSetRenderText(Component renderText) {
|
||||||
if (textStyle != TextStyle.PLAIN){
|
if (textStyle != TextStyle.PLAIN){
|
||||||
this.renderText = textStyle.operator.apply(renderText);
|
this.renderText = textStyle.operator.apply(renderText);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,17 +2,16 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
|
||||||
import net.minecraft.client.world.ClientWorld;
|
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.world.biome.Biome;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class BiomeWidget extends BasicTextWidget {
|
public class BiomeWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -28,17 +27,17 @@ public class BiomeWidget extends BasicTextWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
if (++tickCounter % 20 == 0){
|
if (++tickCounter % 20 == 0){
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
Minecraft client = Minecraft.getInstance();
|
||||||
ClientPlayerEntity player = client.player;
|
LocalPlayer player = client.player;
|
||||||
ClientWorld world = client.world;
|
ClientLevel world = client.level;
|
||||||
if (world != null && player != null){
|
if (world != null && player != null){
|
||||||
RegistryEntry<Biome> biome = world.getBiome(player.getBlockPos());
|
Holder<Biome> biome = world.getBiome(player.blockPosition());
|
||||||
String text = biome.getKeyOrValue().map(
|
String text = biome.unwrap().map(
|
||||||
(biomeKey) -> {
|
(biomeKey) -> {
|
||||||
if (showLabel){
|
if (showLabel){
|
||||||
return translatable("widgets.widgets.biome.label", translatable(biomeKey.getValue().toTranslationKey("biome"))).getString();
|
return translatable("widgets.widgets.biome.label", translatable(biomeKey.identifier().toLanguageKey("biome"))).getString();
|
||||||
} else {
|
} else {
|
||||||
return translatable(biomeKey.getValue().toTranslationKey("biome")).getString();
|
return translatable(biomeKey.identifier().toLanguageKey("biome")).getString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(b) -> "[unregistered " + b + "]"
|
(b) -> "[unregistered " + b + "]"
|
||||||
@@ -55,12 +54,12 @@ public class BiomeWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.biome");
|
return translatable("widgets.widgets.biome");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.biome.description");
|
return translatable("widgets.widgets.biome.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ import de.shiewk.widgets.WidgetSettings;
|
|||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.literal;
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class CPSWidget extends BasicTextWidget {
|
public class CPSWidget extends BasicTextWidget {
|
||||||
|
|
||||||
public static class Click {
|
public static class Click {
|
||||||
public int ticks = 0;
|
public int ticks = 0;
|
||||||
public final long expiresAt = Util.getMeasuringTimeMs() + 1000;
|
public final long expiresAt = Util.getMillis() + 1000;
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "1.2.1")
|
@Deprecated(forRemoval = true, since = "1.2.1")
|
||||||
public int tick(){
|
public int tick(){
|
||||||
@@ -92,7 +92,7 @@ public class CPSWidget extends BasicTextWidget {
|
|||||||
int left = 0;
|
int left = 0;
|
||||||
int right = 0;
|
int right = 0;
|
||||||
int middle = 0;
|
int middle = 0;
|
||||||
long mtime = Util.getMeasuringTimeMs();
|
long mtime = Util.getMillis();
|
||||||
if (countLeftClicks) {
|
if (countLeftClicks) {
|
||||||
leftClicks.removeIf(click -> click.expiresAt <= mtime);
|
leftClicks.removeIf(click -> click.expiresAt <= mtime);
|
||||||
left = leftClicks.size();
|
left = leftClicks.size();
|
||||||
@@ -149,12 +149,12 @@ public class CPSWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.cps");
|
return translatable("widgets.widgets.cps");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.cps.description");
|
return translatable("widgets.widgets.cps.description");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import de.shiewk.widgets.WidgetSettings;
|
|||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public class ClockWidget extends BasicTextWidget {
|
public class ClockWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -25,8 +24,8 @@ public class ClockWidget extends BasicTextWidget {
|
|||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.clock.hourFormat."+key);
|
return Component.translatable("widgets.widgets.clock.hourFormat."+key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +50,8 @@ public class ClockWidget extends BasicTextWidget {
|
|||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text getName(){
|
public Component getName(){
|
||||||
return this.format == null ? Text.translatable("widgets.widgets.clock.dateFormat.none") : Text.of(new SimpleDateFormat(format).format(Date.from(Instant.now())));
|
return this.format == null ? Component.translatable("widgets.widgets.clock.dateFormat.none") : Component.nullToEmpty(new SimpleDateFormat(format).format(Date.from(Instant.now())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,27 +66,27 @@ public class ClockWidget extends BasicTextWidget {
|
|||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text getName(){
|
public Component getName(){
|
||||||
return this.format == null ? Text.translatable("widgets.widgets.clock.weekFormat.none") : Text.of(new SimpleDateFormat(format).format(Date.from(Instant.now())));
|
return this.format == null ? Component.translatable("widgets.widgets.clock.weekFormat.none") : Component.nullToEmpty(new SimpleDateFormat(format).format(Date.from(Instant.now())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ClockWidget(Identifier id) {
|
public ClockWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new EnumWidgetSetting<>("hour_format",
|
new EnumWidgetSetting<>("hour_format",
|
||||||
Text.translatable("widgets.widgets.clock.hourFormat"),
|
Component.translatable("widgets.widgets.clock.hourFormat"),
|
||||||
TimeOption.class,
|
TimeOption.class,
|
||||||
TimeOption.HOUR_24,
|
TimeOption.HOUR_24,
|
||||||
TimeOption::getName),
|
TimeOption::getName),
|
||||||
new ToggleWidgetSetting("show_seconds",
|
new ToggleWidgetSetting("show_seconds",
|
||||||
Text.translatable("widgets.widgets.clock.showSeconds"),
|
Component.translatable("widgets.widgets.clock.showSeconds"),
|
||||||
true),
|
true),
|
||||||
new EnumWidgetSetting<>("date_format",
|
new EnumWidgetSetting<>("date_format",
|
||||||
Text.translatable("widgets.widgets.clock.dateFormat"),
|
Component.translatable("widgets.widgets.clock.dateFormat"),
|
||||||
DateOption.class,
|
DateOption.class,
|
||||||
DateOption.NO_DATE,
|
DateOption.NO_DATE,
|
||||||
DateOption::getName),
|
DateOption::getName),
|
||||||
new EnumWidgetSetting<>("week_format",
|
new EnumWidgetSetting<>("week_format",
|
||||||
Text.translatable("widgets.widgets.clock.weekFormat"),
|
Component.translatable("widgets.widgets.clock.weekFormat"),
|
||||||
WeekOption.class,
|
WeekOption.class,
|
||||||
WeekOption.NO_DAY_OF_WEEK,
|
WeekOption.NO_DAY_OF_WEEK,
|
||||||
WeekOption::getName)
|
WeekOption::getName)
|
||||||
@@ -135,12 +134,12 @@ public class ClockWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.clock");
|
return Component.translatable("widgets.widgets.clock");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.clock.description");
|
return Component.translatable("widgets.widgets.clock.description");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,20 +4,20 @@ import de.shiewk.widgets.WidgetSettings;
|
|||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jspecify.annotations.NonNull;
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class ComboWidget extends BasicTextWidget implements AttackEntityCallback {
|
public class ComboWidget extends BasicTextWidget implements AttackEntityCallback {
|
||||||
|
|
||||||
@@ -40,9 +40,9 @@ public class ComboWidget extends BasicTextWidget implements AttackEntityCallback
|
|||||||
private int displayThreshold = 0;
|
private int displayThreshold = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ActionResult interact(@NonNull PlayerEntity playerEntity, @NonNull World world, @NonNull Hand hand, Entity entity, @Nullable EntityHitResult entityHitResult) {
|
public @NonNull InteractionResult interact(@NonNull Player playerEntity, @NonNull Level world, @NonNull InteractionHand hand, Entity entity, @Nullable EntityHitResult entityHitResult) {
|
||||||
clientHitEntity(entity.getId());
|
clientHitEntity(entity.getId());
|
||||||
return ActionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clientHitEntity(int targetEntityId) {
|
private void clientHitEntity(int targetEntityId) {
|
||||||
@@ -94,12 +94,12 @@ public class ComboWidget extends BasicTextWidget implements AttackEntityCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.combo");
|
return translatable("widgets.widgets.combo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.combo.description");
|
return translatable("widgets.widgets.combo.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,16 @@ package de.shiewk.widgets.widgets;
|
|||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.*;
|
import de.shiewk.widgets.widgets.settings.*;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class CoordinatesWidget extends ResizableWidget {
|
public class CoordinatesWidget extends ResizableWidget {
|
||||||
public CoordinatesWidget(Identifier id) {
|
public CoordinatesWidget(Identifier id) {
|
||||||
@@ -71,7 +70,7 @@ public class CoordinatesWidget extends ResizableWidget {
|
|||||||
protected DirectionWidget.DisplayFormat directionFormat;
|
protected DirectionWidget.DisplayFormat directionFormat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long mt, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long mt, Font textRenderer, int posX, int posY) {
|
||||||
this.backgroundColor.fillHorizontal(context, mt, posX, posY, posX + width(), posY + height());
|
this.backgroundColor.fillHorizontal(context, mt, posX, posY, posX + width(), posY + height());
|
||||||
int y = this.paddingY + 1;
|
int y = this.paddingY + 1;
|
||||||
if (showX){
|
if (showX){
|
||||||
@@ -97,8 +96,8 @@ public class CoordinatesWidget extends ResizableWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
final Font textRenderer = Minecraft.getInstance().font;
|
||||||
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
final LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (hideCoordinates){
|
if (hideCoordinates){
|
||||||
textX = textHiddenX;
|
textX = textHiddenX;
|
||||||
textY = textHiddenY;
|
textY = textHiddenY;
|
||||||
@@ -114,19 +113,19 @@ public class CoordinatesWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
textDirection = directionFormat.format().getString();
|
textDirection = directionFormat.format().getString();
|
||||||
|
|
||||||
txc = width() - textRenderer.getWidth(textX) - paddingX;
|
txc = width() - textRenderer.width(textX) - paddingX;
|
||||||
tyc = width() - textRenderer.getWidth(textY) - paddingX;
|
tyc = width() - textRenderer.width(textY) - paddingX;
|
||||||
tzc = width() - textRenderer.getWidth(textZ) - paddingX;
|
tzc = width() - textRenderer.width(textZ) - paddingX;
|
||||||
tdc = width() - textRenderer.getWidth(textDirection) - paddingX;
|
tdc = width() - textRenderer.width(textDirection) - paddingX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.coordinates");
|
return translatable("widgets.widgets.coordinates");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.coordinates.description");
|
return translatable("widgets.widgets.coordinates.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,19 +5,18 @@ import de.shiewk.widgets.utils.WidgetUtils;
|
|||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
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.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.literal;
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class DirectionWidget extends BasicTextWidget {
|
public class DirectionWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -36,13 +35,13 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
this.showsYaw = showsYaw;
|
this.showsYaw = showsYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text format(int digits) {
|
public Component format(int digits) {
|
||||||
String yaw = "0";
|
String yaw = "0";
|
||||||
String direction = "unknown";
|
String direction = "unknown";
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
yaw = WidgetUtils.reduceDigits(MathHelper.wrapDegrees(player.getYaw()), digits);
|
yaw = WidgetUtils.reduceDigits(Mth.wrapDegrees(player.getYRot()), digits);
|
||||||
direction = player.getHorizontalFacing().name().toLowerCase(Locale.ROOT);
|
direction = player.getDirection().name().toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
return switch (this){
|
return switch (this){
|
||||||
case YAW_ONLY -> literal(yaw);
|
case YAW_ONLY -> literal(yaw);
|
||||||
@@ -55,7 +54,7 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text format(){
|
public Component format(){
|
||||||
return format(1);
|
return format(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,7 +84,7 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long n, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long n, Font textRenderer, int posX, int posY) {
|
||||||
if (realtime) refresh();
|
if (realtime) refresh();
|
||||||
super.renderScaled(context, n, textRenderer, posX, posY);
|
super.renderScaled(context, n, textRenderer, posX, posY);
|
||||||
}
|
}
|
||||||
@@ -95,12 +94,12 @@ public class DirectionWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.direction");
|
return translatable("widgets.widgets.direction");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.direction.description");
|
return translatable("widgets.widgets.direction.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class FPSWidget extends BasicTextWidget {
|
public class FPSWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ public class FPSWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long n, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long n, Font textRenderer, int posX, int posY) {
|
||||||
if (realtime){
|
if (realtime){
|
||||||
timedFrames.add(n);
|
timedFrames.add(n);
|
||||||
while (timedFrames.getFirst() < n - 500_000_100L){
|
while (timedFrames.getFirst() < n - 500_000_100L){
|
||||||
@@ -39,17 +38,17 @@ public class FPSWidget extends BasicTextWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
if (!realtime){
|
if (!realtime){
|
||||||
formatAndSetRenderText(MinecraftClient.getInstance().getCurrentFps() + " FPS");
|
formatAndSetRenderText(Minecraft.getInstance().getFps() + " FPS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.fps");
|
return translatable("widgets.widgets.fps");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.fps.description");
|
return translatable("widgets.widgets.fps.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,28 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.*;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.gl.RenderPipelines;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class InventoryWidget extends ResizableWidget {
|
public class InventoryWidget extends ResizableWidget {
|
||||||
|
|
||||||
private static final Identifier VANILLA_INVENTORY = Identifier.of("widgets", "textures/vanilla_inventory.png");
|
private static final Identifier VANILLA_INVENTORY = Identifier.fromNamespaceAndPath("widgets", "textures/vanilla_inventory.png");
|
||||||
private static final Identifier TEXTURE_PACK_INVENTORY = Identifier.ofVanilla("textures/gui/container/inventory.png");
|
private static final Identifier TEXTURE_PACK_INVENTORY = Identifier.withDefaultNamespace("textures/gui/container/inventory.png");
|
||||||
|
|
||||||
public enum InventoryMode {
|
public enum InventoryMode {
|
||||||
VANILLA,
|
VANILLA,
|
||||||
@@ -40,7 +42,7 @@ public class InventoryWidget extends ResizableWidget {
|
|||||||
this.canDisableHotbar = canDisableHotbar;
|
this.canDisableHotbar = canDisableHotbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text display() {
|
public Component display() {
|
||||||
return translatable("widgets.widgets.inventory.mode." + name().toLowerCase(Locale.ROOT));
|
return translatable("widgets.widgets.inventory.mode." + name().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,13 +60,13 @@ public class InventoryWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private InventoryMode mode = InventoryMode.TEXTURE_PACK;
|
private InventoryMode mode = InventoryMode.TEXTURE_PACK;
|
||||||
private PlayerInventory inventory;
|
private Inventory inventory;
|
||||||
|
|
||||||
private GradientOptions gridColor, boxColor;
|
private GradientOptions gridColor, boxColor;
|
||||||
private boolean showHotbar = false;
|
private boolean showHotbar = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY) {
|
||||||
drawBackground(context, measuringTimeNano, posX, posY);
|
drawBackground(context, measuringTimeNano, posX, posY);
|
||||||
if (inventory != null){
|
if (inventory != null){
|
||||||
drawItems(context, textRenderer, switch (mode){
|
drawItems(context, textRenderer, switch (mode){
|
||||||
@@ -79,15 +81,15 @@ public class InventoryWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBackground(DrawContext context, long mt, int posX, int posY) {
|
private void drawBackground(GuiGraphicsExtractor context, long mt, int posX, int posY) {
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case VANILLA -> context.drawTexture(RenderPipelines.GUI_TEXTURED, VANILLA_INVENTORY, posX, posY, 0, 0, 176, 91, 176, 91);
|
case VANILLA -> context.blit(RenderPipelines.GUI_TEXTURED, VANILLA_INVENTORY, posX, posY, 0, 0, 176, 91, 176, 91);
|
||||||
case TEXTURE_PACK -> {
|
case TEXTURE_PACK -> {
|
||||||
context.enableScissor(posX, posY, posX + width(), posY + 6);
|
context.enableScissor(posX, posY, posX + width(), posY + 6);
|
||||||
context.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE_PACK_INVENTORY, posX, posY, 0, 0, 256, 256, 256, 256);
|
context.blit(RenderPipelines.GUI_TEXTURED, TEXTURE_PACK_INVENTORY, posX, posY, 0, 0, 256, 256, 256, 256);
|
||||||
context.disableScissor();
|
context.disableScissor();
|
||||||
context.enableScissor(posX, posY + 6, posX + width(), posY + height());
|
context.enableScissor(posX, posY + 6, posX + width(), posY + height());
|
||||||
context.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE_PACK_INVENTORY, posX, posY - 75, 0, 0, 256, 256, 256, 256);
|
context.blit(RenderPipelines.GUI_TEXTURED, TEXTURE_PACK_INVENTORY, posX, posY - 75, 0, 0, 256, 256, 256, 256);
|
||||||
context.disableScissor();
|
context.disableScissor();
|
||||||
}
|
}
|
||||||
case GRID -> {
|
case GRID -> {
|
||||||
@@ -127,40 +129,39 @@ public class InventoryWidget extends ResizableWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawItems(DrawContext context, TextRenderer textRenderer, int posX, int posY) {
|
private void drawItems(GuiGraphicsExtractor context, Font textRenderer, int posX, int posY) {
|
||||||
for (int ry = 0; ry < 4; ry++) {
|
for (int ry = 0; ry < 4; ry++) {
|
||||||
if (ry == 0 && !showHotbar) continue;
|
if (ry == 0 && !showHotbar) continue;
|
||||||
for (int rx = 0; rx < 9; rx++) {
|
for (int rx = 0; rx < 9; rx++) {
|
||||||
|
|
||||||
int slot = ry * 9 + rx;
|
int slot = ry * 9 + rx;
|
||||||
ItemStack stack = inventory.getStack(slot);
|
ItemStack stack = inventory.getItem(slot);
|
||||||
if (stack.isEmpty()) continue;
|
if (stack.isEmpty()) continue;
|
||||||
|
|
||||||
int itemY = ry == 0 ? posY + 58 : posY + (ry-1) * 18;
|
int itemY = ry == 0 ? posY + 58 : posY + (ry-1) * 18;
|
||||||
int itemX = posX + rx * 18;
|
int itemX = posX + rx * 18;
|
||||||
|
|
||||||
context.drawItem(stack, itemX, itemY);
|
context.item(stack, itemX, itemY);
|
||||||
context.drawStackOverlay(textRenderer, stack, itemX, itemY);
|
context.itemDecorations(textRenderer, stack, itemX, itemY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerInventory clientPlayerEntityInventory = player.getInventory();
|
inventory = player.getInventory();
|
||||||
if (clientPlayerEntityInventory != null) inventory = clientPlayerEntityInventory;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.inventory");
|
return translatable("widgets.widgets.inventory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.inventory.description");
|
return translatable("widgets.widgets.inventory.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import de.shiewk.widgets.WidgetSettings;
|
|||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.GradientWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -18,11 +18,11 @@ import java.util.Objects;
|
|||||||
public class KeyStrokesWidget extends ResizableWidget {
|
public class KeyStrokesWidget extends ResizableWidget {
|
||||||
public KeyStrokesWidget(Identifier id) {
|
public KeyStrokesWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new ToggleWidgetSetting("showjump", Text.translatable("widgets.widgets.keystrokes.showJumpKey"), true),
|
new ToggleWidgetSetting("showjump", Component.translatable("widgets.widgets.keystrokes.showJumpKey"), true),
|
||||||
new GradientWidgetSetting("bgpressed", Text.translatable("widgets.widgets.keystrokes.colorBackgroundPressed"), 0x50ffffff),
|
new GradientWidgetSetting("bgpressed", Component.translatable("widgets.widgets.keystrokes.colorBackgroundPressed"), 0x50ffffff),
|
||||||
new GradientWidgetSetting("bgunpressed", Text.translatable("widgets.widgets.keystrokes.colorBackgroundUnpressed"), 0x50000000),
|
new GradientWidgetSetting("bgunpressed", Component.translatable("widgets.widgets.keystrokes.colorBackgroundUnpressed"), 0x50000000),
|
||||||
new GradientWidgetSetting("keypressed", Text.translatable("widgets.widgets.keystrokes.colorKeyPressed"), 0xffffffff),
|
new GradientWidgetSetting("keypressed", Component.translatable("widgets.widgets.keystrokes.colorKeyPressed"), 0xffffffff),
|
||||||
new GradientWidgetSetting("keyunpressed", Text.translatable("widgets.widgets.keystrokes.colorKeyUnpressed"), 0xffffffff)
|
new GradientWidgetSetting("keyunpressed", Component.translatable("widgets.widgets.keystrokes.colorKeyUnpressed"), 0xffffffff)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,11 +30,11 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
private boolean showJumpKey = true;
|
private boolean showJumpKey = true;
|
||||||
|
|
||||||
protected static class Key {
|
protected static class Key {
|
||||||
protected final KeyBinding binding;
|
protected final KeyMapping binding;
|
||||||
protected boolean isPressed;
|
protected boolean isPressed;
|
||||||
protected long lastChanged;
|
protected long lastChanged;
|
||||||
|
|
||||||
private Key(KeyBinding binding) {
|
private Key(KeyMapping binding) {
|
||||||
Objects.requireNonNull(binding);
|
Objects.requireNonNull(binding);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
protected String boundToKey;
|
protected String boundToKey;
|
||||||
protected int boundToLength;
|
protected int boundToLength;
|
||||||
|
|
||||||
private KeyLarge(KeyBinding binding) {
|
private KeyLarge(KeyMapping binding) {
|
||||||
super(binding);
|
super(binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
private Key KEY_JUMP;
|
private Key KEY_JUMP;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY) {
|
||||||
if (KEY_JUMP == null) return;
|
if (KEY_JUMP == null) return;
|
||||||
renderKeyStroke(context, textRenderer, measuringTimeNano, posX + 22, posY, KEY_FWD);
|
renderKeyStroke(context, textRenderer, measuringTimeNano, posX + 22, posY, KEY_FWD);
|
||||||
renderKeyStroke(context, textRenderer, measuringTimeNano, posX, posY + 22, KEY_LEFT);
|
renderKeyStroke(context, textRenderer, measuringTimeNano, posX, posY + 22, KEY_LEFT);
|
||||||
@@ -62,7 +62,7 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
if (showJumpKey) renderSpaceBar(context, measuringTimeNano, posX, posY + 44, KEY_JUMP);
|
if (showJumpKey) renderSpaceBar(context, measuringTimeNano, posX, posY + 44, KEY_JUMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderSpaceBar(final DrawContext context, long mt, int posX, int posY, Key key){
|
protected void renderSpaceBar(final GuiGraphicsExtractor context, long mt, int posX, int posY, Key key){
|
||||||
long l = mt - key.lastChanged;
|
long l = mt - key.lastChanged;
|
||||||
if (l < 100000000){
|
if (l < 100000000){
|
||||||
double alpha = 0.00000001d * l;
|
double alpha = 0.00000001d * l;
|
||||||
@@ -74,7 +74,7 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
(key.isPressed ? colorKeyPressed : colorKeyUnpressed).fillHorizontal(context, mt, posX + 5, posY + 4, posX + 59, posY + 5);
|
(key.isPressed ? colorKeyPressed : colorKeyUnpressed).fillHorizontal(context, mt, posX + 5, posY + 4, posX + 59, posY + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderKeyStroke(DrawContext context, TextRenderer textRenderer, long mt, int posX, int posY, KeyLarge key){
|
protected void renderKeyStroke(GuiGraphicsExtractor context, Font textRenderer, long mt, int posX, int posY, KeyLarge key){
|
||||||
long l = mt - key.lastChanged;
|
long l = mt - key.lastChanged;
|
||||||
if (l < 100000000){
|
if (l < 100000000){
|
||||||
double alpha = 0.00000001d * l;
|
double alpha = 0.00000001d * l;
|
||||||
@@ -88,43 +88,43 @@ public class KeyStrokesWidget extends ResizableWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (KEY_FWD == null) KEY_FWD = new KeyLarge(MinecraftClient.getInstance().options.forwardKey);
|
if (KEY_FWD == null) KEY_FWD = new KeyLarge(Minecraft.getInstance().options.keyUp);
|
||||||
if (KEY_BWD == null) KEY_BWD = new KeyLarge(MinecraftClient.getInstance().options.backKey);
|
if (KEY_BWD == null) KEY_BWD = new KeyLarge(Minecraft.getInstance().options.keyDown);
|
||||||
if (KEY_LEFT == null) KEY_LEFT = new KeyLarge(MinecraftClient.getInstance().options.leftKey);
|
if (KEY_LEFT == null) KEY_LEFT = new KeyLarge(Minecraft.getInstance().options.keyLeft);
|
||||||
if (KEY_RIGHT == null) KEY_RIGHT = new KeyLarge(MinecraftClient.getInstance().options.rightKey);
|
if (KEY_RIGHT == null) KEY_RIGHT = new KeyLarge(Minecraft.getInstance().options.keyRight);
|
||||||
if (KEY_JUMP == null) KEY_JUMP = new Key(MinecraftClient.getInstance().options.jumpKey);
|
if (KEY_JUMP == null) KEY_JUMP = new Key(Minecraft.getInstance().options.keyJump);
|
||||||
TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
|
Font renderer = Minecraft.getInstance().font;
|
||||||
for (Key key : new Key[]{KEY_FWD, KEY_BWD, KEY_LEFT, KEY_RIGHT, KEY_JUMP}){
|
for (Key key : new Key[]{KEY_FWD, KEY_BWD, KEY_LEFT, KEY_RIGHT, KEY_JUMP}){
|
||||||
if (key instanceof KeyLarge keyLarge){
|
if (key instanceof KeyLarge keyLarge){
|
||||||
keyLarge.boundToKey = getKeyName(key);
|
keyLarge.boundToKey = getKeyName(key);
|
||||||
keyLarge.boundToLength = renderer.getWidth(keyLarge.boundToKey);
|
keyLarge.boundToLength = renderer.width(keyLarge.boundToKey);
|
||||||
}
|
}
|
||||||
final boolean pressed = key.binding.isPressed();
|
final boolean pressed = key.binding.isDown();
|
||||||
if (pressed != key.isPressed){
|
if (pressed != key.isPressed){
|
||||||
key.isPressed = pressed;
|
key.isPressed = pressed;
|
||||||
key.lastChanged = Util.getMeasuringTimeNano();
|
key.lastChanged = Util.getNanos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getKeyName(Key key) {
|
private static String getKeyName(Key key) {
|
||||||
return switch (key.binding.getBoundKeyTranslationKey()) {
|
return switch (key.binding.saveString()) {
|
||||||
case "key.keyboard.up" -> "\u2191";
|
case "key.keyboard.up" -> "\u2191";
|
||||||
case "key.keyboard.down" -> "\u2193";
|
case "key.keyboard.down" -> "\u2193";
|
||||||
case "key.keyboard.left" -> "\u2190";
|
case "key.keyboard.left" -> "\u2190";
|
||||||
case "key.keyboard.right" -> "\u2192";
|
case "key.keyboard.right" -> "\u2192";
|
||||||
default -> key.binding.getBoundKeyLocalizedText().getString();
|
default -> key.binding.getTranslatedKeyMessage().getString();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.keystrokes");
|
return Component.translatable("widgets.widgets.keystrokes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.keystrokes.description");
|
return Component.translatable("widgets.widgets.keystrokes.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class MemoryUsageWidget extends BasicTextWidget {
|
public class MemoryUsageWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -26,7 +25,7 @@ public class MemoryUsageWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderScaled(DrawContext context, long n, TextRenderer textRenderer, int posX, int posY) {
|
public void renderScaled(GuiGraphicsExtractor context, long n, Font textRenderer, int posX, int posY) {
|
||||||
if (realtime) refresh();
|
if (realtime) refresh();
|
||||||
super.renderScaled(context, n, textRenderer, posX, posY);
|
super.renderScaled(context, n, textRenderer, posX, posY);
|
||||||
}
|
}
|
||||||
@@ -58,12 +57,12 @@ public class MemoryUsageWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.memory");
|
return translatable("widgets.widgets.memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.memory.description");
|
return translatable("widgets.widgets.memory.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,20 @@ import de.shiewk.widgets.WidgetSettings;
|
|||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.profiler.MultiValueDebugSampleLogImpl;
|
import net.minecraft.util.debugchart.LocalSampleLogger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PingWidget extends BasicTextWidget {
|
public class PingWidget extends BasicTextWidget {
|
||||||
|
|
||||||
public PingWidget(Identifier id) {
|
public PingWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new ToggleWidgetSetting("dynamic_color", Text.translatable("widgets.widgets.ping.dynamicColor"), true),
|
new ToggleWidgetSetting("dynamic_color", Component.translatable("widgets.widgets.ping.dynamicColor"), true),
|
||||||
new ToggleWidgetSetting("hide_in_singleplayer", Text.translatable("widgets.widgets.common.hideInSingleplayer"), false)
|
new ToggleWidgetSetting("hide_in_singleplayer", Component.translatable("widgets.widgets.common.hideInSingleplayer"), false)
|
||||||
));
|
));
|
||||||
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
||||||
}
|
}
|
||||||
@@ -32,14 +31,14 @@ public class PingWidget extends BasicTextWidget {
|
|||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
shouldRender = !(hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
shouldRender = !(hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
||||||
if (!shouldRender) return;
|
if (!shouldRender) return;
|
||||||
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
|
final ClientPacketListener networkHandler = Minecraft.getInstance().getConnection();
|
||||||
if (networkHandler != null){
|
if (networkHandler != null){
|
||||||
if (lastPingQuery < Util.getMeasuringTimeMs() - 5000){
|
if (lastPingQuery < Util.getMillis() - 5000){
|
||||||
networkHandler.pingMeasurer.ping();
|
networkHandler.pingDebugMonitor.tick();
|
||||||
lastPingQuery = Util.getMeasuringTimeMs();
|
lastPingQuery = Util.getMillis();
|
||||||
}
|
}
|
||||||
final MultiValueDebugSampleLogImpl pingLog = networkHandler.pingMeasurer.log;
|
final LocalSampleLogger pingLog = networkHandler.pingDebugMonitor.delayTimer;
|
||||||
final int logLength = pingLog.getLength();
|
final int logLength = pingLog.size();
|
||||||
final int avgCompileLength = 3;
|
final int avgCompileLength = 3;
|
||||||
long ping = 0;
|
long ping = 0;
|
||||||
int valuesRead = 0;
|
int valuesRead = 0;
|
||||||
@@ -75,12 +74,12 @@ public class PingWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.ping");
|
return Component.translatable("widgets.widgets.ping");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.ping.description");
|
return Component.translatable("widgets.widgets.ping.description");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.TextFieldWidgetSettingOption;
|
import de.shiewk.widgets.widgets.settings.TextFieldWidgetSettingOption;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public class PlainTextWidget extends BasicTextWidget {
|
public class PlainTextWidget extends BasicTextWidget {
|
||||||
public PlainTextWidget(Identifier id) {
|
public PlainTextWidget(Identifier id) {
|
||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new TextFieldWidgetSettingOption("text", Text.translatable("widgets.widgets.plaintext.text"), Text.translatable("widgets.widgets.plaintext.initial"), Text.translatable("widgets.widgets.plaintext.placeholder"), true, 200)
|
new TextFieldWidgetSettingOption("text", Component.translatable("widgets.widgets.plaintext.text"), Component.translatable("widgets.widgets.plaintext.initial"), Component.translatable("widgets.widgets.plaintext.placeholder"), true, 200)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,13 +17,13 @@ public class PlainTextWidget extends BasicTextWidget {
|
|||||||
public void tickWidget() {}
|
public void tickWidget() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.plaintext");
|
return Component.translatable("widgets.widgets.plaintext");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.plaintext.description");
|
return Component.translatable("widgets.widgets.plaintext.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ package de.shiewk.widgets.widgets;
|
|||||||
|
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.literal;
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class PlayTimeWidget extends BasicTextWidget {
|
public class PlayTimeWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -61,12 +60,12 @@ public class PlayTimeWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.playtime");
|
return translatable("widgets.widgets.playtime");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.playtime.description");
|
return translatable("widgets.widgets.playtime.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ package de.shiewk.widgets.widgets;
|
|||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.literal;
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class PlayerCountWidget extends BasicTextWidget{
|
public class PlayerCountWidget extends BasicTextWidget{
|
||||||
public PlayerCountWidget(Identifier id) {
|
public PlayerCountWidget(Identifier id) {
|
||||||
@@ -28,18 +27,18 @@ public class PlayerCountWidget extends BasicTextWidget{
|
|||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
shouldRender = !(hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
shouldRender = !(hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
||||||
if (!shouldRender) return;
|
if (!shouldRender) return;
|
||||||
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
|
final ClientPacketListener networkHandler = Minecraft.getInstance().getConnection();
|
||||||
String online = networkHandler == null ? "?" : String.valueOf(networkHandler.getListedPlayerListEntries().size());
|
String online = networkHandler == null ? "?" : String.valueOf(networkHandler.getListedOnlinePlayers().size());
|
||||||
formatAndSetRenderText(showLabel ? literal(translatable("widgets.widgets.playerCount.online", online).getString()) : literal(online));
|
formatAndSetRenderText(showLabel ? literal(translatable("widgets.widgets.playerCount.online", online).getString()) : literal(online));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.playerCount");
|
return translatable("widgets.widgets.playerCount");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.playerCount.description");
|
return translatable("widgets.widgets.playerCount.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import de.shiewk.widgets.ModWidget;
|
|||||||
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
import de.shiewk.widgets.widgets.settings.WidgetSettingOption;
|
||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.joml.Matrix3x2fStack;
|
import org.joml.Matrix3x2fStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public abstract class ResizableWidget extends ModWidget {
|
public abstract class ResizableWidget extends ModWidget {
|
||||||
|
|
||||||
@@ -21,25 +21,25 @@ public abstract class ResizableWidget extends ModWidget {
|
|||||||
|
|
||||||
private static List<WidgetSettingOption<?>> addScaleSetting(List<WidgetSettingOption<?>> target) {
|
private static List<WidgetSettingOption<?>> addScaleSetting(List<WidgetSettingOption<?>> target) {
|
||||||
ArrayList<WidgetSettingOption<?>> settings = new ArrayList<>(target);
|
ArrayList<WidgetSettingOption<?>> settings = new ArrayList<>(target);
|
||||||
settings.add(new IntSliderWidgetSetting("size", Text.translatable("widgets.widgets.common.sizePercent"), 25, 100, 400));
|
settings.add(new IntSliderWidgetSetting("size", Component.translatable("widgets.widgets.common.sizePercent"), 25, 100, 400));
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float size = 1f;
|
protected float size = 1f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void render(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY) {
|
public final void render(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY) {
|
||||||
if (size != 1f){
|
if (size != 1f){
|
||||||
Matrix3x2fStack matrices = context.getMatrices();
|
Matrix3x2fStack matrices = context.pose();
|
||||||
matrices.pushMatrix();
|
matrices.pushMatrix();
|
||||||
matrices.translate(-(size-1) * posX, -(size-1) * posY, matrices);
|
matrices.translate(-(size-1) * posX, -(size-1) * posY, matrices);
|
||||||
matrices.scale(size, size, matrices);
|
matrices.scale(size, size, matrices);
|
||||||
}
|
}
|
||||||
this.renderScaled(context, measuringTimeNano, textRenderer, posX, posY);
|
this.renderScaled(context, measuringTimeNano, textRenderer, posX, posY);
|
||||||
if (size != 1f) context.getMatrices().popMatrix();
|
if (size != 1f) context.pose().popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void renderScaled(DrawContext context, long measuringTimeNano, TextRenderer textRenderer, int posX, int posY);
|
public abstract void renderScaled(GuiGraphicsExtractor context, long measuringTimeNano, Font textRenderer, int posX, int posY);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsChanged(WidgetSettings settings) {
|
public void onSettingsChanged(WidgetSettings settings) {
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package de.shiewk.widgets.widgets;
|
|||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ServerInfo;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.ServerData;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class ServerIPWidget extends BasicTextWidget {
|
public class ServerIPWidget extends BasicTextWidget {
|
||||||
public ServerIPWidget(Identifier id) {
|
public ServerIPWidget(Identifier id) {
|
||||||
@@ -31,16 +30,16 @@ public class ServerIPWidget extends BasicTextWidget {
|
|||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
shouldRender = !(this.hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
shouldRender = !(this.hideInSingleplayer && WidgetUtils.isInSingleplayer());
|
||||||
if (!shouldRender) return;
|
if (!shouldRender) return;
|
||||||
final ServerInfo serverEntry = MinecraftClient.getInstance().getCurrentServerEntry();
|
final ServerData serverEntry = Minecraft.getInstance().getCurrentServer();
|
||||||
if (serverEntry != null){
|
if (serverEntry != null){
|
||||||
formatAndSetRenderText(serverEntry.address);
|
formatAndSetRenderText(serverEntry.ip);
|
||||||
} else {
|
} else {
|
||||||
formatAndSetRenderText(translatable("menu.singleplayer"));
|
formatAndSetRenderText(translatable("menu.singleplayer"));
|
||||||
}
|
}
|
||||||
t++;
|
t++;
|
||||||
if (dynamicWidth && t >= 20){
|
if (dynamicWidth && t >= 20){
|
||||||
t = 0;
|
t = 0;
|
||||||
this.width = MinecraftClient.getInstance().textRenderer.getWidth(this.renderText) + 20;
|
this.width = Minecraft.getInstance().font.width(this.renderText) + 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +49,12 @@ public class ServerIPWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.serverIP");
|
return translatable("widgets.widgets.serverIP");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.serverIP.description");
|
return translatable("widgets.widgets.serverIP.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import de.shiewk.widgets.utils.WidgetUtils;
|
|||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
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.network.ClientPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import static de.shiewk.widgets.utils.WidgetUtils.reduceDigits;
|
import static de.shiewk.widgets.utils.WidgetUtils.reduceDigits;
|
||||||
|
|
||||||
@@ -33,16 +32,16 @@ public class SpeedWidget extends BasicTextWidget {
|
|||||||
super(id, List.of(
|
super(id, List.of(
|
||||||
new EnumWidgetSetting<>(
|
new EnumWidgetSetting<>(
|
||||||
"unit",
|
"unit",
|
||||||
Text.translatable("widgets.widgets.speed.unit"),
|
Component.translatable("widgets.widgets.speed.unit"),
|
||||||
Unit.class,
|
Unit.class,
|
||||||
Unit.METERS_PER_SECOND,
|
Unit.METERS_PER_SECOND,
|
||||||
unit -> Text.of(unit.displayName)
|
unit -> Component.nullToEmpty(unit.displayName)
|
||||||
),
|
),
|
||||||
new ToggleWidgetSetting("with_x", Text.translatable("widgets.widgets.speed.withX"), true),
|
new ToggleWidgetSetting("with_x", Component.translatable("widgets.widgets.speed.withX"), true),
|
||||||
new ToggleWidgetSetting("with_y", Text.translatable("widgets.widgets.speed.withY"), false),
|
new ToggleWidgetSetting("with_y", Component.translatable("widgets.widgets.speed.withY"), false),
|
||||||
new ToggleWidgetSetting("with_z", Text.translatable("widgets.widgets.speed.withZ"), true),
|
new ToggleWidgetSetting("with_z", Component.translatable("widgets.widgets.speed.withZ"), true),
|
||||||
new IntSliderWidgetSetting("digits", Text.translatable("widgets.widgets.speed.digits"), 0, 1, 3),
|
new IntSliderWidgetSetting("digits", Component.translatable("widgets.widgets.speed.digits"), 0, 1, 3),
|
||||||
new IntSliderWidgetSetting("window_size", Text.translatable("widgets.widgets.speed.windowSize"), 3, 10, 60)
|
new IntSliderWidgetSetting("window_size", Component.translatable("widgets.widgets.speed.windowSize"), 3, 10, 60)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,19 +53,19 @@ public class SpeedWidget extends BasicTextWidget {
|
|||||||
private double[] averagingWindow = new double[10];
|
private double[] averagingWindow = new double[10];
|
||||||
private int windowPointer = 0;
|
private int windowPointer = 0;
|
||||||
|
|
||||||
private Vec3d lastPos = new Vec3d(0, 0, 0);
|
private Vec3 lastPos = new Vec3(0, 0, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Vec3d lastPos = this.lastPos;
|
Vec3 lastPos = this.lastPos;
|
||||||
Vec3d newPos = this.lastPos = player.getEntityPos();
|
Vec3 newPos = this.lastPos = player.position();
|
||||||
Vec3d velocity = lastPos.subtract(newPos);
|
Vec3 velocity = lastPos.subtract(newPos);
|
||||||
double rt = 0;
|
double rt = 0;
|
||||||
if (withXVelocity) rt += velocity.getX() * velocity.getX();
|
if (withXVelocity) rt += velocity.x() * velocity.x();
|
||||||
if (withYVelocity) rt += velocity.getY() * velocity.getY();
|
if (withYVelocity) rt += velocity.y() * velocity.y();
|
||||||
if (withZVelocity) rt += velocity.getZ() * velocity.getZ();
|
if (withZVelocity) rt += velocity.z() * velocity.z();
|
||||||
averagingWindow[windowPointer++] = switch (unit){
|
averagingWindow[windowPointer++] = switch (unit){
|
||||||
case METERS_PER_SECOND, BLOCKS_PER_SECOND -> Math.sqrt(rt) * WidgetUtils.getClientTickRate();
|
case METERS_PER_SECOND, BLOCKS_PER_SECOND -> Math.sqrt(rt) * WidgetUtils.getClientTickRate();
|
||||||
case CENTIMETERS_PER_TICK -> Math.sqrt(rt) * 100;
|
case CENTIMETERS_PER_TICK -> Math.sqrt(rt) * 100;
|
||||||
@@ -86,13 +85,13 @@ public class SpeedWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return Text.translatable("widgets.widgets.speed");
|
return Component.translatable("widgets.widgets.speed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return Text.translatable("widgets.widgets.speed.description");
|
return Component.translatable("widgets.widgets.speed.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,15 +5,14 @@ import de.shiewk.widgets.WidgetsMod;
|
|||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.widgets.settings.IntSliderWidgetSetting;
|
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.server.ServerTickManager;
|
|
||||||
import net.minecraft.server.integrated.IntegratedServer;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.server.IntegratedServer;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.server.ServerTickRateManager;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.translatable;
|
import static net.minecraft.network.chat.Component.translatable;
|
||||||
|
|
||||||
public class TPSWidget extends BasicTextWidget {
|
public class TPSWidget extends BasicTextWidget {
|
||||||
private TPSWidget(Identifier id) {
|
private TPSWidget(Identifier id) {
|
||||||
@@ -25,7 +24,7 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
getSettings().optionById("textcolor").setShowCondition(() -> !this.dynamicColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final TPSWidget INSTANCE = new TPSWidget(Identifier.of(WidgetsMod.MOD_ID, "tps"));
|
public static final TPSWidget INSTANCE = new TPSWidget(Identifier.fromNamespaceAndPath(WidgetsMod.MOD_ID, "tps"));
|
||||||
|
|
||||||
private static long[] lastUpdates = new long[5];
|
private static long[] lastUpdates = new long[5];
|
||||||
private static int updatePointer = 0;
|
private static int updatePointer = 0;
|
||||||
@@ -40,13 +39,13 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void worldTimeUpdated(long nanoTime) {
|
public static void worldTimeUpdated(long nanoTime) {
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
Minecraft client = Minecraft.getInstance();
|
||||||
if (client.isInSingleplayer()){
|
if (client.isLocalServer()){
|
||||||
IntegratedServer server = client.getServer();
|
IntegratedServer server = client.getSingleplayerServer();
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
ServerTickManager tickManager = server.getTickManager();
|
ServerTickRateManager tickManager = server.tickRateManager();
|
||||||
float tps = 1000f / server.getAverageTickTime();
|
float tps = 1000f / server.getCurrentSmoothedTickTime();
|
||||||
float targetTickRate = tickManager.getTickRate();
|
float targetTickRate = tickManager.tickrate();
|
||||||
if (tickManager.isSprinting()){
|
if (tickManager.isSprinting()){
|
||||||
INSTANCE.updateTPS(tps, targetTickRate, true);
|
INSTANCE.updateTPS(tps, targetTickRate, true);
|
||||||
} else {
|
} else {
|
||||||
@@ -70,8 +69,8 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
float ticksPerSecond = 1000f / mspt;
|
float ticksPerSecond = 1000f / mspt;
|
||||||
|
|
||||||
boolean loadingFinished = updatesSinceWorldChange > lastUpdates.length;
|
boolean loadingFinished = updatesSinceWorldChange > lastUpdates.length;
|
||||||
if (client.world != null) {
|
if (client.level != null) {
|
||||||
INSTANCE.updateTPS(ticksPerSecond, client.world.getTickManager().getTickRate(), loadingFinished);
|
INSTANCE.updateTPS(ticksPerSecond, client.level.tickRateManager().tickrate(), loadingFinished);
|
||||||
} else {
|
} else {
|
||||||
INSTANCE.updateTPS(ticksPerSecond, 20, loadingFinished);
|
INSTANCE.updateTPS(ticksPerSecond, 20, loadingFinished);
|
||||||
}
|
}
|
||||||
@@ -111,12 +110,12 @@ public class TPSWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.tps");
|
return translatable("widgets.widgets.tps");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.tps.description");
|
return translatable("widgets.widgets.tps.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package de.shiewk.widgets.widgets;
|
|||||||
import de.shiewk.widgets.WidgetSettings;
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.EnumWidgetSetting;
|
||||||
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.text.Text.*;
|
import static net.minecraft.network.chat.Component.*;
|
||||||
|
|
||||||
public class WorldTimeWidget extends BasicTextWidget {
|
public class WorldTimeWidget extends BasicTextWidget {
|
||||||
|
|
||||||
@@ -30,11 +30,11 @@ public class WorldTimeWidget extends BasicTextWidget {
|
|||||||
protected boolean showDay;
|
protected boolean showDay;
|
||||||
protected ClockWidget.TimeOption timeFormat;
|
protected ClockWidget.TimeOption timeFormat;
|
||||||
|
|
||||||
public Text getDayLabel(long day) {
|
public Component getDayLabel(long day) {
|
||||||
return translatable("widgets.widgets.worldtime.day", day);
|
return translatable("widgets.widgets.worldtime.day", day);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Text getTimeLabel(long hour, long minute) {
|
public Component getTimeLabel(long hour, long minute) {
|
||||||
return switch (timeFormat) {
|
return switch (timeFormat) {
|
||||||
case NO_TIME -> empty();
|
case NO_TIME -> empty();
|
||||||
case HOUR_24 -> literal(hour + ":" + (minute < 10 ? "0" + minute : minute));
|
case HOUR_24 -> literal(hour + ":" + (minute < 10 ? "0" + minute : minute));
|
||||||
@@ -48,11 +48,11 @@ public class WorldTimeWidget extends BasicTextWidget {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickWidget() {
|
public void tickWidget() {
|
||||||
final World world = MinecraftClient.getInstance().world;
|
final Level world = Minecraft.getInstance().level;
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
formatAndSetRenderText("?");
|
formatAndSetRenderText("?");
|
||||||
} else {
|
} else {
|
||||||
long time = world.getTimeOfDay() + 6000;
|
long time = world.getGameTime() + 6000;
|
||||||
long day = time / 24000;
|
long day = time / 24000;
|
||||||
long hour = time / 1000 % 24;
|
long hour = time / 1000 % 24;
|
||||||
long minute = (long) ((time % 1000) / 16.6666);
|
long minute = (long) ((time % 1000) / 16.6666);
|
||||||
@@ -76,12 +76,12 @@ public class WorldTimeWidget extends BasicTextWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Component getName() {
|
||||||
return translatable("widgets.widgets.worldtime");
|
return translatable("widgets.widgets.worldtime");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getDescription() {
|
public Component getDescription() {
|
||||||
return translatable("widgets.widgets.worldtime.description");
|
return translatable("widgets.widgets.worldtime.description");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package de.shiewk.widgets.widgets.settings;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -18,12 +19,12 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption<T>
|
|||||||
|
|
||||||
private final Class<T> enumClass;
|
private final Class<T> enumClass;
|
||||||
private T value;
|
private T value;
|
||||||
private final Function<T, Text> enumNameGetter;
|
private final Function<T, Component> enumNameGetter;
|
||||||
private int height = 0;
|
private int height = 0;
|
||||||
private boolean mouseClick = false;
|
private boolean mouseClick = false;
|
||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
|
|
||||||
public EnumWidgetSetting(String id, Text name, Class<T> enumClass, T defaultValue, Function<T, Text> enumNameGetter) {
|
public EnumWidgetSetting(String id, Component name, Class<T> enumClass, T defaultValue, Function<T, Component> enumNameGetter) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.enumClass = enumClass;
|
this.enumClass = enumClass;
|
||||||
this.value = defaultValue;
|
this.value = defaultValue;
|
||||||
@@ -58,28 +59,28 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption<T>
|
|||||||
COLOR_TEXT = new Color(255, 255, 255, 255).getRGB();
|
COLOR_TEXT = new Color(255, 255, 255, 255).getRGB();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
final Font textRenderer = Minecraft.getInstance().font;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int nx = 5;
|
int nx = 5;
|
||||||
final int bx = getX() + getWidth();
|
final int bx = getX() + getWidth();
|
||||||
for (T constant : enumClass.getEnumConstants()) {
|
for (T constant : enumClass.getEnumConstants()) {
|
||||||
final Text name = enumNameGetter.apply(constant);
|
final Component name = enumNameGetter.apply(constant);
|
||||||
final int textRendererWidth = textRenderer.getWidth(name);
|
final int textRendererWidth = textRenderer.width(name);
|
||||||
if (nx != 5 && nx + textRendererWidth + 20 > this.getWidth()){
|
if (nx != 5 && nx + textRendererWidth + 20 > this.getWidth()){
|
||||||
y += 24;
|
y += 24;
|
||||||
nx = 5;
|
nx = 5;
|
||||||
}
|
}
|
||||||
final boolean hover = mouseX <= bx - nx && mouseX >= bx - nx - 10 - textRendererWidth && mouseY <= y + 19 + getY() && mouseY >= y + getY();
|
final boolean hover = mouseX <= bx - nx && mouseX >= bx - nx - 10 - textRendererWidth && mouseY <= y + 19 + getY() && mouseY >= y + getY();
|
||||||
context.fill(bx - 10 - textRendererWidth - nx, y + getY(), bx - nx, y + 19 + getY(), constant == value ? COLOR_SELECTED : hover ? COLOR_UNSELECTED_HOVER : COLOR_UNSELECTED);
|
context.fill(bx - 10 - textRendererWidth - nx, y + getY(), bx - nx, y + 19 + getY(), constant == value ? COLOR_SELECTED : hover ? COLOR_UNSELECTED_HOVER : COLOR_UNSELECTED);
|
||||||
context.drawText(textRenderer, name, bx - nx - 5 - textRendererWidth, y + 5 + getY(), COLOR_TEXT, true);
|
context.text(textRenderer, name, bx - nx - 5 - textRendererWidth, y + 5 + getY(), COLOR_TEXT, true);
|
||||||
if (hover && mouseClick){
|
if (hover && mouseClick){
|
||||||
this.value = constant;
|
this.value = constant;
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
WidgetUtils.playSound(SoundEvents.COPPER_BULB_TURN_ON);
|
||||||
}
|
}
|
||||||
if (hover){
|
if (hover){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
}
|
}
|
||||||
nx += textRendererWidth + 20;
|
nx += textRendererWidth + 20;
|
||||||
}
|
}
|
||||||
@@ -89,13 +90,13 @@ public class EnumWidgetSetting<T extends Enum<T>> extends WidgetSettingOption<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
mouseClick = true;
|
mouseClick = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(MouseButtonEvent click) {
|
||||||
mouseClick = false;
|
mouseClick = false;
|
||||||
boolean changed = this.changed;
|
boolean changed = this.changed;
|
||||||
this.changed = false;
|
this.changed = false;
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
package de.shiewk.widgets.widgets.settings;
|
package de.shiewk.widgets.widgets.settings;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.client.screen.WidgetSettingsScreen;
|
import de.shiewk.widgets.client.screen.WidgetSettingsScreen;
|
||||||
import de.shiewk.widgets.client.screen.gradienteditor.GradientEditorScreen;
|
import de.shiewk.widgets.client.screen.gradienteditor.GradientEditorScreen;
|
||||||
import de.shiewk.widgets.color.GradientMode;
|
import de.shiewk.widgets.color.GradientMode;
|
||||||
import de.shiewk.widgets.color.GradientOptions;
|
import de.shiewk.widgets.color.GradientOptions;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import static de.shiewk.widgets.client.WidgetManager.gson;
|
import static de.shiewk.widgets.client.WidgetManager.gson;
|
||||||
import static de.shiewk.widgets.utils.WidgetUtils.colorARGBToHexRGBA;
|
import static de.shiewk.widgets.utils.WidgetUtils.colorARGBToHexRGBA;
|
||||||
|
|
||||||
public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions> {
|
public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions> {
|
||||||
|
|
||||||
public GradientWidgetSetting(String id, Text name, GradientMode defaultMode, int defaultGradientSize, int defaultGradientSpeed, int defaultColor) {
|
public GradientWidgetSetting(String id, Component name, GradientMode defaultMode, int defaultGradientSize, int defaultGradientSpeed, int defaultColor) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.value = new GradientOptions(
|
this.value = new GradientOptions(
|
||||||
defaultMode,
|
defaultMode,
|
||||||
@@ -30,7 +31,7 @@ public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GradientWidgetSetting(String id, Text name, int defaultColor) {
|
public GradientWidgetSetting(String id, Component name, int defaultColor) {
|
||||||
this(id, name, GradientMode.SWEEP, 40, 10, defaultColor);
|
this(id, name, GradientMode.SWEEP, 40, 10, defaultColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,9 +62,9 @@ public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float deltaTicks) {
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
final Font textRenderer = Minecraft.getInstance().font;
|
||||||
final long n = Util.getMeasuringTimeNano();
|
final long n = Util.getNanos();
|
||||||
GradientOptions gradient = this.getValue();
|
GradientOptions gradient = this.getValue();
|
||||||
gradient.fillHorizontal(
|
gradient.fillHorizontal(
|
||||||
context,
|
context,
|
||||||
@@ -81,15 +82,15 @@ public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions>
|
|||||||
displayText = "#" + colorARGBToHexRGBA(colors[0]);
|
displayText = "#" + colorARGBToHexRGBA(colors[0]);
|
||||||
} else {
|
} else {
|
||||||
outlineColor = 0xff_ff_ff_ff;
|
outlineColor = 0xff_ff_ff_ff;
|
||||||
displayText = Text.translatable("widgets.ui.widgetSettings.colors", colors.length).getString();
|
displayText = Component.translatable("widgets.ui.widgetSettings.colors", colors.length).getString();
|
||||||
}
|
}
|
||||||
context.drawHorizontalLine(getX(), getX()+getWidth(), getY(), outlineColor);
|
context.horizontalLine(getX(), getX()+getWidth(), getY(), outlineColor);
|
||||||
context.drawHorizontalLine(getX(), getX()+getWidth(), getY()+getHeight(), outlineColor);
|
context.horizontalLine(getX(), getX()+getWidth(), getY()+getHeight(), outlineColor);
|
||||||
context.drawVerticalLine(getX(), getY(), getY() + getHeight(), outlineColor);
|
context.verticalLine(getX(), getY(), getY() + getHeight(), outlineColor);
|
||||||
context.drawVerticalLine(getX() + getWidth(), getY(), getY() + getHeight(), outlineColor);
|
context.verticalLine(getX() + getWidth(), getY(), getY() + getHeight(), outlineColor);
|
||||||
|
|
||||||
int width = textRenderer.getWidth(displayText);
|
int width = textRenderer.width(displayText);
|
||||||
context.drawText(
|
context.text(
|
||||||
textRenderer,
|
textRenderer,
|
||||||
displayText,
|
displayText,
|
||||||
getX() + (getWidth() / 2 - (width / 2)),
|
getX() + (getWidth() / 2 - (width / 2)),
|
||||||
@@ -99,7 +100,7 @@ public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions>
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (this.isHovered(mouseX, mouseY)){
|
if (this.isHovered(mouseX, mouseY)){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +115,11 @@ public class GradientWidgetSetting extends WidgetSettingOption<GradientOptions>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
Minecraft client = Minecraft.getInstance();
|
||||||
if (client.currentScreen instanceof WidgetSettingsScreen screen) {
|
if (client.screen instanceof WidgetSettingsScreen screen) {
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
WidgetUtils.playSound(SoundEvents.COPPER_BULB_TURN_ON);
|
||||||
client.setScreen(new GradientEditorScreen(client.currentScreen, screen.getWidget(), this, screen.getOnChange()));
|
client.setScreen(new GradientEditorScreen(client.screen, screen.getWidget(), this, screen.getOnChange()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package de.shiewk.widgets.widgets.settings;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
import net.minecraft.client.input.KeyInput;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.Mth;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
||||||
@@ -20,7 +20,7 @@ public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
|||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
private boolean clicked = false;
|
private boolean clicked = false;
|
||||||
|
|
||||||
public IntSliderWidgetSetting(String id, Text name, int minValue, int defaultValue, int maxValue) {
|
public IntSliderWidgetSetting(String id, Component name, int minValue, int defaultValue, int maxValue) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.value = defaultValue;
|
this.value = defaultValue;
|
||||||
this.minValue = minValue;
|
this.minValue = minValue;
|
||||||
@@ -28,7 +28,7 @@ public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(KeyInput input) {
|
public boolean keyPressed(KeyEvent input) {
|
||||||
if (maxValue > value && input.isRight()) {
|
if (maxValue > value && input.isRight()) {
|
||||||
value++;
|
value++;
|
||||||
return true;
|
return true;
|
||||||
@@ -52,28 +52,28 @@ public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int valueToXPos(int value){
|
private int valueToXPos(int value){
|
||||||
return MathHelper.lerp((float) (value - minValue) / (maxValue - minValue), getX() + 5, getX() + 155);
|
return Mth.lerpInt((float) (value - minValue) / (maxValue - minValue), getX() + 5, getX() + 155);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int xPosToValue(int xpos){
|
private int xPosToValue(int xpos){
|
||||||
return MathHelper.lerp((xpos - getX() - 5) / 150f, minValue, maxValue);
|
return Mth.lerpInt((xpos - getX() - 5) / 150f, minValue, maxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
int xp = valueToXPos(getValue());
|
int xp = valueToXPos(getValue());
|
||||||
context.drawHorizontalLine(getX() + 5, getX() + 155, getY() + 6, 0xffffffff);
|
context.horizontalLine(getX() + 5, getX() + 155, getY() + 6, 0xffffffff);
|
||||||
context.drawVerticalLine(getX() + 4, getY() + 3, getY() + 10, 0xffffffff);
|
context.verticalLine(getX() + 4, getY() + 3, getY() + 10, 0xffffffff);
|
||||||
context.drawVerticalLine(getX() + 155, getY() + 3, getY() + 10, 0xffffffff);
|
context.verticalLine(getX() + 155, getY() + 3, getY() + 10, 0xffffffff);
|
||||||
context.fill(xp-2, getY() + 3, xp+2, getY() + 10, 0xffffffff);
|
context.fill(xp-2, getY() + 3, xp+2, getY() + 10, 0xffffffff);
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
final Font textRenderer = Minecraft.getInstance().font;
|
||||||
context.drawText(textRenderer, String.valueOf(getValue()), getX() + 160, getY() + 3, 0xffffffff, true);
|
context.text(textRenderer, String.valueOf(getValue()), getX() + 160, getY() + 3, 0xffffffff, true);
|
||||||
if (clicked){
|
if (clicked){
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
this.value = MathHelper.clamp(xPosToValue(mouseX), minValue, maxValue);
|
this.value = Mth.clamp(xPosToValue(mouseX), minValue, maxValue);
|
||||||
}
|
}
|
||||||
if (isHovering(mouseX, mouseY)){
|
if (isHovering(mouseX, mouseY)){
|
||||||
context.setCursor(StandardCursors.RESIZE_EW);
|
context.requestCursor(CursorTypes.RESIZE_EW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +85,13 @@ public class IntSliderWidgetSetting extends WidgetSettingOption<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
this.clicked = true;
|
this.clicked = true;
|
||||||
return super.mouseClicked(click, doubled);
|
return super.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(MouseButtonEvent click) {
|
||||||
this.clicked = false;
|
this.clicked = false;
|
||||||
boolean t = this.changed;
|
boolean t = this.changed;
|
||||||
this.changed = false;
|
this.changed = false;
|
||||||
|
|||||||
@@ -1,349 +0,0 @@
|
|||||||
package de.shiewk.widgets.widgets.settings;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import de.shiewk.widgets.client.screen.WidgetVisibilityToggle;
|
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.font.TextRenderer;
|
|
||||||
import net.minecraft.client.gui.Click;
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
|
||||||
import net.minecraft.client.input.KeyInput;
|
|
||||||
import net.minecraft.sound.SoundEvents;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link GradientWidgetSetting}
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.3.0")
|
|
||||||
public class RGBAColorWidgetSetting extends WidgetSettingOption<Integer> {
|
|
||||||
public RGBAColorWidgetSetting(String id, Text name, int defaultR, int defaultG, int defaultB, int defaultAlpha) {
|
|
||||||
super(id, name);
|
|
||||||
this.r = defaultR;
|
|
||||||
this.g = defaultG;
|
|
||||||
this.b = defaultB;
|
|
||||||
this.a = defaultAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int r;
|
|
||||||
private int g;
|
|
||||||
private int b;
|
|
||||||
private int a;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonElement saveState() {
|
|
||||||
return new JsonPrimitive(getColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColor(){
|
|
||||||
return a << 24 | r << 16 | g << 8 | b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Integer getValue(){
|
|
||||||
return getColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadState(JsonElement state) {
|
|
||||||
if (state.isJsonPrimitive() && state.getAsJsonPrimitive().isNumber()){
|
|
||||||
final Color color = new Color(state.getAsJsonPrimitive().getAsInt(), true);
|
|
||||||
this.r = color.getRed();
|
|
||||||
this.g = color.getGreen();
|
|
||||||
this.b = color.getBlue();
|
|
||||||
this.a = color.getAlpha();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return 72;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return 24;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
||||||
final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
|
||||||
context.fill(
|
|
||||||
getX(),
|
|
||||||
getY(),
|
|
||||||
getX() + getWidth(),
|
|
||||||
getY() + getHeight(),
|
|
||||||
getColor()
|
|
||||||
);
|
|
||||||
context.drawHorizontalLine(getX(), getX()+getWidth(), getY(), getColor() | 0xff_00_00_00);
|
|
||||||
context.drawHorizontalLine(getX(), getX()+getWidth(), getY()+getHeight(), getColor() | 0xff_00_00_00);
|
|
||||||
context.drawVerticalLine(getX(), getY(), getY() + getHeight(), getColor() | 0xff_00_00_00);
|
|
||||||
context.drawVerticalLine(getX() + getWidth(), getY(), getY() + getHeight(), getColor() | 0xff_00_00_00);
|
|
||||||
|
|
||||||
String colorText = "#" + toHexString();
|
|
||||||
int width = textRenderer.getWidth(colorText);
|
|
||||||
context.drawText(
|
|
||||||
textRenderer,
|
|
||||||
colorText,
|
|
||||||
getX() + (getWidth() / 2 - (width / 2)),
|
|
||||||
getY() + (getHeight() / 2 - 4),
|
|
||||||
0xff_ff_ff_ff,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.isHovered(mouseX, mouseY)){
|
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String toHexSingle(int comp){
|
|
||||||
String s = Integer.toHexString(comp);
|
|
||||||
return "0".repeat(2 - s.length()) + s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toHexString() {
|
|
||||||
return toHexSingle(r) + toHexSingle(g) + toHexSingle(b) + toHexSingle(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_ON);
|
|
||||||
client.setScreen(
|
|
||||||
new ChangeScreen(client.currentScreen, (int) client.mouse.getScaledX(client.getWindow()), (int) client.mouse.getScaledY(client.getWindow()))
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ChangeScreen extends Screen implements WidgetVisibilityToggle {
|
|
||||||
|
|
||||||
private final Screen parent;
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
|
|
||||||
protected ChangeScreen(Screen parent, int x, int y) {
|
|
||||||
super(Text.empty());
|
|
||||||
this.parent = parent;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int PADDING = 16;
|
|
||||||
private static final int BAR_WIDTH = 18;
|
|
||||||
private static final int BAR_HEIGHT = 127 + 20;
|
|
||||||
|
|
||||||
private static final int RECT_WIDTH = 5 * PADDING + 4 * BAR_WIDTH;
|
|
||||||
private static final int RECT_HEIGHT = 2 * PADDING + BAR_HEIGHT;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
if (y + RECT_HEIGHT > height){
|
|
||||||
y = height - RECT_HEIGHT;
|
|
||||||
}
|
|
||||||
if (x + RECT_WIDTH > width){
|
|
||||||
x = width - RECT_WIDTH;
|
|
||||||
}
|
|
||||||
// Color components
|
|
||||||
// Red color
|
|
||||||
addDrawableChild(new ColorBar(
|
|
||||||
x + PADDING,
|
|
||||||
y + PADDING,
|
|
||||||
BAR_WIDTH,
|
|
||||||
BAR_HEIGHT,
|
|
||||||
0
|
|
||||||
));
|
|
||||||
// Green color
|
|
||||||
addDrawableChild(new ColorBar(
|
|
||||||
x + 2* PADDING + BAR_WIDTH,
|
|
||||||
y + PADDING,
|
|
||||||
BAR_WIDTH,
|
|
||||||
BAR_HEIGHT,
|
|
||||||
1
|
|
||||||
));
|
|
||||||
// Blue color
|
|
||||||
addDrawableChild(new ColorBar(
|
|
||||||
x + 3* PADDING + 2* BAR_WIDTH,
|
|
||||||
y + PADDING,
|
|
||||||
BAR_WIDTH,
|
|
||||||
BAR_HEIGHT,
|
|
||||||
2
|
|
||||||
));
|
|
||||||
// Alpha
|
|
||||||
addDrawableChild(new ColorBar(
|
|
||||||
x + 4* PADDING + 3* BAR_WIDTH,
|
|
||||||
y + PADDING,
|
|
||||||
BAR_WIDTH,
|
|
||||||
BAR_HEIGHT,
|
|
||||||
3
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
|
||||||
parent.render(context, 0, 0, deltaTicks);
|
|
||||||
context.fill(x, y, x+ RECT_WIDTH, y+ RECT_HEIGHT,0xc0_00_00_00);
|
|
||||||
context.drawStrokedRectangle(x, y, RECT_WIDTH, RECT_HEIGHT, 0x67_ff_ff_ff);
|
|
||||||
super.render(context, mouseX, mouseY, deltaTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
client.setScreen(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
|
||||||
if (click.x() < x || click.y() < y || click.x() > x + RECT_WIDTH || click.y() > y + RECT_HEIGHT){
|
|
||||||
close();
|
|
||||||
WidgetUtils.playSound(SoundEvents.BLOCK_COPPER_BULB_TURN_OFF);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return super.mouseClicked(click, doubled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldRenderWidgets() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ColorBar extends ClickableWidget {
|
|
||||||
|
|
||||||
private final int component;
|
|
||||||
|
|
||||||
public ColorBar(int x, int y, int width, int height, int component) {
|
|
||||||
super(x, y, width, height, Text.empty());
|
|
||||||
this.component = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
|
|
||||||
if (isHovered()){
|
|
||||||
setValue((int) (getValue() + verticalAmount * 2));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getValue(){
|
|
||||||
return switch (component){
|
|
||||||
case 0 -> RGBAColorWidgetSetting.this.r; // Red
|
|
||||||
case 1 -> RGBAColorWidgetSetting.this.g; // Green
|
|
||||||
case 2 -> RGBAColorWidgetSetting.this.b; // Blue
|
|
||||||
case 3 -> RGBAColorWidgetSetting.this.a; // Alpha
|
|
||||||
default -> throw new IllegalStateException("Component out of range: " + component);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(int val){
|
|
||||||
val = MathHelper.clamp(val, 0, 255);
|
|
||||||
switch (component){
|
|
||||||
case 0 -> RGBAColorWidgetSetting.this.r = val; // Red
|
|
||||||
case 1 -> RGBAColorWidgetSetting.this.g = val; // Green
|
|
||||||
case 2 -> RGBAColorWidgetSetting.this.b = val; // Blue
|
|
||||||
case 3 -> RGBAColorWidgetSetting.this.a = val; // Alpha
|
|
||||||
default -> throw new IllegalStateException("Component out of range: " + component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
|
|
||||||
context.fillGradient(
|
|
||||||
getX() + 2,
|
|
||||||
getY() + 10,
|
|
||||||
getX() + getWidth() - 2,
|
|
||||||
getY() + getHeight() - 10,
|
|
||||||
topColor(),
|
|
||||||
bottomColor()
|
|
||||||
);
|
|
||||||
context.drawHorizontalLine(
|
|
||||||
getX(),
|
|
||||||
getX() + getWidth() - 1,
|
|
||||||
getY() + 10 + (255 - getValue()) / 2,
|
|
||||||
0xffffffff
|
|
||||||
);
|
|
||||||
{
|
|
||||||
String text = ""+getValue();
|
|
||||||
int textWidth = textRenderer.getWidth(text);
|
|
||||||
context.drawText(textRenderer, text, getX() + (getWidth() / 2 - textWidth / 2), getY() - 2, 0xffffffff, true);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
String text = componentLabel();
|
|
||||||
int textWidth = textRenderer.getWidth(text);
|
|
||||||
context.drawText(textRenderer, text, getX() + (getWidth() / 2 - textWidth / 2), getY() + 142, 0xffffffff, true);
|
|
||||||
}
|
|
||||||
if (isHovered()){
|
|
||||||
context.setCursor(StandardCursors.RESIZE_NS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String componentLabel() {
|
|
||||||
return switch (component){
|
|
||||||
case 0 -> "R"; // Red
|
|
||||||
case 1 -> "G"; // Green
|
|
||||||
case 2 -> "B"; // Blue
|
|
||||||
case 3 -> "A"; // Alpha
|
|
||||||
default -> throw new IllegalStateException("Component out of range: " + component);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
|
||||||
return this.mouseDragged(click, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
|
||||||
if (isHovered()){
|
|
||||||
double pos = click.y() - this.getY() - 10;
|
|
||||||
int val = (int) (255 - pos * 2);
|
|
||||||
setValue(val);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int componentMask(){
|
|
||||||
return switch (component){
|
|
||||||
case 0 -> 0x00_ff_00_00; // Red
|
|
||||||
case 1 -> 0x00_00_ff_00; // Green
|
|
||||||
case 2 -> 0x00_00_00_ff; // Blue
|
|
||||||
case 3 -> 0xff_00_00_00; // Alpha
|
|
||||||
default -> throw new IllegalStateException("Component out of range: " + component);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed(KeyInput input) {
|
|
||||||
if (input.isUp()) {
|
|
||||||
setValue(getValue() + 1);
|
|
||||||
return true;
|
|
||||||
} else if (input.isDown()) {
|
|
||||||
setValue(getValue() - 1);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return super.keyPressed(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int bottomColor() {
|
|
||||||
return RGBAColorWidgetSetting.this.getColor() & ~componentMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int topColor() {
|
|
||||||
return RGBAColorWidgetSetting.this.getColor() | componentMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-25
@@ -3,20 +3,21 @@ package de.shiewk.widgets.widgets.settings;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import de.shiewk.widgets.WidgetsMod;
|
import de.shiewk.widgets.WidgetsMod;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.input.CharacterEvent;
|
||||||
import net.minecraft.client.input.CharInput;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
import net.minecraft.client.input.KeyInput;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
||||||
|
|
||||||
private TextField textField = null;
|
private TextField textField = null;
|
||||||
private final Text initialValue;
|
private final Component initialValue;
|
||||||
private final Text placeholder;
|
private final Component placeholder;
|
||||||
private final boolean trim;
|
private final boolean trim;
|
||||||
private final int maxLength;
|
private final int maxLength;
|
||||||
private String value = "";
|
private String value = "";
|
||||||
@@ -25,11 +26,11 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TextField extends TextFieldWidget {
|
public class TextField extends EditBox {
|
||||||
|
|
||||||
public TextField(TextRenderer textRenderer, int width, int height, Text text) {
|
public TextField(Font textRenderer, int width, int height, Component text) {
|
||||||
super(textRenderer, width, height, text);
|
super(textRenderer, width, height, text);
|
||||||
this.setChangedListener(value -> TextFieldWidgetSettingOption.this.setValue(TextFieldWidgetSettingOption.this.trim ? value.trim() : value));
|
this.setResponder(value -> TextFieldWidgetSettingOption.this.setValue(TextFieldWidgetSettingOption.this.trim ? value.trim() : value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +39,7 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextFieldWidgetSettingOption(String id, Text name, Text initialValue, Text placeholder, boolean trim, int maxLength) {
|
public TextFieldWidgetSettingOption(String id, Component name, Component initialValue, Component placeholder, boolean trim, int maxLength) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.initialValue = initialValue;
|
this.initialValue = initialValue;
|
||||||
this.placeholder = placeholder;
|
this.placeholder = placeholder;
|
||||||
@@ -48,10 +49,10 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
|||||||
|
|
||||||
private void initializeTextField() {
|
private void initializeTextField() {
|
||||||
if (textField != null) return;
|
if (textField != null) return;
|
||||||
textField = new TextField(MinecraftClient.getInstance().textRenderer, this.getWidth(), this.getHeight(), Text.empty());
|
textField = new TextField(Minecraft.getInstance().font, this.getWidth(), this.getHeight(), Component.empty());
|
||||||
textField.setPlaceholder(placeholder);
|
textField.setHint(placeholder);
|
||||||
textField.setMaxLength(maxLength);
|
textField.setMaxLength(maxLength);
|
||||||
textField.setText(value.isEmpty() ? initialValue.getString() : value);
|
textField.setValue(value.isEmpty() ? initialValue.getString() : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,7 +68,7 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void loadState(JsonElement state) {
|
public void loadState(JsonElement state) {
|
||||||
if (state.isJsonPrimitive() && state.getAsJsonPrimitive().isString()){
|
if (state.isJsonPrimitive() && state.getAsJsonPrimitive().isString()){
|
||||||
if (textField != null) textField.setText(state.getAsString());
|
if (textField != null) textField.setValue(state.getAsString());
|
||||||
this.value = state.getAsString();
|
this.value = state.getAsString();
|
||||||
} else {
|
} else {
|
||||||
WidgetsMod.LOGGER.warn("Failed to load text field widget setting option for state {}", state);
|
WidgetsMod.LOGGER.warn("Failed to load text field widget setting option for state {}", state);
|
||||||
@@ -89,33 +90,33 @@ public class TextFieldWidgetSettingOption extends WidgetSettingOption<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(@NonNull GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
initializeTextField();
|
initializeTextField();
|
||||||
textField.render(context, mouseX, mouseY, delta);
|
textField.extractRenderState(context, mouseX, mouseY, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
return isFocused() && textField.mouseClicked(click, doubled);
|
return isFocused() && textField.mouseClicked(click, doubled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(Click click) {
|
public boolean mouseReleased(MouseButtonEvent click) {
|
||||||
return isFocused() && textField.mouseReleased(click);
|
return isFocused() && textField.mouseReleased(click);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean charTyped(CharInput input) {
|
public boolean charTyped(CharacterEvent input) {
|
||||||
return isFocused() && textField.charTyped(input);
|
return isFocused() && textField.charTyped(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(KeyInput input) {
|
public boolean keyPressed(KeyEvent input) {
|
||||||
return isFocused() && textField.keyPressed(input);
|
return isFocused() && textField.keyPressed(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyReleased(KeyInput input) {
|
public boolean keyReleased(KeyEvent input) {
|
||||||
return isFocused() && textField.keyReleased(input);
|
return isFocused() && textField.keyReleased(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package de.shiewk.widgets.widgets.settings;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.mojang.blaze3d.platform.cursor.CursorTypes;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.gui.Click;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.client.gui.cursor.StandardCursors;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -19,7 +19,7 @@ public class ToggleWidgetSetting extends WidgetSettingOption<Boolean> {
|
|||||||
private boolean value;
|
private boolean value;
|
||||||
private long toggleTime = 0;
|
private long toggleTime = 0;
|
||||||
|
|
||||||
public ToggleWidgetSetting(String id, Text name, boolean defaultValue) {
|
public ToggleWidgetSetting(String id, Component name, boolean defaultValue) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.value = defaultValue;
|
this.value = defaultValue;
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,11 @@ public class ToggleWidgetSetting extends WidgetSettingOption<Boolean> {
|
|||||||
COLOR_DISABLED_THUMB = new Color(255, 200, 200, 255).getRGB();
|
COLOR_DISABLED_THUMB = new Color(255, 200, 200, 255).getRGB();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
|
||||||
int col = value ? COLOR_ENABLED : COLOR_DISABLED;
|
int col = value ? COLOR_ENABLED : COLOR_DISABLED;
|
||||||
int thumb = value ? COLOR_ENABLED_THUMB : COLOR_DISABLED_THUMB;
|
int thumb = value ? COLOR_ENABLED_THUMB : COLOR_DISABLED_THUMB;
|
||||||
int thumbLoc = (Util.getMeasuringTimeNano() - toggleTime) < 300000000f ?
|
int thumbLoc = (Util.getNanos() - toggleTime) < 300000000f ?
|
||||||
(int) (getX() + MathHelper.lerp(WidgetUtils.computeEasing((Util.getMeasuringTimeNano() - toggleTime) / 300000000f),
|
(int) (getX() + Mth.lerp(WidgetUtils.computeEasing((Util.getNanos() - toggleTime) / 300000000f),
|
||||||
value ? 2 : getWidth() - 4 - 12,
|
value ? 2 : getWidth() - 4 - 12,
|
||||||
value ? getWidth() - 4 - 12 : 4))
|
value ? getWidth() - 4 - 12 : 4))
|
||||||
: value ? getX() + getWidth() - 4 - 12 : getX() + 4;
|
: value ? getX() + getWidth() - 4 - 12 : getX() + 4;
|
||||||
@@ -59,20 +59,20 @@ public class ToggleWidgetSetting extends WidgetSettingOption<Boolean> {
|
|||||||
context.fill(thumbLoc, getY() + 4, thumbLoc + 12, getY() + getHeight() - 4, thumb);
|
context.fill(thumbLoc, getY() + 4, thumbLoc + 12, getY() + getHeight() - 4, thumb);
|
||||||
|
|
||||||
if (this.isHovered(mouseX, mouseY)){
|
if (this.isHovered(mouseX, mouseY)){
|
||||||
context.setCursor(StandardCursors.POINTING_HAND);
|
context.requestCursor(CursorTypes.POINTING_HAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
toggle();
|
toggle();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggle(){
|
public void toggle(){
|
||||||
this.value = !value;
|
this.value = !value;
|
||||||
WidgetUtils.playSound(value ? SoundEvents.BLOCK_COPPER_BULB_TURN_ON : SoundEvents.BLOCK_COPPER_BULB_TURN_OFF);
|
WidgetUtils.playSound(value ? SoundEvents.COPPER_BULB_TURN_ON : SoundEvents.COPPER_BULB_TURN_OFF);
|
||||||
this.toggleTime = Util.getMeasuringTimeNano();
|
this.toggleTime = Util.getNanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,28 +2,28 @@ package de.shiewk.widgets.widgets.settings;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import de.shiewk.widgets.utils.WidgetUtils;
|
import de.shiewk.widgets.utils.WidgetUtils;
|
||||||
import net.minecraft.client.gui.Click;
|
|
||||||
import net.minecraft.client.gui.Drawable;
|
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
|
||||||
import net.minecraft.client.gui.widget.Widget;
|
|
||||||
import net.minecraft.client.input.CharInput;
|
|
||||||
import net.minecraft.client.input.KeyInput;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
|
import net.minecraft.client.gui.components.Renderable;
|
||||||
|
import net.minecraft.client.gui.layouts.LayoutElement;
|
||||||
|
import net.minecraft.client.input.CharacterEvent;
|
||||||
|
import net.minecraft.client.input.KeyEvent;
|
||||||
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
public abstract class WidgetSettingOption<T> implements Drawable, Widget {
|
public abstract class WidgetSettingOption<T> implements Renderable, LayoutElement {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final Text name;
|
private final Component name;
|
||||||
private int x = 0;
|
private int x = 0;
|
||||||
private int y = 0;
|
private int y = 0;
|
||||||
private int maxRenderWidth = 200; // this will always be changed before rendering
|
private int maxRenderWidth = 200; // this will always be changed before rendering
|
||||||
private boolean focused = false;
|
private boolean focused = false;
|
||||||
private BooleanSupplier shouldShow = WidgetUtils.TRUE_SUPPLIER;
|
private BooleanSupplier shouldShow = WidgetUtils.TRUE_SUPPLIER;
|
||||||
|
|
||||||
protected WidgetSettingOption(String id, Text name) {
|
protected WidgetSettingOption(String id, Component name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public abstract class WidgetSettingOption<T> implements Drawable, Widget {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Text getName() {
|
public final Component getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,23 +48,23 @@ public abstract class WidgetSettingOption<T> implements Drawable, Widget {
|
|||||||
public abstract void loadState(JsonElement state);
|
public abstract void loadState(JsonElement state);
|
||||||
public abstract T getValue();
|
public abstract T getValue();
|
||||||
|
|
||||||
public boolean mouseClicked(Click click, boolean doubled) {
|
public boolean mouseClicked(MouseButtonEvent click, boolean doubled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mouseReleased(Click click){
|
public boolean mouseReleased(MouseButtonEvent click){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean charTyped(CharInput input) {
|
public boolean charTyped(CharacterEvent input) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean keyPressed(KeyInput input) {
|
public boolean keyPressed(KeyEvent input) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean keyReleased(KeyInput input) {
|
public boolean keyReleased(KeyEvent input) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public abstract class WidgetSettingOption<T> implements Drawable, Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void forEachChild(Consumer<ClickableWidget> consumer) {
|
public final void visitWidgets(@NonNull Consumer<AbstractWidget> consumer) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"license": "LGPL-3.0-only",
|
"license": "LGPL-3.0-only",
|
||||||
"icon": "assets/widgets/icon.png",
|
"icon": "assets/widgets/icon.png",
|
||||||
"accessWidener": "widgets.accesswidener",
|
"accessWidener": "widgets.classtweaker",
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"client": [
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=${loader_version}",
|
"fabricloader": ">=${loader_version}",
|
||||||
"fabric": "*",
|
"fabric-api": "*",
|
||||||
"minecraft": "~${minecraft_version}"
|
"minecraft": "~${minecraft_version}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
accessWidener v2 named
|
|
||||||
|
|
||||||
accessible field net/minecraft/client/network/ClientPlayNetworkHandler pingMeasurer Lnet/minecraft/client/network/PingMeasurer;
|
|
||||||
accessible field net/minecraft/client/network/PingMeasurer log Lnet/minecraft/util/profiler/MultiValueDebugSampleLogImpl;
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
classTweaker v1 official
|
||||||
|
|
||||||
|
accessible field net/minecraft/client/multiplayer/ClientPacketListener pingDebugMonitor Lnet/minecraft/client/multiplayer/PingDebugMonitor;
|
||||||
|
accessible field net/minecraft/client/multiplayer/PingDebugMonitor delayTimer Lnet/minecraft/util/debugchart/LocalSampleLogger;
|
||||||
Reference in New Issue
Block a user