11package com .tanishisherewith .dynamichud .utils .contextmenu .skinsystem ;
22
3+ import com .mojang .blaze3d .platform .cursor .CursorTypes ;
34import com .tanishisherewith .dynamichud .DynamicHUD ;
45import com .tanishisherewith .dynamichud .helpers .DrawHelper ;
56import com .tanishisherewith .dynamichud .helpers .animationhelper .EasingType ;
@@ -222,6 +223,10 @@ private int getGroupPanelX() {
222223 return imageX - groupPanelWidth - 15 ;
223224 }
224225
226+ public void playClickSound () {
227+ mc .getSoundManager ().play (SimpleSoundInstance .forUI (SoundEvents .UI_BUTTON_CLICK , 1.0F ));
228+ }
229+
225230 private void renderSearchBox (GuiGraphicsExtractor graphics , int mouseX , int mouseY ) {
226231 searchBox .setX (searchBoxX );
227232 searchBox .setY (searchBoxY );
@@ -252,8 +257,13 @@ private void renderSearchBox(GuiGraphicsExtractor graphics, int mouseX, int mous
252257 }
253258
254259 public void drawSingularButton (GuiGraphicsExtractor graphics , String Component , int mouseX , int mouseY , int x , int y , int width , int height , boolean enabled ) {
255- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (enabled , isMouseOver (mouseX , mouseY , x , y , width , height )), x , y , width , height );
260+ boolean isMouseOverButton = isMouseOver (mouseX , mouseY , x , y , width , height );
261+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (enabled , isMouseOverButton ), x , y , width , height );
256262 graphics .text (mc .font , Component , x + width / 2 - mc .font .width (Component ) / 2 , y + mc .font .lineHeight / 2 - 1 , Color .WHITE .getRGB (), true );
263+
264+ if (isMouseOverButton ) {
265+ graphics .requestCursor (CursorTypes .POINTING_HAND );
266+ }
257267 }
258268
259269 public void drawSingularButton (GuiGraphicsExtractor graphics , String Component , int mouseX , int mouseY , int x , int y , int width , int height ) {
@@ -273,7 +283,9 @@ private void renderOptionGroups(GuiGraphicsExtractor graphics, int mouseX, int m
273283
274284 DrawHelper .drawScrollableText (graphics , mc .font , group .getName (), groupX + groupPanelWidth / 2 , groupX + 2 , yOffset , groupX + groupPanelWidth - 2 , yOffset + 20 , -1 );
275285
276- //Scrollable Component uses scissor, so we need to enable the context menu scissor again
286+ renderTooltipIfHovered (graphics , group , groupX , yOffset , groupPanelWidth ,20 , mouseX , mouseY , groupPanelWidth ,2200L );
287+
288+ //Scrollable text uses scissor, so we need to enable the context menu scissor again
277289 this .enableContextMenuScissor (graphics );
278290
279291 yOffset += 20 ; // Space for the header
@@ -304,7 +316,7 @@ private int renderSelectedGroupOptions(GuiGraphicsExtractor graphics, int mouseX
304316 if (option .getY () >= imageY - option .getHeight () && option .getY () <= imageY + option .getHeight () + panelHeight ) {
305317 option .render (graphics , option .getX (), option .getY (), mouseX , mouseY );
306318
307- renderTooltipIfHovered (graphics , option , option .getX (), option .getY (), mouseX , mouseY , targetWidth );
319+ renderTooltipIfHovered (graphics , option , imageX + 4 , option .getY (), targetWidth - option .getWidth (), option . getHeight (), mouseX , mouseY , targetWidth );
308320 }
309321 }
310322 return yOffset ;
@@ -366,23 +378,19 @@ public boolean mouseClicked(ContextMenu<?> menu, double mouseX, double mouseY, i
366378 }
367379 }
368380 if (isMouseOver (mouseX , mouseY , imageX + 3 , imageY + 3 , 14 , 14 )) {
369- mc .getSoundManager ().play (SimpleSoundInstance .forUI (
370- SoundEvents .UI_BUTTON_CLICK , 1.0F ));
371-
381+ playClickSound ();
372382 contextMenu .close ();
373383 scrollHandler .stopDragging ();
374384 return true ;
375385 }
376386 int size = (int ) (groupPanelWidth * 0.5f );
377387 //Up and down button
378388 if (groupScrollHandler .isOffsetWithinBounds (-10 ) && isMouseOver (mouseX , mouseY , getGroupPanelX () + groupPanelWidth / 2.0 - size / 2.0 , imageY - 14 , size , 14 )) {
379- mc .getSoundManager ().play (SimpleSoundInstance .forUI (
380- SoundEvents .UI_BUTTON_CLICK , 1.0F ));
389+ playClickSound ();
381390 groupScrollHandler .addOffset (-10 );
382391 }
383392 if (groupScrollHandler .isOffsetWithinBounds (10 ) && isMouseOver (mouseX , mouseY , getGroupPanelX () + groupPanelWidth / 2.0 - size / 2.0 , imageY + panelHeight + 2 , size , 14 )) {
384- mc .getSoundManager ().play (SimpleSoundInstance .forUI (
385- SoundEvents .UI_BUTTON_CLICK , 1.0F ));
393+ playClickSound ();
386394 groupScrollHandler .addOffset (10 );
387395 }
388396
@@ -540,11 +548,24 @@ public void render(GuiGraphicsExtractor graphics, BooleanOption option, int x, i
540548 int width = 50 ;
541549 option .setPosition (x + panelWidth - 75 , y );
542550 option .setWidth (width );
543- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOver (mouseX , mouseY ,x + panelWidth - 75 , y , width , 20 )), x + panelWidth - 75 , y , width , 20 );
551+ boolean isMouseOverButton = isMouseOver (mouseX , mouseY ,x + panelWidth - 75 , y , width , 20 );
552+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOverButton ), x + panelWidth - 75 , y , width , 20 );
544553
545554 Component text = option .getBooleanType ().getText (option .get ());
546555 int color = option .get () ? Color .GREEN .getRGB () : Color .RED .getRGB ();
547556 graphics .text (mc .font , text , (int ) (x + panelWidth - 75 + (width / 2.0f ) - (mc .font .width (text ) / 2.0f )), y + 5 , color , true );
557+
558+ if (isMouseOverButton ) {
559+ graphics .requestCursor (CursorTypes .POINTING_HAND );
560+ }
561+ }
562+ @ Override
563+ public boolean mouseClicked (BooleanOption option , double mouseX , double mouseY , int button ) {
564+ if (option .mouseClicked (mouseX ,mouseY ,button )) {
565+ playClickSound ();
566+ return true ;
567+ }
568+ return false ;
548569 }
549570 }
550571
@@ -576,7 +597,8 @@ public void render(GuiGraphicsExtractor graphics, ColorOption option, int x, int
576597 graphics .text (mc .font , displayName , x + 15 , y + 25 / 2 - 5 , -1 , true );
577598
578599 int width = 20 ;
579- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (!option .isVisible , isMouseOver (mouseX , mouseY ,x + panelWidth - 45 , y , width , 20 )), x + panelWidth - 45 , y , width , 20 );
600+ boolean isMouseOverButton = isMouseOver (mouseX , mouseY ,x + panelWidth - 45 , y , width , 20 );
601+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (!option .isVisible , isMouseOverButton ), x + panelWidth - 45 , y , width , 20 );
580602
581603 int shadowOpacity = Math .min (option .get ().getAlpha (), 45 );
582604 DrawHelper .drawRectangleWithShadowBadWay (graphics ,
@@ -616,12 +638,15 @@ public void render(GuiGraphicsExtractor graphics, ColorOption option, int x, int
616638 if (option .getColorGradient ().getColorPickerButton ().isPicking ()) {
617639 // DrawHelper.enableScissor(imageX, imageY + 2, panelWidth, panelHeight - 4, graphics);
618640 }
641+ if (isMouseOverButton ) {
642+ graphics .requestCursor (CursorTypes .POINTING_HAND );
643+ }
619644 }
620-
621645 @ Override
622646 public boolean mouseClicked (ColorOption option , double mouseX , double mouseY , int button ) {
623647 if (button == GLFW .GLFW_MOUSE_BUTTON_LEFT && isMouseOver (mouseX , mouseY , option .getX () + panelWidth - 45 , option .getY (), 20 , 20 )) {
624648 boolean isOpening = !option .getColorGradient ().shouldDisplay ();
649+ playClickSound ();
625650 scaleAnimation .startValue (scale );
626651 if (isOpening ) {
627652 option .getColorGradient ().display ();
@@ -674,15 +699,30 @@ public void render(GuiGraphicsExtractor graphics, DoubleOption option, int x, in
674699
675700 double sliderX = option .getX () + ((option .get () - option .minValue ) / (option .maxValue - option .minValue )) * (option .getWidth () - 8 );
676701 boolean isMouseOverHandle = isMouseOver (mouseX , mouseY , sliderX , y , 10 , 20 );
702+ boolean isMouseOverSlider = option .isMouseOver (mouseX , mouseY );
677703
678- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , option . isMouseOver ( mouseX , mouseY ) ? HIGHLIGHTED_TEXTURE : TEXTURE , option .getX (), y , option .getWidth (), 20 );
704+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , isMouseOverSlider ? HIGHLIGHTED_TEXTURE : TEXTURE , option .getX (), y , option .getWidth (), 20 );
679705 graphics .blitSprite (RenderPipelines .GUI_TEXTURED , isMouseOverHandle ? HANDLE_HIGHLIGHTED_TEXTURE : HANDLE_TEXTURE , (int ) Math .round (sliderX ), y , 8 , 20 );
680706
681707 int decimalPlaces = String .valueOf (option .step ).split ("\\ ." )[1 ].length ();
682708
683709 // Format option.get() to the determined number of decimal places
684710 String formattedValue = String .format ("%." + decimalPlaces + "f" , option .get ());
685711 graphics .centeredText (mc .font , formattedValue , option .getX () + option .getWidth () / 2 , y + Math .round ((float ) mc .font .lineHeight /2 ), -1 );
712+
713+ if (isMouseOverHandle && option .isDragging ()) {
714+ graphics .requestCursor (CursorTypes .RESIZE_EW );
715+ } else if (isMouseOverSlider ) {
716+ graphics .requestCursor (CursorTypes .POINTING_HAND );
717+ }
718+ }
719+ @ Override
720+ public boolean mouseReleased (DoubleOption option , double mouseX , double mouseY , int button ) {
721+ if (option .mouseReleased (mouseX ,mouseY ,button )) {
722+ playClickSound ();
723+ return true ;
724+ }
725+ return false ;
686726 }
687727 }
688728
@@ -707,9 +747,23 @@ public void render(GuiGraphicsExtractor graphics, CycleOption<E> option, int x,
707747
708748 option .setPosition (x + panelWidth - maxWidth - 25 , y );
709749
710- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , option .isMouseOver (mouseX , mouseY )), option .getX (), y , maxWidth , 20 );
750+ boolean isMouseOverButton = option .isMouseOver (mouseX , mouseY );
751+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOverButton ), option .getX (), y , maxWidth , 20 );
711752 String text = option .get ().toString ();
712753 graphics .text (mc .font , text , option .getX () + maxWidth / 2 - mc .font .width (text ) / 2 , y + 5 , Color .CYAN .getRGB (), true );
754+
755+ if (isMouseOverButton ) {
756+ graphics .requestCursor (CursorTypes .POINTING_HAND );
757+ }
758+ }
759+
760+ @ Override
761+ public boolean mouseClicked (CycleOption option , double mouseX , double mouseY , int button ) {
762+ if (option .mouseClicked (mouseX ,mouseY ,button )) {
763+ playClickSound ();
764+ return true ;
765+ }
766+ return false ;
713767 }
714768 }
715769
@@ -725,11 +779,24 @@ public void render(GuiGraphicsExtractor graphics, SubMenuOption option, int x, i
725779
726780 option .setPosition (x + panelWidth - 55 , y );
727781
728- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , option .isMouseOver (mouseX , mouseY )), option .getX (), y , option .getWidth (), 20 );
782+ boolean isMouseOverButton = option .isMouseOver (mouseX , mouseY );
783+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOverButton ), option .getX (), y , option .getWidth (), 20 );
729784 String text = "Open" ;
730785 graphics .text (mc .font , text , option .getX () + option .getWidth () / 2 - mc .font .width (text ) / 2 , y + 5 , Color .YELLOW .getRGB (), true );
731786
732787 option .getSubMenu ().render (graphics , x + option .getParentMenu ().getWidth (), y , mouseX , mouseY );
788+ if (isMouseOverButton ) {
789+ graphics .requestCursor (CursorTypes .POINTING_HAND );
790+ }
791+ }
792+
793+ @ Override
794+ public boolean mouseClicked (SubMenuOption option , double mouseX , double mouseY , int button ) {
795+ if (option .mouseClicked (mouseX ,mouseY ,button )) {
796+ playClickSound ();
797+ return true ;
798+ }
799+ return false ;
733800 }
734801 }
735802
@@ -746,8 +813,22 @@ public void render(GuiGraphicsExtractor graphics, RunnableOption option, int x,
746813
747814 option .setPosition (x + panelWidth - 51 , y );
748815
749- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (!option .get (), option .isMouseOver (mouseX , mouseY )), option .getX (), y , option .getWidth (), 20 );
816+ boolean isMouseOverButton = option .isMouseOver (mouseX , mouseY );
817+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (!option .get (), isMouseOverButton ), option .getX (), y , option .getWidth (), 20 );
750818 graphics .text (mc .font , "Run" , option .getX () + option .getWidth () / 2 - mc .font .width ("Run" ) / 2 , y + 5 , option .get () ? DARK_GREEN .getRGB () : DARK_RED .getRGB (), true );
819+ if (isMouseOverButton ) {
820+ graphics .requestCursor (CursorTypes .POINTING_HAND );
821+ }
822+ }
823+
824+
825+ @ Override
826+ public boolean mouseClicked (RunnableOption option , double mouseX , double mouseY , int button ) {
827+ if (option .mouseClicked (mouseX ,mouseY ,button )) {
828+ playClickSound ();
829+ return true ;
830+ }
831+ return false ;
751832 }
752833 }
753834
@@ -764,18 +845,24 @@ public void render(GuiGraphicsExtractor graphics, KeybindOption option, int x, i
764845 option .setPosition (buttonX , y );
765846 option .setWidth (width );
766847
767- graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOver (mouseX , mouseY , buttonX , y , width , 20 )), buttonX , y , width , 20 );
848+ boolean isMouseOverButton = isMouseOver (mouseX , mouseY , buttonX , y , width , 20 );
849+ graphics .blitSprite (RenderPipelines .GUI_TEXTURED , TEXTURES .get (true , isMouseOverButton ), buttonX , y , width , 20 );
768850
769851 String text = option .isListening () ? "> ??? <" : KeybindOption .getKeyName (option .get ());
770852 int color = option .isListening () ? Color .YELLOW .getRGB () : Color .WHITE .getRGB ();
771853 graphics .text (mc .font , text , (int ) (buttonX + (width / 2.0f ) - (mc .font .width (text ) / 2.0f )), y + 6 , color , true );
854+
855+ if (isMouseOverButton ) {
856+ graphics .requestCursor (CursorTypes .POINTING_HAND );
857+ }
772858 }
773859
774860 @ Override
775861 public boolean mouseClicked (KeybindOption option , double mouseX , double mouseY , int button ) {
776862 int width = 70 ;
777863 int buttonX = option .getX ();
778864 if (isMouseOver (mouseX , mouseY , buttonX , option .getY (), width , 20 )) {
865+ playClickSound ();
779866 option .setListening (true );
780867 return true ;
781868 }
0 commit comments