Search in sources :

Example 1 with MessageClientGuiLoadSaveArmour

use of riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour in project Armourers-Workshop by RiskyKen.

the class GuiSkinLibrary method dialogResult.

@Override
public void dialogResult(AbstractGuiDialog dialog, DialogResult result) {
    if (result == DialogResult.OK) {
        if (dialog instanceof GuiDialogNewFolder) {
            GuiDialogNewFolder newFolderDialog = (GuiDialogNewFolder) dialog;
            if (fileSwitchType == LibraryFileType.LOCAL) {
                File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
                dir = new File(dir, newFolderDialog.getFolderName());
                if (!dir.exists()) {
                    dir.mkdir();
                }
                reloadLocalLibrary();
                ModLogger.log(String.format("making folder call %s in %s", newFolderDialog.getFolderName(), currentFolder));
                ModLogger.log("full path: " + dir.getAbsolutePath());
            } else {
                MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
                message.newFolder(new LibraryFile(newFolderDialog.getFolderName(), currentFolder, null, true), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
                PacketHandler.networkWrapper.sendToServer(message);
            }
        }
        if (dialog instanceof GuiDialogDelete) {
            GuiDialogDelete deleteDialog = (GuiDialogDelete) dialog;
            boolean isFolder = deleteDialog.isFolder();
            String name = deleteDialog.getFileName();
            if (fileSwitchType == LibraryFileType.LOCAL) {
                File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
                if (deleteDialog.isFolder()) {
                    dir = new File(dir, name + "/");
                } else {
                    dir = new File(dir, name + SkinIOUtils.SKIN_FILE_EXTENSION);
                }
                if (dir.isDirectory() == isFolder) {
                    if (dir.exists()) {
                        if (isFolder) {
                            try {
                                FileUtils.deleteDirectory(dir);
                                reloadLocalLibrary();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            LibraryFile libraryFile = new LibraryFile(currentFolder + deleteDialog.getFileName());
                            ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
                            dir.delete();
                            reloadLocalLibrary();
                        }
                    }
                }
            } else {
                MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
                message.delete(new LibraryFile(deleteDialog.getFileName(), currentFolder, null, isFolder), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
                PacketHandler.networkWrapper.sendToServer(message);
            // ClientSkinCache.INSTANCE.clearIdForFileName(currentFolder + deleteDialog.getName());
            }
        }
        if (dialog instanceof GuiDialogOverwrite) {
            GuiDialogOverwrite overwriteDialog = (GuiDialogOverwrite) dialog;
            MessageClientGuiLoadSaveArmour message;
            boolean clientLoad = false;
            boolean publicList = true;
            if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
                // Is playing on a server.
                clientLoad = true;
            }
            if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
                publicList = false;
            }
            if (clientLoad) {
                message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
                PacketHandler.networkWrapper.sendToServer(message);
            } else {
                message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
                PacketHandler.networkWrapper.sendToServer(message);
            }
            LibraryFile libraryFile = new LibraryFile(currentFolder + overwriteDialog.getFileName());
            ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
        // reloadLocalLibrary();
        // TODO clear name lookup list on clients or just removed this one name
        }
    }
    super.dialogResult(dialog, result);
}
Also used : MessageClientGuiLoadSaveArmour(riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour) MessageClientGuiSkinLibraryCommand(riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiSkinLibraryCommand) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) IOException(java.io.IOException) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) File(java.io.File) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 2 with MessageClientGuiLoadSaveArmour

use of riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour 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

LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)2 MessageClientGuiLoadSaveArmour (riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour)2 File (java.io.File)1 IOException (java.io.IOException)1 GuiFileListItem (riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem)1 ILibraryManager (riskyken.armourersWorkshop.common.library.ILibraryManager)1 MessageClientGuiSkinLibraryCommand (riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiSkinLibraryCommand)1 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)1 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)1