Search in sources :

Example 1 with AreaTypeWidget

use of me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget in project pnc-repressurized by TeamPneumatic.

the class ProgWidgetArea method addAreaTypeTooltip.

public void addAreaTypeTooltip(List<String> curTooltip) {
    curTooltip.add("Area type: " + type.getName());
    List<AreaTypeWidget> widgets = new ArrayList<>();
    type.addUIWidgets(widgets);
    for (AreaTypeWidget widget : widgets) {
        curTooltip.add(String.format("%s %s", I18n.format(widget.title), widget.getCurValue()));
    }
}
Also used : AreaTypeWidget(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget) ArrayList(java.util.ArrayList)

Example 2 with AreaTypeWidget

use of me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgWidgetArea method saveWidgets.

private void saveWidgets() {
    for (Pair<AreaTypeWidget, IGuiWidget> entry : areaTypeValueWidgets) {
        AreaTypeWidget widget = entry.getLeft();
        IGuiWidget guiWidget = entry.getRight();
        if (widget instanceof AreaTypeWidgetInteger) {
            AreaTypeWidgetInteger intWidget = (AreaTypeWidgetInteger) widget;
            intWidget.writeAction.accept(((WidgetTextFieldNumber) guiWidget).getValue());
        } else if (widget instanceof AreaTypeWidgetEnum<?>) {
            @SuppressWarnings("unchecked") AreaTypeWidgetEnum<Enum<?>> enumWidget = (AreaTypeWidgetEnum<Enum<?>>) widget;
            WidgetComboBox cbb = (WidgetComboBox) guiWidget;
            List<String> enumNames = getEnumNames(enumWidget.enumClass);
            Object[] enumValues = enumWidget.enumClass.getEnumConstants();
            Object selectedValue = enumValues[enumNames.indexOf(cbb.getText())];
            enumWidget.writeAction.accept((Enum<?>) selectedValue);
        }
    }
}
Also used : AreaTypeWidgetEnum(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetEnum) AreaTypeWidgetInteger(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetInteger) AreaTypeWidget(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget) IGuiWidget(me.desht.pneumaticcraft.client.gui.widget.IGuiWidget) ArrayList(java.util.ArrayList) List(java.util.List) AreaTypeWidgetEnum(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetEnum) WidgetComboBox(me.desht.pneumaticcraft.client.gui.widget.WidgetComboBox)

Example 3 with AreaTypeWidget

use of me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgWidgetArea method switchToWidgets.

private void switchToWidgets(AreaType type) {
    saveWidgets();
    areaTypeValueWidgets.forEach(p -> removeWidget(p.getRight()));
    areaTypeStaticWidgets.forEach(w -> removeWidget(w));
    areaTypeValueWidgets.clear();
    areaTypeStaticWidgets.clear();
    int curY = guiTop + 60;
    int x = guiLeft + 150;
    List<AreaTypeWidget> widgets = new ArrayList<>();
    type.addUIWidgets(widgets);
    for (AreaTypeWidget widget : widgets) {
        WidgetLabel titleWidget = new WidgetLabel(x, curY, I18n.format(widget.title));
        addWidget(titleWidget);
        areaTypeStaticWidgets.add(titleWidget);
        curY += fontRenderer.FONT_HEIGHT + 1;
        if (widget instanceof AreaTypeWidgetInteger) {
            AreaTypeWidgetInteger intWidget = (AreaTypeWidgetInteger) widget;
            WidgetTextFieldNumber intField = new WidgetTextFieldNumber(fontRenderer, x, curY, 40, fontRenderer.FONT_HEIGHT + 1);
            intField.setValue(intWidget.readAction.get());
            addWidget(intField);
            areaTypeValueWidgets.add(new ImmutablePair<AreaType.AreaTypeWidget, IGuiWidget>(widget, intField));
            curY += fontRenderer.FONT_HEIGHT + 20;
        } else if (widget instanceof AreaTypeWidgetEnum<?>) {
            AreaTypeWidgetEnum<?> enumWidget = (AreaTypeWidgetEnum<?>) widget;
            WidgetComboBox enumCbb = new WidgetComboBox(fontRenderer, x, curY, 80, fontRenderer.FONT_HEIGHT + 1).setFixedOptions();
            enumCbb.setElements(getEnumNames(enumWidget.enumClass));
            enumCbb.setText(enumWidget.readAction.get().toString());
            addWidget(enumCbb);
            areaTypeValueWidgets.add(new ImmutablePair<AreaType.AreaTypeWidget, IGuiWidget>(widget, enumCbb));
            curY += fontRenderer.FONT_HEIGHT + 20;
        } else {
            throw new IllegalStateException("Invalid widget type: " + widget.getClass());
        }
    }
}
Also used : WidgetLabel(me.desht.pneumaticcraft.client.gui.widget.WidgetLabel) AreaTypeWidgetInteger(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetInteger) WidgetTextFieldNumber(me.desht.pneumaticcraft.client.gui.widget.WidgetTextFieldNumber) IGuiWidget(me.desht.pneumaticcraft.client.gui.widget.IGuiWidget) ArrayList(java.util.ArrayList) AreaType(me.desht.pneumaticcraft.common.progwidgets.area.AreaType) AreaTypeWidgetEnum(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetEnum) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) AreaTypeWidget(me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget) WidgetComboBox(me.desht.pneumaticcraft.client.gui.widget.WidgetComboBox)

Aggregations

ArrayList (java.util.ArrayList)3 AreaTypeWidget (me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget)3 IGuiWidget (me.desht.pneumaticcraft.client.gui.widget.IGuiWidget)2 WidgetComboBox (me.desht.pneumaticcraft.client.gui.widget.WidgetComboBox)2 AreaTypeWidgetEnum (me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetEnum)2 AreaTypeWidgetInteger (me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidgetInteger)2 List (java.util.List)1 WidgetLabel (me.desht.pneumaticcraft.client.gui.widget.WidgetLabel)1 WidgetTextFieldNumber (me.desht.pneumaticcraft.client.gui.widget.WidgetTextFieldNumber)1 AreaType (me.desht.pneumaticcraft.common.progwidgets.area.AreaType)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1