1
1
package dev .boxadactle .debugkeybind .gui ;
2
2
3
3
import dev .boxadactle .boxlib .gui .config .BOptionScreen ;
4
+ import dev .boxadactle .boxlib .gui .config .widget .button .BCustomButton ;
4
5
import dev .boxadactle .boxlib .gui .config .widget .label .BCenteredLabel ;
6
+ import dev .boxadactle .boxlib .gui .config .widget .label .BLabel ;
5
7
import dev .boxadactle .boxlib .util .ClientUtils ;
6
8
import dev .boxadactle .debugkeybind .DebugKeybindMain ;
7
9
import dev .boxadactle .debugkeybind .keybind .DebugKeybind ;
8
10
import dev .boxadactle .debugkeybind .keybind .DebugKeybinds ;
11
+ import dev .boxadactle .debugkeybind .keybind .GlobalKeybind ;
12
+ import net .minecraft .client .KeyMapping ;
13
+ import net .minecraft .client .gui .components .AbstractWidget ;
9
14
import net .minecraft .client .gui .components .Button ;
10
15
import net .minecraft .client .gui .screens .Screen ;
16
+ import net .minecraft .client .resources .language .I18n ;
11
17
import net .minecraft .network .chat .Component ;
12
18
19
+ import java .util .List ;
20
+ import java .util .function .Function ;
21
+
13
22
public class DebugKeybindsScreen extends BOptionScreen {
14
23
15
24
KeybindEntry selectedEntry ;
@@ -19,8 +28,8 @@ public DebugKeybindsScreen(Screen parent) {
19
28
}
20
29
21
30
@ Override
22
- protected Component getName () {
23
- return Component . translatable ("controls.keybinds.debug.title" );
31
+ protected String getName () {
32
+ return I18n . get ("controls.keybinds.debug.title" );
24
33
}
25
34
26
35
@ Override
@@ -48,28 +57,28 @@ protected void initFooter(int startX, int startY) {
48
57
49
58
refreshEntries ();
50
59
});
51
- resetButton .setMessage (Component . translatable ("controls.resetAll" ));
60
+ resetButton .setMessage (I18n . get ("controls.resetAll" ));
52
61
53
62
Button doneButton = createHalfDoneButton (startX , startY , (b ) -> {
54
63
ClientUtils .setScreen (parent );
55
64
56
65
DebugKeybindMain .CONFIG .save ();
57
66
});
58
- doneButton .setX (startX + getButtonWidth (ButtonType .SMALL ) + getPadding ());
67
+ doneButton .x = (startX + getButtonWidth (ButtonType .SMALL ) + getPadding ());
59
68
60
- addRenderableWidget (resetButton );
61
- addRenderableWidget (doneButton );
69
+ addButton (resetButton );
70
+ addButton (doneButton );
62
71
}
63
72
64
73
@ Override
65
74
protected void initConfigButtons () {
66
- addConfigLine (new BCenteredLabel (Component . translatable ("key.categories.debug" )));
75
+ addConfigLine (new BCenteredLabel (I18n . get ("key.categories.debug" )));
67
76
68
77
for (DebugKeybind keybind : DebugKeybinds .getGlobalKeybinds ()) {
69
78
addConfigLine (new KeybindEntry (keybind , this ::setSelectedEntry , this ::refreshEntries ));
70
79
}
71
80
72
- addConfigLine (new BCenteredLabel (Component . translatable ("key.categories.debug_actions" )));
81
+ addConfigLine (new BCenteredLabel (I18n . get ("key.categories.debug_actions" )));
73
82
74
83
for (DebugKeybind keybind : DebugKeybinds .getActionKeybinds ()) {
75
84
addConfigLine (new KeybindEntry (keybind , this ::setSelectedEntry , this ::refreshEntries ));
@@ -104,4 +113,97 @@ public boolean mouseClicked(double d, double e, int i) {
104
113
105
114
return super .mouseClicked (d , e , i );
106
115
}
116
+
117
+ @ Override
118
+ public void onClose () {
119
+ super .onClose ();
120
+
121
+ DebugKeybindMain .CONFIG .save ();
122
+ }
123
+
124
+ public class KeybindEntry extends ConfigEntry {
125
+ public DebugKeybind keybind ;
126
+
127
+ public BLabel label ;
128
+ public KeybindButton keybindButton ;
129
+ public ResetButton resetButton ;
130
+
131
+ Runnable globalRefresh ;
132
+
133
+ public KeybindEntry (DebugKeybind keybind , Function <KeybindEntry , Boolean > onSelect , Runnable refresh ) {
134
+ label = new BLabel (keybind .getTranslation ());
135
+ keybindButton = new KeybindButton (keybind , () -> onSelect .apply (this ), DebugKeybindsScreen .this ::renderTooltip );
136
+ resetButton = new ResetButton (keybind , refresh );
137
+
138
+ this .keybind = keybind ;
139
+
140
+ refresh ();
141
+
142
+ this .globalRefresh = refresh ;
143
+ }
144
+
145
+ @ Override
146
+ public List <? extends AbstractWidget > getWidgets () {
147
+ return List .of (label , keybindButton , resetButton );
148
+ }
149
+
150
+ @ Override
151
+ public boolean isInvalid () {
152
+ return false ;
153
+ }
154
+
155
+ public void updateKey (int code ) {
156
+ keybindButton .update (code );
157
+
158
+ refresh ();
159
+ globalRefresh .run ();
160
+ }
161
+
162
+ public void resetKey () {
163
+ keybindButton .resetKey ();
164
+
165
+ globalRefresh .run ();
166
+ }
167
+
168
+ public void refresh () {
169
+ resetButton .refresh ();
170
+
171
+ if (keybind .isUnbound ()) {
172
+ keybindButton .updateConflicts (List .of ());
173
+ return ;
174
+ }
175
+
176
+ List <String > collisions = keybind .checkConflicts (DebugKeybinds .toList ());
177
+
178
+ if (keybind instanceof GlobalKeybind ) {
179
+ KeyMapping [] mappings = ClientUtils .getOptions ().keyMappings .clone ();
180
+
181
+ collisions .addAll (((GlobalKeybind ) keybind ).checkMinecraftConflicts (List .of (mappings )));
182
+ }
183
+
184
+ keybindButton .updateConflicts (collisions );
185
+ }
186
+
187
+ @ Override
188
+ public void render (int index , int y , int x , int entryWidth , int entryHeight , int mouseX , int mouseY , boolean hovered , float tickDelta ) {
189
+ int keybindWidth = 75 ;
190
+ int resetWidth = 50 ;
191
+ int padding = 2 ;
192
+
193
+ label .x = (x - 25 );
194
+ label .y = (y );
195
+ label .setWidth (entryWidth - keybindWidth - resetWidth - padding );
196
+ label .render (mouseX , mouseY , tickDelta );
197
+
198
+ keybindButton .x = (x + entryWidth - keybindWidth - resetWidth - padding );
199
+ keybindButton .y =(y );
200
+ keybindButton .setWidth (keybindWidth );
201
+ keybindButton .render (mouseX , mouseY , tickDelta );
202
+
203
+ resetButton .x = (x + entryWidth - resetWidth );
204
+ resetButton .y = (y );
205
+ resetButton .setWidth (resetWidth );
206
+ resetButton .render (mouseX , mouseY , tickDelta );
207
+ }
208
+ }
107
209
}
0 commit comments