Skip to content

Commit

Permalink
Finaly fix Options Screen and clean up half of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeOnuke committed Dec 16, 2024
1 parent 909f746 commit 1f636f7
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 214 deletions.
46 changes: 32 additions & 14 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +82,12 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,18 +201,28 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand All @@ -231,4 +249,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
43 changes: 0 additions & 43 deletions src/client/java/com/lukeonuke/minihud/gui/MHButton.java

This file was deleted.

7 changes: 3 additions & 4 deletions src/client/java/com/lukeonuke/minihud/gui/MHGuiUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lukeonuke.minihud.gui;

import com.lukeonuke.minihud.MicroHudColors;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
Expand All @@ -17,15 +16,15 @@ public static boolean isHovered(int x, int y, int width, int height, int mouseX,
return hovered;
}

public static void drawText(DrawContext context, TextRenderer textRenderer, Text text, int xPos, int yPos, int color, boolean shadow){
public static void drawText(DrawContext context, TextRenderer textRenderer, Text text, int xPos, int yPos, int color, boolean shadow) {
context.drawText(textRenderer, text, xPos, yPos, color, shadow);
}

public static void drawText(DrawContext context, TextRenderer textRenderer, String text, int xPos, int yPos, int color, boolean shadow){
public static void drawText(DrawContext context, TextRenderer textRenderer, String text, int xPos, int yPos, int color, boolean shadow) {
drawText(context, textRenderer, Text.of(text), xPos, yPos, color, shadow);
}

public static void drawText(DrawContext context, TextRenderer textRenderer, String text, int xPos, int yPos, int color){
public static void drawText(DrawContext context, TextRenderer textRenderer, String text, int xPos, int yPos, int color) {
drawText(context, textRenderer, text, xPos, yPos, color, true);
}
}
84 changes: 19 additions & 65 deletions src/client/java/com/lukeonuke/minihud/gui/OptionsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@
import com.lukeonuke.minihud.gui.list.MHList;
import com.lukeonuke.minihud.gui.list.ScrollingText;
import com.lukeonuke.minihud.renderer.MicroHudRenderer;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand All @@ -36,13 +25,10 @@
public class OptionsScreen extends Screen {
private final int padding = 8;
private MHList availableList;
private MHList selectedList;
private MHLineList selected;
private MicroHudRenderer renderer;
final private MicroHudOptions microHudOptions = MicroHudOptions.getInstance();

private boolean wasLineRendererEnabled;
public static final Identifier MH_OPTIONS_BACKGROUND_TEXTURE = Identifier.of("microhud:textures/gui/microhud_gui_background.png"); //textures/block/glass.png

public OptionsScreen() {
super(Text.of("Options"));
Expand All @@ -54,14 +40,14 @@ protected void init() {
super.init();
renderer = MicroHudRenderer.getInstance();

ButtonWidget doneButton = this.addDrawableChild(new ButtonWidget.Builder(ScreenTexts.DONE, (event) -> {
this.addDrawableChild(new ButtonWidget.Builder(ScreenTexts.DONE, (event) -> {
MicroHud.LOGGER.info("Done");
exit(true);
}).dimensions(this.width - 100 - padding, this.height - 20 - padding, 100, 20).build());

//padding, this.height - 20 - padding, 100, 20, ScreenTexts.CANCEL
this.addDrawableChild(new ButtonWidget.Builder(ScreenTexts.CANCEL, (event) -> {
MicroHud.LOGGER.info("Cancled options screen");
MicroHud.LOGGER.info("Canceled options screen");
exit(false);
}).dimensions(padding, this.height - 20 - padding, 100, 20).build());

Expand All @@ -71,14 +57,14 @@ protected void init() {
}).dimensions(this.width / 2 - 75, this.height - 20 - padding, 150, 20).build());
updatePlayerDiscordTagToggleButton(playerDiscordToggleButtonWidget);

ButtonWidget privacyPolicyButton = this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("gui.microhud.configuration.privacyPolicy"), (event) -> {
this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("gui.microhud.configuration.privacyPolicy"), (event) -> {
try {
Util.getOperatingSystem().open(new URI("https://weather.lukeonuke.com/privacy/privacypolicy/"));
} catch (URISyntaxException e) {
MicroHud.LOGGER.error("Couldn't navigate to privacy policy: " + e.getMessage());
MicroHud.LOGGER.error("Couldn't navigate to privacy policy: {}", e.getMessage());
}
exit(false);
}).dimensions(this.width - padding*2 - textRenderer.getWidth(Text.translatable("gui.microhud.configuration.privacyPolicy")), 2, textRenderer.getWidth(Text.translatable("gui.microhud.configuration.privacyPolicy")) + padding, 20).build());
}).dimensions(this.width - padding * 2 - textRenderer.getWidth(Text.translatable("gui.microhud.configuration.privacyPolicy")), 2, textRenderer.getWidth(Text.translatable("gui.microhud.configuration.privacyPolicy")) + padding, 20).build());

this.addDrawable(
new ScrollingText(
Expand All @@ -87,34 +73,16 @@ protected void init() {
)
);

//super(client, width, height, 32, height - 55 + 4, 36);
/*
* 36 - gornja grana
*
* */
//MHLineList lineList = this.addDrawableChild(new MHLineList(0, padding + textRenderer.fontHeight + padding, textRenderer));
int w = 150;
int h = this.height - padding * 3 - textRenderer.fontHeight;

availableList = new MHList(client, w, h, (textRenderer.fontHeight + padding) * 2 + padding * 2, this.height - (20 + textRenderer.fontHeight + padding * 3), textRenderer.fontHeight + padding);
availableList = new MHList(client, w, h, (textRenderer.fontHeight + padding) * 2 + padding * 2, textRenderer.fontHeight + padding);
this.addSelectableChild(availableList);
availableList.setX(padding); //setleftpos
availableList.setX(padding); //set left pos

//selectedList = new MHList(client, 200, h, textRenderer.fontHeight + padding * 2, this.height - padding, textRenderer.fontHeight + padding);
//this.addSelectableChild(selectedList);
//selectedList.setLeftPos(this.width / 2);

selected = this.addDrawableChild(new MHLineList(this.width / 2, (textRenderer.fontHeight + padding) * 2 + padding * 2, textRenderer, availableList));
this.addDrawableChild(new MHLineList(this.width / 2, (textRenderer.fontHeight + padding) * 2 + padding * 2, textRenderer, availableList));

refreshLists();

/*this.addDrawableChild(new ButtonWidget(this.width / 2 - 10, this.height / 2 - 10, 20, 20, Text.of(">"), (event) -> {
MHList.Entry entry = availableList.getFocused();
MicroHud.LOGGER.info("Adding selected {}", entry);
if(entry == null) return;
availableList.removeEntry(entry);
selectedList.addEntry(entry);
}));*/
wasLineRendererEnabled = renderer.getEnabled();
renderer.setEnabled(false);
}
Expand All @@ -127,22 +95,14 @@ public void refreshLists() {
if (enabledModules.getClass().equals(rendererModule.getClass())) contains.set(true);
});
if (!contains.get())
availableList.addEntry(new MHList.Entry(true, false, rendererModule, textRenderer, availableList));
availableList.addEntry(new MHList.Entry(true, rendererModule, textRenderer, availableList));
});


//selectedList.children().clear();
//renderer.getRendererModules().forEach(rendererModule -> {
// selectedList.addEntry(new MHList.Entry(false, true, rendererModule, textRenderer, selectedList, availableList));
//});
}

private void exit(boolean save) {
if (save) {
ArrayList<String> classes = new ArrayList<>();
renderer.getRendererModules().forEach(rendererModule -> {
classes.add(rendererModule.getClass().getSimpleName());
});
renderer.getRendererModules().forEach(rendererModule -> classes.add(rendererModule.getClass().getSimpleName()));
microHudOptions.setEnabledRendererModules(classes);
microHudOptions.save();
}
Expand All @@ -151,17 +111,10 @@ private void exit(boolean save) {

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
// context.fill(0, 0, this.width, this.height, MicroHudColors.TRANSLUCENT);
// context.fill(0, 0, this.width, padding * 2 + textRenderer.fontHeight, MicroHudColors.TRANSLUCENT);
RenderSystem.enableBlend();
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);

context.drawTexture(RenderLayer::getGuiTextured, MH_OPTIONS_BACKGROUND_TEXTURE, 0, 0, 0F, 0.0F, this.width, this.height, 32, 32);
context.drawTexture(RenderLayer::getGuiTextured, MH_OPTIONS_BACKGROUND_TEXTURE, 0, 0, 0F, 0.0F, this.width, padding * 2 + textRenderer.fontHeight, 32, 32);
context.fill(0, 0, this.width, this.height, -1, MicroHudColors.TRANSLUCENT);
context.fill(0, 0, this.width, padding * 2 + textRenderer.fontHeight, -1, MicroHudColors.TRANSLUCENT);
int bottomDarkerAreaHeight = 20 + textRenderer.fontHeight + padding * 3;
context.drawTexture(RenderLayer::getGuiTextured, MH_OPTIONS_BACKGROUND_TEXTURE, 0, this.height-bottomDarkerAreaHeight, 0F, 0F, this.width, bottomDarkerAreaHeight, 32, 32);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.disableBlend();
context.fill(0, this.height - bottomDarkerAreaHeight, this.width, this.height, -1, MicroHudColors.TRANSLUCENT);
}


Expand All @@ -175,13 +128,14 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
availableList.render(context, mouseX, mouseY, delta);

Text title = Text.translatable("gui.microhud.configuration.title");

MHGuiUtil.drawText(context, textRenderer, title, ((this.width - textRenderer.getWidth(title.getString())) / 2), padding, 0xFFFFFF, false);

MHGuiUtil.drawText(context, textRenderer, Text.translatable("gui.microhud.configuration.available"), padding, padding * 3 + textRenderer.fontHeight, 0xFFFFFF, false);
MHGuiUtil.drawText(context, textRenderer, Text.translatable("gui.microhud.configuration.selected"), this.width / 2, padding * 3 + textRenderer.fontHeight, 0xFFFFFF, false);

if (!wasLineRendererEnabled) MHGuiUtil.drawText(context, textRenderer, MutableText.of(new TranslatableTextContent("gui.microhud.configuration.renderDisabled", null, new Object[]{MicroHud.toggleRenderer.getBoundKeyLocalizedText().getString()})).getString(), padding, padding * 3, MicroHudColors.RED);
if (!wasLineRendererEnabled)
MHGuiUtil.drawText(context, textRenderer, MutableText.of(new TranslatableTextContent("gui.microhud.configuration.renderDisabled", null, new Object[]{MicroHud.toggleRenderer.getBoundKeyLocalizedText().getString()})).getString(), padding, padding * 3, MicroHudColors.RED);

super.render(context, mouseX, mouseY, delta);
}
Expand All @@ -192,10 +146,10 @@ public void close() {
super.close();
}

private void updatePlayerDiscordTagToggleButton(ButtonWidget buttonWidget){
if(microHudOptions.getEnabledPlayerDiscordTag()){
private void updatePlayerDiscordTagToggleButton(ButtonWidget buttonWidget) {
if (microHudOptions.getEnabledPlayerDiscordTag()) {
buttonWidget.setMessage(Text.of("Player discord tag: " + Formatting.BOLD + Formatting.GREEN + "ON"));
}else{
} else {
buttonWidget.setMessage(Text.of("Player discord tag: " + Formatting.BOLD + Formatting.RED + "OFF"));
}
}
Expand Down
Loading

0 comments on commit 1f636f7

Please sign in to comment.