Skip to content

Commit

Permalink
expanded feature: fix and refactor cleargrid button
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Nov 30, 2024
1 parent 8b23fa9 commit 9fa04b9
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import java.util.List;
import com.lothrazar.storagenetwork.StorageNetworkMod;
import com.lothrazar.storagenetwork.api.IGuiNetwork;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.TileableTexture;
import com.lothrazar.storagenetwork.gui.components.TextboxInteger;
import com.lothrazar.storagenetwork.jei.JeiHooks;
import com.lothrazar.storagenetwork.network.ClearRecipeMessage;
import com.lothrazar.storagenetwork.network.RequestMessage;
import com.lothrazar.storagenetwork.registry.PacketRegistry;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
Expand Down Expand Up @@ -99,23 +95,21 @@ public boolean mouseScrolled(double x, double y, double mouseButton) {
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
getNetwork().mouseClicked(mouseX, mouseY, mouseButton);
var size = getNetwork().getSize();
if (size.isCrafting()) {
//TODO: this is part of crafting grid, to clear it out. should be its own button class
int rectX = 63;
int rectY = 110;
if (size == NetworkScreenSize.EXPANDED) {
rectX = 63;
rectY = 110 + 200;
}
// TODO: revise above .out.println(mouseX + "," + mouseY);
if (isHovering(rectX, rectY, 7, 7, mouseX, mouseY)) {

PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
return true;
}
}
// var size = getNetwork().getSize();
// if (size.isCrafting()) {
// //TODO: this is part of crafting grid, to clear it out. should be its own button class
// int rectX = 63;
// int rectY = 110;
//
// // TODO: revise above
// if (isHovering(rectX, rectY, 7, 7, mouseX, mouseY)) {
// System.out.println("clear cancelled do nothing,");
//
// // PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
// // PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
// return true;
// }
// }
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.lothrazar.storagenetwork.block.expand;

import com.lothrazar.storagenetwork.StorageNetworkMod;
import com.lothrazar.storagenetwork.api.EnumSortType;
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import com.lothrazar.storagenetwork.gui.TileableTexture;
import com.lothrazar.storagenetwork.util.SsnConsts;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.fml.ModList;

Expand All @@ -38,6 +33,8 @@ public void init() {
addRenderableWidget(network.directionBtn);
addRenderableWidget(network.sortBtn);
addRenderableWidget(network.focusBtn);
if (this.network.getSize().isCrafting())
addRenderableWidget(network.clearGridBtn);
if (this.getAutoFocus()) {
network.searchBar.setFocused(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class TileInventoryExpanded extends TileInventory {

public TileInventoryExpanded(BlockPos pos, BlockState state) {
super(SsnRegistry.Tiles.INVENTORY_EXPANDED.get(), pos, state);
super(SsnRegistry.Tiles.REQUEST_EXPANDED.get(), pos, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -53,11 +52,6 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY)
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc, w, h);
network.resize(mc, w, h);
}
// all the IGUINETWORK implementations

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -36,6 +35,8 @@ public void init() {
addRenderableWidget(network.directionBtn);
addRenderableWidget(network.sortBtn);
addRenderableWidget(network.focusBtn);
if (this.network.getSize().isCrafting())
addRenderableWidget(network.clearGridBtn);
if (this.getAutoFocus()) {
network.searchBar.setFocused(true);
}
Expand All @@ -54,11 +55,6 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY)
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc, w, h);
network.resize(mc, w, h);
}
// all the IGUINETWORK implementations

@Override
Expand All @@ -81,6 +77,7 @@ public void setSort(EnumSortType s) {
tile.setSort(s);
}

@Override
public BlockPos getPos() {
return tile.getBlockPos();
}
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.lothrazar.storagenetwork.gui.components.ButtonRequest;
import com.lothrazar.storagenetwork.gui.components.ButtonRequest.TextureEnum;
import com.lothrazar.storagenetwork.gui.slot.ItemSlotNetwork;
import com.lothrazar.storagenetwork.network.ClearRecipeMessage;
import com.lothrazar.storagenetwork.network.InsertMessage;
import com.lothrazar.storagenetwork.network.RequestMessage;
import com.lothrazar.storagenetwork.registry.PacketRegistry;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class NetworkWidget {
public ButtonRequest sortBtn;
public ButtonRequest jeiBtn;
public ButtonRequest focusBtn;
public ButtonRequest clearGridBtn;
private List<ItemSlotNetwork> slots;
private final IGuiNetwork gui;
private long lastClick;
Expand Down Expand Up @@ -151,12 +153,23 @@ public void init(Font font) {
}, DEFAULT_NARRATION);
focusBtn.setHeight(11);
focusBtn.setWidth(6);
}

//called by outer component
@Deprecated
public void resize(Minecraft mc, int width, int height) {
//todo: how many rows? dynamically change size on screen resize from client
if (this.getSize() != NetworkScreenSize.LARGE) {
x = searchBar.getX() - 19;
y = searchBar.getY() + 13;
if (this.getSize() == NetworkScreenSize.EXPANDED) {
//omg this is a bit of a mess i should refactor this
x = searchBar.getX() - 99;
y = searchBar.getY() - 2;
}
clearGridBtn = new ButtonRequest(
x, y, "", (p) -> {
PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
}, DEFAULT_NARRATION);
clearGridBtn.setHeight(7);
clearGridBtn.setWidth(7);
this.clearGridBtn.setTextureId(TextureEnum.CRAFTCLEAR);
}
}

public List<ItemStack> getStacks() {
Expand Down Expand Up @@ -331,6 +344,9 @@ public void drawGuiContainerForegroundLayer(GuiGraphics ms, int mouseX, int mous
else if (sortBtn != null && sortBtn.isMouseOver(mouseX, mouseY)) {
tooltip = Component.translatable("gui.storagenetwork.req.tooltip_" + gui.getSort().name().toLowerCase());
}
else if (clearGridBtn != null && clearGridBtn.isMouseOver(mouseX, mouseY)) {
tooltip = Component.translatable("gui.storagenetwork.req.tooltip_cleargrid");
}
else if (focusBtn != null && focusBtn.isMouseOver(mouseX, mouseY)) {
tooltip = Component.translatable("gui.storagenetwork.autofocus.tooltip." + gui.getAutoFocus());
}
Expand Down Expand Up @@ -459,6 +475,8 @@ public void render() {
sortBtn.setTextureId(TextureEnum.SORT_NAME);
break;
}
if (this.clearGridBtn != null) {
}
focusBtn.setTextureId(gui.getAutoFocus() ? TextureEnum.RED : TextureEnum.GREY);
directionBtn.setTextureId(gui.getDownwards() ? TextureEnum.SORT_DOWN : TextureEnum.SORT_UP);
if (jeiBtn != null && ModList.get().isLoaded("jei")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ButtonRequest extends Button {

public static enum TextureEnum {

ALLOWLIST, IGNORELIST, SORT_AMT, SORT_MOD, SORT_NAME, SORT_UP, SORT_DOWN, JEI_RED, JEI_GREEN, IMPORT, PLUS, MINUS, REDSTONETRUE, REDSTONEFALSE, RED, GREY;
ALLOWLIST, IGNORELIST, SORT_AMT, SORT_MOD, SORT_NAME, SORT_UP, SORT_DOWN, JEI_RED, JEI_GREEN, IMPORT, PLUS, MINUS, REDSTONETRUE, REDSTONEFALSE, RED, GREY, CRAFTCLEAR;

public int getX() {
switch (this) {
Expand Down Expand Up @@ -50,6 +50,8 @@ public int getX() {
return 196;
case MINUS:
return 177;
case CRAFTCLEAR:
return 209;
default:
return 0;
}
Expand Down Expand Up @@ -82,6 +84,8 @@ public int getY() {
return 13;
case MINUS:
return 13;
case CRAFTCLEAR:
return 53;
default:
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -37,6 +36,8 @@ public void init() {
addRenderableWidget(network.directionBtn);
addRenderableWidget(network.sortBtn);
addRenderableWidget(network.focusBtn);
if (this.network.getSize().isCrafting())
addRenderableWidget(network.clearGridBtn);
if (this.getAutoFocus()) {
network.searchBar.setFocused(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.lothrazar.storagenetwork.item.remote;

import com.lothrazar.storagenetwork.StorageNetworkMod;
import com.lothrazar.storagenetwork.api.EnumSortType;
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fml.ModList;
Expand Down Expand Up @@ -36,6 +33,8 @@ public void init() {
addRenderableWidget(network.directionBtn);
addRenderableWidget(network.sortBtn);
addRenderableWidget(network.focusBtn);
if (network.clearGridBtn != null)
addRenderableWidget(network.clearGridBtn);
if (this.getAutoFocus()) {
network.searchBar.setFocused(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -55,12 +54,6 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc, w, h);
network.resize(mc, w, h);
}

@Override
public boolean getDownwards() {
return ItemStorageCraftingRemote.getDownwards(remote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static class Blocks {
public static final RegistryObject<Block> FILTER_KABEL = BLOCKS.register("filter_kabel", () -> new BlockCableFilter());
public static final RegistryObject<Block> EXPORT_KABEL = BLOCKS.register("export_kabel", () -> new BlockCableExport());
public static final RegistryObject<Block> INVENTORY = BLOCKS.register("inventory", () -> new BlockInventory());
public static final RegistryObject<Block> INVENTORY_EXPANDED = BLOCKS.register("inventory_expanded", () -> new BlockInventoryExpanded());
public static final RegistryObject<Block> REQUEST_EXPANDED = BLOCKS.register("request_expanded", () -> new BlockInventoryExpanded());
public static final RegistryObject<Block> EXCHANGE = BLOCKS.register("exchange", () -> new BlockExchange());
public static final RegistryObject<Block> COLLECTOR = BLOCKS.register("collector", () -> new BlockCollection());
}
Expand All @@ -83,7 +83,7 @@ public static class Items {
// public static final RegistryObject<Item> REQUEST_EXPANDED = ITEMS.register("request_expanded", () -> new BlockItem(Blocks.REQUEST_EXPANDED.get(), new Item.Properties()));
public static final RegistryObject<Item> KABEL = ITEMS.register("kabel", () -> new BlockItem(Blocks.KABEL.get(), new Item.Properties()));
public static final RegistryObject<Item> INVENTORY = ITEMS.register("inventory", () -> new BlockItem(Blocks.INVENTORY.get(), new Item.Properties()));
public static final RegistryObject<Item> INVENTORY_EXPANDED = ITEMS.register("inventory_expanded", () -> new BlockItem(Blocks.INVENTORY_EXPANDED.get(), new Item.Properties()));
public static final RegistryObject<Item> INVENTORY_EXPANDED = ITEMS.register("request_expanded", () -> new BlockItem(Blocks.REQUEST_EXPANDED.get(), new Item.Properties()));
public static final RegistryObject<Item> MAS = ITEMS.register("master", () -> new BlockItem(Blocks.MASTER.get(), new Item.Properties()));
public static final RegistryObject<Item> SK = ITEMS.register("storage_kabel", () -> new BlockItem(Blocks.STORAGE_KABEL.get(), new Item.Properties()));
public static final RegistryObject<Item> IK = ITEMS.register("import_kabel", () -> new BlockItem(Blocks.IMPORT_KABEL.get(), new Item.Properties()));
Expand Down Expand Up @@ -111,7 +111,7 @@ public static class Tiles {

public static final RegistryObject<BlockEntityType<TileMain>> MASTER = TILES.register("master", () -> BlockEntityType.Builder.of(TileMain::new, Blocks.MASTER.get()).build(null));
public static final RegistryObject<BlockEntityType<TileInventory>> INVENTORY = TILES.register("inventory", () -> BlockEntityType.Builder.of(TileInventory::new, Blocks.INVENTORY.get()).build(null));
public static final RegistryObject<BlockEntityType<TileInventoryExpanded>> INVENTORY_EXPANDED = TILES.register("inventory_expanded", () -> BlockEntityType.Builder.of(TileInventoryExpanded::new, Blocks.INVENTORY_EXPANDED.get()).build(null));
public static final RegistryObject<BlockEntityType<TileInventoryExpanded>> REQUEST_EXPANDED = TILES.register("request_expanded", () -> BlockEntityType.Builder.of(TileInventoryExpanded::new, Blocks.REQUEST_EXPANDED.get()).build(null));
public static final RegistryObject<BlockEntityType<TileRequest>> REQUEST = TILES.register("request", () -> BlockEntityType.Builder.of(TileRequest::new, Blocks.REQUEST.get()).build(null));
public static final RegistryObject<BlockEntityType<TileCable>> KABEL = TILES.register("kabel", () -> BlockEntityType.Builder.of(TileCable::new, Blocks.KABEL.get()).build(null));
public static final RegistryObject<BlockEntityType<TileCableLink>> STORAGE_KABEL = TILES.register("storage_kabel", () -> BlockEntityType.Builder.of(TileCableLink::new, Blocks.STORAGE_KABEL.get()).build(null));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "storagenetwork:block/request_expanded"
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/storagenetwork/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
"gui.storagenetwork.tooltip_clear": "Clear Search",
"gui.storagenetwork.fil.tooltip_jei_on": "JEI search enabled",
"gui.storagenetwork.fil.tooltip_jei_off": "JEI search disabled",

"gui.storagenetwork.req.tooltip_cleargrid":"Clear Grid",

"block.storagenetwork.kabel.tooltip": "Basic network cable ",
"block.storagenetwork.storage_kabel.tooltip": "Used to connect inventory to the network",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "storagenetwork:block/request_expanded"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "storagenetwork:item/expanded_remote"
}
}
Binary file modified src/main/resources/assets/storagenetwork/textures/gui/cable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/storagenetwork/textures/gui/request.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9fa04b9

Please sign in to comment.