16
16
import org .lwjgl .input .Mouse ;
17
17
18
18
import com .glodblock .github .FluidCraft ;
19
- import com .glodblock .github .client .gui .FCGuiTextField ;
20
19
import com .glodblock .github .client .gui .GuiFluidMonitor ;
21
20
import com .glodblock .github .client .gui .GuiItemMonitor ;
22
21
import com .glodblock .github .client .gui .container .base .FCContainerMonitor ;
28
27
29
28
import appeng .api .config .CraftingStatus ;
30
29
import appeng .api .config .PinsState ;
30
+ import appeng .api .config .SearchBoxFocusPriority ;
31
31
import appeng .api .config .SearchBoxMode ;
32
32
import appeng .api .config .Settings ;
33
33
import appeng .api .config .TerminalStyle ;
45
45
import appeng .client .gui .widgets .GuiTabButton ;
46
46
import appeng .client .gui .widgets .IDropToFillTextField ;
47
47
import appeng .client .gui .widgets .ISortSource ;
48
+ import appeng .client .gui .widgets .MEGuiTextField ;
48
49
import appeng .client .me .InternalSlotME ;
49
50
import appeng .client .me .ItemRepo ;
50
51
import appeng .client .me .PinSlotME ;
@@ -93,7 +94,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
93
94
public GuiTabButton craftingStatusBtn ;
94
95
protected IDisplayRepo repo ;
95
96
protected GuiImgButton craftingStatusImgBtn ;
96
- protected FCGuiTextField searchField ;
97
+ protected MEGuiTextField searchField ;
97
98
protected int perRow = 9 ;
98
99
protected int reservedSpace = 0 ;
99
100
protected boolean customSortOrder = true ;
@@ -113,6 +114,10 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
113
114
protected boolean hasShiftKeyDown = false ;
114
115
private PinsState pinsState ;
115
116
public final boolean hasPinHost ;
117
+ private boolean canBeAutoFocused ;
118
+ private boolean isAutoFocused ;
119
+ protected int currentMouseY ;
120
+ protected int currentMouseX ;
116
121
117
122
@ SuppressWarnings ("unchecked" )
118
123
public FCGuiMonitor (final InventoryPlayer inventoryPlayer , final ITerminalHost te , final FCContainerMonitor <T > c ) {
@@ -337,18 +342,19 @@ public void initGui() {
337
342
AEConfig .instance .settings .getSetting (Settings .TERMINAL_STYLE )));
338
343
this .offsetY += 20 ;
339
344
340
- // Right now 80 > offsetX, but that can be changed later.
341
- // noinspection DataFlowIssue
342
- this .searchField = new FCGuiTextField (
343
- this .fontRendererObj ,
344
- this .guiLeft + Math .max (80 , this .offsetX ),
345
- this .guiTop + 4 ,
346
- 90 ,
347
- 12 );
348
- this .searchField .setEnableBackgroundDrawing (false );
345
+ this .searchField = new MEGuiTextField (90 , 12 ) {
346
+
347
+ @ Override
348
+ public void onTextChange (final String oldText ) {
349
+ final String text = getText ();
350
+ repo .setSearchString (text );
351
+ repo .updateView ();
352
+ setScrollBar ();
353
+ }
354
+ };
355
+ this .searchField .x = this .guiLeft + Math .max (80 , this .offsetX );
356
+ this .searchField .y = this .guiTop + 4 ;
349
357
this .searchField .setMaxStringLength (25 );
350
- this .searchField .setTextColor (0xFFFFFF );
351
- this .searchField .setVisible (true );
352
358
if (ModAndClassUtil .isSearchStringTooltip )
353
359
searchField .setMessage (ButtonToolTips .SearchStringTooltip .getLocal ());
354
360
@@ -384,7 +390,9 @@ public void initGui() {
384
390
}
385
391
386
392
final Enum <?> setting = AEConfig .instance .settings .getSetting (Settings .SEARCH_MODE );
387
- this .searchField .setFocused (SearchBoxMode .AUTOSEARCH == setting || SearchBoxMode .NEI_AUTOSEARCH == setting );
393
+ this .canBeAutoFocused = SearchBoxMode .AUTOSEARCH == setting || SearchBoxMode .NEI_AUTOSEARCH == setting ;
394
+ this .searchField .setFocused (this .canBeAutoFocused );
395
+ this .isAutoFocused = this .canBeAutoFocused ;
388
396
389
397
if (ModAndClassUtil .isSearchBar && (AEConfig .instance .preserveSearchBar || this .isSubGui ())) {
390
398
setSearchString (memoryText , false );
@@ -420,6 +428,7 @@ public void initGui() {
420
428
421
429
public void setSearchString (String memoryText , boolean updateView ) {
422
430
this .searchField .setText (memoryText );
431
+ this .searchField .setCursorPositionEnd ();
423
432
this .repo .setSearchString (memoryText );
424
433
if (updateView ) {
425
434
this .repo .updateView ();
@@ -429,13 +438,8 @@ public void setSearchString(String memoryText, boolean updateView) {
429
438
430
439
@ Override
431
440
protected void mouseClicked (final int xCoord , final int yCoord , final int btn ) {
432
- final Enum <?> searchMode = AEConfig .instance .settings .getSetting (Settings .SEARCH_MODE );
433
- if (searchMode != SearchBoxMode .AUTOSEARCH && searchMode != SearchBoxMode .NEI_AUTOSEARCH ) {
434
- this .searchField .mouseClicked (xCoord , yCoord , btn );
435
- }
436
- if (btn == 1 && this .searchField .isMouseIn (xCoord , yCoord )) {
437
- setSearchString ("" , true );
438
- }
441
+ this .searchField .mouseClicked (xCoord , yCoord , btn );
442
+ isAutoFocused = false ;
439
443
super .mouseClicked (xCoord , yCoord , btn );
440
444
}
441
445
@@ -718,6 +722,9 @@ public void drawBG(final int offsetX, final int offsetY, final int mouseX, final
718
722
if (this .searchField != null ) {
719
723
this .searchField .drawTextBox ();
720
724
}
725
+
726
+ this .currentMouseX = mouseX ;
727
+ this .currentMouseY = mouseY ;
721
728
}
722
729
723
730
protected String getBackground () {
@@ -740,18 +747,29 @@ protected void repositionSlot(final AppEngSlot s) {
740
747
741
748
@ Override
742
749
protected void keyTyped (final char character , final int key ) {
743
- if (!this .checkHotbarKeys (key )) {
744
- if (character == ' ' && this .searchField .getText ().isEmpty ()) {
745
- return ;
746
- }
750
+ if (character == ' ' && this .searchField .getText ().isEmpty ()) {
751
+ return ;
752
+ }
747
753
748
- if (this .searchField .textboxKeyTyped (character , key )) {
749
- this .repo .setSearchString (this .searchField .getText ());
750
- this .repo .updateView ();
751
- this .setScrollBar ();
752
- } else {
753
- super .keyTyped (character , key );
754
- }
754
+ boolean skipHotbarCheck = searchField .isFocused ()
755
+ && (AEConfig .instance .searchBoxFocusPriority == SearchBoxFocusPriority .ALWAYS
756
+ || (AEConfig .instance .searchBoxFocusPriority == SearchBoxFocusPriority .NO_AUTOSEARCH
757
+ && !isAutoFocused ));
758
+
759
+ if (!skipHotbarCheck && checkHotbarKeys (key )) {
760
+ return ;
761
+ }
762
+
763
+ final boolean mouseInGui = this
764
+ .isPointInRegion (0 , 0 , this .xSize , this .ySize , this .currentMouseX , this .currentMouseY );
765
+
766
+ if (this .canBeAutoFocused && !searchField .isFocused () && mouseInGui ) {
767
+ searchField .setFocused (true );
768
+ isAutoFocused = true ;
769
+ }
770
+
771
+ if (!searchField .textboxKeyTyped (character , key )) {
772
+ super .keyTyped (character , key );
755
773
}
756
774
}
757
775
@@ -833,13 +851,6 @@ public void setStandardSize(final int standardSize) {
833
851
this .standardSize = standardSize ;
834
852
}
835
853
836
- @ Override
837
- public void drawScreen (final int mouseX , final int mouseY , final float btn ) {
838
- super .drawScreen (mouseX , mouseY , btn );
839
- if (ModAndClassUtil .isSearchBar && AEConfig .instance .preserveSearchBar && searchField != null )
840
- handleTooltip (mouseX , mouseY , searchField .new TooltipProvider ());
841
- }
842
-
843
854
public boolean isOverSearchField (int x , int y ) {
844
855
return searchField .isMouseIn (x , y );
845
856
}
@@ -881,4 +892,23 @@ public void setAEPins(IAEItemStack[] pins) {
881
892
public void setPinsState (PinsState state ) {
882
893
configSrc .putSetting (Settings .PINS_STATE , state );
883
894
}
895
+
896
+ @ SuppressWarnings ("SameParameterValue" )
897
+ protected boolean isPointInRegion (int rectX , int rectY , int rectWidth , int rectHeight , int pointX , int pointY ) {
898
+ pointX -= this .guiLeft ;
899
+ pointY -= this .guiTop ;
900
+ return pointX >= rectX - 1 && pointX < rectX + rectWidth + 1
901
+ && pointY >= rectY - 1
902
+ && pointY < rectY + rectHeight + 1 ;
903
+ }
904
+
905
+ // Moving items via hotbar keys in terminals isn't working anyway.
906
+ // Let's disable hotbar keys processing for terminal slots to allow proper input of numbers in the search field
907
+ @ Override
908
+ protected boolean checkHotbarKeys (int keyCode ) {
909
+ if (theSlot instanceof SlotME ) {
910
+ return false ;
911
+ }
912
+ return super .checkHotbarKeys (keyCode );
913
+ }
884
914
}
0 commit comments