Search in sources :

Example 1 with HypixelApiFriendObject

use of club.sk1er.website.api.requests.HypixelApiFriendObject in project Hyperium by HyperiumClient.

the class HypixelFriendsGui method pack.

protected void pack() {
    int textWidth = Math.max(ResolutionUtil.current().getScaledWidth() / 9, 100);
    int height = 20;
    if (textField == null)
        textField = new GuiTextField(nextId(), Minecraft.getMinecraft().fontRendererObj, ResolutionUtil.current().getScaledWidth() / 2 - textWidth / 2, 25, textWidth, height);
    reg("SORT", new GuiButton(nextId(), ResolutionUtil.current().getScaledWidth() - 153, 23, 150, 20, "Sort by: "), guiButton -> {
        int ord = sortType.ordinal();
        ord++;
        if (ord >= FriendSortType.values().length)
            ord = 0;
        sortType = FriendSortType.values()[ord];
        rebuildFriends();
        this.friends.sort(sortType);
    }, guiButton -> guiButton.displayString = "Sort by: " + sortType.getName());
    reg("PARTY", new GuiButton(nextId(), ResolutionUtil.current().getScaledWidth() - 153, 23 + 21, 150, 20, "Party Selected"), guiButton -> {
        Iterator<HypixelApiFriendObject> iterator = selected.iterator();
        while (iterator.hasNext()) {
            HypixelApiFriendObject next = iterator.next();
            if (iterator.hasNext())
                Hyperium.INSTANCE.getHandlers().getCommandQueue().queue("/party invite " + next.getName());
            else
                Hyperium.INSTANCE.getHandlers().getCommandQueue().register("/party invite " + next.getName(), () -> guiButton.enabled = true);
        }
        selected.clear();
        guiButton.enabled = false;
    }, guiButton -> {
        try {
            if (selected.size() > 10 && !Hyperium.INSTANCE.getHandlers().getDataHandler().getCurrentUser().get().isStaffOrYT()) {
                guiButton.enabled = false;
                guiButton.displayString = "Too many players!";
            } else {
                guiButton.enabled = true;
                guiButton.displayString = "Party Selected";
            }
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    });
    reg("REMOVE", new GuiButton(nextId(), ResolutionUtil.current().getScaledWidth() - 153, 23 + 21 * 2, 150, 20, "Remove (Hold down)"), guiButton -> {
    }, guiButton -> {
        if (guiButton.isMouseOver() && Mouse.isButtonDown(0) && guiButton.enabled) {
            if (selected.isEmpty()) {
                guiButton.displayString = "Select people first!";
                return;
            }
            removeTicks++;
            final int totalTick = 100;
            if (removeTicks >= totalTick) {
                Iterator<HypixelApiFriendObject> iterator = selected.iterator();
                while (iterator.hasNext()) {
                    HypixelApiFriendObject next = iterator.next();
                    if (iterator.hasNext())
                        Hyperium.INSTANCE.getHandlers().getCommandQueue().queue("/friend remove " + next.getName());
                    else
                        Hyperium.INSTANCE.getHandlers().getCommandQueue().register("/friend remove " + next.getName(), () -> guiButton.enabled = true);
                }
                guiButton.enabled = false;
                selected.clear();
            }
            double remaining = totalTick - removeTicks;
            guiButton.displayString = ChatColor.RED + "Removing in: " + NumberUtil.round(remaining / 20, 1);
        } else {
            removeTicks = 0;
            guiButton.displayString = "Remove (Hold down)";
        }
    });
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) HypixelApiFriendObject(club.sk1er.website.api.requests.HypixelApiFriendObject) GuiTextField(net.minecraft.client.gui.GuiTextField) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with HypixelApiFriendObject

use of club.sk1er.website.api.requests.HypixelApiFriendObject in project Hyperium by HyperiumClient.

the class HypixelFriendsGui method mouseClicked.

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
    super.mouseClicked(mouseX, mouseY, mouseButton);
    textField.mouseClicked(mouseX, mouseY, mouseButton);
    selectedItem = null;
    GuiBoxItem<HypixelApiFriendObject> remove = null;
    for (GuiBoxItem<HypixelApiFriendObject> selectedBox : selectedBoxes) {
        if (selectedBox.getBox().isMouseOver(mouseX, mouseY)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
                selected.remove(selectedBox.getObject());
                remove = selectedBox;
            } else
                selectedItem = selectedBox;
        }
    }
    if (remove != null) {
        selectedBoxes.remove(remove);
    }
    for (GuiBoxItem<HypixelApiFriendObject> selectedBox : friendListBoxes) {
        if (selectedBox.getBox().isMouseOver(mouseX, mouseY)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
                if (selected.contains(selectedBox.getObject()))
                    continue;
                selected.add(selectedBox.getObject());
                GuiBoxItem<HypixelApiFriendObject> e = new GuiBoxItem<>(new GuiBlock(2 + 5, columnWidth + 5, topRenderBound + 1 + (selected.size()) * 11, topRenderBound + 1 + (selected.size() + 1) * 11), selectedBox.getObject());
                selectedBoxes.add(e);
                selectedItem = e;
            } else
                selectedItem = selectedBox;
        }
    }
}
Also used : GuiBoxItem(cc.hyperium.gui.GuiBoxItem) HypixelApiFriendObject(club.sk1er.website.api.requests.HypixelApiFriendObject) GuiBlock(cc.hyperium.gui.GuiBlock)

Example 3 with HypixelApiFriendObject

use of club.sk1er.website.api.requests.HypixelApiFriendObject in project Hyperium by HyperiumClient.

the class HypixelFriendsGui method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    selectedBoxes.clear();
    friendListBoxes.clear();
    friends.removeIf(hypixelApiFriendObject -> !hypixelApiFriendObject.getDisplay().toLowerCase().contains(textField.getText().toLowerCase()));
    super.drawScreen(mouseX, mouseY, partialTicks);
    textField.drawTextBox();
    // Some long name
    final int bottomRenderBound = ResolutionUtil.current().getScaledHeight() / 9 * 8;
    if (selectedItem != null) {
        GuiBlock box = selectedItem.getBox();
        int left = box.getLeft() - 2;
        int right = box.getLeft() + fontRendererObj.getStringWidth(selectedItem.getObject().getDisplay()) + 2;
        int top = box.getTop() - 2;
        int bottom = top + 10;
        if (top >= topRenderBound && bottom <= bottomRenderBound) {
            Gui.drawRect(left, top, right, top + 1, Color.RED.getRGB());
            Gui.drawRect(left, bottom, right, bottom + 1, Color.RED.getRGB());
            Gui.drawRect(right, top, right - 1, bottom, Color.RED.getRGB());
            Gui.drawRect(left, top, left + 1, bottom, Color.RED.getRGB());
        }
    }
    GuiBlock namesBlock = new GuiBlock(2, columnWidth, topRenderBound, topRenderBound);
    int row = 1;
    namesBlock.drawString("Currently selected: ", fontRendererObj, false, true, namesBlock.getWidth() / 2, 1, true, true, Color.RED.getRGB(), true);
    for (HypixelApiFriendObject object : selected) {
        namesBlock.drawString(object.getDisplay(), fontRendererObj, false, false, 5, 1 + row * 11, true, true, Color.WHITE.getRGB(), true);
        selectedBoxes.add(new GuiBoxItem<>(new GuiBlock(2 + 5, namesBlock.getRight() + 5, namesBlock.getTop() + 1 + row * 11, namesBlock.getTop() + 1 + (row + 1) * 11), object));
        row++;
    }
    GuiBlock friendsBlock = new GuiBlock(namesBlock.getRight() + 15, ResolutionUtil.current().getScaledWidth() - 100, topRenderBound, bottomRenderBound);
    int drawX = friendsBlock.getLeft();
    int drawY = friendsBlock.getTop() - offset;
    if (drawY > bottomRenderBound) {
        offset = 0;
    }
    int cols = 1;
    while (drawX + columnWidth * cols < friendsBlock.getRight()) {
        cols++;
    }
    cols -= 1;
    if (cols <= 0)
        return;
    for (HypixelApiFriendObject object : friends.get()) {
        if (drawX + columnWidth > friendsBlock.getRight()) {
            drawX = friendsBlock.getLeft();
            drawY += 11;
        }
        if (selectedItem != null && selectedItem.getObject().equals(object) && !selected.contains(selectedItem.getObject())) {
            selectedItem = new GuiBoxItem<>(new GuiBlock(drawX, drawX + columnWidth, drawY + friendsBlock.getTop(), drawY + friendsBlock.getTop() + 11), object);
        }
        if (friendsBlock.drawString(object.getDisplay(), fontRendererObj, false, false, drawX - friendsBlock.getLeft(), drawY, false, false, Color.WHITE.getRGB(), true)) {
            GuiBoxItem<HypixelApiFriendObject> e = new GuiBoxItem<>(new GuiBlock(drawX, drawX + columnWidth, drawY + friendsBlock.getTop(), drawY + friendsBlock.getTop() + 11), object);
            friendListBoxes.add(e);
        }
        drawX += columnWidth;
    }
    // After first wave, if bottom of people is still not on screen, fix
    if (drawY < topRenderBound)
        offset = 0;
}
Also used : GuiBoxItem(cc.hyperium.gui.GuiBoxItem) HypixelApiFriendObject(club.sk1er.website.api.requests.HypixelApiFriendObject) GuiBlock(cc.hyperium.gui.GuiBlock)

Aggregations

HypixelApiFriendObject (club.sk1er.website.api.requests.HypixelApiFriendObject)3 GuiBlock (cc.hyperium.gui.GuiBlock)2 GuiBoxItem (cc.hyperium.gui.GuiBoxItem)2 ExecutionException (java.util.concurrent.ExecutionException)1 GuiButton (net.minecraft.client.gui.GuiButton)1 GuiTextField (net.minecraft.client.gui.GuiTextField)1