From 3dc60ec1a760fda9aa21a6de9e56f390a6f5d85f Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:58:35 -0400 Subject: [PATCH] GuiSoundSelection 1.12 Backports GuiSoundSelection from 1.12 - customScrollDoubleClicked (to be renamed) - Better GUI Selection Handling --- .../npcs/client/gui/roles/GuiNpcBard.java | 40 +- .../client/gui/select/GuiDialogSelection.java | 124 ++++++ .../client/gui/select/GuiQuestSelection.java | 124 ++++++ .../client/gui/select/GuiSoundSelection.java | 126 ++++++ .../gui/select/GuiTextureSelection.java | 376 ++++++++++++++++++ .../npcs/client/gui/util/GuiCustomScroll.java | 15 +- .../gui/util/ICustomScrollListener.java | 1 + 7 files changed, 785 insertions(+), 21 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java index e1b4522d0..3b5549f15 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java @@ -6,22 +6,20 @@ import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.GuiNpcSoundSelection; -import noppes.npcs.client.gui.util.GuiNPCInterface2; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcLabel; -import noppes.npcs.client.gui.util.GuiNpcTextField; +import noppes.npcs.client.gui.select.GuiSoundSelection; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobBard; -public class GuiNpcBard extends GuiNPCInterface2 -{ +public class GuiNpcBard extends GuiNPCInterface2 implements ISubGuiListener +{ private JobBard job; private GuiNpcSoundSelection gui; - + public GuiNpcBard(EntityNPCInterface npc) { - super(npc); + super(npc); job = (JobBard) npc.jobInterface; } @@ -36,7 +34,7 @@ public class GuiNpcBard extends GuiNPCInterface2 this.addButton(new GuiNpcButton(2, guiLeft + 75, guiTop + 71, new String[]{"gui.none","item.npcBanjo.name","item.npcViolin.name","item.npcGuitar.name","item.npcHarp.name","item.npcFrenchHorn.name"}, job.getInstrument().ordinal())); this.addButton(new GuiNpcButton(3, guiLeft + 75, guiTop + 92, new String[]{"bard.jukebox","bard.background"}, job.isStreamer?0:1)); - + addLabel(new GuiNpcLabel(2,"bard.ondistance", guiLeft + 60, guiTop + 143)); addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft+160, guiTop + 138, 40, 20, job.minRange + "")); getTextField(2).integersOnly = true; @@ -44,7 +42,7 @@ public class GuiNpcBard extends GuiNPCInterface2 addLabel(new GuiNpcLabel(4,"bard.hasoff", guiLeft + 60, guiTop + 166)); addButton(new GuiNpcButton(4, guiLeft + 160, guiTop + 161, 60, 20, new String[]{"gui.no","gui.yes"}, job.hasOffRange?1:0)); - + addLabel(new GuiNpcLabel(3,"bard.offdistance", guiLeft + 60, guiTop + 189)); addTextField(new GuiNpcTextField(3,this, this.fontRendererObj, guiLeft+160, guiTop + 184, 40, 20, job.maxRange + "")); getTextField(3).integersOnly = true; @@ -52,7 +50,7 @@ public class GuiNpcBard extends GuiNPCInterface2 getLabel(3).enabled = job.hasOffRange; getTextField(3).enabled = job.hasOffRange; - + } @Override public void elementClicked(){ @@ -64,12 +62,8 @@ public class GuiNpcBard extends GuiNPCInterface2 GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0) { - - gui = new GuiNpcSoundSelection(this, job.song); - NoppesUtil.openGUI(player, gui); - - job.song = ""; - MusicController.Instance.stopMusic(); + setSubGui(new GuiSoundSelection(job.song)); + MusicController.Instance.stopMusic(); } if(button.id == 1) { @@ -91,14 +85,14 @@ public class GuiNpcBard extends GuiNPCInterface2 job.hasOffRange = button.getValue() == 1; initGui(); } - + } @Override public void save() { job.minRange = getTextField(2).getInteger(); job.maxRange = getTextField(3).getInteger(); - + if(job.minRange > job.maxRange) job.maxRange = job.minRange; @@ -107,4 +101,12 @@ public class GuiNpcBard extends GuiNPCInterface2 } + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + job.song = gss.selectedResource.toString(); + getLabel(0).label = job.song; + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java new file mode 100644 index 000000000..0389d9ec1 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java @@ -0,0 +1,124 @@ +//package noppes.npcs.client.gui.select; +// +//import com.google.common.collect.Lists; +//import net.minecraft.client.gui.GuiButton; +//import noppes.npcs.client.gui.util.*; +//import noppes.npcs.controllers.DialogController; +//import noppes.npcs.controllers.data.Dialog; +//import noppes.npcs.controllers.data.DialogCategory; +// +//import java.util.HashMap; +// +//public class GuiDialogSelection extends SubGuiInterface implements ICustomScrollListener{ +// private HashMap categoryData = new HashMap(); +// private HashMap dialogData = new HashMap(); +// +// private GuiCustomScroll scrollCategories; +// private GuiCustomScroll scrollDialogs; +// +// private DialogCategory selectedCategory; +// public Dialog selectedDialog; +// +// private GuiSelectionListener listener; +// +// public GuiDialogSelection(int dialog){ +// drawDefaultBackground = false; +// title = ""; +// setBackground("menubg.png"); +// xSize = 366; +// ySize = 226; +// this.selectedDialog = DialogController.instance.dialogs.get(dialog); +// if(selectedDialog != null) { +// selectedCategory = selectedDialog.category; +// } +// } +// +// @Override +// public void initGui(){ +// super.initGui(); +// +// if(parent instanceof GuiSelectionListener){ +// listener = (GuiSelectionListener) parent; +// } +// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); +// this.addLabel(new GuiNpcLabel(1, "dialog.dialogs", guiLeft + 175, guiTop + 4)); +// +// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); +// +// HashMap categoryData = new HashMap(); +// HashMap dialogData = new HashMap(); +// +// for(DialogCategory category : DialogController.instance.categories.values()) { +// categoryData.put(category.title, category); +// } +// this.categoryData = categoryData; +// +// if(selectedCategory != null) { +// for(Dialog dialog : selectedCategory.dialogs.values()) { +// dialogData.put(dialog.title, dialog); +// } +// } +// this.dialogData = dialogData; +// +// if(scrollCategories == null){ +// scrollCategories = new GuiCustomScroll(this,0); +// scrollCategories.setSize(170, 200); +// } +// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); +// if(selectedCategory != null) { +// scrollCategories.setSelected(selectedCategory.title); +// } +// +// scrollCategories.guiLeft = guiLeft + 4; +// scrollCategories.guiTop = guiTop + 14; +// this.addScroll(scrollCategories); +// +// if(scrollDialogs == null){ +// scrollDialogs = new GuiCustomScroll(this,1); +// scrollDialogs.setSize(170, 200); +// } +// scrollDialogs.setList(Lists.newArrayList(dialogData.keySet())); +// if(selectedDialog != null) { +// scrollDialogs.setSelected(selectedDialog.title); +// } +// scrollDialogs.guiLeft = guiLeft + 175; +// scrollDialogs.guiTop = guiTop + 14; +// this.addScroll(scrollDialogs); +// } +// +// @Override +// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { +// if(guiCustomScroll.id == 0){ +// selectedCategory = categoryData.get(scrollCategories.getSelected()); +// selectedDialog = null; +// scrollDialogs.selected = -1; +// } +// if(guiCustomScroll.id == 1){ +// selectedDialog = dialogData.get(scrollDialogs.getSelected()); +// } +// initGui(); +// } +// +// @Override +// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { +// if(selectedDialog == null) +// return; +// if(listener != null) { +// listener.selected(selectedDialog.id, selectedDialog.title); +// } +// close(); +// } +// +// @Override +// protected void actionPerformed(GuiButton guibutton){ +// int id = guibutton.id; +// if(id == 2){ +// if(selectedDialog != null) { +// scrollDoubleClicked(null, null); +// } +// else { +// close(); +// } +// } +// } +//} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java new file mode 100644 index 000000000..0ba761347 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java @@ -0,0 +1,124 @@ +//package noppes.npcs.client.gui.select; +// +//import com.google.common.collect.Lists; +//import net.minecraft.client.gui.GuiButton; +//import noppes.npcs.client.gui.util.*; +//import noppes.npcs.controllers.QuestController; +//import noppes.npcs.controllers.data.Quest; +//import noppes.npcs.controllers.data.QuestCategory; +// +//import java.util.HashMap; +// +//public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollListener{ +// private HashMap categoryData = new HashMap(); +// private HashMap questData = new HashMap(); +// +// private GuiCustomScroll scrollCategories; +// private GuiCustomScroll scrollQuests; +// +// private QuestCategory selectedCategory; +// public Quest selectedQuest; +// +// private GuiSelectionListener listener; +// +// public GuiQuestSelection(int quest){ +// drawDefaultBackground = false; +// title = ""; +// setBackground("menubg.png"); +// xSize = 366; +// ySize = 226; +// this.selectedQuest = QuestController.instance.quests.get(quest); +// if(selectedQuest != null) { +// selectedCategory = selectedQuest.category; +// } +// } +// +// @Override +// public void initGui(){ +// super.initGui(); +// +// if(parent instanceof GuiSelectionListener){ +// listener = (GuiSelectionListener) parent; +// } +// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); +// this.addLabel(new GuiNpcLabel(1, "quest.quests", guiLeft + 175, guiTop + 4)); +// +// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); +// +// HashMap categoryData = new HashMap(); +// HashMap questData = new HashMap(); +// +// for(QuestCategory category : QuestController.instance.categories.values()) { +// categoryData.put(category.title, category); +// } +// this.categoryData = categoryData; +// +// if(selectedCategory != null) { +// for(Quest quest : selectedCategory.quests.values()) { +// questData.put(quest.title, quest); +// } +// } +// this.questData = questData; +// +// if(scrollCategories == null){ +// scrollCategories = new GuiCustomScroll(this,0); +// scrollCategories.setSize(170, 200); +// } +// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); +// if(selectedCategory != null) { +// scrollCategories.setSelected(selectedCategory.title); +// } +// +// scrollCategories.guiLeft = guiLeft + 4; +// scrollCategories.guiTop = guiTop + 14; +// this.addScroll(scrollCategories); +// +// if(scrollQuests == null){ +// scrollQuests = new GuiCustomScroll(this,1); +// scrollQuests.setSize(170, 200); +// } +// scrollQuests.setList(Lists.newArrayList(questData.keySet())); +// if(selectedQuest != null) { +// scrollQuests.setSelected(selectedQuest.title); +// } +// scrollQuests.guiLeft = guiLeft + 175; +// scrollQuests.guiTop = guiTop + 14; +// this.addScroll(scrollQuests); +// } +// +// @Override +// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { +// if(guiCustomScroll.id == 0){ +// selectedCategory = categoryData.get(scrollCategories.getSelected()); +// selectedQuest = null; +// scrollQuests.selected = -1; +// } +// if(guiCustomScroll.id == 1){ +// selectedQuest = questData.get(scrollQuests.getSelected()); +// } +// initGui(); +// } +// +// @Override +// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { +// if(selectedQuest == null) +// return; +// if(listener != null) { +// listener.selected(selectedQuest.id, selectedQuest.title); +// } +// close(); +// } +// +// @Override +// protected void actionPerformed(GuiButton guibutton){ +// int id = guibutton.id; +// if(id == 2){ +// if(selectedQuest != null) { +// scrollDoubleClicked(null, null); +// } +// else { +// close(); +// } +// } +// } +//} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java new file mode 100644 index 000000000..9c1dcfdc0 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java @@ -0,0 +1,126 @@ +package noppes.npcs.client.gui.select; + +import com.google.common.collect.Lists; +import cpw.mods.fml.relauncher.ReflectionHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.SoundHandler; +import net.minecraft.client.audio.SoundRegistry; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.controllers.MusicController; +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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener{ + + private GuiCustomScroll scrollCategories; + private GuiCustomScroll scrollQuests; + + private String selectedDomain; + public ResourceLocation selectedResource; + + private HashMap> domains = new HashMap>(); + + public GuiSoundSelection(String sound){ + drawDefaultBackground = false; + title = ""; + setBackground("menubg.png"); + xSize = 366; + ySize = 226; + + SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); + SoundRegistry registry = ReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4); + + Set set = registry.getKeys(); + for(ResourceLocation location : set){ + List list = domains.get(location.getResourceDomain()); + if(list == null) + domains.put(location.getResourceDomain(), list = new ArrayList()); + list.add(location.getResourcePath()); + domains.put(location.getResourceDomain(), list); + } + if(sound != null && !sound.isEmpty()){ + selectedResource = new ResourceLocation(sound); + selectedDomain = selectedResource.getResourceDomain(); + if(!domains.containsKey(selectedDomain)) { + selectedDomain = null; + } + } + } + + @Override + public void initGui(){ + super.initGui(); + this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); + this.addButton(new GuiNpcButton(1, guiLeft + 160, guiTop + 212, 70, 20, "gui.play")); + getButton(1).enabled = selectedResource != null; + + if(scrollCategories == null){ + scrollCategories = new GuiCustomScroll(this,0); + scrollCategories.setSize(90, 200); + } + scrollCategories.setList(Lists.newArrayList(domains.keySet())); + if(selectedDomain != null) { + scrollCategories.setSelected(selectedDomain); + } + + scrollCategories.guiLeft = guiLeft + 4; + scrollCategories.guiTop = guiTop + 14; + this.addScroll(scrollCategories); + + if(scrollQuests == null){ + scrollQuests = new GuiCustomScroll(this,1); + scrollQuests.setSize(250, 200); + } + if(selectedDomain != null) { + scrollQuests.setList(domains.get(selectedDomain)); + } + if(selectedResource != null) { + scrollQuests.setSelected(selectedResource.getResourcePath()); + } + scrollQuests.guiLeft = guiLeft + 95; + scrollQuests.guiTop = guiTop + 14; + this.addScroll(scrollQuests); + + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + super.actionPerformed(guibutton); + if(guibutton.id == 1){ + MusicController.Instance.stopMusic(); + MusicController.Instance.playSound(selectedResource.toString(), (float)player.posX, (float)player.posY, (float)player.posZ); + } + if(guibutton.id == 2){ + close(); + } + } + + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { + if(selectedResource == null) + return; + close(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0){ + selectedDomain = guiCustomScroll.getSelected(); + selectedResource = null; + scrollQuests.selected = -1; + } + if(guiCustomScroll.id == 1){ + selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected()); + } + initGui(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java new file mode 100644 index 000000000..74e1ed521 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java @@ -0,0 +1,376 @@ +//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> domains = new HashMap>(); +// private HashMap textures = new HashMap(); +// +// 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 map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2); +// HashSet set = new HashSet(); +// for(String name: map.keySet()){ +// FallbackResourceManager manager = map.get(name); +// List 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 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 list = new ArrayList(); +// list.add(up); +// List 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 data = domains.get(selectedDomain); +// List list = new ArrayList(); +// 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 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 list = domains.get(domain); +// if(list == null) { +// domains.put(domain, list = new ArrayList()); +// } +// 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; +// } +// } +//} diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index aae79e6a6..81415e7d0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -36,6 +36,9 @@ public class GuiCustomScroll extends GuiScreen public boolean visible = true; private boolean selectable = true; + private int lastClickedItem; + private long lastClickedTime = 0; + public GuiCustomScroll(GuiScreen parent, int id) { width = 176; @@ -274,8 +277,16 @@ public class GuiCustomScroll extends GuiScreen selected = hover; hover = -1; } - if(listener != null) - listener.customScrollClicked(i, j, k,this); + + if(listener != null) { + long time = System.currentTimeMillis(); + listener.customScrollClicked(i, j, k, this); + if(selected >= 0 && selected == lastClickedItem && time - lastClickedTime < 500) { + listener.customScrollDoubleClicked(list.get(selected), this); + } + lastClickedTime = time; + lastClickedItem = selected; + } } private void drawScrollBar() diff --git a/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java b/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java index b761c0c8f..d47a0f5ab 100644 --- a/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java +++ b/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java @@ -6,4 +6,5 @@ public interface ICustomScrollListener { void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll); + default void customScrollDoubleClicked(String selection, GuiCustomScroll scroll){} }