From c28b4b301c6785eefff7c7f8a51ebb37bd5270ea Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 23:14:33 +0800 Subject: Add supporting me links --- .../rei/impl/client/config/ConfigManagerImpl.java | 32 ++++++-- .../impl/client/config/entries/TitleTextEntry.java | 87 ++++++++++++++++++++++ 2 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 485b90271..078f46344 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -352,10 +352,6 @@ public class ConfigManagerImpl implements ConfigManager { builder.setGlobalized(true); builder.setGlobalizedExpanded(false); if (Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null) { - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); - } - return builder.setAfterInitConsumer(screen -> { TextListEntry feedbackEntry = ConfigEntryBuilder.create().startTextDescription( new TranslatableComponent("text.rei.feedback", new TranslatableComponent("text.rei.feedback.link") .withStyle(style -> style @@ -366,8 +362,32 @@ public class ConfigManagerImpl implements ConfigManager { )) .withStyle(ChatFormatting.GRAY) ).build(); - feedbackEntry.setScreen((AbstractConfigScreen) screen); - ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) feedbackEntry); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, feedbackEntry); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); + } + return builder.setAfterInitConsumer(screen -> { + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new EmptyEntry(4)); + TextListEntry supportText = ConfigEntryBuilder.create().startTextDescription( + new TranslatableComponent("text.rei.support.me.desc", + new TranslatableComponent("text.rei.support.me.patreon") + .withStyle(style -> style + .withColor(TextColor.fromRgb(0xff1fc3ff)) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://patreon.com/shedaniel")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://patreon.com/shedaniel"))) + ), + new TranslatableComponent("text.rei.support.me.bisect") + .withStyle(style -> style + .withColor(TextColor.fromRgb(0xff1fc3ff)) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.bisecthosting.com/shedaniel")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://www.bisecthosting.com/shedaniel"))) + ) + ) + .withStyle(ChatFormatting.GRAY) + ).build(); + supportText.setScreen((AbstractConfigScreen) screen); + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) supportText); + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new TitleTextEntry(new TranslatableComponent("text.rei.support.me"))); ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new EmptyEntry(4)); ScreenHooks.addRenderableWidget(screen, new Button(screen.width - 104, 4, 100, 20, new TranslatableComponent("text.rei.credits"), button -> { CreditsScreen creditsScreen = new CreditsScreen(screen); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java new file mode 100644 index 000000000..3e2bdc48a --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java @@ -0,0 +1,87 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.config.entries; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Unit; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +@ApiStatus.Internal +public class TitleTextEntry extends AbstractConfigListEntry { + private Component text; + + public TitleTextEntry(Component text) { + super(NarratorChatListener.NO_TITLE, false); + this.text = text; + } + + @Override + public Unit getValue() { + return Unit.INSTANCE; + } + + @Override + public Optional getDefaultValue() { + return Optional.of(Unit.INSTANCE); + } + + @Override + public void save() { + } + + @Override + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); + matrices.pushPose(); + matrices.translate(x + entryWidth / 2F - Minecraft.getInstance().font.width(text) * 1.5F / 2F, y + 5, 1.0F); + matrices.scale(1.5F, 1.5F, 1.0F); + Minecraft.getInstance().font.drawShadow(matrices, text, 0.0F, 0.0F, -1); + matrices.popPose(); + } + + @Override + public int getItemHeight() { + return 26; + } + + @Override + public List children() { + return Collections.emptyList(); + } + + @Override + public List narratables() { + return Collections.emptyList(); + } +} -- cgit