Search in sources :

Example 1 with SimpleTexture

use of betterquesting.api2.client.gui.resources.textures.SimpleTexture in project BetterQuesting by Funwayguy.

the class GuiHome method initPanel.

@Override
public void initPanel() {
    super.initPanel();
    PEventBroadcaster.INSTANCE.register(this, PEventButton.class);
    ResourceLocation homeGui = new ResourceLocation(QuestSettings.INSTANCE.getProperty(NativeProps.HOME_IMAGE));
    IGuiTexture homeSplashBG = new SimpleTexture(homeGui, new GuiRectangle(0, 0, 256, 128));
    IGuiTexture homeSplashTitle = new SimpleTexture(homeGui, new GuiRectangle(0, 128, 256, 128)).maintainAspect(true);
    float ancX = QuestSettings.INSTANCE.getProperty(NativeProps.HOME_ANC_X);
    float ancY = QuestSettings.INSTANCE.getProperty(NativeProps.HOME_ANC_Y);
    int offX = QuestSettings.INSTANCE.getProperty(NativeProps.HOME_OFF_X);
    int offY = QuestSettings.INSTANCE.getProperty(NativeProps.HOME_OFF_Y);
    // Background panel
    CanvasTextured bgCan = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), PresetTexture.PANEL_MAIN.getTexture());
    this.addPanel(bgCan);
    // Inner canvas bounds
    CanvasEmpty inCan = new CanvasEmpty(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(16, 16, 16, 16), 0));
    bgCan.addPanel(inCan);
    CanvasTextured splashCan = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 32), 0), homeSplashBG);
    inCan.addPanel(splashCan);
    CanvasTextured splashTitle = new CanvasTextured(new GuiTransform(new Vector4f(ancX, ancY, ancX, ancY), new GuiPadding(offX, offY, -256 - offX, -128 - offY), 0), homeSplashTitle);
    splashCan.addPanel(splashTitle);
    PanelButton btnExit = new PanelButton(new GuiTransform(new Vector4f(0F, 1F, 0.25F, 1F), new GuiPadding(0, -32, 0, 0), 0), 0, I18n.format("betterquesting.home.exit"));
    inCan.addPanel(btnExit);
    PanelButton btnQuests = new PanelButton(new GuiTransform(new Vector4f(0.25F, 1F, 0.5F, 1F), new GuiPadding(0, -32, 0, 0), 0), 1, I18n.format("betterquesting.home.quests"));
    inCan.addPanel(btnQuests);
    PanelButton btnParty = new PanelButton(new GuiTransform(new Vector4f(0.5F, 1F, 0.75F, 1F), new GuiPadding(0, -32, 0, 0), 0), 2, I18n.format("betterquesting.home.party"));
    inCan.addPanel(btnParty);
    PanelButton btnTheme = new PanelButton(new GuiTransform(new Vector4f(0.75F, 1F, 1F, 1F), new GuiPadding(0, -32, 0, 0), 0), 3, I18n.format("betterquesting.home.theme"));
    inCan.addPanel(btnTheme);
    if (QuestingAPI.getAPI(ApiReference.SETTINGS).canUserEdit(mc.player)) {
        PanelButton btnEdit = new PanelButton(new GuiTransform(GuiAlign.TOP_LEFT, new GuiPadding(0, 0, -16, -16), 0), 4, "").setIcon(PresetIcon.ICON_GEAR.getTexture());
        inCan.addPanel(btnEdit);
    }
}
Also used : IGuiTexture(betterquesting.api2.client.gui.resources.textures.IGuiTexture) Vector4f(org.lwjgl.util.vector.Vector4f) PanelButton(betterquesting.api2.client.gui.controls.PanelButton) IPanelButton(betterquesting.api2.client.gui.controls.IPanelButton) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) ResourceLocation(net.minecraft.util.ResourceLocation) CanvasTextured(betterquesting.api2.client.gui.panels.CanvasTextured) GuiTransform(betterquesting.api2.client.gui.misc.GuiTransform) SimpleTexture(betterquesting.api2.client.gui.resources.textures.SimpleTexture) GuiPadding(betterquesting.api2.client.gui.misc.GuiPadding) CanvasEmpty(betterquesting.api2.client.gui.panels.CanvasEmpty)

Example 2 with SimpleTexture

use of betterquesting.api2.client.gui.resources.textures.SimpleTexture 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)

Aggregations

GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)2 IGuiTexture (betterquesting.api2.client.gui.resources.textures.IGuiTexture)2 SimpleTexture (betterquesting.api2.client.gui.resources.textures.SimpleTexture)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 EnumQuestState (betterquesting.api.enums.EnumQuestState)1 IQuest (betterquesting.api.questing.IQuest)1 IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)1 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)1 PanelButton (betterquesting.api2.client.gui.controls.PanelButton)1 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)1 GuiPadding (betterquesting.api2.client.gui.misc.GuiPadding)1 GuiTransform (betterquesting.api2.client.gui.misc.GuiTransform)1 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)1 CanvasEmpty (betterquesting.api2.client.gui.panels.CanvasEmpty)1 CanvasTextured (betterquesting.api2.client.gui.panels.CanvasTextured)1 PanelGeneric (betterquesting.api2.client.gui.panels.content.PanelGeneric)1 PanelLine (betterquesting.api2.client.gui.panels.content.PanelLine)1 IGuiColor (betterquesting.api2.client.gui.resources.colors.IGuiColor)1 IGuiLine (betterquesting.api2.client.gui.resources.lines.IGuiLine)1 GuiTextureColored (betterquesting.api2.client.gui.resources.textures.GuiTextureColored)1