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

Commit 70b8245

Browse files
committed
first commit
0 parents  commit 70b8245

File tree

10 files changed

+641
-0
lines changed

10 files changed

+641
-0
lines changed

META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
FMLCorePlugin: org.devinprogress.inputfix.TransformerLoader
3+
Created-By: 1.7.0 (Oracle Corporation)

README.MD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Yet Another InputFix Mod
2+
Using ASM Transformer to hook into Minecraft, hoping to provide a universal solution available anywhere.
3+
Forge Required.
4+
5+
## Bugs & TODOs
6+
7+
- IBus still not work.
8+
- Make it available for GuiEditSign & GuiEditBook
9+
- Complete the Bridge system
10+
11+
## License
12+
- GPLv3
13+
- **NOT** allowed in ModPacks without my permission.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.devinprogress.inputfix;
2+
3+
import net.minecraft.client.gui.GuiScreen;
4+
import net.minecraft.client.gui.GuiTextField;
5+
6+
import javax.swing.*;
7+
8+
/**
9+
* Created by recursiveg on 14-9-11.
10+
*/
11+
public class CommonBridge implements IActionBridge{
12+
private GuiTextField txt=null;
13+
14+
public CommonBridge(GuiTextField textField,GuiScreen screen,InputFieldWrapper wrapper){
15+
txt=textField;
16+
wrapper.DoActions(ActionFeedback.SetText,txt.getText());
17+
18+
}
19+
@Override
20+
public IActionBridge.ActionFeedback onEnter(JTextField txt) {
21+
//System.out.println("[Debug Bridge][onEnter]"+txt.getText());
22+
this.txt.setText(txt.getText());
23+
return IActionBridge.ActionFeedback.Quit;
24+
}
25+
26+
@Override
27+
public IActionBridge.ActionFeedback onEsc(JTextField txt) {
28+
//System.out.println("[Debug Bridge][onEsc]"+txt.getText());
29+
return IActionBridge.ActionFeedback.Quit;
30+
}
31+
32+
@Override
33+
public IActionBridge.ActionFeedback onChanged(JTextField txt) {
34+
//System.out.println("[Debug Bridge][onChange]"+txt.getText());
35+
this.txt.setText(txt.getText());
36+
return IActionBridge.ActionFeedback.Nothing;
37+
}
38+
39+
@Override
40+
public IActionBridge.ActionFeedback onTab(JTextField txt) {
41+
//System.out.println("[Debug Bridge][onTab]"+txt.getText());
42+
return IActionBridge.ActionFeedback.Nothing;
43+
}
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.devinprogress.inputfix;
2+
3+
import net.minecraft.client.gui.GuiScreen;
4+
import net.minecraft.client.gui.GuiTextField;
5+
6+
import javax.swing.*;
7+
8+
/**
9+
* Created by recursiveg on 14-9-11.
10+
*/
11+
public class DebugBridge implements IActionBridge {
12+
13+
public DebugBridge(GuiTextField textField,GuiScreen screen,InputFieldWrapper wrapper){
14+
15+
}
16+
@Override
17+
public ActionFeedback onEnter(JTextField txt) {
18+
System.out.println("[Debug Bridge][onEnter]"+txt.getText());
19+
return ActionFeedback.Quit;
20+
}
21+
22+
@Override
23+
public ActionFeedback onEsc(JTextField txt) {
24+
System.out.println("[Debug Bridge][onEsc]"+txt.getText());
25+
return ActionFeedback.Quit;
26+
}
27+
28+
@Override
29+
public ActionFeedback onChanged(JTextField txt) {
30+
System.out.println("[Debug Bridge][onChange]"+txt.getText());
31+
return ActionFeedback.Nothing;
32+
}
33+
34+
@Override
35+
public ActionFeedback onTab(JTextField txt) {
36+
System.out.println("[Debug Bridge][onTab]"+txt.getText());
37+
return ActionFeedback.Nothing;
38+
}
39+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.devinprogress.inputfix;
2+
3+
import javax.swing.*;
4+
5+
/**
6+
* Created by recursiveg on 14-9-11.
7+
*/
8+
public interface IActionBridge {
9+
//public IActionBridge(GuiTextField textField,GuiScreen screen,InputFieldWrapper wrapper);
10+
enum ActionFeedback{
11+
Nothing,
12+
Clean,
13+
Quit,
14+
SetText
15+
}
16+
public ActionFeedback onEnter(final JTextField txt);
17+
public ActionFeedback onEsc(final JTextField txt);
18+
public ActionFeedback onChanged(final JTextField txt);
19+
public ActionFeedback onTab(final JTextField txt);
20+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (C) 2014 Fang0716
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.devinprogress.inputfix;
19+
20+
import cpw.mods.fml.client.FMLClientHandler;
21+
import net.minecraft.util.StringUtils;
22+
23+
import org.lwjgl.opengl.Display;
24+
25+
import javax.swing.*;
26+
import javax.swing.text.JTextComponent;
27+
import javax.swing.text.html.ImageView;
28+
29+
import java.awt.*;
30+
import java.awt.event.ActionEvent;
31+
import java.awt.event.KeyEvent;
32+
import java.awt.event.MouseAdapter;
33+
import java.awt.event.MouseEvent;
34+
import java.awt.event.MouseMotionAdapter;
35+
36+
public class InputBox extends JFrame {
37+
final static JFrame frame = new JFrame("Input Window");
38+
final static JTextField comp = new JTextField();
39+
final static Font font = new Font("微软雅黑", 0, 17);
40+
final static JScrollPane scroll = new JScrollPane(comp);
41+
42+
private static int x = 0;
43+
private static int y = 0;
44+
45+
public static void showGUI(String text) {
46+
47+
comp.addMouseListener(new MouseAdapter() {
48+
public void mousePressed(MouseEvent e) {
49+
x = e.getX();
50+
y = e.getY();
51+
}
52+
});
53+
54+
comp.addMouseMotionListener(new MouseMotionAdapter() {
55+
@Override
56+
public void mouseMoved(MouseEvent e) {
57+
frame.setLocation(1,1);
58+
}
59+
});
60+
61+
comp.addMouseMotionListener(new MouseMotionAdapter() {
62+
public void mouseDragged(MouseEvent e) {
63+
int left = frame.getLocation().x;
64+
int top = frame.getLocation().y;
65+
frame.setLocation(left + e.getX() - x, top + e.getY() - y);
66+
}
67+
});
68+
69+
frame.getContentPane().add(scroll, BorderLayout.CENTER);
70+
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
71+
comp.setFont(font);
72+
comp.setAutoscrolls(true);
73+
74+
if (text.equalsIgnoreCase("/")) {
75+
comp.setText(text);
76+
comp.setSelectionStart(1);
77+
comp.setSelectionEnd(1);
78+
}
79+
frame.setSize(Display.getWidth(), 25);
80+
frame.setUndecorated(true);
81+
frame.setLocation(Display.getX(), Display.getY() + Display.getHeight());
82+
frame.setAlwaysOnTop(true);
83+
frame.setVisible(true);
84+
85+
// Request focus
86+
FMLClientHandler.instance().getClient().setIngameNotInFocus();
87+
comp.requestFocus();
88+
89+
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
90+
KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
91+
InputMap inputmap = comp.getInputMap();
92+
ActionMap actionmap = comp.getActionMap();
93+
94+
Action enterAction = new AbstractAction() {
95+
@Override
96+
public void actionPerformed(ActionEvent event) {
97+
if(Main.txt!=null)
98+
Main.txt.setText(StringUtils.isNullOrEmpty(comp.getText())?"":comp.getText());
99+
comp.setText("");
100+
frame.dispose();
101+
FMLClientHandler.instance().getClient().setIngameFocus();
102+
}
103+
};
104+
105+
Action escAction = new AbstractAction() {
106+
@Override
107+
public void actionPerformed(ActionEvent event) {
108+
comp.setText("");
109+
frame.dispose();
110+
FMLClientHandler.instance().getClient().thePlayer.closeScreen();
111+
FMLClientHandler.instance().getClient().setIngameFocus();
112+
}
113+
};
114+
115+
inputmap.put(enter, "enter");
116+
inputmap.put(esc, "esc");
117+
actionmap.put("enter", enterAction);
118+
actionmap.put("esc", escAction);
119+
120+
}
121+
122+
public static void closeframe() {
123+
frame.dispose();
124+
}
125+
126+
public static boolean isFrameDisplayable() {
127+
return frame.isDisplayable();
128+
}
129+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package org.devinprogress.inputfix;
2+
3+
import cpw.mods.fml.client.FMLClientHandler;
4+
import org.lwjgl.opengl.Display;
5+
6+
import javax.swing.*;
7+
import javax.swing.event.DocumentEvent;
8+
import javax.swing.event.DocumentListener;
9+
import java.awt.*;
10+
import java.awt.event.ActionEvent;
11+
import java.awt.event.KeyEvent;
12+
import java.util.Collections;
13+
14+
/**
15+
* Created by recursiveg on 14-9-11.
16+
*/
17+
public class InputFieldWrapper {
18+
private static final int TextFieldHeight=25;
19+
private Canvas canvas = null;
20+
private JFrame frame = null;
21+
private JTextField txtField = null;
22+
private boolean Showed=false;
23+
private IActionBridge bridge=null;
24+
25+
public InputFieldWrapper(int Width,int Height){
26+
canvas =new Canvas();
27+
frame =new JFrame("Minecraft");
28+
txtField =new JTextField();
29+
30+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
31+
frame.setLayout(new BorderLayout());
32+
frame.setVisible(true);
33+
frame.add(canvas,BorderLayout.CENTER);
34+
try {
35+
Display.setParent(canvas);
36+
}catch(Exception e){
37+
e.printStackTrace();
38+
}
39+
frame.setPreferredSize(new Dimension(Width, Height));
40+
frame.pack();
41+
42+
txtField.setVisible(false);
43+
txtField.setPreferredSize(new Dimension(Width, TextFieldHeight));
44+
bindKeys();
45+
frame.add(txtField, BorderLayout.PAGE_END);
46+
47+
frame.pack();
48+
frame.validate();
49+
}
50+
51+
public void show(){
52+
buildBridge();
53+
if(Showed)return;
54+
Showed=true;
55+
frame.setSize(new Dimension(frame.getWidth(), frame.getHeight() + TextFieldHeight));
56+
txtField.setVisible(true);
57+
txtField.setCaretPosition(txtField.getText().length());
58+
//txtField.setText("");
59+
FMLClientHandler.instance().getClient().setIngameNotInFocus();
60+
txtField.requestFocus();
61+
frame.validate();
62+
}
63+
public void hide(){
64+
bridge=null;
65+
if(!Showed)return;
66+
Showed=false;
67+
txtField.setVisible(false);
68+
txtField.setText("");
69+
frame.setSize(new Dimension(frame.getWidth(), frame.getHeight() - TextFieldHeight));
70+
canvas.requestFocus();
71+
FMLClientHandler.instance().getClient().setIngameFocus();
72+
frame.validate();
73+
}
74+
public void DoActions(IActionBridge.ActionFeedback action, Object obj){
75+
if(action== IActionBridge.ActionFeedback.Quit){
76+
hide();
77+
}else if(action== IActionBridge.ActionFeedback.Nothing){
78+
return;
79+
}else if(action== IActionBridge.ActionFeedback.SetText){
80+
if (obj instanceof String)
81+
txtField.setText((String)obj);
82+
}else if(action== IActionBridge.ActionFeedback.Clean){
83+
txtField.setText("");
84+
}
85+
}
86+
87+
private void bindKeys(){
88+
InputMap inputmap = txtField.getInputMap();
89+
ActionMap actionmap = txtField.getActionMap();
90+
91+
txtField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
92+
txtField.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
93+
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
94+
KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
95+
KeyStroke tab=KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0);
96+
Action enterAction = new AbstractAction() {
97+
@Override
98+
public void actionPerformed(ActionEvent event) {
99+
if(bridge!=null)DoActions(bridge.onEnter(txtField),null);
100+
}
101+
};
102+
Action escAction = new AbstractAction() {
103+
@Override
104+
public void actionPerformed(ActionEvent event) {
105+
if(bridge!=null)DoActions(bridge.onEsc(txtField),null);
106+
}
107+
};
108+
Action tabAction = new AbstractAction() {
109+
@Override
110+
public void actionPerformed(ActionEvent event) {
111+
if(bridge!=null)DoActions(bridge.onTab(txtField),null);
112+
}
113+
};
114+
inputmap.put(enter, "enter");actionmap.put("enter", enterAction);
115+
inputmap.put(esc, "esc");actionmap.put("esc", escAction);
116+
inputmap.put(tab,"tab");actionmap.put("tab",tabAction);
117+
txtField.getDocument().addDocumentListener(new DocumentListener() {
118+
@Override
119+
public void insertUpdate(DocumentEvent e) {
120+
if(bridge!=null)DoActions(bridge.onChanged(txtField),null);
121+
}
122+
123+
@Override
124+
public void removeUpdate(DocumentEvent e) {
125+
if(bridge!=null)DoActions(bridge.onChanged(txtField),null);
126+
}
127+
128+
@Override
129+
public void changedUpdate(DocumentEvent e) {
130+
131+
}
132+
});
133+
}
134+
135+
private void buildBridge(){//TODO
136+
//bridge=new DebugBridge(Main.currentTextField,Main.currentGuiScreen,this);
137+
bridge=new CommonBridge(Main.currentTextField,Main.currentGuiScreen,this);
138+
}
139+
}

0 commit comments

Comments
 (0)