Skip to content
This repository was archived by the owner on Jan 3, 2020. It is now read-only.

Commit 98d6153

Browse files
committed
add CommonBridge
1 parent 34da3b3 commit 98d6153

File tree

9 files changed

+94
-15
lines changed

9 files changed

+94
-15
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ group= "org.devinprogress.YAIF" // http://maven.apache.org/guides/mini/guide-nam
2222
archivesBaseName = "YetAnotherInputFix"
2323

2424
minecraft {
25-
version = "1.7.2-10.12.2.1121"
25+
version = "1.7.2-10.12.2.1147"
2626
assetDir = "eclipse/assets"
2727
}
2828

src/main/java/org/devinprogress/YAIF/Bridges/CommonBridge.java

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,44 @@
33
import net.minecraft.client.gui.GuiScreen;
44
import net.minecraft.client.gui.GuiTextField;
55
import org.devinprogress.YAIF.InputFieldWrapper;
6+
import org.devinprogress.YAIF.YetAnotherInputFix;
67

78
import javax.swing.*;
9+
import java.lang.reflect.Method;
810

911
/**
1012
* Created by recursiveg on 14-9-11.
1113
*/
1214
public class CommonBridge implements IActionBridge{
13-
private GuiTextField txt=null;
14-
15-
public CommonBridge(GuiTextField textField,InputFieldWrapper wrapper){
16-
txt=textField;
17-
wrapper.DoActions(ActionFeedback.SetText,txt.getText());
18-
15+
private GuiScreen scr=null;
16+
private Method M_keyTyped=null;
17+
private InputFieldWrapper wrapper=null;
18+
public CommonBridge(GuiScreen screen,InputFieldWrapper wrapper){
19+
scr=screen;
20+
this.wrapper=wrapper;
21+
try{
22+
M_keyTyped=scr.getClass().getDeclaredMethod(YetAnotherInputFix.ObfuscatedEnv?"func_73869_a":"keyTyped",char.class,int.class);
23+
M_keyTyped.setAccessible(true);
24+
}catch(Exception e){
25+
e.printStackTrace();
26+
}
1927
}
2028
@Override
2129
public IActionBridge.ActionFeedback onEnter(JTextField txt) { //send msg
22-
this.txt.setText(txt.getText());
23-
return IActionBridge.ActionFeedback.Quit;
30+
try{
31+
String str=txt.getText();
32+
if(str.length()==0){
33+
M_keyTyped.invoke(scr,'\n',28);
34+
}else{
35+
for(int i=0;i<str.length();i++){
36+
M_keyTyped.invoke(scr,str.charAt(i),-1);
37+
}
38+
wrapper.setTextNoEvent("");
39+
}
40+
}catch(Exception e){
41+
e.printStackTrace();
42+
}
43+
return null;
2444
}
2545

2646
@Override
@@ -30,7 +50,6 @@ public IActionBridge.ActionFeedback onEsc(JTextField txt) {
3050

3151
@Override
3252
public IActionBridge.ActionFeedback onChange(JTextField txt) {
33-
this.txt.setText(txt.getText());
3453
return IActionBridge.ActionFeedback.Nothing;
3554
}
3655

@@ -48,8 +67,26 @@ public ActionFeedback onUp(JTextField txt) {
4867
public ActionFeedback onDown(JTextField txt) {
4968
return null;
5069
}
70+
71+
@Override
72+
public ActionFeedback onBackspace(JTextField txt) {
73+
try{
74+
String str=txt.getText();
75+
if(str.length()==0) {
76+
M_keyTyped.invoke(scr, ' ', 14);
77+
}else{
78+
String str2=txt.getText();
79+
str2=str2.substring(0,str2.length()-1);
80+
wrapper.setTextNoEvent(str2);
81+
}
82+
}catch(Exception e){
83+
e.printStackTrace();
84+
}
85+
return null;
86+
}
87+
5188
@Override
5289
public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
53-
return txtField==txt;
90+
return scr==screen;
5491
}
5592
}

src/main/java/org/devinprogress/YAIF/Bridges/DebugBridge.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public ActionFeedback onUp(JTextField txt) {
4747
public ActionFeedback onDown(JTextField txt) {
4848
return null;
4949
}
50+
51+
@Override
52+
public ActionFeedback onBackspace(JTextField txt) {
53+
return null;
54+
}
55+
5056
@Override
5157
public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
5258
return false;

src/main/java/org/devinprogress/YAIF/Bridges/EditBookBridge.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public ActionFeedback onDown(JTextField txt) {
7070
return null;
7171
}
7272

73+
@Override
74+
public ActionFeedback onBackspace(JTextField txt) {
75+
return null;
76+
}
77+
7378
@Override
7479
public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
7580
return false;

src/main/java/org/devinprogress/YAIF/Bridges/EditSignBridge.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public ActionFeedback onDown(JTextField txt) {
100100
return null;
101101
}
102102

103+
@Override
104+
public ActionFeedback onBackspace(JTextField txt) {
105+
String str2=txt.getText();
106+
str2=str2.substring(0,str2.length()-1);
107+
wrapper.setTextNoEvent(str2);
108+
return onChange(txt);
109+
}
110+
103111
@Override
104112
public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
105113
return screen==gui;

src/main/java/org/devinprogress/YAIF/Bridges/GuiChatBridge.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ public ActionFeedback onDown(JTextField txt) {
127127
return null;
128128
}
129129

130+
@Override
131+
public ActionFeedback onBackspace(JTextField txt) {
132+
String str2=txt.getText();
133+
str2=str2.substring(0,str2.length()-1);
134+
wrapper.setTextNoEvent(str2);
135+
return onChange(txt);
136+
}
137+
130138
@Override
131139
public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
132140
return this.screen==screen && txtField==txt;

src/main/java/org/devinprogress/YAIF/Bridges/IActionBridge.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ enum ActionFeedback{
2424
public ActionFeedback onTab(final JTextField txt);
2525
public ActionFeedback onUp(final JTextField txt);
2626
public ActionFeedback onDown(final JTextField txt);
27+
public ActionFeedback onBackspace(final JTextField txt);
2728
public boolean sameAs(GuiScreen screen,GuiTextField txtField);
2829
}

src/main/java/org/devinprogress/YAIF/InputFieldWrapper.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cpw.mods.fml.client.FMLClientHandler;
44
import net.minecraft.client.gui.GuiChat;
55
import net.minecraft.client.gui.inventory.GuiEditSign;
6+
import org.devinprogress.YAIF.Bridges.CommonBridge;
67
import org.devinprogress.YAIF.Bridges.EditSignBridge;
78
import org.devinprogress.YAIF.Bridges.GuiChatBridge;
89
import org.devinprogress.YAIF.Bridges.IActionBridge;
@@ -90,6 +91,7 @@ private void bindKeys(){
9091
KeyStroke tab=KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0);
9192
KeyStroke up=KeyStroke.getKeyStroke(KeyEvent.VK_UP,0);
9293
KeyStroke down=KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0);
94+
KeyStroke backsp=KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE,0);
9395

9496
//TODO: to see if the `if` can be removed
9597
Action enterAction = new AbstractAction() {
@@ -122,6 +124,12 @@ public void actionPerformed(ActionEvent event) {
122124
if(bridge!=null)DoActions(bridge.onDown(txtField),null);
123125
}
124126
};
127+
Action backspAction=new AbstractAction() {
128+
@Override
129+
public void actionPerformed(ActionEvent e) {
130+
if(bridge!=null)DoActions(bridge.onBackspace(txtField),null);
131+
}
132+
};
125133
txtField.getDocument().addDocumentListener(new DocumentListener() {
126134
@Override
127135
public void insertUpdate(DocumentEvent e) {
@@ -147,6 +155,7 @@ public void changedUpdate(DocumentEvent e) {
147155
inputmap.put(tab,"tab");actionmap.put("tab", tabAction);
148156
inputmap.put(up,"up");actionmap.put("up", upAction);
149157
inputmap.put(down,"down");actionmap.put("down", downAction);
158+
inputmap.put(backsp,"backsp");actionmap.put("backsp",backspAction);
150159
}
151160

152161
public void setEnabled(boolean flag){ //Reserved for further use
@@ -208,9 +217,8 @@ private IActionBridge getBridge(){//Remember to add cases here if new Bridges ad
208217
}
209218
else if(YetAnotherInputFix.currentGuiScreen instanceof GuiEditSign)
210219
return new EditSignBridge((GuiEditSign)YetAnotherInputFix.currentGuiScreen,this);
211-
else
212-
return null;
213-
//else bridge=new CommonBridge(YetAnotherInputFix.currentTextField, this);
220+
//else return null;
221+
else return new CommonBridge(YetAnotherInputFix.currentGuiScreen, this);
214222
}
215223

216224
public void setTextNoEvent(final String str){

src/main/java/org/devinprogress/YAIF/YetAnotherInputFix.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import cpw.mods.fml.common.gameevent.TickEvent;
1010
import net.minecraft.client.gui.GuiNewChat;
1111
import net.minecraft.client.gui.GuiScreen;
12+
import net.minecraft.client.gui.GuiScreenBook;
1213
import net.minecraft.client.gui.GuiTextField;
1314
import net.minecraft.client.gui.inventory.GuiEditSign;
1415
import net.minecraft.client.settings.KeyBinding;
@@ -66,6 +67,11 @@ public void onGuiChange(GuiScreenEvent.InitGuiEvent.Post e) {
6667
currentTextField=null;
6768
wrapper.show();
6869
}
70+
if(e.gui instanceof GuiScreenBook){
71+
currentGuiScreen=e.gui;
72+
currentTextField=null;
73+
wrapper.show();
74+
}
6975
}
7076

7177
//Multi-threading is a problem
@@ -89,7 +95,7 @@ public void tryGetFocus(TickEvent.ClientTickEvent event){
8995

9096
@SubscribeEvent
9197
public void onGuiClosing(GuiOpenEvent e){
92-
if(e.gui==null&&FMLClientHandler.instance().getClient().currentScreen==currentGuiScreen)
98+
if(e.gui==null&&FMLClientHandler.instance().getClient().currentScreen==currentGuiScreen&&wrapper!=null)
9399
wrapper.hide();
94100
}
95101

0 commit comments

Comments
 (0)