Skip to content

Commit 53248e5

Browse files
committed
进度条显示,KTV歌词客户端计时
1 parent 650a7e8 commit 53248e5

19 files changed

Lines changed: 257 additions & 199 deletions

File tree

client

Submodule client updated 30 files

server/core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ dependencies {
33
shadowImplementation("org.apache.httpcomponents.core5:httpcore5:${Versions.httpcore5}")
44
shadowImplementation("org.apache.httpcomponents.core5:httpcore5-h2:${Versions.httpcore5_h2}")
55

6-
compileOnly("com.google.code.gson:gson:${Versions.gson}")
6+
implementation("com.google.code.gson:gson:${Versions.gson}")
77
compileOnly("net.kyori:adventure-text-minimessage:${Versions.minimessage}")
88
}

server/core/src/main/java/com/coloryr/allmusic/server/core/command/sub/CommandHud.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class CommandHud extends ACommand {
1919
this.add("info");
2020
this.add("list");
2121
this.add("lyric");
22+
this.add("state");
2223
this.add("pic");
2324
}};
2425
private final Map<String, ICommand> commandList = new HashMap<>();
@@ -29,6 +30,7 @@ public CommandHud() {
2930
commandList.put("info", new CommandHudSet(HudType.INFO));
3031
commandList.put("list", new CommandHudSet(HudType.LIST));
3132
commandList.put("lyric", new CommandHudSet(HudType.LYRIC));
33+
commandList.put("state", new CommandHudSet(HudType.STATE));
3234
commandList.put("pic", new CommandHudSet(HudType.PIC));
3335
}
3436

@@ -70,7 +72,7 @@ public void execute(Object sender, String name, String[] args) {
7072
if (args.length == 2 || args.length == 3) {
7173
boolean temp = HudUtils.setHudEnable(name, null, args.length == 3 ? args[2] : null);
7274
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().hud.state
73-
.replace(ARG.state, temp ? "启用" : "关闭")
75+
.replace(ARG.value, temp ? AllMusic.getMessage().hudList.enable : AllMusic.getMessage().hudList.disable)
7476
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(null)));
7577
return;
7678
}

server/core/src/main/java/com/coloryr/allmusic/server/core/command/sub/CommandHudSet.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.coloryr.allmusic.codec.HudBasePosObj;
44
import com.coloryr.allmusic.codec.HudPosType;
5-
import com.coloryr.allmusic.codec.HudItemPosObj;
5+
import com.coloryr.allmusic.codec.HudStatePosObj;
66
import com.coloryr.allmusic.codec.HudType;
77
import com.coloryr.allmusic.server.core.AllMusic;
88
import com.coloryr.allmusic.server.core.command.ACommand;
@@ -32,6 +32,8 @@ public class CommandHudSet extends AHudCommand {
3232
private static final List<String> info = new ArrayList<String>() {{
3333
this.add("color");
3434
this.add("shadow");
35+
this.add("loop");
36+
this.add("maxwidth");
3537
}};
3638
private static final List<String> tf = new ArrayList<String>() {{
3739
this.add("true");
@@ -54,6 +56,7 @@ public CommandHudSet(HudType type) {
5456
commandList.put("color", new HudColor(type));
5557
commandList.put("shadow", new HudShadow(type));
5658
commandList.put("loop", new HudLoop(type));
59+
commandList.put("maxwidth", new HudMaxWidth(type));
5760
}
5861
}
5962

@@ -101,7 +104,7 @@ public void execute(Object sender, String name, String[] args) {
101104
if (args.length == 3 || args.length == 4) {
102105
boolean temp = HudUtils.setHudEnable(name, type, args.length == 4 ? args[3] : null);
103106
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().hud.state
104-
.replace(ARG.state, temp
107+
.replace(ARG.value, temp
105108
? AllMusic.getMessage().hudList.enable
106109
: AllMusic.getMessage().hudList.disable)
107110
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type)));
@@ -178,9 +181,36 @@ public void execute(Object sender, String name, String[] args) {
178181
return;
179182
}
180183

181-
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().hud.set4
184+
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().hud.set5
182185
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
183-
.replace(ARG.alpha, String.valueOf(obj.alpha)));
186+
.replace(ARG.value, String.valueOf(obj.alpha)));
187+
} catch (Exception e) {
188+
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
189+
}
190+
}
191+
}
192+
193+
private static class HudMaxWidth extends AHudCommand {
194+
public HudMaxWidth(HudType type) {
195+
super(type);
196+
}
197+
198+
@Override
199+
public void execute(Object sender, String name, String[] args) {
200+
try {
201+
if (args.length != 4) {
202+
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
203+
return;
204+
}
205+
int width = HudUtils.setHudHudMaxWidth(name, type, args[3]);
206+
if (width == -1) {
207+
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().command.error);
208+
return;
209+
}
210+
211+
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().hud.set6
212+
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
213+
.replace(ARG.value, String.valueOf(width)));
184214
} catch (Exception e) {
185215
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
186216
}
@@ -211,7 +241,7 @@ public void execute(Object sender, String name, String[] args) {
211241
}
212242
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.set1
213243
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
214-
.replace(ARG.dir, AllMusic.getMessage().hudList.getDir(type1)));
244+
.replace(ARG.value, AllMusic.getMessage().hudList.getDir(type1)));
215245
}
216246

217247
@Override
@@ -241,7 +271,7 @@ public void execute(Object sender, String name, String[] args) {
241271
}
242272
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.set2
243273
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
244-
.replace(ARG.color, String.format("%06X", color & 0xFFFFFF)));
274+
.replace(ARG.value, String.format("%06X", color & 0xFFFFFF)));
245275
}
246276
}
247277

@@ -255,7 +285,7 @@ public void execute(Object sender, String name, String[] args) {
255285
if (args.length == 3 || args.length == 4) {
256286
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.set3
257287
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
258-
.replace(ARG.state, HudUtils.setShadow(name, type, args.length == 4 ? args[3] : null)
288+
.replace(ARG.value, HudUtils.setShadow(name, type, args.length == 4 ? args[3] : null)
259289
? AllMusic.getMessage().hudList.enable
260290
: AllMusic.getMessage().hudList.disable));
261291
return;
@@ -290,7 +320,7 @@ public void execute(Object sender, String name, String[] args) {
290320
}
291321
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.set2
292322
.replace(ARG.hud, AllMusic.getMessage().hudList.getHud(type))
293-
.replace(ARG.color, loop));
323+
.replace(ARG.value, loop));
294324
}
295325

296326
@Override
@@ -310,7 +340,7 @@ public void execute(Object sender, String name, String[] args) {
310340
return;
311341
}
312342
AllMusic.side.sendMessage(sender,
313-
AllMusic.getMessage().hud.picSize.replace(ARG.size, args[2]));
343+
AllMusic.getMessage().hud.picSize.replace(ARG.value, args[2]));
314344
}
315345
}
316346

@@ -319,7 +349,7 @@ private static class PicRotate extends ACommand {
319349
public void execute(Object sender, String name, String[] args) {
320350
if (args.length == 3 || args.length == 4) {
321351
AllMusic.side.sendMessage(sender, AllMusic.getMessage().hud.picRotate
322-
.replace(ARG.state, HudUtils.setPicRotate(name, args.length == 4 ? args[3] : null)
352+
.replace(ARG.value, HudUtils.setPicRotate(name, args.length == 4 ? args[3] : null)
323353
? AllMusic.getMessage().hudList.enable
324354
: AllMusic.getMessage().hudList.disable));
325355
return;
@@ -344,7 +374,7 @@ public void execute(Object sender, String name, String[] args) {
344374
return;
345375
}
346376
AllMusic.side.sendMessage(sender,
347-
AllMusic.getMessage().hud.picSpeed.replace(ARG.size, args[3]));
377+
AllMusic.getMessage().hud.picSpeed.replace(ARG.value, args[3]));
348378
}
349379
}
350380
}

server/core/src/main/java/com/coloryr/allmusic/server/core/command/sub/CommandNext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CommandNext extends ACommand {
1010

1111
@Override
1212
public void execute(Object sender, String name, String[] args) {
13-
PlayMusic.musicLessTime = 1;
13+
PlayMusic.musicLessTime = 10;
1414
AllMusic.side.sendMessage(sender, "<light_purple>[AllMusic3]<dark_green>已强制切歌");
1515
BanSave.removeMutePlayer(name);
1616
}

server/core/src/main/java/com/coloryr/allmusic/server/core/music/KtvLyric.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
package com.coloryr.allmusic.server.core.music;
22

33
import com.coloryr.allmusic.server.core.objs.music.LyricItemObj;
4+
import com.coloryr.allmusic.codec.KtvLyricObj;
45

56
import java.util.HashMap;
67
import java.util.Map;
78

89
public class LyricSave {
910
protected boolean haveLyric;
10-
protected float kly = 0;
1111
protected LyricItemObj now;
1212
private Map<Long, LyricItemObj> lyric;
13-
private Map<Long, KtvLyric> klyric;
14-
private KtvLyric ktvNow;
13+
private Map<Long, KtvLyricObj> klyric;
14+
private KtvLyricObj ktvNow;
1515

1616
public LyricSave() {
1717
haveLyric = false;
1818
lyric = new HashMap<>();
1919
}
2020

21-
public void setKlyric(Map<Long, KtvLyric> klyric) {
21+
public KtvLyricObj getKtvNow() {
22+
return ktvNow;
23+
}
24+
25+
public LyricItemObj getNow() {
26+
return now;
27+
}
28+
29+
public void setKlyric(Map<Long, KtvLyricObj> klyric) {
2230
this.klyric = klyric;
2331
}
2432

@@ -42,50 +50,17 @@ public String getTlyric() {
4250
return now.tlyric;
4351
}
4452

45-
public float getKly() {
46-
return kly;
47-
}
48-
49-
public void kUpdate(long playNow) {
50-
if (now == null || now.lyric == null || now.lyric.isEmpty()
51-
|| ktvNow == null || ktvNow.items == null || ktvNow.items.isEmpty()) {
52-
kly = 0.0f;
53-
return;
54-
}
55-
56-
if (playNow < ktvNow.start) {
57-
kly = 0.0f;
58-
return;
59-
}
60-
61-
if (playNow >= ktvNow.start + ktvNow.time) {
62-
kly = 1.0f;
63-
return;
64-
}
65-
66-
for (int i = 0; i < ktvNow.items.size(); i++) {
67-
KtvLyric.KtvItem item = ktvNow.items.get(i);
68-
if (playNow >= item.start && playNow < item.start + item.time) {
69-
float progressInChar = (float) (playNow - item.start) / item.time;
70-
kly = (i + progressInChar) / ktvNow.items.size();
71-
return;
72-
}
73-
}
74-
75-
kly = 0.0f;
76-
}
77-
78-
private void ktvGetNext(long time) {
53+
public boolean ktvGetNext(long time) {
7954
if (klyric == null)
80-
return;
55+
return false;
8156

82-
KtvLyric temp = klyric.get(time);
57+
KtvLyricObj temp = klyric.get(time);
8358
if (temp != null) {
8459
ktvNow = temp;
85-
kly = 0.0f;
60+
return true;
8661
}
8762

88-
kUpdate(time);
63+
return false;
8964
}
9065

9166
public boolean lyricGetNext(long playNow) {
@@ -94,18 +69,21 @@ public boolean lyricGetNext(long playNow) {
9469

9570
LyricItemObj temp = lyric.get(playNow);
9671
if (temp != null && now != temp) {
72+
if (ktvNow != null) {
73+
long time = Math.abs(ktvNow.start - temp.start);
74+
KtvLyricObj.KtvItem start = ktvNow.items.get(0);
75+
if (time > 500 && (start != null && !temp.lyric.startsWith(start.key))) {
76+
ktvNow = null;
77+
}
78+
}
79+
9780
now = temp.copy();
9881
if (now.tlyric == null) {
9982
now.tlyric = "";
10083
}
101-
kly = 0.0f;
10284
return true;
10385
}
10486

10587
return false;
10688
}
107-
108-
public void updateKtv(long playNow) {
109-
ktvGetNext(playNow);
110-
}
11189
}

server/core/src/main/java/com/coloryr/allmusic/server/core/music/PlayMusic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public static void addMusic(Object sender, String id, IMusicApi api, String play
296296
}
297297
if (AllMusic.getConfig().playListSwitch
298298
&& (PlayMusic.nowPlayMusic != null && PlayMusic.nowPlayMusic.isList())) {
299-
PlayMusic.musicLessTime = 1;
299+
PlayMusic.musicLessTime = 10;
300300
if (!isList) {
301301
AllMusic.side.broadcastInTask(AllMusic.getMessage().musicPlay.switchMusic);
302302
}

0 commit comments

Comments
 (0)