Skip to content

Commit

Permalink
Added tooltips to options
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCrayfish committed Feb 9, 2021
1 parent 905cec3 commit c934ad2
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/mrcrayfish/controllable/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/mrcrayfish/controllable/client/IToolTip.java
Original file line number Diff line number Diff line change
@@ -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<IReorderingProcessor> getToolTip();
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

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;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.TranslationTextComponent;

import javax.annotation.Nullable;

/**
* Author: MrCrayfish
*/
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)
{
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
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<GameSettings> getter, BiConsumer<GameSettings, Boolean> setter)
{
super(title, getter, setter);
this.toolTip = new TranslationTextComponent(title + ".desc");
}

@Override
public void nextValue(GameSettings settings)
{
this.set(settings, String.valueOf(!this.get(settings)));
}

@Override
public List<IReorderingProcessor> getToolTip()
{
return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
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;

/**
* Author: MrCrayfish
*/
public class ControllableEnumOption<T extends Enum<T> & IStringSerializable> extends AbstractOption
public class ControllableEnumOption<T extends Enum<T> & IStringSerializable> extends AbstractOption implements IToolTip
{
private Class<T> enumClass;
private int ordinal = 0;
private Function<GameSettings, T> getter;
private BiConsumer<GameSettings, T> setter;
private BiFunction<GameSettings, ControllableEnumOption<T>, ITextComponent> displayNameGetter;
private TranslationTextComponent toolTip;

public ControllableEnumOption(String title, Class<T> enumClass, Function<GameSettings, T> getter, BiConsumer<GameSettings, T> setter, BiFunction<GameSettings, ControllableEnumOption<T>, ITextComponent> displayNameGetter)
{
Expand All @@ -29,6 +36,7 @@ public ControllableEnumOption(String title, Class<T> enumClass, Function<GameSet
this.getter = getter;
this.setter = setter;
this.displayNameGetter = displayNameGetter;
this.toolTip = new TranslationTextComponent(title + ".desc");
}

private void nextEnum(GameSettings options)
Expand Down Expand Up @@ -69,4 +77,10 @@ private T getEnum(int ordinal)
if(ordinal >= e.length) ordinal = 0;
return e[ordinal];
}

@Override
public List<IReorderingProcessor> getToolTip()
{
return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
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;

/**
* 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<GameSettings, Double> getter, BiConsumer<GameSettings, Double> setter, BiFunction<GameSettings, SliderPercentageOption, ITextComponent> displayNameGetter)
{
super(title, minValue, maxValue, stepSize, getter, setter, displayNameGetter);
this.toolTip = new TranslationTextComponent(title + ".desc");
}

@Override
public Widget createWidget(GameSettings settings, int x, int y, int width)
{
return new ControllableOptionSlider(settings, x, y, width, 20, this);
}

@Override
public List<IReorderingProcessor> getToolTip()
{
return Minecraft.getInstance().fontRenderer.trimStringToWidth(this.toolTip, 200);
}
}
13 changes: 13 additions & 0 deletions src/main/resources/assets/controllable/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,42 @@
"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",
"controllable.options.flipLeftThumbstickY": "Flip Left Y-Axis",
"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",
Expand Down

0 comments on commit c934ad2

Please sign in to comment.