5
5
import net .minecraft .client .gui .GuiScreen ;
6
6
import net .minecraft .client .gui .GuiTextField ;
7
7
import org .devinprogress .YAIF .InputFieldWrapper ;
8
+ import org .devinprogress .YAIF .YetAnotherInputFix ;
8
9
import org .lwjgl .input .Keyboard ;
9
10
10
11
import javax .swing .*;
12
+ import java .awt .event .ActionEvent ;
13
+ import java .awt .event .KeyEvent ;
11
14
12
15
/**
13
16
* Created by recursiveg on 14-9-13.
@@ -17,102 +20,131 @@ public class GuiChatBridge extends BaseActionBridge {
17
20
private GuiTextField txt =null ;
18
21
private InputFieldWrapper wrapper =null ;
19
22
20
- private boolean isCmd =false ;
21
- //private static Method keyTypedMethod=null;
22
-
23
23
public GuiChatBridge (GuiTextField textField ,GuiChat screen ,InputFieldWrapper wrapper ){
24
24
this .screen =screen ;
25
25
txt =textField ;
26
26
this .wrapper =wrapper ;
27
- //wrapper.DoActions(ActionFeedback.SetText,txt.getText());
28
-
29
- if (screen .defaultInputFieldText .equals ("/" ))
30
- isCmd =true ;
31
- else
32
- isCmd =false ;
33
27
}
34
- /*
35
- @Override
36
- public ActionFeedback onEnter(JTextField txt) { //send
37
- this.txt.setText(txt.getText());
38
- screen.keyTyped('\n', 28);//Magic Numbers can be found at http://minecraft.gamepedia.com/Key_Codes
39
- Keyboard.enableRepeatEvents(false);
40
- FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().resetScroll();
41
28
42
- return ActionFeedback.Quit;
29
+ @ Override
30
+ public boolean needShow (){
31
+ return !screen .defaultInputFieldText .equals ("/" );
43
32
}
44
33
45
34
@ Override
46
- public ActionFeedback onEsc(JTextField txt) {
47
- //SetInGameFocus will close the GuiChat.
48
- Keyboard.enableRepeatEvents(false);
49
- FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().resetScroll();
50
- return ActionFeedback.Quit;
35
+ public void bindKeys (JTextField tf ){
36
+ super .bindKeys (tf );
37
+
38
+ bindKey (tf , KeyEvent .VK_ENTER ,"enter" , new AbstractAction () {
39
+ @ Override
40
+ public void actionPerformed (ActionEvent e ) {
41
+ txt .setText (wrapper .getText ());
42
+ screen .keyTyped ('\n' , 28 );
43
+ wrapper .bridgeQuit ();
44
+ }
45
+ });
46
+
47
+ bindKey (tf , KeyEvent .VK_ESCAPE , "esc" , new AbstractAction () {
48
+ @ Override
49
+ public void actionPerformed (ActionEvent e ) {
50
+ YetAnotherInputFix .log ("GuiChatBridge ESC Pressed" );
51
+ wrapper .bridgeQuit ();
52
+ }
53
+ });
54
+
55
+ bindKey (tf ,KeyEvent .VK_UP ,"up" ,new AbstractAction () {
56
+ @ Override
57
+ public void actionPerformed (ActionEvent e ) {
58
+ dispatch (new Runnable () {
59
+ @ Override
60
+ public void run () {
61
+ screen .keyTyped (' ' , 200 );
62
+ SwingUtilities .invokeLater (new Runnable () {
63
+ @ Override
64
+ public void run () {
65
+ textChangedByBridge =true ;
66
+ wrapper .setText (txt .getText ());
67
+ }
68
+ });
69
+ }
70
+ });
71
+ }
72
+ });
73
+
74
+ bindKey (tf ,KeyEvent .VK_DOWN ,"down" ,new AbstractAction () {
75
+ @ Override
76
+ public void actionPerformed (ActionEvent e ) {
77
+ dispatch (new Runnable () {
78
+ @ Override
79
+ public void run () {
80
+ screen .keyTyped (' ' , 208 );
81
+ SwingUtilities .invokeLater (new Runnable () {
82
+ @ Override
83
+ public void run () {
84
+ textChangedByBridge =true ;
85
+ wrapper .setText (txt .getText ());
86
+ }
87
+ });
88
+ }
89
+ });
90
+ }
91
+ });
92
+
93
+ bindKey (tf , KeyEvent .VK_TAB , "tab" , new AbstractAction () {
94
+ @ Override
95
+ public void actionPerformed (ActionEvent e ) {
96
+ final int cursorPos =wrapper .getCaretPosition ();
97
+ dispatch (new Runnable () {
98
+ @ Override
99
+ public void run () {
100
+ txt .setCursorPosition (cursorPos );
101
+ screen .keyTyped ('\t' ,15 );
102
+ final String str =txt .getText ();
103
+ final int pos =txt .getCursorPosition ();
104
+ SwingUtilities .invokeLater (new Runnable () {
105
+ @ Override
106
+ public void run () {
107
+ textChangedByBridge =true ;
108
+ wrapper .setText (str ,pos );
109
+ }
110
+ });
111
+ }
112
+ });
113
+ }
114
+ });
115
+
116
+ setListenDocumentEvent (tf );
51
117
}
52
118
53
119
@ Override
54
- public ActionFeedback onChange(final JTextField txt) {
55
- final String str;
56
- if(txt.getText().length()>100){
57
- str=txt.getText().substring(0,100);
120
+ protected void textUpdated (){
121
+ final String str =wrapper .getText ();
122
+ if (str .length ()>100 ){
58
123
SwingUtilities .invokeLater (new Runnable () {
59
124
@ Override
60
125
public void run () {
61
- txt.setText(str);
126
+ textChangedByBridge =true ;
127
+ wrapper .setText (str .substring (0 ,100 ));
62
128
}
63
129
});
64
- }else{
65
- str=txt.getText();
130
+ this .txt .setText (str .substring (0 ,100 ));
131
+ }else {
132
+ this .txt .setText (str );
66
133
}
67
- this.txt.setText(str);
68
- return BaseActionBridge.ActionFeedback.Nothing;
69
- }
70
-
71
- @Override
72
- public ActionFeedback onTab(JTextField txt) {
73
- //You have to listen to S3APacketTabComplete to get the compliance result.
74
- //YetAnotherInputFix.logger.info("Tab Completion not finished yet.");
75
- int cursorPos=txt.getCaretPosition();
76
- this.txt.setCursorPosition(cursorPos);
77
- screen.keyTyped('\t',15);
78
- wrapper.setTextNoEvent(this.txt.getText());
79
- //TODO: Finish it.
80
- return null;//return null == return Nothing
81
- }
82
-
83
- @Override
84
- public ActionFeedback onUp(JTextField txt) {
85
- screen.keyTyped( ' ', 200);
86
- wrapper.setTextNoEvent(this.txt.getText());
87
- return null;
88
134
}
89
135
90
136
@ Override
91
- public ActionFeedback onDown(JTextField txt) {
92
- screen.keyTyped(' ', 208);
93
- wrapper.setTextNoEvent(this.txt.getText());
94
- return null;
137
+ public void onTabComplete (GuiChat screen ){
138
+ if (screen !=this .screen )
139
+ throw new RuntimeException ("WTF onTabComplete Received but screen not match?!" );
140
+ final String str =txt .getText ();
141
+ final int pos =txt .getCursorPosition ();
142
+ SwingUtilities .invokeLater (new Runnable () {
143
+ @ Override
144
+ public void run () {
145
+ textChangedByBridge =true ;
146
+ wrapper .setText (str ,pos );
147
+ }
148
+ });
95
149
}
96
-
97
- @Override
98
- public ActionFeedback onBackspace(JTextField txt) {
99
- String str2=txt.getText();
100
- str2=str2.substring(0,str2.length()-1);
101
- wrapper.setTextNoEvent(str2);
102
- return onChange(txt);
103
- }
104
-
105
- @Override
106
- public void onTabComplete(JTextField txt) {
107
- wrapper.setTextNoEvent(this.txt.getText());
108
- }
109
-
110
- @Override
111
- public boolean sameAs(GuiScreen screen, GuiTextField txtField) {
112
- return this.screen==screen && txtField==txt;
113
- }
114
-
115
- public boolean isCommand(){
116
- return isCmd;
117
- }*/
118
150
}
0 commit comments