Search in sources :

Example 1 with AbstractButtonWidget

use of net.minecraft.client.gui.widget.AbstractButtonWidget 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 2 with AbstractButtonWidget

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

the class SpeedRunOptionScreen method getToolTip.

public ArrayList<Text> getToolTip(int mouseX, int mouseY) {
    ArrayList<Text> tooltipList = new ArrayList<>();
    Optional<Element> e = buttonListWidget.hoveredElement(mouseX, mouseY);
    if (e.isPresent()) {
        Element element = e.get();
        if (element instanceof ButtonScrollListWidget.Entry) {
            ButtonScrollListWidget.Entry entry = (ButtonScrollListWidget.Entry) element;
            AbstractButtonWidget buttonWidget = entry.getButtonWidget();
            if (tooltips.containsKey(buttonWidget)) {
                String text = tooltips.get(buttonWidget).get();
                for (String s : text.split("\n")) {
                    tooltipList.add(new LiteralText(s));
                }
                return tooltipList;
            }
        }
    }
    if (SpeedRunIGTInfoScreen.UPDATE_STATUS == SpeedRunIGTInfoScreen.UpdateStatus.OUTDATED) {
        tooltipList.add(new TranslatableText("speedrunigt.message.update_found"));
    }
    return tooltipList;
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) Element(net.minecraft.client.gui.Element) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Example 3 with AbstractButtonWidget

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

the class TimerCustomizeScreen method init.

@Override
protected void init() {
    normalOptions.clear();
    igtOptions.clear();
    rtaOptions.clear();
    fontOptions.clear();
    availableFonts.clear();
    fontSelectButtons.clear();
    backgroundOptions.clear();
    if (client != null) {
        FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
        if (!fontManager.getFontStorages().containsKey(drawer.getTimerFont())) {
            availableFonts.add(drawer.getTimerFont());
        }
        availableFonts.addAll(fontManager.getFontStorages().keySet());
    }
    initNormal();
    initIGTButtons();
    initRTAButtons();
    initFontButtons();
    initBackgroundButtons();
    this.normalButton = addButton(new ButtonWidget(width / 2 - 149, height / 2 - 48, 58, 20, new TranslatableText("options.title").append("..."), (ButtonWidget button) -> openTab(0)));
    this.igtButton = addButton(new ButtonWidget(width / 2 - 89, height / 2 - 48, 58, 20, new LiteralText("IGT..."), (ButtonWidget button) -> openTab(1)));
    this.rtaButton = addButton(new ButtonWidget(width / 2 - 29, height / 2 - 48, 58, 20, new LiteralText("RTA..."), (ButtonWidget button) -> openTab(2)));
    this.fontButton = addButton(new ButtonWidget(width / 2 + 31, height / 2 - 48, 58, 20, new TranslatableText("speedrunigt.title.font"), (ButtonWidget button) -> {
        openTab(3);
        openFontPage();
    }));
    this.backgroundButton = addButton(new ButtonWidget(width / 2 + 91, height / 2 - 48, 58, 20, new TranslatableText("speedrunigt.title.background"), (ButtonWidget button) -> openTab(4)));
    addButton(new ButtonWidget(width / 2 - 89, height / 2 + 62, 58, 20, new TranslatableText("speedrunigt.option.hide"), (ButtonWidget button) -> {
        hide = !hide;
        for (AbstractButtonWidget normalOption : normalOptions) {
            normalOption.visible = !hide && currentTab == 0;
        }
        for (AbstractButtonWidget igtOption : igtOptions) {
            igtOption.visible = !hide && currentTab == 1;
        }
        for (AbstractButtonWidget rtaOption : rtaOptions) {
            rtaOption.visible = !hide && currentTab == 2;
        }
        for (AbstractButtonWidget fontOption : fontOptions) {
            fontOption.visible = !hide && currentTab == 3;
        }
        for (AbstractButtonWidget backgroundOption : backgroundOptions) {
            backgroundOption.visible = !hide && currentTab == 4;
        }
        openTab(currentTab);
        button.setMessage(new TranslatableText("speedrunigt.option." + (!hide ? "hide" : "show")));
    }));
    this.saveButton = addButton(new ButtonWidget(width / 2 - 29, height / 2 + 62, 58, 20, new TranslatableText("selectWorld.edit.save"), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_POSITION_X, drawer.getIGT_XPos());
        SpeedRunIGT.TIMER_DRAWER.setIGT_XPos(drawer.getIGT_XPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_POSITION_Y, drawer.getIGT_YPos());
        SpeedRunIGT.TIMER_DRAWER.setIGT_YPos(drawer.getIGT_YPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_SCALE, drawer.getIGTScale());
        SpeedRunIGT.TIMER_DRAWER.setIGTScale(drawer.getIGTScale());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_COLOR, drawer.getIGTColor());
        SpeedRunIGT.TIMER_DRAWER.setIGTColor(drawer.getIGTColor());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_DECO, drawer.getIGTDecoration());
        SpeedRunIGT.TIMER_DRAWER.setIGTDecoration(drawer.getIGTDecoration());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_POSITION_X, drawer.getRTA_XPos());
        SpeedRunIGT.TIMER_DRAWER.setRTA_XPos(drawer.getRTA_XPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_POSITION_Y, drawer.getRTA_YPos());
        SpeedRunIGT.TIMER_DRAWER.setRTA_YPos(drawer.getRTA_YPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_SCALE, drawer.getRTAScale());
        SpeedRunIGT.TIMER_DRAWER.setRTAScale(drawer.getRTAScale());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_COLOR, drawer.getRTAColor());
        SpeedRunIGT.TIMER_DRAWER.setRTAColor(drawer.getRTAColor());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_DECO, drawer.getRTADecoration());
        SpeedRunIGT.TIMER_DRAWER.setRTADecoration(drawer.getRTADecoration());
        SpeedRunOption.setOption(SpeedRunOptions.DISPLAY_TIME_ONLY, drawer.isSimplyTimer());
        SpeedRunIGT.TIMER_DRAWER.setSimplyTimer(drawer.isSimplyTimer());
        SpeedRunOption.setOption(SpeedRunOptions.LOCK_TIMER_POSITION, drawer.isLocked());
        SpeedRunIGT.TIMER_DRAWER.setLocked(drawer.isLocked());
        SpeedRunOption.setOption(SpeedRunOptions.DISPLAY_DECIMALS, drawer.getTimerDecimals());
        SpeedRunIGT.TIMER_DRAWER.setTimerDecimals(drawer.getTimerDecimals());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_TEXT_FONT, drawer.getTimerFont());
        SpeedRunIGT.TIMER_DRAWER.setTimerFont(drawer.getTimerFont());
        SpeedRunOption.setOption(SpeedRunOptions.BACKGROUND_OPACITY, drawer.getBGOpacity());
        SpeedRunIGT.TIMER_DRAWER.setBGOpacity(drawer.getBGOpacity());
        SpeedRunOption.setOption(SpeedRunOptions.RTA_BACKGROUND_PADDING, drawer.getRTAPadding());
        SpeedRunIGT.TIMER_DRAWER.setRTAPadding(drawer.getRTAPadding());
        SpeedRunOption.setOption(SpeedRunOptions.IGT_BACKGROUND_PADDING, drawer.getIGTPadding());
        SpeedRunIGT.TIMER_DRAWER.setIGTPadding(drawer.getIGTPadding());
        changed = false;
    }));
    addButton(new ButtonWidget(width / 2 + 31, height / 2 + 62, 58, 20, ScreenTexts.CANCEL, (ButtonWidget button) -> {
        if (client != null)
            client.openScreen(parent);
    }));
    fontConfigButton.visible = false;
    openTab(0);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Example 4 with AbstractButtonWidget

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

the class TimerCustomizeScreen method openTab.

private void openTab(int tab) {
    currentTab = tab;
    this.normalButton.active = tab != 0;
    this.igtButton.active = tab != 1;
    this.rtaButton.active = tab != 2;
    this.fontButton.active = tab != 3;
    this.backgroundButton.active = tab != 4;
    if (hide)
        return;
    for (AbstractButtonWidget normalOption : normalOptions) {
        normalOption.visible = tab == 0;
    }
    for (AbstractButtonWidget igtOption : igtOptions) {
        igtOption.visible = tab == 1;
    }
    for (AbstractButtonWidget rtaOption : rtaOptions) {
        rtaOption.visible = tab == 2;
    }
    for (AbstractButtonWidget fontOption : fontOptions) {
        fontOption.visible = tab == 3;
    }
    for (AbstractButtonWidget backgroundOption : backgroundOptions) {
        backgroundOption.visible = tab == 4;
    }
    fontConfigButton.visible = tab == 3 && Objects.equals(drawer.getTimerFont().getNamespace(), SpeedRunIGT.MOD_ID);
}
Also used : AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget)

Example 5 with AbstractButtonWidget

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

the class TimerCustomizeScreen method initFontButtons.

public void initFontButtons() {
    ButtonWidget prevButton = addButton(new ButtonWidget(width / 2 - 180, height / 2 + 6, 20, 20, new LiteralText("<"), (ButtonWidget button) -> {
        fontPage--;
        openFontPage();
    }));
    ButtonWidget nextButton = addButton(new ButtonWidget(width / 2 + 180, height / 2 + 6, 20, 20, new LiteralText(">"), (ButtonWidget button) -> {
        fontPage++;
        openFontPage();
    }));
    fontOptions.add(prevButton);
    fontOptions.add(nextButton);
    fontSelectButtons.add(addButton(new ButtonWidget(width / 2 + 35, height / 2 - 16, 50, 20, new TranslatableText("speedrunigt.option.select"), (ButtonWidget button) -> {
        int c = (fontPage * 3);
        if (availableFonts.size() > c) {
            for (ButtonWidget fontSelectButton : fontSelectButtons) fontSelectButton.active = true;
            drawer.setTimerFont(availableFonts.get(c));
            button.active = false;
            openFontPage();
            changed = true;
        }
    })));
    fontSelectButtons.add(addButton(new ButtonWidget(width / 2 + 35, height / 2 + 6, 50, 20, new TranslatableText("speedrunigt.option.select"), (ButtonWidget button) -> {
        int c = (fontPage * 3) + 1;
        if (availableFonts.size() > c) {
            for (ButtonWidget fontSelectButton : fontSelectButtons) fontSelectButton.active = true;
            drawer.setTimerFont(availableFonts.get(c));
            button.active = false;
            openFontPage();
            changed = true;
        }
    })));
    fontSelectButtons.add(addButton(new ButtonWidget(width / 2 + 35, height / 2 + 28, 50, 20, new TranslatableText("speedrunigt.option.select"), (ButtonWidget button) -> {
        int c = (fontPage * 3) + 2;
        if (availableFonts.size() > c) {
            for (ButtonWidget fontSelectButton : fontSelectButtons) fontSelectButton.active = true;
            drawer.setTimerFont(availableFonts.get(c));
            button.active = false;
            openFontPage();
            changed = true;
        }
    })));
    for (AbstractButtonWidget fontOption : fontOptions) {
        fontOption.visible = false;
    }
    for (ButtonWidget fontSelectButton : fontSelectButtons) {
        fontSelectButton.visible = false;
    }
    fontOptions.addAll(fontSelectButtons);
    fontConfigButton = addButton(new ButtonWidget(width / 2 + 88, 0, 50, 20, new LiteralText("Config"), (ButtonWidget button) -> {
        if (client != null)
            client.openScreen(new FontConfigScreen(this, drawer.getTimerFont()));
    }));
    fontOptions.add(addButton(new ButtonWidget(width / 2 - 154, height / 2 - 80, 150, 20, new TranslatableText("speedrunigt.option.timer_position.font.open_folder"), (ButtonWidget button) -> Util.getOperatingSystem().open(SpeedRunIGT.FONT_PATH.toFile()))));
    fontOptions.add(addButton(new ButtonWidget(width / 2 + 4, height / 2 - 80, 150, 20, new TranslatableText("speedrunigt.option.timer_position.font.description"), (ButtonWidget button) -> Util.getOperatingSystem().open("https://youtu.be/agBbiTQWj78"))));
    openFontPage();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Aggregations

AbstractButtonWidget (net.minecraft.client.gui.widget.AbstractButtonWidget)5 TranslatableText (net.minecraft.text.TranslatableText)4 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)3 LiteralText (net.minecraft.text.LiteralText)3 OptionButtonFactory (com.redlimerl.speedrunigt.api.OptionButtonFactory)1 FontManagerAccessor (com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor)1 Element (net.minecraft.client.gui.Element)1 Text (net.minecraft.text.Text)1