feat: first player progress display
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package gui.widget;
|
||||
|
||||
import game.Game;
|
||||
import game.Player;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
|
||||
public class MultiPlayerCompleteProgress {
|
||||
|
||||
private final Game game;
|
||||
private final int emptyCellCount;
|
||||
private final ImVec2 progressSize = new ImVec2(700, 50);
|
||||
private final SmoothProgressBar progressBar;
|
||||
|
||||
public MultiPlayerCompleteProgress(Game game) {
|
||||
this.game = game;
|
||||
this.emptyCellCount = game.getDoku().getEmptyCells().size();
|
||||
this.progressBar = new SmoothProgressBar();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
Player firstPlayer = game.getLeaderboard().get(0);
|
||||
ImGui.setCursorPosX(ImGui.getIO().getDisplaySizeX() / 2.0f - progressSize.x / 2.0f);
|
||||
String progressText = firstPlayer.getPseudo() + " - " + firstPlayer.getScore() + "/" + emptyCellCount;
|
||||
this.progressBar.render(progressText, progressSize, 1.0f - firstPlayer.getScore() / (float) emptyCellCount);
|
||||
}
|
||||
|
||||
}
|
||||
21
app/src/main/java/gui/widget/SmoothProgressBar.java
Normal file
21
app/src/main/java/gui/widget/SmoothProgressBar.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package gui.widget;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
|
||||
public class SmoothProgressBar {
|
||||
|
||||
private float lastProgress = 0;
|
||||
private final float speed = 2.0f;
|
||||
private final float clipConstant = 0.001f;
|
||||
|
||||
public void render(String label, ImVec2 size, float progress) {
|
||||
float delta = progress - lastProgress;
|
||||
if (Math.abs(delta) < clipConstant)
|
||||
lastProgress = progress;
|
||||
else
|
||||
lastProgress = lastProgress + delta * ImGui.getIO().getDeltaTime() * speed;
|
||||
ImGui.progressBar(lastProgress, size, label);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user