2424package com .fox2code .hypertale .dashboard ;
2525
2626import com .fox2code .hypertale .launcher .BuildConfig ;
27+ import com .fox2code .hypertale .loader .HypertaleConfig ;
28+ import com .fox2code .hypertale .loader .HypertaleIcons ;
2729import com .fox2code .hypertale .utils .HypertaleTextUtil ;
2830import com .fox2code .hypertale .utils .HypertaleUptimeManager ;
2931import com .fox2code .hypertale .utils .HypertaleUptimeReceiver ;
@@ -79,13 +81,14 @@ public void build(@NonNull Ref<EntityStore> ref, @NonNull UICommandBuilder comma
7981 commandBuilder .set ("#Description.Text" , "Hypertale " + BuildConfig .HYPERTALE_VERSION + "\n " +
8082 "Running Hytale " + HytaleVersion .HYTALE_VERSION );
8183 long uptime = Instant .now ().getEpochSecond () - HytaleServer .get ().getBoot ().getEpochSecond ();
82- buildUpdate (commandBuilder , uptime , HypertaleTextUtil .makeUptimeString (uptime ));
84+ buildUpdate (commandBuilder , uptime , HypertaleTextUtil .makeUptimeString (uptime ), true );
8385 HypertaleUptimeManager .addUptimeListener (this );
8486 eventBuilder .addEventBinding (CustomUIEventBindingType .Activating ,
8587 "#CloseButton" , new EventData ());
8688 }
8789
88- public static void buildUpdate (@ NonNull UICommandBuilder commandBuilder , long uptime , @ NonNull String uptimeText ) {
90+ public static void buildUpdate (@ NonNull UICommandBuilder commandBuilder , long uptime ,
91+ @ NonNull String uptimeText , boolean building ) {
8992 commandBuilder .set ("#StatPlayers.Text" , String .valueOf (Universe .get ().getPlayerCount ()));
9093 commandBuilder .set ("#StatUptime.Text" , uptimeText );
9194 commandBuilder .set ("#StatUptime.Style" , uptime >= TIME_48_HOURS ? labelSevere :
@@ -108,6 +111,53 @@ public static void buildUpdate(@NonNull UICommandBuilder commandBuilder, long up
108111 (ramUsagePercent > 95.0D || freeMemory < MEM_128MB ) ? labelSevere :
109112 (ramUsagePercent > 90.0 || freeMemory < MEM_512MB ) ? labelSerious :
110113 (ramUsagePercent > 80.0 || freeMemory < MEM_1536MB ) ? labelWarn : labelFine );
114+ if (building ) {
115+ if (HypertaleConfig .disableFox2CodeIcons ) {
116+ commandBuilder .set ("#Fox2CodeIndicator.Visible" , false );
117+ return ;
118+ }
119+ if (uptime < TIME_1_MINUTE ) {
120+ commandBuilder .set ("#Fox2CodeIndicator.Background" , HypertaleIcons .FOX2WOW_ICON );
121+ return ;
122+ }
123+ // For the warning level icon, the level are calculated slightly differently.
124+ int [] condition = new int [4 ]; // {warn, serious, severe, verySevere}
125+ addCond (condition , uptime >= TIME_48_HOURS ? 2 :
126+ uptime >= TIME_24_HOURS ? 1 : 0 );
127+ addCond (condition , cpuLoad >= 0.95D ? 4 : cpuLoad >= 0.9D ? 3 :
128+ cpuLoad >= 0.75D ? 2 : cpuLoad >= 0.5D ? 1 : 0 );
129+ addCond (condition , (ramUsagePercent > 95.0D || freeMemory < MEM_128MB ) ? 4 :
130+ (ramUsagePercent > 90.0 || freeMemory < MEM_512MB ) ? 3 :
131+ (ramUsagePercent > 80.0 || freeMemory < MEM_1536MB ) ? 1 : 0 );
132+ int warningLevel = condition .length - 1 ;
133+ while (warningLevel -->0 ) {
134+ if (condition [warningLevel ] > 2 || condition [warningLevel + 1 ] != 0 ) {
135+ break ;
136+ }
137+ }
138+ warningLevel ++;
139+ if (warningLevel == 0 && condition [0 ] != 0 ) {
140+ // The heart icon is only for when everything is fine!
141+ warningLevel = 1 ;
142+ }
143+ commandBuilder .set ("#Fox2CodeIndicator.Background" , switch (warningLevel ) {
144+ case 3 -> HypertaleIcons .FOX2XX_ICON ;
145+ case 2 -> HypertaleIcons .FOX2PANIC_ICON ;
146+ case 1 -> HypertaleIcons .FOX2PRR2_ICON ;
147+ case 0 -> HypertaleIcons .FOX2HEART2_ICON ;
148+ default -> HypertaleIcons .FOX2WOW_ICON ;
149+ });
150+ }
151+ }
152+
153+ private static void addCond (int [] condition , int conditionType ) {
154+ switch (conditionType ) {
155+ case 4 : condition [3 ]++; // fall through
156+ case 3 : condition [2 ]++; // fall through
157+ case 2 : condition [1 ]++; // fall through
158+ case 1 : condition [0 ]++; // fall through
159+ case 0 : break ;
160+ }
111161 }
112162
113163 @ Override
@@ -119,7 +169,7 @@ public void handleDataEvent(@NonNull Ref<EntityStore> ref, @NonNull Store<Entity
119169 @ Override
120170 public void onReceiveUptime (long uptime , String uptimeText ) {
121171 UICommandBuilder commandBuilder = new UICommandBuilder ();
122- buildUpdate (commandBuilder , uptime , uptimeText );
172+ buildUpdate (commandBuilder , uptime , uptimeText , false );
123173 // This works exactly like sendUpdate except it supports async calling
124174 this .cachedPageManager .updateCustomPage (new CustomPage (
125175 this .getClass ().getName (), false , false ,
0 commit comments