Search in sources :

Example 1 with IGuiWidget

use of me.desht.pneumaticcraft.client.gui.widget.IGuiWidget in project pnc-repressurized by TeamPneumatic.

the class GuiProgWidgetLiquidFilter method addValidFluids.

private void addValidFluids() {
    List<Fluid> fluids = new ArrayList<Fluid>();
    for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
        if (fluid.getLocalizedName(new FluidStack(fluid, 1)).toLowerCase().contains(searchField.getText())) {
            fluids.add(fluid);
        }
    }
    fluids.sort(Comparator.comparing(Fluid::getName));
    scrollbar.setStates(Math.max(0, (fluids.size() - GRID_WIDTH * GRID_HEIGHT + GRID_WIDTH - 1) / GRID_WIDTH));
    int offset = scrollbar.getState() * GRID_WIDTH;
    for (IGuiWidget widget : widgets) {
        if (widget.getID() >= 0 && widget instanceof WidgetFluidFilter) {
            int idWithOffset = widget.getID() + offset;
            ((WidgetFluidFilter) widget).setFluid(idWithOffset >= 0 && idWithOffset < fluids.size() ? fluids.get(idWithOffset) : null);
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IGuiWidget(me.desht.pneumaticcraft.client.gui.widget.IGuiWidget) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) WidgetFluidFilter(me.desht.pneumaticcraft.client.gui.widget.WidgetFluidFilter)

Example 2 with IGuiWidget

use of me.desht.pneumaticcraft.client.gui.widget.IGuiWidget in project pnc-repressurized by TeamPneumatic.

the class ProgWidgetBlockCondition method getOptionWindow.

@Override
@SideOnly(Side.CLIENT)
public GuiScreen getOptionWindow(GuiProgrammer guiProgrammer) {
    return new GuiProgWidgetCondition(this, guiProgrammer) {

        @Override
        public void initGui() {
            super.initGui();
            addWidget(new GuiCheckBox(500, guiLeft + 5, guiTop + 60, 0xFF404040, I18n.format("gui.progWidget.conditionBlock.checkForAir")).setChecked(checkingForAir).setTooltip(I18n.format("gui.progWidget.conditionBlock.checkForAir.tooltip")));
            addWidget(new GuiCheckBox(501, guiLeft + 5, guiTop + 72, 0xFF404040, I18n.format("gui.progWidget.conditionBlock.checkForLiquids")).setChecked(checkingForLiquids).setTooltip(I18n.format("gui.progWidget.conditionBlock.checkForLiquids.tooltip")));
        }

        @Override
        protected boolean requiresNumber() {
            return false;
        }

        @Override
        protected boolean isSidedWidget() {
            return false;
        }

        @Override
        public void actionPerformed(IGuiWidget widget) {
            switch(widget.getID()) {
                case 500:
                    checkingForAir = !checkingForAir;
                    break;
                case 501:
                    checkingForLiquids = !checkingForLiquids;
                    break;
                default:
                    super.actionPerformed(widget);
                    break;
            }
        }
    };
}
Also used : IGuiWidget(me.desht.pneumaticcraft.client.gui.widget.IGuiWidget) GuiProgWidgetCondition(me.desht.pneumaticcraft.client.gui.programmer.GuiProgWidgetCondition) GuiCheckBox(me.desht.pneumaticcraft.client.gui.widget.GuiCheckBox) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IGuiWidget

use of me.desht.pneumaticcraft.client.gui.widget.IGuiWidget in project pnc-repressurized by TeamPneumatic.

the class GuiPneumaticScreenBase method drawScreen.

@Override
public void drawScreen(int x, int y, float partialTicks) {
    if (getTexture() != null) {
        FMLClientHandler.instance().getClient().getTextureManager().bindTexture(getTexture());
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    }
    super.drawScreen(x, y, partialTicks);
    for (IGuiWidget widget : widgets) {
        widget.render(x, y, partialTicks);
    }
    for (IGuiWidget widget : widgets) {
        widget.postRender(x, y, partialTicks);
    }
    GlStateManager.enableTexture2D();
    GlStateManager.color(0.25f, 0.25f, 0.25f, 1.0f);
    List<String> tooltip = new ArrayList<>();
    for (Object obj : buttonList) {
        if (obj instanceof GuiButtonSpecial) {
            GuiButtonSpecial button = (GuiButtonSpecial) obj;
            if (button.x < x && button.x + button.getWidth() > x && button.y < y && button.y + button.getHeight() > y) {
                button.getTooltip(tooltip);
            }
        }
    }
    boolean shift = PneumaticCraftRepressurized.proxy.isSneakingInGui();
    for (IGuiWidget widget : widgets) {
        if (widget.getBounds().contains(x, y))
            widget.addTooltip(x, y, tooltip, shift);
    }
    if (!tooltip.isEmpty()) {
        List<String> localizedTooltip = new ArrayList<>();
        for (String line : tooltip) {
            String localizedLine = I18n.format(line);
            for (String wrappedLine : localizedLine.split("\\\\n")) {
                String[] lines = WordUtils.wrap(wrappedLine, 50).split(System.getProperty("line.separator"));
                localizedTooltip.addAll(Arrays.asList(lines));
            }
        }
        drawHoveringText(localizedTooltip, x, y, fontRenderer);
    }
    GlStateManager.color(0.25f, 0.25f, 0.25f, 1.0f);
}
Also used : IGuiWidget(me.desht.pneumaticcraft.client.gui.widget.IGuiWidget) ArrayList(java.util.ArrayList)

Example 4 with IGuiWidget

use of me.desht.pneumaticcraft.client.gui.widget.IGuiWidget 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 5 with IGuiWidget

use of me.desht.pneumaticcraft.client.gui.widget.IGuiWidget 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

IGuiWidget (me.desht.pneumaticcraft.client.gui.widget.IGuiWidget)5 ArrayList (java.util.ArrayList)4 WidgetComboBox (me.desht.pneumaticcraft.client.gui.widget.WidgetComboBox)2 AreaTypeWidget (me.desht.pneumaticcraft.common.progwidgets.area.AreaType.AreaTypeWidget)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 GuiProgWidgetCondition (me.desht.pneumaticcraft.client.gui.programmer.GuiProgWidgetCondition)1 GuiCheckBox (me.desht.pneumaticcraft.client.gui.widget.GuiCheckBox)1 WidgetFluidFilter (me.desht.pneumaticcraft.client.gui.widget.WidgetFluidFilter)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 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1