3
3
import net .minecraft .client .gui .screen .Screen ;
4
4
import net .minecraft .client .gui .screen .ScreenTexts ;
5
5
import net .minecraft .client .gui .widget .ButtonWidget ;
6
+ import net .minecraft .client .gui .widget .TextFieldWidget ;
6
7
import net .minecraft .client .util .InputUtil ;
7
8
import net .minecraft .client .util .math .MatrixStack ;
8
9
import net .minecraft .text .LiteralText ;
10
+ import net .minecraft .text .TranslatableText ;
9
11
import org .jetbrains .annotations .ApiStatus ;
10
12
import org .jetbrains .annotations .Nullable ;
13
+ import org .lwjgl .glfw .GLFW ;
11
14
import org .mcsr .speedrunapi .SpeedrunAPI ;
12
15
import org .mcsr .speedrunapi .config .SpeedrunConfigContainer ;
13
16
import org .mcsr .speedrunapi .config .screen .widgets .list .SpeedrunOptionListWidget ;
@@ -21,7 +24,10 @@ public class SpeedrunConfigScreen extends Screen {
21
24
@ Nullable
22
25
private final Predicate <InputUtil .Key > inputListener ;
23
26
private final Screen parent ;
27
+
24
28
private SpeedrunOptionListWidget list ;
29
+ private TextFieldWidget searchField ;
30
+ private boolean searchFieldOpen ;
25
31
26
32
public SpeedrunConfigScreen (SpeedrunConfigContainer <?> config , @ Nullable Predicate <InputUtil .Key > inputListener , Screen parent ) {
27
33
super (new LiteralText (config .getModContainer ().getMetadata ().getName ()));
@@ -30,9 +36,26 @@ public SpeedrunConfigScreen(SpeedrunConfigContainer<?> config, @Nullable Predica
30
36
this .parent = parent ;
31
37
}
32
38
39
+ private void toggleSearchField () {
40
+ this .searchFieldOpen = !this .searchFieldOpen ;
41
+ this .searchField .setVisible (this .searchFieldOpen );
42
+ if (this .searchFieldOpen ) {
43
+ this .setFocused (this .searchField );
44
+ this .searchField .setSelected (true );
45
+ this .list .adjustTop (50 );
46
+ } else {
47
+ this .searchField .setText ("" );
48
+ this .list .adjustTop (25 );
49
+ }
50
+ }
51
+
33
52
@ Override
34
53
protected void init () {
35
- this .list = new SpeedrunOptionListWidget (this .config , this , this .client , this .width , this .height , 25 , this .height - 32 );
54
+ this .searchField = new TextFieldWidget (this .textRenderer , this .width / 2 - 100 , 25 , 200 , 20 , this .searchField , new TranslatableText ("speedrunapi.gui.config.search" ));
55
+ this .searchField .setVisible (this .searchFieldOpen );
56
+ this .searchField .setChangedListener (string -> this .list .updateEntries (string ));
57
+ this .addChild (this .searchField );
58
+ this .list = new SpeedrunOptionListWidget (this , this .config , this .client , this .width , this .height , 25 , this .height - 32 , this .searchField .getText ());
36
59
this .addChild (this .list );
37
60
this .addButton (new ButtonWidget (this .width / 2 - 100 , this .height - 27 , 200 , 20 , ScreenTexts .DONE , button -> this .onClose ()));
38
61
}
@@ -41,6 +64,7 @@ protected void init() {
41
64
public void render (MatrixStack matrices , int mouseX , int mouseY , float delta ) {
42
65
this .renderBackground (matrices );
43
66
this .list .render (matrices , mouseX , mouseY , delta );
67
+ this .searchField .render (matrices , mouseX , mouseY , delta );
44
68
this .drawCenteredText (matrices , this .textRenderer , this .title , this .width / 2 , 10 , 0xFFFFFF );
45
69
super .render (matrices , mouseX , mouseY , delta );
46
70
}
@@ -50,6 +74,10 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
50
74
if (this .inputListener != null && this .inputListener .test (InputUtil .fromKeyCode (keyCode , scanCode ))) {
51
75
return true ;
52
76
}
77
+ if (keyCode == GLFW .GLFW_KEY_F && Screen .hasControlDown ()) {
78
+ this .toggleSearchField ();
79
+ return true ;
80
+ }
53
81
return super .keyPressed (keyCode , scanCode , modifiers );
54
82
}
55
83
0 commit comments