Skip to content

Commit

Permalink
wip: fix tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jan 9, 2024
1 parent bda19e0 commit a441062
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

public class CookingForBlockheads {

// TODO search doesn't do anything

public static final String MOD_ID = "cookingforblockheads";
public static final Logger logger = LogManager.getLogger(MOD_ID);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.blay09.mods.cookingforblockheads.api;

import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

Expand All @@ -9,7 +10,7 @@
public interface ISortButton {
ResourceLocation getIcon();

String getTooltip();
Component getTooltip();

Comparator<RecipeWithStatus> getComparator(Player player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorHunger;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

Expand All @@ -19,8 +20,8 @@ public ResourceLocation getIcon() {
}

@Override
public String getTooltip() {
return "tooltip.cookingforblockheads.sort_by_hunger";
public Component getTooltip() {
return Component.translatable("tooltip.cookingforblockheads.sort_by_hunger");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorName;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

Expand All @@ -19,8 +20,8 @@ public ResourceLocation getIcon() {
}

@Override
public String getTooltip() {
return "tooltip.cookingforblockheads.sort_by_name";
public Component getTooltip() {
return Component.translatable("tooltip.cookingforblockheads.sort_by_name");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorSaturation;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

Expand All @@ -19,8 +20,8 @@ public ResourceLocation getIcon() {
}

@Override
public String getTooltip() {
return "tooltip.cookingforblockheads.sort_by_saturation";
public Component getTooltip() {
return Component.translatable("tooltip.cookingforblockheads.sort_by_saturation");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package net.blay09.mods.cookingforblockheads.client.gui;

import com.google.common.collect.Lists;
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;

import java.util.Comparator;
import java.util.List;

public class SortButton extends Button {

private final ISortButton button;

private final List<Component> tooltipLines = Lists.newArrayList();

public SortButton(int x, int y, ISortButton button, OnPress onPress) {
super(x, y, 20, 20, Component.empty(), onPress, Button.DEFAULT_NARRATION);
this.button = button;
this.tooltipLines.add(Component.translatable(this.button.getTooltip()));
setTooltip(Tooltip.create(this.button.getTooltip()));
}

@Override
Expand All @@ -38,10 +35,6 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
guiGraphics.blit(button.getIcon(), getX(), getY(), button.getIconTextureX(), texY, width, height);
}

public List<Component> getTooltipLines() {
return tooltipLines;
}

public Comparator<RecipeWithStatus> getComparator(Player player) {
return button.getComparator(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,6 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
matrixSlot.updateSlot(partialTicks);
}

for (Button sortButton : this.sortButtons) {
if (sortButton instanceof SortButton && sortButton.isMouseOver(mouseX, mouseY) && sortButton.active) {
guiGraphics.renderTooltip(font, ((SortButton) sortButton).getTooltipLines(), Optional.empty(), mouseX, mouseY);
}
}

this.renderTooltip(guiGraphics, mouseX, mouseY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void setScrollOffset(int scrollOffset) {

public void search(@Nullable String term) {
this.currentSearch = term;
updateCraftableSlots();
updateFilteredRecipes();
setScrollOffset(0);
}

Expand Down

0 comments on commit a441062

Please sign in to comment.