diff --git a/java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java b/java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java index 60aca3e..419df0e 100644 --- a/java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java +++ b/java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java @@ -21,6 +21,7 @@ public class GuiSoundPlayer extends GuiScreen implements IListGui { private GuiRemoteSoundsList soundsList; private TileSoundPlayer tile; + private GuiButton playButton; public GuiSoundPlayer(TileSoundPlayer tile) { @@ -34,7 +35,8 @@ public void initGui() super.initGui(); soundsList = new GuiRemoteSoundsList(this, 150); this.field_146292_n.add(new GuiButton(0, getWidth() / 2, getHeight() - 42, I18n.getStringParams("gui.done"))); - this.field_146292_n.add(new GuiButton(1, getWidth() / 2, getHeight() - 72, "Play")); + this.field_146292_n.add(playButton = new GuiButton(1, getWidth() / 2, getHeight() - 72, "Play")); + onSelectedSoundChanged(); } @Override @@ -82,6 +84,11 @@ protected void func_146284_a(GuiButton button) } } + public void onSelectedSoundChanged() + { + playButton.field_146124_l = tile.getSelectedSound() != null; + } + @Override public Minecraft getMinecraftInstance() { @@ -98,6 +105,7 @@ public FontRenderer getFontRenderer() public void selectSoundIndex(int selected) { tile.selectSoundIndex(selected); + onSelectedSoundChanged(); } @Override diff --git a/java/com/dynious/soundscool/client/gui/GuiSounds.java b/java/com/dynious/soundscool/client/gui/GuiSounds.java index e16cf9c..6f6d139 100644 --- a/java/com/dynious/soundscool/client/gui/GuiSounds.java +++ b/java/com/dynious/soundscool/client/gui/GuiSounds.java @@ -27,6 +27,7 @@ public class GuiSounds extends GuiScreen implements IListGui private JFileChooser fileChooser; private EntityPlayer player; private GuiButton uploadButton; + private GuiButton playButton; public GuiSounds(EntityPlayer player) { @@ -43,27 +44,16 @@ public void initGui() soundsList = new GuiLocalSoundsList(this, 150); this.field_146292_n.add(new GuiButton(0, getWidth() / 2, getHeight() - 42, I18n.getStringParams("gui.done"))); this.field_146292_n.add(new GuiButton(1, 10, getHeight() - 42, 150, 20, "Select File")); - this.field_146292_n.add(new GuiButton(2, getWidth() / 2, getHeight() - 102, "Play Sound")); + this.field_146292_n.add(playButton = new GuiButton(2, getWidth() / 2, getHeight() - 102, "Play Sound")); + playButton.field_146124_l = false; this.field_146292_n.add(uploadButton = new GuiButton(3, getWidth() / 2, getHeight() - 72, "Upload")); + uploadButton.field_146124_l = false; } @Override public void updateScreen() { super.updateScreen(); - if (selectedSound != null) - { - if (NetworkHandler.hasServerSound(selectedSound.getSoundName())) - { - uploadButton.field_146126_j = "Remove"; - uploadButton.field_146124_l = NetworkHandler.uploadedSounds.get(selected).getCategory().equals(player.getDisplayName()); - } - else - { - uploadButton.field_146126_j = "Upload"; - uploadButton.field_146124_l = true; - } - } } @Override @@ -114,8 +104,9 @@ protected void func_146284_a(GuiButton button) int fcReturn = fileChooser.showOpenDialog(null); if (fcReturn == JFileChooser.APPROVE_OPTION) { + selectSoundIndex(-1); selectedSound = new Sound(fileChooser.getSelectedFile()); - selected = -1; + onSelectedSoundChanged(); } break; case 2: @@ -131,14 +122,13 @@ protected void func_146284_a(GuiButton button) { Sound sound = SoundHandler.setupSound(selectedSound.getSoundLocation()); NetworkHelper.clientSoundUpload(sound); - selectedSound = null; + selectSoundIndex(-1); } else { SoundsCool.proxy.getChannel().writeOutbound(new RemoveSoundPacket(selectedSound.getSoundName())); SoundHandler.removeSound(selectedSound); - selectedSound = null; - selected = -1; + selectSoundIndex(-1); } } break; @@ -146,6 +136,34 @@ protected void func_146284_a(GuiButton button) } } + public void onSelectedSoundChanged() + { + if (selectedSound != null) + { + if (NetworkHandler.hasServerSound(selectedSound.getSoundName())) + { + if (selected == -1) + { + selectSoundIndex(NetworkHandler.uploadedSounds.indexOf(NetworkHandler.getServerSound(selectedSound.getSoundName()))); + } + uploadButton.field_146126_j = "Remove"; + uploadButton.field_146124_l = NetworkHandler.uploadedSounds.get(selected).getCategory().equals(player.getDisplayName()); + } + else + { + uploadButton.field_146126_j = "Upload"; + uploadButton.field_146124_l = true; + } + playButton.field_146124_l = true; + } + else + { + uploadButton.field_146126_j = "Upload"; + uploadButton.field_146124_l = false; + playButton.field_146124_l = false; + } + } + @Override public Minecraft getMinecraftInstance() { @@ -171,6 +189,7 @@ public void selectSoundIndex(int selected) { this.selectedSound = null; } + onSelectedSoundChanged(); } @Override diff --git a/java/com/dynious/soundscool/handler/NetworkHandler.java b/java/com/dynious/soundscool/handler/NetworkHandler.java index 9361990..44dd327 100644 --- a/java/com/dynious/soundscool/handler/NetworkHandler.java +++ b/java/com/dynious/soundscool/handler/NetworkHandler.java @@ -16,22 +16,22 @@ public class NetworkHandler private static Map soundChunks = new HashMap(); @SideOnly(Side.CLIENT) - public static boolean hasServerSound(Sound sound) + public static boolean hasServerSound(String soundName) { - return uploadedSounds.contains(sound); + return getServerSound(soundName) != null; } @SideOnly(Side.CLIENT) - public static boolean hasServerSound(String soundName) + public static Sound getServerSound(String soundName) { for (Sound sound : uploadedSounds) { if (sound.getSoundName().equals(soundName)) { - return true; + return sound; } } - return false; + return null; } public static void addSoundChunk(String soundName, byte[] soundChunk) diff --git a/java/com/dynious/soundscool/handler/SoundHandler.java b/java/com/dynious/soundscool/handler/SoundHandler.java index 0df2684..5ecdff2 100644 --- a/java/com/dynious/soundscool/handler/SoundHandler.java +++ b/java/com/dynious/soundscool/handler/SoundHandler.java @@ -79,6 +79,7 @@ public static void removeSound(Sound sound) sound.getSoundLocation().deleteOnExit(); } sounds.remove(sound); + NetworkHandler.uploadedSounds.remove(NetworkHandler.getServerSound(sound.getSoundName())); } } @@ -121,7 +122,6 @@ public static Sound setupSound(File file) if (Minecraft.getMinecraft().func_147104_D() != null) { category = new File("sounds" + File.separator + Minecraft.getMinecraft().func_147104_D().serverMOTD); - System.out.println(Minecraft.getMinecraft().func_147104_D().serverMOTD); } else {