Search in sources :

Example 36 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project ViaFabric by ViaVersion.

the class ViaConfigScreen method onClickClientSide.

private void onClickClientSide(ButtonWidget widget) {
    if (!ViaFabric.config.isClientSideEnabled()) {
        MinecraftClient.getInstance().openScreen(new ConfirmScreen(answer -> {
            if (answer) {
                ViaFabric.config.setClientSideEnabled(true);
                // AUTO
                ViaFabric.config.setClientSideVersion(-2);
                ViaFabric.config.saveConfig();
                widget.setMessage(getClientSideText().asString());
            }
            MinecraftClient.getInstance().openScreen(this);
        }, new TranslatableText("gui.enable_client_side.question"), new TranslatableText("gui.enable_client_side.warning"), new TranslatableText("gui.enable_client_side.enable").asString(), new TranslatableText("gui.cancel").asString()));
    } else {
        ViaFabric.config.setClientSideEnabled(false);
        ViaFabric.config.saveConfig();
    }
    widget.setMessage(getClientSideText().asString());
}
Also used : Screen(net.minecraft.client.gui.screen.Screen) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) AbstractViaConfigScreen(com.viaversion.fabric.common.config.AbstractViaConfigScreen) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) Environment(net.fabricmc.api.Environment) TranslatableText(net.minecraft.text.TranslatableText) EnvType(net.fabricmc.api.EnvType) ViaFabric(com.viaversion.fabric.mc114.ViaFabric) MinecraftClient(net.minecraft.client.MinecraftClient) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) CompletableFuture(java.util.concurrent.CompletableFuture) ProtocolUtils(com.viaversion.fabric.common.util.ProtocolUtils) TranslatableText(net.minecraft.text.TranslatableText) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen)

Example 37 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project ViaFabric by ViaVersion.

the class ViaFabricClient method registerGui.

private void registerGui() {
    try {
        ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
            if (!(screen instanceof MultiplayerScreen))
                return;
            ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10, // Size
            40, // Size
            20, // Start pos of texture
            0, // Start pos of texture
            0, // v Hover offset
            20, new Identifier("viafabric:textures/gui/widgets.png"), // Texture size
            256, // Texture size
            256, it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)), new TranslatableText("gui.via_button"));
            if (ViaFabric.config.isHideButton())
                enableClientSideViaVersion.visible = false;
            Screens.getButtons(screen).add(enableClientSideViaVersion);
        });
    } catch (NoClassDefFoundError ignored) {
        ViaFabric.JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) MultiplayerScreen(net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen) Identifier(net.minecraft.util.Identifier) ViaConfigScreen(com.viaversion.fabric.mc117.gui.ViaConfigScreen) TexturedButtonWidget(net.minecraft.client.gui.widget.TexturedButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) TexturedButtonWidget(net.minecraft.client.gui.widget.TexturedButtonWidget)

Example 38 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project ViaFabric by ViaVersion.

the class ViaConfigScreen method onClickClientSide.

private void onClickClientSide(ButtonWidget widget) {
    if (!ViaFabric.config.isClientSideEnabled()) {
        MinecraftClient.getInstance().openScreen(new ConfirmScreen(answer -> {
            if (answer) {
                ViaFabric.config.setClientSideEnabled(true);
                // AUTO
                ViaFabric.config.setClientSideVersion(-2);
                ViaFabric.config.saveConfig();
                widget.setMessage(getClientSideText());
            }
            MinecraftClient.getInstance().openScreen(this);
        }, new TranslatableText("gui.enable_client_side.question"), new TranslatableText("gui.enable_client_side.warning"), new TranslatableText("gui.enable_client_side.enable"), new TranslatableText("gui.cancel")));
    } else {
        ViaFabric.config.setClientSideEnabled(false);
        ViaFabric.config.saveConfig();
    }
    widget.setMessage(getClientSideText());
}
Also used : ScreenTexts(net.minecraft.client.gui.screen.ScreenTexts) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) AbstractViaConfigScreen(com.viaversion.fabric.common.config.AbstractViaConfigScreen) ViaFabric(com.viaversion.fabric.mc116.ViaFabric) Environment(net.fabricmc.api.Environment) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) CompletableFuture(java.util.concurrent.CompletableFuture) ProtocolUtils(com.viaversion.fabric.common.util.ProtocolUtils) Screen(net.minecraft.client.gui.screen.Screen) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) EnvType(net.fabricmc.api.EnvType) MinecraftClient(net.minecraft.client.MinecraftClient) TranslatableText(net.minecraft.text.TranslatableText) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen)

Example 39 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project ViaFabric by ViaVersion.

the class MixinMultiplayerScreen method onInit.

@Inject(method = "init", at = @At("TAIL"), remap = false)
private void onInit(CallbackInfo ci) {
    ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(this.width / 2 + 113, 10, // Size
    40, // Size
    20, // Start pos of texture
    0, // Start pos of texture
    0, // v Hover offset
    20, new Identifier("viafabric:textures/gui/widgets.png"), // Texture size
    256, // Texture size
    256, it -> MinecraftClient.getInstance().openScreen(new ViaConfigScreen(this)), new TranslatableText("gui.via_button").asString());
    if (ViaFabric.config.isHideButton())
        enableClientSideViaVersion.visible = false;
    addButton(enableClientSideViaVersion);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) Identifier(net.minecraft.util.Identifier) ViaConfigScreen(com.viaversion.fabric.mc115.gui.ViaConfigScreen) TexturedButtonWidget(net.minecraft.client.gui.widget.TexturedButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) TexturedButtonWidget(net.minecraft.client.gui.widget.TexturedButtonWidget) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 40 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project ViaFabric by ViaVersion.

the class ViaConfigScreen method onClickClientSide.

private void onClickClientSide(ButtonWidget widget) {
    if (!ViaFabric.config.isClientSideEnabled()) {
        MinecraftClient.getInstance().openScreen(new ConfirmScreen(answer -> {
            if (answer) {
                ViaFabric.config.setClientSideEnabled(true);
                // AUTO
                ViaFabric.config.setClientSideVersion(-2);
                ViaFabric.config.saveConfig();
                widget.setMessage(getClientSideText().asString());
            }
            MinecraftClient.getInstance().openScreen(this);
        }, new TranslatableText("gui.enable_client_side.question"), new TranslatableText("gui.enable_client_side.warning"), new TranslatableText("gui.enable_client_side.enable").asString(), new TranslatableText("gui.cancel").asString()));
    } else {
        ViaFabric.config.setClientSideEnabled(false);
        ViaFabric.config.saveConfig();
    }
    widget.setMessage(getClientSideText().asString());
}
Also used : Screen(net.minecraft.client.gui.screen.Screen) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) AbstractViaConfigScreen(com.viaversion.fabric.common.config.AbstractViaConfigScreen) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) Environment(net.fabricmc.api.Environment) TranslatableText(net.minecraft.text.TranslatableText) EnvType(net.fabricmc.api.EnvType) MinecraftClient(net.minecraft.client.MinecraftClient) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) CompletableFuture(java.util.concurrent.CompletableFuture) ViaFabric(com.viaversion.fabric.mc115.ViaFabric) ProtocolUtils(com.viaversion.fabric.common.util.ProtocolUtils) TranslatableText(net.minecraft.text.TranslatableText) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen)

Aggregations

ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)114 Screen (net.minecraft.client.gui.screen.Screen)84 MatrixStack (net.minecraft.client.util.math.MatrixStack)70 LiteralText (net.minecraft.text.LiteralText)67 TranslatableText (net.minecraft.text.TranslatableText)54 MinecraftClient (net.minecraft.client.MinecraftClient)42 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)41 Text (net.minecraft.text.Text)30 GLFW (org.lwjgl.glfw.GLFW)27 Inject (org.spongepowered.asm.mixin.injection.Inject)25 ConfirmScreen (net.minecraft.client.gui.screen.ConfirmScreen)20 EnvType (net.fabricmc.api.EnvType)19 Environment (net.fabricmc.api.Environment)19 ScreenTexts (net.minecraft.client.gui.screen.ScreenTexts)19 Mixin (org.spongepowered.asm.mixin.Mixin)19 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)18 ArrayList (java.util.ArrayList)18 At (org.spongepowered.asm.mixin.injection.At)18 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)18 Wrapper (me.dustin.jex.helper.misc.Wrapper)17