added renaming feature with quartz cutting knife
This commit is contained in:
@@ -30,7 +30,7 @@ import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.bootstrap.contents.QuartzKnifeObj;
|
||||
|
||||
|
||||
public class GuiQuartzKnife extends AEBaseGui
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.container.implementations.ContainerRenamer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiRenamer extends AEBaseGui {
|
||||
private MEGuiTextField textField;
|
||||
private GuiButton confirmButton;
|
||||
|
||||
public GuiRenamer(InventoryPlayer ip, ICustomNameObject obj) {
|
||||
super(new ContainerRenamer(ip, obj));
|
||||
this.xSize = 256;
|
||||
|
||||
this.textField = new MEGuiTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 230, 12) {
|
||||
@Override
|
||||
public void onTextChange(final String oldText) {
|
||||
final String text = getText();
|
||||
|
||||
if (!text.equals(oldText)) {
|
||||
((ContainerRenamer) inventorySlots).setCustomName(text);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.textField.setEnableBackgroundDrawing(false);
|
||||
this.textField.setMaxStringLength(32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.textField.x = this.guiLeft + 12;
|
||||
this.textField.y = this.guiTop + 35;
|
||||
this.textField.setFocused(true);
|
||||
|
||||
this.buttonList.add(this.confirmButton = new GuiButton(0, this.guiLeft + 238, this.guiTop + 33, 12, 12, "↵"));
|
||||
|
||||
((ContainerRenamer) this.inventorySlots).setTextField(this.textField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.Renamer.getLocal()), 12, 8, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
this.bindTexture("guis/renamer.png");
|
||||
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
|
||||
this.textField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) throws IOException{
|
||||
this.textField.mouseClicked(xCoord, yCoord, btn);
|
||||
super.mouseClicked(xCoord, yCoord, btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) throws IOException {
|
||||
if (key == 28) { // Enter
|
||||
try {
|
||||
NetworkHandler.instance().sendToServer(
|
||||
new PacketValueConfig("QuartzKnife.ReName", this.textField.getText()));
|
||||
} catch (IOException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
this.mc.player.closeScreen();
|
||||
} else if (!this.textField.textboxKeyTyped(character, key)) {
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(final GuiButton btn) throws IOException {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
if(btn == this.confirmButton) {
|
||||
try {
|
||||
NetworkHandler.instance().sendToServer(
|
||||
new PacketValueConfig("QuartzKnife.ReName", this.textField.getText()));
|
||||
this.mc.player.closeScreen();
|
||||
} catch (IOException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOverTextField(final int mousex, final int mousey) {
|
||||
return textField.isMouseIn(mousex, mousey);
|
||||
}
|
||||
|
||||
public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) {
|
||||
textField.setText(displayName);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,8 @@ public class MEGuiTextField extends GuiTextField
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
public void onTextChange(final String oldText) {}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked( final int xPos, final int yPos, final int button )
|
||||
{
|
||||
@@ -97,6 +100,28 @@ public class MEGuiTextField extends GuiTextField
|
||||
return withinXRange && withinYRange;
|
||||
}
|
||||
|
||||
public boolean textboxKeyTyped(final char keyChar, final int keyID) {
|
||||
if (!isFocused()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String oldText = getText();
|
||||
boolean handled = super.textboxKeyTyped(keyChar, keyID);
|
||||
|
||||
if (!handled
|
||||
&& (keyID == Keyboard.KEY_RETURN
|
||||
|| keyID == Keyboard.KEY_NUMPADENTER
|
||||
|| keyID == Keyboard.KEY_ESCAPE)) {
|
||||
setFocused(false);
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
onTextChange(oldText);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public void selectAll()
|
||||
{
|
||||
this.setCursorPosition( 0 );
|
||||
@@ -127,6 +152,21 @@ public class MEGuiTextField extends GuiTextField
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text, boolean ignoreTrigger) {
|
||||
final String oldText = getText();
|
||||
|
||||
super.setText(text);
|
||||
super.setCursorPositionEnd();
|
||||
|
||||
if (!ignoreTrigger) {
|
||||
onTextChange(oldText);
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
setText(text, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelectionBox( int startX, int startY, int endX, int endY )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user