• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 15366166327

31 May 2025 05:58PM UTC coverage: 44.766% (-0.5%) from 45.303%
15366166327

push

github

rubensworks
Bump mod version

2565 of 8515 branches covered (30.12%)

Branch coverage included in aggregate %.

11734 of 23427 relevant lines covered (50.09%)

2.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/cyclops/integrateddynamics/core/client/gui/container/ContainerScreenAspectSettings.java
1
package org.cyclops.integrateddynamics.core.client.gui.container;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.gui.Font;
7
import net.minecraft.client.gui.GuiGraphics;
8
import net.minecraft.client.resources.language.I18n;
9
import net.minecraft.nbt.CompoundTag;
10
import net.minecraft.network.chat.Component;
11
import net.minecraft.resources.ResourceLocation;
12
import net.minecraft.world.entity.player.Inventory;
13
import org.cyclops.cyclopscore.client.gui.component.button.ButtonText;
14
import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended;
15
import org.cyclops.cyclopscore.helper.Helpers;
16
import org.cyclops.cyclopscore.helper.L10NHelpers;
17
import org.cyclops.cyclopscore.helper.RenderHelpers;
18
import org.cyclops.integrateddynamics.Reference;
19
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElement;
20
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElementValueType;
21
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
22
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
23
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
24
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
25
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
26
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.GuiElementValueTypeString;
27
import org.cyclops.integrateddynamics.core.inventory.container.ContainerAspectSettings;
28
import org.cyclops.integrateddynamics.core.logicprogrammer.RenderPattern;
29
import org.lwjgl.glfw.GLFW;
30

31
import java.util.List;
32

33
/**
34
 * Gui for aspect settings.
35
 * @author rubensworks
36
 */
37
public class ContainerScreenAspectSettings extends ContainerScreenExtended<ContainerAspectSettings> {
38

39
    private static final int ERROR_WIDTH = 13;
40
    private static final int ERROR_HEIGHT = 13;
41
    private static final int OK_WIDTH = 14;
42
    private static final int OK_HEIGHT = 12;
43

44
    private final List<IAspectPropertyTypeInstance> propertyTypes;
45
    protected final SubGuiHolder subGuiHolder = new SubGuiHolder();
×
46
    protected IGuiInputElementValueType<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> guiElement = null;
×
47
    protected int activePropertyIndex = 0;
×
48
    protected RenderPattern propertyConfigPattern = null;
×
49
    protected SubGuiValueTypeInfo propertyInfo = null;
×
50
    private ButtonText buttonLeft = null;
×
51
    private ButtonText buttonRight = null;
×
52
    private ButtonText buttonExit = null;
×
53
    private Component lastError;
54

55
    public ContainerScreenAspectSettings(ContainerAspectSettings container, Inventory inventory, Component title) {
56
        super(container, inventory, title);
×
57

58
        //noinspection deprecation
59
        this.propertyTypes = Lists.newArrayList(container.getAspect().getDefaultProperties().getTypes());
×
60
    }
×
61

62
    @Override
63
    protected ResourceLocation constructGuiTexture() {
64
        return ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "textures/gui/aspect_settings.png");
×
65
    }
66

67
    public int getActivePropertyIndex() {
68
        return activePropertyIndex;
×
69
    }
70

71
    protected void saveSetting() {
72
        if(guiElement != null && lastError == null) {
×
73
            container.setValue(ValueDeseralizationContext.ofClient(), getActiveProperty(), guiElement.getValue());
×
74
        }
75
    }
×
76

77
    protected void refreshButtonEnabled() {
78
        buttonLeft.active = getActivePropertyIndex() > 0;
×
79
        buttonRight.active = getActivePropertyIndex() < propertyTypes.size() - 1;
×
80
    }
×
81

82
    @Override
83
    protected int getBaseYSize() {
84
        return 213;
×
85
    }
86

87
    @Override
88
    public void init() {
89
        super.init();
×
90
        subGuiHolder.init(this.leftPos, this.topPos);
×
91
        addRenderableWidget(buttonExit = new ButtonText(leftPos + 7, topPos + 5, 12, 10, Component.translatable("gui.cyclopscore.up"), Component.literal("<<"), createServerPressable(ContainerAspectSettings.BUTTON_EXIT, (button) -> {
×
92
            saveSetting();
×
93
        }), true));
×
94
        addRenderableWidget(buttonLeft = new ButtonText(leftPos + 21, topPos + 5, 10, 10, Component.translatable("gui.cyclopscore.left"), Component.literal("<"), (button) -> {
×
95
            saveSetting();
×
96
            if(getActivePropertyIndex() > 0) {
×
97
                setActiveProperty(getActivePropertyIndex() - 1);
×
98
                refreshButtonEnabled();
×
99
            }
100
        }, true));
×
101
        addRenderableWidget(buttonRight = new ButtonText(leftPos + 159, topPos + 5, 10, 10, Component.translatable("gui.cyclopscore.right"), Component.literal(">"), (button) -> {
×
102
            saveSetting();
×
103
            if(getActivePropertyIndex() < propertyTypes.size()) {
×
104
                setActiveProperty(getActivePropertyIndex() + 1);
×
105
                refreshButtonEnabled();
×
106
            }
107
        }, true));
×
108
        refreshButtonEnabled();
×
109

110
        setActiveProperty(activePropertyIndex);
×
111
    }
×
112

113
    @Override
114
    protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
115
        super.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
×
116
        subGuiHolder.renderBg(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, partialTicks, mouseX, mouseY);
×
117
    }
×
118

119
    @Override
120
    protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
121
        // super.drawGuiContainerForegroundLayer(matrixStack, mouseX, mouseY);
122
        subGuiHolder.drawGuiContainerForegroundLayer(guiGraphics, this.leftPos, this.topPos, getMinecraft().getTextureManager(), font, mouseX, mouseY);
×
123

124
        IAspectPropertyTypeInstance activeProperty = getActiveProperty();
×
125
        if(activeProperty != null) {
×
126
            String label = L10NHelpers.localize(activeProperty.getTranslationKey());
×
127
            RenderHelpers.drawScaledCenteredString(guiGraphics.pose(), guiGraphics.bufferSource(), font, label, 88, 10, 0,
×
128
                    1.0F, 140, Helpers.RGBToInt(10, 10, 10), false, Font.DisplayMode.NORMAL);
×
129
            if (RenderHelpers.isPointInRegion(this.leftPos + 40, this.topPos, 110, 20, mouseX, mouseY)) {
×
130
                String unlocalizedInfo = activeProperty.getTranslationKey() + ".info";
×
131
                if (I18n.exists(unlocalizedInfo)) {
×
132
                    drawTooltip(Lists.newArrayList(Component.translatable(unlocalizedInfo)
×
133
                            .withStyle(ChatFormatting.GRAY)), guiGraphics.pose(), mouseX - this.leftPos, mouseY - this.topPos + 20);
×
134
                }
135
            }
136
        }
137
    }
×
138

139
    @Override
140
    public boolean charTyped(char typedChar, int keyCode) {
141
        if(!subGuiHolder.charTyped(typedChar, keyCode)) {
×
142
            if (keyCode == 1 || this.getMinecraft().options.keyInventory.getKey().getValue() == keyCode) {
×
143
                saveSetting();
×
144
                this.getMinecraft().player.closeContainer();
×
145
            } else {
146
                return super.charTyped(typedChar, keyCode);
×
147
            }
148
        } else {
149
            if(guiElement != null) {
×
150
                onValueChanged();
×
151
            }
152
        }
153
        return false;
×
154
    }
155

156
    @Override
157
    public boolean keyPressed(int typedChar, int keyCode, int modifiers) {
158
        if (typedChar != GLFW.GLFW_KEY_ESCAPE) {
×
159
            if (this.subGuiHolder.keyPressed(typedChar, keyCode, modifiers)) {
×
160
                if(guiElement != null) {
×
161
                    onValueChanged();
×
162
                }
163
                return true;
×
164
            } else {
165
                return false;
×
166
            }
167
        } else {
168
            saveSetting();
×
169
            return super.keyPressed(typedChar, keyCode, modifiers);
×
170
        }
171
    }
172

173
    @Override
174
    public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
175
        return subGuiHolder.mouseClicked(mouseX, mouseY, mouseButton)
×
176
                || super.mouseClicked(mouseX, mouseY, mouseButton);
×
177
    }
178

179
    protected void onValueChanged() {
180
        lastError = guiElement.validate();
×
181
    }
×
182

183
    protected IAspectPropertyTypeInstance getActiveProperty() {
184
        return propertyTypes.get(Math.max(0, Math.min(propertyTypes.size() - 1, activePropertyIndex)));
×
185
    }
186

187
    protected void setActiveProperty(int index) {
188
        onActivateElement(propertyTypes.get(activePropertyIndex = index));
×
189
    }
×
190

191
    protected void onActivateElement(IAspectPropertyTypeInstance property) {
192
        // Deactivate old element
193
        if(guiElement != null) {
×
194
            guiElement.deactivate();
×
195
            subGuiHolder.removeSubGui(propertyConfigPattern);
×
196
            subGuiHolder.removeSubGui(propertyInfo);
×
197
        }
198

199
        // Determine element type
200
        IValueTypeLogicProgrammerElement lpElement = property.getType().createLogicProgrammerElement();
×
201
        guiElement = lpElement.createInnerGuiElement();
×
202
        if (guiElement == null) {
×
203
            throw new UnsupportedOperationException("Tried to invoke createInnerGuiElement on a value type that does not have an inner gui element: " + property.getType().getTypeName());
×
204
        }
205

206
        // Create new element
207
        guiElement.setValidator(property.getValidator());
×
208
        subGuiHolder.addSubGui(propertyConfigPattern = guiElement.createSubGui(8, 17, 160, 91, this, (ContainerAspectSettings) getMenu()));
×
209
        subGuiHolder.addSubGui(propertyInfo = new SubGuiValueTypeInfo(guiElement));
×
210
        propertyConfigPattern.init(leftPos, topPos);
×
211
        guiElement.activate();
×
212
        syncInputValue();
×
213
        lastError = guiElement.validate();
×
214
    }
×
215

216
    protected void syncInputValue() {
217
        IAspectPropertyTypeInstance property = getActiveProperty();
×
218
        IValue value = container.getPropertyValue(ValueDeseralizationContext.of(Minecraft.getInstance().player.level()), property);
×
219
        if(value != null) {
×
220
            guiElement.setValue(value);
×
221
            guiElement.setValueInGui(propertyConfigPattern, false);
×
222
        }
223
        onValueChanged();
×
224
    }
×
225

226

227
    @Override
228
    public void onUpdate(int valueId, CompoundTag value) {
229
        super.onUpdate(valueId, value);
×
230
        IAspectPropertyTypeInstance property = container.getPropertyIds().get(valueId);
×
231
        if(property != null && getActiveProperty() == property) {
×
232
            syncInputValue();
×
233
        }
234
    }
×
235

236
    public class SubGuiValueTypeInfo extends GuiElementValueTypeString.SubGuiValueTypeInfo<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> {
237

238
        public SubGuiValueTypeInfo(IGuiInputElement<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> element) {
×
239
            super(ContainerScreenAspectSettings.this, (ContainerAspectSettings) ContainerScreenAspectSettings.this.container, element, 8, 105, 160, 20);
×
240
        }
×
241

242
        @Override
243
        protected boolean showError() {
244
            return true;
×
245
        }
246

247
        @Override
248
        protected Component getLastError() {
249
            return lastError;
×
250
        }
251

252
        @Override
253
        protected ResourceLocation getTexture() {
254
            return texture;
×
255
        }
256

257
    }
258

259
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc