11package simpleclient .gui ;
22
3+ import com .mojang .blaze3d .systems .RenderSystem ;
34import com .mojang .blaze3d .vertex .PoseStack ;
5+ import com .mojang .math .Axis ;
6+ import net .minecraft .client .gui .Gui ;
7+ import net .minecraft .client .gui .GuiComponent ;
48import net .minecraft .client .gui .screens .Screen ;
9+ import net .minecraft .client .renderer .GameRenderer ;
510import net .minecraft .network .chat .Component ;
11+ import net .minecraft .resources .ResourceLocation ;
12+ import org .joml .AxisAngle4d ;
13+ import org .joml .AxisAngle4f ;
14+ import org .joml .Quaternionf ;
615import simpleclient .adapter .ItemRendererAdapter ;
716import simpleclient .adapter .ItemRendererAdapterImpl ;
817import simpleclient .adapter .TextRendererAdapter ;
918import simpleclient .adapter .TextRendererAdapterImpl ;
1019import simpleclient .feature .*;
1120import simpleclient .text .Text ;
1221
22+ import java .io .IOException ;
1323import java .util .List ;
1424
1525public class EditFeaturesScreen extends Screen {
@@ -26,7 +36,7 @@ public EditFeaturesScreen() {
2636 public void render (PoseStack poseStack , int mouseX , int mouseY , float delta ) {
2737 TextRendererAdapter textRenderer = new TextRendererAdapterImpl (poseStack , font );
2838 ItemRendererAdapter itemRenderer = new ItemRendererAdapterImpl (poseStack );
29- // Render Features
39+ // Render Renderable Features
3040 for (Feature feature : FeatureManager .INSTANCE .getFeatures ()) {
3141 if (feature instanceof RenderableFeature rf && rf .isEnabled ()) {
3242 rf .renderDummy (textRenderer , itemRenderer , width , height );
@@ -35,32 +45,54 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) {
3545 int y1 = df .getYPos (height ) - 1 ;
3646 int x2 = df .getXPos (width ) + df .getWidth (textRenderer , itemRenderer , width , height ) + 1 ;
3747 int y2 = df .getYPos (height ) + df .getHeight (textRenderer , itemRenderer , width , height ) + 1 ;
38- fill (poseStack , x1 - 1 , y1 - 1 , x2 + 1 , y1 , 0xFFAAAAAA );
39- fill (poseStack , x1 - 1 , y2 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
40- fill (poseStack , x1 - 1 , y1 - 1 , x1 , y2 + 1 , 0xFFAAAAAA );
41- fill (poseStack , x2 , y1 - 1 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
48+ GuiComponent . fill (poseStack , x1 - 1 , y1 - 1 , x2 + 1 , y1 , 0xFFAAAAAA );
49+ GuiComponent . fill (poseStack , x1 - 1 , y2 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
50+ GuiComponent . fill (poseStack , x1 - 1 , y1 - 1 , x1 , y2 + 1 , 0xFFAAAAAA );
51+ GuiComponent . fill (poseStack , x2 , y1 - 1 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
4252 }
4353 }
4454 }
45- // Render Buttons
46- fill (poseStack , 0 , 0 , width / 4 , height , 0x77000000 );
47- List <EnableableFeature > enableableFeatures = FeatureManager .INSTANCE .getEnableableFeatures ();
48- for (int i = 0 ; i < enableableFeatures .size (); i ++) {
49- EnableableFeature feature = enableableFeatures .get (i );
50- int x = i % 3 ;
51- int y = i / 3 ;
52- int wSize = (width / 4 - 8 ) / 3 ;
55+ // Render Enableable Features
56+ GuiComponent .fill (poseStack , 0 , 0 , width / 4 , height , 0x77000000 );
57+ List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
58+ for (int i = 0 ; i < features .size (); i ++) {
59+ Feature feature = features .get (i );
60+ int count = (int ) Math .ceil ((double ) width / 4 / 100 );
61+ int x = i % count ;
62+ int y = i / count ;
63+ int wSize = (width / 4 - 2 - count * 2 ) / count ;
5364 int wX1 = 2 + (2 + wSize ) * x ;
5465 int wY1 = 2 + 2 + (2 + wSize ) * y ;
5566 int wX2 = (2 + wSize ) * x + wSize ;
5667 int wY2 = 2 + (2 + wSize ) * y + wSize ;
57- fill (poseStack , wX1 , scroll + wY1 , wX2 , scroll + wY2 , 0xff555555 );
58- fill (poseStack , wX1 + wSize / 10 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 , wX1 + wSize / 10 + wSize / 3 , scroll + wY2 - wSize / 10 , feature .isEnabled () ? 0xff00ff00 : 0xffff0000 );
59- if (feature .isEnabled ()) {
60- fill (poseStack , wX1 + wSize / 10 + wSize / 3 / 2 + wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 + wSize / 20 , wX1 + wSize / 10 + wSize / 3 - wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 20 , 0xff000000 );
61- } else {
62- fill (poseStack , wX1 + wSize / 10 + wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 + wSize / 20 , wX1 + wSize / 10 + wSize / 3 / 2 - wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 20 , 0xff000000 );
68+ // Background
69+ GuiComponent .fill (poseStack , wX1 , scroll + wY1 , wX2 , scroll + wY2 , 0xff555555 );
70+ // Enable Button
71+ if (feature instanceof EnableableFeature ef ) {
72+ GuiComponent .fill (poseStack , wX1 + wSize / 10 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 , wX1 + wSize / 10 + wSize / 3 , scroll + wY2 - wSize / 10 , ef .isEnabled () ? 0xff00ff00 : 0xffff0000 );
73+ if (ef .isEnabled ()) {
74+ GuiComponent .fill (poseStack , wX1 + wSize / 10 + wSize / 3 / 2 + wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 + wSize / 20 , wX1 + wSize / 10 + wSize / 3 - wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 20 , 0xff000000 );
75+ } else {
76+ GuiComponent .fill (poseStack , wX1 + wSize / 10 + wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 + wSize / 20 , wX1 + wSize / 10 + wSize / 3 / 2 - wSize / 20 , scroll + wY2 - wSize / 10 - wSize / 20 , 0xff000000 );
77+ }
78+ }
79+ // Config Button
80+ if (feature .hasConfig ()) {
81+ poseStack .pushPose ();
82+ int h = wSize / 3 / 2 ;
83+ int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
84+ int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
85+ if (cogwheelX <= mouseX && mouseX <= cogwheelX + h &&
86+ cogwheelY <= mouseY && mouseY <= cogwheelY + h ) {
87+ poseStack .rotateAround (Axis .ZP .rotation ((float ) (System .currentTimeMillis () % 4000 ) / 400 ), cogwheelX + h / 2 , cogwheelY + h / 2 , 0.0F );
88+ }
89+ RenderSystem .setShader (GameRenderer ::getPositionTexShader );
90+ RenderSystem .setShaderColor (1.0F , 1.0F , 1.0F , 1.0F );
91+ RenderSystem .setShaderTexture (0 , new ResourceLocation ("simpleclient" , "textures/settings.png" ));
92+ GuiComponent .blit (poseStack , cogwheelX , cogwheelY , 0 , 0 , h , h , h , h );
93+ poseStack .popPose ();
6394 }
95+ // Name
6496 poseStack .pushPose ();
6597 float scaleX = (((float ) wSize ) * 0.8F ) / textRenderer .getWidth (feature .getName ().split (" - " )[0 ]);
6698 float scaleY = (((float ) wSize ) * 0.3F ) / textRenderer .getHeight ();
@@ -98,19 +130,28 @@ public void mouseMoved(double mouseX, double mouseY) {
98130 @ Override
99131 public boolean mouseReleased (double mouseX , double mouseY , int button ) {
100132 if (active == null ) {
101- List <EnableableFeature > enableableFeatures = FeatureManager .INSTANCE .getEnableableFeatures ();
102- for (int i = 0 ; i < enableableFeatures .size (); i ++) {
103- EnableableFeature feature = enableableFeatures .get (i );
104- int x = i % 3 ;
105- int y = i / 3 ;
106- int wSize = (width / 4 - 8 ) / 3 ;
133+ List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
134+ for (int i = 0 ; i < features .size (); i ++) {
135+ Feature feature = features .get (i );
136+ int count = (int ) Math .ceil ((double ) width / 4 / 100 );
137+ int x = i % count ;
138+ int y = i / count ;
139+ int wSize = (width / 4 - 2 - count * 2 ) / count ;
107140 int wX1 = 2 + (2 + wSize ) * x ;
108141 int wY1 = 2 + 2 + (2 + wSize ) * y ;
109142 int wX2 = (2 + wSize ) * x + wSize ;
110143 int wY2 = 2 + (2 + wSize ) * y + wSize ;
111- if (wX1 <= mouseX && mouseX <= wX2 &&
144+ int h = wSize / 3 / 2 ;
145+ int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
146+ int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
147+ if (feature .hasConfig () &&
148+ cogwheelX <= mouseX && mouseX <= cogwheelX + h &&
149+ cogwheelY <= mouseY && mouseY <= cogwheelY + h ) {
150+ minecraft .setScreen (new EditFeatureConfigScreen (feature , this ));
151+ } else if (feature instanceof EnableableFeature ef &&
152+ wX1 <= mouseX && mouseX <= wX2 &&
112153 wY1 + scroll <= mouseY && mouseY <= wY2 + scroll ) {
113- feature .setEnabled (!feature .isEnabled ());
154+ ef .setEnabled (!ef .isEnabled ());
114155 }
115156 }
116157 } else active = null ;
@@ -138,7 +179,7 @@ public void removed() {
138179
139180 @ Override
140181 public boolean mouseScrolled (double mouseX , double mouseY , double amount ) {
141- scroll += amount * height / 50 ;
182+ scroll += amount * height / 30 ;
142183 return super .mouseScrolled (mouseX , mouseY , amount );
143184 }
144185
0 commit comments