1616import java .util .List ;
1717
1818public class EditFeaturesScreen extends Screen {
19- public DraggableFeature active ;
20- public double offsetX = 0 ;
21- public double offsetY = 0 ;
22- public int scroll = 0 ;
19+ public DraggableFeature active ;
20+ public double offsetX = 0 ;
21+ public double offsetY = 0 ;
22+ public int scroll = 0 ;
2323
24- public EditFeaturesScreen () {
25- super (Component .translatable ("simpleclient.edit_features" ));
26- }
24+ public EditFeaturesScreen () {
25+ super (Component .translatable ("simpleclient.edit_features" ));
26+ }
2727
28- @ Override
29- public void render (GuiGraphics guiGraphics , int mouseX , int mouseY , float delta ) {
30- TextRendererAdapter textRenderer = new TextRendererAdapterImpl (guiGraphics , font );
31- ItemRendererAdapter itemRenderer = new ItemRendererAdapterImpl (guiGraphics );
32- // Render Renderable Features
33- for (Feature feature : FeatureManager .INSTANCE .getFeatures ()) {
34- if (feature instanceof RenderableFeature rf && rf .isEnabled ()) {
35- rf .renderDummy (textRenderer , itemRenderer , width , height );
36- if (rf instanceof DraggableFeature df ) {
37- int x1 = df .getXPos (width ) - 1 ;
38- int y1 = df .getYPos (height ) - 1 ;
39- int x2 = df .getXPos (width ) + df .getWidth (textRenderer , itemRenderer , width , height ) + 1 ;
40- int y2 = df .getYPos (height ) + df .getHeight (textRenderer , itemRenderer , width , height ) + 1 ;
41- guiGraphics .fill (x1 - 1 , y1 - 1 , x2 + 1 , y1 , 0xFFAAAAAA );
42- guiGraphics .fill (x1 - 1 , y2 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
43- guiGraphics .fill (x1 - 1 , y1 - 1 , x1 , y2 + 1 , 0xFFAAAAAA );
44- guiGraphics .fill (x2 , y1 - 1 , x2 + 1 , y2 + 1 , 0xFFAAAAAA );
45- }
46- }
47- }
48- // Render Enableable Features
49- guiGraphics .fill (0 , 0 , width / 4 , height , 0x77000000 );
50- List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
51- for (int i = 0 ; i < features .size (); i ++) {
52- Feature feature = features .get (i );
53- int count = (int ) Math .ceil ((double ) width / 4 / 100 );
54- int x = i % count ;
55- int y = i / count ;
56- int wSize = (width / 4 - 2 - count * 2 ) / count ;
57- int wX1 = 3 + (2 + wSize ) * x ;
58- int wY1 = 2 + 2 + (2 + wSize ) * y ;
59- int wX2 = (2 + wSize ) * x + wSize + 1 ;
60- int wY2 = 2 + (2 + wSize ) * y + wSize ;
61- // Background
62- int corners = (wY2 - wY1 ) / 8 ;
63- DrawUtil .drawCircle (guiGraphics , wX1 + corners , scroll + wY1 + corners , corners , 90.0F , -90.0F , 0xFF555555 );
64- DrawUtil .drawCircle (guiGraphics , wX2 - corners , scroll + wY1 + corners , corners , 90.0F , 0.0F , 0xFF555555 );
65- DrawUtil .drawCircle (guiGraphics , wX1 + corners , scroll + wY2 - corners , corners , 90.0F , 180.0F , 0xFF555555 );
66- DrawUtil .drawCircle (guiGraphics , wX2 - corners , scroll + wY2 - corners , corners , 90.0F , 90.0F , 0xFF555555 );
67- guiGraphics .fill (wX1 + corners , scroll + wY1 , wX2 - corners , scroll + wY1 + corners , 0xFF555555 );
68- guiGraphics .fill (wX1 + corners , scroll + wY2 - corners , wX2 - corners , scroll + wY2 , 0xFF555555 );
69- guiGraphics .fill (wX1 , scroll + wY1 + corners , wX1 + corners , scroll + wY2 - corners , 0xFF555555 );
70- guiGraphics .fill (wX2 - corners , scroll + wY1 + corners , wX2 , scroll + wY2 - corners , 0xFF555555 );
71- guiGraphics .fill (wX1 + corners , scroll + wY1 + corners , wX2 - corners , scroll + wY2 - corners , 0xFF555555 );
72- // Enable Button
73- if (feature instanceof EnableableFeature ef ) {
74- int height = wSize / 6 ;
75- DrawUtil .drawCircle (guiGraphics , wX1 + wSize / 10 + height / 2 , scroll + wY2 - wSize / 10 - height / 2 , height / 2 , 180.0F , 180.0F , ef .isEnabled () ? 0xFF00FF00 : 0xFFFF0000 );
76- DrawUtil .drawCircle (guiGraphics , wX1 + wSize / 10 + wSize / 3 - height / 2 , scroll + wY2 - wSize / 10 - height / 2 , height / 2 , 180.0F , 0.0F , ef .isEnabled () ? 0xFF00FF00 : 0xFFFF0000 );
77- guiGraphics .fill (wX1 + wSize / 10 + height / 2 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 , wX1 + wSize / 10 + wSize / 3 - height / 2 , scroll + wY2 - wSize / 10 , ef .isEnabled () ? 0xFF00FF00 : 0xFFFF0000 );
78- if (ef .isEnabled ()) {
79- DrawUtil .drawCircle (guiGraphics , wX1 + wSize / 10 + wSize / 3 - height / 2 , scroll + wY2 - wSize / 10 - height / 2 , height * 2 / 5 , 360.0F , 0.0F , 0xFF000000 );
80- } else {
81- DrawUtil .drawCircle (guiGraphics , wX1 + wSize / 10 + height / 2 , scroll + wY2 - wSize / 10 - height / 2 , height * 2 / 5 , 360.0F , 0.0F , 0xFF000000 );
82- }
83- }
84- // Config Button
85- if (feature .hasConfig ()) {
86- guiGraphics .pose ().pushPose ();
87- int h = wSize / 3 / 2 ;
88- int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
89- int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
90- if (cogwheelX <= mouseX && mouseX <= cogwheelX + h &&
91- cogwheelY <= mouseY && mouseY <= cogwheelY + h ) {
92- guiGraphics .pose ().rotateAround (Axis .ZP .rotation ((float ) (System .currentTimeMillis () % 4000 ) / 400 ), cogwheelX + h / 2 , cogwheelY + h / 2 , 0.0F );
93- }
94- guiGraphics .blit (new ResourceLocation ("simpleclient" , "textures/settings.png" ), cogwheelX , cogwheelY , 0 , 0 , h , h , h , h );
95- guiGraphics .pose ().popPose ();
96- }
97- // Name
98- guiGraphics .pose ().pushPose ();
99- float scaleX = (((float ) wSize ) * 0.8F ) / textRenderer .getWidth (feature .getName ().split (" - " )[0 ]);
100- float scaleY = (((float ) wSize ) * 0.3F ) / textRenderer .getHeight ();
101- float scale = Math .min (scaleX , scaleY );
102- guiGraphics .pose ().scale (scale , scale , scale );
103- int yOffset = 0 ;
104- for (String str : feature .getName ().split (" - " )) {
105- textRenderer .render (Text .literal (str ), (int ) ((wX1 + (wSize - textRenderer .getWidth (str ) * scale ) / 2 ) / scale ), (int ) ((scroll + wY1 + wSize * 0.1F + yOffset ) / scale ), 0xffffff );
106- yOffset += textRenderer .getHeight ();
107- }
108- guiGraphics .pose ().popPose ();
109- }
110- }
28+ @ Override
29+ public void render (GuiGraphics guiGraphics , int mouseX , int mouseY , float delta ) {
30+ TextRendererAdapter textRenderer = new TextRendererAdapterImpl (guiGraphics , font );
31+ ItemRendererAdapter itemRenderer = new ItemRendererAdapterImpl (guiGraphics );
32+ // Render Renderable Features
33+ for (Feature feature : FeatureManager .INSTANCE .getFeatures ()) {
34+ if (feature instanceof RenderableFeature rf && rf .isEnabled ()) {
35+ rf .renderDummy (textRenderer , itemRenderer , width , height );
36+ if (rf instanceof DraggableFeature df ) {
37+ final float xPos = df .getXPos (width );
38+ final float yPos = df .getYPos (height );
11139
112- @ Override
113- public boolean mouseClicked (double mouseX , double mouseY , int button ) {
114- TextRendererAdapter textRenderer = new TextRendererAdapterImpl (null , font );
115- ItemRendererAdapter itemRenderer = new ItemRendererAdapterImpl (null );
116- active = getFeature (textRenderer , itemRenderer , mouseX , mouseY );
117- if (active != null ) {
118- offsetX = mouseX - active .getXPos (width );
119- offsetY = mouseY - active .getYPos (height );
120- }
121- return super .mouseClicked (mouseX , mouseY , button );
122- }
40+ DrawUtil .border (guiGraphics , xPos - 1 , yPos - 1 ,
41+ xPos + df .getWidth (textRenderer , itemRenderer , width , height ) + 1 ,
42+ yPos + df .getHeight (textRenderer , itemRenderer , width , height ) + 1 , 1.f , 1.f , 0xFFAAAAAA );
43+ }
44+ }
45+ }
46+ // Render Enableable Features
47+ DrawUtil .rectangle (guiGraphics , 0 , 0 , width / 4 , height , 0x77000000 );
48+ List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
49+ for (int i = 0 ; i < features .size (); i ++) {
50+ Feature feature = features .get (i );
51+ int count = (int ) Math .ceil ((double ) width / 4 / 100 );
52+ int x = i % count ;
53+ int y = i / count ;
54+ int wSize = (width / 4 - 2 - count * 2 ) / count ;
55+ int wX1 = 3 + (2 + wSize ) * x ;
56+ int wY1 = 2 + 2 + (2 + wSize ) * y ;
57+ int wX2 = (2 + wSize ) * x + wSize + 1 ;
58+ int wY2 = 2 + (2 + wSize ) * y + wSize ;
59+ // Background
60+ int corners = (wY2 - wY1 ) / 8 ;
61+ DrawUtil .roundedRectangle (guiGraphics , wX1 , wY1 + this .scroll , wX2 , wY2 + this .scroll , corners , 0xFF555555 );
12362
124- @ Override
125- public void mouseMoved (double mouseX , double mouseY ) {
126- if (active != null ) {
127- active .setXPos ((int ) (mouseX - offsetX ), width );
128- active .setYPos ((int ) (mouseY - offsetY ), height );
129- }
130- }
63+ // Enable Button
64+ if (feature instanceof EnableableFeature ef ) {
65+ int height = wSize / 6 ;
66+ DrawUtil .stadium (guiGraphics , wX1 + wSize / 10 , scroll + wY2 - wSize / 10 - wSize / 3 / 2 ,
67+ wX1 + wSize / 10 + wSize / 3 , scroll + wY2 - wSize / 10 ,
68+ ef .isEnabled () ? 0xFF00FF00 : 0xFFFF0000 );
69+ if (ef .isEnabled ()) {
70+ DrawUtil .circle (guiGraphics , wX1 + wSize / 10 + wSize / 3 - height / 2 ,
71+ scroll + wY2 - wSize / 10 - height / 2 , height * 2 / 5 , 0xFF000000 );
72+ } else {
73+ DrawUtil .circle (guiGraphics , wX1 + wSize / 10 + height / 2 , scroll + wY2 - wSize / 10 - height / 2 ,
74+ height * 2 / 5 , 0xFF000000 );
75+ }
76+ }
77+ // Config Button
78+ if (feature .hasConfig ()) {
79+ guiGraphics .pose ().pushPose ();
80+ int h = wSize / 3 / 2 ;
81+ int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
82+ int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
83+ if (cogwheelX <= mouseX && mouseX <= cogwheelX + h && cogwheelY <= mouseY && mouseY <= cogwheelY + h ) {
84+ guiGraphics .pose ().rotateAround (Axis .ZP .rotation ((float ) (System .currentTimeMillis () % 4000 ) / 400 ),
85+ cogwheelX + h / 2 , cogwheelY + h / 2 , 0.0F );
86+ }
87+ guiGraphics .blit (new ResourceLocation ("simpleclient" , "textures/settings.png" ), cogwheelX , cogwheelY , 0 ,
88+ 0 , h , h , h , h );
89+ guiGraphics .pose ().popPose ();
90+ }
91+ // Name
92+ guiGraphics .pose ().pushPose ();
93+ float scaleX = (((float ) wSize ) * 0.8F ) / textRenderer .getWidth (feature .getName ().split (" - " )[0 ]);
94+ float scaleY = (((float ) wSize ) * 0.3F ) / textRenderer .getHeight ();
95+ float scale = Math .min (scaleX , scaleY );
96+ guiGraphics .pose ().scale (scale , scale , scale );
97+ int yOffset = 0 ;
98+ for (String str : feature .getName ().split (" - " )) {
99+ textRenderer .render (Text .literal (str ),
100+ (int ) ((wX1 + (wSize - textRenderer .getWidth (str ) * scale ) / 2 ) / scale ),
101+ (int ) ((scroll + wY1 + wSize * 0.1F + yOffset ) / scale ), 0xffffff );
102+ yOffset += textRenderer .getHeight ();
103+ }
104+ guiGraphics .pose ().popPose ();
105+ }
106+ }
131107
132- @ Override
133- public boolean mouseReleased (double mouseX , double mouseY , int button ) {
134- if (active == null ) {
135- List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
136- for (int i = 0 ; i < features .size (); i ++) {
137- Feature feature = features .get (i );
138- int count = (int ) Math .ceil ((double ) width / 4 / 100 );
139- int x = i % count ;
140- int y = i / count ;
141- int wSize = (width / 4 - 2 - count * 2 ) / count ;
142- int wX1 = 2 + (2 + wSize ) * x ;
143- int wY1 = 2 + 2 + (2 + wSize ) * y ;
144- int wX2 = (2 + wSize ) * x + wSize ;
145- int wY2 = 2 + (2 + wSize ) * y + wSize ;
146- int h = wSize / 3 / 2 ;
147- int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
148- int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
149- if (feature .hasConfig () &&
150- cogwheelX <= mouseX && mouseX <= cogwheelX + h &&
151- cogwheelY <= mouseY && mouseY <= cogwheelY + h ) {
152- minecraft .setScreen (new EditFeatureConfigScreen (feature , this ));
153- } else if (feature instanceof EnableableFeature ef &&
154- wX1 <= mouseX && mouseX <= wX2 &&
155- wY1 + scroll <= mouseY && mouseY <= wY2 + scroll ) {
156- ef .setEnabled (!ef .isEnabled ());
157- }
158- }
159- } else active = null ;
160- return super .mouseReleased (mouseX , mouseY , button );
161- }
108+ @ Override
109+ public boolean mouseClicked (double mouseX , double mouseY , int button ) {
110+ TextRendererAdapter textRenderer = new TextRendererAdapterImpl (null , font );
111+ ItemRendererAdapter itemRenderer = new ItemRendererAdapterImpl (null );
112+ active = getFeature (textRenderer , itemRenderer , mouseX , mouseY );
113+ if (active != null ) {
114+ offsetX = mouseX - active .getXPos (width );
115+ offsetY = mouseY - active .getYPos (height );
116+ }
117+ return super .mouseClicked (mouseX , mouseY , button );
118+ }
162119
163- private DraggableFeature getFeature (TextRendererAdapter textRenderer , ItemRendererAdapter itemRenderer , double mouseX , double mouseY ) {
164- for (Feature feature : FeatureManager .INSTANCE .getFeatures ()) {
165- if (feature instanceof DraggableFeature df && df .isEnabled ()) {
166- int x1 = df .getXPos (width ) - 1 ;
167- int y1 = df .getYPos (height ) - 1 ;
168- int x2 = df .getXPos (width ) + df .getWidth (textRenderer , itemRenderer , width , height ) + 1 ;
169- int y2 = df .getYPos (height ) + df .getHeight (textRenderer , itemRenderer , width , height ) + 1 ;
170- if (x1 <= mouseX && mouseX <= x2 &&
171- y1 <= mouseY && mouseY <= y2 ) return df ;
172- }
173- }
174- return null ;
175- }
120+ @ Override
121+ public void mouseMoved (double mouseX , double mouseY ) {
122+ if (active != null ) {
123+ active .setXPos ((int ) (mouseX - offsetX ), width );
124+ active .setYPos ((int ) (mouseY - offsetY ), height );
125+ }
126+ }
176127
177- @ Override
178- public void removed () {
179- FeatureManager .INSTANCE .getJson ().save ();
180- }
128+ @ Override
129+ public boolean mouseReleased (double mouseX , double mouseY , int button ) {
130+ if (active == null ) {
131+ List <Feature > features = FeatureManager .INSTANCE .getFeatures ();
132+ for (int i = 0 ; i < features .size (); i ++) {
133+ Feature feature = features .get (i );
134+ int count = (int ) Math .ceil ((double ) width / 4 / 100 );
135+ int x = i % count ;
136+ int y = i / count ;
137+ int wSize = (width / 4 - 2 - count * 2 ) / count ;
138+ int wX1 = 2 + (2 + wSize ) * x ;
139+ int wY1 = 2 + 2 + (2 + wSize ) * y ;
140+ int wX2 = (2 + wSize ) * x + wSize ;
141+ int wY2 = 2 + (2 + wSize ) * y + wSize ;
142+ int h = wSize / 3 / 2 ;
143+ int cogwheelX = wX1 + wSize / 10 * 4 + wSize / 3 ;
144+ int cogwheelY = scroll + wY2 - wSize / 10 - wSize / 3 / 2 ;
145+ if (feature .hasConfig () && cogwheelX <= mouseX && mouseX <= cogwheelX + h && cogwheelY <= mouseY
146+ && mouseY <= cogwheelY + h ) {
147+ minecraft .setScreen (new EditFeatureConfigScreen (feature , this ));
148+ } else if (feature instanceof EnableableFeature ef && wX1 <= mouseX && mouseX <= wX2
149+ && wY1 + scroll <= mouseY && mouseY <= wY2 + scroll ) {
150+ ef .setEnabled (!ef .isEnabled ());
151+ }
152+ }
153+ } else
154+ active = null ;
155+ return super .mouseReleased (mouseX , mouseY , button );
156+ }
181157
182- @ Override
183- public boolean mouseScrolled (double mouseX , double mouseY , double amount ) {
184- scroll += amount * height / 30 ;
185- return super .mouseScrolled (mouseX , mouseY , amount );
186- }
158+ private DraggableFeature getFeature (TextRendererAdapter textRenderer , ItemRendererAdapter itemRenderer ,
159+ double mouseX , double mouseY ) {
160+ for (Feature feature : FeatureManager .INSTANCE .getFeatures ()) {
161+ if (feature instanceof DraggableFeature df && df .isEnabled ()) {
162+ int x1 = df .getXPos (width ) - 1 ;
163+ int y1 = df .getYPos (height ) - 1 ;
164+ int x2 = df .getXPos (width ) + df .getWidth (textRenderer , itemRenderer , width , height ) + 1 ;
165+ int y2 = df .getYPos (height ) + df .getHeight (textRenderer , itemRenderer , width , height ) + 1 ;
166+ if (x1 <= mouseX && mouseX <= x2 && y1 <= mouseY && mouseY <= y2 )
167+ return df ;
168+ }
169+ }
170+ return null ;
171+ }
187172
188- @ Override
189- public boolean isPauseScreen () {
190- return true ;
191- }
173+ @ Override
174+ public void removed () {
175+ FeatureManager .INSTANCE .getJson ().save ();
176+ }
177+
178+ @ Override
179+ public boolean mouseScrolled (double mouseX , double mouseY , double amount ) {
180+ scroll += amount * height / 30 ;
181+ return super .mouseScrolled (mouseX , mouseY , amount );
182+ }
183+
184+ @ Override
185+ public boolean isPauseScreen () {
186+ return true ;
187+ }
192188}
0 commit comments