Search in sources :

Example 6 with IQuestLineEntry

use of betterquesting.api.questing.IQuestLineEntry 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 7 with IQuestLineEntry

use of betterquesting.api.questing.IQuestLineEntry in project BetterQuesting by Funwayguy.

the class ToolboxToolGrab method disableTool.

@Override
public void disableTool() {
    if (grabbed != null) {
        IQuestLineEntry qle = gui.getQuestLine().getQuestLine().getValue(grabID);
        if (qle != null) {
            // Reset position
            grabbed.x = qle.getPosX();
            grabbed.y = qle.getPosY();
        }
    }
    grabbed = null;
    grabID = -1;
}
Also used : IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry)

Example 8 with IQuestLineEntry

use of betterquesting.api.questing.IQuestLineEntry in project BetterQuesting by Funwayguy.

the class ToolboxToolScale method disableTool.

@Override
public void disableTool() {
    if (grabbed != null) {
        IQuestLineEntry qle = gui.getQuestLine().getQuestLine().getValue(grabID);
        if (qle != null) {
            // Reset size
            grabbed.width = qle.getSize();
            grabbed.height = qle.getSize();
        }
    }
    grabbed = null;
    grabID = -1;
}
Also used : IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry)

Example 9 with IQuestLineEntry

use of betterquesting.api.questing.IQuestLineEntry in project BetterQuesting by Funwayguy.

the class LegacyLoader_v0 method readLine.

public void readLine(IQuestLine qLine, JsonObject json) {
    IPropertyContainer props = qLine.getProperties();
    props.setProperty(NativeProps.NAME, JsonHelper.GetString(json, "name", "New Quest Line"));
    props.setProperty(NativeProps.DESC, JsonHelper.GetString(json, "description", "No Description"));
    for (JsonElement je : JsonHelper.GetArray(json, "quests")) {
        if (je == null || !je.isJsonObject()) {
            continue;
        }
        JsonObject json2 = je.getAsJsonObject();
        IQuestLineEntry entry = new QuestLineEntry(JsonHelper.GetNumber(json2, "x", 0).intValue(), JsonHelper.GetNumber(json2, "y", 0).intValue(), 24);
        int qID = JsonHelper.GetNumber(json2, "id", -1).intValue();
        if (qID >= 0) {
            qLine.add(entry, qID);
        }
    }
}
Also used : IPropertyContainer(betterquesting.api.properties.IPropertyContainer) JsonElement(com.google.gson.JsonElement) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry) QuestLineEntry(betterquesting.questing.QuestLineEntry) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry) JsonObject(com.google.gson.JsonObject)

Example 10 with IQuestLineEntry

use of betterquesting.api.questing.IQuestLineEntry in project BetterQuesting by Funwayguy.

the class PktHandlerImport method handleServer.

@Override
public void handleServer(NBTTagCompound tag, EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    if (!isOP) {
        BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to import quests without OP permissions!");
        sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
        // Player is not operator. Do nothing
        return;
    }
    NBTTagCompound jsonBase = tag.getCompoundTag("data");
    IQuestDatabase impQuestDB = new ImportedQuests();
    IQuestLineDatabase impQuestLineDB = new ImportedQuestLines();
    impQuestDB.readFromNBT(jsonBase.getTagList("quests", 10), EnumSaveType.CONFIG);
    impQuestLineDB.readFromNBT(jsonBase.getTagList("lines", 10), EnumSaveType.CONFIG);
    BetterQuesting.logger.log(Level.INFO, "Importing " + impQuestDB.size() + " quest(s) and " + impQuestLineDB.size() + " quest line(s) from " + sender.getGameProfile().getName());
    HashMap<Integer, Integer> remapped = getRemappedIDs(impQuestDB.getAllKeys());
    for (Entry<Integer, Integer> entry : remapped.entrySet()) {
        QuestDatabase.INSTANCE.add(impQuestDB.getValue(entry.getKey()), entry.getValue());
    }
    for (IQuestLine questLine : impQuestLineDB.getAllValues()) {
        for (IQuestLineEntry qle : questLine.getAllValues()) {
            int oldID = questLine.getKey(qle);
            questLine.removeKey(oldID);
            questLine.add(qle, remapped.get(oldID));
        }
        QuestLineDatabase.INSTANCE.add(questLine, QuestLineDatabase.INSTANCE.nextKey());
    }
    PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
    PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ImportedQuestLines(betterquesting.client.importers.ImportedQuestLines) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry) ImportedQuests(betterquesting.client.importers.ImportedQuests) TextComponentString(net.minecraft.util.text.TextComponentString) IQuestDatabase(betterquesting.api.questing.IQuestDatabase) IQuestLine(betterquesting.api.questing.IQuestLine) IQuestLineDatabase(betterquesting.api.questing.IQuestLineDatabase)

Aggregations

IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 QuestingPacket (betterquesting.api.network.QuestingPacket)3 IQuest (betterquesting.api.questing.IQuest)3 IQuestLine (betterquesting.api.questing.IQuestLine)3 QuestLineEntry (betterquesting.questing.QuestLineEntry)2 GuiButtonQuestInstance (betterquesting.api.client.gui.controls.GuiButtonQuestInstance)1 EnumQuestState (betterquesting.api.enums.EnumQuestState)1 IPropertyContainer (betterquesting.api.properties.IPropertyContainer)1 IQuestDatabase (betterquesting.api.questing.IQuestDatabase)1 IQuestLineDatabase (betterquesting.api.questing.IQuestLineDatabase)1 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)1 GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)1 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)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 IGuiTexture (betterquesting.api2.client.gui.resources.textures.IGuiTexture)1