aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui
diff options
context:
space:
mode:
authorquerns <33518699+querns@users.noreply.github.com>2023-10-09 09:55:31 -0500
committerGitHub <noreply@github.com>2023-10-09 16:55:31 +0200
commitdff250c6d32156270b9a39137346a2b3767cb4a2 (patch)
treec3ad948b6aa9e5b9edefde7e4517e9b78be7d2fe /src/main/java/gregtech/api/gui
parent45566b43ee5d8b8f75170916530fd884e0ff74db (diff)
downloadGT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.tar.gz
GT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.tar.bz2
GT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.zip
Allows covers to be configured to tick more slowly (#2307)
* Right clicking covers with a jackhammer will now make them tick more slowly * Interim commit, switching tasks * Finishes tick rate button in cover UIs * Change tick rate multiplier to a tick rate addition * Missed one number in the multiplier -> addition conversion * Hold Ctrl to adjust tick rate by 5 steps per click, move button closer to corner of cover GUI * Adjust how holding Ctrl computes tick rate change, remove gray formatting option for tick rate formatter * Cover tick rate addition can now be prevented per-cover-behavior, minor code tweaks
Diffstat (limited to 'src/main/java/gregtech/api/gui')
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UITextures.java3
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java82
2 files changed, 85 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
index 19bf3ca3f4..ffeec40561 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
@@ -380,6 +380,9 @@ public class GT_UITextures {
public static final UITexture OVERLAY_RETRACT_PIPE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/retract_pipes");
+ public static final UITexture OVERLAY_BUTTON_HOURGLASS = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/hourglass");
+
/**
* Can adjust size as needed.
*/
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java b/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java
new file mode 100644
index 0000000000..883ffb4079
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java
@@ -0,0 +1,82 @@
+package gregtech.api.gui.widgets;
+
+import static gregtech.api.gui.modularui.GT_UITextures.OVERLAY_BUTTON_HOURGLASS;
+import static gregtech.common.covers.CoverInfo.MAX_TICK_RATE_ADDITION;
+
+import java.util.List;
+
+import net.minecraft.util.StatCollector;
+
+import org.jetbrains.annotations.NotNull;
+
+import com.google.common.collect.ImmutableList;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
+import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder;
+import com.gtnewhorizons.modularui.api.widget.Widget;
+import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
+import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
+
+import gregtech.api.gui.modularui.GT_UITextures;
+import gregtech.common.covers.CoverInfo;
+
+public class GT_CoverTickRateButton extends ButtonWidget {
+
+ private static final UITexture BACKGROUND = GT_UITextures.BUTTON_COVER_NORMAL.getSubArea(0, 0, 1, 0.5f);
+
+ private final CoverInfo coverInfo;
+ private int clientTickRate;
+ private int tickRateAddition;
+
+ public GT_CoverTickRateButton(@NotNull CoverInfo coverInfo, @NotNull IWidgetBuilder<?> builder) {
+ this.coverInfo = coverInfo;
+ this.clientTickRate = coverInfo.getTickRate();
+ this.tickRateAddition = coverInfo.getTickRateAddition();
+
+ super.setBackground(BACKGROUND, OVERLAY_BUTTON_HOURGLASS);
+ super.setOnClick(this::onClick);
+ super.dynamicTooltip(this::dynamicTooltip);
+ super.attachSyncer(
+ new FakeSyncWidget.IntegerSyncer(this.coverInfo::getTickRate, integer -> clientTickRate = integer),
+ builder,
+ (widget, aInt) -> notifyTooltipChange())
+ .attachSyncer(
+ new FakeSyncWidget.IntegerSyncer(
+ this.coverInfo::getTickRateAddition,
+ integer -> tickRateAddition = integer),
+ builder);
+
+ }
+
+ private void onClick(@NotNull ClickData clickData, @NotNull Widget widget) {
+ final int iterations = clickData.ctrl ? 5 : 1;
+ final boolean isDecreasing = clickData.mouseButton == 1;
+
+ // Do five operations at once if Ctrl is held down. Since the actual increase granted by each invocation can be
+ // different on each call, just call the method several times rather than trying to do a bunch of weird math.
+ for (int i = 0; i < iterations; i++) {
+ coverInfo.adjustTickRateMultiplier(isDecreasing);
+ }
+ }
+
+ private List<String> dynamicTooltip() {
+ final String boundsNotification;
+
+ if (tickRateAddition == 0) {
+ boundsNotification = StatCollector.translateToLocal("gt.cover.info.button.bounds_notification.minimum");
+ } else if (tickRateAddition >= MAX_TICK_RATE_ADDITION - 1) {
+ // Clamping can make tickRateAddition approach but never actually equal MAX_ADDITION, so we need this
+ // adjustment.
+ boundsNotification = StatCollector.translateToLocal("gt.cover.info.button.bounds_notification.maximum");
+ } else {
+ boundsNotification = "";
+ }
+
+ return ImmutableList.of(
+ StatCollector.translateToLocalFormatted(
+ "gt.cover.info.button.tick_rate.1",
+ new CoverInfo.ClientTickRateFormatter(clientTickRate),
+ boundsNotification),
+ StatCollector.translateToLocal("gt.cover.info.button.tick_rate.2"),
+ StatCollector.translateToLocal("gt.cover.info.button.tick_rate.3"));
+ }
+}