11package hellfirepvp .modularmachinery .client .gui ;
22
3+ import hellfirepvp .modularmachinery .ModularMachinery ;
34import hellfirepvp .modularmachinery .common .container .ContainerParallelController ;
5+ import hellfirepvp .modularmachinery .common .network .PktParallelControllerUpdate ;
46import hellfirepvp .modularmachinery .common .tiles .TileParallelController ;
7+ import hellfirepvp .modularmachinery .common .util .MiscUtils ;
58import net .minecraft .client .Minecraft ;
9+ import net .minecraft .client .audio .SoundHandler ;
10+ import net .minecraft .client .gui .FontRenderer ;
611import net .minecraft .client .gui .GuiButton ;
712import net .minecraft .client .gui .GuiTextField ;
813import net .minecraft .client .renderer .GlStateManager ;
14+ import net .minecraft .client .resources .I18n ;
915import net .minecraft .entity .player .EntityPlayer ;
1016import net .minecraftforge .client .model .animation .Animation ;
17+ import org .lwjgl .input .Keyboard ;
1118
19+ import java .io .IOException ;
1220import java .util .ArrayList ;
1321import java .util .List ;
1422
1523public class GuiContainerParallelController extends GuiContainerBase <ContainerParallelController > {
1624 private final TileParallelController parallelCtrlInterface ;
17- private List <GuiButton > buttons = new ArrayList <>();
25+ private final List <GuiButton > buttons = new ArrayList <>();
1826 private GuiButton increment_1 ;
1927 private GuiButton increment_10 ;
2028 private GuiButton increment_100 ;
2129 private GuiButton decrement_1 ;
2230 private GuiButton decrement_10 ;
2331 private GuiButton decrement_100 ;
2432 private GuiTextField textField ;
33+
2534 public GuiContainerParallelController (TileParallelController te , EntityPlayer opening ) {
2635 super (new ContainerParallelController (te , opening ));
2736 this .parallelCtrlInterface = te ;
@@ -30,7 +39,24 @@ public GuiContainerParallelController(TileParallelController te, EntityPlayer op
3039 @ Override
3140 protected void drawGuiContainerForegroundLayer (int mouseX , int mouseY ) {
3241 super .drawGuiContainerForegroundLayer (mouseX , mouseY );
42+ GlStateManager .pushMatrix ();
43+ GlStateManager .color (1.0F , 1.0F , 1.0F , 1.0F );
44+
45+ int offsetX = 4 ;
46+ int offsetY = 4 ;
47+ FontRenderer fr = this .fontRenderer ;
48+ fr .drawStringWithShadow (I18n .format ("gui.parallelcontroller.title" ), offsetX , offsetY , 0xFFFFFF );
49+ offsetX += 2 ;
50+ offsetY += 12 ;
51+
52+ TileParallelController .ParallelControllerProvider provider = parallelCtrlInterface .provideComponent ();
3353
54+ fr .drawStringWithShadow (I18n .format ("gui.parallelcontroller.max_value" , provider .getMaxParallelism ()), offsetX , offsetY , 0xFFFFFF );
55+ offsetY += 33 ;
56+ fr .drawStringWithShadow (I18n .format ("gui.parallelcontroller.current_value" , provider .getParallelism ()), offsetX , offsetY , 0xFFFFFF );
57+
58+ GlStateManager .color (1.0F , 1.0F , 1.0F , 1.0F );
59+ GlStateManager .popMatrix ();
3460 }
3561
3662 @ Override
@@ -53,29 +79,146 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
5379 }
5480 }
5581
82+ @ Override
83+ protected void mouseClicked (int mouseX , int mouseY , int mouseButton ) throws IOException {
84+ super .mouseClicked (mouseX , mouseY , mouseButton );
85+ if (mouseButton != 0 ) {
86+ return ;
87+ }
88+
89+ boolean clicked = textField .mouseClicked (mouseX , mouseY , mouseButton );
90+ if (clicked ) {
91+ return ;
92+ }
93+
94+ Minecraft mc = Minecraft .getMinecraft ();
95+ SoundHandler soundHandler = mc .getSoundHandler ();
96+
97+ TileParallelController .ParallelControllerProvider provider = parallelCtrlInterface .provideComponent ();
98+ int parallelism = provider .getParallelism ();
99+ int maxParallelism = provider .getMaxParallelism ();
100+ int maxCanIncrement = maxParallelism - parallelism ;
101+
102+ if (increment_1 .mousePressed (mc , mouseX , mouseY )) {
103+ if (maxCanIncrement >= 1 ) {
104+ ModularMachinery .NET_CHANNEL .sendToServer (
105+ new PktParallelControllerUpdate (parallelism + 1 )
106+ );
107+ }
108+ increment_1 .playPressSound (soundHandler );
109+ return ;
110+ }
111+ if (increment_10 .mousePressed (mc , mouseX , mouseY )) {
112+ if (maxCanIncrement >= 10 ) {
113+ ModularMachinery .NET_CHANNEL .sendToServer (
114+ new PktParallelControllerUpdate (parallelism + 10 )
115+ );
116+ } else {
117+ ModularMachinery .NET_CHANNEL .sendToServer (
118+ new PktParallelControllerUpdate (maxParallelism )
119+ );
120+ }
121+ increment_10 .playPressSound (soundHandler );
122+ return ;
123+ }
124+ if (increment_100 .mousePressed (mc , mouseX , mouseY )) {
125+ if (maxCanIncrement >= 100 ) {
126+ ModularMachinery .NET_CHANNEL .sendToServer (
127+ new PktParallelControllerUpdate (parallelism + 100 )
128+ );
129+ } else {
130+ ModularMachinery .NET_CHANNEL .sendToServer (
131+ new PktParallelControllerUpdate (maxParallelism )
132+ );
133+ }
134+ increment_100 .playPressSound (soundHandler );
135+ return ;
136+ }
137+ int maxCanDecrement = Math .max (0 , parallelism - 1 );
138+ if (decrement_1 .mousePressed (mc , mouseX , mouseY )) {
139+ if (maxCanDecrement >= 1 ) {
140+ ModularMachinery .NET_CHANNEL .sendToServer (
141+ new PktParallelControllerUpdate (parallelism - 1 )
142+ );
143+ }
144+ decrement_1 .playPressSound (soundHandler );
145+ return ;
146+ }
147+ if (decrement_10 .mousePressed (mc , mouseX , mouseY )) {
148+ if (maxCanDecrement >= 10 ) {
149+ ModularMachinery .NET_CHANNEL .sendToServer (
150+ new PktParallelControllerUpdate (parallelism - 10 )
151+ );
152+ } else {
153+ ModularMachinery .NET_CHANNEL .sendToServer (
154+ new PktParallelControllerUpdate (1 )
155+ );
156+ }
157+ decrement_10 .playPressSound (soundHandler );
158+ return ;
159+ }
160+ if (decrement_100 .mousePressed (mc , mouseX , mouseY )) {
161+ if (maxCanDecrement >= 100 ) {
162+ ModularMachinery .NET_CHANNEL .sendToServer (
163+ new PktParallelControllerUpdate (parallelism - 100 )
164+ );
165+ } else {
166+ ModularMachinery .NET_CHANNEL .sendToServer (
167+ new PktParallelControllerUpdate (1 )
168+ );
169+ }
170+ decrement_100 .playPressSound (soundHandler );
171+ }
172+ }
173+
174+ @ Override
175+ public void keyTyped (char c , int i ) throws IOException {
176+ if (!textField .isFocused ()) {
177+ super .keyTyped (c , i );
178+ }
179+
180+ if (i == Keyboard .KEY_RETURN ) {
181+ TileParallelController .ParallelControllerProvider provider = parallelCtrlInterface .provideComponent ();
182+
183+ try {
184+ int newParallelism = Integer .parseInt (textField .getText ());
185+ if (newParallelism < provider .getMaxParallelism () && newParallelism > 0 ) {
186+ ModularMachinery .NET_CHANNEL .sendToServer (new PktParallelControllerUpdate (newParallelism ));
187+ }
188+ textField .setText ("" );
189+ } catch (NumberFormatException ignored ) {
190+ }
191+ return ;
192+ }
193+
194+ if (Character .isDigit (c ) || MiscUtils .isTextBoxKey (i )) {
195+ textField .textboxKeyTyped (c , i );
196+ }
197+ }
198+
56199 @ Override
57200 public void initGui () {
58201 super .initGui ();
59- textField = new GuiTextField (0 , fontRenderer , 10 , this .height / 2 - 48 , 160 , 10 );
60- textField .setMaxStringLength (16 );
202+ textField = new GuiTextField (0 , fontRenderer , this . width / 2 - 15 , this .height / 2 - 35 , 95 , 10 );
203+ textField .setMaxStringLength (10 );
61204
62- decrement_1 = new GuiButton (1 , this .width / 2 - 81 , this .height / 2 + 25 , 20 , 20 ,
205+ decrement_1 = new GuiButton (1 , this .width / 2 - 81 , this .height / 2 - 57 , 30 , 20 ,
63206 "-1" );
64207 buttons .add (decrement_1 );
65- decrement_10 = new GuiButton (2 , this .width / 2 - 51 , this .height / 2 + 25 , 30 , 20 ,
208+ decrement_10 = new GuiButton (2 , this .width / 2 - 16 , this .height / 2 - 57 , 30 , 20 ,
66209 "-10" );
67210 buttons .add (decrement_10 );
68- decrement_100 = new GuiButton (3 , this .width / 2 - 1 , this .height / 2 + 25 , 40 , 20 ,
211+ decrement_100 = new GuiButton (3 , this .width / 2 + 51 , this .height / 2 - 57 , 30 , 20 ,
69212 "-100" );
70213 buttons .add (decrement_100 );
71214
72- increment_1 = new GuiButton (4 , this .width / 2 - 81 , this .height / 2 - 25 , 20 , 20 ,
215+ increment_1 = new GuiButton (4 , this .width / 2 - 81 , this .height / 2 - 23 , 30 , 20 ,
73216 "+1" );
74217 buttons .add (increment_1 );
75- increment_10 = new GuiButton (5 , this .width / 2 - 51 , this .height / 2 - 25 , 30 , 20 ,
218+ increment_10 = new GuiButton (5 , this .width / 2 - 16 , this .height / 2 - 23 , 30 , 20 ,
76219 "+10" );
77220 buttons .add (increment_10 );
78- increment_100 = new GuiButton (6 , this .width / 2 - 1 , this .height / 2 - 25 , 40 , 20 ,
221+ increment_100 = new GuiButton (6 , this .width / 2 + 51 , this .height / 2 - 23 , 30 , 20 ,
79222 "+100" );
80223 buttons .add (increment_100 );
81224 }
0 commit comments