ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java

96 lines
4 KiB
Java
Raw Normal View History

/*
* This file ("FilterSettingsGui.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
2024-03-02 21:23:08 +01:00
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
2024-03-03 01:20:53 +01:00
import net.minecraft.client.gui.GuiGraphics;
2024-03-06 00:02:32 +01:00
import net.minecraft.client.gui.components.AbstractButton;
2024-03-02 21:23:08 +01:00
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
2024-03-04 20:21:48 +01:00
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
2021-02-26 22:15:48 +01:00
import java.util.ArrayList;
import java.util.List;
2024-03-06 00:02:32 +01:00
import java.util.function.Consumer;
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2024-03-03 01:20:53 +01:00
public class FilterSettingsGui {
private final FilterSettings theSettings;
2024-03-13 02:05:05 +01:00
public Button allowButton;
2024-03-06 00:47:10 +01:00
public Button modButton;
2024-03-10 23:10:39 +01:00
public FilterSettingsGui(FilterSettings settings, int x, int y, Consumer<AbstractButton> buttonConsumer, Consumer<Integer> clickConsumer, int idOffset) {
this.theSettings = settings;
2024-03-13 02:05:05 +01:00
this.allowButton = Button.builder(Component.literal("A"), $ -> {
theSettings.isAllowFilter = !theSettings.isAllowFilter;
2024-03-10 23:10:39 +01:00
clickConsumer.accept(idOffset);
2024-03-06 19:59:34 +01:00
})
2024-03-06 00:47:10 +01:00
.bounds(x, y, 16, 12).build();
2024-03-13 02:05:05 +01:00
buttonConsumer.accept(this.allowButton);
2016-11-26 21:32:27 +01:00
y += 14;
2024-03-06 19:59:34 +01:00
this.modButton = Button.builder(Component.literal("MO"), $ -> {
theSettings.respectMod = !theSettings.respectMod;
2024-03-10 23:10:39 +01:00
clickConsumer.accept(idOffset + 1);
2024-03-06 19:59:34 +01:00
})
2024-03-06 00:47:10 +01:00
.bounds(x, y, 16, 12).build();
2024-03-06 00:02:32 +01:00
buttonConsumer.accept(this.modButton);
2021-03-01 20:55:50 +01:00
this.tick();
}
2024-03-10 23:10:39 +01:00
/* public void buttonClicked(int id) {
2024-03-06 00:02:32 +01:00
CompoundTag data = new CompoundTag();
data.putInt("ButtonID", id);
data.putInt("PlayerID", Minecraft.getInstance().player.getId());
data.putString("WorldID", Minecraft.getInstance().level.dimension().location().toString());
PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER));
2024-03-10 23:10:39 +01:00
}*/
2024-03-06 00:02:32 +01:00
2021-03-01 20:55:50 +01:00
public void tick() {
2024-03-13 02:05:05 +01:00
if (this.theSettings.isAllowFilter)
this.allowButton.setMessage(Component.literal("A").withStyle(ChatFormatting.DARK_GREEN));
else
this.allowButton.setMessage(Component.literal("D").withStyle(ChatFormatting.RED));
2024-03-05 23:23:49 +01:00
this.modButton.setMessage(Component.literal("MO").withStyle(this.theSettings.respectMod
2024-03-02 21:23:08 +01:00
? ChatFormatting.DARK_GREEN
: ChatFormatting.RED));
}
2024-03-03 01:20:53 +01:00
public void drawHover(GuiGraphics guiGraphics, int mouseX, int mouseY) {
2021-02-26 22:15:48 +01:00
Minecraft mc = Minecraft.getInstance();
2024-03-02 21:23:08 +01:00
List<Component> list = new ArrayList<>();
2024-03-13 02:05:05 +01:00
if (this.allowButton.isMouseOver(mouseX, mouseY)) {
list.add((this.theSettings.isAllowFilter
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.allow")
: Component.translatable("info." + ActuallyAdditions.MODID + ".gui.deny")).withStyle(ChatFormatting.BOLD));
list.add(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.filterInfo"));
2021-03-01 20:55:50 +01:00
} else if (this.modButton.isMouseOver(mouseX, mouseY)) {
2023-03-16 00:17:57 +01:00
list.add((this.theSettings.respectMod
2024-03-03 01:20:53 +01:00
? Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectMod")
: Component.translatable("info." + ActuallyAdditions.MODID + ".gui.ignoreMod")).withStyle(ChatFormatting.BOLD));
list.add(Component.translatable("info." + ActuallyAdditions.MODID + ".gui.respectModInfo"));
2017-04-01 19:40:39 +02:00
}
2023-03-16 00:17:57 +01:00
//TODO tooltips still jank
2024-03-03 01:20:53 +01:00
if (!list.isEmpty()) {
2024-03-12 16:35:56 +01:00
guiGraphics.renderComponentTooltip(mc.font, list, mouseX, mouseY);
2024-03-02 21:23:08 +01:00
}
}
}