Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions java/squeek/appleskin/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
174 changes: 107 additions & 67 deletions java/squeek/appleskin/client/TooltipOverlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions resources/assets/appleskin/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down