| 1 | package net.minecraft.client.gui.stream;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.io.IOException;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Set;
|
| 7 | import net.minecraft.client.gui.GuiButton;
|
| 8 | import net.minecraft.client.gui.GuiScreen;
|
| 9 | import net.minecraft.client.resources.I18n;
|
| 10 | import net.minecraft.client.stream.IStream;
|
| 11 | import net.minecraft.util.ChatComponentText;
|
| 12 | import net.minecraft.util.ChatComponentTranslation;
|
| 13 | import net.minecraft.util.EnumChatFormatting;
|
| 14 | import net.minecraft.util.IChatComponent;
|
| 15 | import tv.twitch.chat.ChatUserInfo;
|
| 16 | import tv.twitch.chat.ChatUserMode;
|
| 17 | import tv.twitch.chat.ChatUserSubscription;
|
| 18 |
|
| 19 | public class GuiTwitchUserMode extends GuiScreen
|
| 20 | {
|
| 21 | private static final EnumChatFormatting field_152331_a = EnumChatFormatting.DARK_GREEN;
|
| 22 | private static final EnumChatFormatting field_152335_f = EnumChatFormatting.RED;
|
| 23 | private static final EnumChatFormatting field_152336_g = EnumChatFormatting.DARK_PURPLE;
|
| 24 | private final ChatUserInfo field_152337_h;
|
| 25 | private final IChatComponent field_152338_i;
|
| 26 | private final List<IChatComponent> field_152332_r = Lists.<IChatComponent>newArrayList();
|
| 27 | private final IStream stream;
|
| 28 | private int field_152334_t;
|
| 29 |
|
| 30 | public GuiTwitchUserMode(IStream streamIn, ChatUserInfo p_i1064_2_)
|
| 31 | {
|
| 32 | this.stream = streamIn;
|
| 33 | this.field_152337_h = p_i1064_2_;
|
| 34 | this.field_152338_i = new ChatComponentText(p_i1064_2_.displayName);
|
| 35 | this.field_152332_r.addAll(func_152328_a(p_i1064_2_.modes, p_i1064_2_.subscriptions, streamIn));
|
| 36 | }
|
| 37 |
|
| 38 | public static List<IChatComponent> func_152328_a(Set<ChatUserMode> p_152328_0_, Set<ChatUserSubscription> p_152328_1_, IStream p_152328_2_)
|
| 39 | {
|
| 40 | String s = p_152328_2_ == null ? null : p_152328_2_.func_152921_C();
|
| 41 | boolean flag = p_152328_2_ != null && p_152328_2_.func_152927_B();
|
| 42 | List<IChatComponent> list = Lists.<IChatComponent>newArrayList();
|
| 43 |
|
| 44 | for (ChatUserMode chatusermode : p_152328_0_)
|
| 45 | {
|
| 46 | IChatComponent ichatcomponent = func_152329_a(chatusermode, s, flag);
|
| 47 |
|
| 48 | if (ichatcomponent != null)
|
| 49 | {
|
| 50 | IChatComponent ichatcomponent1 = new ChatComponentText("- ");
|
| 51 | ichatcomponent1.appendSibling(ichatcomponent);
|
| 52 | list.add(ichatcomponent1);
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | for (ChatUserSubscription chatusersubscription : p_152328_1_)
|
| 57 | {
|
| 58 | IChatComponent ichatcomponent2 = func_152330_a(chatusersubscription, s, flag);
|
| 59 |
|
| 60 | if (ichatcomponent2 != null)
|
| 61 | {
|
| 62 | IChatComponent ichatcomponent3 = new ChatComponentText("- ");
|
| 63 | ichatcomponent3.appendSibling(ichatcomponent2);
|
| 64 | list.add(ichatcomponent3);
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | return list;
|
| 69 | }
|
| 70 |
|
| 71 | public static IChatComponent func_152330_a(ChatUserSubscription p_152330_0_, String p_152330_1_, boolean p_152330_2_)
|
| 72 | {
|
| 73 | IChatComponent ichatcomponent = null;
|
| 74 |
|
| 75 | if (p_152330_0_ == ChatUserSubscription.TTV_CHAT_USERSUB_SUBSCRIBER)
|
| 76 | {
|
| 77 | if (p_152330_1_ == null)
|
| 78 | {
|
| 79 | ichatcomponent = new ChatComponentTranslation("stream.user.subscription.subscriber", new Object[0]);
|
| 80 | }
|
| 81 | else if (p_152330_2_)
|
| 82 | {
|
| 83 | ichatcomponent = new ChatComponentTranslation("stream.user.subscription.subscriber.self", new Object[0]);
|
| 84 | }
|
| 85 | else
|
| 86 | {
|
| 87 | ichatcomponent = new ChatComponentTranslation("stream.user.subscription.subscriber.other", new Object[] {p_152330_1_});
|
| 88 | }
|
| 89 |
|
| 90 | ichatcomponent.getChatStyle().setColor(field_152331_a);
|
| 91 | }
|
| 92 | else if (p_152330_0_ == ChatUserSubscription.TTV_CHAT_USERSUB_TURBO)
|
| 93 | {
|
| 94 | ichatcomponent = new ChatComponentTranslation("stream.user.subscription.turbo", new Object[0]);
|
| 95 | ichatcomponent.getChatStyle().setColor(field_152336_g);
|
| 96 | }
|
| 97 |
|
| 98 | return ichatcomponent;
|
| 99 | }
|
| 100 |
|
| 101 | public static IChatComponent func_152329_a(ChatUserMode p_152329_0_, String p_152329_1_, boolean p_152329_2_)
|
| 102 | {
|
| 103 | IChatComponent ichatcomponent = null;
|
| 104 |
|
| 105 | if (p_152329_0_ == ChatUserMode.TTV_CHAT_USERMODE_ADMINSTRATOR)
|
| 106 | {
|
| 107 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.administrator", new Object[0]);
|
| 108 | ichatcomponent.getChatStyle().setColor(field_152336_g);
|
| 109 | }
|
| 110 | else if (p_152329_0_ == ChatUserMode.TTV_CHAT_USERMODE_BANNED)
|
| 111 | {
|
| 112 | if (p_152329_1_ == null)
|
| 113 | {
|
| 114 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.banned", new Object[0]);
|
| 115 | }
|
| 116 | else if (p_152329_2_)
|
| 117 | {
|
| 118 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.banned.self", new Object[0]);
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.banned.other", new Object[] {p_152329_1_});
|
| 123 | }
|
| 124 |
|
| 125 | ichatcomponent.getChatStyle().setColor(field_152335_f);
|
| 126 | }
|
| 127 | else if (p_152329_0_ == ChatUserMode.TTV_CHAT_USERMODE_BROADCASTER)
|
| 128 | {
|
| 129 | if (p_152329_1_ == null)
|
| 130 | {
|
| 131 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.broadcaster", new Object[0]);
|
| 132 | }
|
| 133 | else if (p_152329_2_)
|
| 134 | {
|
| 135 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.broadcaster.self", new Object[0]);
|
| 136 | }
|
| 137 | else
|
| 138 | {
|
| 139 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.broadcaster.other", new Object[0]);
|
| 140 | }
|
| 141 |
|
| 142 | ichatcomponent.getChatStyle().setColor(field_152331_a);
|
| 143 | }
|
| 144 | else if (p_152329_0_ == ChatUserMode.TTV_CHAT_USERMODE_MODERATOR)
|
| 145 | {
|
| 146 | if (p_152329_1_ == null)
|
| 147 | {
|
| 148 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.moderator", new Object[0]);
|
| 149 | }
|
| 150 | else if (p_152329_2_)
|
| 151 | {
|
| 152 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.moderator.self", new Object[0]);
|
| 153 | }
|
| 154 | else
|
| 155 | {
|
| 156 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.moderator.other", new Object[] {p_152329_1_});
|
| 157 | }
|
| 158 |
|
| 159 | ichatcomponent.getChatStyle().setColor(field_152331_a);
|
| 160 | }
|
| 161 | else if (p_152329_0_ == ChatUserMode.TTV_CHAT_USERMODE_STAFF)
|
| 162 | {
|
| 163 | ichatcomponent = new ChatComponentTranslation("stream.user.mode.staff", new Object[0]);
|
| 164 | ichatcomponent.getChatStyle().setColor(field_152336_g);
|
| 165 | }
|
| 166 |
|
| 167 | return ichatcomponent;
|
| 168 | }
|
| 169 |
|
| 170 | /**
|
| 171 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 172 | * window resizes, the buttonList is cleared beforehand.
|
| 173 | */
|
| 174 | public void initGui()
|
| 175 | {
|
| 176 | int i = this.width / 3;
|
| 177 | int j = i - 130;
|
| 178 | this.buttonList.add(new GuiButton(1, i * 0 + j / 2, this.height - 70, 130, 20, I18n.format("stream.userinfo.timeout", new Object[0])));
|
| 179 | this.buttonList.add(new GuiButton(0, i * 1 + j / 2, this.height - 70, 130, 20, I18n.format("stream.userinfo.ban", new Object[0])));
|
| 180 | this.buttonList.add(new GuiButton(2, i * 2 + j / 2, this.height - 70, 130, 20, I18n.format("stream.userinfo.mod", new Object[0])));
|
| 181 | this.buttonList.add(new GuiButton(5, i * 0 + j / 2, this.height - 45, 130, 20, I18n.format("gui.cancel", new Object[0])));
|
| 182 | this.buttonList.add(new GuiButton(3, i * 1 + j / 2, this.height - 45, 130, 20, I18n.format("stream.userinfo.unban", new Object[0])));
|
| 183 | this.buttonList.add(new GuiButton(4, i * 2 + j / 2, this.height - 45, 130, 20, I18n.format("stream.userinfo.unmod", new Object[0])));
|
| 184 | int k = 0;
|
| 185 |
|
| 186 | for (IChatComponent ichatcomponent : this.field_152332_r)
|
| 187 | {
|
| 188 | k = Math.max(k, this.fontRendererObj.getStringWidth(ichatcomponent.getFormattedText()));
|
| 189 | }
|
| 190 |
|
| 191 | this.field_152334_t = this.width / 2 - k / 2;
|
| 192 | }
|
| 193 |
|
| 194 | /**
|
| 195 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 196 | */
|
| 197 | protected void actionPerformed(GuiButton button) throws IOException
|
| 198 | {
|
| 199 | if (button.enabled)
|
| 200 | {
|
| 201 | if (button.id == 0)
|
| 202 | {
|
| 203 | this.stream.func_152917_b("/ban " + this.field_152337_h.displayName);
|
| 204 | }
|
| 205 | else if (button.id == 3)
|
| 206 | {
|
| 207 | this.stream.func_152917_b("/unban " + this.field_152337_h.displayName);
|
| 208 | }
|
| 209 | else if (button.id == 2)
|
| 210 | {
|
| 211 | this.stream.func_152917_b("/mod " + this.field_152337_h.displayName);
|
| 212 | }
|
| 213 | else if (button.id == 4)
|
| 214 | {
|
| 215 | this.stream.func_152917_b("/unmod " + this.field_152337_h.displayName);
|
| 216 | }
|
| 217 | else if (button.id == 1)
|
| 218 | {
|
| 219 | this.stream.func_152917_b("/timeout " + this.field_152337_h.displayName);
|
| 220 | }
|
| 221 |
|
| 222 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | /**
|
| 227 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 228 | */
|
| 229 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 230 | {
|
| 231 | this.drawDefaultBackground();
|
| 232 | this.drawCenteredString(this.fontRendererObj, this.field_152338_i.getUnformattedText(), this.width / 2, 70, 16777215);
|
| 233 | int i = 80;
|
| 234 |
|
| 235 | for (IChatComponent ichatcomponent : this.field_152332_r)
|
| 236 | {
|
| 237 | this.drawString(this.fontRendererObj, ichatcomponent.getFormattedText(), this.field_152334_t, i, 16777215);
|
| 238 | i += this.fontRendererObj.FONT_HEIGHT;
|
| 239 | }
|
| 240 |
|
| 241 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 242 | }
|
| 243 | }
|
| 244 |
|