4848import com .cleanroommc .modularui .widgets .textfield .TextFieldWidget ;
4949import org .jetbrains .annotations .NotNull ;
5050import org .jetbrains .annotations .Nullable ;
51+ import org .lwjgl .input .Keyboard ;
5152
5253import java .util .Objects ;
5354import java .util .Set ;
@@ -303,25 +304,35 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
303304 }
304305
305306 protected PanelSyncHandler .IPanelBuilder entryDescription (String key , T entry ) {
306- return (syncManager , syncHandler ) -> GTGuis .createPopupPanel (key , 168 , 36 + 6 )
307- .child (IKey .lang ("cover.generic.ender.set_description.title" , entry .getColorStr ())
308- .color (UI_TITLE_COLOR )
309- .shadow (false )
310- .asWidget ()
311- .left (4 )
312- .top (6 ))
313- .child (new TextFieldWidget ()
314- .setTextColor (Color .WHITE .darker (1 ))
315- .widthRel (0.95f )
316- .height (18 )
317- .value (new StringSyncValue (entry ::getDescription , string -> {
318- entry .setDescription (string );
319- if (syncHandler .isPanelOpen ()) {
320- syncHandler .closePanel ();
307+ return (syncManager , syncHandler ) -> {
308+ var sync = new StringSyncValue (entry ::getDescription , entry ::setDescription );
309+ return GTGuis .createPopupPanel (key , 168 , 36 + 6 )
310+ .child (IKey .lang ("cover.generic.ender.set_description.title" , entry .getColorStr ())
311+ .color (UI_TITLE_COLOR )
312+ .asWidget ()
313+ .left (4 )
314+ .top (6 ))
315+ .child (new TextFieldWidget () {
316+
317+ // todo move this to new class?
318+ @ Override
319+ public @ NotNull Result onKeyPressed (char character , int keyCode ) {
320+ var result = super .onKeyPressed (character , keyCode );
321+ if (result == Result .SUCCESS && keyCode == Keyboard .KEY_RETURN ) {
322+ sync .setStringValue (getText ());
323+ if (syncHandler .isPanelOpen ()) {
324+ syncHandler .closePanel ();
325+ }
321326 }
322- }))
323- .alignX (0.5f )
324- .bottom (6 ));
327+ return result ;
328+ }
329+ }.setTextColor (Color .WHITE .darker (1 ))
330+ .value (sync )
331+ .widthRel (0.95f )
332+ .height (18 )
333+ .alignX (0.5f )
334+ .bottom (6 ));
335+ };
325336 }
326337
327338 protected IWidget createRow (final String name , final PanelSyncManager syncManager , final EntryTypes <T > type ) {
@@ -346,7 +357,7 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
346357 .size (16 )
347358 .background (GTGuiTextures .SLOT .asIcon ().size (18 ))
348359 .top (1 ))
349- .child (new InteractableText <>(entry , CoverAbstractEnderLink . this ::updateColor )
360+ .child (new InteractableText <>(entry , this ::updateColor )
350361 .tooltip (tooltip -> tooltip .setAutoUpdate (true ))
351362 .tooltipBuilder (tooltip -> {
352363 String desc = entry .getDescription ();
@@ -361,7 +372,6 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
361372 .addTooltipLine (IKey .lang ("cover.generic.ender.set_description.tooltip" ))
362373 .onMousePressed (i -> {
363374 // open entry settings
364- // todo this isn't working for some reason
365375 if (panelHandler .isPanelOpen ()) {
366376 panelHandler .closePanel ();
367377 } else {
0 commit comments