Skip to content

Commit

Permalink
Also block play button usage when no sound is selected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynious committed Jan 13, 2014
1 parent e31643b commit ead47bc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
10 changes: 9 additions & 1 deletion java/com/dynious/soundscool/client/gui/GuiSoundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class GuiSoundPlayer extends GuiScreen implements IListGui
{
private GuiRemoteSoundsList soundsList;
private TileSoundPlayer tile;
private GuiButton playButton;

public GuiSoundPlayer(TileSoundPlayer tile)
{
Expand All @@ -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
Expand Down Expand Up @@ -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()
{
Expand All @@ -98,6 +105,7 @@ public FontRenderer getFontRenderer()
public void selectSoundIndex(int selected)
{
tile.selectSoundIndex(selected);
onSelectedSoundChanged();
}

@Override
Expand Down
55 changes: 37 additions & 18 deletions java/com/dynious/soundscool/client/gui/GuiSounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -131,21 +122,48 @@ 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;
}
}
}

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()
{
Expand All @@ -171,6 +189,7 @@ public void selectSoundIndex(int selected)
{
this.selectedSound = null;
}
onSelectedSoundChanged();
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions java/com/dynious/soundscool/handler/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public class NetworkHandler
private static Map<String, byte[]> soundChunks = new HashMap<String, byte[]>();

@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)
Expand Down
2 changes: 1 addition & 1 deletion java/com/dynious/soundscool/handler/SoundHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void removeSound(Sound sound)
sound.getSoundLocation().deleteOnExit();
}
sounds.remove(sound);
NetworkHandler.uploadedSounds.remove(NetworkHandler.getServerSound(sound.getSoundName()));
}
}

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit ead47bc

Please sign in to comment.