Search in sources :

Example 1 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project SpeedRunIGT by RedLime.

the class SpeedRunCategoryScreen method init.

@Override
protected void init() {
    assert client != null;
    addButton(new ButtonWidget(width / 2 - 100, height - 35, 200, 20, ScreenTexts.CANCEL, button -> client.openScreen(parent)));
    this.listWidget = new CategorySelectionListWidget(client);
    addChild(listWidget);
}
Also used : InGameTimer(com.redlimerl.speedrunigt.timer.InGameTimer) SpeedRunOption(com.redlimerl.speedrunigt.option.SpeedRunOption) SpeedRunOptions(com.redlimerl.speedrunigt.option.SpeedRunOptions) Util(net.minecraft.util.Util) Environment(net.fabricmc.api.Environment) TranslatableText(net.minecraft.text.TranslatableText) CheckboxWidget(net.minecraft.client.gui.widget.CheckboxWidget) ArrayList(java.util.ArrayList) EnvType(net.fabricmc.api.EnvType) ElementListWidget(net.minecraft.client.gui.widget.ElementListWidget) GlStateManager(com.mojang.blaze3d.platform.GlStateManager) ScreenTexts(net.minecraft.client.gui.screen.ScreenTexts) I18n(net.minecraft.client.resource.language.I18n) MatrixStack(net.minecraft.client.util.math.MatrixStack) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) Collectors(java.util.stream.Collectors) RunCategory(com.redlimerl.speedrunigt.timer.running.RunCategory) TimerStatus(com.redlimerl.speedrunigt.timer.TimerStatus) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) MathHelper(net.minecraft.util.math.MathHelper) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) TextRenderer(net.minecraft.client.font.TextRenderer) Element(net.minecraft.client.gui.Element) AbstractPressableButtonWidget(net.minecraft.client.gui.widget.AbstractPressableButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) AbstractPressableButtonWidget(net.minecraft.client.gui.widget.AbstractPressableButtonWidget)

Example 2 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project SpeedRunIGT by RedLime.

the class SpeedRunOptionScreen method init.

@Override
protected void init() {
    super.init();
    categorySubButtons.clear();
    categorySelectButtons.clear();
    tooltips.clear();
    List<OptionButtonFactory> optionButtonFactoryList = SpeedRunOption.getOptionButtonFactories();
    int categoryCount = 0;
    for (OptionButtonFactory factory : optionButtonFactoryList) {
        OptionButtonFactory.Storage builder = factory.create(this).build();
        AbstractButtonWidget button = builder.getButtonWidget();
        if (builder.getTooltip() != null)
            tooltips.put(button, builder.getTooltip());
        String category = builder.getCategory();
        ArrayList<AbstractButtonWidget> categoryList = categorySubButtons.getOrDefault(category, new ArrayList<>());
        categoryList.add(button);
        categorySubButtons.put(category, categoryList);
        if (!categorySelectButtons.containsKey(category)) {
            ButtonWidget buttonWidget = new ButtonWidget(width - 110, 30 + (categoryCount++ * 22), 80, 20, new TranslatableText(category), (ButtonWidget buttonWidget1) -> selectCategory(category));
            categorySelectButtons.put(category, buttonWidget);
            addButton(buttonWidget);
        }
    }
    addButton(new ButtonWidget(width - 85, height - 35, 70, 20, ScreenTexts.CANCEL, (ButtonWidget button) -> onClose()));
    addButton(new ButtonWidget(15, height - 35, 70, 20, new TranslatableText("speedrunigt.menu.donate"), (ButtonWidget button) -> Util.getOperatingSystem().open("https://ko-fi.com/redlimerl")));
    buttonListWidget = addChild(new ButtonScrollListWidget());
    categorySelectButtons.keySet().stream().findFirst().ifPresent(this::selectCategory);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) OptionButtonFactory(com.redlimerl.speedrunigt.api.OptionButtonFactory) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget)

Example 3 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project SpeedRunIGT by RedLime.

the class TimerCustomizeScreen method initIGTButtons.

public void initIGTButtons() {
    igtOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 - 16, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_red", "IGT").append(" : ").append(String.valueOf(ColorMixer.getRed(drawer.getIGTColor()))), ColorMixer.getRed(drawer.getIGTColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_red", "IGT").append(" : ").append(String.valueOf(ColorMixer.getRed(drawer.getIGTColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getIGTColor();
            drawer.setIGTColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), (int) (this.value * 255), ColorMixer.getGreen(color), ColorMixer.getBlue(color)));
            changed = true;
        }
    }));
    igtOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 + 6, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_green", "IGT").append(" : ").append(String.valueOf(ColorMixer.getGreen(drawer.getIGTColor()))), ColorMixer.getGreen(drawer.getIGTColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_green", "IGT").append(" : ").append(String.valueOf(ColorMixer.getGreen(drawer.getIGTColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getIGTColor();
            drawer.setIGTColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), ColorMixer.getRed(color), (int) (this.value * 255), ColorMixer.getBlue(color)));
            changed = true;
        }
    }));
    igtOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 + 28, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_blue", "IGT").append(" : ").append(String.valueOf(ColorMixer.getBlue(drawer.getIGTColor()))), ColorMixer.getBlue(drawer.getIGTColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_blue", "IGT").append(" : ").append(String.valueOf(ColorMixer.getBlue(drawer.getIGTColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getIGTColor();
            drawer.setIGTColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), ColorMixer.getRed(color), ColorMixer.getGreen(color), (int) (this.value * 255)));
            changed = true;
        }
    }));
    igtOptions.add(addButton(new SliderWidget(width / 2 + 6, height / 2 - 16, 120, 20, new TranslatableText("speedrunigt.option.timer_position.scale", "IGT").append(" : ").append(((int) (drawer.getIGTScale() * 100)) + "%"), drawer.getIGTScale() / 3f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.scale", "IGT").append(" : ").append(((int) (drawer.getIGTScale() * 100)) + "%"));
        }

        @Override
        protected void applyValue() {
            drawer.setIGTScale(Math.round((float) this.value * 3f * 20f) / 20f);
            changed = true;
        }
    }));
    igtOptions.add(addButton(new ButtonWidget(width / 2 + 6, height / 2 + 6, 120, 20, new TranslatableText("speedrunigt.option.timer_position.text_decorate", "IGT").append(" : ").append(new TranslatableText("speedrunigt.option.timer_position.text_decorate." + drawer.getIGTDecoration().name().toLowerCase(Locale.ROOT))), (ButtonWidget button) -> {
        int order = drawer.getIGTDecoration().ordinal();
        drawer.setIGTDecoration(TimerDecoration.values()[(++order) % TimerDecoration.values().length]);
        changed = true;
        button.setMessage(new TranslatableText("speedrunigt.option.timer_position.text_decorate", "IGT").append(" : ").append(new TranslatableText("speedrunigt.option.timer_position.text_decorate." + drawer.getIGTDecoration().name().toLowerCase(Locale.ROOT))));
    })));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) SliderWidget(net.minecraft.client.gui.widget.SliderWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget)

Example 4 with ButtonWidget

use of net.minecraft.client.gui.widget.ButtonWidget in project SpeedRunIGT by RedLime.

the class TimerCustomizeScreen method initRTAButtons.

public void initRTAButtons() {
    rtaOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 - 16, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_red", "RTA").append(" : ").append(String.valueOf(ColorMixer.getRed(drawer.getRTAColor()))), ColorMixer.getRed(drawer.getRTAColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_red", "RTA").append(" : ").append(String.valueOf(ColorMixer.getRed(drawer.getRTAColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getRTAColor();
            drawer.setRTAColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), (int) (this.value * 255), ColorMixer.getGreen(color), ColorMixer.getBlue(color)));
            changed = true;
        }
    }));
    rtaOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 + 6, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_green", "RTA").append(" : ").append(String.valueOf(ColorMixer.getGreen(drawer.getRTAColor()))), ColorMixer.getGreen(drawer.getRTAColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_green", "RTA").append(" : ").append(String.valueOf(ColorMixer.getGreen(drawer.getRTAColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getRTAColor();
            drawer.setRTAColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), ColorMixer.getRed(color), (int) (this.value * 255), ColorMixer.getBlue(color)));
            changed = true;
        }
    }));
    rtaOptions.add(addButton(new SliderWidget(width / 2 - 127, height / 2 + 28, 120, 20, new TranslatableText("speedrunigt.option.timer_position.color_blue", "RTA").append(" : ").append(String.valueOf(ColorMixer.getBlue(drawer.getRTAColor()))), ColorMixer.getBlue(drawer.getRTAColor()) / 255.0f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.color_blue", "RTA").append(" : ").append(String.valueOf(ColorMixer.getBlue(drawer.getRTAColor()))));
        }

        @Override
        protected void applyValue() {
            int color = drawer.getRTAColor();
            drawer.setRTAColor(ColorMixer.getArgb(ColorMixer.getAlpha(color), ColorMixer.getRed(color), ColorMixer.getGreen(color), (int) (this.value * 255)));
            changed = true;
        }
    }));
    rtaOptions.add(addButton(new SliderWidget(width / 2 + 6, height / 2 - 16, 120, 20, new TranslatableText("speedrunigt.option.timer_position.scale", "RTA").append(" : ").append(((int) (drawer.getRTAScale() * 100)) + "%"), drawer.getRTAScale() / 3f) {

        @Override
        protected void updateMessage() {
            this.setMessage(new TranslatableText("speedrunigt.option.timer_position.scale", "RTA").append(" : ").append(((int) (drawer.getRTAScale() * 100)) + "%"));
        }

        @Override
        protected void applyValue() {
            drawer.setRTAScale(Math.round((float) this.value * 3f * 20f) / 20f);
            changed = true;
        }
    }));
    rtaOptions.add(addButton(new ButtonWidget(width / 2 + 6, height / 2 + 6, 120, 20, new TranslatableText("speedrunigt.option.timer_position.text_decorate", "RTA").append(" : ").append(new TranslatableText("speedrunigt.option.timer_position.text_decorate." + drawer.getRTADecoration().name().toLowerCase(Locale.ROOT))), (ButtonWidget button) -> {
        int order = drawer.getRTADecoration().ordinal();
        drawer.setRTADecoration(TimerDecoration.values()[(++order) % TimerDecoration.values().length]);
        changed = true;
        button.setMessage(new TranslatableText("speedrunigt.option.timer_position.text_decorate", "RTA").append(" : ").append(new TranslatableText("speedrunigt.option.timer_position.text_decorate." + drawer.getRTADecoration().name().toLowerCase(Locale.ROOT))));
    })));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) SliderWidget(net.minecraft.client.gui.widget.SliderWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget)

Example 5 with ButtonWidget

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

the class ColorButton method init.

@Override
protected void init() {
    ModConfig config = BlockMeterClient.getConfigManager().getConfig();
    // Create Color Selector
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            final int colorIndex = i * 4 + j;
            this.addDrawableChild(new ColorButton(this.width / 2 - 44 + j * 22, this.height / 2 - 88 + i * 22, 20, 20, null, DyeColor.byId(colorIndex).getColorComponents(), config.colorIndex == colorIndex, false, button -> {
                ClientMeasureBox.setColorIndex(colorIndex);
                final ClientMeasureBox currentBox = BlockMeterClient.getInstance().getCurrentBox();
                if (currentBox != null)
                    currentBox.setColor(DyeColor.byId(colorIndex));
                MinecraftClient.getInstance().setScreen((Screen) null);
            }));
        }
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 10, BUTTONWIDTH, 20, new TranslatableText("blockmeter.keepColor", new Object[] { new TranslatableText(config.incrementColor ? "options.off" : "options.on") }), button -> {
        config.incrementColor = !config.incrementColor;
        MinecraftClient.getInstance().setScreen((Screen) null);
        // Todo find a way to increment to a new Color if a box was created while
        // incrementColor was disabled
        BlockMeterClient.getConfigManager().save();
    }));
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 32, BUTTONWIDTH, 20, new TranslatableText("blockmeter.diagonal", new Object[] { new TranslatableText(config.innerDiagonal ? "options.on" : "options.off") }), button -> {
        System.err.println("IDK WHAT YOU ARE DOING");
        config.innerDiagonal = !config.innerDiagonal;
        MinecraftClient.getInstance().setScreen((Screen) null);
        BlockMeterClient.getConfigManager().save();
    }));
    this.addDrawableChild(new ButtonWidget(this.width / 2 - BUTTONWIDTH / 2, this.height / 2 + 54, BUTTONWIDTH, 20, new TranslatableText("blockmeter.showOthers", new Object[] { new TranslatableText(config.showOtherUsersBoxes ? "options.on" : "options.off") }), button -> {
        System.err.println("IDK WHAT YOU ARE DOING");
        config.showOtherUsersBoxes = !config.showOtherUsersBoxes;
        MinecraftClient.getInstance().setScreen((Screen) null);
        BlockMeterClient.getConfigManager().save();
    }));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Tessellator(net.minecraft.client.render.Tessellator) Color(me.shedaniel.math.Color) BlockMeterClient(win.baruna.blockmeter.BlockMeterClient) GameRenderer(net.minecraft.client.render.GameRenderer) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ModConfig(win.baruna.blockmeter.ModConfig) NarratorManager(net.minecraft.client.util.NarratorManager) Screen(net.minecraft.client.gui.screen.Screen) DrawMode(net.minecraft.client.render.VertexFormat.DrawMode) DyeColor(net.minecraft.util.DyeColor) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) BufferBuilder(net.minecraft.client.render.BufferBuilder) MutableText(net.minecraft.text.MutableText) MinecraftClient(net.minecraft.client.MinecraftClient) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) TextRenderer(net.minecraft.client.font.TextRenderer) VertexFormats(net.minecraft.client.render.VertexFormats) TranslatableText(net.minecraft.text.TranslatableText) Screen(net.minecraft.client.gui.screen.Screen) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ModConfig(win.baruna.blockmeter.ModConfig)

Aggregations

ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)40 Screen (net.minecraft.client.gui.screen.Screen)27 LiteralText (net.minecraft.text.LiteralText)24 MatrixStack (net.minecraft.client.util.math.MatrixStack)22 TranslatableText (net.minecraft.text.TranslatableText)21 MinecraftClient (net.minecraft.client.MinecraftClient)15 Text (net.minecraft.text.Text)12 Inject (org.spongepowered.asm.mixin.injection.Inject)10 Mixin (org.spongepowered.asm.mixin.Mixin)9 At (org.spongepowered.asm.mixin.injection.At)9 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)9 ScreenTexts (net.minecraft.client.gui.screen.ScreenTexts)8 List (java.util.List)7 AbstractButtonWidget (net.minecraft.client.gui.widget.AbstractButtonWidget)7 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)7 GLFW (org.lwjgl.glfw.GLFW)7 Shadow (org.spongepowered.asm.mixin.Shadow)6 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)5 IOException (java.io.IOException)5 RenderUtils (dev.hypnotic.utils.render.RenderUtils)4