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);
}
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;
}
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();
}
Aggregations