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

Commit b69e85f

Browse files
committed
ugly patch to focus issue
1 parent af3068a commit b69e85f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public GuiChatBridge(GuiTextField textField,GuiChat screen,InputFieldWrapper wra
4444
@Override
4545
public ActionFeedback onEnter(JTextField txt) { //send
4646
this.txt.setText(txt.getText());
47-
/*try {
47+
try {
4848
keyTypedMethod.invoke(screen, '\n', 28);//Magic Numbers can be found at http://minecraft.gamepedia.com/Key_Codes
4949
}catch(Exception e){
5050
e.printStackTrace();
51-
}*/
51+
}
5252
return ActionFeedback.Quit;
5353
}
5454

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void hide(){
179179

180180
canvas.requestFocusInWindow();
181181
frame.validate();
182-
FMLClientHandler.instance().getClient().setIngameFocus();
182+
YetAnotherInputFix.needFocus=true;
183183
}
184184

185185
public void DoActions(IActionBridge.ActionFeedback action, Object obj){

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
88
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
99
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
10+
import cpw.mods.fml.common.gameevent.TickEvent;
1011
import cpw.mods.fml.common.versioning.ArtifactVersion;
1112
import cpw.mods.fml.common.versioning.VersionRange;
1213
import net.minecraft.client.gui.GuiScreen;
@@ -16,6 +17,7 @@
1617
import net.minecraftforge.client.event.GuiOpenEvent;
1718
import net.minecraftforge.client.event.GuiScreenEvent;
1819
import net.minecraftforge.common.MinecraftForge;
20+
import org.lwjgl.opengl.Display;
1921

2022
import java.io.File;
2123
import java.lang.reflect.Field;
@@ -38,6 +40,7 @@ public class YetAnotherInputFix{
3840
private static InputFieldWrapper wrapper =null;
3941
public static GuiTextField txt = null;
4042
public static final Logger logger=Logger.getLogger("YAIF");
43+
public static boolean needFocus=false;
4144

4245
//Will be called before the Constructor! Be careful.
4346
public static void SetupTextFieldWrapper(int W, int H){
@@ -47,6 +50,7 @@ public static void SetupTextFieldWrapper(int W, int H){
4750
@Mod.EventHandler
4851
public void load(FMLInitializationEvent event) {
4952
MinecraftForge.EVENT_BUS.register(this);
53+
FMLCommonHandler.instance().bus().register(this);
5054
}
5155

5256
@SubscribeEvent
@@ -61,6 +65,23 @@ public void onGuiChange(GuiScreenEvent.InitGuiEvent.Post e) {
6165
}
6266
}
6367

68+
//Multi-threading is a problem
69+
//TODO: UGLY PATCH!!!
70+
@SubscribeEvent
71+
public void tryGetFocus(TickEvent.ClientTickEvent event){
72+
if(needFocus){
73+
try{
74+
Display.makeCurrent();
75+
}catch(Exception e){
76+
e.printStackTrace();
77+
}
78+
if(Display.isActive()){
79+
FMLClientHandler.instance().getClient().setIngameFocus();
80+
needFocus=false;
81+
}
82+
}
83+
}
84+
6485
public static void TextFieldFocusChange(GuiTextField textField, boolean isFocused) {
6586
if (isFocused) {
6687
/*if (currentGuiScreen != null) {

0 commit comments

Comments
 (0)