Backport some JEI features

* Licensed under LGPL
* Remove TMI style
* Remove Load/Save inventory state
* Reworked ItemPanel so it's no longer used statically
* BookmarkPanel inherits from ItemPanel
* Rework LayoutManager
* Bookmarks - including loading & saving
* Utility/Cheat buttons line up and wrap based on GUI size
This commit is contained in:
Jason Mitchell committed 2019-12-30 14:32:55 -08:00
1 parent 5087a95e02
commit 6d9ff9ea0a
54 files changed
+1604 -919

No files matched your search

+55 -75
View File
@@ -1,43 +1,44 @@
package codechicken.nei;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ChatAllowedCharacters;
import cpw.mods.fml.client.config.HoverChecker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import static codechicken.lib.gui.GuiDraw.*;
public abstract class TextField extends Widget
{
protected GuiTextField field;
protected final HoverChecker hoverChecker;
private static final int maxSearchLength = 256;
public boolean centered;
public String identifier;
private boolean previousKeyboardRepeatEnabled;
public TextField(String ident) {
identifier = ident;
field = new GuiTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0);
field.setMaxStringLength(maxSearchLength);
this.hoverChecker = new HoverChecker(0, 0, 0, 0, 0);
field.setCursorPositionZero();
// Keyboard.enableRepeatEvents(true);
}
public int getTextColour() {
return focused() ? 0xFFE0E0E0 : 0xFF909090;
}
public void drawBox() {
drawRect(x, y, w, h, 0xffA0A0A0);
drawRect(x + 1, y + 1, w - 2, h - 2, 0xFF000000);
}
@Override
public void draw(int mousex, int mousey) {
drawBox();
field.xPosition = this.x + 2;
field.yPosition = this.y + 2;
field.width = this.w - 4;
field.height = this.h - 4;
field.setTextColor(getTextColour());
String drawtext = text;
int textWidth;
while((textWidth = getStringWidth(drawtext)) > w - 14)
drawtext = drawtext.substring(1);
if (focused() && (cursorCounter / 6) % 2 == 0)
drawtext = drawtext + '_';
int textx = centered ? x + (w - textWidth) / 2 : x + 4;
int texty = y + (h + 1) / 2 - 3;
drawString(drawtext, textx, texty, getTextColour());
field.drawTextBox();
}
@Override
@@ -48,9 +49,13 @@ public abstract class TextField extends Widget
@Override
public boolean handleClick(int mousex, int mousey, int button) {
setFocus(true);
if (button == 1)
setText("");
setFocus(true);
else
field.mouseClicked(mousex, mousey, button);
return true;
}
@@ -59,58 +64,32 @@ public abstract class TextField extends Widget
if (!focused())
return false;
if (keyID == Keyboard.KEY_BACK) {
if (text.length() > 0) {
setText(text.substring(0, text.length() - 1));
backdowntime = System.currentTimeMillis();
boolean handled = field.textboxKeyTyped(keyChar, keyID);
if(!handled) {
if (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_NUMPADENTER || keyID == Keyboard.KEY_ESCAPE) {
setFocus(false);
handled = true;
}
} else if (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_ESCAPE) {
setFocus(false);
onExit();
} else if (keyChar == 22)//paste
{
String pastestring = GuiScreen.getClipboardString();
if (pastestring == null)
pastestring = "";
}
if (isValid(text + pastestring))
setText(text + pastestring);
} else if (isValid(text + keyChar))
setText(text + keyChar);
if(handled) {
onTextChange(text());
}
return true;
}
return handled;
public void onExit() {
}
public abstract void onTextChange(String oldText);
public boolean isValid(String string) {
// Solve the problem that Minecraft can't post Chinese characters
return ChatAllowedCharacters.isAllowedCharacter(string.charAt(string.length() - 1));
}
@Override
public void update() {
cursorCounter++;
if (backdowntime > 0) {
if (Keyboard.isKeyDown(Keyboard.KEY_BACK) && text.length() > 0) {
if (System.currentTimeMillis() - backdowntime > 200 / (1 + backs * 0.3F)) {
setText(text.substring(0, text.length() - 1));
backdowntime = System.currentTimeMillis();
backs++;
}
} else {
backdowntime = 0;
backs = 0;
}
}
}
public void setText(String s) {
String oldText = text;
text = filterText(s);
String oldText = text();
field.setText(s);
field.setCursorPositionZero();
onTextChange(oldText);
}
@@ -119,25 +98,26 @@ public abstract class TextField extends Widget
}
public void setFocus(boolean focus) {
if (focus) {
LayoutManager.setInputFocused(this);
} else if (focused()) {
LayoutManager.setInputFocused(null);
final boolean previousFocus = field.isFocused();
field.setFocused(focus);
if (previousFocus != focus) {
if (focus) {
previousKeyboardRepeatEnabled = Keyboard.areRepeatEventsEnabled();
Keyboard.enableRepeatEvents(true);
} else {
Keyboard.enableRepeatEvents(previousKeyboardRepeatEnabled);
}
}
}
public boolean focused() {
return LayoutManager.getInputFocused() == this;
return field.isFocused();
}
public String text() {
return text;
return field.getText();
}
private String text = "";
public boolean centered;
public long backdowntime;
public int backs;
public String identifier;
public int cursorCounter;
}