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

CyclopsMC / IntegratedDynamics / 16552051255

27 Jul 2025 01:58PM UTC coverage: 53.206% (+8.0%) from 45.161%
16552051255

push

github

rubensworks
Resolve minor TODOs

2888 of 8740 branches covered (33.04%)

Branch coverage included in aggregate %.

17341 of 29280 relevant lines covered (59.22%)

3.08 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.IModHelpers;
16
import org.cyclops.integrateddynamics.Reference;
17
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElement;
18
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElementValueType;
19
import org.cyclops.integrateddynamics.api.client.gui.subgui.IGuiInputElementValueTypeClient;
20
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
21
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
22
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
23
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
24
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
25
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.SubGuiValueTypeInfoBase;
26
import org.cyclops.integrateddynamics.core.inventory.container.ContainerAspectSettings;
27
import org.cyclops.integrateddynamics.core.logicprogrammer.client.RenderPattern;
28
import org.lwjgl.glfw.GLFW;
29

30
import java.util.List;
31

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

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

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

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

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

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

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

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

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

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

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

109
        setActiveProperty(activePropertyIndex);
×
110
    }
×
111

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

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

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

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

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

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

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

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

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

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

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

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

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

225

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

235
    public class SubGuiValueTypeInfo extends SubGuiValueTypeInfoBase<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> {
236

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

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

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

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

256
    }
257

258
}
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