-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/me/varun/autobuilder/gui/notification/Notification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package me.varun.autobuilder.gui.notification; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Color; | ||
import com.badlogic.gdx.graphics.g2d.Batch; | ||
import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
import com.badlogic.gdx.graphics.g2d.GlyphLayout; | ||
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | ||
import me.varun.autobuilder.util.RoundedShapeRenderer; | ||
import space.earlygrey.shapedrawer.ShapeDrawer; | ||
|
||
public class Notification { | ||
private final long deleteTime; | ||
private final long creationTime; | ||
private final Color color; | ||
private final String text; | ||
|
||
private static final long ANIMATE_IN_OUT_TIME = 100; //ns | ||
|
||
/** | ||
* | ||
* @param color Color of the background of the notification | ||
* @param text Text in the notification | ||
* @param duration duration of the notification (ms) | ||
*/ | ||
public Notification(Color color, String text, long duration){ | ||
this.color = color; | ||
this.text = text; | ||
this.creationTime = System.currentTimeMillis(); | ||
this.deleteTime = this.creationTime + (duration); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Notification{" + | ||
"deleteTime=" + deleteTime + | ||
", creationTime=" + creationTime + | ||
", color=" + color + | ||
", text='" + text + '\'' + | ||
'}'; | ||
} | ||
|
||
public boolean tick(ShapeDrawer drawer, Batch batch, BitmapFont font, ShaderProgram fontShader){ | ||
long now = System.currentTimeMillis(); | ||
float renderHeight = (Gdx.graphics.getHeight()) + Math.min(Math.min((float) (now - creationTime) / ANIMATE_IN_OUT_TIME, (float) (deleteTime - now) / ANIMATE_IN_OUT_TIME), 1) * (-50); | ||
RoundedShapeRenderer.roundedRect(drawer, Gdx.graphics.getWidth()/2f - (700/2f), renderHeight, 700, 40, 5, color); | ||
|
||
batch.setShader(fontShader); | ||
batch.setColor(Color.WHITE); | ||
font.getData().setScale(27 / 64f); | ||
GlyphLayout glyphLayout = new GlyphLayout(); | ||
glyphLayout.setText(font, text, Color.WHITE, 700, 1, false); | ||
font.draw(batch, glyphLayout, Gdx.graphics.getWidth()/2f - (700/2f), renderHeight+30); | ||
batch.setShader(null); | ||
|
||
return deleteTime < now; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/me/varun/autobuilder/gui/notification/NotificationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.varun.autobuilder.gui.notification; | ||
|
||
import com.badlogic.gdx.graphics.g2d.Batch; | ||
import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | ||
import space.earlygrey.shapedrawer.ShapeDrawer; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class NotificationHandler { | ||
private final static ArrayList<Notification> notifications = new ArrayList<>(); | ||
|
||
public static void addNotification(Notification notification){ | ||
notifications.add(notification); | ||
} | ||
|
||
ArrayList<Notification> notificationsToDelete = new ArrayList<>(); | ||
public void processNotification(ShapeDrawer drawer, Batch batch, BitmapFont font, ShaderProgram fontShader){ | ||
notificationsToDelete.clear(); | ||
for (Notification notification : notifications) { | ||
if (notification.tick(drawer, batch, font, fontShader)) { | ||
notificationsToDelete.add(notification); | ||
} | ||
} | ||
|
||
for (Notification notification : notificationsToDelete) { | ||
notifications.remove(notification); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters