| 1 | package net.minecraft.client.gui.stream;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.io.IOException;
|
| 5 | import java.net.URI;
|
| 6 | import java.util.Arrays;
|
| 7 | import java.util.List;
|
| 8 | import net.minecraft.client.Minecraft;
|
| 9 | import net.minecraft.client.gui.GuiButton;
|
| 10 | import net.minecraft.client.gui.GuiScreen;
|
| 11 | import net.minecraft.client.renderer.OpenGlHelper;
|
| 12 | import net.minecraft.client.resources.I18n;
|
| 13 | import net.minecraft.client.stream.IStream;
|
| 14 | import net.minecraft.client.stream.NullStream;
|
| 15 | import net.minecraft.util.ChatComponentTranslation;
|
| 16 | import net.minecraft.util.IChatComponent;
|
| 17 | import net.minecraft.util.Session;
|
| 18 | import net.minecraft.util.Util;
|
| 19 | import org.apache.logging.log4j.LogManager;
|
| 20 | import org.apache.logging.log4j.Logger;
|
| 21 | import org.lwjgl.opengl.GL11;
|
| 22 | import org.lwjgl.opengl.GLContext;
|
| 23 | import tv.twitch.ErrorCode;
|
| 24 |
|
| 25 | public class GuiStreamUnavailable extends GuiScreen
|
| 26 | {
|
| 27 | private static final Logger field_152322_a = LogManager.getLogger();
|
| 28 | private final IChatComponent field_152324_f;
|
| 29 | private final GuiScreen parentScreen;
|
| 30 | private final GuiStreamUnavailable.Reason field_152326_h;
|
| 31 | private final List<ChatComponentTranslation> field_152327_i;
|
| 32 | private final List<String> field_152323_r;
|
| 33 |
|
| 34 | public GuiStreamUnavailable(GuiScreen p_i1070_1_, GuiStreamUnavailable.Reason p_i1070_2_)
|
| 35 | {
|
| 36 | this(p_i1070_1_, p_i1070_2_, (List<ChatComponentTranslation>)null);
|
| 37 | }
|
| 38 |
|
| 39 | public GuiStreamUnavailable(GuiScreen parentScreenIn, GuiStreamUnavailable.Reason p_i46311_2_, List<ChatComponentTranslation> p_i46311_3_)
|
| 40 | {
|
| 41 | this.field_152324_f = new ChatComponentTranslation("stream.unavailable.title", new Object[0]);
|
| 42 | this.field_152323_r = Lists.<String>newArrayList();
|
| 43 | this.parentScreen = parentScreenIn;
|
| 44 | this.field_152326_h = p_i46311_2_;
|
| 45 | this.field_152327_i = p_i46311_3_;
|
| 46 | }
|
| 47 |
|
| 48 | /**
|
| 49 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 50 | * window resizes, the buttonList is cleared beforehand.
|
| 51 | */
|
| 52 | public void initGui()
|
| 53 | {
|
| 54 | if (this.field_152323_r.isEmpty())
|
| 55 | {
|
| 56 | this.field_152323_r.addAll(this.fontRendererObj.listFormattedStringToWidth(this.field_152326_h.func_152561_a().getFormattedText(), (int)((float)this.width * 0.75F)));
|
| 57 |
|
| 58 | if (this.field_152327_i != null)
|
| 59 | {
|
| 60 | this.field_152323_r.add("");
|
| 61 |
|
| 62 | for (ChatComponentTranslation chatcomponenttranslation : this.field_152327_i)
|
| 63 | {
|
| 64 | this.field_152323_r.add(chatcomponenttranslation.getUnformattedTextForChat());
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | if (this.field_152326_h.func_152559_b() != null)
|
| 70 | {
|
| 71 | this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 50, 150, 20, I18n.format("gui.cancel", new Object[0])));
|
| 72 | this.buttonList.add(new GuiButton(1, this.width / 2 - 155 + 160, this.height - 50, 150, 20, I18n.format(this.field_152326_h.func_152559_b().getFormattedText(), new Object[0])));
|
| 73 | }
|
| 74 | else
|
| 75 | {
|
| 76 | this.buttonList.add(new GuiButton(0, this.width / 2 - 75, this.height - 50, 150, 20, I18n.format("gui.cancel", new Object[0])));
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 82 | */
|
| 83 | public void onGuiClosed()
|
| 84 | {
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 89 | */
|
| 90 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 91 | {
|
| 92 | this.drawDefaultBackground();
|
| 93 | int i = Math.max((int)((double)this.height * 0.85D / 2.0D - (double)((float)(this.field_152323_r.size() * this.fontRendererObj.FONT_HEIGHT) / 2.0F)), 50);
|
| 94 | this.drawCenteredString(this.fontRendererObj, this.field_152324_f.getFormattedText(), this.width / 2, i - this.fontRendererObj.FONT_HEIGHT * 2, 16777215);
|
| 95 |
|
| 96 | for (String s : this.field_152323_r)
|
| 97 | {
|
| 98 | this.drawCenteredString(this.fontRendererObj, s, this.width / 2, i, 10526880);
|
| 99 | i += this.fontRendererObj.FONT_HEIGHT;
|
| 100 | }
|
| 101 |
|
| 102 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 103 | }
|
| 104 |
|
| 105 | @SuppressWarnings("incomplete-switch")
|
| 106 |
|
| 107 | /**
|
| 108 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 109 | */
|
| 110 | protected void actionPerformed(GuiButton button) throws IOException
|
| 111 | {
|
| 112 | if (button.enabled)
|
| 113 | {
|
| 114 | if (button.id == 1)
|
| 115 | {
|
| 116 | switch (this.field_152326_h)
|
| 117 | {
|
| 118 | case ACCOUNT_NOT_BOUND:
|
| 119 | case FAILED_TWITCH_AUTH:
|
| 120 | this.func_152320_a("https://account.mojang.com/me/settings");
|
| 121 | break;
|
| 122 |
|
| 123 | case ACCOUNT_NOT_MIGRATED:
|
| 124 | this.func_152320_a("https://account.mojang.com/migrate");
|
| 125 | break;
|
| 126 |
|
| 127 | case UNSUPPORTED_OS_MAC:
|
| 128 | this.func_152320_a("http://www.apple.com/osx/");
|
| 129 | break;
|
| 130 |
|
| 131 | case UNKNOWN:
|
| 132 | case LIBRARY_FAILURE:
|
| 133 | case INITIALIZATION_FAILURE:
|
| 134 | this.func_152320_a("http://bugs.mojang.com/browse/MC");
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | this.mc.displayGuiScreen(this.parentScreen);
|
| 139 | }
|
| 140 | }
|
| 141 |
|
| 142 | private void func_152320_a(String p_152320_1_)
|
| 143 | {
|
| 144 | try
|
| 145 | {
|
| 146 | Class<?> oclass = Class.forName("java.awt.Desktop");
|
| 147 | Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
|
| 148 | oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(p_152320_1_)});
|
| 149 | }
|
| 150 | catch (Throwable throwable)
|
| 151 | {
|
| 152 | field_152322_a.error("Couldn\'t open link", throwable);
|
| 153 | }
|
| 154 | }
|
| 155 |
|
| 156 | public static void func_152321_a(GuiScreen p_152321_0_)
|
| 157 | {
|
| 158 | Minecraft minecraft = Minecraft.getMinecraft();
|
| 159 | IStream istream = minecraft.getTwitchStream();
|
| 160 |
|
| 161 | if (!OpenGlHelper.framebufferSupported)
|
| 162 | {
|
| 163 | List<ChatComponentTranslation> list = Lists.<ChatComponentTranslation>newArrayList();
|
| 164 | list.add(new ChatComponentTranslation("stream.unavailable.no_fbo.version", new Object[] {GL11.glGetString(GL11.GL_VERSION)}));
|
| 165 | list.add(new ChatComponentTranslation("stream.unavailable.no_fbo.blend", new Object[] {Boolean.valueOf(GLContext.getCapabilities().GL_EXT_blend_func_separate)}));
|
| 166 | list.add(new ChatComponentTranslation("stream.unavailable.no_fbo.arb", new Object[] {Boolean.valueOf(GLContext.getCapabilities().GL_ARB_framebuffer_object)}));
|
| 167 | list.add(new ChatComponentTranslation("stream.unavailable.no_fbo.ext", new Object[] {Boolean.valueOf(GLContext.getCapabilities().GL_EXT_framebuffer_object)}));
|
| 168 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.NO_FBO, list));
|
| 169 | }
|
| 170 | else if (istream instanceof NullStream)
|
| 171 | {
|
| 172 | if (((NullStream)istream).func_152937_a().getMessage().contains("Can\'t load AMD 64-bit .dll on a IA 32-bit platform"))
|
| 173 | {
|
| 174 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.LIBRARY_ARCH_MISMATCH));
|
| 175 | }
|
| 176 | else
|
| 177 | {
|
| 178 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.LIBRARY_FAILURE));
|
| 179 | }
|
| 180 | }
|
| 181 | else if (!istream.func_152928_D() && istream.func_152912_E() == ErrorCode.TTV_EC_OS_TOO_OLD)
|
| 182 | {
|
| 183 | switch (Util.getOSType())
|
| 184 | {
|
| 185 | case WINDOWS:
|
| 186 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.UNSUPPORTED_OS_WINDOWS));
|
| 187 | break;
|
| 188 |
|
| 189 | case OSX:
|
| 190 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.UNSUPPORTED_OS_MAC));
|
| 191 | break;
|
| 192 |
|
| 193 | default:
|
| 194 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.UNSUPPORTED_OS_OTHER));
|
| 195 | }
|
| 196 | }
|
| 197 | else if (!minecraft.getTwitchDetails().containsKey("twitch_access_token"))
|
| 198 | {
|
| 199 | if (minecraft.getSession().getSessionType() == Session.Type.LEGACY)
|
| 200 | {
|
| 201 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.ACCOUNT_NOT_MIGRATED));
|
| 202 | }
|
| 203 | else
|
| 204 | {
|
| 205 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.ACCOUNT_NOT_BOUND));
|
| 206 | }
|
| 207 | }
|
| 208 | else if (!istream.func_152913_F())
|
| 209 | {
|
| 210 | switch (istream.func_152918_H())
|
| 211 | {
|
| 212 | case INVALID_TOKEN:
|
| 213 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.FAILED_TWITCH_AUTH));
|
| 214 | break;
|
| 215 |
|
| 216 | case ERROR:
|
| 217 | default:
|
| 218 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.FAILED_TWITCH_AUTH_ERROR));
|
| 219 | }
|
| 220 | }
|
| 221 | else if (istream.func_152912_E() != null)
|
| 222 | {
|
| 223 | List<ChatComponentTranslation> list1 = Arrays.<ChatComponentTranslation>asList(new ChatComponentTranslation[] {new ChatComponentTranslation("stream.unavailable.initialization_failure.extra", new Object[]{ErrorCode.getString(istream.func_152912_E())})});
|
| 224 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.INITIALIZATION_FAILURE, list1));
|
| 225 | }
|
| 226 | else
|
| 227 | {
|
| 228 | minecraft.displayGuiScreen(new GuiStreamUnavailable(p_152321_0_, GuiStreamUnavailable.Reason.UNKNOWN));
|
| 229 | }
|
| 230 | }
|
| 231 |
|
| 232 | public static enum Reason
|
| 233 | {
|
| 234 | NO_FBO(new ChatComponentTranslation("stream.unavailable.no_fbo", new Object[0])),
|
| 235 | LIBRARY_ARCH_MISMATCH(new ChatComponentTranslation("stream.unavailable.library_arch_mismatch", new Object[0])),
|
| 236 | LIBRARY_FAILURE(new ChatComponentTranslation("stream.unavailable.library_failure", new Object[0]), new ChatComponentTranslation("stream.unavailable.report_to_mojang", new Object[0])),
|
| 237 | UNSUPPORTED_OS_WINDOWS(new ChatComponentTranslation("stream.unavailable.not_supported.windows", new Object[0])),
|
| 238 | UNSUPPORTED_OS_MAC(new ChatComponentTranslation("stream.unavailable.not_supported.mac", new Object[0]), new ChatComponentTranslation("stream.unavailable.not_supported.mac.okay", new Object[0])),
|
| 239 | UNSUPPORTED_OS_OTHER(new ChatComponentTranslation("stream.unavailable.not_supported.other", new Object[0])),
|
| 240 | ACCOUNT_NOT_MIGRATED(new ChatComponentTranslation("stream.unavailable.account_not_migrated", new Object[0]), new ChatComponentTranslation("stream.unavailable.account_not_migrated.okay", new Object[0])),
|
| 241 | ACCOUNT_NOT_BOUND(new ChatComponentTranslation("stream.unavailable.account_not_bound", new Object[0]), new ChatComponentTranslation("stream.unavailable.account_not_bound.okay", new Object[0])),
|
| 242 | FAILED_TWITCH_AUTH(new ChatComponentTranslation("stream.unavailable.failed_auth", new Object[0]), new ChatComponentTranslation("stream.unavailable.failed_auth.okay", new Object[0])),
|
| 243 | FAILED_TWITCH_AUTH_ERROR(new ChatComponentTranslation("stream.unavailable.failed_auth_error", new Object[0])),
|
| 244 | INITIALIZATION_FAILURE(new ChatComponentTranslation("stream.unavailable.initialization_failure", new Object[0]), new ChatComponentTranslation("stream.unavailable.report_to_mojang", new Object[0])),
|
| 245 | UNKNOWN(new ChatComponentTranslation("stream.unavailable.unknown", new Object[0]), new ChatComponentTranslation("stream.unavailable.report_to_mojang", new Object[0]));
|
| 246 |
|
| 247 | private final IChatComponent field_152574_m;
|
| 248 | private final IChatComponent field_152575_n;
|
| 249 |
|
| 250 | private Reason(IChatComponent p_i1066_3_)
|
| 251 | {
|
| 252 | this(p_i1066_3_, (IChatComponent)null);
|
| 253 | }
|
| 254 |
|
| 255 | private Reason(IChatComponent p_i1067_3_, IChatComponent p_i1067_4_)
|
| 256 | {
|
| 257 | this.field_152574_m = p_i1067_3_;
|
| 258 | this.field_152575_n = p_i1067_4_;
|
| 259 | }
|
| 260 |
|
| 261 | public IChatComponent func_152561_a()
|
| 262 | {
|
| 263 | return this.field_152574_m;
|
| 264 | }
|
| 265 |
|
| 266 | public IChatComponent func_152559_b()
|
| 267 | {
|
| 268 | return this.field_152575_n;
|
| 269 | }
|
| 270 | }
|
| 271 | }
|
| 272 |
|