summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/storage/GuiMealTerminal.java
blob: 9af4f73ae61eb5b05abc116f0d95ab87285a95c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package jp.plusplus.fbs.storage;

import jp.plusplus.fbs.FBS;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

/**
 * Created by plusplus_F on 2016/03/08.
 */
public class GuiMealTerminal extends GuiContainer {
    private static final ResourceLocation rl = new ResourceLocation(FBS.MODID+":textures/gui/terminal.png");

    private float currentScroll;
    private boolean isScrolling;
    private boolean wasClicking;
    private GuiTextField searchField;
    private boolean field_147057_D;

    public GuiMealTerminal(Container p_i1072_1_) {
        super(p_i1072_1_);
        this.allowUserInput = true;
        this.xSize = 195;
        this.ySize = 222;
    }

    @Override
    public void initGui() {
        super.initGui();
        this.buttonList.clear();
        Keyboard.enableRepeatEvents(true);
        this.searchField = new GuiTextField(this.fontRendererObj, this.guiLeft + 80, this.guiTop + 5, 89, this.fontRendererObj.FONT_HEIGHT);
        this.searchField.setMaxStringLength(15);
        this.searchField.setEnableBackgroundDrawing(false);
        this.searchField.setVisible(false);
        this.searchField.setTextColor(16777215);
    }

    @Override
    public void onGuiClosed() {
        super.onGuiClosed();
        Keyboard.enableRepeatEvents(false);
    }

    @Override
    protected void keyTyped(char p_73869_1_, int p_73869_2_) {
        if (this.field_147057_D) {
            this.field_147057_D = false;
            this.searchField.setText("");
        }

        if (!this.checkHotbarKeys(p_73869_2_)) {
            if (this.searchField.textboxKeyTyped(p_73869_1_, p_73869_2_)) {
                this.updateSearch();
            } else {
                super.keyTyped(p_73869_1_, p_73869_2_);
            }
        }
    }

    protected void updateSearch(){

    }

    @Override
    public void handleMouseInput() {
        super.handleMouseInput();

        int i = Mouse.getEventDWheel();
        if (i != 0) {
            ContainerMealTerminal cmt=(ContainerMealTerminal)inventorySlots;
            int j = cmt.inv.allItem.length / 9 - 5 + 1;

            if (i > 0) i = 1;
            if (i < 0) i = -1;

            this.currentScroll = (float) ((double) this.currentScroll - (double) i / (double) j);
            if (this.currentScroll < 0.0F) this.currentScroll = 0.0F;
            if (this.currentScroll > 1.0F) this.currentScroll = 1.0F;

            cmt.scrollTo(currentScroll);
        }
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.getTextureManager().bindTexture(rl);

        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

        //GuiContainerCreative
        this.drawTexturedModalRect(k+175, l+18+ (int)((196.f-15.f) * this.currentScroll), 232, 0, 12, 15);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
        GL11.glDisable(GL11.GL_BLEND);
        this.fontRendererObj.drawString(I18n.format("tile.fbs.mealCrystal.name"), 8, 6, 4210752);
    }


    public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
        boolean flag = Mouse.isButtonDown(0);
        int k = this.guiLeft;
        int l = this.guiTop;
        int i1 = k + 175;
        int j1 = l + 18;
        int k1 = i1 + 14;
        int l1 = j1 + 196;

        ContainerMealTerminal cmt=(ContainerMealTerminal)inventorySlots;

        if (!this.wasClicking && flag && p_73863_1_ >= i1 && p_73863_2_ >= j1 && p_73863_1_ < k1 && p_73863_2_ < l1) {
            this.isScrolling = true;
        }

        if (!flag) {
            this.isScrolling = false;
        }

        this.wasClicking = flag;

        if (this.isScrolling) {
            this.currentScroll = ((float) (p_73863_2_ - j1) - 7.5F) / ((float) (l1 - j1) - 15.0F);

            if (this.currentScroll < 0.0F) this.currentScroll = 0.0F;
            if (this.currentScroll > 1.0F) this.currentScroll = 1.0F;

            cmt.scrollTo(this.currentScroll);
        }

        super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glDisable(GL11.GL_LIGHTING);
    }
}