Skip to content

Commit

Permalink
feat: expand inventory to two rows at the bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
mzdun committed Oct 1, 2024
1 parent 47bc149 commit 9f79e9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public InventoryHandler(ScannerInventory inventory) {
Constants.TOP + row * Constants.BUTTON_SIZE));
}
}
for (int col = 0; col < Constants.COLUMNS_COUNT; ++col) {
this.addSlot(new Slot(inventory, col, Constants.DX + col * Constants.BUTTON_SIZE,
Constants.INVENTORY_HEIGHT - Constants.BOTTOM - Constants.BUTTON_SIZE));
final var topRow = Constants.INVENTORY_HEIGHT - Constants.BOTTOM - 2 * Constants.BUTTON_SIZE;
for (int row = 0; row < Constants.AT_HAND_ROWS_COUNT; ++row) {
final var idOffset = row * Constants.COLUMNS_COUNT;
for (int col = 0; col < Constants.COLUMNS_COUNT; ++col) {
this.addSlot(new Slot(inventory, idOffset + col, Constants.DX + col * Constants.BUTTON_SIZE,
topRow + row * Constants.BUTTON_SIZE));
}
}
this.scrollItems(0.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface Constants {
Identifier ITEMS_BG = Identifier.ofVanilla("textures/gui/container/creative_inventory/tab_items.png");

int ROWS_COUNT = 5;
int AT_HAND_ROWS_COUNT = 2;
int COLUMNS_COUNT = 9;
int DX = 9;
int TOP = 18;
Expand All @@ -28,7 +29,8 @@ public interface Constants {
int SCROLLBAR_WIDTH = 12;
int SCROLLBAR_HEIGHT = 15;

int INVENTORY_HEIGHT = TOP + ROWS_COUNT * BUTTON_SIZE + VERTICAL_SPACE + BUTTON_SIZE + BOTTOM;
int TEXTURE_HEIGHT = TOP + ROWS_COUNT * BUTTON_SIZE + VERTICAL_SPACE + BUTTON_SIZE + BOTTOM;
int INVENTORY_HEIGHT = TEXTURE_HEIGHT + BUTTON_SIZE;
int INVENTORY_WIDTH = DX + COLUMNS_COUNT * BUTTON_SIZE + SCROLLBAR_SEP + SCROLLBAR_WIDTH + DX;

int OPTION_SEP = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.midnightbits.scanner.modmenu.InventoryHandler;
import com.midnightbits.scanner.modmenu.ScannerInventory;
import com.midnightbits.scanner.rt.core.Id;
import com.mojang.datafixers.kinds.Const;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.util.Identifier;

import java.util.Set;
import java.util.function.Consumer;
Expand All @@ -16,8 +18,6 @@
// - Dropping item stack _anywhere_ should merge with preexisting stack (count still 1)
// - Add scrolling (low prio, nothing _to_ scroll)
// - _Nice to have_: Dropping item to on-hand inventory should re-sort that inventory
// - _Nice to have_: Expand the on-hand inventory to two rows (paint the texture, then
// overlay with the bottom of the same texture)

@Environment(value = EnvType.CLIENT)
public class InventoryWidget extends HandledWidget<InventoryHandler> {
Expand Down Expand Up @@ -49,6 +49,24 @@ protected void drawForeground(DrawContext context, int mouseX, int mouseY) {
context.drawText(client.textRenderer, inventory.getName(), 8, 6, 0x404040, false);
}

@Override
protected void drawBackground(DrawContext context) {
final var mid_bottom_cut = 2;
final var top_section_y = 0;
final var top_section_h = Constants.TEXTURE_HEIGHT - Constants.BUTTON_SIZE - Constants.BOTTOM;
final var middle_section_y = Constants.TOP + Constants.BUTTON_SIZE;
final var middle_section_h = 2 * Constants.BUTTON_SIZE - mid_bottom_cut;
final var bottom_section_y = Constants.TEXTURE_HEIGHT - Constants.BOTTOM - mid_bottom_cut;
final var bottom_section_h = Constants.BOTTOM + mid_bottom_cut;
drawBackgroundSection(context, 0, top_section_y, top_section_h);
drawBackgroundSection(context, top_section_h, middle_section_y, middle_section_h);
drawBackgroundSection(context, top_section_h + middle_section_h, bottom_section_y, bottom_section_h);
}

private void drawBackgroundSection(DrawContext context, int y, int u, int height) {
context.drawTexture(Constants.ITEMS_BG, 0, y, 0, u, Constants.INVENTORY_WIDTH, height);
}

// Inventory widget
public void applyPendingValue() {
final var ids = inventory.serialize();
Expand Down

0 comments on commit 9f79e9c

Please sign in to comment.