Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
first prototype of component edit screen
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Jul 16, 2024
1 parent 5e1fa70 commit 4811bde
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 124 deletions.
40 changes: 22 additions & 18 deletions src/main/java/io/wispforest/gadget/client/GadgetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import io.wispforest.gadget.client.gui.GadgetScreen;
import io.wispforest.gadget.client.gui.inspector.UIInspector;
import io.wispforest.gadget.client.log.ChatLogAppender;
import io.wispforest.gadget.client.nbt.StackComponentDataScreen;
import io.wispforest.gadget.client.resource.ViewResourcesScreen;
import io.wispforest.gadget.mappings.MappingsManager;
import io.wispforest.gadget.mixin.client.HandledScreenAccessor;
import io.wispforest.gadget.network.BlockEntityTarget;
import io.wispforest.gadget.network.EntityTarget;
import io.wispforest.gadget.network.GadgetNetworking;
Expand Down Expand Up @@ -41,6 +43,8 @@
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -200,24 +204,24 @@ public void onInitializeClient() {
}, TitleScreen.class, GameMenuScreen.class);

ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
// if (screen instanceof HandledScreen<?> handled)
// ScreenKeyboardEvents.allowKeyPress(screen).register((screen1, key, scancode, modifiers) -> {
// if (!INSPECT_KEY.matchesKey(key, scancode)) return true;
//
// double mouseX = client.mouse.getX()
// * (double)client.getWindow().getScaledWidth() / (double)client.getWindow().getWidth();
// double mouseY = client.mouse.getY()
// * (double)client.getWindow().getScaledHeight() / (double)client.getWindow().getHeight();
// var slot = ((HandledScreenAccessor) handled).callGetSlotAt(mouseX, mouseY);
//
// if (slot == null) return true;
// if (slot instanceof CreativeInventoryScreen.LockableSlot) return true;
// if (slot.getStack().isEmpty()) return true;
//
// client.setScreen(new StackNbtDataScreen(handled, slot));
//
// return false;
// });
if (screen instanceof HandledScreen<?> handled)
ScreenKeyboardEvents.allowKeyPress(screen).register((screen1, key, scancode, modifiers) -> {
if (!INSPECT_KEY.matchesKey(key, scancode)) return true;

double mouseX = client.mouse.getX()
* (double)client.getWindow().getScaledWidth() / (double)client.getWindow().getWidth();
double mouseY = client.mouse.getY()
* (double)client.getWindow().getScaledHeight() / (double)client.getWindow().getHeight();
var slot = ((HandledScreenAccessor) handled).callGetSlotAt(mouseX, mouseY);

if (slot == null) return true;
if (slot instanceof CreativeInventoryScreen.LockableSlot) return true;
if (slot.getStack().isEmpty()) return true;

client.setScreen(new StackComponentDataScreen(handled, slot));

return false;
});

ScreenKeyboardEvents.allowKeyPress(screen).register((screen1, key, scancode, modifiers) -> {
if (!Screen.hasShiftDown()) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.wispforest.gadget.client.nbt;

import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.container.Containers;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.ScrollContainer;
import io.wispforest.owo.ui.core.*;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.Registries;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;

public class StackComponentDataScreen extends BaseOwoScreen<FlowLayout> {
private final ItemStack stack;
private final HandledScreen<?> parent;

public StackComponentDataScreen(HandledScreen<?> parent, Slot slot) {
this.stack = slot.getStack();
this.parent = parent;
}

@Override
protected @NotNull OwoUIAdapter<FlowLayout> createAdapter() {
return OwoUIAdapter.create(this, Containers::verticalFlow);
}

@Override
protected void build(FlowLayout rootComponent) {
rootComponent
.horizontalAlignment(HorizontalAlignment.CENTER)
.verticalAlignment(VerticalAlignment.CENTER)
.surface(Surface.VANILLA_TRANSLUCENT);


FlowLayout main = Containers.verticalFlow(Sizing.fill(100), Sizing.content());

ScrollContainer<FlowLayout> scroll = Containers.verticalScroll(Sizing.fill(95), Sizing.fill(100), main)
.scrollbar(ScrollContainer.Scrollbar.flat(Color.ofArgb(0xA0FFFFFF)));

rootComponent.child(scroll.child(main));

main
.padding(Insets.of(15));

for (var component : stack.getComponents()) {
FlowLayout full = Containers.verticalFlow(Sizing.content(), Sizing.content());
FlowLayout row = Containers.horizontalFlow(Sizing.content(), Sizing.content());

full.child(row);
main.child(full);

row.child(Components.label(Text.literal(Registries.DATA_COMPONENT_TYPE.getId(component.type()).toString())
.append(Text.literal(" = ")
.formatted(Formatting.GRAY))));

NbtElement tag = component.encode(client.world.getRegistryManager().getOps(NbtOps.INSTANCE)).getOrThrow();

NbtCompound compound;
if (tag instanceof NbtCompound c) {
compound = c;
} else {
compound = new NbtCompound();
compound.put("<value>", tag);
}

full.child(new NbtDataIsland(compound, null));
}
}

@Override
public void close() {
client.setScreen(parent);
}
}
106 changes: 0 additions & 106 deletions src/main/java/io/wispforest/gadget/client/nbt/StackNbtDataScreen.java

This file was deleted.

0 comments on commit 4811bde

Please sign in to comment.