001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.Minecraft;
006import net.minecraft.client.renderer.Tessellator;
007import org.lwjgl.input.Mouse;
008import org.lwjgl.opengl.GL11;
009
010@SideOnly(Side.CLIENT)
011public abstract class SelectionListBase
012{
013    private final Minecraft field_96622_a;
014    private final int field_96619_e;
015    private final int field_96616_f;
016    private final int field_96617_g;
017    private final int field_96627_h;
018    protected final int field_96620_b;
019    protected int field_96621_c;
020    protected int field_96618_d;
021    private float field_96628_i = -2.0F;
022    private float field_96625_j;
023    private float field_96626_k;
024    private int field_96623_l = -1;
025    private long field_96624_m = 0L;
026
027    public SelectionListBase(Minecraft par1Minecraft, int par2, int par3, int par4, int par5, int par6)
028    {
029        this.field_96622_a = par1Minecraft;
030        this.field_96616_f = par3;
031        this.field_96627_h = par3 + par5;
032        this.field_96620_b = par6;
033        this.field_96619_e = par2;
034        this.field_96617_g = par2 + par4;
035    }
036
037    protected abstract int func_96608_a();
038
039    protected abstract void func_96615_a(int i, boolean flag);
040
041    protected abstract boolean func_96609_a(int i);
042
043    protected int func_96613_b()
044    {
045        return this.func_96608_a() * this.field_96620_b;
046    }
047
048    protected abstract void func_96611_c();
049
050    protected abstract void func_96610_a(int i, int j, int k, int l, Tessellator tessellator);
051
052    private void func_96614_f()
053    {
054        int i = this.func_96607_d();
055
056        if (i < 0)
057        {
058            i = 0;
059        }
060
061        if (this.field_96626_k < 0.0F)
062        {
063            this.field_96626_k = 0.0F;
064        }
065
066        if (this.field_96626_k > (float)i)
067        {
068            this.field_96626_k = (float)i;
069        }
070    }
071
072    public int func_96607_d()
073    {
074        return this.func_96613_b() - (this.field_96627_h - this.field_96616_f - 4);
075    }
076
077    public void func_96612_a(int par1, int par2, float par3)
078    {
079        this.field_96621_c = par1;
080        this.field_96618_d = par2;
081        this.func_96611_c();
082        int k = this.func_96608_a();
083        int l = this.func_96606_e();
084        int i1 = l + 6;
085        int j1;
086        int k1;
087        int l1;
088        int i2;
089        int j2;
090
091        if (Mouse.isButtonDown(0))
092        {
093            if (this.field_96628_i == -1.0F)
094            {
095                boolean flag = true;
096
097                if (par2 >= this.field_96616_f && par2 <= this.field_96627_h)
098                {
099                    int k2 = this.field_96619_e + 2;
100                    j1 = this.field_96617_g - 2;
101                    k1 = par2 - this.field_96616_f + (int)this.field_96626_k - 4;
102                    l1 = k1 / this.field_96620_b;
103
104                    if (par1 >= k2 && par1 <= j1 && l1 >= 0 && k1 >= 0 && l1 < k)
105                    {
106                        boolean flag1 = l1 == this.field_96623_l && Minecraft.getSystemTime() - this.field_96624_m < 250L;
107                        this.func_96615_a(l1, flag1);
108                        this.field_96623_l = l1;
109                        this.field_96624_m = Minecraft.getSystemTime();
110                    }
111                    else if (par1 >= k2 && par1 <= j1 && k1 < 0)
112                    {
113                        flag = false;
114                    }
115
116                    if (par1 >= l && par1 <= i1)
117                    {
118                        this.field_96625_j = -1.0F;
119                        j2 = this.func_96607_d();
120
121                        if (j2 < 1)
122                        {
123                            j2 = 1;
124                        }
125
126                        i2 = (int)((float)((this.field_96627_h - this.field_96616_f) * (this.field_96627_h - this.field_96616_f)) / (float)this.func_96613_b());
127
128                        if (i2 < 32)
129                        {
130                            i2 = 32;
131                        }
132
133                        if (i2 > this.field_96627_h - this.field_96616_f - 8)
134                        {
135                            i2 = this.field_96627_h - this.field_96616_f - 8;
136                        }
137
138                        this.field_96625_j /= (float)(this.field_96627_h - this.field_96616_f - i2) / (float)j2;
139                    }
140                    else
141                    {
142                        this.field_96625_j = 1.0F;
143                    }
144
145                    if (flag)
146                    {
147                        this.field_96628_i = (float)par2;
148                    }
149                    else
150                    {
151                        this.field_96628_i = -2.0F;
152                    }
153                }
154                else
155                {
156                    this.field_96628_i = -2.0F;
157                }
158            }
159            else if (this.field_96628_i >= 0.0F)
160            {
161                this.field_96626_k -= ((float)par2 - this.field_96628_i) * this.field_96625_j;
162                this.field_96628_i = (float)par2;
163            }
164        }
165        else
166        {
167            while (!this.field_96622_a.gameSettings.touchscreen && Mouse.next())
168            {
169                int l2 = Mouse.getEventDWheel();
170
171                if (l2 != 0)
172                {
173                    if (l2 > 0)
174                    {
175                        l2 = -1;
176                    }
177                    else if (l2 < 0)
178                    {
179                        l2 = 1;
180                    }
181
182                    this.field_96626_k += (float)(l2 * this.field_96620_b / 2);
183                }
184            }
185
186            this.field_96628_i = -1.0F;
187        }
188
189        this.func_96614_f();
190        GL11.glDisable(GL11.GL_LIGHTING);
191        GL11.glDisable(GL11.GL_FOG);
192        Tessellator tessellator = Tessellator.instance;
193        this.field_96622_a.renderEngine.func_98187_b("/gui/background.png");
194        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
195        float f1 = 32.0F;
196        tessellator.startDrawingQuads();
197        tessellator.setColorOpaque_I(2105376);
198        tessellator.addVertexWithUV((double)this.field_96619_e, (double)this.field_96627_h, 0.0D, (double)((float)this.field_96619_e / f1), (double)((float)(this.field_96627_h + (int)this.field_96626_k) / f1));
199        tessellator.addVertexWithUV((double)this.field_96617_g, (double)this.field_96627_h, 0.0D, (double)((float)this.field_96617_g / f1), (double)((float)(this.field_96627_h + (int)this.field_96626_k) / f1));
200        tessellator.addVertexWithUV((double)this.field_96617_g, (double)this.field_96616_f, 0.0D, (double)((float)this.field_96617_g / f1), (double)((float)(this.field_96616_f + (int)this.field_96626_k) / f1));
201        tessellator.addVertexWithUV((double)this.field_96619_e, (double)this.field_96616_f, 0.0D, (double)((float)this.field_96619_e / f1), (double)((float)(this.field_96616_f + (int)this.field_96626_k) / f1));
202        tessellator.draw();
203        j1 = this.field_96619_e + 2;
204        k1 = this.field_96616_f + 4 - (int)this.field_96626_k;
205        int i3;
206
207        for (l1 = 0; l1 < k; ++l1)
208        {
209            j2 = k1 + l1 * this.field_96620_b;
210            i2 = this.field_96620_b - 4;
211
212            if (j2 + this.field_96620_b <= this.field_96627_h && j2 - 4 >= this.field_96616_f)
213            {
214                if (this.func_96609_a(l1))
215                {
216                    i3 = this.field_96619_e + 2;
217                    int j3 = this.field_96617_g - 2;
218                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
219                    GL11.glDisable(GL11.GL_TEXTURE_2D);
220                    tessellator.startDrawingQuads();
221                    tessellator.setColorOpaque_I(8421504);
222                    tessellator.addVertexWithUV((double)i3, (double)(j2 + i2 + 2), 0.0D, 0.0D, 1.0D);
223                    tessellator.addVertexWithUV((double)j3, (double)(j2 + i2 + 2), 0.0D, 1.0D, 1.0D);
224                    tessellator.addVertexWithUV((double)j3, (double)(j2 - 2), 0.0D, 1.0D, 0.0D);
225                    tessellator.addVertexWithUV((double)i3, (double)(j2 - 2), 0.0D, 0.0D, 0.0D);
226                    tessellator.setColorOpaque_I(0);
227                    tessellator.addVertexWithUV((double)(i3 + 1), (double)(j2 + i2 + 1), 0.0D, 0.0D, 1.0D);
228                    tessellator.addVertexWithUV((double)(j3 - 1), (double)(j2 + i2 + 1), 0.0D, 1.0D, 1.0D);
229                    tessellator.addVertexWithUV((double)(j3 - 1), (double)(j2 - 1), 0.0D, 1.0D, 0.0D);
230                    tessellator.addVertexWithUV((double)(i3 + 1), (double)(j2 - 1), 0.0D, 0.0D, 0.0D);
231                    tessellator.draw();
232                    GL11.glEnable(GL11.GL_TEXTURE_2D);
233                }
234
235                this.func_96610_a(l1, j1, j2, i2, tessellator);
236            }
237        }
238
239        GL11.glDisable(GL11.GL_DEPTH_TEST);
240        byte b0 = 4;
241        GL11.glEnable(GL11.GL_BLEND);
242        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
243        GL11.glDisable(GL11.GL_ALPHA_TEST);
244        GL11.glShadeModel(GL11.GL_SMOOTH);
245        GL11.glDisable(GL11.GL_TEXTURE_2D);
246        tessellator.startDrawingQuads();
247        tessellator.setColorRGBA_I(0, 0);
248        tessellator.addVertexWithUV((double)this.field_96619_e, (double)(this.field_96616_f + b0), 0.0D, 0.0D, 1.0D);
249        tessellator.addVertexWithUV((double)this.field_96617_g, (double)(this.field_96616_f + b0), 0.0D, 1.0D, 1.0D);
250        tessellator.setColorRGBA_I(0, 255);
251        tessellator.addVertexWithUV((double)this.field_96617_g, (double)this.field_96616_f, 0.0D, 1.0D, 0.0D);
252        tessellator.addVertexWithUV((double)this.field_96619_e, (double)this.field_96616_f, 0.0D, 0.0D, 0.0D);
253        tessellator.draw();
254        tessellator.startDrawingQuads();
255        tessellator.setColorRGBA_I(0, 255);
256        tessellator.addVertexWithUV((double)this.field_96619_e, (double)this.field_96627_h, 0.0D, 0.0D, 1.0D);
257        tessellator.addVertexWithUV((double)this.field_96617_g, (double)this.field_96627_h, 0.0D, 1.0D, 1.0D);
258        tessellator.setColorRGBA_I(0, 0);
259        tessellator.addVertexWithUV((double)this.field_96617_g, (double)(this.field_96627_h - b0), 0.0D, 1.0D, 0.0D);
260        tessellator.addVertexWithUV((double)this.field_96619_e, (double)(this.field_96627_h - b0), 0.0D, 0.0D, 0.0D);
261        tessellator.draw();
262        j2 = this.func_96607_d();
263
264        if (j2 > 0)
265        {
266            i2 = (this.field_96627_h - this.field_96616_f) * (this.field_96627_h - this.field_96616_f) / this.func_96613_b();
267
268            if (i2 < 32)
269            {
270                i2 = 32;
271            }
272
273            if (i2 > this.field_96627_h - this.field_96616_f - 8)
274            {
275                i2 = this.field_96627_h - this.field_96616_f - 8;
276            }
277
278            i3 = (int)this.field_96626_k * (this.field_96627_h - this.field_96616_f - i2) / j2 + this.field_96616_f;
279
280            if (i3 < this.field_96616_f)
281            {
282                i3 = this.field_96616_f;
283            }
284
285            tessellator.startDrawingQuads();
286            tessellator.setColorRGBA_I(0, 255);
287            tessellator.addVertexWithUV((double)l, (double)this.field_96627_h, 0.0D, 0.0D, 1.0D);
288            tessellator.addVertexWithUV((double)i1, (double)this.field_96627_h, 0.0D, 1.0D, 1.0D);
289            tessellator.addVertexWithUV((double)i1, (double)this.field_96616_f, 0.0D, 1.0D, 0.0D);
290            tessellator.addVertexWithUV((double)l, (double)this.field_96616_f, 0.0D, 0.0D, 0.0D);
291            tessellator.draw();
292            tessellator.startDrawingQuads();
293            tessellator.setColorRGBA_I(8421504, 255);
294            tessellator.addVertexWithUV((double)l, (double)(i3 + i2), 0.0D, 0.0D, 1.0D);
295            tessellator.addVertexWithUV((double)i1, (double)(i3 + i2), 0.0D, 1.0D, 1.0D);
296            tessellator.addVertexWithUV((double)i1, (double)i3, 0.0D, 1.0D, 0.0D);
297            tessellator.addVertexWithUV((double)l, (double)i3, 0.0D, 0.0D, 0.0D);
298            tessellator.draw();
299            tessellator.startDrawingQuads();
300            tessellator.setColorRGBA_I(12632256, 255);
301            tessellator.addVertexWithUV((double)l, (double)(i3 + i2 - 1), 0.0D, 0.0D, 1.0D);
302            tessellator.addVertexWithUV((double)(i1 - 1), (double)(i3 + i2 - 1), 0.0D, 1.0D, 1.0D);
303            tessellator.addVertexWithUV((double)(i1 - 1), (double)i3, 0.0D, 1.0D, 0.0D);
304            tessellator.addVertexWithUV((double)l, (double)i3, 0.0D, 0.0D, 0.0D);
305            tessellator.draw();
306        }
307
308        GL11.glEnable(GL11.GL_TEXTURE_2D);
309        GL11.glShadeModel(GL11.GL_FLAT);
310        GL11.glEnable(GL11.GL_ALPHA_TEST);
311        GL11.glDisable(GL11.GL_BLEND);
312    }
313
314    protected int func_96606_e()
315    {
316        return this.field_96617_g - 8;
317    }
318}