From f0858f657b803f72019dbf3aafd5a04e329d664d Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Thu, 29 Jan 2015 03:05:09 -0500 Subject: [PATCH] Display time since achieving recent scores. - Added history icon by Google: https://www.iconfinder.com/icons/326655/ - Draw history icon and elapsed time next to score buttons if they were achieved within 24 hours. Conforming to osu! behavior, the elapsed time is not updated in real-time. Signed-off-by: Jeffrey Han --- res/history.png | Bin 0 -> 1283 bytes src/itdelatrisu/opsu/GameImage.java | 6 ++++ src/itdelatrisu/opsu/ScoreData.java | 40 ++++++++++++++++++++-- src/itdelatrisu/opsu/states/SongMenu.java | 17 +++++---- 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 res/history.png diff --git a/res/history.png b/res/history.png new file mode 100644 index 0000000000000000000000000000000000000000..cb091c99f2f9563fb6f04848cb316f104c8742a7 GIT binary patch literal 1283 zcmV+e1^oJnP)iKFMoFudS(=3D8j)C3n5C6pRO}kM{b87(x$V;*bB*EhzOys4Gb51)UfBEbKKGfk z=iYnH^TL17R0$BSS@0T>3H51bA30FDDkfEHj6@D1>#q`yuHY1>x;_W+ZC`Vw9} z25bV}0k%l$s5)ueqkuWVvt6~_z(U{yNv=3)+x>y(fW|6>>Nem>NqZ_r+V*w8V&L3P zrk((P0S<*Q=mneu3<7!<5jIatYAQ(Db~j0XcS3jy@I25hWy(I_ePA>2y`=U8j7-?1 zV}Qxw?=)Ki%ufv$+lvBV+W3RETT`C(w#SyaFGkpIDuBJvw$fg1wf#!c1lzaTZb<ZngblJ_*~yZ0}0|+G2ZfC3m3h0k+qr5Wl++=~mkdLSJ{= zn^MA|z6vJ?w(D%KNLX{P?V<5TY>nPu3bciDIN$aHw@CVc)Z4BPdw+n%ZL?Mu7yG~IC`cgvQoyC%#YI|1Ab7pBL zur=x)Z@W*XNQ^nQXPyFYuZr5;fvYnm06b;;ks6b3PUst%DG_9z?ddfPkv3p|)O}H= z46J8tPphG~cSr5P*--YBYS-G{Ch5BxkUkK#>$8&Xt>S`XY~LX1<1S$Q8MV*MRM|`Y zfu**W*&bLXMmB1MmRnY#P2;xtgH3AnzeIH6{SM=-Z$*G$8O3+bY zw4{Tzy0^oz*qm^3G)mf@iM((aSP@O^4ZKj}?C#M7!kquW6I0jfYrc=Xy`cbP$)brP52Vv zZJ=K?^cyfCgf6KyVo*_M1konndIE3Qez+1kUcR0Oyq7?@9hi|%xEQeEw)doHY)!U@ zbdhXd+piW-PH#_iY7xNK0B?p`UMf&0R9M$!~uuB7Erm-Iuy zTeZX(6mSPHkIuinlwv1<*MLQmj(3_0l(~U=15?A(zYAoK0ZqVSNe7C~U%I&av%vU} tLXIoa`$x%re%k=7lXQgBcG~{u_79BUAsneZ5as{?002ovPDHLkV1nSmV5R^7 literal 0 HcmV?d00001 diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index 065566dc..2ffc139e 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -465,6 +465,12 @@ public enum GameImage { return img.getScaledCopy((h * 0.15f) / img.getHeight()); } }, + HISTORY ("history", "png", false, false) { + @Override + protected Image process_sub(Image img, int w, int h) { + return img.getScaledCopy((h * 0.0278f) / img.getHeight()); + } + }, REPOSITORY ("repo", "png", false, false) { @Override protected Image process_sub(Image img, int w, int h) { diff --git a/src/itdelatrisu/opsu/ScoreData.java b/src/itdelatrisu/opsu/ScoreData.java index 4fbdfa93..992543fa 100644 --- a/src/itdelatrisu/opsu/ScoreData.java +++ b/src/itdelatrisu/opsu/ScoreData.java @@ -59,6 +59,9 @@ public class ScoreData implements Comparable { /** Game mod bitmask. */ public int mods; + /** Time since the score was achieved. */ + private String timeSince; + /** The grade. */ private Grade grade; @@ -191,6 +194,26 @@ public class ScoreData implements Comparable { return grade; } + /** + * Returns the time since achieving the score, or null if over 24 hours. + * This value will not change after the first call. + * @return a string: {number}{s|m|h} + */ + public String getTimeSince() { + if (timeSince == null) { + long seconds = (System.currentTimeMillis() / 1000L) - timestamp; + if (seconds < 60) + timeSince = String.format("%ds", seconds); + else if (seconds < 3600) + timeSince = String.format("%dm", seconds / 60L); + else if (seconds < 86400) + timeSince = String.format("%dh", seconds / 3600L); + else + timeSince = ""; + } + return (timeSince.isEmpty()) ? null : timeSince; + } + /** * Draws the score data as a rectangular button. * @param g the graphics context @@ -201,8 +224,10 @@ public class ScoreData implements Comparable { */ public void draw(Graphics g, int index, int rank, long prevScore, boolean focus) { Image img = getGrade().getMenuImage(); + float textX = baseX + buttonWidth * 0.24f; + float edgeX = baseX + buttonWidth * 0.98f; float y = baseY + index * (buttonOffset); - float textX = baseX + buttonWidth * 0.24f, edgeX = baseX + buttonWidth * 0.98f; + float midY = y + buttonHeight / 2f; float marginY = Utils.FONT_DEFAULT.getLineHeight() * 0.01f; // rectangle outline @@ -219,7 +244,7 @@ public class ScoreData implements Comparable { } // grade image - img.drawCentered(baseX + buttonWidth * 0.15f, y + buttonHeight / 2f); + img.drawCentered(baseX + buttonWidth * 0.15f, midY); // score float textOffset = (buttonHeight - Utils.FONT_MEDIUM.getLineHeight() - Utils.FONT_SMALL.getLineHeight()) / 2f; @@ -269,6 +294,17 @@ public class ScoreData implements Comparable { y + marginY + Utils.FONT_DEFAULT.getLineHeight() * 2, diff, Color.white ); + + // time since + if (getTimeSince() != null) { + Image clock = GameImage.HISTORY.getImage(); + clock.drawCentered(baseX + buttonWidth * 1.02f + clock.getWidth() / 2f, midY); + Utils.FONT_DEFAULT.drawString( + baseX + buttonWidth * 1.03f + clock.getWidth(), + midY - Utils.FONT_DEFAULT.getLineHeight() / 2f, + getTimeSince(), Color.white + ); + } } @Override diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index 4da0eb7d..d4cb3b99 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -280,7 +280,7 @@ public class SongMenu extends BasicGameState { for (int i = 0; i < MAX_SONG_BUTTONS && node != null; i++, node = node.next) { // draw the node float offset = (i == hoverIndex) ? hoverOffset : 0f; - ScoreData[] scores = getScoreDataForNode(node); + ScoreData[] scores = getScoreDataForNode(node, false); node.draw( buttonX - offset, buttonY + (i*buttonOffset), (scores == null) ? Grade.NULL : scores[0].getGrade(), @@ -797,7 +797,7 @@ public class SongMenu extends BasicGameState { // reload scores if (focusNode != null) { scoreMap = ScoreDB.getMapSetScores(focusNode.osuFiles.get(focusNode.osuFileIndex)); - focusScores = getScoreDataForNode(focusNode); + focusScores = getScoreDataForNode(focusNode, true); } resetGame = false; @@ -892,7 +892,7 @@ public class SongMenu extends BasicGameState { // load scores scoreMap = ScoreDB.getMapSetScores(osu); - focusScores = getScoreDataForNode(focusNode); + focusScores = getScoreDataForNode(focusNode, true); startScore = 0; // check startNode bounds @@ -936,9 +936,10 @@ public class SongMenu extends BasicGameState { * Returns all the score data for an OsuGroupNode from scoreMap. * If no score data is available for the node, return null. * @param node the OsuGroupNode + * @param setTimeSince whether or not to set the "time since" field for the scores * @return the ScoreData array */ - private ScoreData[] getScoreDataForNode(OsuGroupNode node) { + private ScoreData[] getScoreDataForNode(OsuGroupNode node, boolean setTimeSince) { if (scoreMap == null || scoreMap.isEmpty() || node.osuFileIndex == -1) // node not expanded return null; @@ -950,9 +951,13 @@ public class SongMenu extends BasicGameState { ScoreData s = scores[0]; if (osu.beatmapID == s.MID && osu.beatmapSetID == s.MSID && osu.title.equals(s.title) && osu.artist.equals(s.artist) && - osu.creator.equals(s.creator)) + osu.creator.equals(s.creator)) { + if (setTimeSince) { + for (int i = 0; i < scores.length; i++) + scores[i].getTimeSince(); + } return scores; - else + } else return null; // incorrect map }