Skip to content

Commit

Permalink
Added finishing animation to that GitHub dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Dalton <[email protected]>
  • Loading branch information
Danny Dalton committed Oct 20, 2018
1 parent 7002341 commit 2537c10
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
44 changes: 42 additions & 2 deletions src/com/bongo/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.bongo;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;
Expand Down Expand Up @@ -97,7 +97,7 @@ private static void finish() {
int ok = JOptionPane.showOptionDialog(window,
"BongoCat MIDI Player\nhttps://github.com/marios8543/BongoMidi\nRestart?",
"Thanks for playing!",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,
new ImageIcon(Objects.requireNonNull(Renderer.load_asset("bongo.png"))),
new FinishAnimation(),
null,null);
if(ok==JOptionPane.YES_OPTION){
restart();
Expand Down Expand Up @@ -299,3 +299,43 @@ public static void main(String[] args) {
speedSlider.setValue((int) parser.sequencer.getTempoInBPM());
}
}

class FinishAnimation implements Icon {
FinishAnimation() {
final Thread renderThread = new Thread(() -> {
while (true){
try {
Thread.sleep(200);
} catch (Exception e) {
JOptionPane.showMessageDialog(Main.window, e.getMessage(), "Rendering thread error", JOptionPane.ERROR_MESSAGE);
break;
}
if (component != null) component.repaint();
}
});
renderThread.start();
}

public void paintIcon(Component c, Graphics g, int x, int y) {
if (FinishAnimation.component == null) FinishAnimation.component = c;
g.clearRect(0,0, c.getWidth(), c.getHeight());
// TODO: Actually get the bongo image to load/display here
// I simply use "Percussion" for now
g.drawImage(bongo.note.cpatch.getAsset(), x, y, c);
g.drawImage(Renderer.get_lhand(bongo.l_hand), x, y, c);
g.drawImage(Renderer.get_rhand(bongo.r_hand), x, y, c);
bongo.swap();
}

private Renderer.Bongo bongo = new Renderer.Bongo();

private static Component component;

public int getIconWidth() {
return 380;
}

public int getIconHeight() {
return 264;
}
}
8 changes: 8 additions & 0 deletions src/com/bongo/MidiParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public static class Note {
this.status = status;
}

Note() {
this.patch = 0;
this.cpatch = Renderer.Instr_Categ.Percussion;
this.channel = 9;
this.midi_number = 0;
this.status = true;
}

@Override
public String toString() {
return String.format("Note: %d - Channel: %d - Patch: %d (Category: %s) - Status: %s",this.midi_number,this.channel,this.patch,this.cpatch,this.status);
Expand Down
17 changes: 16 additions & 1 deletion src/com/bongo/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public static class Bongo {
Boolean l_hand=false;
Boolean r_hand=false;

// only use this with the final animation
Bongo() {
x = 0;
y = 0;
lastSecondValue = 0L;
note = new Note();
l_hand = true;
}

// same goes here
void swap() {
l_hand = !l_hand;
r_hand = !r_hand;
}

Bongo(Note note) {
if(note.status){
if(note.cpatch==Instr_Categ.Percussion || note.cpatch==Instr_Categ.CPerc){
Expand Down Expand Up @@ -75,7 +90,7 @@ public String toString(){

private static final ClassLoader classLoader = Renderer.class.getClassLoader();

static Image load_asset(String asset){
private static Image load_asset(String asset){
try{
return ImageIO.read(Objects.requireNonNull(classLoader.getResource(asset))).getScaledInstance(380,264,Image.SCALE_FAST);
}
Expand Down

0 comments on commit 2537c10

Please sign in to comment.