|
6 | 6 | import net.minecraft.client.gui.GuiTextField;
|
7 | 7 | import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
8 | 8 | import net.minecraft.client.gui.inventory.GuiEditSign;
|
9 |
| -import org.devinprogress.yaif.bridges.*; |
| 9 | +import org.devinprogress.yaif.bridges.BaseActionBridge; |
| 10 | +import org.devinprogress.yaif.bridges.DoNothingBridge; |
| 11 | +import org.devinprogress.yaif.bridges.EditSignBridge; |
| 12 | +import org.devinprogress.yaif.bridges.GuiChatBridge; |
10 | 13 |
|
11 | 14 | import java.lang.reflect.Field;
|
12 | 15 | import java.util.HashSet;
|
|
18 | 21 |
|
19 | 22 | /* NEVER try to figure out how this f**king machine works */
|
20 | 23 | public class GuiStateManager {
|
21 |
| - private static GuiStateManager INSTANCE=null; |
22 |
| - private InputFieldWrapper wrapper=null; |
23 |
| - private GuiScreen currentScreen=null,incomingScreen=null; |
24 |
| - private GuiTextField currentTextField=null; |
25 |
| - private BaseActionBridge bridge=null; |
26 |
| - private Set<Class> InputableGui=new HashSet<Class>(){{add(GuiEditSign.class);add(GuiScreenBook.class);}}; |
27 |
| - private Set<Class> UnInputableGui=new HashSet<Class>(); |
28 |
| - |
29 |
| - private GuiStateManager(){ |
30 |
| - if (INSTANCE!=null) |
| 24 | + private static GuiStateManager INSTANCE = null; |
| 25 | + private InputFieldWrapper wrapper = null; |
| 26 | + private GuiScreen currentScreen = null, incomingScreen = null; |
| 27 | + private GuiTextField currentTextField = null; |
| 28 | + private BaseActionBridge bridge = null; |
| 29 | + private Set<Class> InputableGui = new HashSet<Class>() {{ |
| 30 | + add(GuiEditSign.class); |
| 31 | + add(GuiScreenBook.class); |
| 32 | + }}; |
| 33 | + private Set<Class> UnInputableGui = new HashSet<Class>(); |
| 34 | + |
| 35 | + private GuiStateManager() { |
| 36 | + if (INSTANCE != null) |
31 | 37 | throw new RuntimeException("Duplicated Initialization for GuiStateManager");
|
32 | 38 | }
|
33 | 39 |
|
34 |
| - public static GuiStateManager getInstance(){ |
35 |
| - if(INSTANCE==null) |
36 |
| - INSTANCE=new GuiStateManager(); |
| 40 | + public static GuiStateManager getInstance() { |
| 41 | + if (INSTANCE == null) |
| 42 | + INSTANCE = new GuiStateManager(); |
37 | 43 | return INSTANCE;
|
38 | 44 | }
|
39 | 45 |
|
40 |
| - public void setWrapper(InputFieldWrapper w){ |
41 |
| - if(wrapper!=null) |
| 46 | + public void setWrapper(InputFieldWrapper w) { |
| 47 | + if (wrapper != null) |
42 | 48 | throw new RuntimeException("InputFieldWrapper already set.");
|
43 |
| - wrapper=w; |
| 49 | + wrapper = w; |
44 | 50 | }
|
45 | 51 |
|
46 | 52 | public void TextFieldFocusChanged(GuiScreen screen, GuiTextField textField, boolean isFocused) {
|
47 |
| - if(isFocused){ |
48 |
| - if(screen==currentScreen){//textField switched in the same GUI |
| 53 | + if (isFocused) { |
| 54 | + if (screen == currentScreen) {//textField switched in the same GUI |
49 | 55 | wrapper.releaseCurrentBridge();
|
50 |
| - currentTextField=textField; |
51 |
| - bridge=getNewBridge(); |
| 56 | + currentTextField = textField; |
| 57 | + bridge = getNewBridge(); |
52 | 58 | wrapper.setupBridge(bridge);
|
53 |
| - }else{//the TextField in a new bridge |
54 |
| - if(screen==incomingScreen) { |
| 59 | + } else {//the TextField in a new bridge |
| 60 | + if (screen == incomingScreen) { |
55 | 61 | currentScreen = screen;
|
56 |
| - incomingScreen=null; |
| 62 | + incomingScreen = null; |
57 | 63 | currentTextField = textField;
|
58 | 64 | bridge = getNewBridge();
|
59 | 65 | wrapper.setupBridge(bridge);
|
60 | 66 | }/*else{
|
61 | 67 | YetAnotherInputFix.log("WTF TextField %s Init without screen?",textField);
|
62 | 68 | }*/
|
63 | 69 | }
|
64 |
| - }else{ |
65 |
| - if(textField==currentTextField) { |
| 70 | + } else { |
| 71 | + if (textField == currentTextField) { |
66 | 72 | wrapper.releaseCurrentBridge();
|
67 | 73 | bridge = null;
|
68 |
| - currentTextField=null; |
| 74 | + currentTextField = null; |
69 | 75 | }
|
70 |
| - if(currentScreen instanceof GuiContainerCreative) { |
| 76 | + if (currentScreen instanceof GuiContainerCreative) { |
71 | 77 | wrapper.closeInputField();
|
72 |
| - bridge=null; |
| 78 | + bridge = null; |
73 | 79 | }
|
74 | 80 | }
|
75 | 81 | }
|
76 | 82 |
|
77 | 83 | private BaseActionBridge getNewBridge() {
|
78 |
| - if(currentScreen instanceof GuiChat) |
79 |
| - return new GuiChatBridge(currentTextField,(GuiChat)currentScreen,wrapper); |
80 |
| - else if(currentScreen instanceof GuiEditSign) |
81 |
| - return new EditSignBridge((GuiEditSign)currentScreen,wrapper); |
| 84 | + if (currentScreen instanceof GuiChat) |
| 85 | + return new GuiChatBridge(currentTextField, (GuiChat) currentScreen, wrapper); |
| 86 | + else if (currentScreen instanceof GuiEditSign) |
| 87 | + return new EditSignBridge((GuiEditSign) currentScreen, wrapper); |
82 | 88 | else
|
83 | 89 | return new DoNothingBridge();
|
84 | 90 | }
|
85 | 91 |
|
86 | 92 | public void onTabCompletePacket(GuiScreen screen) {
|
87 | 93 | GuiChat chatScreen;
|
88 |
| - if(screen instanceof GuiChat) |
89 |
| - chatScreen=(GuiChat)screen; |
| 94 | + if (screen instanceof GuiChat) |
| 95 | + chatScreen = (GuiChat) screen; |
90 | 96 | else
|
91 | 97 | throw new RuntimeException("PacketTabComplete Received but GuiChat was not shown.");
|
92 | 98 | bridge.onTabComplete(chatScreen);
|
93 | 99 | }
|
94 | 100 |
|
95 |
| - public void preInitGuiEvent(GuiScreen gui){ |
96 |
| - if(hasGuiTextField(gui)) |
97 |
| - incomingScreen=gui; |
| 101 | + public void preInitGuiEvent(GuiScreen gui) { |
| 102 | + if (hasGuiTextField(gui)) |
| 103 | + incomingScreen = gui; |
98 | 104 | else {
|
99 | 105 | incomingScreen = null;
|
100 | 106 | wrapper.closeInputField();
|
101 |
| - bridge=null; |
| 107 | + bridge = null; |
102 | 108 | }
|
103 | 109 | }
|
104 | 110 |
|
105 | 111 | public void postInitGuiEvent(GuiScreen screen) {
|
106 |
| - if(screen instanceof GuiEditSign||screen instanceof GuiScreenBook){ |
107 |
| - currentScreen=screen; |
108 |
| - incomingScreen=null; |
109 |
| - bridge=getNewBridge(); |
| 112 | + if (screen instanceof GuiEditSign || screen instanceof GuiScreenBook) { |
| 113 | + currentScreen = screen; |
| 114 | + incomingScreen = null; |
| 115 | + bridge = getNewBridge(); |
110 | 116 | wrapper.setupBridge(bridge);
|
111 | 117 | }
|
112 |
| - if (incomingScreen==screen) { |
| 118 | + if (incomingScreen == screen) { |
113 | 119 | currentScreen = incomingScreen;
|
114 | 120 | incomingScreen = null;
|
115 |
| - }else if(bridge!=null){ |
| 121 | + } else if (bridge != null) { |
116 | 122 | bridge.postGuiInit();
|
117 | 123 | }
|
118 | 124 | }
|
119 | 125 |
|
120 | 126 | public void nullGuiOpenEvent(GuiScreen currentScreen) {
|
121 | 127 | wrapper.closeInputField();
|
122 |
| - if(currentScreen instanceof GuiEditSign||currentScreen instanceof GuiScreenBook) |
123 |
| - YetAnotherInputFix.needFocus=true; |
124 |
| - bridge=null; |
125 |
| - this.currentScreen=null; |
126 |
| - this.currentTextField=null; |
127 |
| - this.incomingScreen=null; |
| 128 | + if (currentScreen instanceof GuiEditSign || currentScreen instanceof GuiScreenBook) |
| 129 | + YetAnotherInputFix.needFocus = true; |
| 130 | + bridge = null; |
| 131 | + this.currentScreen = null; |
| 132 | + this.currentTextField = null; |
| 133 | + this.incomingScreen = null; |
128 | 134 | }
|
129 | 135 |
|
130 |
| - public void inputFieldClosed(){ |
131 |
| - bridge=null; |
132 |
| - this.currentScreen=null; |
133 |
| - this.currentTextField=null; |
134 |
| - this.incomingScreen=null; |
135 |
| - YetAnotherInputFix.needFocus=true; |
| 136 | + public void inputFieldClosed() { |
| 137 | + bridge = null; |
| 138 | + this.currentScreen = null; |
| 139 | + this.currentTextField = null; |
| 140 | + this.incomingScreen = null; |
| 141 | + YetAnotherInputFix.needFocus = true; |
136 | 142 | }
|
137 | 143 |
|
138 |
| - private boolean hasGuiTextField(GuiScreen gui){ |
139 |
| - if(gui==null)return false; |
140 |
| - Class GuiClass=gui.getClass(); |
141 |
| - if(UnInputableGui.contains(GuiClass))return false; |
142 |
| - if(InputableGui.contains(GuiClass))return true; |
| 144 | + private boolean hasGuiTextField(GuiScreen gui) { |
| 145 | + if (gui == null) return false; |
| 146 | + Class GuiClass = gui.getClass(); |
| 147 | + if (UnInputableGui.contains(GuiClass)) return false; |
| 148 | + if (InputableGui.contains(GuiClass)) return true; |
143 | 149 | boolean hasTextField = false;
|
144 | 150 |
|
145 | 151 | for (Field f : GuiClass.getDeclaredFields()) {
|
|
0 commit comments