Skip to content

Commit

Permalink
simplify status keys
Browse files Browse the repository at this point in the history
remove unneeded method
spotless
  • Loading branch information
ghzdude committed Jan 8, 2025
1 parent b9fb922 commit 08b8c45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ public static class Builder {
private boolean isStructureFormed;

// Keys for the three-state working system, can be set custom by multiblocks.
private IKey idlingKey = IKey.lang("gregtech.multiblock.idling");
private IKey pausedKey = IKey.lang("gregtech.multiblock.work_paused");
private IKey runningKey = IKey.lang("gregtech.multiblock.running");
private IKey idlingKey = IKey.lang("gregtech.multiblock.idling").format(TextFormatting.GRAY);
private IKey pausedKey = IKey.lang("gregtech.multiblock.work_paused").format(TextFormatting.GOLD);
private IKey runningKey = IKey.lang("gregtech.multiblock.running").format(TextFormatting.GREEN);
private boolean dirty;

protected static Widget<?> keyMapper(IDrawable key) {
Expand Down Expand Up @@ -691,7 +691,7 @@ public Builder addWorkingStatusLine() {
public Builder addWorkPausedLine(boolean checkState) {
if (!isStructureFormed) return this;
if (!checkState || !isWorkingEnabled.getAsBoolean()) {
addKey(KeyUtil.colored(TextFormatting.GOLD, pausedKey));
addKey(pausedKey);
}
return this;
}
Expand All @@ -705,7 +705,7 @@ public Builder addWorkPausedLine(boolean checkState) {
public Builder addRunningPerfectlyLine(boolean checkState) {
if (!isStructureFormed) return this;
if (!checkState || isActive.getAsBoolean()) {
addKey(KeyUtil.colored(TextFormatting.GREEN, runningKey));
addKey(runningKey);
}
return this;
}
Expand All @@ -719,7 +719,7 @@ public Builder addRunningPerfectlyLine(boolean checkState) {
public Builder addIdlingLine(boolean checkState) {
if (!isStructureFormed) return this;
if (!checkState || (isWorkingEnabled.getAsBoolean() && !isActive.getAsBoolean())) {
addKey(KeyUtil.colored(TextFormatting.GRAY, idlingKey));
addKey(idlingKey);
}
return this;
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/gregtech/api/util/KeyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public class KeyUtil {

public static final String SECTION = "§";

public static IKey colored(TextFormatting formatting, IKey... keys) {
if (ArrayUtils.isEmpty(keys)) return wrap(formatting);
if (keys.length == 1) return IKey.comp(wrap(formatting), keys[0]);
return IKey.comp(keys).format(formatting);
}

public static IKey string(String s) {
return IKey.str(s);
}
Expand Down Expand Up @@ -55,7 +49,8 @@ public static IKey lang(TextFormatting formatting, String lang, Object... args)
public static IKey lang(TextFormatting formatting, String lang, Supplier<?>... argSuppliers) {
if (ArrayUtils.isEmpty(argSuppliers)) return IKey.lang(lang).format(formatting);
if (argSuppliers.length == 1)
return IKey.dynamic(() -> IKey.lang(lang, fixArg(formatting, argSuppliers[0].get())).format(formatting).getFormatted());
return IKey.dynamic(
() -> IKey.lang(lang, fixArg(formatting, argSuppliers[0].get())).format(formatting).getFormatted());
final Object[] args = new Object[argSuppliers.length];
return IKey.dynamic(() -> {
Arrays.setAll(args, value -> fixArg(formatting, argSuppliers[value].get()));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/mixins/mui2/KeyCompMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.drawable.text.BaseKey;

import com.cleanroommc.modularui.drawable.text.CompoundKey;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = CompoundKey.class, remap = false)
public abstract class KeyCompMixin extends BaseKey {

@Redirect(method = "get", at = @At(value = "INVOKE", target = "Lcom/cleanroommc/modularui/api/drawable/IKey;get()Ljava/lang/String;"))
@Redirect(method = "get",
at = @At(value = "INVOKE",
target = "Lcom/cleanroommc/modularui/api/drawable/IKey;get()Ljava/lang/String;"))
public String formatTheKeys(IKey key) {
return key.getFormatted();
}
Expand Down

0 comments on commit 08b8c45

Please sign in to comment.