This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
package gui.widget;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import imgui.ImGui;
|
||||
|
||||
public class TimerRenderer {
|
||||
|
||||
private float time;
|
||||
private final float duration;
|
||||
private final long endTime;
|
||||
|
||||
public TimerRenderer(float duration) {
|
||||
this.time = 0;
|
||||
this.duration = duration;
|
||||
public TimerRenderer(Instant startTime, int duration) {
|
||||
this.endTime = startTime.getEpochSecond() + duration;
|
||||
}
|
||||
|
||||
private long getTimeRemaining() {
|
||||
long currentTime = Instant.now().getEpochSecond();
|
||||
return endTime - currentTime;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
this.time += ImGui.getIO().getDeltaTime();
|
||||
float remainingTime = this.duration - this.time;
|
||||
int seconds = (int) remainingTime;
|
||||
int minutes = seconds / 60;
|
||||
seconds %= 60;
|
||||
String text = String.format("%02d:%02d", minutes, seconds);
|
||||
long seconds = getTimeRemaining();
|
||||
long minutes = seconds / 60;
|
||||
String text = String.format("%02d:%02d", minutes, seconds % 60);
|
||||
var textSize = ImGui.calcTextSize(text);
|
||||
ImGui.setCursorPosX(ImGui.getIO().getDisplaySizeX() / 2.0f - textSize.x / 2.0f);
|
||||
ImGui.text(text);
|
||||
|
||||
Reference in New Issue
Block a user