Skip to content

Commit

Permalink
Merge pull request #151 from Feodor0090/clock-offset-vis
Browse files Browse the repository at this point in the history
Clock offset visualizer
  • Loading branch information
Feodor0090 authored Jun 17, 2023
2 parents be283ab + b7b8e7f commit d3778e0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
Binary file added res/ui/exwf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/nmania/ui/ng/AudioSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String GetOption() {

public void OnOptionActivate(IDisplay d) {
d.Push(new Alert("AUDIO SETTINGS",
"Feedback samples - sounds like restart, fail, pass, etc. \n BMS's sounds - usage of effects provided by loaded beatmap, not default ones. \n Clock offset - set to positive to make notes appear earlier than music, set to negative to make notes appear before than music. Value is in milliseconds (1000 is 1 second)."));
"Feedback samples - sounds like restart, fail, pass, etc. \n BMS's sounds - usage of effects provided by loaded beatmap, not default ones."));
}

public void OnSelect(ListItem item, ListScreen screen, IDisplay display) {
Expand All @@ -48,7 +48,7 @@ public void OnSelect(ListItem item, ListScreen screen, IDisplay display) {
((SwitchItem) item).Toggle();
break;
case 4:
display.Push(new NumberBox("Clock offset", 0, this, Settings.gameplayOffset, true));
display.Push(new OffsetBox(0, this, Settings.gameplayOffset, true));
break;
case 5:
NumberBox nb = new NumberBox("Audio volume (%)", 1, this, Settings.volume, false);
Expand Down
12 changes: 6 additions & 6 deletions src/nmania/ui/ng/NumberBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public void OnOptionActivate(IDisplay d) {
public void Paint(Graphics g, int w, int h) {
g.setFont(num);
int fh = num.getHeight();
int offs = fh;
int offs = 10;
if (showPlusMinus) {
offs += 40;
offs += 35;
int b = (int) (Math.abs(1f - NmaniaDisplay.beatProgress * 2f) * 32);
g.setColor(ColorUtils.blend(-1, NmaniaDisplay.PINK_COLOR, b));
g.fillRoundRect(fh, 10, 35, fh, fh, fh);
g.fillRoundRect(w - fh - 35, 10, 35, fh, fh, fh);
g.fillRoundRect(1, 10, 34, fh, fh, fh);
g.fillRoundRect(w - 35, 10, 34, fh, fh, fh);
g.setColor(-1);
g.drawString("-1", fh + 17, 10, Graphics.TOP | Graphics.HCENTER);
g.drawString("+1", w - fh - 17, 10, Graphics.TOP | Graphics.HCENTER);
g.drawString("-1", 18, 10, Graphics.TOP | Graphics.HCENTER);
g.drawString("+1", w - 18, 10, Graphics.TOP | Graphics.HCENTER);
}

g.setColor(NmaniaDisplay.NEGATIVE_COLOR);
Expand Down
64 changes: 64 additions & 0 deletions src/nmania/ui/ng/OffsetBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package nmania.ui.ng;

import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

import nmania.GL;
import tube42.lib.imagelib.ColorUtils;

public class OffsetBox extends NumberBox {

public OffsetBox(int UUID, INumberBoxHandler handler, int value, boolean allowNegative) {
super("Clock offset", UUID, handler, value, allowNegative);
showPlusMinus = true;
try {
wf = Image.createImage("/ui/exwf.png");
} catch (IOException e) {
GL.Log("Failed to load waveform image, screen will fail!");
}
}

private Image wf;

public void Paint(Graphics g, int w, int h) {
g.setColor(0);
g.fillRect(w - 46, 5, 42, h - 10);
g.setColor(-1);
g.drawRect(w - 46, 5, 41, h - 11);
int time = (int) (System.currentTimeMillis() % 723);
int pprogress = (723 - time) * 112 / 723;
// waveform
{
g.drawRegion(wf, 112 - pprogress, 0, pprogress, 52, Sprite.TRANS_MIRROR_ROT90, w - 101, h - 5 - pprogress,
0);
int cy = h - 5 - pprogress - 112;
while (cy > 5) {
g.drawRegion(wf, 0, 0, 112, 52, Sprite.TRANS_MIRROR_ROT90, w - 101, cy, 0);
cy -= 112;
}
int ty = -(cy - 5);
g.drawRegion(wf, 0, 0, 112 - ty, 52, Sprite.TRANS_MIRROR_ROT90, w - 101, 5, 0);
}
// notes
for (int i = -2; i < 30; i++) {
int ny = h - 6 - pprogress - (56 * i) - (value * 112 / 723);
for (int j = 0; j < 25; j++) {
int ly = ny - j;
if (ly <= 5)
break;
if (ly >= h - 6)
continue;
g.setColor(ColorUtils.blend(0, 0x00ff00, j * 255 / 24));
g.drawLine(w - 45, ly, w - 6, ly);
}
}
super.Paint(g, w - 105, h);
}

public void OnTouch(IDisplay d, int s, int x, int y, int dx, int dy, int w, int h) {
super.OnTouch(d, s, x, y, dx, dy, w - 105, h);
}
}

0 comments on commit d3778e0

Please sign in to comment.