1
1
package dynamic_fps .impl .feature .battery ;
2
2
3
- import dynamic_fps .impl .util .ResourceLocations ;
4
3
import net .minecraft .client .Minecraft ;
5
- import net .minecraft .client .gui .Font ;
6
- import net .minecraft .client .gui .GuiGraphics ;
7
- import net .minecraft .client .gui .components .toasts .Toast ;
8
- import net .minecraft .client .gui .components .toasts .ToastManager ;
9
- import net .minecraft .client .renderer .RenderType ;
10
4
import net .minecraft .network .chat .Component ;
11
5
import net .minecraft .resources .ResourceLocation ;
12
- import org .jetbrains .annotations .NotNull ;
13
6
14
7
import static dynamic_fps .impl .util .Localization .localized ;
15
8
16
- public class BatteryToast implements Toast {
17
- private long firstRender ;
18
-
19
- private Component title ;
20
- private Component description ;
21
- private ResourceLocation icon ;
22
- private Visibility visibility ;
23
-
9
+ public class BatteryToast extends BaseToast {
24
10
private static BatteryToast queuedToast ;
25
11
26
- private static final ResourceLocation MOD_ICON = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background_icon.png" );
27
- private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background.png" );
28
-
29
12
private BatteryToast (Component title , ResourceLocation icon ) {
30
- this .title = title ;
31
- this .icon = icon ;
32
- this .visibility = Visibility .SHOW ;
13
+ super (title , Component .empty (), icon );
33
14
}
34
15
35
16
/**
@@ -47,39 +28,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
47
28
}
48
29
49
30
@ Override
50
- public @ NotNull Visibility getWantedVisibility () {
51
- return this .visibility ;
52
- }
53
-
54
- @ Override
55
- public void update (ToastManager toastManager , long currentTime ) {
56
- if (this .firstRender == 0 ) {
57
- return ;
58
- }
59
-
60
- if (currentTime - this .firstRender >= 5000.0 * toastManager .getNotificationDisplayTimeMultiplier ()) {
61
- this .visibility = Visibility .HIDE ;
62
- }
63
- }
64
-
65
- @ Override
66
- public void render (GuiGraphics graphics , Font font , long currentTime ) {
67
- if (this .firstRender == 0 ) {
68
- if (this == queuedToast ) {
69
- queuedToast = null ;
70
- }
71
-
72
- this .firstRender = currentTime ;
73
- // Initialize when first rendering so the battery percentage is mostly up-to-date
74
- this .description = localized ("toast" , "battery_charge" , BatteryTracker .charge ());
31
+ public void onFirstRender () {
32
+ if (this == queuedToast ) {
33
+ queuedToast = null ;
75
34
}
76
- // resource, x, y, z, ?, ?, width, height, width, height
77
- graphics .blit (RenderType ::guiTextured , BACKGROUND_IMAGE , 0 , 0 , 0.0f , 0 , this .width (), this .height (), this .width (), this .height ());
78
-
79
- graphics .blit (RenderType ::guiTextured , MOD_ICON , 2 , 2 , 0.0f , 0 , 8 , 8 , 8 , 8 );
80
- graphics .blit (RenderType ::guiTextured , this .icon , 8 , 8 , 0.0f , 0 , 16 , 16 , 16 , 16 );
81
35
82
- graphics . drawString ( Minecraft . getInstance (). font , this . title , 30 , 7 , 0x5f3315 , false );
83
- graphics . drawString ( Minecraft . getInstance (). font , this .description , 30 , 18 , - 16777216 , false );
36
+ // Initialize when first rendering so the battery percentage is mostly up-to-date
37
+ this .description = localized ( "toast" , "battery_charge" , BatteryTracker . charge () );
84
38
}
85
39
}
0 commit comments