1
1
package wafflestomper .ghostwriter .gui .screen ;
2
2
3
3
import com .mojang .blaze3d .vertex .PoseStack ;
4
+ import net .minecraft .client .gui .GuiComponent ;
4
5
import net .minecraft .client .gui .screens .ConfirmScreen ;
5
6
import net .minecraft .client .gui .screens .Screen ;
6
7
import net .minecraft .client .gui .components .Button ;
7
8
import net .minecraft .network .chat .Component ;
8
9
import net .minecraft .network .chat .Style ;
9
10
import wafflestomper .ghostwriter .*;
11
+ import wafflestomper .ghostwriter .gui .GuiUtils ;
10
12
import wafflestomper .ghostwriter .gui .widget .FileSelectionList ;
11
13
import wafflestomper .ghostwriter .gui .GhostLayer ;
12
14
import wafflestomper .ghostwriter .gui .widget .SelectableFilenameField ;
@@ -124,7 +126,10 @@ private void saveClicked() {
124
126
125
127
public void init () {
126
128
super .init ();
127
- if (this .minecraft != null ) this .minecraft .keyboardHandler .setSendRepeatsToGui (true );
129
+ if (this .minecraft == null ) return ;
130
+
131
+ // I can't remember what this did but setSendRepeatsToGui() is no longer a valid function...
132
+ // this.minecraft.keyboardHandler.setSendRepeatsToGui(true);
128
133
129
134
if (!this .initialized ) {
130
135
this .fileSelectionList = new FileSelectionList (this , this .minecraft , this .width , this .height , 32 , this .height - 64 , SLOT_HEIGHT );
@@ -153,29 +158,48 @@ public void init() {
153
158
// For some reason the button list is cleared when the window is resized
154
159
int mainButtonsY = this .height - BORDER_HEIGHT - BUTTON_HEIGHT ;
155
160
int loadX = this .width / 2 - 127 ;
156
- this .btnLoad = this .addRenderableWidget (new Button (loadX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT ,
157
- Component .translatable ("Load" ), (pressedButton ) -> this .loadClicked (false )));
161
+
162
+ this .btnLoad = this .addRenderableWidget (
163
+ GuiUtils .buttonFactory (
164
+ loadX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT , "Load" ,
165
+ (pressedButton ) -> this .loadClicked (false )
166
+ )
167
+ );
158
168
159
169
int autoReloadX = loadX + BUTTON_WIDTH ;
160
- this .btnAutoReload = this .addRenderableWidget (new Button (autoReloadX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT ,
161
- Component .translatable ("AutoReload" ), (pressedButton ) -> this .loadClicked (true )));
170
+ this .btnAutoReload = this .addRenderableWidget (
171
+ GuiUtils .buttonFactory (
172
+ autoReloadX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT , "AutoReload" ,
173
+ (pressedButton ) -> this .loadClicked (true )
174
+ )
175
+ );
162
176
163
177
int saveX = autoReloadX + BUTTON_WIDTH + 7 ;
164
- this .btnSave = this .addRenderableWidget (new Button (saveX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT ,
165
- Component .translatable ("Save" ), (pressedButton ) -> this .saveClicked ()));
178
+ this .btnSave = this .addRenderableWidget (
179
+ GuiUtils .buttonFactory (
180
+ saveX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT , "Save" ,
181
+ (pressedButton ) -> this .saveClicked ()
182
+ )
183
+ );
166
184
167
185
int cancelX = this .width / 2 + 127 - BUTTON_WIDTH ;
168
- this .addRenderableWidget (new Button (cancelX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT ,
169
- Component .translatable ("Cancel" ), (pressedButton ) -> goBackToParentGui ()));
186
+ this .addRenderableWidget (
187
+ GuiUtils .buttonFactory (
188
+ cancelX , mainButtonsY , BUTTON_WIDTH , BUTTON_HEIGHT , "Cancel" ,
189
+ (pressedButton ) -> goBackToParentGui ()
190
+ )
191
+ );
170
192
171
193
//Add buttons for each non-empty drive letter
172
194
int rootNum = 100 ;
173
195
List <File > roots = this .FILE_HANDLER .getValidRoots ();
174
196
for (File root : roots ) {
175
- this .addRenderableWidget (new Button (5 , 35 + 21 * (rootNum - 100 ), 50 , 20 ,
176
- Component .translatable (root .getAbsolutePath ()), (pressedButton ) ->
177
- this .driveButtonClicked (root )
178
- ));
197
+ this .addRenderableWidget (
198
+ GuiUtils .buttonFactory (
199
+ 5 , 35 + 21 * (rootNum - 100 ), 50 , 20 , root .getAbsolutePath (),
200
+ (pressedButton ) -> this .driveButtonClicked (root )
201
+ )
202
+ );
179
203
rootNum ++;
180
204
}
181
205
@@ -188,12 +212,19 @@ public void init() {
188
212
this .filenameField .y = this .height - BORDER_HEIGHT * 2 - BUTTON_HEIGHT * 2 ;
189
213
190
214
// Add button for enabling file extension editing
191
- this .btnEditExtension = this .addRenderableWidget (new Button (this .filenameField .x + this .filenameField .getWidth () + 3 ,
192
- this .filenameField .y , 25 , this .filenameField .getHeight (), Component .translatable ("EXT" ),
193
- (pressedButton ) -> {
194
- this .filenameField .toggleExtensionModifications ();
195
- this .updateButtons ();
196
- }));
215
+ this .btnEditExtension = this .addRenderableWidget (
216
+ GuiUtils .buttonFactory (
217
+ this .filenameField .x + this .filenameField .getWidth () + 3 ,
218
+ this .filenameField .y ,
219
+ 25 ,
220
+ this .filenameField .getHeight (),
221
+ "EXT" ,
222
+ (pressedButton ) -> {
223
+ this .filenameField .toggleExtensionModifications ();
224
+ this .updateButtons ();
225
+ }
226
+ )
227
+ );
197
228
198
229
this .updateButtons ();
199
230
}
@@ -232,9 +263,9 @@ public void render(PoseStack PoseStack, int mouseX, int mouseY, float partialTic
232
263
String reversed = new StringBuilder (displayPath ).reverse ().toString ();
233
264
// func_238361_b_() is trimStringToWidth()
234
265
reversed = this .font .getSplitter ().plainHeadByWidth (reversed , allowedSize , Style .EMPTY );
235
- displayPath = "..." + new StringBuilder (reversed ).reverse (). toString () ;
266
+ displayPath = "..." + new StringBuilder (reversed ).reverse ();
236
267
}
237
- this .drawCenteredString (PoseStack , this .font , displayPath , this .width / 2 , 20 , 0xDDDDDD );
268
+ GuiComponent .drawCenteredString (PoseStack , this .font , displayPath , this .width / 2 , 20 , 0xDDDDDD );
238
269
239
270
this .filenameField .render (PoseStack , mouseX , mouseY , partialTicks );
240
271
@@ -251,8 +282,7 @@ else if (this.hoveringText != null) {
251
282
252
283
public void setSelectedSlot (FileSelectionList .Entry entry ) {
253
284
this .fileSelectionList .setSelected (entry );
254
- if (this .enableLoading && entry instanceof FileSelectionList .PathItemEntry ) {
255
- FileSelectionList .PathItemEntry p = (FileSelectionList .PathItemEntry ) entry ;
285
+ if (this .enableLoading && entry instanceof FileSelectionList .PathItemEntry p ) {
256
286
if (p .path == this .selectedFile ) {
257
287
return ;
258
288
} else if (p .path .isFile ()) {
@@ -316,7 +346,7 @@ public void updateButtons() {
316
346
if (this .filenameField .allowExtensionModifications ) {
317
347
this .btnEditExtension .setMessage (Component .translatable ("EXT" ));
318
348
} else {
319
- this .btnEditExtension .setMessage (Component .translatable ("\u00a7 mEXT " ));
349
+ this .btnEditExtension .setMessage (Component .translatable ("§mEXT " ));
320
350
}
321
351
}
322
352
0 commit comments