Search in sources :

Example 1 with GuiFileListItem

use of riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem in project Armourers-Workshop by RiskyKen.

the class GuiSkinLibrary method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float partialTickTime) {
    int oldMouseX = mouseX;
    int oldMouseY = mouseY;
    if (isDialogOpen()) {
        mouseX = mouseY = 0;
    }
    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
    super.drawScreen(mouseX, mouseY, partialTickTime);
    GL11.glPopAttrib();
    ILibraryManager libraryManager = ArmourersWorkshop.proxy.libraryManager;
    ArrayList<LibraryFile> files = libraryManager.getServerPublicFileList().getFileList();
    loadSaveButton.enabled = true;
    if (isLoading()) {
        loadSaveButton.displayString = GuiHelper.getLocalizedControlName(armourLibrary.getInventoryName(), "load");
        if (fileList.getSelectedListEntry() == null || ((GuiFileListItem) fileList.getSelectedListEntry()).getFile().directory) {
            loadSaveButton.displayString = "";
            loadSaveButton.enabled = false;
        }
    } else {
        loadSaveButton.displayString = GuiHelper.getLocalizedControlName(armourLibrary.getInventoryName(), "save");
    }
    if (!((Slot) inventorySlots.inventorySlots.get(36)).getHasStack() & !armourLibrary.isCreativeLibrary()) {
        loadSaveButton.displayString = "";
        loadSaveButton.enabled = false;
    }
    if (fileSwitchType == LibraryFileType.LOCAL) {
        files = libraryManager.getClientPublicFileList().getFileList();
        if (!mc.isIntegratedServerRunning()) {
            loadSaveButton.enabled = false;
            if (isLoading()) {
                loadSaveButton.enabled = ConfigHandler.allowClientsToUploadSkins;
            } else {
                loadSaveButton.enabled = ConfigHandler.allowClientsToDownloadSkins;
            }
        }
    } else {
        loadSaveButton.enabled = true;
    }
    if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
        files = libraryManager.getServerPrivateFileList(mc.thePlayer).getFileList();
    }
    String typeFilter = dropDownList.getListSelectedItem().tag;
    ISkinType skinTypeFilter = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(typeFilter);
    lastSkinType = skinTypeFilter;
    lastSearchText = searchTextbox.getText();
    IGuiListItem selectedItem = fileList.getSelectedListEntry();
    if (selectedItem != null) {
    // deleteButton.enabled = !((GuiFileListItem)selectedItem).getFile().readOnly;
    } else {
    // deleteButton.enabled = false;
    }
    fileList.setSelectedIndex(-1);
    fileList.clearList();
    if (!(currentFolder.equals("/") | currentFolder.equals(getPrivateRoot(player)))) {
        fileList.addListItem(new GuiFileListItem(new LibraryFile("../", "", null, true)));
        if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile().fileName.equals("../")) {
            fileList.setSelectedIndex(0);
        }
    }
    if (files != null) {
        for (int i = 0; i < files.size(); i++) {
            LibraryFile file = files.get(i);
            if (skinTypeFilter == null | skinTypeFilter == file.skinType) {
                if (file.filePath.equals(currentFolder)) {
                    if (!searchTextbox.getText().equals("")) {
                        if (file.fileName.toLowerCase().contains(searchTextbox.getText().toLowerCase())) {
                            fileList.addListItem(new GuiFileListItem(file));
                            if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile() == file) {
                                fileList.setSelectedIndex(fileList.getSize() - 1);
                            }
                        }
                    } else {
                        fileList.addListItem(new GuiFileListItem(file));
                        if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile() == file) {
                            fileList.setSelectedIndex(fileList.getSize() - 1);
                        }
                    }
                }
            }
        }
    }
    scrollAmount = scrollbar.getValue();
    fileList.setScrollPercentage(scrollbar.getPercentageValue());
    for (int i = 0; i < buttonList.size(); i++) {
        GuiButton button = (GuiButton) buttonList.get(i);
        if (button instanceof GuiIconButton) {
            ((GuiIconButton) button).drawRollover(mc, mouseX, mouseY);
        }
    }
    if (showModelPreviews()) {
        GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
        if (item != null && !item.getFile().isDirectory()) {
            SkinIdentifier identifier = new SkinIdentifier(0, new LibraryFile(item.getFile().getFullName()), 0, null);
            Skin skin = ClientSkinCache.INSTANCE.getSkin(identifier, true);
            if (skin != null) {
                SkinPointer skinPointer = new SkinPointer(identifier);
                int listRight = this.width - INVENTORY_WIDTH - PADDING * 5;
                listRight = MathHelper.clamp_int(listRight, 0, 200);
                listRight += INVENTORY_WIDTH + PADDING * 2 + 10;
                int listTop = TITLE_HEIGHT + 14 + PADDING * 2;
                int xSize = (this.width - listRight - PADDING) / 2;
                int ySize = (this.height - listTop - PADDING) / 2;
                float x = listRight + xSize;
                float y = listTop + ySize;
                float scale = 1F;
                scale = 1 * Math.min(xSize, ySize);
                ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
                int startX = listRight + PADDING;
                int startY = listTop + PADDING;
                int tarW = (int) (x + xSize);
                int tarH = (int) (y + ySize);
                drawRect(startX, startY, tarW, tarH, 0x77777777);
                if (scale > 8) {
                    GL11.glPushMatrix();
                    GL11.glTranslatef((float) x, (float) y, 500.0F);
                    GL11.glScalef(10, 10, -10);
                    GL11.glRotatef(30, 1, 0, 0);
                    GL11.glRotatef(45, 0, 1, 0);
                    float rotation = (float) ((double) System.currentTimeMillis() / 10 % 360);
                    GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
                    RenderHelper.enableStandardItemLighting();
                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
                    GL11.glEnable(GL11.GL_NORMALIZE);
                    GL11.glEnable(GL11.GL_COLOR_MATERIAL);
                    ModRenderHelper.enableAlphaBlend();
                    SkinItemRenderHelper.renderSkinAsItem(skin, skinPointer, true, false, tarW - startX, tarH - startY);
                    GL11.glPopAttrib();
                    GL11.glPopMatrix();
                }
            }
        }
    }
    GL11.glColor4f(1, 1, 1, 1);
    if (isDialogOpen()) {
        this.dialog.draw(oldMouseX, oldMouseY, partialTickTime);
    }
}
Also used : IGuiListItem(riskyken.armourersWorkshop.client.gui.controls.IGuiListItem) ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ILibraryManager(riskyken.armourersWorkshop.common.library.ILibraryManager) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier) ScaledResolution(net.minecraft.client.gui.ScaledResolution) GuiFileListItem(riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem) GuiButton(net.minecraft.client.gui.GuiButton) GuiIconButton(riskyken.armourersWorkshop.client.gui.controls.GuiIconButton) Slot(net.minecraft.inventory.Slot) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile)

Example 2 with GuiFileListItem

use of riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem in project Armourers-Workshop by RiskyKen.

the class GuiSkinLibrary method mouseClicked.

@Override
protected void mouseClicked(int mouseX, int mouseY, int button) {
    if (!isDialogOpen()) {
        searchTextbox.mouseClicked(mouseX, mouseY, button);
        filenameTextbox.mouseClicked(mouseX, mouseY, button);
        if (button == 1) {
            if (searchTextbox.isFocused()) {
                searchTextbox.setText("");
            }
            if (filenameTextbox.isFocused()) {
                filenameTextbox.setText("");
            }
        }
        if (!dropDownList.getIsDroppedDown()) {
            GuiFileListItem oldItem = (GuiFileListItem) fileList.getSelectedListEntry();
            if (fileList.mouseClicked(mouseX, mouseY, button)) {
                GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
                if (!item.getFile().isDirectory()) {
                    filenameTextbox.setText(item.getDisplayName());
                } else {
                    if (item.getFile().fileName.equals("../") & oldItem == item) {
                        goBackFolder();
                    } else if (oldItem == item) {
                        setCurrentFolder(item.getFile().getFullName() + "/");
                    }
                }
            }
        }
        scrollbar.setValue(scrollAmount);
        scrollbar.mousePressed(mc, mouseX, mouseY);
        setupLibraryEditButtons();
    }
    super.mouseClicked(mouseX, mouseY, button);
}
Also used : GuiFileListItem(riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem)

Example 3 with GuiFileListItem

use of riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem in project Armourers-Workshop by RiskyKen.

the class GuiSkinLibrary method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    String filename = filenameTextbox.getText().trim();
    if (button == fileSwitchlocal | button == fileSwitchRemotePublic | button == fileSwitchRemotePrivate) {
        if (button == fileSwitchlocal) {
            setFileSwitchType(LibraryFileType.LOCAL);
        }
        if (button == fileSwitchRemotePublic) {
            setFileSwitchType(LibraryFileType.SERVER_PUBLIC);
        }
        if (button == fileSwitchRemotePrivate) {
            setFileSwitchType(LibraryFileType.SERVER_PRIVATE);
        }
    }
    if (button == reloadButton) {
        if (fileSwitchType == LibraryFileType.LOCAL) {
            ILibraryManager libraryManager = ArmourersWorkshop.proxy.libraryManager;
            libraryManager.reloadLibrary();
        } else {
        // TODO reload server library
        }
    }
    if (button == openFolderButton) {
        openEquipmentFolder();
    }
    if (button == deleteButton) {
        if (fileList.getSelectedListEntry() != null) {
            GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
            openDialog(new GuiDialogDelete(this, armourLibrary.getInventoryName() + ".dialog.delete", this, 190, 100, item.getFile().isDirectory(), item.getDisplayName()));
        }
    }
    if (button == newFolderButton) {
        openDialog(new GuiDialogNewFolder(this, armourLibrary.getInventoryName() + ".dialog.newFolder", this, 190, 120));
    }
    if (button == checkBoxTrack) {
        trackFile = checkBoxTrack.isChecked();
    }
    GuiFileListItem fileItem = (GuiFileListItem) fileList.getSelectedListEntry();
    boolean clientLoad = false;
    boolean publicList = true;
    MessageClientGuiLoadSaveArmour message;
    if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
        // Is playing on a server.
        clientLoad = true;
    }
    if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
        publicList = false;
    }
    if (button == loadSaveButton) {
        if (fileItem != null && !fileItem.getFile().isDirectory()) {
            LibraryFile file = fileItem.getFile();
            if (isLoading()) {
                if (clientLoad) {
                    Skin itemData = SkinIOUtils.loadSkinFromFileName(file.filePath + filename + SkinIOUtils.SKIN_FILE_EXTENSION);
                    if (itemData != null) {
                        SkinUploadHelper.uploadSkinToServer(itemData);
                    }
                } else {
                    message = new MessageClientGuiLoadSaveArmour(file.fileName, file.filePath, LibraryPacketType.SERVER_LOAD, publicList, trackFile);
                    PacketHandler.networkWrapper.sendToServer(message);
                }
                filenameTextbox.setText("");
            }
        }
        if (!filename.isEmpty()) {
            if (!isLoading()) {
                if (fileExists(currentFolder, filename)) {
                    openDialog(new GuiDialogOverwrite(this, armourLibrary.getInventoryName() + ".dialog.overwrite", this, 190, 100, filename));
                    return;
                }
                if (clientLoad) {
                    message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
                    PacketHandler.networkWrapper.sendToServer(message);
                } else {
                    message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
                    PacketHandler.networkWrapper.sendToServer(message);
                }
            // filenameTextbox.setText("");
            }
        }
    }
    setupLibraryEditButtons();
}
Also used : MessageClientGuiLoadSaveArmour(riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour) GuiFileListItem(riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem) ILibraryManager(riskyken.armourersWorkshop.common.library.ILibraryManager) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile)

Aggregations

GuiFileListItem (riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem)3 ILibraryManager (riskyken.armourersWorkshop.common.library.ILibraryManager)2 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)2 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)2 GuiButton (net.minecraft.client.gui.GuiButton)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 Slot (net.minecraft.inventory.Slot)1 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)1 GuiIconButton (riskyken.armourersWorkshop.client.gui.controls.GuiIconButton)1 IGuiListItem (riskyken.armourersWorkshop.client.gui.controls.IGuiListItem)1 MessageClientGuiLoadSaveArmour (riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour)1 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)1 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)1