Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import com.cleanroommc.modularui.widgets.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Flow;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.function.BooleanSupplier;

public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {

Expand Down Expand Up @@ -117,6 +120,18 @@ default ParentWidget<?> createSettingsRow() {
return new ParentWidget<>().height(16).widthRel(1.0f).marginBottom(2);
}

/**
* Create a dynamic lang key that switches between {@code cover.generic.enabled} and {@code cover.generic.disabled}
* depending on the result of the given boolean supplier. <br/>
*
* @param keyBase the base of the lang key to use. {@code .enabled} and {@code .disabled} will be appended.
*/
default IKey createEnabledKey(@NotNull String keyBase, @NotNull BooleanSupplier enabledState) {
String enabled = keyBase + ".enabled";
String disabled = keyBase + ".disabled";
return IKey.lang(() -> enabledState.getAsBoolean() ? enabled : disabled);
}

default int getIncrementValue(MouseData data) {
int adjust = 1;
if (data.shift) adjust *= 4;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gregtech/common/covers/CoverFluidFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
.coverChildrenHeight()
.setEnabledIf(b -> getFilterMode() != FluidFilterMode.FILTER_BOTH)
.child(new ToggleButton()
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
"cover.generic.enabled" :
"cover.generic.disabled").get())
.color(Color.WHITE.main).shadow(false))
.overlay(createEnabledKey("cover.generic", () -> this.allowFlow)
.color(Color.WHITE.main)
.shadow(false))
.tooltip(tooltip -> tooltip
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
.size(72, 18)
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/gregtech/common/covers/CoverFluidVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand Down Expand Up @@ -79,16 +78,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan

@Override
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);

return super.createUI(data, syncManager)
.child(Flow.row().height(18).widthRel(1f)
.marginBottom(2)
.child(new ToggleButton()
.value(isWorking)
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
"behaviour.soft_hammer.enabled" :
"behaviour.soft_hammer.disabled").get())
.overlay(createEnabledKey("behaviour.soft_hammer", () -> this.isWorkingAllowed)
.color(Color.WHITE.darker(1)))
.widthRel(0.6f)
.left(0)));
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gregtech/common/covers/CoverItemFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
.coverChildrenHeight()
.setEnabledIf(b -> getFilterMode() != ItemFilterMode.FILTER_BOTH)
.child(new ToggleButton()
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
"cover.generic.enabled" :
"cover.generic.disabled").get())
.color(Color.WHITE.main).shadow(false))
.overlay(createEnabledKey("cover.generic", () -> this.allowFlow)
.color(Color.WHITE.main)
.shadow(false))
.tooltip(tooltip -> tooltip
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
.size(72, 18)
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/gregtech/common/covers/CoverItemVoiding.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand Down Expand Up @@ -80,16 +79,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan

@Override
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);

return super.createUI(data, guiSyncManager)
.child(Flow.row().height(18).widthRel(1f)
.marginBottom(2)
.child(new ToggleButton()
.value(isWorking)
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
"behaviour.soft_hammer.enabled" :
"behaviour.soft_hammer.disabled").get())
.overlay(createEnabledKey("behaviour.soft_hammer", () -> this.isWorkingAllowed)
.color(Color.WHITE.darker(1)))
.widthRel(0.6f)
.left(0)));
Expand Down
Loading