Skip to content

Commit 22d4377

Browse files
committed
Remove nested lang keys in dynamic keys
1 parent 70bfc8a commit 22d4377

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/main/java/gregtech/api/cover/CoverWithUI.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import com.cleanroommc.modularui.widgets.ToggleButton;
3434
import com.cleanroommc.modularui.widgets.layout.Flow;
3535
import org.jetbrains.annotations.ApiStatus;
36+
import org.jetbrains.annotations.NotNull;
37+
38+
import java.util.function.BooleanSupplier;
3639

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

@@ -117,6 +120,14 @@ default ParentWidget<?> createSettingsRow() {
117120
return new ParentWidget<>().height(16).widthRel(1.0f).marginBottom(2);
118121
}
119122

123+
/**
124+
* Create a dynamic lang key that switches between {@code cover.generic.enabled} and {@code cover.generic.disabled}
125+
* depending on the result of the given boolean supplier.
126+
*/
127+
default IKey createEnabledKey(@NotNull BooleanSupplier enabledState) {
128+
return IKey.lang(() -> enabledState.getAsBoolean() ? "cover.generic.enabled" : "cover.generic.disabled");
129+
}
130+
120131
default int getIncrementValue(MouseData data) {
121132
int adjust = 1;
122133
if (data.shift) adjust *= 4;

src/main/java/gregtech/common/covers/CoverFluidFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
166166
.coverChildrenHeight()
167167
.setEnabledIf(b -> getFilterMode() != FluidFilterMode.FILTER_BOTH)
168168
.child(new ToggleButton()
169-
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
170-
"cover.generic.enabled" :
171-
"cover.generic.disabled").get())
172-
.color(Color.WHITE.main).shadow(false))
169+
.overlay(createEnabledKey(() -> this.allowFlow)
170+
.color(Color.WHITE.main)
171+
.shadow(false))
173172
.tooltip(tooltip -> tooltip
174173
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
175174
.size(72, 18)

src/main/java/gregtech/common/covers/CoverFluidVoiding.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import codechicken.lib.render.pipeline.IVertexOperation;
2525
import codechicken.lib.vec.Cuboid6;
2626
import codechicken.lib.vec.Matrix4;
27-
import com.cleanroommc.modularui.api.drawable.IKey;
2827
import com.cleanroommc.modularui.factory.GuiData;
2928
import com.cleanroommc.modularui.factory.SidedPosGuiData;
3029
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -79,16 +78,15 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
7978

8079
@Override
8180
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
82-
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
81+
// noinspection DuplicatedCode
82+
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
8383

8484
return super.createUI(data, syncManager)
8585
.child(Flow.row().height(18).widthRel(1f)
8686
.marginBottom(2)
8787
.child(new ToggleButton()
8888
.value(isWorking)
89-
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
90-
"behaviour.soft_hammer.enabled" :
91-
"behaviour.soft_hammer.disabled").get())
89+
.overlay(createEnabledKey(() -> this.isWorkingAllowed)
9290
.color(Color.WHITE.darker(1)))
9391
.widthRel(0.6f)
9492
.left(0)));

src/main/java/gregtech/common/covers/CoverItemFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
168168
.coverChildrenHeight()
169169
.setEnabledIf(b -> getFilterMode() != ItemFilterMode.FILTER_BOTH)
170170
.child(new ToggleButton()
171-
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
172-
"cover.generic.enabled" :
173-
"cover.generic.disabled").get())
174-
.color(Color.WHITE.main).shadow(false))
171+
.overlay(createEnabledKey(() -> this.allowFlow)
172+
.color(Color.WHITE.main)
173+
.shadow(false))
175174
.tooltip(tooltip -> tooltip
176175
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
177176
.size(72, 18)

src/main/java/gregtech/common/covers/CoverItemVoiding.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import codechicken.lib.render.pipeline.IVertexOperation;
2222
import codechicken.lib.vec.Cuboid6;
2323
import codechicken.lib.vec.Matrix4;
24-
import com.cleanroommc.modularui.api.drawable.IKey;
2524
import com.cleanroommc.modularui.factory.GuiData;
2625
import com.cleanroommc.modularui.factory.SidedPosGuiData;
2726
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -80,16 +79,15 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
8079

8180
@Override
8281
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
83-
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
82+
// noinspection DuplicatedCode
83+
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
8484

8585
return super.createUI(data, guiSyncManager)
8686
.child(Flow.row().height(18).widthRel(1f)
8787
.marginBottom(2)
8888
.child(new ToggleButton()
8989
.value(isWorking)
90-
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
91-
"behaviour.soft_hammer.enabled" :
92-
"behaviour.soft_hammer.disabled").get())
90+
.overlay(createEnabledKey(() -> this.isWorkingAllowed)
9391
.color(Color.WHITE.darker(1)))
9492
.widthRel(0.6f)
9593
.left(0)));

0 commit comments

Comments
 (0)