Search in sources :

Example 1 with OptionButtonFactory

use of com.redlimerl.speedrunigt.api.OptionButtonFactory 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 OptionButtonFactory

use of com.redlimerl.speedrunigt.api.OptionButtonFactory in project SpeedRunIGT by RedLime.

the class OptionButtonsImpl method createOptionButtons.

@Override
public Collection<OptionButtonFactory> createOptionButtons() {
    ArrayList<OptionButtonFactory> factories = new ArrayList<>();
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.timer_position"), (ButtonWidget button) -> MinecraftClient.getInstance().openScreen(new TimerCustomizeScreen(screen)))).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.timer_category"), (ButtonWidget button) -> MinecraftClient.getInstance().openScreen(new SpeedRunCategoryScreen(screen)))).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.check_info"), (ButtonWidget button) -> MinecraftClient.getInstance().openScreen(new SpeedRunIGTInfoScreen(screen)))).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.reload"), (ButtonWidget button) -> MinecraftClient.getInstance().openScreen(new ConfirmScreen(boolean1 -> {
        if (boolean1) {
            SpeedRunOption.reload();
        }
        MinecraftClient.getInstance().openScreen(screen);
    }, new TranslatableText("speedrunigt.message.reload_options"), LiteralText.EMPTY)))).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.global_options").append(" : ").append(SpeedRunOption.isUsingGlobalConfig() ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setUseGlobalConfig(!SpeedRunOption.isUsingGlobalConfig());
        MinecraftClient.getInstance().openScreen(new ConfirmScreen(boolean1 -> {
            if (boolean1) {
                SpeedRunOption.reload();
            }
            MinecraftClient.getInstance().openScreen(screen);
        }, new TranslatableText("speedrunigt.message.reload_options"), LiteralText.EMPTY));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.global_options.description", SpeedRunOption.getConfigPath())).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.timer_position.toggle_timer").append(" : ").append(TIMER_DRAWER.isToggle() ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        TIMER_DRAWER.setToggle(!TIMER_DRAWER.isToggle());
        SpeedRunOption.setOption(SpeedRunOptions.TOGGLE_TIMER, TIMER_DRAWER.isToggle());
        button.setMessage(new TranslatableText("speedrunigt.option.timer_position.toggle_timer").append(" : ").append(TIMER_DRAWER.isToggle() ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.hide_timer_in_options").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_OPTIONS) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.HIDE_TIMER_IN_OPTIONS, !SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_OPTIONS));
        button.setMessage(new TranslatableText("speedrunigt.option.hide_timer_in_options").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_OPTIONS) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.hide_timer_in_debugs").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_DEBUGS) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.HIDE_TIMER_IN_DEBUGS, !SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_DEBUGS));
        button.setMessage(new TranslatableText("speedrunigt.option.hide_timer_in_debugs").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.HIDE_TIMER_IN_DEBUGS) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.waiting_first_input").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.WAITING_FIRST_INPUT) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.WAITING_FIRST_INPUT, !SpeedRunOption.getOption(SpeedRunOptions.WAITING_FIRST_INPUT));
        button.setMessage(new TranslatableText("speedrunigt.option.waiting_first_input").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.WAITING_FIRST_INPUT) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.waiting_first_input.description")).setCategory("speedrunigt.option.category.timing"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.auto_toggle_coop").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.AUTOMATIC_COOP_MODE) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.AUTOMATIC_COOP_MODE, !SpeedRunOption.getOption(SpeedRunOptions.AUTOMATIC_COOP_MODE));
        button.setMessage(new TranslatableText("speedrunigt.option.auto_toggle_coop").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.AUTOMATIC_COOP_MODE) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.auto_toggle_coop.description")).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.start_old_worlds").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_START_GENERATED_WORLD) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_START_GENERATED_WORLD, !SpeedRunOption.getOption(SpeedRunOptions.TIMER_START_GENERATED_WORLD));
        button.setMessage(new TranslatableText("speedrunigt.option.start_old_worlds").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_START_GENERATED_WORLD) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.start_old_worlds.description")).setCategory("speedrunigt.option.category.timing"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.limitless_reset").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_LIMITLESS_RESET) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_LIMITLESS_RESET, !SpeedRunOption.getOption(SpeedRunOptions.TIMER_LIMITLESS_RESET));
        button.setMessage(new TranslatableText("speedrunigt.option.limitless_reset").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_LIMITLESS_RESET) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.limitless_reset.description")).setCategory("speedrunigt.option.category.timing"));
    if (Math.random() < 0.1) {
        factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new LiteralText("amongus"), (ButtonWidget button) -> {
        })).setCategory("sus"));
    }
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.current_extensions"), (ButtonWidget button) -> {
    })).setToolTip(() -> {
        StringBuilder extension = new StringBuilder(I18n.translate("speedrunigt.option.current_extensions.description", SpeedRunIGTApi.getProviders().length));
        extension.append("\n");
        int auto = 0;
        for (ModContainer provider : SpeedRunIGTApi.getProviders()) {
            if (auto++ > 4) {
                auto = 0;
                extension.append("\n");
            }
            extension.append(String.format("%s v%s,", provider.getMetadata().getName(), provider.getMetadata().getVersion()));
        }
        return extension.substring(0, extension.length() - 1);
    }).setCategory("speedrunigt.option.category.general"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.legacy_igt_mode").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_LEGACY_IGT_MODE) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_LEGACY_IGT_MODE, !SpeedRunOption.getOption(SpeedRunOptions.TIMER_LEGACY_IGT_MODE));
        button.setMessage(new TranslatableText("speedrunigt.option.legacy_igt_mode").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.TIMER_LEGACY_IGT_MODE) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.legacy_igt_mode.description")).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.auto_save_interval").append(" : ").append(new TranslatableText("speedrunigt.option.auto_save_interval." + SpeedRunOption.getOption(SpeedRunOptions.TIMER_DATA_AUTO_SAVE).name().toLowerCase(Locale.ROOT))), (ButtonWidget button) -> {
        int order = SpeedRunOption.getOption(SpeedRunOptions.TIMER_DATA_AUTO_SAVE).ordinal() + 1;
        SpeedRunOptions.TimerSaveInterval[] intervals = SpeedRunOptions.TimerSaveInterval.values();
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_DATA_AUTO_SAVE, intervals[order % intervals.length]);
        button.setMessage(new TranslatableText("speedrunigt.option.auto_save_interval").append(" : ").append(new TranslatableText("speedrunigt.option.auto_save_interval." + SpeedRunOption.getOption(SpeedRunOptions.TIMER_DATA_AUTO_SAVE).name().toLowerCase(Locale.ROOT))));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.auto_save_interval.description")).setCategory("speedrunigt.option.category.timer"));
    factories.add(screen -> new OptionButtonFactory.Builder().setButtonWidget(new ButtonWidget(0, 0, 150, 20, new TranslatableText("speedrunigt.option.auto_retime").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.AUTO_RETIME_FOR_GUIDELINE) ? ScreenTexts.ON : ScreenTexts.OFF), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.AUTO_RETIME_FOR_GUIDELINE, !SpeedRunOption.getOption(SpeedRunOptions.AUTO_RETIME_FOR_GUIDELINE));
        button.setMessage(new TranslatableText("speedrunigt.option.auto_retime").append(" : ").append(SpeedRunOption.getOption(SpeedRunOptions.AUTO_RETIME_FOR_GUIDELINE) ? ScreenTexts.ON : ScreenTexts.OFF));
    })).setToolTip(() -> I18n.translate("speedrunigt.option.auto_retime.description")).setCategory("speedrunigt.option.category.timer"));
    return factories;
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) SpeedRunOption(com.redlimerl.speedrunigt.option.SpeedRunOption) SpeedRunOptions(com.redlimerl.speedrunigt.option.SpeedRunOptions) LiteralText(net.minecraft.text.LiteralText) ScreenTexts(net.minecraft.client.gui.screen.ScreenTexts) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) I18n(net.minecraft.client.resource.language.I18n) SpeedRunCategoryScreen(com.redlimerl.speedrunigt.gui.screen.SpeedRunCategoryScreen) Collection(java.util.Collection) TranslatableText(net.minecraft.text.TranslatableText) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) OptionButtonFactory(com.redlimerl.speedrunigt.api.OptionButtonFactory) ArrayList(java.util.ArrayList) TimerCustomizeScreen(com.redlimerl.speedrunigt.gui.screen.TimerCustomizeScreen) SpeedRunIGTInfoScreen(com.redlimerl.speedrunigt.gui.screen.SpeedRunIGTInfoScreen) Locale(java.util.Locale) SpeedRunIGTApi(com.redlimerl.speedrunigt.api.SpeedRunIGTApi) MinecraftClient(net.minecraft.client.MinecraftClient) TIMER_DRAWER(com.redlimerl.speedrunigt.SpeedRunIGT.TIMER_DRAWER) ModContainer(net.fabricmc.loader.api.ModContainer) SpeedRunIGTInfoScreen(com.redlimerl.speedrunigt.gui.screen.SpeedRunIGTInfoScreen) ModContainer(net.fabricmc.loader.api.ModContainer) ArrayList(java.util.ArrayList) TimerCustomizeScreen(com.redlimerl.speedrunigt.gui.screen.TimerCustomizeScreen) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ConfirmScreen(net.minecraft.client.gui.screen.ConfirmScreen) OptionButtonFactory(com.redlimerl.speedrunigt.api.OptionButtonFactory) SpeedRunCategoryScreen(com.redlimerl.speedrunigt.gui.screen.SpeedRunCategoryScreen) LiteralText(net.minecraft.text.LiteralText)

Example 3 with OptionButtonFactory

use of com.redlimerl.speedrunigt.api.OptionButtonFactory in project SpeedRunIGT by RedLime.

the class SpeedRunIGT method onInitializeClient.

@Override
public void onInitializeClient() {
    MOD_VERSION = (FabricLoader.getInstance().getModContainer(SpeedRunIGT.MOD_ID).isPresent() ? FabricLoader.getInstance().getModContainer(SpeedRunIGT.MOD_ID).get().getMetadata().getVersion().getFriendlyString() : "Unknown+Unknown");
    // init default option buttons
    SpeedRunOption.addOptionButtonFactories(new OptionButtonsImpl().createOptionButtons().toArray(new OptionButtonFactory[0]));
    // init default categories
    new CategoryRegistryImpl().registerCategories().forEach(RunCategory::registerCategory);
    // Registry API's
    for (EntrypointContainer<SpeedRunIGTApi> entryPoint : FabricLoader.getInstance().getEntrypointContainers("speedrunigt", SpeedRunIGTApi.class)) {
        SpeedRunIGTApi api = entryPoint.getEntrypoint();
        // Registry single option button
        OptionButtonFactory singleFactory = api.createOptionButton();
        if (singleFactory != null)
            SpeedRunOption.addOptionButtonFactories(singleFactory);
        // Registry multiple option buttons
        Collection<OptionButtonFactory> multipleFactory = api.createOptionButtons();
        if (multipleFactory != null)
            SpeedRunOption.addOptionButtonFactories(multipleFactory.toArray(new OptionButtonFactory[0]));
        // Registry single category
        RunCategory singleCategory = api.registerCategory();
        if (singleCategory != null)
            RunCategory.registerCategory(singleCategory);
        // Registry multiple categories
        Collection<RunCategory> multipleCategories = api.registerCategories();
        if (multipleCategories != null)
            multipleCategories.forEach(RunCategory::registerCategory);
        API_PROVIDERS.add(entryPoint.getProvider());
    }
    // Options initialize
    SpeedRunOption.init();
    // Translate initialize
    try {
        TranslateHelper.init();
    } catch (Throwable e) {
        e.printStackTrace();
    }
    // Key Bindings initialize
    timerResetKeyBinding = KeyBindingRegistry.registerKeyBinding(new KeyBinding("speedrunigt.controls.start_timer", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_U, "speedrunigt.title.options"));
    timerStopKeyBinding = KeyBindingRegistry.registerKeyBinding(new KeyBinding("speedrunigt.controls.stop_timer", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_I, "speedrunigt.title.options"));
    // End initializing
    isInitialized = true;
    // Update checking
    SpeedRunIGTInfoScreen.checkUpdate();
    // Add default fonts
    FontUtils.copyDefaultFonts();
}
Also used : KeyBinding(net.minecraft.client.options.KeyBinding) OptionButtonFactory(com.redlimerl.speedrunigt.api.OptionButtonFactory) CategoryRegistryImpl(com.redlimerl.speedrunigt.impl.CategoryRegistryImpl) SpeedRunIGTApi(com.redlimerl.speedrunigt.api.SpeedRunIGTApi) OptionButtonsImpl(com.redlimerl.speedrunigt.impl.OptionButtonsImpl) RunCategory(com.redlimerl.speedrunigt.timer.running.RunCategory)

Aggregations

OptionButtonFactory (com.redlimerl.speedrunigt.api.OptionButtonFactory)3 SpeedRunIGTApi (com.redlimerl.speedrunigt.api.SpeedRunIGTApi)2 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)2 TranslatableText (net.minecraft.text.TranslatableText)2 TIMER_DRAWER (com.redlimerl.speedrunigt.SpeedRunIGT.TIMER_DRAWER)1 SpeedRunCategoryScreen (com.redlimerl.speedrunigt.gui.screen.SpeedRunCategoryScreen)1 SpeedRunIGTInfoScreen (com.redlimerl.speedrunigt.gui.screen.SpeedRunIGTInfoScreen)1 TimerCustomizeScreen (com.redlimerl.speedrunigt.gui.screen.TimerCustomizeScreen)1 CategoryRegistryImpl (com.redlimerl.speedrunigt.impl.CategoryRegistryImpl)1 OptionButtonsImpl (com.redlimerl.speedrunigt.impl.OptionButtonsImpl)1 SpeedRunOption (com.redlimerl.speedrunigt.option.SpeedRunOption)1 SpeedRunOptions (com.redlimerl.speedrunigt.option.SpeedRunOptions)1 RunCategory (com.redlimerl.speedrunigt.timer.running.RunCategory)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Locale (java.util.Locale)1 ModContainer (net.fabricmc.loader.api.ModContainer)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ConfirmScreen (net.minecraft.client.gui.screen.ConfirmScreen)1 ScreenTexts (net.minecraft.client.gui.screen.ScreenTexts)1