Search in sources :

Example 6 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project BlockMeter by ModProg.

the class SelectBoxGui method init.

@Override
protected void init() {
    final int uiHeight = (boxes.length + 1) * (BUTTONHEIGHT + PADDING);
    for (int i = 0; i < boxes.length; i++) {
        final ClientMeasureBox box = boxes[i];
        final TranslatableText text = new TranslatableText("blockmeter.boxToString", new Object[] { box.getBlockStart().getX(), box.getBlockStart().getY(), box.getBlockStart().getZ(), box.getBlockEnd().getX(), box.getBlockEnd().getY(), box.getBlockEnd().getZ() });
        // text.setStyle(text.getStyle().withColor(TextColor.fromRgb(box.getColor().getSignColor())));
        this.addDrawableChild(new ColorButton(this.width / 2 - (BUTTONWIDTH) / 2, this.height / 2 - uiHeight / 2 + i * (BUTTONHEIGHT + PADDING), BUTTONWIDTH, BUTTONHEIGHT, text, box.getColor().getColorComponents(), false, true, button -> {
            box.loosenCorner(block);
            MinecraftClient.getInstance().setScreen((Screen) null);
        }));
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 - uiHeight / 2 + boxes.length * (BUTTONHEIGHT + PADDING) + PADDING, BUTTONWIDTH, BUTTONHEIGHT, new TranslatableText("gui.cancel"), button -> {
        MinecraftClient.getInstance().setScreen((Screen) null);
    }));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NarratorManager(net.minecraft.client.util.NarratorManager) Screen(net.minecraft.client.gui.screen.Screen) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) MinecraftClient(net.minecraft.client.MinecraftClient) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) BlockPos(net.minecraft.util.math.BlockPos) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) Screen(net.minecraft.client.gui.screen.Screen) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget)

Example 7 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project RPG-Hud by KurodaAkira.

the class GuiSettingsMod method init.

@Override
public void init() {
    TextRenderer fontRenderer = client.textRenderer;
    if (this.subSetting.equals("")) {
        GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + 0 % 2 * 160, this.height / 6 - 14 + 20 * (0 >> 1), "general", new TranslatableText("gui.rpg.general"), button -> {
            GuiButtonTooltip b = (GuiButtonTooltip) button;
            if (b.enumOptions != null)
                client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
        }).setTooltip(I18n.translate("tooltip.general", new Object[0]));
        this.addDrawableChild(guismallbutton);
        int count = 1;
        for (HudElementType type : HudElementType.values()) {
            List<String> settings = this.settings.getSettingsOf(type);
            if (!settings.isEmpty()) {
                guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + count % 2 * 160, this.height / 6 - 14 + 20 * (count >> 1), type.name(), new TranslatableText(type.getDisplayName()), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        this.client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                    }
                }).setTooltip(I18n.translate("tooltip.element", new Object[0]));
                this.addDrawableChild(guismallbutton);
                count++;
            }
        }
    } else {
        List<String> settingList = this.settings.getSettingsOf(this.subSetting);
        for (int i = 0; i < settingList.size(); i++) {
            if (this.settings.getSetting(settingList.get(i)) instanceof SettingPosition) {
                String[] values = ((String) this.settings.getSetting(settingList.get(i)).getValue()).split("_");
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel settingLabel = new GuiTextLabel(this.width / 2 - 152 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                labelList.add(settingLabel);
                TextFieldWidget xPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[0]));
                xPos.setText(values[0]);
                xPos.setMaxLength(6);
                this.addDrawableChild(xPos);
                fields.add(xPos);
                TextFieldWidget yPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160 + 48, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[1]));
                yPos.setText(values[1]);
                yPos.setMaxLength(6);
                this.addDrawableChild(yPos);
                fields.add(yPos);
                textFields.put(settingList.get(i), fields);
            } else if (this.settings.getSetting(settingList.get(i)) instanceof SettingDouble) {
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel scaleLabel = new GuiTextLabel(this.width / 2 - 151 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                TextFieldWidget scale = new TextFieldWidgetMod(fontRenderer, ValueType.DOUBLE, this.width / 2 - 100 + i % 2 * 160 + 3, this.height / 6 - 12 + 20 * (i >> 1), 90, 15, new TranslatableText(String.valueOf(this.settings.getDoubleValue(settingList.get(i)))));
                scale.setText(String.valueOf(this.settings.getDoubleValue(settingList.get(i))));
                labelList.add(scaleLabel);
                this.addDrawableChild(scale);
                fields.add(scale);
                textFields.put(settingList.get(i), fields);
            } else {
                GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 14 + 20 * (i >> 1), settingList.get(i), new TranslatableText(this.settings.getButtonString(settingList.get(i))), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        if (settings.getSetting(b.enumOptions) instanceof SettingColor) {
                            client.setScreen(new GuiSettingsModColor(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                        } else {
                            settings.increment(b.enumOptions);
                            button.setMessage(new TranslatableText(settings.getButtonString(b.enumOptions)));
                        }
                    }
                }).setTooltip(this.settings.getSetting(settingList.get(i)).getTooltip());
                this.addDrawableChild(guismallbutton);
            }
        }
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, new TranslatableText("gui.done"), button -> {
        Settings settings = ModRPGHud.instance.settings;
        for (String settingID : textFields.keySet()) {
            for (TextFieldWidget t : textFields.get(settingID)) {
                if (t instanceof TextFieldWidgetMod) {
                    ValueType type = ((TextFieldWidgetMod) t).getValueType();
                    switch(type) {
                        case DOUBLE:
                            double value;
                            try {
                                value = Double.valueOf(textFields.get(settingID).get(0).getText());
                                this.settings.getSetting(settingID).setValue(value);
                            } catch (NumberFormatException e) {
                            }
                            break;
                        case POSITION:
                            this.settings.getSetting(settingID).setValue(textFields.get(settingID).get(0).getText() + "_" + textFields.get(settingID).get(1).getText());
                            break;
                    }
                }
            }
        }
        settings.saveSettings();
        client.setScreen(parent);
    }));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) I18n(net.minecraft.client.resource.language.I18n) Environment(net.fabricmc.api.Environment) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) HashMap(java.util.HashMap) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ArrayList(java.util.ArrayList) List(java.util.List) ModRPGHud(net.spellcraftgaming.rpghud.main.ModRPGHud) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) Screen(net.minecraft.client.gui.screen.Screen) Settings(net.spellcraftgaming.rpghud.settings.Settings) DrawableHelper(net.minecraft.client.gui.DrawableHelper) Map(java.util.Map) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) EnvType(net.fabricmc.api.EnvType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) Text(net.minecraft.text.Text) TextRenderer(net.minecraft.client.font.TextRenderer) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Settings(net.spellcraftgaming.rpghud.settings.Settings) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 8 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project como-client by gingerchicken.

the class LecternScreenMixin method init.

@Inject(at = { @At("TAIL") }, method = { "init" })
public void init(CallbackInfo ci) {
    LecternCrash lecternCrash = this.getLecternCrash();
    if (!lecternCrash.isEnabled())
        return;
    int buttonWidth = 98;
    int buttonHeight = 20;
    this.addDrawableChild(new ButtonWidget(this.width / 2 - buttonWidth / 2, 196 + buttonHeight + 4, buttonWidth, buttonHeight, Text.of("Crash"), button -> {
        lecternCrash.doCrash();
        this.close();
        button.active = false;
    }));
}
Also used : CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Screen(net.minecraft.client.gui.screen.Screen) Mixin(org.spongepowered.asm.mixin.Mixin) Inject(org.spongepowered.asm.mixin.injection.Inject) LecternCrash(net.como.client.modules.exploits.LecternCrash) ComoClient(net.como.client.ComoClient) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) Text(net.minecraft.text.Text) LecternScreen(net.minecraft.client.gui.screen.ingame.LecternScreen) At(org.spongepowered.asm.mixin.injection.At) LecternCrash(net.como.client.modules.exploits.LecternCrash) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project EssentialClient by senseiwells.

the class TitleScreenMixin method onInit.

@Inject(method = "initWidgetsNormal", at = @At("TAIL"))
private void onInit(CallbackInfo ci) {
    if (this.client == null || !ClientRules.ESSENTIAL_CLIENT_BUTTON.getValue()) {
        return;
    }
    ButtonWidget buttonWidget = this.addButton(new ButtonWidget(this.width / 2 - 100, this.height / 4 + 120, 200, 20, new LiteralText("Essential Client Menu"), (b) -> this.client.openScreen(new ConfigScreen(this))));
    buttonWidget.active = true;
}
Also used : LiteralText(net.minecraft.text.LiteralText) ClientRules(essentialclient.clientrule.ClientRules) Inject(org.spongepowered.asm.mixin.injection.Inject) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ConfigScreen(essentialclient.gui.ConfigScreen) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) TitleScreen(net.minecraft.client.gui.screen.TitleScreen) Screen(net.minecraft.client.gui.screen.Screen) Mixin(org.spongepowered.asm.mixin.Mixin) Constant(org.spongepowered.asm.mixin.injection.Constant) Text(net.minecraft.text.Text) ModifyConstant(org.spongepowered.asm.mixin.injection.ModifyConstant) At(org.spongepowered.asm.mixin.injection.At) ConfigScreen(essentialclient.gui.ConfigScreen) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project Wurst7 by Wurst-Imperium.

the class AltManagerScreen method init.

@Override
public void init() {
    listGui = new ListGui(client, this, altManager.getList());
    Exception folderException = altManager.getFolderException();
    if (folderException != null && shouldAsk) {
        TranslatableText title = new TranslatableText("gui.wurst.altmanager.folder_error.title");
        TranslatableText message = new TranslatableText("gui.wurst.altmanager.folder_error.message", folderException);
        TranslatableText buttonText = new TranslatableText("gui.done");
        // This just sets shouldAsk to false and closes the message.
        Runnable action = () -> confirmGenerate(false);
        NoticeScreen screen = new NoticeScreen(action, title, message, buttonText);
        client.setScreen(screen);
    } else if (altManager.getList().isEmpty() && shouldAsk) {
        TranslatableText title = new TranslatableText("gui.wurst.altmanager.empty.title");
        TranslatableText message = new TranslatableText("gui.wurst.altmanager.empty.message");
        BooleanConsumer callback = this::confirmGenerate;
        ConfirmScreen screen = new ConfirmScreen(callback, title, message);
        client.setScreen(screen);
    }
    addDrawableChild(useButton = new ButtonWidget(width / 2 - 154, height - 52, 100, 20, new LiteralText("Login"), b -> pressLogin()));
    addDrawableChild(new ButtonWidget(width / 2 - 50, height - 52, 100, 20, new LiteralText("Direct Login"), b -> client.setScreen(new DirectLoginScreen(this))));
    addDrawableChild(new ButtonWidget(width / 2 + 54, height - 52, 100, 20, new LiteralText("Add"), b -> client.setScreen(new AddAltScreen(this, altManager))));
    addDrawableChild(starButton = new ButtonWidget(width / 2 - 154, height - 28, 75, 20, new LiteralText("Favorite"), b -> pressFavorite()));
    addDrawableChild(editButton = new ButtonWidget(width / 2 - 76, height - 28, 74, 20, new LiteralText("Edit"), b -> pressEdit()));
    addDrawableChild(deleteButton = new ButtonWidget(width / 2 + 2, height - 28, 74, 20, new LiteralText("Delete"), b -> pressDelete()));
    addDrawableChild(new ButtonWidget(width / 2 + 80, height - 28, 75, 20, new LiteralText("Cancel"), b -> client.setScreen(prevScreen)));
    addDrawableChild(importButton = new ButtonWidget(8, 8, 50, 20, new LiteralText("Import"), b -> pressImportAlts()));
    addDrawableChild(exportButton = new ButtonWidget(58, 8, 50, 20, new LiteralText("Export"), b -> pressExportAlts()));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) JsonException(net.wurstclient.util.json.JsonException) TranslatableText(net.minecraft.text.TranslatableText) ArrayList(java.util.ArrayList) VertexFormat(net.minecraft.client.render.VertexFormat) HashSet(java.util.HashSet) Style(net.minecraft.text.Style) InvalidPathException(java.nio.file.InvalidPathException) StringVisitable(net.minecraft.text.StringVisitable) NoticeScreen(net.minecraft.client.gui.screen.NoticeScreen) BufferRenderer(net.minecraft.client.render.BufferRenderer) GL11(org.lwjgl.opengl.GL11) VertexFormats(net.minecraft.client.render.VertexFormats) Path(java.nio.file.Path) ClickableWidget(net.minecraft.client.gui.widget.ClickableWidget) Drawable(net.minecraft.client.gui.Drawable) Tessellator(net.minecraft.client.render.Tessellator) Matrix4f(net.minecraft.util.math.Matrix4f) Files(java.nio.file.Files) BooleanConsumer(it.unimi.dsi.fastutil.booleans.BooleanConsumer) MultiProcessingUtils(net.wurstclient.util.MultiProcessingUtils) GameRenderer(net.minecraft.client.render.GameRenderer) MatrixStack(net.minecraft.client.util.math.MatrixStack) IScreen(net.wurstclient.mixinterface.IScreen) IOException(java.io.IOException) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ListWidget(net.wurstclient.util.ListWidget) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) GLFW(org.lwjgl.glfw.GLFW) WsonObject(net.wurstclient.util.json.WsonObject) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) net.wurstclient.altmanager(net.wurstclient.altmanager) Paths(java.nio.file.Paths) WurstClient(net.wurstclient.WurstClient) MathHelper(net.minecraft.util.math.MathHelper) StringJoiner(java.util.StringJoiner) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) BufferBuilder(net.minecraft.client.render.BufferBuilder) MinecraftClient(net.minecraft.client.MinecraftClient) Text(net.minecraft.text.Text) BufferedReader(java.io.BufferedReader) JsonUtils(net.wurstclient.util.json.JsonUtils) NoticeScreen(net.minecraft.client.gui.screen.NoticeScreen) BooleanConsumer(it.unimi.dsi.fastutil.booleans.BooleanConsumer) JsonException(net.wurstclient.util.json.JsonException) InvalidPathException(java.nio.file.InvalidPathException) IOException(java.io.IOException) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)138 Screen (net.minecraft.client.gui.screen.Screen)100 LiteralText (net.minecraft.text.LiteralText)87 MatrixStack (net.minecraft.client.util.math.MatrixStack)84 TranslatableText (net.minecraft.text.TranslatableText)57 MinecraftClient (net.minecraft.client.MinecraftClient)51 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)46 Text (net.minecraft.text.Text)43 Inject (org.spongepowered.asm.mixin.injection.Inject)32 GLFW (org.lwjgl.glfw.GLFW)28 ArrayList (java.util.ArrayList)26 List (java.util.List)26 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)25 ScreenTexts (net.minecraft.client.gui.screen.ScreenTexts)25 Mixin (org.spongepowered.asm.mixin.Mixin)25 Identifier (net.minecraft.util.Identifier)24 At (org.spongepowered.asm.mixin.injection.At)23 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)23 EnvType (net.fabricmc.api.EnvType)21 Environment (net.fabricmc.api.Environment)21