diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-08-27 13:23:37 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-08-27 13:23:37 +0900 |
| commit | 03b0adcf960c5e462fddc8e045b146a8c727670c (patch) | |
| tree | dcd998806437b6fea4e6ce0d34f5ddf97404d674 /api/src/main/java | |
| parent | 1ba613d9c97e722e76f459162de2e1a1c9e875bb (diff) | |
| download | RoughlyEnoughItems-03b0adcf960c5e462fddc8e045b146a8c727670c.tar.gz RoughlyEnoughItems-03b0adcf960c5e462fddc8e045b146a8c727670c.tar.bz2 RoughlyEnoughItems-03b0adcf960c5e462fddc8e045b146a8c727670c.zip | |
Refactors to overlays and reiruntime
Diffstat (limited to 'api/src/main/java')
6 files changed, 58 insertions, 9 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java index 540dcc2ab..41e0870d3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java @@ -24,10 +24,12 @@ package me.shedaniel.rei.api.client; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipQueue; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -60,12 +62,17 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { * * @return whether the overlay is visible */ - boolean isOverlayVisible(); + default boolean isOverlayVisible() { + return ConfigObject.getInstance().isOverlayVisible(); + } /** * Toggles the visibility of the overlay. */ - void toggleOverlayVisible(); + default void toggleOverlayVisible() { + ConfigObject.getInstance().setOverlayVisible(!ConfigObject.getInstance().isOverlayVisible()); + ConfigManager.getInstance().saveConfig(); + } /** * Returns the screen overlay of REI, if available and constructed. @@ -126,7 +133,9 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { * @return whether dark mode is enabled * @see ConfigObject#isUsingDarkTheme() */ - boolean isDarkThemeEnabled(); + default boolean isDarkThemeEnabled() { + return ConfigObject.getInstance().isUsingDarkTheme(); + } /** * Returns the text field used for searching, if constructed. @@ -144,7 +153,11 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { * @param tooltip the tooltip to display, or {@code null} * @see Tooltip#queue() */ - void queueTooltip(@Nullable Tooltip tooltip); + default void queueTooltip(@Nullable Tooltip tooltip) { + if (getOverlay(false, false).isEmpty()) { + TooltipQueue.getInstance().queue(tooltip); + } + } /** * Clear all queued tooltips. @@ -153,7 +166,11 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { * @since 8.3 */ @ApiStatus.Experimental - void clearTooltips(); + default void clearTooltips() { + if (getOverlay(false, false).isEmpty()) { + TooltipQueue.getInstance().clear(); + } + } /** * Returns the texture location of the default display background. @@ -162,7 +179,9 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { * * @return the texture location of the default display background */ - ResourceLocation getDefaultDisplayTexture(); + default ResourceLocation getDefaultDisplayTexture() { + return getDefaultDisplayTexture(isDarkThemeEnabled()); + } /** * Returns the texture location of the default display background. diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java index 856e696de..b423dd5ae 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.config.ConfigObject; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.TextComponent; @@ -331,7 +332,7 @@ public abstract class Label extends WidgetWithBounds { public abstract void setColor(int color); public Label color(int lightModeColor, int darkModeColor) { - return color(REIRuntime.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor); + return color(ConfigObject.getInstance().isUsingDarkTheme() ? darkModeColor : lightModeColor); } public final Label color(int color) { @@ -344,7 +345,7 @@ public abstract class Label extends WidgetWithBounds { public abstract void setHoveredColor(int hoveredColor); public final Label hoveredColor(int lightModeColor, int darkModeColor) { - return hoveredColor(REIRuntime.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor); + return hoveredColor(ConfigObject.getInstance().isUsingDarkTheme() ? darkModeColor : lightModeColor); } public final Label hoveredColor(int color) { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Panel.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Panel.java index f1adf8b06..875931202 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Panel.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Panel.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.config.ConfigObject; import java.util.function.Predicate; @@ -56,7 +57,7 @@ public abstract class Panel extends WidgetWithBounds { } public final Panel color(int lightColor, int darkColor) { - return color(REIRuntime.getInstance().isDarkThemeEnabled() ? darkColor : lightColor); + return color(ConfigObject.getInstance().isUsingDarkTheme() ? darkColor : lightColor); } public abstract Predicate<Panel> getRendering(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index 848e853de..e2d3511f1 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -174,6 +174,9 @@ public interface Tooltip { Tooltip withContextStack(EntryStack<?> stack); + /** + * Queues this tooltip to be displayed. + */ default void queue() { EnvExecutor.runInEnv(Env.CLIENT, () -> () -> REIRuntime.getInstance().queueTooltip(this)); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java new file mode 100644 index 000000000..c938cd8d6 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java @@ -0,0 +1,19 @@ +package me.shedaniel.rei.api.client.gui.widgets; + +import me.shedaniel.rei.impl.client.ClientInternals; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +@ApiStatus.Experimental +public interface TooltipQueue { + static TooltipQueue getInstance() { + return ClientInternals.getTooltipQueue(); + } + + void queue(@Nullable Tooltip tooltip); + + void clear(); + + @Nullable + Tooltip get(); +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java index 706ea27ad..0791ec310 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java @@ -29,6 +29,7 @@ import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.client.gui.widgets.TooltipQueue; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.entry.PreFilteredEntryList; import me.shedaniel.rei.api.client.registry.screen.ClickArea; @@ -64,6 +65,7 @@ public final class ClientInternals { private static final FavoritesEntriesListProvider FAVORITES_ENTRIES_LIST = resolveService(FavoritesEntriesListProvider.class); private static final List<OverlayTicker> OVERLAY_TICKERS = resolveServices(OverlayTicker.class); private static final AutoCraftingEvaluator AUTO_CRAFTING_EVALUATOR = resolveService(AutoCraftingEvaluator.class); + private static final TooltipQueue TOOLTIP_QUEUE = resolveService(TooltipQueue.class); private static Function<CompoundTag, DataResult<FavoriteEntry>> favoriteEntryFromJson = (object) -> throwNotSetup(); private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); private static BiConsumer<List<ClientTooltipComponent>, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); @@ -165,6 +167,10 @@ public final class ClientInternals { return AUTO_CRAFTING_EVALUATOR.builder(display); } + public static TooltipQueue getTooltipQueue() { + return TOOLTIP_QUEUE; + } + public static DataResult<FavoriteEntry> favoriteEntryFromJson(CompoundTag tag) { return favoriteEntryFromJson.apply(tag); } |
