Skip to content

Commit

Permalink
🔖 SpruceUI v1.3.5: Add utility methods, 1.16 compability and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Feb 13, 2020
1 parent 3c32933 commit e5d9416
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {

modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modCompile "io.github.prospector:modmenu:1.8.5+build.23"
modCompile "io.github.prospector:modmenu:${project.modmenu_version}"

api "org.jetbrains:annotations:17.0.0"
api("org.aperlambda:lambdajcommon:1.8.0") {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.9
yarn_mappings=1.15.2+build.14:v2
loader_version=0.7.6+build.180

# Mod Properties
mod_version = 1.3.4
mod_version = 1.3.5
maven_group = me.lambdaurora
archives_base_name = spruceui

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.4.29+build.290-1.15
modmenu_version=1.10.1+build.30
13 changes: 12 additions & 1 deletion src/main/java/me/lambdaurora/spruceui/hud/Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package me.lambdaurora.spruceui.hud;

import com.google.common.collect.ImmutableList;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import org.aperlambda.lambdacommon.Identifier;
Expand All @@ -23,7 +24,7 @@
* Represents a HUD.
*
* @author LambdAurora
* @version 1.3.4
* @version 1.3.5
* @since 1.2.0
*/
public abstract class Hud extends DrawableHelper implements Identifiable
Expand Down Expand Up @@ -125,6 +126,16 @@ public boolean hasTicks()
return false;
}

/**
* Returns a list of this HUD's components.
*
* @return The HUD's components.
*/
public @NotNull List<HudComponent> getComponents()
{
return ImmutableList.copyOf(this.components);
}

@Override
public @NotNull Identifier getIdentifier()
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lambdaurora/spruceui/hud/HudComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Represents a HUD component.
*
* @author LambdAurora
* @version 1.3.1
* @version 1.3.5
* @since 1.2.0
*/
public abstract class HudComponent extends DrawableHelper implements Identifiable
Expand All @@ -28,7 +28,7 @@ public abstract class HudComponent extends DrawableHelper implements Identifiabl
protected int x;
protected int y;

protected HudComponent(Identifier identifier, int x, int y)
protected HudComponent(@NotNull Identifier identifier, int x, int y)
{
this.identifier = identifier;
this.x = x;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright © 2020 LambdAurora <[email protected]>
*
* This file is part of SpruceUI.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/

package me.lambdaurora.spruceui.hud.component;

import me.lambdaurora.spruceui.hud.HudComponent;
import net.minecraft.client.MinecraftClient;
import org.aperlambda.lambdacommon.Identifier;
import org.jetbrains.annotations.NotNull;

/**
* Represents a text HUD component.
*
* @author LambdAurora
* @version 1.3.5
* @since 1.3.5
*/
public class TextHudComponent extends HudComponent
{
protected MinecraftClient client;
protected String text;
protected int color;

public TextHudComponent(@NotNull Identifier identifier, int x, int y, String text)
{
this(identifier, x, y, text, 0xffffffff);
}

public TextHudComponent(@NotNull Identifier identifier, int x, int y, String text, int color)
{
super(identifier, x, y);
this.client = MinecraftClient.getInstance();
this.text = text;
this.color = color;
}

/**
* Gets this component's text.
*
* @return The component's text.
*/
public String getText()
{
return this.text;
}

/**
* Sets this component's text.
*
* @param text The text.
*/
public void setText(String text)
{
this.text = text;
}

/**
* Gets this component's text color.
*
* @return The text color.
*/
public int getColor()
{
return this.color;
}

/**
* Sets this component's text color.
*
* @param color The text color.
*/
public void setColor(int color)
{
this.color = color;
}

@Override
public void render(float tickDelta)
{
this.drawString(client.textRenderer, this.text, this.x, this.y, this.color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
package me.lambdaurora.spruceui.option;

import me.lambdaurora.spruceui.SpruceButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.options.BooleanOption;
import net.minecraft.client.options.GameOptions;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.TextFormat;
Expand All @@ -27,7 +29,7 @@
* Works the same as the vanilla one but can provide a tooltip.
*
* @author LambdAurora
* @version 1.3.2
* @version 1.3.5
* @since 1.0.0
*/
public class SpruceBooleanOption extends SpruceOption
Expand Down Expand Up @@ -107,4 +109,32 @@ public boolean isColored()
boolean value = this.get();
return this.getDisplayPrefix() + (this.colored ? (value ? TextFormat.GREEN : TextFormat.RED) : "") + I18n.translate(value ? "options.on" : "options.off");
}

/**
* Returns a new SpruceUI Boolean Option from the Vanilla one.
*
* @param key The option's key.
* @param vanilla The Vanilla option.
* @param tooltip The tooltip.
* @return The SpruceUI option.
*/
public static @NotNull SpruceBooleanOption fromVanilla(@NotNull String key, @NotNull BooleanOption vanilla, @Nullable Text tooltip)
{
return fromVanilla(key, vanilla, tooltip, false);
}

/**
* Returns a new SpruceUI Boolean Option from the Vanilla one.
*
* @param key The option's key.
* @param vanilla The Vanilla option.
* @param tooltip The tooltip.
* @param colored True if the option value is colored, else false.
* @return The SpruceUI option.
*/
public static @NotNull SpruceBooleanOption fromVanilla(@NotNull String key, @NotNull BooleanOption vanilla, @Nullable Text tooltip, boolean colored)
{
GameOptions options = MinecraftClient.getInstance().options;
return new SpruceBooleanOption(key, () -> vanilla.get(options), newValue -> vanilla.set(options, String.valueOf(newValue)), tooltip, colored);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
package me.lambdaurora.spruceui.option;

import me.lambdaurora.spruceui.SpruceButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.options.CyclingOption;
import net.minecraft.client.options.GameOptions;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,7 +27,7 @@
* Works the same as the vanilla one but can provide a tooltip.
*
* @author LambdAurora
* @version 1.3.2
* @version 1.3.5
* @since 1.0.0
*/
public class SpruceCyclingOption extends SpruceOption
Expand Down Expand Up @@ -72,4 +74,18 @@ public void cycle(int amount)
{
return this.messageProvider.apply(this);
}

/**
* Returns a new SpruceUI Cycling Option from the Vanilla one.
*
* @param key The option's key.
* @param vanilla The Vanilla option.
* @param tooltip The tooltip.
* @return The SpruceUI option.
*/
public static @NotNull SpruceCyclingOption fromVanilla(@NotNull String key, @NotNull CyclingOption vanilla, @Nullable Text tooltip)
{
GameOptions options = MinecraftClient.getInstance().options;
return new SpruceCyclingOption(key, amount -> vanilla.cycle(options, amount), option -> vanilla.getMessage(options), tooltip);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
package me.lambdaurora.spruceui.option;

import me.lambdaurora.spruceui.SpruceOptionSliderWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.options.DoubleOption;
import net.minecraft.client.options.GameOptions;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
Expand All @@ -27,7 +29,7 @@
* Works the same as the vanilla one but can provide a tooltip.
*
* @author LambdAurora
* @version 1.3.2
* @version 1.3.5
* @since 1.0.0
*/
public class SpruceDoubleOption extends SpruceOption
Expand Down Expand Up @@ -118,4 +120,22 @@ public double get()
{
return this.displayStringGetter.apply(this);
}

/**
* Returns a new SpruceUI Double Option from the Vanilla one.
*
* @param key The option's key.
* @param vanilla The Vanilla option.
* @param tooltip The tooltip.
* @return The SpruceUI option.
*/
public static @NotNull SpruceDoubleOption fromVanilla(@NotNull String key, @NotNull DoubleOption vanilla, float step, @Nullable Text tooltip)
{
GameOptions options = MinecraftClient.getInstance().options;
return new SpruceDoubleOption(key, vanilla.getMin(), vanilla.getMax(), step,
() -> vanilla.get(options),
newValue -> vanilla.set(options, newValue),
option -> vanilla.getDisplayString(options),
tooltip);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depends": {
"fabricloader": ">=0.4.0",
"fabric": "*",
"minecraft": "1.15.x"
"minecraft": ">=1.15"
},
"suggests": {
},
Expand Down

0 comments on commit e5d9416

Please sign in to comment.