| 1 | package com.mojang.blaze3d.platform;
|
| 2 |
|
| 3 | import com.mojang.logging.LogUtils;
|
| 4 | import java.nio.IntBuffer;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import org.lwjgl.sdl.SDLError;
|
| 8 | import org.lwjgl.sdl.SDLMessageBox;
|
| 9 | import org.lwjgl.sdl.SDL_MessageBoxButtonData;
|
| 10 | import org.lwjgl.sdl.SDL_MessageBoxData;
|
| 11 | import org.lwjgl.sdl.SDL_MessageBoxButtonData.Buffer;
|
| 12 | import org.lwjgl.system.MemoryStack;
|
| 13 | import org.slf4j.Logger;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class MessageBox {
|
| 17 | private static final Logger LOGGER = LogUtils.getLogger();
|
| 18 | private static final String DEFAULT_TITLE = "Minecraft";
|
| 19 | private static final int BUTTON_ID_YES = 1;
|
| 20 | private static final String BUTTON_TITLE_YES = "Yes";
|
| 21 | private static final int BUTTON_ID_NO = 2;
|
| 22 | private static final String BUTTON_TITLE_NO = "No";
|
| 23 |
|
| 24 | public static void error(final String message) {
|
| 25 | if (!SDLMessageBox.SDL_ShowSimpleMessageBox(16, "Minecraft", message, 0L)) {
|
| 26 | String error = SDLError.SDL_GetError();
|
| 27 | LOGGER.error("Failed to show error message '{}': {}", message, error);
|
| 28 | }
|
| 29 | }
|
| 30 |
|
| 31 | public static boolean errorWithContinue(final String message) {
|
| 32 | try (MemoryStack stack = MemoryStack.stackPush()) {
|
| 33 | IntBuffer buttonResult = stack.callocInt(1);
|
| 34 | Buffer buttonData = SDL_MessageBoxButtonData.calloc(2, stack);
|
| 35 | buttonData.get(0).buttonID(1).text(stack.UTF8("Yes"));
|
| 36 | buttonData.get(1).buttonID(2).text(stack.UTF8("No"));
|
| 37 | SDL_MessageBoxData data = SDL_MessageBoxData.calloc(stack)
|
| 38 | .flags(16)
|
| 39 | .title(stack.UTF8("Minecraft", true))
|
| 40 | .message(stack.UTF8(message, true))
|
| 41 | .buttons(buttonData);
|
| 42 | if (SDLMessageBox.SDL_ShowMessageBox(data, buttonResult)) {
|
| 43 | return buttonResult.get(0) == 1;
|
| 44 | }
|
| 45 |
|
| 46 | String error = SDLError.SDL_GetError();
|
| 47 | LOGGER.error("Failed to show error message '{}': {}", message, error);
|
| 48 | return false;
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 |
|