Better GUI Texture Selector

This commit is contained in:
Kam committed 2024-03-13 17:19:13 -04:00
1 parent 221ce89026
commit 3d4e917b0e
5 files changed
+455 -490

No files matched your search

@@ -1,92 +0,0 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
public class GuiNPCTextures extends GuiNpcSelectionInterface
{
public GuiNPCTextures(EntityNPCInterface npc,GuiScreen parent)
{
super(npc, parent, npc.display.texture);
title = "Select Texture";
this.parent = parent;
}
public void initGui()
{
super.initGui();
int index = npc.display.texture.lastIndexOf("/");
if(index > 0){
String asset = npc.display.texture.substring(index + 1);
if(npc.display.texture.equals(assets.getAsset(asset)))
slot.selected = asset;
}
}
public void drawScreen(int i, int j, float f)
{
npc.isDrawn = true;
int l = (width/2)-180;
int i1 = (height/2) - 90;
GL11.glEnable(32826 /*GL_RESCALE_NORMAL_EXT*/);
GL11.glEnable(2903 /*GL_COLOR_MATERIAL*/);
GL11.glPushMatrix();
GL11.glTranslatef(l + 33, i1 + 131, 50F);
float f1 = (50F * 5) / npc.display.modelSize;
GL11.glScalef(-f1, f1, f1);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
float f2 = npc.renderYawOffset;
float f3 = npc.rotationYaw;
float f4 = npc.rotationPitch;
float f7 = npc.rotationYawHead;
float f5 = (float)(l + 33) - i;
float f6 = (float)((i1 + 131) - 50) - j;
GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-(float)Math.atan(f6 / 40F) * 20F, 1.0F, 0.0F, 0.0F);
npc.renderYawOffset = (float)Math.atan(f5 / 40F) * 20F;
npc.rotationYaw = (float)Math.atan(f5 / 40F) * 40F;
npc.rotationPitch = -(float)Math.atan(f6 / 40F) * 20F;
npc.rotationYawHead = npc.rotationYaw;
npc.cloakUpdate();
GL11.glTranslatef(0.0F, npc.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180F;
RenderManager.instance.renderEntityWithPosYaw(npc, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
npc.renderYawOffset = f2;
npc.rotationYaw = f3;
npc.rotationPitch = f4;
npc.rotationYawHead = f7;
npc.isDrawn = false;
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(32826 /*GL_RESCALE_NORMAL_EXT*/);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
super.drawScreen(i, j, f);
}
@Override
public void elementClicked(){
if(dataTextures.contains(slot.selected) && slot.selected != null){
npc.display.texture = assets.getAsset(slot.selected);
npc.textureLocation = null;
}
}
public void save() {
}
@Override
public String[] getExtension() {
return new String[]{"png"};
}
}
@@ -9,6 +9,7 @@ import noppes.npcs.client.Client;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.*;
import noppes.npcs.client.gui.model.GuiCreationScreen;
import noppes.npcs.client.gui.select.GuiTextureSelection;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumPacketServer;
@@ -153,7 +154,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
initGui();
}
else if(button.id == 3){
NoppesUtil.openGUI(player, new GuiNPCTextures(npc, this));
setSubGui(new GuiTextureSelection(npc, npc.display.getSkinTexture()));
}
else if(button.id == 5){
display.disableLivingAnimation = button.getValue() == 1;
@@ -197,6 +198,12 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene
GeckoAddonClient.Instance.geckoNpcDisplayActionPerformed(this, button);
}
@Override
public void closeSubGui(SubGuiInterface subgui) {
super.closeSubGui(subgui);
initGui();
}
@Override
public void save() {
if(display.skinType == 1)
@@ -1,376 +1,374 @@
//package noppes.npcs.client.gui.select;
//
//import com.google.common.collect.Lists;
//import net.minecraft.client.Minecraft;
//import net.minecraft.client.gui.GuiButton;
//import net.minecraft.client.resources.*;
//import net.minecraft.item.crafting.CraftingManager;
//import net.minecraft.util.ResourceLocation;
//import noppes.npcs.CustomNpcs;
//import noppes.npcs.LogWriter;
//import noppes.npcs.client.gui.util.GuiCustomScroll;
//import noppes.npcs.client.gui.util.GuiNpcButton;
//import noppes.npcs.client.gui.util.ICustomScrollListener;
//import noppes.npcs.client.gui.util.SubGuiInterface;
//import noppes.npcs.entity.EntityNPCInterface;
//
//import java.io.File;
//import java.io.UnsupportedEncodingException;
//import java.net.URL;
//import java.net.URLDecoder;
//import java.nio.charset.StandardCharsets;
//import java.util.*;
//import java.util.zip.ZipEntry;
//import java.util.zip.ZipFile;
//
//public class GuiTextureSelection extends SubGuiInterface implements ICustomScrollListener{
//
// private String up = "..<" + I18n.translateToLocal("gui.up") + ">..";
// private GuiCustomScroll scrollCategories;
// private GuiCustomScroll scrollQuests;
//
// private String location = "";
// private String selectedDomain;
// public ResourceLocation selectedResource;
//
// private HashMap<String,List<TextureData>> domains = new HashMap<String,List<TextureData>>();
// private HashMap<String, TextureData> textures = new HashMap<String, TextureData>();
//
// public GuiTextureSelection(EntityNPCInterface npc, String texture){
// this.npc = npc;
// drawDefaultBackground = false;
// title = "";
// setBackground("menubg.png");
// xSize = 366;
// ySize = 226;
//
// SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
//
// Map<String, FallbackResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
// HashSet<String> set = new HashSet<String>();
// for(String name: map.keySet()){
// FallbackResourceManager manager = map.get(name);
// List<IResourcePack> list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 1);
// for(IResourcePack pack : list){
// if(pack instanceof LegacyV2Adapter) {
// pack = ObfuscationReflectionHelper.getPrivateValue(LegacyV2Adapter.class, (LegacyV2Adapter)pack, 0);;
// }
// if(pack instanceof AbstractResourcePack){
// AbstractResourcePack p = (AbstractResourcePack) pack;
// File file = p.resourcePackFile;
// if(file != null)
// set.add(file.getAbsolutePath());
// }
// }
// }
// for(String file : set){
// File f = new File(file);
// if(f.isDirectory()) {
// checkFolder(new File(f, "assets"), f.getAbsolutePath().length());
// }
// else {
// progressFile(f);
// }
// }
// for (ModContainer mod : Loader.instance().getModList()) {
// if(mod.getSource().exists())
// progressFile(mod.getSource());
// }
//
// ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
// repos.updateRepositoryEntriesAll();
// List<ResourcePackRepository.Entry> list = repos.getRepositoryEntries();
// if(repos.getServerResourcePack() != null) {
// AbstractResourcePack p = (AbstractResourcePack) repos.getServerResourcePack();
// File file = p.resourcePackFile;
// if(file != null)
// progressFile(file);
// }
// for(ResourcePackRepository.Entry entry : list) {
// File file = new File(repos.getDirResourcepacks(),entry.getResourcePackName());
// if(file.exists()){
// progressFile(file);
// }
// }
// checkFolder(new File(CustomNpcs.Dir,"assets"),CustomNpcs.Dir.getAbsolutePath().length());
//
// URL url = DefaultResourcePack.class.getResource("/");
// if(url != null) {
// File f = decodeFile(url.getFile());
// if(f.isDirectory()) {
// checkFolder(new File(f,"assets"), url.getFile().length());
// }
// else {
// progressFile(f);
// }
// }
//
// url = CraftingManager.class.getResource("/assets/.mcassetsroot");
// if(url != null) {
// File f = decodeFile(url.getFile());
// if(f.isDirectory()) {
// checkFolder(new File(f,"assets"), url.getFile().length());
// }
// else {
// progressFile(f);
// }
// }
//
// if(texture != null && !texture.isEmpty()){
// selectedResource = new ResourceLocation(texture);
// selectedDomain = selectedResource.getResourceDomain();
// if(!domains.containsKey(selectedDomain)) {
// selectedDomain = null;
// }
// int i = selectedResource.getResourcePath().lastIndexOf('/');
// location = selectedResource.getResourcePath().substring(0, i + 1);
// if(location.startsWith("textures/")){
// location = location.substring(9);
// }
// }
// }
// private File decodeFile(String url) {
// if(url.startsWith("file:")) {
// url = url.substring(5);
// }
// url = url.replace('/', File.separatorChar);
// int i = url.indexOf('!');
// if(i > 0) {
// url = url.substring(0, i);
// }
// try {
// url = URLDecoder.decode(url, StandardCharsets.UTF_8.name());
// } catch (UnsupportedEncodingException e) {
// }
// return new File(url);
// }
//
// @Override
// public void initGui(){
// super.initGui();
//
// if(selectedDomain != null) {
// title = selectedDomain + ":" + location;
// }
// else {
// title = "";
// }
//
// this.addButton(new GuiNpcButton(2, guiLeft + 264, guiTop + 170, 90, 20, "gui.done"));
// this.addButton(new GuiNpcButton(1, guiLeft + 264, guiTop + 190, 90, 20, "gui.cancel"));
//
// if(scrollCategories == null){
// scrollCategories = new GuiCustomScroll(this,0);
// scrollCategories.setSize(120, 200);
// }
//
// if(selectedDomain == null) {
// scrollCategories.setList(Lists.newArrayList(domains.keySet()));
// if(selectedDomain != null) {
// scrollCategories.setSelected(selectedDomain);
// }
// }
// else {
// List<String> list = new ArrayList<String>();
// list.add(up);
// List<TextureData> data = domains.get(selectedDomain);
// for(TextureData td : data) {
// if(location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) {
// String path = td.path.substring(location.length());
// int i = path.indexOf('/');
// if(i < 0)
// continue;
// path = path.substring(0, i);
// if(!path.isEmpty() && !list.contains(path)) {
// list.add(path);
// }
// }
// }
// scrollCategories.setList(list);
// }
// scrollCategories.guiLeft = guiLeft + 4;
// scrollCategories.guiTop = guiTop + 14;
// this.addScroll(scrollCategories);
//
// if(scrollQuests == null){
// scrollQuests = new GuiCustomScroll(this,1);
// scrollQuests.setSize(130, 200);
// }
// if(selectedDomain != null) {
// textures.clear();
// List<TextureData> data = domains.get(selectedDomain);
// List<String> list = new ArrayList<String>();
// String loc = location;
// if(scrollCategories.hasSelected() && !scrollCategories.getSelected().equals(up)) {
// loc += scrollCategories.getSelected() + '/';
// }
// for(TextureData td : data) {
// if(td.path.equals(loc) && !list.contains(td.name)) {
// list.add(td.name);
// textures.put(td.name, td);
// }
// }
// scrollQuests.setList(list);
// }
// if(selectedResource != null) {
// scrollQuests.setSelected(selectedResource.getResourcePath());
// }
// scrollQuests.guiLeft = guiLeft + 125;
// scrollQuests.guiTop = guiTop + 14;
// this.addScroll(scrollQuests);
//
// }
//
// @Override
// protected void actionPerformed(GuiButton guibutton){
// super.actionPerformed(guibutton);
// if(guibutton.id == 2){
// npc.display.setSkinTexture(selectedResource.toString());
// }
// npc.textureLocation = null;
// close();
// parent.initGui();
// }
//
// @Override
// public void drawScreen(int i, int j, float f){
// super.drawScreen(i, j, f);
//
// npc.textureLocation = selectedResource;
// drawNpc(npc, guiLeft + 276, guiTop + 140, 2, 0);
// }
//
//
// @Override
// public void scrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
// if(scroll == scrollQuests) {
// if(scroll.id == 1){
// TextureData data = textures.get(scroll.getSelected());
// selectedResource = new ResourceLocation(selectedDomain, data.absoluteName);
// }
// }
// else {
// initGui();
// }
// }
//
// @Override
// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) {
// if(scroll == scrollCategories) {
// if(selectedDomain == null) {
// selectedDomain = selection;
// }
// else if(selection.equals(up)) {
// int i = location.lastIndexOf('/', location.length() - 2);
// if(i < 0) {
// if(location.isEmpty()) {
// selectedDomain = null;
// }
// location = "";
// }
// else {
// location = location.substring(0, i + 1);
// }
// }
// else {
// location = location + selection + '/';
// }
// scrollCategories.selected = -1;
// scrollQuests.selected = -1;
// initGui();
// }
// else {
// npc.display.setSkinTexture(selectedResource.toString());
// close();
// parent.initGui();
// }
// }
//
// private void progressFile(File file){
// try {
// if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")))
// {
// ZipFile zip = new ZipFile(file);
// Enumeration<? extends ZipEntry> entries = zip.entries();
// while(entries.hasMoreElements()){
// ZipEntry zipentry = entries.nextElement();
// String entryName = zipentry.getName();
// addFile(entryName);
//
// }
// zip.close();
// }
// else if(file.isDirectory()){
// int length = file.getAbsolutePath().length();
// checkFolder(file,length);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// private void checkFolder(File file, int length){
// File[] files = file.listFiles();
// if(files == null){
// return;
// }
// for(File f : files){
// String name = null;
// try {
// name = f.getAbsolutePath().substring(length);
// name = name.replace("\\", "/");
// if(!name.startsWith("/"))
// name = "/" + name;
// if(f.isDirectory()){
// addFile(name + "/");
// checkFolder(f, length);
// }
// else
// addFile(name);
// }
// catch(Throwable e) {
// LogWriter.error("error with: " + name, e);
// }
// }
// }
// private void addFile(String name) {
// name = name.toLowerCase();
// if(name.startsWith("/")) {
// name = name.substring(1);
// }
// if(!name.startsWith("assets/") || !name.toLowerCase().endsWith(".png")) {
// return;
// }
// name = name.substring(7);
// int i = name.indexOf('/');
// String domain = name.substring(0, i);
// name = name.substring(i + 10);
//
// List<TextureData> list = domains.get(domain);
// if(list == null) {
// domains.put(domain, list = new ArrayList<TextureData>());
// }
// boolean contains = false;
// for(TextureData data : list) {
// if(data.absoluteName.equals(name)) {
// contains = true;
// break;
// }
// }
// if(!contains)
// list.add(new TextureData(domain, name));
// }
// class TextureData{
// String domain;
// String absoluteName;
// String name;
// String path;
// public TextureData(String domain, String absoluteName) {
// this.domain = domain;
// int i = absoluteName.lastIndexOf('/');
// name = absoluteName.substring(i + 1);
// path = absoluteName.substring(0, i + 1);
// this.absoluteName = "textures/" + absoluteName;
// }
// }
//}
package noppes.npcs.client.gui.select;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.*;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class GuiTextureSelection extends SubGuiInterface implements ICustomScrollListener {
private final String up = "..<" + StatCollector.translateToLocal("gui.up") + ">..";
private GuiCustomScroll scrollCategories;
private GuiCustomScroll scrollTextures;
private String location = "";
private String selectedDomain;
public ResourceLocation selectedResource;
private final HashMap<String,List<TextureData>> domains = new HashMap<String,List<TextureData>>();
private final HashMap<String, TextureData> textures = new HashMap<String, TextureData>();
public GuiTextureSelection(EntityNPCInterface npc, String texture){
this.npc = npc;
drawDefaultBackground = false;
title = "";
setBackground("menubg.png");
xSize = 366;
ySize = 226;
SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
Map<String, FallbackResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
HashSet<String> set = new HashSet<String>();
for(String name: map.keySet()){
if(!(map.get(name) instanceof FallbackResourceManager))
continue;
FallbackResourceManager manager = (FallbackResourceManager) map.get(name);
List<IResourcePack> list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 0);
for(IResourcePack pack : list){
if(pack instanceof AbstractResourcePack){
AbstractResourcePack p = (AbstractResourcePack) pack;
File file = NPCResourceHelper.getPackFile(p);
if(file != null)
set.add(file.getAbsolutePath());
}
}
}
for(String file : set){
File f = new File(file);
if(f.isDirectory()) {
checkFolder(new File(f, "assets"), f.getAbsolutePath().length());
}
else {
progressFile(f);
}
}
for (ModContainer mod : Loader.instance().getModList()) {
if(mod.getSource().exists())
progressFile(mod.getSource());
}
ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
repos.updateRepositoryEntriesAll();
List<ResourcePackRepository.Entry> list = repos.getRepositoryEntries();
for(ResourcePackRepository.Entry entry : list) {
File file = new File(repos.getDirResourcepacks(),entry.getResourcePackName());
if(file.exists()){
progressFile(file);
}
}
checkFolder(new File(CustomNpcs.Dir,"assets"),CustomNpcs.Dir.getAbsolutePath().length());
URL url = DefaultResourcePack.class.getResource("/");
if(url != null) {
File f = decodeFile(url.getFile());
if(f.isDirectory()) {
checkFolder(new File(f,"assets"), url.getFile().length());
}
else {
progressFile(f);
}
}
url = CraftingManager.class.getResource("/assets/.mcassetsroot");
if(url != null) {
File f = decodeFile(url.getFile());
if(f.isDirectory()) {
checkFolder(new File(f,"assets"), url.getFile().length());
}
else {
progressFile(f);
}
}
if(texture != null && !texture.isEmpty()){
selectedResource = new ResourceLocation(texture);
selectedDomain = selectedResource.getResourceDomain();
if(!domains.containsKey(selectedDomain)) {
selectedDomain = null;
}
int i = selectedResource.getResourcePath().lastIndexOf('/');
location = selectedResource.getResourcePath().substring(0, i + 1);
if(location.startsWith("textures/")){
location = location.substring(9);
}
}
}
private File decodeFile(String url) {
if(url.startsWith("file:")) {
url = url.substring(5);
}
url = url.replace('/', File.separatorChar);
int i = url.indexOf('!');
if(i > 0) {
url = url.substring(0, i);
}
try {
url = URLDecoder.decode(url, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ignored) {
}
return new File(url);
}
@Override
public void initGui(){
super.initGui();
if(selectedDomain != null) {
title = selectedDomain + ":" + location;
}
else {
title = "";
}
this.addButton(new GuiNpcButton(2, guiLeft + 264, guiTop + 170, 90, 20, "gui.done"));
this.addButton(new GuiNpcButton(1, guiLeft + 264, guiTop + 190, 90, 20, "gui.cancel"));
if(scrollCategories == null){
scrollCategories = new GuiCustomScroll(this,0);
scrollCategories.setSize(120, 200);
}
if(selectedDomain == null) {
scrollCategories.setList(Lists.newArrayList(domains.keySet()));
if(selectedDomain != null) {
scrollCategories.setSelected(selectedDomain);
}
}
else {
List<String> list = new ArrayList<String>();
list.add(up);
List<TextureData> data = domains.get(selectedDomain);
for(TextureData td : data) {
if(location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) {
String path = td.path.substring(location.length());
int i = path.indexOf('/');
if(i < 0)
continue;
path = path.substring(0, i);
if(!path.isEmpty() && !list.contains(path)) {
list.add(path);
}
}
}
scrollCategories.setList(list);
}
scrollCategories.guiLeft = guiLeft + 4;
scrollCategories.guiTop = guiTop + 14;
this.addScroll(scrollCategories);
if(scrollTextures == null){
scrollTextures = new GuiCustomScroll(this,1);
scrollTextures.setSize(130, 200);
}
if(selectedDomain != null) {
textures.clear();
List<TextureData> data = domains.get(selectedDomain);
List<String> list = new ArrayList<String>();
String loc = location;
if(scrollCategories.hasSelected() && !scrollCategories.getSelected().equals(up)) {
loc += scrollCategories.getSelected() + '/';
}
for(TextureData td : data) {
if(td.path.equals(loc) && !list.contains(td.name)) {
list.add(td.name);
textures.put(td.name, td);
}
}
scrollTextures.setList(list);
}
if(selectedResource != null) {
scrollTextures.setSelected(selectedResource.getResourcePath());
}
scrollTextures.guiLeft = guiLeft + 125;
scrollTextures.guiTop = guiTop + 14;
this.addScroll(scrollTextures);
}
@Override
protected void actionPerformed(GuiButton guibutton){
super.actionPerformed(guibutton);
if(guibutton.id == 2){
npc.display.setSkinTexture(selectedResource.toString());
}
npc.textureLocation = null;
close();
parent.initGui();
}
@Override
public void drawScreen(int i, int j, float f){
super.drawScreen(i, j, f);
npc.textureLocation = selectedResource;
drawNpc(npc, 307, 150, 1.5F, 0);
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if(scroll == scrollTextures) {
if(scroll.id == 1){
TextureData data = textures.get(scroll.getSelected());
selectedResource = new ResourceLocation(selectedDomain, data.absoluteName);
}
}
else {
initGui();
scrollTextures.resetScroll();
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if(scroll == scrollCategories) {
if(selectedDomain == null) {
selectedDomain = selection;
}
else if(selection.equals(up)) {
int i = location.lastIndexOf('/', location.length() - 2);
if(i < 0) {
if(location.isEmpty()) {
selectedDomain = null;
}
location = "";
}
else {
location = location.substring(0, i + 1);
}
}
else {
location = location + selection + '/';
}
scrollCategories.selected = -1;
scrollTextures.selected = -1;
initGui();
}
else {
npc.display.setSkinTexture(selectedResource.toString());
close();
parent.initGui();
}
}
private void progressFile(File file){
try {
if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")))
{
ZipFile zip = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zip.entries();
while(entries.hasMoreElements()){
ZipEntry zipentry = entries.nextElement();
String entryName = zipentry.getName();
addFile(entryName);
}
zip.close();
}
else if(file.isDirectory()){
int length = file.getAbsolutePath().length();
checkFolder(file,length);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void checkFolder(File file, int length){
File[] files = file.listFiles();
if(files == null){
return;
}
for(File f : files){
String name = null;
try {
name = f.getAbsolutePath().substring(length);
name = name.replace("\\", "/");
if(!name.startsWith("/"))
name = "/" + name;
if(f.isDirectory()){
addFile(name + "/");
checkFolder(f, length);
}
else
addFile(name);
}
catch(Throwable e) {
LogWriter.error("error with: " + name);
}
}
}
private void addFile(String name) {
if(name.startsWith("/")) {
name = name.substring(1);
}
if(!name.startsWith("assets/") || !name.endsWith(".png")) {
return;
}
name = name.substring(7);
int i = name.indexOf('/');
String domain = name.substring(0, i);
name = name.substring(i + 10);
List<TextureData> list = domains.get(domain);
if(list == null) {
domains.put(domain, list = new ArrayList<TextureData>());
}
boolean contains = false;
for(TextureData data : list) {
if(data.absoluteName.equals(name)) {
contains = true;
break;
}
}
if(!contains)
list.add(new TextureData(domain, name));
}
static class TextureData {
String domain;
String absoluteName;
String name;
String path;
public TextureData(String domain, String absoluteName) {
this.domain = domain;
int i = absoluteName.lastIndexOf('/');
name = absoluteName.substring(i + 1);
path = absoluteName.substring(0, i + 1);
this.absoluteName = "textures/" + absoluteName;
}
}
}
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.CustomNpcResourceListener;
@@ -253,10 +254,14 @@ public abstract class GuiNPCInterface extends GuiScreen
if(scroll.hoverableText){
scroll.drawHover(i, j, f, hasSubGui()?0:this.mouseWheel);
}
for(GuiNpcButton button : buttons.values())
for(GuiNpcButton button : buttons.values()){
if(!button.hoverableText.isEmpty()){
button.drawHover(i, j, hasSubGui());
}
if(hasSubGui() != button.getHasSubGUI())
button.updateSubGUI(hasSubGui());
}
if(subgui != null)
subgui.drawScreen(i,j,f);
}
@@ -330,44 +335,63 @@ public abstract class GuiNPCInterface extends GuiScreen
return subgui;
}
public void drawNpc(int x, int y){
public void drawNpc(int x, int y){
drawNpc(npc, x, y, 1, 0);
}
public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation){
EntityNPCInterface npc = null;
if(entity instanceof EntityNPCInterface)
npc = (EntityNPCInterface) entity;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
npc.isDrawn = true;
if(npc != null)
npc.isDrawn = true;
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft + x, guiTop + y, 50F);
float scale = 1;
if(npc.height > 2.4)
if(entity.height > 2.4)
scale = 2 / npc.height;
GL11.glScalef(-30 * scale, 30 * scale, 30 * scale);
GL11.glScalef(-30 * scale * zoomed, 30 * scale * zoomed, 30 * scale * zoomed);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
float f2 = npc.renderYawOffset;
float f3 = npc.rotationYaw;
float f4 = npc.rotationPitch;
float f7 = npc.rotationYawHead;
float f2 = entity.renderYawOffset;
float f3 = entity.rotationYaw;
float f4 = entity.rotationPitch;
float f7 = entity.rotationYawHead;
float f5 = (float) (guiLeft + x) - mouseX;
float f6 = (float) ((guiTop + y) - 50) - mouseY;
float f6 = (float) ((guiTop + y) - 50 * scale * zoomed) - mouseY;
int orientation = 0;
if(npc != null){
orientation = npc.ai.orientation;
npc.ai.orientation = rotation;
}
GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-(float) Math.atan(f6 / 40F) * 20F, 1.0F, 0.0F, 0.0F);
npc.renderYawOffset = (float) Math.atan(f5 / 40F) * 20F;
npc.rotationYaw = (float) Math.atan(f5 / 40F) * 40F;
npc.rotationPitch = -(float) Math.atan(f6 / 40F) * 20F;
npc.rotationYawHead = npc.rotationYaw;
GL11.glTranslatef(0.0F, npc.yOffset, 0.0F);
entity.renderYawOffset = rotation;
entity.rotationYaw = (float)Math.atan(f5 / 80F) * 40F + rotation;
entity.rotationPitch = -(float) Math.atan(f6 / 40F) * 20F;
entity.rotationYawHead = entity.rotationYaw;
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180F;
RenderManager.instance.renderEntityWithPosYaw(npc, 0, 0, 0, 0, 1);
npc.renderYawOffset = f2;
npc.rotationYaw = f3;
npc.rotationPitch = f4;
npc.rotationYawHead = f7;
RenderManager.instance.renderEntityWithPosYaw(entity, 0, 0, 0, 0, 1);
entity.prevRenderYawOffset = entity.renderYawOffset = f2;
entity.prevRotationYaw = entity.rotationYaw = f3;
entity.prevRotationPitch = entity.rotationPitch = f4;
entity.prevRotationYawHead = entity.rotationYawHead = f7;
if(npc != null){
npc.ai.orientation = orientation;
}
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
npc.isDrawn = false;
if(npc != null)
npc.isDrawn = false;
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
@@ -2,8 +2,10 @@ package noppes.npcs.client.gui.util;
import kamkeel.util.TextSplitter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
@@ -21,6 +23,7 @@ public class GuiNpcButton extends GuiButton{
public String hoverableText = "";
public int oldHover;
public int hoverCount = 0;
boolean hasSubGUI = false;
public GuiNpcButton(int i, int j, int k, String s) {
super(i, j, k, StatCollector.translateToLocal(s));
@@ -200,4 +203,29 @@ public class GuiNpcButton extends GuiButton{
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
@Override
public int getHoverState(boolean mouseOver)
{
byte b0 = 1;
if (!this.enabled)
{
b0 = 0;
}
else if (mouseOver && !this.hasSubGUI)
{
b0 = 2;
}
return b0;
}
public void updateSubGUI(boolean hasSubGUI)
{
this.hasSubGUI = hasSubGUI;
}
public boolean getHasSubGUI()
{
return this.hasSubGUI;
}
}