feat: first player progress display
This commit is contained in:
@@ -2,6 +2,7 @@ package gui.menu;
|
||||
|
||||
import game.Game;
|
||||
import gui.widget.LeaderboardRenderer;
|
||||
import gui.widget.MultiPlayerCompleteProgress;
|
||||
import gui.widget.SudokuRenderer;
|
||||
import gui.widget.TimerRenderer;
|
||||
import imgui.ImGui;
|
||||
@@ -16,6 +17,7 @@ public class MultiPlayerDokuView extends BaseView {
|
||||
private final SudokuRenderer sudokuRenderer;
|
||||
private final LeaderboardRenderer leaderboardRenderer;
|
||||
private final TimerRenderer timerRenderer;
|
||||
private final MultiPlayerCompleteProgress completeProgress;
|
||||
|
||||
public MultiPlayerDokuView(StateMachine stateMachine, Client client, Server server) {
|
||||
super(stateMachine);
|
||||
@@ -26,6 +28,7 @@ public class MultiPlayerDokuView extends BaseView {
|
||||
this.sudokuRenderer.onCellChange.connect(this::onCellChange);
|
||||
this.client.onDisconnect.connect(this::onDisconnect);
|
||||
this.timerRenderer = new TimerRenderer(this.client.getGame().getStartTime(), Game.GAME_DURATION);
|
||||
this.completeProgress = new MultiPlayerCompleteProgress(this.client.getGame());
|
||||
}
|
||||
|
||||
private void onCellChange(Cell cell) {
|
||||
@@ -42,6 +45,7 @@ public class MultiPlayerDokuView extends BaseView {
|
||||
public void render() {
|
||||
this.timerRenderer.render();
|
||||
this.leaderboardRenderer.render();
|
||||
this.completeProgress.render();
|
||||
this.sudokuRenderer.render();
|
||||
if (ImGui.button("Quitter")) {
|
||||
this.client.stop();
|
||||
|
||||
@@ -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