Skip to content

Commit b5ab60d

Browse files
committed
Display remaining time to event start
1 parent dbc8a20 commit b5ab60d

File tree

4 files changed

+80
-33
lines changed

4 files changed

+80
-33
lines changed

assets/lang/lang_en.properties

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ m.resource_mod="Resource mod"
126126
m.code_mod="Code mod"
127127
m.code_mod_jdkincompatible="Incompatible"
128128
m.modlist_footer="Displaying {0} out of {1} mod(s)."
129-
m.days="Days"
130-
m.hours="Hours"
131-
m.minutes="Minutes"
132-
m.seconds="Seconds"
129+
m.days="Day(s)"
130+
m.hours="Hour(s)"
131+
m.minutes="Minute(s)"
132+
m.seconds="Second(s)"
133+
m.timer_days="{0} day(s)"
134+
m.timer_hours="{0} hour(s)"
135+
m.timer_minutes="{0} minute(s)"
136+
m.timer_less_than_minute="less than a minute"
137+
m.timer_seconds="{0} second(s)"
133138
m.online="Online"
134139
m.offline="Offline"
135140
m.recently_restarted="Recently restarted"
@@ -167,7 +172,10 @@ m.animated_banners_disable="Disable animated banners"
167172
m.animated_banners_enable="Enable animated banners"
168173
m.add_server="Add a server"
169174
m.add_server_text="Third party servers will be automatically added to this list once they are publicly available.\n\nYou can redeem Beta access to third party servers by going into the Betas tab in the launcher's settings."
170-
m.banner_ends_at="Runs through {0}"
175+
m.banner_starts_at_date="Starts on {0}"
176+
m.banner_starts_at_remaining="Starts in {0}"
177+
m.banner_ends_at_date="Runs through {0}"
178+
m.banner_ends_at_remaining="Ends in {0}"
171179
m.banner_ends_at_ended="This event has ended"
172180

173181
# Options (usually on comboboxes)

src/main/java/com/luuqui/launcher/LauncherEventHandler.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,20 +526,24 @@ public static void updateBanner() {
526526
LauncherGUI.bannerLinkButton.setVisible(false);
527527
}
528528

529-
if(LauncherApp.selectedServer.announceBannerEndsAt != 0L) {
530-
if(System.currentTimeMillis() > LauncherApp.selectedServer.announceBannerEndsAt) {
531-
LauncherGUI.bannerEndsAt.setText(Locale.getValue("m.banner_ends_at_ended"));
529+
if(LauncherApp.selectedServer.announceBannerEndsAt != 0L || LauncherApp.selectedServer.announceBannerStartsAt != 0L) {
530+
531+
if(LauncherApp.selectedServer.announceBannerStartsAt > System.currentTimeMillis()) {
532+
// The event has not yet started
533+
LauncherGUI.bannerTimer.setText(Locale.getValue("m.banner_starts_at_remaining", DateUtil.getFormattedRemaining(LauncherApp.selectedServer.announceBannerStartsAt)));
534+
} else if(System.currentTimeMillis() > LauncherApp.selectedServer.announceBannerEndsAt) {
535+
// The event already ended
536+
LauncherGUI.bannerTimer.setText(Locale.getValue("m.banner_ends_at_ended"));
532537
} else {
533-
Calendar calendar = Calendar.getInstance();
534-
calendar.setTimeInMillis(LauncherApp.selectedServer.announceBannerEndsAt);
535-
calendar.setTimeZone(TimeZone.getTimeZone("PST")); // Game's timezone
536-
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM"); // Only the month, we'll concatenate the day later.
537-
538-
LauncherGUI.bannerEndsAt.setText(Locale.getValue("m.banner_ends_at", dateFormat.format(calendar.getTime()) + " " + DateUtil.getDayNumberWithSuffix(calendar.get(Calendar.DATE) - 1)));
538+
// The event is currently running
539+
LauncherGUI.bannerTimer.setText(Locale.getValue("m.banner_ends_at_date", DateUtil.getFormattedMonthDay(LauncherApp.selectedServer.announceBannerEndsAt)));
539540
}
540-
LauncherGUI.bannerEndsAt.setVisible(true);
541+
542+
// In any case, the timer needs to be visible
543+
LauncherGUI.bannerTimer.setVisible(true);
541544
} else {
542-
LauncherGUI.bannerEndsAt.setVisible(false);
545+
// Nothing to show here.
546+
LauncherGUI.bannerTimer.setVisible(false);
543547
}
544548
});
545549
refreshThread.start();

src/main/java/com/luuqui/launcher/LauncherGUI.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,21 @@ protected void paintComponent(Graphics g) {
358358
launcherVersion.setBounds(10, 493, 230, 15);
359359
sidePane.add(launcherVersion);
360360

361+
Icon timerIcon = IconFontSwing.buildIcon(FontAwesome.CLOCK_O, 16, Color.WHITE);
362+
bannerTimer = new JLabel("");
363+
bannerTimer.setIcon(timerIcon);
364+
bannerTimer.setBounds(40, 50, 225, 25);
365+
bannerTimer.setFont(Fonts.fontReg);
366+
bannerTimer.setForeground(Color.WHITE);
367+
bannerTimer.setHorizontalAlignment(SwingConstants.CENTER);
368+
bannerTimer.setVerticalAlignment(SwingConstants.CENTER);
369+
bannerTimer.putClientProperty(FlatClientProperties.STYLE,
370+
"background:" + ColorUtil.colorToHexString(CustomColors.INTERFACE_MAINPANE_BACKGROUND)
371+
+ "AA; foreground:" + ColorUtil.colorToHexString(Color.WHITE)
372+
+ "; arc:999;");
373+
bannerTimer.setVisible(false);
374+
mainPane.add(bannerTimer);
375+
361376
bannerTitle = new JLabel(Locale.getValue("m.banner_title_default"));
362377
bannerTitle.setBounds(35, -60, 700, 340);
363378
bannerTitle.setFont(Fonts.fontMedGiant);
@@ -376,21 +391,6 @@ protected void paintComponent(Graphics g) {
376391
bannerSubtitle2.setForeground(Color.WHITE);
377392
mainPane.add(bannerSubtitle2);
378393

379-
Icon endsAtIcon = IconFontSwing.buildIcon(FontAwesome.CLOCK_O, 16, Color.WHITE);
380-
bannerEndsAt = new JLabel("");
381-
bannerEndsAt.setIcon(endsAtIcon);
382-
bannerEndsAt.setBounds(40, 50, 225, 25);
383-
bannerEndsAt.setFont(Fonts.fontReg);
384-
bannerEndsAt.setForeground(Color.WHITE);
385-
bannerEndsAt.setHorizontalAlignment(SwingConstants.CENTER);
386-
bannerEndsAt.setVerticalAlignment(SwingConstants.CENTER);
387-
bannerEndsAt.putClientProperty(FlatClientProperties.STYLE,
388-
"background:" + ColorUtil.colorToHexString(CustomColors.INTERFACE_MAINPANE_BACKGROUND)
389-
+ "AA; foreground:" + ColorUtil.colorToHexString(Color.WHITE)
390-
+ "; arc:999;");
391-
bannerEndsAt.setVisible(false);
392-
mainPane.add(bannerEndsAt);
393-
394394
bannerLinkButton = new JButton(Locale.getValue("b.learn_more"));
395395
bannerLinkButton.setBounds(40, 195, 110, 25);
396396
bannerLinkButton.setFont(Fonts.fontMed);
@@ -727,10 +727,10 @@ protected static void specialKeyReleased() {
727727
// Main pane
728728
public static JPanel mainPane;
729729
public static BufferedImage banner = null;
730+
public static JLabel bannerTimer;
730731
public static JLabel bannerTitle;
731732
public static JLabel bannerSubtitle1;
732733
public static JLabel bannerSubtitle2;
733-
public static JLabel bannerEndsAt;
734734
public static JButton bannerLinkButton;
735735
public static JButton launchButton;
736736
public static JButton updateButton;

src/main/java/com/luuqui/util/DateUtil.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,54 @@
11
package com.luuqui.util;
22

3+
import com.luuqui.launcher.Locale;
4+
35
import java.text.DateFormat;
46
import java.text.SimpleDateFormat;
57
import java.util.Calendar;
68
import java.util.Date;
9+
import java.util.TimeZone;
10+
11+
import static com.luuqui.util.Log.log;
712

813
public class DateUtil {
914

15+
private static final String TIMEZONE = "PST"; // Game's timezone
16+
1017
public static String getDateAsString() {
1118
Date date = Calendar.getInstance().getTime();
1219
DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
1320
return dateFormat.format(date);
1421
}
1522

16-
public static String getDayNumberWithSuffix(int date) {
23+
public static String getFormattedRemaining(long timestamp) {
24+
long remainingMillis = timestamp - System.currentTimeMillis();
25+
long minutesRemaining = (remainingMillis / 1000L) / 60L;
26+
long hoursRemaining = minutesRemaining / 60L;
27+
long daysRemaining = hoursRemaining / 24L;
28+
29+
log.info("Remaining time", "remainingMillis", remainingMillis, "daysRemaining", daysRemaining, "hoursRemaining", hoursRemaining, "minutesRemaining", minutesRemaining);
30+
31+
if(daysRemaining > 0L) {
32+
return Locale.getValue("m.timer_days", String.valueOf(daysRemaining));
33+
} else if(hoursRemaining > 0L) {
34+
return Locale.getValue("m.timer_hours", String.valueOf(hoursRemaining));
35+
} else if(minutesRemaining > 0L) {
36+
return Locale.getValue("m.timer_minutes", String.valueOf(minutesRemaining));
37+
} else {
38+
return Locale.getValue("m.timer_less_than_minute");
39+
}
40+
}
41+
42+
public static String getFormattedMonthDay(long timestamp) {
43+
Calendar calendar = Calendar.getInstance();
44+
calendar.setTimeInMillis(timestamp);
45+
calendar.setTimeZone(TimeZone.getTimeZone(TIMEZONE));
46+
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM"); // Only the month, we'll concatenate the day later.
47+
48+
return dateFormat.format(calendar.getTime()) + " " + DateUtil.getDayNumberWithSuffix(calendar.get(Calendar.DATE) - 1);
49+
}
50+
51+
private static String getDayNumberWithSuffix(int date) {
1752
String suffix = "th";
1853
switch (date) {
1954
case 1:

0 commit comments

Comments
 (0)