Draw Editor Notes and Beat lines.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent b19eff2e03
commit aa6611ff2f
  1. 33
      LLSIG/src/main/java/LLSIG/Canvas.java
  2. 20
      LLSIG/src/main/java/LLSIG/LLSIG.java

@ -6,6 +6,8 @@ import java.awt.geom.Rectangle2D;
import java.awt.font.FontRenderContext;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.JPanel;
@ -55,9 +57,37 @@ public class Canvas extends JPanel implements AudioSpectrumListener{
SpectrographBar sb = spectrograph.get(i);
sb.draw(g,SPECTROBAR_SIZE*i,SPECTROBAR_SIZE,this.getHeight());
}
g.setColor(Color.WHITE);
g.drawString(Double.toString(LLSIG.game.musicPlayer.getPlayPosition()),0,32);
if (LLSIG.game.EDITOR) {
final int MARGIN_X = 32;
final int BEAT_RANGE = 6;
final int BEAT_SPACING = 64;
final int NOTE_Y=(int)(MIDDLE_Y-NOTE_SIZE/2);
for (int y=-BEAT_RANGE;y<BEAT_RANGE;y++) {
g.setColor(Color.GRAY);
g.fillRect(MARGIN_X,(int)(NOTE_Y+(y)*BEAT_SPACING),this.getWidth()-MARGIN_X,4);
g.setColor(Color.DARK_GRAY);
for (int yy=0;yy<LLSIG.EDITOR_BEAT_DIVISIONS;yy++) {
g.fillRect(MARGIN_X*2,(int)(NOTE_Y+(y)*BEAT_SPACING)+(BEAT_SPACING/LLSIG.EDITOR_BEAT_DIVISIONS)*yy,this.getWidth()-MARGIN_X*2,2);
}
}
for (int i=0;i<9;i++) {
if (LLSIG.keyState[i]) {
g.setColor(Color.MAGENTA);
} else {
g.setColor(Color.GRAY);
}
int NOTE_X=(int)(((this.getWidth()-MARGIN_X*2)/9)*i-NOTE_SIZE/2+MARGIN_X);
g.fillOval(NOTE_X,NOTE_Y,NOTE_SIZE,NOTE_SIZE);
Lane lane = LLSIG.game.lanes.get(i);
List<Note> notes = lane.noteChart.stream().filter((note)->Math.abs(LLSIG.EDITOR_CURSOR_BEAT-note.beatSnapStart)<BEAT_RANGE).collect(Collectors.toList());
for (Note n : notes) {
g.fillOval(NOTE_X-NOTE_SIZE/2,(int)(NOTE_Y+(LLSIG.EDITOR_CURSOR_BEAT-n.beatSnapStart)*BEAT_SPACING-NOTE_SIZE/2),NOTE_SIZE,NOTE_SIZE);
}
}
} else {
if (LLSIG.game.BPM_MEASURE) {
g.drawString("Average BPM: "+LLSIG.approximateBPM(),MIDDLE_X-128,MIDDLE_Y+64);
} else
@ -133,6 +163,7 @@ public class Canvas extends JPanel implements AudioSpectrumListener{
}
}
}
}
@Override
public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
if (spectrograph.size()!=magnitudes.length) {

@ -50,6 +50,12 @@ public class LLSIG implements KeyListener{
public boolean METRONOME = false;
public boolean BPM_MEASURE = false;
public boolean PLAYING = true; //Whether or not a song is loaded and playing.
public boolean EDITOR = false; //Whether or not we are in beatmap editing mode.
public static int EDITOR_CURSOR_BEAT = 0;
public static int EDITOR_BEAT_DIVISIONS = 4;
public static BeatTiming EDITOR_CURSOR_WINDOW;
public static int beatNumber = 0;
public static boolean[] lanePress = new boolean[9]; //A lane is being requested to being pressed.
@ -81,10 +87,7 @@ public class LLSIG implements KeyListener{
LLSIG(JFrame f) {
Platform.startup(() ->
{
// This block will be executed on JavaFX Thread
});
Platform.startup(()->{});
this.window = f;
@ -113,7 +116,9 @@ public class LLSIG implements KeyListener{
PLAYING = new File("music/"+song+".mp3").exists();
if (PLAYING) {
this.musicPlayer = new Player(Paths.get("music/"+song+".mp3").toUri().toString());
if (!EDITOR) {
musicPlayer.play();
}
LoadSongData(song,lanes);
}
@ -136,6 +141,7 @@ public class LLSIG implements KeyListener{
bpm=bt.bpm;
offset=bt.offset;
beatDelay = ((1/((double)bpm/60))*1000);
beatNumber=0;
System.out.println("BPM is "+bpm+". Delay is "+beatDelay);
}
}
@ -298,15 +304,15 @@ public class LLSIG implements KeyListener{
case KeyEvent.VK_P:{if (LLSIG.game.PLAYING&&musicPlayer.isPaused()) {musicPlayer.resume();} else {musicPlayer.pause();}}break;
case KeyEvent.VK_Q:{if (LLSIG.game.PLAYING) {musicPlayer.pause();SaveSongData(song,lanes);}}break;
}
if (LLSIG.game.PLAYING&&lane!=-1&&EDITMODE) {
if (lane!=-1) {
if (PLAYING&&EDITMODE) {
Note n = new Note(NoteType.NORMAL,musicPlayer.getPlayPosition());
n.active=false;
System.out.println(Math.round(((musicPlayer.getPlayPosition()-offset)/beatDelay)*4)/(double)4);
n.setBeatSnap(Math.round(((musicPlayer.getPlayPosition()-offset)/beatDelay)*4)/(double)4);
LLSIG.game.lanes.get(lane).addNote(n);
}
if (lane!=-1) {
if (PLAYING&&!EDITMODE) {
if (PLAYING&&!EDITMODE&&!EDITOR) {
Lane l = lanes.get(lane);
if (l.noteExists()) {
Note n = l.getNote();

Loading…
Cancel
Save