Search in sources :

Example 6 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class PanelVBarFill method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    IGuiRect bounds = this.getTransform();
    GlStateManager.pushMatrix();
    GlStateManager.color(1F, 1F, 1F, 1F);
    if (texBack != null) {
        texBack.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    float f = MathHelper.clamp(fillDriver.readValue(), 0F, 1F);
    Minecraft mc = Minecraft.getMinecraft();
    if (this.flipBar) {
        RenderUtils.startScissor(mc, new GuiRectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), (int) (bounds.getHeight() * f), 0));
    } else {
        RenderUtils.startScissor(mc, new GuiRectangle(bounds.getX(), bounds.getY() + (int) (bounds.getHeight() - (bounds.getHeight() * f)), bounds.getWidth(), (int) (bounds.getHeight() * f), 0));
    }
    if (this.clrThreshold > 0 && f < this.clrThreshold) {
        int tmpC = this.clrLow;
        if (lerpClr) {
            tmpC = RenderUtils.lerpRGB(clrLow, clrNorm, f / clrThreshold);
        }
        int a1 = (tmpC >> 24) & 255;
        int r1 = (tmpC >> 16) & 255;
        int g1 = (tmpC >> 8) & 255;
        int b1 = tmpC & 255;
        GlStateManager.color(r1 / 255F, g1 / 255F, b1 / 255F, a1 / 255F);
    } else {
        int a1 = this.clrNorm >> 24 & 255;
        int r1 = this.clrNorm >> 16 & 255;
        int g1 = this.clrNorm >> 8 & 255;
        int b1 = this.clrNorm & 255;
        GlStateManager.color(r1 / 255F, g1 / 255F, b1 / 255F, a1 / 255F);
    }
    if (texFill != null) {
        texFill.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    RenderUtils.endScissor(mc);
    GlStateManager.popMatrix();
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) Minecraft(net.minecraft.client.Minecraft)

Example 7 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class CanvasScrolling method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    float zs = zoomScale.readValue();
    if (isDragging) {
        int dx = (int) ((dragMX - mx) / zs);
        int dy = (int) ((dragMY - my) / zs);
        if (scrollBounds.getWidth() > 0) {
            float dsx = dx / (float) scrollBounds.getWidth() + dragSX;
            scrollX.writeValue(dsx);
            if (!hasDragged && Math.abs(dragSX - scrollX.readValue()) > 0.05F) {
                hasDragged = true;
            }
        }
        if (scrollBounds.getHeight() > 0) {
            float dsy = dy / (float) scrollBounds.getHeight() + dragSY;
            scrollY.writeValue(dsy);
            if (!hasDragged && Math.abs(dragSY - scrollY.readValue()) > 0.05F) {
                hasDragged = true;
            }
        }
    } else if (hasDragged) {
        hasDragged = false;
    }
    if (lsx != getScrollX() || lsy != getScrollY()) {
        this.updatePanelScroll();
    }
    GlStateManager.pushMatrix();
    Minecraft mc = Minecraft.getMinecraft();
    RenderUtils.startScissor(mc, new GuiRectangle(transform));
    int tx = transform.getX();
    int ty = transform.getY();
    GlStateManager.translate(tx - lsx * zs, ty - lsy * zs, 0F);
    GlStateManager.scale(zs, zs, 1F);
    int smx = (int) ((mx - tx) / zs) + lsx;
    int smy = (int) ((my - ty) / zs) + lsy;
    for (IGuiPanel panel : guiPanels) {
        if (panel.isEnabled()) {
            panel.drawPanel(smx, smy, partialTick);
        }
    }
    RenderUtils.endScissor(mc);
    GlStateManager.popMatrix();
}
Also used : IGuiPanel(betterquesting.api2.client.gui.panels.IGuiPanel) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) Minecraft(net.minecraft.client.Minecraft)

Example 8 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class GuiScrollingBase method drawBackground.

@Override
public void drawBackground(int mx, int my, float partialTick) {
    int listY = posY - scroll;
    int maxScroll = Math.max(0, getListHeight() - height);
    boolean isHovering = isWithin(mx, my, posX, posY, width - 8, height);
    int mx2 = !isHovering ? -256 : mx;
    int my2 = !isHovering ? -256 : my;
    if (maxScroll > 0 && (Mouse.isButtonDown(0) || Mouse.isButtonDown(2))) {
        if (dragScroll && (dragState == 0 || (dragState == -1 && isHovering))) {
            this.setScrollPos(scrollDrag - (my - myDrag));
            // Manual drag
            dragState = 0;
        } else if (dragState == 1 || (dragState == -1 && isWithin(mx, my, posX + width - 8, posY, 8, height))) {
            this.setScrollPos((int) ((my - posY - 8) / (float) (height - 20F) * maxScroll));
            // Scroll bar
            dragState = 1;
        } else {
            // Missed
            dragState = 3;
        }
    } else {
        // Idle
        dragState = -1;
        scrollDrag = scroll;
        myDrag = my;
    }
    scroll = MathHelper.clamp(scroll, 0, maxScroll);
    GlStateManager.pushMatrix();
    for (int i = 0; i < entries.size(); i++) {
        IScrollingEntry e = entries.get(i);
        boolean scissor = !e.canDrawOutsideBox(false);
        if (scissor) {
            RenderUtils.startScissor(mc, new GuiRectangle(posX, posY, width - 8, height));
        }
        e.drawBackground(mx2, my2, posX, listY, width - 8);
        if (scissor) {
            RenderUtils.endScissor(mc);
        }
        listY += e.getHeight();
    }
    if (!hideBounds) {
        RenderUtils.DrawLine(posX, posY, posX + width - 8, posY, 1F, getTextColor());
        RenderUtils.DrawLine(posX, posY + height, posX + width - 8, posY + height, 1F, getTextColor());
    }
    this.mc.renderEngine.bindTexture(currentTheme().getGuiTexture());
    if (maxScroll > 0) {
        this.drawTexturedModalRect(posX + width - 8, posY, 248, 0, 8, 20);
        int n = 20;
        while (n + 20 < height) {
            this.drawTexturedModalRect(posX + width - 8, posY + n, 248, 20, 8, 20);
            n += 20;
        }
        if (height % 20 != 0) {
            // Little bit of trickery here to neaten things up
            n -= 20 - height % 20;
        }
        this.drawTexturedModalRect(posX + width - 8, posY + n, 248, 40, 8, 20);
        this.drawTexturedModalRect(posX + width - 8, posY + (int) Math.max(0, n * (float) scroll / (float) maxScroll), 248, 60, 8, 20);
    }
    GlStateManager.popMatrix();
}
Also used : GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle)

Example 9 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class CanvasQuestLine method setQuestLine.

/**
 * Loads in quests and connecting lines
 * @param line The quest line to load
 */
public void setQuestLine(IQuestLine line) {
    // Rest contents
    this.getAllPanels().clear();
    if (line == null) {
        return;
    }
    EntityPlayer player = Minecraft.getMinecraft().player;
    UUID pid = QuestingAPI.getQuestingUUID(player);
    String bgString = line.getProperties().getProperty(NativeProps.BG_IMAGE);
    if (bgString != null && bgString.length() > 0) {
        ResourceLocation bgRes = new ResourceLocation(bgString);
        int bgSize = line.getProperties().getProperty(NativeProps.BG_SIZE);
        this.addPanel(new PanelGeneric(new GuiRectangle(0, 0, bgSize, bgSize), new SimpleTexture(bgRes, new GuiRectangle(0, 0, 256, 256))));
    }
    // Used later to center focus the quest line within the window
    boolean flag = false;
    int minX = 0;
    int minY = 0;
    int maxX = 0;
    int maxY = 0;
    HashMap<Integer, PanelButtonStorage<IQuest>> questBtns = new HashMap<>();
    for (IQuestLineEntry qle : line.getAllValues()) {
        int id = line.getKey(qle);
        IQuest quest = QuestDatabase.INSTANCE.getValue(id);
        if (quest == null || !isQuestShown(quest, pid)) {
            continue;
        }
        EnumQuestState qState = quest.getState(pid);
        IGuiTexture txFrame = null;
        IGuiColor txIconCol = null;
        boolean main = quest.getProperties().getProperty(NativeProps.MAIN);
        switch(qState) {
            case LOCKED:
                txFrame = main ? PresetTexture.QUEST_MAIN_0.getTexture() : PresetTexture.QUEST_NORM_0.getTexture();
                txIconCol = PresetColor.QUEST_ICON_LOCKED.getColor();
                break;
            case UNLOCKED:
                txFrame = main ? PresetTexture.QUEST_MAIN_1.getTexture() : PresetTexture.QUEST_NORM_1.getTexture();
                txIconCol = PresetColor.QUEST_ICON_UNLOCKED.getColor();
                break;
            case UNCLAIMED:
                txFrame = main ? PresetTexture.QUEST_MAIN_2.getTexture() : PresetTexture.QUEST_NORM_2.getTexture();
                txIconCol = PresetColor.QUEST_ICON_PENDING.getColor();
                break;
            case COMPLETED:
                txFrame = main ? PresetTexture.QUEST_MAIN_3.getTexture() : PresetTexture.QUEST_NORM_3.getTexture();
                txIconCol = PresetColor.QUEST_ICON_COMPLETE.getColor();
                break;
        }
        IGuiRect rect = new GuiRectangle(qle.getPosX(), qle.getPosY(), qle.getSize(), qle.getSize());
        PanelButtonStorage<IQuest> paBtn = new PanelButtonStorage<>(rect, buttonId, "", quest);
        paBtn.setTextures(new GuiTextureColored(txFrame, txIconCol), new GuiTextureColored(txFrame, txIconCol), new GuiTextureColored(txFrame, txIconCol));
        paBtn.setIcon(new ItemTexture(quest.getItemIcon()), 4);
        paBtn.setTooltip(quest.getTooltip(player));
        this.addPanel(paBtn);
        questBtns.put(id, paBtn);
        if (!flag) {
            minX = rect.getX();
            minY = rect.getY();
            maxX = minX + rect.getWidth();
            maxY = minY + rect.getHeight();
            flag = true;
        } else {
            minX = Math.min(minX, rect.getX());
            minY = Math.min(minY, rect.getY());
            maxX = Math.max(maxX, rect.getX() + rect.getWidth());
            maxY = Math.max(maxY, rect.getY() + rect.getHeight());
        }
    }
    for (Entry<Integer, PanelButtonStorage<IQuest>> entry : questBtns.entrySet()) {
        IQuest quest = entry.getValue().getStoredValue();
        List<IQuest> reqList = quest.getPrerequisites();
        if (reqList.size() <= 0) {
            continue;
        }
        boolean main = quest.getProperties().getProperty(NativeProps.MAIN);
        EnumQuestState qState = quest.getState(pid);
        IGuiLine lineRender = null;
        IGuiColor txLineCol = null;
        switch(qState) {
            case LOCKED:
                lineRender = PresetLine.QUEST_LOCKED.getLine();
                txLineCol = PresetColor.QUEST_LINE_LOCKED.getColor();
                break;
            case UNLOCKED:
                lineRender = PresetLine.QUEST_UNLOCKED.getLine();
                txLineCol = PresetColor.QUEST_LINE_UNLOCKED.getColor();
                break;
            case UNCLAIMED:
                lineRender = PresetLine.QUEST_PENDING.getLine();
                txLineCol = PresetColor.QUEST_LINE_PENDING.getColor();
                break;
            case COMPLETED:
                lineRender = PresetLine.QUEST_COMPLETE.getLine();
                txLineCol = PresetColor.QUEST_LINE_COMPLETE.getColor();
                break;
        }
        for (IQuest req : reqList) {
            int id = QuestDatabase.INSTANCE.getKey(req);
            PanelButtonStorage<IQuest> parBtn = questBtns.get(id);
            if (parBtn != null) {
                PanelLine prLine = new PanelLine(parBtn.getTransform(), entry.getValue().getTransform(), lineRender, main ? 8 : 4, txLineCol, 1);
                this.addPanel(prLine);
            }
        }
    }
    float frameW = getTransform().getWidth();
    float frameH = getTransform().getHeight();
    if (frameW <= 0 || frameH <= 0) {
        return;
    }
    minX -= margin;
    minY -= margin;
    maxX += margin;
    maxY += margin;
    float scale = Math.min(frameW / (maxX - minX), frameH / (maxY - minY));
    scale = MathHelper.clamp(scale, 0.25F, 2F);
    this.setZoom(scale);
    int scrollX = Math.round((maxX - minX) / 2F - (frameW / scale) / 2F);
    int scrollY = Math.round((maxY - minY) / 2F - (frameH / scale) / 2F);
    this.setScrollX(scrollX);
    this.setScrollY(scrollY);
}
Also used : HashMap(java.util.HashMap) IGuiColor(betterquesting.api2.client.gui.resources.colors.IGuiColor) IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) ResourceLocation(net.minecraft.util.ResourceLocation) UUID(java.util.UUID) PanelButtonStorage(betterquesting.api2.client.gui.controls.PanelButtonStorage) IQuest(betterquesting.api.questing.IQuest) IGuiTexture(betterquesting.api2.client.gui.resources.textures.IGuiTexture) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) IGuiLine(betterquesting.api2.client.gui.resources.lines.IGuiLine) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry) PanelLine(betterquesting.api2.client.gui.panels.content.PanelLine) SimpleTexture(betterquesting.api2.client.gui.resources.textures.SimpleTexture) GuiTextureColored(betterquesting.api2.client.gui.resources.textures.GuiTextureColored) EnumQuestState(betterquesting.api.enums.EnumQuestState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PanelGeneric(betterquesting.api2.client.gui.panels.content.PanelGeneric) ItemTexture(betterquesting.api2.client.gui.resources.textures.ItemTexture)

Example 10 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class GuiQuestLines method initPanel.

@Override
public void initPanel() {
    super.initPanel();
    if (selectedLineId >= 0) {
        selectedLine = QuestLineDatabase.INSTANCE.getValue(selectedLineId);
        if (selectedLine == null) {
            selectedLineId = -1;
        }
    } else {
        selectedLine = null;
    }
    boolean canEdit = QuestingAPI.getAPI(ApiReference.SETTINGS).canUserEdit(mc.player);
    PEventBroadcaster.INSTANCE.register(this, PEventButton.class);
    CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), PresetTexture.PANEL_MAIN.getTexture());
    this.addPanel(cvBackground);
    if (canEdit) {
        cvBackground.addPanel(new PanelButton(new GuiTransform(GuiAlign.BOTTOM_CENTER, -100, -16, 100, 16, 0), 0, I18n.format("gui.back")));
        cvBackground.addPanel(new PanelButton(new GuiTransform(GuiAlign.BOTTOM_CENTER, 0, -16, 100, 16, 0), 3, I18n.format("betterquesting.btn.edit")));
    } else {
        cvBackground.addPanel(new PanelButton(new GuiTransform(GuiAlign.BOTTOM_CENTER, -100, -16, 200, 16, 0), 0, I18n.format("gui.back")));
    }
    CanvasScrolling cvList = new CanvasScrolling(new GuiTransform(GuiAlign.LEFT_EDGE, new GuiPadding(16, 16, -158, 16), 0));
    cvBackground.addPanel(cvList);
    PanelVScrollBar pnQScroll = new PanelVScrollBar(new GuiTransform(GuiAlign.RIGHT_EDGE, new GuiPadding(0, 0, -8, 0), 0));
    cvList.setScrollDriverY(pnQScroll);
    cvBackground.addPanel(pnQScroll);
    pnQScroll.getTransform().setParent(cvList.getTransform());
    List<IQuestLine> lineList = QuestLineDatabase.INSTANCE.getAllValues();
    this.qlBtns = new PanelButtonStorage[lineList.size()];
    UUID playerID = QuestingAPI.getQuestingUUID(mc.player);
    for (int i = 0; i < lineList.size(); i++) {
        IQuestLine ql = lineList.get(i);
        PanelButtonStorage<IQuestLine> btnLine = new PanelButtonStorage<>(new GuiRectangle(0, i * 16, 142, 16, 0), 1, I18n.format(ql.getUnlocalisedName()), ql);
        boolean show = canEdit;
        if (!show) {
            for (int qID : ql.getAllKeys()) {
                IQuest q = QuestDatabase.INSTANCE.getValue(qID);
                if (q != null && CanvasQuestLine.isQuestShown(q, playerID)) {
                    show = true;
                    break;
                }
            }
        }
        if (!show || ql == selectedLine) {
            btnLine.setBtnState(false);
        }
        cvList.addPanel(btnLine);
        qlBtns[i] = btnLine;
    }
    pnQScroll.setEnabled(cvList.getScrollBounds().getHeight() > 0);
    CanvasTextured cvFrame = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(174, 16, 16, 66), 0), PresetTexture.AUX_FRAME_0.getTexture());
    cvBackground.addPanel(cvFrame);
    cvQuest = new CanvasQuestLine(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), 2);
    cvFrame.addPanel(cvQuest);
    cvDesc = new CanvasScrolling(new GuiTransform(GuiAlign.BOTTOM_EDGE, new GuiPadding(174, -66, 24, 16), 0));
    cvBackground.addPanel(cvDesc);
    paDesc = new PanelTextBox(new GuiRectangle(0, 0, cvDesc.getTransform().getWidth(), 0, 0), "", true);
    paDesc.setColor(PresetColor.TEXT_MAIN.getColor());
    cvDesc.addPanel(paDesc);
    scDesc = new PanelVScrollBar(new GuiTransform(GuiAlign.BOTTOM_RIGHT, new GuiPadding(-24, -66, 16, 16), 0));
    cvDesc.setScrollDriverY(scDesc);
    cvBackground.addPanel(scDesc);
    if (selectedLine != null) {
        cvQuest.setQuestLine(selectedLine);
        cvQuest.setZoom(lastZoom);
        cvQuest.setScrollX(lastScrollX);
        cvQuest.setScrollY(lastScrollY);
        paDesc.setText(I18n.format(selectedLine.getUnlocalisedDescription()));
        scDesc.setEnabled(cvDesc.getScrollBounds().getHeight() > 0);
    }
    // === DECORATIVE LINES ===
    IGuiRect ls0 = new GuiTransform(GuiAlign.TOP_LEFT, 16, 16, 0, 0, 0);
    ls0.setParent(cvBackground.getTransform());
    IGuiRect le0 = new GuiTransform(GuiAlign.TOP_LEFT, 166, 16, 0, 0, 0);
    le0.setParent(cvBackground.getTransform());
    PanelLine paLine0 = new PanelLine(ls0, le0, PresetLine.GUI_DIVIDER.getLine(), 1, PresetColor.GUI_DIVIDER.getColor(), -1);
    cvBackground.addPanel(paLine0);
    IGuiRect ls1 = new GuiTransform(GuiAlign.BOTTOM_LEFT, 16, -16, 0, 0, 0);
    ls1.setParent(cvBackground.getTransform());
    IGuiRect le1 = new GuiTransform(GuiAlign.BOTTOM_LEFT, 166, -16, 0, 0, 0);
    le1.setParent(cvBackground.getTransform());
    PanelLine paLine1 = new PanelLine(ls1, le1, PresetLine.GUI_DIVIDER.getLine(), 1, PresetColor.GUI_DIVIDER.getColor(), 1);
    cvBackground.addPanel(paLine1);
    IGuiRect ls3 = new GuiTransform(GuiAlign.BOTTOM_LEFT, 174, -16, 0, 0, 0);
    ls3.setParent(cvBackground.getTransform());
    IGuiRect le3 = new GuiTransform(GuiAlign.BOTTOM_RIGHT, -16, -16, 0, 0, 0);
    le3.setParent(cvBackground.getTransform());
    PanelLine paLine3 = new PanelLine(ls3, le3, PresetLine.GUI_DIVIDER.getLine(), 1, PresetColor.GUI_DIVIDER.getColor(), 1);
    cvBackground.addPanel(paLine3);
}
Also used : PanelButton(betterquesting.api2.client.gui.controls.PanelButton) IPanelButton(betterquesting.api2.client.gui.controls.IPanelButton) IQuest(betterquesting.api.questing.IQuest) PanelVScrollBar(betterquesting.api2.client.gui.panels.bars.PanelVScrollBar) PanelLine(betterquesting.api2.client.gui.panels.content.PanelLine) PanelTextBox(betterquesting.api2.client.gui.panels.content.PanelTextBox) IQuestLine(betterquesting.api.questing.IQuestLine) CanvasTextured(betterquesting.api2.client.gui.panels.CanvasTextured) CanvasScrolling(betterquesting.api2.client.gui.panels.lists.CanvasScrolling) UUID(java.util.UUID) PanelButtonStorage(betterquesting.api2.client.gui.controls.PanelButtonStorage)

Aggregations

GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)12 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)6 PanelButton (betterquesting.api2.client.gui.controls.PanelButton)5 CanvasTextured (betterquesting.api2.client.gui.panels.CanvasTextured)5 Minecraft (net.minecraft.client.Minecraft)5 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)4 PanelVScrollBar (betterquesting.api2.client.gui.panels.bars.PanelVScrollBar)4 PanelLine (betterquesting.api2.client.gui.panels.content.PanelLine)4 CanvasScrolling (betterquesting.api2.client.gui.panels.lists.CanvasScrolling)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Vector4f (org.lwjgl.util.vector.Vector4f)4 IQuest (betterquesting.api.questing.IQuest)3 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)3 GuiPadding (betterquesting.api2.client.gui.misc.GuiPadding)3 CanvasEmpty (betterquesting.api2.client.gui.panels.CanvasEmpty)3 PanelTextBox (betterquesting.api2.client.gui.panels.content.PanelTextBox)3 IGuiTexture (betterquesting.api2.client.gui.resources.textures.IGuiTexture)3 GuiTransform (betterquesting.api2.client.gui.misc.GuiTransform)2 PanelGeneric (betterquesting.api2.client.gui.panels.content.PanelGeneric)2 IGuiColor (betterquesting.api2.client.gui.resources.colors.IGuiColor)2