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);
}
}
}
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;
}
}
};
}
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);
}
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);
}
}
}
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());
}
}
}
Aggregations