From c934ad2ebcab3b497f5ae81db5602f8a2b6e1d78 Mon Sep 17 00:00:00 2001 From: MrCrayfish Date: Tue, 9 Feb 2021 20:09:47 +1030 Subject: [PATCH] Added tooltips to options --- .../com/mrcrayfish/controllable/Config.java | 4 +- .../controllable/client/IToolTip.java | 15 +++++++ .../client/gui/SettingsScreen.java | 45 +++++++++++++++++++ .../settings/ControllableBooleanOption.java | 18 +++++++- .../settings/ControllableEnumOption.java | 16 ++++++- .../ControllableSliderPercentageOption.java | 17 ++++++- .../assets/controllable/lang/en_us.json | 13 ++++++ 7 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/mrcrayfish/controllable/client/IToolTip.java diff --git a/src/main/java/com/mrcrayfish/controllable/Config.java b/src/main/java/com/mrcrayfish/controllable/Config.java index a18e069f..2964431a 100644 --- a/src/main/java/com/mrcrayfish/controllable/Config.java +++ b/src/main/java/com/mrcrayfish/controllable/Config.java @@ -61,8 +61,8 @@ public Options(ForgeConfigSpec.Builder builder) this.deadZone = builder.comment("The distance you have to move the thumbstick before it's input is registered. This fixes drifting as some thumbsticks don't center to zero.").defineInRange("deadZone", 0.15, 0.0, 1.0); this.rotationSpeed = builder.comment("The speed which the camera turns in game").defineInRange("rotationSpeed", 25.0, 0.0, 50.0); this.mouseSpeed = builder.comment("The speed which the cursor or virtual mouse moves around the screen").defineInRange("mouseSpeed", 15.0, 0.0, 50.0); - this.showActions = builder.comment("If true, shows common actions when displaying available on the screen").defineEnum("showActions", ActionVisibility.MINIMAL); - this.quickCraft = builder.comment("If true, allows you to craft quickly when clicking an item in the recipe book").define("quickCraft", true); + this.showActions = builder.comment("If enabled, shows common actions when displaying available on the screen").defineEnum("showActions", ActionVisibility.MINIMAL); + this.quickCraft = builder.comment("If enabled, allows you to craft quickly when clicking an item in the recipe book").define("quickCraft", true); } builder.pop(); } diff --git a/src/main/java/com/mrcrayfish/controllable/client/IToolTip.java b/src/main/java/com/mrcrayfish/controllable/client/IToolTip.java new file mode 100644 index 00000000..dbe58a5c --- /dev/null +++ b/src/main/java/com/mrcrayfish/controllable/client/IToolTip.java @@ -0,0 +1,15 @@ +package com.mrcrayfish.controllable.client; + +import net.minecraft.util.IReorderingProcessor; +import net.minecraft.util.text.ITextComponent; + +import java.util.List; + +/** + * Author: MrCrayfish + */ +public interface IToolTip +{ + List getToolTip(); +} + diff --git a/src/main/java/com/mrcrayfish/controllable/client/gui/SettingsScreen.java b/src/main/java/com/mrcrayfish/controllable/client/gui/SettingsScreen.java index 46679ccb..daeb8293 100644 --- a/src/main/java/com/mrcrayfish/controllable/client/gui/SettingsScreen.java +++ b/src/main/java/com/mrcrayfish/controllable/client/gui/SettingsScreen.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mrcrayfish.controllable.Config; +import com.mrcrayfish.controllable.client.IToolTip; import com.mrcrayfish.controllable.client.settings.ControllerOptions; import net.minecraft.client.AbstractOption; import net.minecraft.client.gui.DialogTexts; @@ -9,6 +10,8 @@ import net.minecraft.client.gui.widget.button.Button; import net.minecraft.util.text.TranslationTextComponent; +import javax.annotation.Nullable; + /** * Author: MrCrayfish */ @@ -16,6 +19,8 @@ public class SettingsScreen extends Screen { private static final AbstractOption[] OPTIONS = new AbstractOption[]{ControllerOptions.AUTO_SELECT, ControllerOptions.RENDER_MINI_PLAYER, ControllerOptions.VIRTUAL_MOUSE, ControllerOptions.CONSOLE_HOTBAR, ControllerOptions.CONTROLLER_ICONS, ControllerOptions.CURSOR_TYPE, ControllerOptions.INVERT_LOOK, ControllerOptions.DEAD_ZONE, ControllerOptions.ROTATION_SPEED, ControllerOptions.MOUSE_SPEED, ControllerOptions.SHOW_ACTIONS, ControllerOptions.QUICK_CRAFT}; private final Screen parentScreen; + private IToolTip hoveredTooltip; + private int hoveredCounter; protected SettingsScreen(Screen parentScreen) { @@ -45,11 +50,51 @@ public void onClose() Config.save(); } + @Override + public void tick() + { + if(this.hoveredTooltip != null) + { + if(this.hoveredCounter < 20) + { + this.hoveredCounter++; + } + } + else + { + this.hoveredCounter = 0; + } + } + @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); drawCenteredString(matrixStack, this.font, this.title, this.width / 2, 20, 0xFFFFFF); super.render(matrixStack, mouseX, mouseY, partialTicks); + + this.hoveredTooltip = this.getHoveredToolTip(mouseX, mouseY); + if(this.hoveredTooltip != null && this.hoveredCounter >= 20) + { + this.renderTooltip(matrixStack, this.hoveredTooltip.getToolTip(), mouseX, mouseY); + } + } + + @Nullable + private IToolTip getHoveredToolTip(int mouseX, int mouseY) + { + for(int i = 0; i < OPTIONS.length; i++) + { + AbstractOption option = OPTIONS[i]; + if(!(option instanceof IToolTip)) + continue; + int x = this.width / 2 - 155 + i % 2 * 160; + int y = this.height / 6 + 24 * (i >> 1); + if(mouseX >= x && mouseY >= y && mouseX < x + 150 && mouseY < y + 20) + { + return (IToolTip) option; + } + } + return null; } } diff --git a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableBooleanOption.java b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableBooleanOption.java index bf00a30e..d81a4f7a 100644 --- a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableBooleanOption.java +++ b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableBooleanOption.java @@ -1,19 +1,29 @@ package com.mrcrayfish.controllable.client.settings; +import com.mrcrayfish.controllable.client.IToolTip; import net.minecraft.client.GameSettings; +import net.minecraft.client.Minecraft; import net.minecraft.client.settings.BooleanOption; +import net.minecraft.util.IReorderingProcessor; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import java.util.Collections; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.Predicate; /** * Author: MrCrayfish */ -public class ControllableBooleanOption extends BooleanOption +public class ControllableBooleanOption extends BooleanOption implements IToolTip { + private TranslationTextComponent toolTip; + public ControllableBooleanOption(String title, Predicate getter, BiConsumer setter) { super(title, getter, setter); + this.toolTip = new TranslationTextComponent(title + ".desc"); } @Override @@ -21,4 +31,10 @@ public void nextValue(GameSettings settings) { this.set(settings, String.valueOf(!this.get(settings))); } + + @Override + public List getToolTip() + { + return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200); + } } diff --git a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableEnumOption.java b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableEnumOption.java index cc6f64bf..57e0b8a8 100644 --- a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableEnumOption.java +++ b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableEnumOption.java @@ -1,12 +1,18 @@ package com.mrcrayfish.controllable.client.settings; +import com.mrcrayfish.controllable.client.IToolTip; import net.minecraft.client.AbstractOption; import net.minecraft.client.GameSettings; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.OptionButton; +import net.minecraft.util.IReorderingProcessor; import net.minecraft.util.IStringSerializable; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import java.util.Collections; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -14,13 +20,14 @@ /** * Author: MrCrayfish */ -public class ControllableEnumOption & IStringSerializable> extends AbstractOption +public class ControllableEnumOption & IStringSerializable> extends AbstractOption implements IToolTip { private Class enumClass; private int ordinal = 0; private Function getter; private BiConsumer setter; private BiFunction, ITextComponent> displayNameGetter; + private TranslationTextComponent toolTip; public ControllableEnumOption(String title, Class enumClass, Function getter, BiConsumer setter, BiFunction, ITextComponent> displayNameGetter) { @@ -29,6 +36,7 @@ public ControllableEnumOption(String title, Class enumClass, Function= e.length) ordinal = 0; return e[ordinal]; } + + @Override + public List getToolTip() + { + return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200); + } } diff --git a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableSliderPercentageOption.java b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableSliderPercentageOption.java index d33ba093..2ad9daf4 100644 --- a/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableSliderPercentageOption.java +++ b/src/main/java/com/mrcrayfish/controllable/client/settings/ControllableSliderPercentageOption.java @@ -1,11 +1,17 @@ package com.mrcrayfish.controllable.client.settings; +import com.mrcrayfish.controllable.client.IToolTip; import com.mrcrayfish.controllable.client.gui.widget.ControllableOptionSlider; import net.minecraft.client.GameSettings; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.settings.SliderPercentageOption; +import net.minecraft.util.IReorderingProcessor; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import java.util.Collections; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; @@ -13,11 +19,14 @@ /** * Author: MrCrayfish */ -public class ControllableSliderPercentageOption extends SliderPercentageOption +public class ControllableSliderPercentageOption extends SliderPercentageOption implements IToolTip { + private TranslationTextComponent toolTip; + public ControllableSliderPercentageOption(String title, double minValue, double maxValue, float stepSize, Function getter, BiConsumer setter, BiFunction displayNameGetter) { super(title, minValue, maxValue, stepSize, getter, setter, displayNameGetter); + this.toolTip = new TranslationTextComponent(title + ".desc"); } @Override @@ -25,4 +34,10 @@ public Widget createWidget(GameSettings settings, int x, int y, int width) { return new ControllableOptionSlider(settings, x, y, width, 20, this); } + + @Override + public List getToolTip() + { + return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200); + } } diff --git a/src/main/resources/assets/controllable/lang/en_us.json b/src/main/resources/assets/controllable/lang/en_us.json index 54af5a18..fa471f24 100644 --- a/src/main/resources/assets/controllable/lang/en_us.json +++ b/src/main/resources/assets/controllable/lang/en_us.json @@ -43,22 +43,34 @@ "controllable.gui.layout.invalid_layout": "One or more buttons are not assigned. Resolve any buttons that have an exclamation icon. If you continue, some buttons may not work!", "controllable.gui.layout.thumbsticks": "Thumbstick Settings", "controllable.options.forceFeedback": "Vibration", + "controllable.options.forceFeedback.desc": "If enabled, some actions will cause the controller to vibrate", "controllable.options.autoSelect": "Auto Select", + "controllable.options.autoSelect.desc": "If enabled, controller will be automatically selected on start up or when plugged in", "controllable.options.deadZone": "Dead Zone", + "controllable.options.deadZone.desc": "The distance you have to move the thumbstick before it's input is registered. This fixes drifting as some thumbsticks don't center to zero.", "controllable.options.deadZone.format": "Dead Zone: %s", "controllable.options.rotationSpeed": "Rotation Speed", + "controllable.options.rotationSpeed.desc": "The speed which the camera turns in game", "controllable.options.rotationSpeed.format": "Rotation Speed: %s", "controllable.options.mouseSpeed": "Mouse Speed", + "controllable.options.mouseSpeed.desc": "The speed which the cursor or virtual mouse moves around the screen", "controllable.options.mouseSpeed.format": "Mouse Speed: %s", "controllable.options.renderMiniPlayer": "Render Mini Player", + "controllable.options.renderMiniPlayer.desc": "If enabled, the player will render in the top left corner likes Bedrock Edition", "controllable.options.virtualMouse": "Virtual Mouse", + "controllable.options.virtualMouse.desc": "If enabled, the game will use a virtual cursor instead of the real cursor. This must be turned on to be able to run multiple instances!", "controllable.options.consoleHotbar": "Console Hotbar", + "controllable.options.consoleHotbar.desc": "If enabled, hotbar will render closer to the center of the screen like on console.", "controllable.options.cursorType": "Cursor Type", + "controllable.options.cursorType.desc": "The image to use for the cursor. This only applies if virtual mouse is enabled!", "controllable.options.cursorType.format": "Cursor Type: %s", "controllable.options.controllerIcons": "Icons", + "controllable.options.controllerIcons.desc": "The controller icons to use in game to display actions", "controllable.options.controllerIcons.format": "Icons: %s", "controllable.options.invertLook": "Invert Look", + "controllable.options.invertLook.desc": "If enabled, inverts the controls on the Y axis for the camera", "controllable.options.showActions": "Show Actions", + "controllable.options.showActions.desc": "If enabled, shows common actions when displaying available on the screen", "controllable.options.showActions.format": "Show Actions: %s", "controllable.options.switchThumbsticks": "Switch Thumbsticks", "controllable.options.flipLeftThumbstickX": "Flip Left X-Axis", @@ -66,6 +78,7 @@ "controllable.options.flipRightThumbstickX": "Flip Right X-Axis", "controllable.options.flipRightThumbstickY": "Flip Right Y-Axis", "controllable.options.quickCraft": "Quick Craft", + "controllable.options.quickCraft.desc": "If enabled, allows you to craft quickly when clicking an item in the recipe book", "controllable.controller.default": "Default", "controllable.controller.playstation": "Playstation", "controllable.controller.xbox": "Xbox",