use of riskyken.armourersWorkshop.common.library.ILibraryManager in project Armourers-Workshop by RiskyKen.
the class EntitySkinHandler method getRandomSkinOfType.
public LibraryFile getRandomSkinOfType(ISkinType skinType) {
ILibraryManager libraryManager = ArmourersWorkshop.getProxy().libraryManager;
LibraryFileList fileList = null;
if (ArmourersWorkshop.isDedicated()) {
fileList = libraryManager.getServerPublicFileList();
} else {
fileList = libraryManager.getClientPublicFileList();
}
ArrayList<LibraryFile> typeList = fileList.getCachedFileListForSkinType(skinType);
if (typeList == null) {
return null;
}
ArrayList<LibraryFile> validFiles = new ArrayList<LibraryFile>();
for (int i = 0; i < typeList.size(); i++) {
if (typeList.get(i).filePath.startsWith(ConfigHandler.enitiySpawnSkinTargetPath)) {
validFiles.add(typeList.get(i));
}
}
// touhou
Random random = new Random();
if (!validFiles.isEmpty()) {
return validFiles.get(random.nextInt(validFiles.size()));
}
return null;
}
use of riskyken.armourersWorkshop.common.library.ILibraryManager 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);
}
}
use of riskyken.armourersWorkshop.common.library.ILibraryManager 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();
}
Aggregations