11package mekanism .client .gui ;
22
33import java .util .ArrayList ;
4+ import java .util .Collections ;
45import java .util .List ;
56import mekanism .api .text .EnumColor ;
67import mekanism .client .gui .element .GuiUpArrow ;
78import mekanism .client .gui .element .bar .GuiVerticalPowerBar ;
89import mekanism .client .gui .element .button .BasicColorButton ;
10+ import mekanism .client .gui .element .button .TooltipColorButton ;
911import mekanism .client .gui .element .tab .GuiEnergyTab ;
1012import mekanism .client .gui .element .tab .GuiVisualsTab ;
1113import mekanism .common .MekanismLang ;
1820import mekanism .common .tile .machine .TileEntityDimensionalStabilizer ;
1921import mekanism .common .util .text .BooleanStateDisplay .OnOff ;
2022import net .minecraft .client .gui .GuiGraphics ;
23+ import net .minecraft .client .gui .components .Tooltip ;
2124import net .minecraft .core .SectionPos ;
2225import net .minecraft .network .chat .Component ;
2326import net .minecraft .world .entity .player .Inventory ;
2427import org .jetbrains .annotations .NotNull ;
28+ import org .jetbrains .annotations .Nullable ;
2529
2630public class GuiDimensionalStabilizer extends GuiMekanismTile <TileEntityDimensionalStabilizer , MekanismTileContainer <TileEntityDimensionalStabilizer >> {
2731
@@ -50,7 +54,7 @@ protected void addGuiElements() {
5054 int shiftedZ = z + TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ;
5155 int chunkZ = tileChunkZ + z ;
5256 if (x == 0 && z == 0 ) {
53- addRenderableWidget (BasicColorButton . renderActive (this , 63 + 10 * shiftedX , 19 + 10 * shiftedZ , 10 , EnumColor .DARK_BLUE , (element , mouseX , mouseY ) -> {
57+ addRenderableWidget (new BasicColorButton (this , 63 + 10 * shiftedX , 19 + 10 * shiftedZ , 10 , () -> EnumColor .DARK_BLUE , (element , mouseX , mouseY ) -> {
5458 for (int i = 1 ; i <= TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ; i ++) {
5559 if (hasAtRadius (i , false )) {
5660 return PacketUtils .sendToServer (new PacketGuiInteract (GuiInteraction .ENABLE_RADIUS_CHUNKLOAD , tile , i ));
@@ -64,39 +68,49 @@ protected void addGuiElements() {
6468 }
6569 }
6670 return false ;
67- }, (onHover , guiGraphics , mouseX , mouseY ) -> {
68- List <Component > tooltips = new ArrayList <>();
69- tooltips .add (MekanismLang .STABILIZER_CENTER .translate (EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
70- //TODO: Can we eventually optimize this further such as if we know that we have 1 enabled as we are enabling either radius 2 or "3" (nothing)
71- // then even if nothing is enabled at radius 2 currently, we don't have to check radius 1 to know that we should display the text for disabling it
72- // for now it doesn't really matter as given we only support a radius of two it only checks at most the inner radius (8 extra boolean lookups)
73- for (int i = 1 ; i <= TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ; i ++) {
74- if (hasAtRadius (i , false )) {
75- //Add an empty line for readability. Must be done by adding a string that just renders a space
76- tooltips .add (Component .literal (" " ));
77- tooltips .add (MekanismLang .STABILIZER_ENABLE_RADIUS .translate (EnumColor .INDIGO , i , EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
78- break ;
71+ }) {
72+ private List <Component > lastInfo = Collections .emptyList ();
73+ @ Nullable
74+ private Tooltip lastTooltip ;
75+
76+ @ Override
77+ public void updateTooltip (int mouseX , int mouseY ) {
78+ List <Component > tooltips = new ArrayList <>();
79+ tooltips .add (MekanismLang .STABILIZER_CENTER .translate (EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
80+ //TODO: Can we eventually optimize this further such as if we know that we have 1 enabled as we are enabling either radius 2 or "3" (nothing)
81+ // then even if nothing is enabled at radius 2 currently, we don't have to check radius 1 to know that we should display the text for disabling it
82+ // for now it doesn't really matter as given we only support a radius of two it only checks at most the inner radius (8 extra boolean lookups)
83+ for (int i = 1 ; i <= TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ; i ++) {
84+ if (hasAtRadius (i , false )) {
85+ //Add an empty line for readability. Must be done by adding a string that just renders a space
86+ tooltips .add (Component .literal (" " ));
87+ tooltips .add (MekanismLang .STABILIZER_ENABLE_RADIUS .translate (EnumColor .INDIGO , i , EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
88+ break ;
89+ }
7990 }
80- }
81- for (int i = TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ; i > 0 ; i --) {
82- if (hasAtRadius (i , true )) {
83- //Add an empty line for readability. Must be done by adding a string that just renders a space
84- tooltips .add (Component .literal (" " ));
85- tooltips .add (MekanismLang .STABILIZER_DISABLE_RADIUS .translate (EnumColor .INDIGO , i , EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
86- break ;
91+ for (int i = TileEntityDimensionalStabilizer .MAX_LOAD_RADIUS ; i > 0 ; i --) {
92+ if (hasAtRadius (i , true )) {
93+ //Add an empty line for readability. Must be done by adding a string that just renders a space
94+ tooltips .add (Component .literal (" " ));
95+ tooltips .add (MekanismLang .STABILIZER_DISABLE_RADIUS .translate (EnumColor .INDIGO , i , EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ));
96+ break ;
97+ }
98+ }
99+ if (!tooltips .equals (lastInfo )) {
100+ lastInfo = tooltips ;
101+ lastTooltip = MultiLineTooltip .createMulti (tooltips );
87102 }
103+ setTooltip (lastTooltip );
88104 }
89- onHover .displayTooltips (guiGraphics , mouseX , mouseY , tooltips );
90- }));
105+ });
91106 } else {
92107 int packetTarget = shiftedX * TileEntityDimensionalStabilizer .MAX_LOAD_DIAMETER + shiftedZ ;
93- addRenderableWidget (BasicColorButton . toggle (this , 63 + 10 * shiftedX , 19 + 10 * shiftedZ , 10 , EnumColor .DARK_BLUE ,
108+ addRenderableWidget (new TooltipColorButton (this , 63 + 10 * shiftedX , 19 + 10 * shiftedZ , 10 , EnumColor .DARK_BLUE ,
94109 () -> tile .isChunkLoadingAt (shiftedX , shiftedZ ),
95110 (element , mouseX , mouseY ) -> PacketUtils .sendToServer (new PacketGuiInteract (GuiInteraction .TOGGLE_CHUNKLOAD , tile , packetTarget )),
96- (element , graphics , mouseX , mouseY ) -> element .displayTooltips (graphics , mouseX , mouseY ,
97- MekanismLang .STABILIZER_TOGGLE_LOADING .translate (OnOff .of (tile .isChunkLoadingAt (shiftedX , shiftedZ ), true ),
98- EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ )
99- )));
111+ MekanismLang .STABILIZER_TOGGLE_LOADING .translate (OnOff .of (true , true ), EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ ),
112+ MekanismLang .STABILIZER_TOGGLE_LOADING .translate (OnOff .of (false , true ), EnumColor .INDIGO , chunkX , EnumColor .INDIGO , chunkZ )
113+ ));
100114 }
101115 }
102116 }
0 commit comments