package noppes.npcs.client.gui; import cpw.mods.fml.common.ObfuscationReflectionHelper; 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.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.util.*; import java.util.*; public class SubGuiNpcSoundSelection extends SubGuiInterface { public GuiNPCStringSlot slot; public String domain; private final GuiScreen parent; public GuiSelectionListener listener; private String up = "..<" + StatCollector.translateToLocal("gui.up") + ">.."; private HashMap> domains = new HashMap>(); public SubGuiNpcSoundSelection(GuiScreen parent, String sound) { SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); SoundRegistry registry = ObfuscationReflectionHelper.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); } drawDefaultBackground = false; this.parent = parent; if(parent instanceof GuiSelectionListener) listener = (GuiSelectionListener) parent; } public void initGui() { super.initGui(); String ss = "Current domain: " + domain; if(domain == null) ss = "Select domain"; addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff)); Collection col = domains.keySet(); if(domain != null){ col = domains.get(domain); if(!col.contains(up)) col.add(up); } slot = new GuiNPCStringSlot(col, this, false, 18); slot.registerScrollButtons(4, 5); if(domain != null){ this.addButton(new GuiNpcButton(1, width / 2 - 100, height - 27,198, 20, "gui.play")); this.addButton(new GuiNpcButton(3, width / 2 - 100, height - 50,98, 20, "gui.done")); } else this.addButton(new GuiNpcButton(4, width / 2 - 100, height - 50,98, 20, "gui.open")); this.addButton(new GuiNpcButton(2, width / 2 + 2, height - 50,98, 20, "gui.cancel")); } public void drawScreen(int i, int j, float f) { slot.drawScreen(i, j, f); super.drawScreen(i, j, f); } public void doubleClicked() { if(slot.selected == null || slot.selected.isEmpty()) return; if(slot.selected.equals(up)){ domain = null; initGui(); } else if(domain == null){ domain = slot.selected; initGui(); } else{ if(parent instanceof GuiNPCInterface){ ((GuiNPCInterface)parent).elementClicked(); } else if(this.parent instanceof GuiNPCInterface2){ ((GuiNPCInterface2)parent).elementClicked(); } close(); } } protected void actionPerformed(GuiButton guibutton) { super.actionPerformed(guibutton); if(guibutton.id == 1){ MusicController.Instance.stopMusic(); MusicController.Instance.playSound(getSelected(), (float)player.posX, (float)player.posY, (float)player.posZ); } if(guibutton.id == 2){ close(); } if(guibutton.id == 3){ if(slot.selected == null || slot.selected.equals(up)) return; doubleClicked(); } if(guibutton.id == 4){ doubleClicked(); } } public void save() { } public void close() { this.save(); super.close(); } public String getSelected(){ if(slot.selected == null || slot.selected.isEmpty()) return ""; return domain + ":" + slot.selected; } }