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

CyclopsMC / IntegratedDynamics / 15366205963

31 May 2025 06:03PM UTC coverage: 45.019% (-0.5%) from 45.524%
15366205963

push

github

rubensworks
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21

2555 of 8509 branches covered (30.03%)

Branch coverage included in aggregate %.

11885 of 23566 relevant lines covered (50.43%)

2.4 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.evaluate.variable.IValue;
20
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
21
import org.cyclops.integrateddynamics.api.logicprogrammer.IValueTypeLogicProgrammerElement;
22
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectPropertyTypeInstance;
23
import org.cyclops.integrateddynamics.core.client.gui.subgui.SubGuiHolder;
24
import org.cyclops.integrateddynamics.core.evaluate.variable.gui.GuiElementValueTypeString;
25
import org.cyclops.integrateddynamics.core.inventory.container.ContainerAspectSettings;
26
import org.cyclops.integrateddynamics.core.logicprogrammer.RenderPattern;
27
import org.lwjgl.glfw.GLFW;
28

29
import java.util.List;
30

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

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

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

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

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

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

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

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

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

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

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

108
        setActiveProperty(activePropertyIndex);
×
109
    }
×
110

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

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

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

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

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

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

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

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

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

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

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

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

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

224

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

234
    public class SubGuiValueTypeInfo extends GuiElementValueTypeString.SubGuiValueTypeInfo<RenderPattern, ContainerScreenAspectSettings, ContainerAspectSettings> {
235

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

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

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

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

255
    }
256

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