From 7884c33ceccfbaa1a0eabd20fda316a9bd4e8854 Mon Sep 17 00:00:00 2001 From: thimblebird Date: Thu, 12 Sep 2024 01:26:45 +0200 Subject: [PATCH] Closes https://github.com/squeek502/AppleSkin/issues/258 Adds ability to show/hide hunger/saturation in tooltips Fixes "showFoodValuesInTooltip" not overwriting "showFoodValuesInTooltipAlways" --- java/squeek/appleskin/ModConfig.java | 8 + .../client/TooltipOverlayHandler.java | 174 +++++++++++------- resources/assets/appleskin/lang/en_us.json | 4 + 3 files changed, 119 insertions(+), 67 deletions(-) diff --git a/java/squeek/appleskin/ModConfig.java b/java/squeek/appleskin/ModConfig.java index b68882a..17c42c3 100644 --- a/java/squeek/appleskin/ModConfig.java +++ b/java/squeek/appleskin/ModConfig.java @@ -25,6 +25,14 @@ public static void init() @Comment("If true, shows the hunger and saturation values of food in its tooltip while holding SHIFT") public boolean showFoodValuesInTooltip = true; + @ConfigEntry.Gui.Tooltip() + @Comment("If true, shows the hunger value of food in its tooltip") + public boolean showHungerValueInTooltip = true; + + @ConfigEntry.Gui.Tooltip() + @Comment("If true, shows the saturation value of food in its tooltip") + public boolean showSaturationValueInTooltip = true; + @ConfigEntry.Gui.Tooltip() @Comment("If true, shows the hunger and saturation values of food in its tooltip automatically (without needing to hold SHIFT)") public boolean showFoodValuesInTooltipAlways = true; diff --git a/java/squeek/appleskin/client/TooltipOverlayHandler.java b/java/squeek/appleskin/client/TooltipOverlayHandler.java index 0738e7f..82f1549 100644 --- a/java/squeek/appleskin/client/TooltipOverlayHandler.java +++ b/java/squeek/appleskin/client/TooltipOverlayHandler.java @@ -122,23 +122,51 @@ boolean shouldRenderHungerBars() @Override public int getHeight() { - // hunger + spacing + saturation + arbitrary spacing, + int height = 0; + // hunger + if (ModConfig.INSTANCE.showHungerValueInTooltip) + { + height += 9; + } + // spacing + if (ModConfig.INSTANCE.showHungerValueInTooltip && ModConfig.INSTANCE.showSaturationValueInTooltip) + { + height += 1; + } + // saturation + if (ModConfig.INSTANCE.showSaturationValueInTooltip) + { + height += 7; + } + // arbitrary spacing, // for some reason 3 extra looks best - return 9 + 1 + 7 + 3; + if (ModConfig.INSTANCE.showHungerValueInTooltip || ModConfig.INSTANCE.showSaturationValueInTooltip) + { + height += 3; + } + return height; } @Override public int getWidth(TextRenderer textRenderer) { - int hungerBarLength = hungerBars * 9; - if (hungerBarsText != null) + int hungerBarLength = 0; + if (ModConfig.INSTANCE.showHungerValueInTooltip) { - hungerBarLength += textRenderer.getWidth(hungerBarsText); + hungerBarLength = hungerBars * 9; + if (hungerBarsText != null) + { + hungerBarLength += textRenderer.getWidth(hungerBarsText); + } } - int saturationBarLength = saturationBars * 7; - if (saturationBarsText != null) + int saturationBarLength = 0; + if (ModConfig.INSTANCE.showSaturationValueInTooltip) { - saturationBarLength += textRenderer.getWidth(saturationBarsText); + saturationBarLength = saturationBars * 7; + if (saturationBarsText != null) + { + saturationBarLength += textRenderer.getWidth(saturationBarsText); + } } return Math.max(hungerBarLength, saturationBarLength); } @@ -271,79 +299,86 @@ public void onRenderTooltip(DrawContext context, FoodOverlay foodOverlay, int to RenderSystem.defaultBlendFunc(); // Render from right to left so that the icons 'face' the right way - x += (foodOverlay.hungerBars - 1) * 9; - - boolean isRotten = FoodHelper.isRotten(modifiedFood); - - for (int i = 0; i < foodOverlay.hungerBars * 2; i += 2) + if (ModConfig.INSTANCE.showHungerValueInTooltip) { - context.drawGuiTexture(TextureHelper.FOOD_EMPTY_TEXTURE, x, y, 9, 9); + x += (foodOverlay.hungerBars - 1) * 9; - FoodOutline outline = FoodOutline.get(modifiedFoodHunger, defaultFoodHunger, i); - if (outline != FoodOutline.NORMAL) + boolean isRotten = FoodHelper.isRotten(modifiedFood); + + for (int i = 0; i < foodOverlay.hungerBars * 2; i += 2) { - outline.setShaderColor(context); - context.drawGuiTexture(TextureHelper.HUNGER_OUTLINE_SPRITE, x, y, 9, 9); + context.drawGuiTexture(TextureHelper.FOOD_EMPTY_TEXTURE, x, y, 9, 9); + + FoodOutline outline = FoodOutline.get(modifiedFoodHunger, defaultFoodHunger, i); + if (outline != FoodOutline.NORMAL) + { + outline.setShaderColor(context); + context.drawGuiTexture(TextureHelper.HUNGER_OUTLINE_SPRITE, x, y, 9, 9); + } + + context.setShaderColor(1.0F, 1.0F, 1.0F, .25F); + boolean isDefaultHalf = defaultFoodHunger - 1 == i; + Identifier defaultFoodIcon = TextureHelper.getFoodTexture(isRotten, isDefaultHalf ? FoodType.HALF : FoodType.FULL); + context.drawGuiTexture(defaultFoodIcon, x, y, 9, 9); + context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + + if (modifiedFoodHunger > i) + { + boolean isModifiedHalf = modifiedFoodHunger - 1 == i; + Identifier modifiedFoodIcon = TextureHelper.getFoodTexture(isRotten, isModifiedHalf ? FoodType.HALF : FoodType.FULL); + context.drawGuiTexture(modifiedFoodIcon, x, y, 9, 9); + } + + x -= 9; } - - context.setShaderColor(1.0F, 1.0F, 1.0F, .25F); - boolean isDefaultHalf = defaultFoodHunger - 1 == i; - Identifier defaultFoodIcon = TextureHelper.getFoodTexture(isRotten, isDefaultHalf ? FoodType.HALF : FoodType.FULL); - context.drawGuiTexture(defaultFoodIcon, x, y, 9, 9); - context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - - if (modifiedFoodHunger > i) + if (foodOverlay.hungerBarsText != null) { - boolean isModifiedHalf = modifiedFoodHunger - 1 == i; - Identifier modifiedFoodIcon = TextureHelper.getFoodTexture(isRotten, isModifiedHalf ? FoodType.HALF : FoodType.FULL); - context.drawGuiTexture(modifiedFoodIcon, x, y, 9, 9); + x += 18; + matrixStack.push(); + matrixStack.translate(x, y, tooltipZ); + matrixStack.scale(0.75f, 0.75f, 0.75f); + context.drawTextWithShadow(textRenderer, foodOverlay.hungerBarsText, 2, 2, 0xFFAAAAAA); + matrixStack.pop(); } - - x -= 9; - } - if (foodOverlay.hungerBarsText != null) - { - x += 18; - matrixStack.push(); - matrixStack.translate(x, y, tooltipZ); - matrixStack.scale(0.75f, 0.75f, 0.75f); - context.drawTextWithShadow(textRenderer, foodOverlay.hungerBarsText, 2, 2, 0xFFAAAAAA); - matrixStack.pop(); } - x = toolTipX; - y += 10; + if (ModConfig.INSTANCE.showSaturationValueInTooltip) { + x = toolTipX; - float modifiedSaturationIncrement = modifiedFood.saturation(); - float absModifiedSaturationIncrement = Math.abs(modifiedSaturationIncrement); + if (ModConfig.INSTANCE.showHungerValueInTooltip) + { + y += 10; + } - // Render from right to left so that the icons 'face' the right way - x += (foodOverlay.saturationBars - 1) * 7; + float modifiedSaturationIncrement = modifiedFood.saturation(); + float absModifiedSaturationIncrement = Math.abs(modifiedSaturationIncrement); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - for (int i = 0; i < foodOverlay.saturationBars * 2; i += 2) - { - float effectiveSaturationOfBar = (absModifiedSaturationIncrement - i) / 2f; + // Render from right to left so that the icons 'face' the right way + x += (foodOverlay.saturationBars - 1) * 7; - boolean shouldBeFaded = absModifiedSaturationIncrement <= i; - if (shouldBeFaded) - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, .5F); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + for (int i = 0; i < foodOverlay.saturationBars * 2; i += 2) { + float effectiveSaturationOfBar = (absModifiedSaturationIncrement - i) / 2f; - context.drawTexture(TextureHelper.MOD_ICONS, x, y, tooltipZ, effectiveSaturationOfBar >= 1 ? 21 : effectiveSaturationOfBar > 0.5 ? 14 : effectiveSaturationOfBar > 0.25 ? 7 : effectiveSaturationOfBar > 0 ? 0 : 28, modifiedSaturationIncrement >= 0 ? 27 : 34, 7, 7, 256, 256); + boolean shouldBeFaded = absModifiedSaturationIncrement <= i; + if (shouldBeFaded) + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, .5F); - if (shouldBeFaded) - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + context.drawTexture(TextureHelper.MOD_ICONS, x, y, tooltipZ, effectiveSaturationOfBar >= 1 ? 21 : effectiveSaturationOfBar > 0.5 ? 14 : effectiveSaturationOfBar > 0.25 ? 7 : effectiveSaturationOfBar > 0 ? 0 : 28, modifiedSaturationIncrement >= 0 ? 27 : 34, 7, 7, 256, 256); - x -= 7; - } - if (foodOverlay.saturationBarsText != null) - { - x += 14; - matrixStack.push(); - matrixStack.translate(x, y, tooltipZ); - matrixStack.scale(0.75f, 0.75f, 0.75f); - context.drawTextWithShadow(textRenderer, foodOverlay.saturationBarsText, 2, 1, 0xFFAAAAAA); - matrixStack.pop(); + if (shouldBeFaded) + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + + x -= 7; + } + if (foodOverlay.saturationBarsText != null) { + x += 14; + matrixStack.push(); + matrixStack.translate(x, y, tooltipZ); + matrixStack.scale(0.75f, 0.75f, 0.75f); + context.drawTextWithShadow(textRenderer, foodOverlay.saturationBarsText, 2, 1, 0xFFAAAAAA); + matrixStack.pop(); + } } RenderSystem.disableBlend(); @@ -366,12 +401,17 @@ private boolean shouldShowTooltip(ItemStack hoveredStack, TooltipType type) return false; } - boolean shouldShowTooltip = (ModConfig.INSTANCE.showFoodValuesInTooltip && KeyHelper.isShiftKeyDown()) || ModConfig.INSTANCE.showFoodValuesInTooltipAlways; + boolean shouldShowTooltip = (ModConfig.INSTANCE.showFoodValuesInTooltip && KeyHelper.isShiftKeyDown()) || (ModConfig.INSTANCE.showFoodValuesInTooltip && ModConfig.INSTANCE.showFoodValuesInTooltipAlways); if (!shouldShowTooltip) { return false; } + if (!ModConfig.INSTANCE.showHungerValueInTooltip && !ModConfig.INSTANCE.showSaturationValueInTooltip) + { + return false; + } + if (!FoodHelper.isFood(hoveredStack)) { return false; diff --git a/resources/assets/appleskin/lang/en_us.json b/resources/assets/appleskin/lang/en_us.json index e4c6291..be5e90b 100644 --- a/resources/assets/appleskin/lang/en_us.json +++ b/resources/assets/appleskin/lang/en_us.json @@ -2,6 +2,10 @@ "text.autoconfig.appleskin.title": "AppleSkin", "text.autoconfig.appleskin.option.showFoodValuesInTooltip": "Show food values in tooltip", "text.autoconfig.appleskin.option.showFoodValuesInTooltip.@Tooltip": "If true, shows the hunger and saturation values of food in its tooltip while holding SHIFT", + "text.autoconfig.appleskin.option.showHungerValueInTooltip": "Show hunger value in tooltip", + "text.autoconfig.appleskin.option.showHungerValueInTooltip.@Tooltip": "If true, shows the hunger value of food in its tooltip", + "text.autoconfig.appleskin.option.showSaturationValueInTooltip": "Show saturation value in tooltip", + "text.autoconfig.appleskin.option.showSaturationValueInTooltip.@Tooltip": "If true, shows the saturation value of food in its tooltip", "text.autoconfig.appleskin.option.showFoodValuesInTooltipAlways": "Always show food values in tooltip", "text.autoconfig.appleskin.option.showFoodValuesInTooltipAlways.@Tooltip": "If true, shows the hunger and saturation values of food in its tooltip automatically (without needing to hold SHIFT)", "text.autoconfig.appleskin.option.showFoodValuesHudOverlay": "Show hunger restored from held food",