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