Skip to content

Commit

Permalink
Allow configuring MekaSuit UI Jitter via helmet options (mekanism/Mek…
Browse files Browse the repository at this point in the history
…anism-Feature-Requests#587), and allow adjusting it and opacity via arrow keys
  • Loading branch information
pupnewfster committed Feb 28, 2024
1 parent 246efdb commit 2a15e50
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 16 deletions.
@@ -1,5 +1,5 @@
// 1.20.4 2024-02-28T14:39:06.33847 Languages: en_us for mod: mekanism
// 1.20.4 2024-02-28T15:25:16.3656249 Languages: en_us for mod: mekanism
0e98b8c7cddc1a598c7667ea29f63dcf18723bbe assets/mekanism/lang/en_au.json
0e98b8c7cddc1a598c7667ea29f63dcf18723bbe assets/mekanism/lang/en_gb.json
ffb530f7e53364dec77570639880aa5ac39613f3 assets/mekanism/lang/en_ud.json
0254339444a7c784567777c2fd4bc3a7e0fb7e23 assets/mekanism/lang/en_us.json
51ba90f999a7c570e8297ba47b6c8195777ebc90 assets/mekanism/lang/en_ud.json
feaa7621abd7677181d223e10d3fc935febf89e8 assets/mekanism/lang/en_us.json
Expand Up @@ -974,6 +974,7 @@
"gui.mekanism.issues.no_recipe": "ʇnduᴉ ɥᵷnouǝ ʇou ɹo ǝdᴉɔǝɹ ᵷuᴉɥɔʇɐɯ oN - ",
"gui.mekanism.issues.no_space": "ʇndʇno uᴉ ɯooɹ ɥᵷnouǝ ʇoN - ",
"gui.mekanism.issues.no_space.overflow": "ɹǝɟɟnq ꞁɐuɹǝʇuᴉ uᴉ pǝɹoʇs ʍoꞁɟɹǝʌo 'ʇndʇno uᴉ ɯooɹ ɥᵷnouǝ ʇoN - ",
"gui.mekanism.jitter": "%%%s :ɹǝʇʇᴉՐ",
"gui.mekanism.liquid": "%s :pᴉnbᴉꞀ",
"gui.mekanism.max": "%s :xɐW",
"gui.mekanism.max_output": "ʇ/%s :ʇndʇnO xɐW",
Expand All @@ -988,7 +989,7 @@
"gui.mekanism.no_fluid": "pᴉnꞁɟ oN",
"gui.mekanism.no_recipe": "(ǝdᴉɔǝɹ oN)",
"gui.mekanism.none": "ǝuoN",
"gui.mekanism.opacity": "ʎʇᴉɔɐdO",
"gui.mekanism.opacity": "%%%s :ʎʇᴉɔɐdO",
"gui.mekanism.pigment": "%s :ʇuǝɯᵷᴉԀ",
"gui.mekanism.process_rate": "%s :ǝʇɐᴚ ssǝɔoɹԀ",
"gui.mekanism.process_rate_mb": "ʇ/ᗺɯ %s :ǝʇɐᴚ ssǝɔoɹԀ",
Expand Down
Expand Up @@ -974,6 +974,7 @@
"gui.mekanism.issues.no_recipe": " - No matching recipe or not enough input",
"gui.mekanism.issues.no_space": " - Not enough room in output",
"gui.mekanism.issues.no_space.overflow": " - Not enough room in output, overflow stored in internal buffer",
"gui.mekanism.jitter": "Jitter: %1$s%%",
"gui.mekanism.liquid": "Liquid: %1$s",
"gui.mekanism.max": "Max: %1$s",
"gui.mekanism.max_output": "Max Output: %1$s/t",
Expand All @@ -988,7 +989,7 @@
"gui.mekanism.no_fluid": "No fluid",
"gui.mekanism.no_recipe": "(No recipe)",
"gui.mekanism.none": "None",
"gui.mekanism.opacity": "Opacity",
"gui.mekanism.opacity": "Opacity: %1$s%%",
"gui.mekanism.pigment": "Pigment: %1$s",
"gui.mekanism.process_rate": "Process Rate: %1$s",
"gui.mekanism.process_rate_mb": "Process Rate: %1$s mB/t",
Expand Down
@@ -0,0 +1,3 @@
{
"sound_event.mekanismgenerators.tile.generator.wind": "Wind generator wooshes"
}
@@ -0,0 +1,3 @@
{
"sound_event.mekanismgenerators.tile.generator.wind": "Wind generator wooshes"
}
Expand Up @@ -895,7 +895,8 @@ private void addMisc() {
add(MekanismLang.COLOR_PICKER, "Color Picker");
add(MekanismLang.HELMET_OPTIONS, "Helmet Options");
add(MekanismLang.HUD_OVERLAY, "HUD Overlay:");
add(MekanismLang.OPACITY, "Opacity");
add(MekanismLang.OPACITY, "Opacity: %1$s%%");
add(MekanismLang.JITTER, "Jitter: %1$s%%");
add(MekanismLang.DEFAULT, "Default");
add(MekanismLang.WARNING, "Warning");
add(MekanismLang.DANGER, "Danger");
Expand Down
32 changes: 31 additions & 1 deletion src/main/java/mekanism/client/gui/element/GuiSlider.java
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import org.lwjgl.glfw.GLFW;

public class GuiSlider extends GuiElement {

Expand Down Expand Up @@ -53,8 +54,37 @@ public void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
}
}

@Override
public boolean keyPressed(int key, int i, int j) {
if (super.keyPressed(key, i, j)) {
return true;
}
double shift;
if (isPreviousButton(key) && value > 0) {
shift = -0.01;
} else if (isNextButton(key) && value < 1) {
shift = 0.01;
} else {
return false;
}
value = Mth.clamp(value + shift, 0, 1);
callback.accept(value);
return true;
}

private void set(double mouseX, double mouseY) {
double oldValue = value;
value = Mth.clamp(((mouseX - getX() - 2) / (width - 6)), 0, 1);
callback.accept(value);
if (!Mth.equal(value, oldValue)) {
callback.accept(value);
}
}

private boolean isPreviousButton(int key) {
return key == GLFW.GLFW_KEY_UP || key == GLFW.GLFW_KEY_LEFT;
}

private boolean isNextButton(int key) {
return key == GLFW.GLFW_KEY_DOWN || key == GLFW.GLFW_KEY_RIGHT;
}
}
Expand Up @@ -13,30 +13,41 @@
public class GuiMekaSuitHelmetOptions extends GuiWindow {

public GuiMekaSuitHelmetOptions(IGuiWrapper gui, int x, int y) {
super(gui, x, y, 140, 115, WindowType.MEKA_SUIT_HELMET);
super(gui, x, y, 140, 140, WindowType.MEKA_SUIT_HELMET);
interactionStrategy = InteractionStrategy.NONE;
addChild(new GuiColorPickerSlot(gui, relativeX + 12, relativeY + 32, false, HUDColor.REGULAR::getColor, color -> {
MekanismConfig.client.hudColor.set(color.rgb());
// save the updated config info
MekanismConfig.client.save();
}));
addChild(new GuiColorPickerSlot(gui, relativeX + 61, relativeY + 32, false, HUDColor.WARNING::getColor, color -> {
MekanismConfig.client.hudWarningColor.set(color.rgb());
// save the updated config info
MekanismConfig.client.save();
}));
addChild(new GuiColorPickerSlot(gui, relativeX + 110, relativeY + 32, false, HUDColor.DANGER::getColor, color -> {
MekanismConfig.client.hudDangerColor.set(color.rgb());
// save the updated config info
MekanismConfig.client.save();
}));

GuiSlider slider = addChild(new GuiSlider(gui, relativeX + 10, relativeY + 62, 120, value -> MekanismConfig.client.hudOpacity.set((float) value)));
slider.setValue(MekanismConfig.client.hudOpacity.get());
GuiSlider opacitySlider = addChild(new GuiSlider(gui, relativeX + 10, relativeY + 62, 120, value -> {
MekanismConfig.client.hudOpacity.set(value);
MekanismConfig.client.save();
}));
opacitySlider.setValue(MekanismConfig.client.hudOpacity.get());

GuiSlider jitterSlider = addChild(new GuiSlider(gui, relativeX + 10, relativeY + 87, 120, value -> {
//Jitter is on a scale of [1, 100]
// so we need to multiply the [0, 1] value by 99 to get it to [0, 99]
// and then add 1 to shift it to [1, 100]
MekanismConfig.client.hudJitter.set(99 * value + 1);
MekanismConfig.client.save();
}));
//Jitter is on a scale of [1, 100]
// so we need to subtract 1 to get it to [0, 99]
// and then divide by 99 to get it to [0, 1]
jitterSlider.setValue((MekanismConfig.client.hudJitter.get() - 1) / 99);

addChild(new GuiScreenSwitch(gui, relativeX + 7, relativeY + 87, 126, MekanismLang.COMPASS.translate(), MekanismConfig.client.hudCompassEnabled, () -> {
addChild(new GuiScreenSwitch(gui, relativeX + 7, relativeY + 112, 126, MekanismLang.COMPASS.translate(), MekanismConfig.client.hudCompassEnabled, () -> {
MekanismConfig.client.hudCompassEnabled.set(!MekanismConfig.client.hudCompassEnabled.get());
// save the updated config info
MekanismConfig.client.save();
}));
}
Expand All @@ -52,6 +63,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) {
drawScaledCenteredText(guiGraphics, MekanismLang.WARNING.translate(), relativeX + 70, relativeY + 52, subheadingTextColor(), 0.8F);
drawScaledCenteredText(guiGraphics, MekanismLang.DANGER.translate(), relativeX + 119, relativeY + 52, subheadingTextColor(), 0.8F);

drawScaledCenteredText(guiGraphics, MekanismLang.OPACITY.translate(), relativeX + 70, relativeY + 75, subheadingTextColor(), 0.8F);
drawScaledCenteredText(guiGraphics, MekanismLang.OPACITY.translate(Math.round(MekanismConfig.client.hudOpacity.get() * 100)),relativeX + 70, relativeY + 75, subheadingTextColor(), 0.8F);
drawScaledCenteredText(guiGraphics, MekanismLang.JITTER.translate((int) MekanismConfig.client.hudJitter.get()), relativeX + 70, relativeY + 100, subheadingTextColor(), 0.8F);
}
}
1 change: 1 addition & 0 deletions src/main/java/mekanism/common/MekanismLang.java
Expand Up @@ -251,6 +251,7 @@ public enum MekanismLang implements ILangEntry {
HELMET_OPTIONS("gui", "helmet_options"),
HUD_OVERLAY("gui", "hud_overlay"),
OPACITY("gui", "opacity"),
JITTER("gui", "jitter"),
DEFAULT("gui", "default"),
WARNING("gui", "warning"),
DANGER("gui", "danger"),
Expand Down
Expand Up @@ -59,6 +59,11 @@ public void set(float value) {
cachedValue = value;
}

public void set(double value) {
internal.set(value);
cachedValue = (float) value;
}

@Override
protected boolean clearCachedValue(boolean checkChanged) {
if (!resolved) {
Expand Down

0 comments on commit 2a15e50

Please sign in to comment.