aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/sign/SignSelectionList.java
blob: e4a6e10306fc525f20048a646bc5590ecc45e4f5 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package at.hannibal2.skyhanni.sign;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiListExtended;
import net.minecraft.client.gui.inventory.GuiEditSign;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.network.play.client.C12PacketUpdateSign;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class SignSelectionList extends GuiListExtended {

    public static final List<Entry> AUCTION_STARTING_BID_PRICES = new ArrayList<>();
    public static final List<Entry> AUCTION_BID_PRICES = new ArrayList<>();
    public static final List<Entry> AUCTION_QUERIES = new ArrayList<>();
    public static final List<Entry> BANK_WITHDRAW = new ArrayList<>();
    public static final List<Entry> BANK_DEPOSIT = new ArrayList<>();
    public static final List<Entry> BAZAAR_ORDER = new ArrayList<>();
    public static final List<Entry> BAZAAR_PRICE = new ArrayList<>();
    private int selectedSlotIndex = -1;
    private final List<SignSelectionList.Entry> list;
    private final String title;

    public SignSelectionList(Minecraft mc, int width, int height, int top, int bottom, List<SignSelectionList.Entry> list, String title) {
        super(mc, width, height, top, bottom, 16);
        this.list = list;
        this.title = title;

        if (this.getSize() > 5) {
            this.list.remove(0);
        }
        Collections.reverse(this.list);
    }

    @Override
    protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) {
        this.selectedSlotIndex = slotIndex;
    }

    @Override
    public IGuiListEntry getListEntry(int index) {
        return this.list.stream().distinct().collect(Collectors.toList()).get(index);
    }

    @Override
    protected int getSize() {
        return this.list.stream().distinct().collect(Collectors.toList()).size();
    }

    @Override
    protected boolean isSelected(int index) {
        return index == this.selectedSlotIndex;
    }

    @Override
    protected void drawContainerBackground(Tessellator tessellator) {}

    @Override
    protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha) {}

    @Override
    public int getListWidth() {
        return 100;
    }

    @Override
    public int getSlotHeight() {
        return 10;
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        if (this.field_178041_q) {
            this.mouseX = mouseX;
            this.mouseY = mouseY;
            this.drawBackground();
            this.bindAmountScrolled();
            GlStateManager.disableLighting();
            GlStateManager.disableFog();
            Tessellator tessellator = Tessellator.getInstance();
            this.drawContainerBackground(tessellator);
            int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
            int l = this.top + 4 - (int) this.amountScrolled;

            if (this.hasListHeader) {
                this.drawListHeader(k, l, tessellator);
            }

            this.drawSelectionBox(k, l, mouseX, mouseY);
            this.mc.fontRendererObj.drawString(this.title + ":", k, l - 12, 16777215);
            GlStateManager.disableDepth();
            this.overlayBackground(0, this.top, 255, 255);
            this.overlayBackground(this.bottom, this.height, 255, 255);
            this.func_148142_b(mouseX, mouseY);
        }
        GlStateManager.enableDepth();
    }

    public void add(String value) {
        this.list.add(new Entry(value));
    }

    public static void clearAll() {
        SignSelectionList.AUCTION_STARTING_BID_PRICES.clear();
        SignSelectionList.AUCTION_BID_PRICES.clear();
        SignSelectionList.AUCTION_QUERIES.clear();
        SignSelectionList.BANK_WITHDRAW.clear();
        SignSelectionList.BANK_DEPOSIT.clear();
        SignSelectionList.BAZAAR_ORDER.clear();
        SignSelectionList.BAZAAR_PRICE.clear();
    }

    public static class Entry implements GuiListExtended.IGuiListEntry {

        private final Minecraft mc;
        private final String value;
        private long lastClicked;

        public Entry(String value) {
            this.mc = Minecraft.getMinecraft();
            this.value = value;
        }

        @Override
        public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}

        @Override
        public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
            this.mc.fontRendererObj.drawString(this.value, x + 2, y + 2, 16777215);
        }

        @Override
        public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
            //            TileEntitySign sign = ((GuiEditSign)this.mc.currentScreen).tileSign;
            //            TileEntitySign sign = ().tileSign;
            TileEntitySign sign = LorenzSignUtils.getTileSign((GuiEditSign) this.mc.currentScreen);
            sign.markDirty();

            if (Minecraft.getSystemTime() - this.lastClicked < 250L) {
                //                if (SkyBlockcatiaSettings.INSTANCE.auctionBidConfirm && NumberUtils.isNumeric(this.value))
                //                {
                //                    int price = Integer.parseInt(this.value);
                //
                //                    if (price >= SkyBlockcatiaSettings.INSTANCE.auctionBidConfirmValue)
                //                    {
                //                        this.mc.displayGuiScreen(new GuiYesNo(this.mc.currentScreen, LangUtils.translate("message.bid_confirm_title"), LangUtils.translate("message.bid_confirm"), 201));
                //                    }
                //                    else
                //                    {
                //                        SignSelectionList.processSignData(sign);
                //                        this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
                //                        this.mc.displayGuiScreen(null);
                //                    }
                //                }
                //                else
                //                {
                SignSelectionList.processSignData(sign);
                this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
                this.mc.displayGuiScreen(null);
                //                }
            }

            sign.signText[0] = new ChatComponentText(this.value);

            if (this.mc.currentScreen instanceof IEditSign) {
                ((IEditSign) this.mc.currentScreen).getTextInputUtil().moveCaretToEnd();
            }
            this.lastClicked = Minecraft.getSystemTime();
            return false;
        }

        @Override
        public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) {}

        @Override
        public boolean equals(Object obj) {
            if (!(obj instanceof Entry)) {
                return false;
            }
            if (obj == this) {
                return true;
            }
            Entry other = (Entry) obj;
            return new EqualsBuilder().append(this.value, other.value).isEquals();
        }

        @Override
        public int hashCode() {
            return new HashCodeBuilder().append(this.value).toHashCode();
        }

        public String getValue() {
            return this.value;
        }
    }

    public static void processSignData(TileEntitySign sign) {
        NetHandlerPlayClient nethandlerplayclient = Minecraft.getMinecraft().getNetHandler();

        if (nethandlerplayclient != null) {
            nethandlerplayclient.addToSendQueue(new C12PacketUpdateSign(sign.getPos(), sign.signText));
        }
        sign.setEditable(true);
    }
}