Search in sources :

Example 26 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiUnitProgrammer method render.

public void render(int x, int y, boolean showFlow, boolean showInfo, boolean translate) {
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    int origX = x;
    int origY = y;
    x -= translatedX;
    y -= translatedY;
    float scale = getScale();
    x = (int) (x / scale);
    y = (int) (y / scale);
    if (scaleScroll.getState() != lastZoom) {
        float shift = SCALE_PER_STEP * (scaleScroll.getState() - lastZoom);
        if (new Rectangle(guiLeft + startX, guiTop + startY, areaWidth, areaHeight).contains(origX, origY) && !scaleScroll.isDragging()) {
            translatedX += shift * x;
            translatedY += shift * y;
        } else {
            translatedX += areaWidth / 2 * shift;
            translatedY += areaHeight / 2 * shift;
        }
    }
    lastZoom = scaleScroll.getState();
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    GL11.glScissor((guiLeft + startX) * sr.getScaleFactor(), (sr.getScaledHeight() - areaHeight - (guiTop + startY)) * sr.getScaleFactor(), areaWidth * sr.getScaleFactor(), areaHeight * sr.getScaleFactor());
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glPushMatrix();
    GL11.glTranslated(translatedX, translatedY, 0);
    GL11.glScaled(scale, scale, 1);
    if (showFlow)
        showFlow();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    for (IProgWidget widget : progWidgets) {
        GL11.glPushMatrix();
        GL11.glTranslated(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
        GL11.glScaled(0.5, 0.5, 1);
        widget.render();
        GL11.glPopMatrix();
    }
    for (IProgWidget widget : progWidgets) {
        List<String> errors = new ArrayList<String>();
        widget.addErrors(errors, progWidgets);
        if (errors.size() > 0) {
            drawBorder(widget, 0xFFFF0000);
        } else {
            List<String> warnings = new ArrayList<String>();
            widget.addWarnings(warnings, progWidgets);
            if (warnings.size() > 0) {
                drawBorder(widget, 0xFFFFFF00);
            }
        }
    }
    renderAdditionally();
    GL11.glColor4d(1, 1, 1, 1);
    if (showInfo) {
        for (IProgWidget widget : progWidgets) {
            GL11.glPushMatrix();
            GL11.glTranslated(widget.getX() + guiLeft, widget.getY() + guiTop, 0);
            GL11.glScaled(0.5, 0.5, 1);
            widget.renderExtraInfo();
            GL11.glPopMatrix();
        }
    }
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    boolean isLeftClicking = Mouse.isButtonDown(0);
    if (translate && isLeftClicking && wasClicking && !scaleScroll.isDragging() && new Rectangle(guiLeft + startX, guiTop + startY, areaWidth, areaHeight).contains(origX, origY)) {
        translatedX += origX - lastMouseX;
        translatedY += origY - lastMouseY;
    }
    wasClicking = isLeftClicking;
    lastMouseX = origX;
    lastMouseY = origY;
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList)

Example 27 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiUnitProgrammer method renderForeground.

public void renderForeground(int x, int y, IProgWidget tooltipExcludingWidget) {
    IProgWidget widget = getHoveredWidget(x, y);
    if (widget != null && widget != tooltipExcludingWidget) {
        List<String> tooltip = new ArrayList<>();
        widget.getTooltip(tooltip);
        List<String> errors = new ArrayList<>();
        widget.addErrors(errors, progWidgets);
        if (errors.size() > 0) {
            tooltip.add(TextFormatting.RED + I18n.format("gui.programmer.errors"));
            for (String s : errors) {
                String msg = I18n.hasKey(s) ? I18n.format(s) : s;
                String[] lines = WordUtils.wrap("- " + msg, 30).split(System.getProperty("line.separator"));
                for (String line : lines) {
                    tooltip.add(TextFormatting.RED + "   " + line);
                }
            }
        }
        List<String> warnings = new ArrayList<String>();
        widget.addWarnings(warnings, progWidgets);
        if (warnings.size() > 0) {
            tooltip.add(TextFormatting.YELLOW + I18n.format("gui.programmer.warnings"));
            for (String s : warnings) {
                String msg = I18n.hasKey(s) ? I18n.format(s) : s;
                String[] lines = WordUtils.wrap("- " + msg, 30).split(System.getProperty("line.separator"));
                for (String line : lines) {
                    tooltip.add(TextFormatting.YELLOW + "   " + line);
                }
            }
        }
        addAdditionalInfoToTooltip(widget, tooltip);
        if (tooltip.size() > 0)
            drawHoveringText(tooltip, x - guiLeft, y - guiTop, fontRenderer);
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) ArrayList(java.util.ArrayList)

Example 28 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiDroneDebuggerOptions method drawScreen.

@Override
public void drawScreen(int x, int y, float partialTicks) {
    if (selectedDrone != null) {
        Minecraft.getMinecraft().fontRenderer.drawString("Drone name: " + selectedDrone.getName(), 20, screenHeight - 15, 0xFFFFFFFF, true);
        Minecraft.getMinecraft().fontRenderer.drawString("Routine: " + selectedDrone.getLabel(), screenWidth / 2, screenHeight - 15, 0xFFFFFFFF, true);
    }
    programmerUnit.render(x, y, true, true, true);
    programmerUnit.renderForeground(x, y, null);
    if (selectedDrone == null) {
        drawCenteredString(Minecraft.getMinecraft().fontRenderer, "Press '" + Keyboard.getKeyName(KeyHandler.getInstance().keybindDebuggingDrone.getKeyCode()) + "' on a Drone when tracked by an Entity Tracker to debug the Drone.", screenWidth / 2, screenHeight / 2, 0xFFFF0000);
    }
    IProgWidget widget = programmerUnit.getHoveredWidget(x, y);
    if (widget == null)
        widget = areaShowingWidget;
    upgradeHandler.getShowingPositions().clear();
    if (widget != null) {
        int widgetId = selectedDrone.getProgWidgets().indexOf(widget);
        for (DebugEntry entry : selectedDrone.getDebugEntries()) {
            if (entry.getProgWidgetId() == widgetId && !entry.getPos().equals(new BlockPos(0, 0, 0))) {
                upgradeHandler.getShowingPositions().add(entry.getPos());
            }
        }
    }
}
Also used : IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) BlockPos(net.minecraft.util.math.BlockPos) DebugEntry(me.desht.pneumaticcraft.common.entity.living.DebugEntry)

Example 29 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class GuiDroneDebuggerOptions method initGui.

@Override
public void initGui(IGuiScreen gui) {
    GuiScreen guiScreen = (GuiScreen) gui;
    screenWidth = guiScreen.width;
    screenHeight = guiScreen.height;
    if (PneumaticCraftRepressurized.proxy.getPlayer() != null) {
        ItemStack helmet = PneumaticCraftRepressurized.proxy.getPlayer().getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        if (helmet != null) {
            int entityId = NBTUtil.getInteger(helmet, NBTKeys.PNEUMATIC_HELMET_DEBUGGING_DRONE);
            Entity entity = PneumaticCraftRepressurized.proxy.getClientWorld().getEntityByID(entityId);
            if (entity instanceof EntityDrone) {
                selectedDrone = (EntityDrone) entity;
            }
        }
    }
    int spacing = 20;
    programmingStartX = spacing;
    programmingWidth = guiScreen.width - spacing * 2;
    programmingHeight = guiScreen.height - spacing - PROGRAMMING_START_Y;
    programmerUnit = new DebugInfoProgrammerUnit(selectedDrone != null ? selectedDrone.getProgWidgets() : new ArrayList<IProgWidget>(), gui.getFontRenderer(), 0, 0, guiScreen.width, guiScreen.height, 100, programmingStartX, PROGRAMMING_START_Y, programmingWidth, programmingHeight, 0, 0, 0);
    if (selectedDrone != null) {
        for (IProgWidget widget : selectedDrone.getProgWidgets()) {
            if (widget instanceof ProgWidgetStart) {
                programmerUnit.gotoPiece(widget);
                break;
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) EntityDrone(me.desht.pneumaticcraft.common.entity.living.EntityDrone) GuiScreen(net.minecraft.client.gui.GuiScreen) IGuiScreen(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IGuiScreen) ItemStack(net.minecraft.item.ItemStack) ProgWidgetStart(me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)

Example 30 with IProgWidget

use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.

the class TileEntityProgrammer method getWidgetsFromNBT.

private static void getWidgetsFromNBT(NBTTagCompound tag, List<IProgWidget> progWidgets) {
    NBTTagList widgetTags = tag.getTagList("widgets", 10);
    for (int i = 0; i < widgetTags.tagCount(); i++) {
        NBTTagCompound widgetTag = widgetTags.getCompoundTagAt(i);
        String widgetName = widgetTag.getString("name");
        for (IProgWidget widget : WidgetRegistrator.registeredWidgets) {
            if (widgetName.equals(widget.getWidgetString())) {
                // create the right progWidget for the given id tag.
                IProgWidget addedWidget = widget.copy();
                addedWidget.readFromNBT(widgetTag);
                progWidgets.add(addedWidget);
                break;
            }
        }
    }
    updatePuzzleConnections(progWidgets);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IProgWidget(me.desht.pneumaticcraft.common.progwidgets.IProgWidget) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

IProgWidget (me.desht.pneumaticcraft.common.progwidgets.IProgWidget)33 Point (java.awt.Point)10 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 PacketProgrammerUpdate (me.desht.pneumaticcraft.common.network.PacketProgrammerUpdate)4 ProgWidgetStart (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetStart)4 GuiScreen (net.minecraft.client.gui.GuiScreen)3 BlockPos (net.minecraft.util.math.BlockPos)3 IProgrammable (me.desht.pneumaticcraft.api.item.IProgrammable)2 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)2 PacketGuiButton (me.desht.pneumaticcraft.common.network.PacketGuiButton)2 PacketUpdateTextfield (me.desht.pneumaticcraft.common.network.PacketUpdateTextfield)2 IVariableWidget (me.desht.pneumaticcraft.common.progwidgets.IVariableWidget)2 ProgWidgetArea (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetArea)2 ProgWidgetCoordinate (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinate)2 ProgWidgetCoordinateOperator (me.desht.pneumaticcraft.common.progwidgets.ProgWidgetCoordinateOperator)2 Entity (net.minecraft.entity.Entity)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 Rectangle (java.awt.Rectangle)1