From 81972bbfe935675a28472c7c50f9971d3b70d4f8 Mon Sep 17 00:00:00 2001 From: Globox1997 Date: Fri, 16 Aug 2024 08:47:44 +0200 Subject: [PATCH] minor tweaks --- .../mayor/screen/MayorScreen.java | 6 ++++-- .../mayor/screen/MayorVillageScreen.java | 21 ++++++++++++++++++- .../screen/widget/ItemScrollableWidget.java | 5 ++++- .../screen/widget/ObjectScrollableWidget.java | 7 +++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/fabricatedatelier/mayor/screen/MayorScreen.java b/src/main/java/io/fabricatedatelier/mayor/screen/MayorScreen.java index c0ee6cd..b310190 100644 --- a/src/main/java/io/fabricatedatelier/mayor/screen/MayorScreen.java +++ b/src/main/java/io/fabricatedatelier/mayor/screen/MayorScreen.java @@ -73,7 +73,7 @@ protected void init() { } } - this.buildingCategoryScrollableWidget = this.addDrawableChild(new ObjectScrollableWidget(16, 16, 56, 170, Text.translatable("building.category"), this.textRenderer, this)); + this.buildingCategoryScrollableWidget = this.addDrawableChild(new ObjectScrollableWidget(16, 16, 56, 170, Text.translatable("building.category"), this.textRenderer)); List objects = new ArrayList<>(); List texts = new ArrayList<>(); for (int i = 0; i < MayorCategory.BuildingCategory.values().length; i++) { @@ -81,8 +81,10 @@ protected void init() { texts.add(Text.translatable(MayorCategory.BuildingCategory.values()[i].name())); } this.buildingCategoryScrollableWidget.setObjects(objects, texts); + this.buildingCategoryScrollableWidget.setMayorScreen(this); - this.buildingScrollableWidget = this.addDrawableChild(new ObjectScrollableWidget(80, 16, 70, 170, Text.translatable("building.buildings"), this.textRenderer, this)); + this.buildingScrollableWidget = this.addDrawableChild(new ObjectScrollableWidget(80, 16, 70, 170, Text.translatable("building.buildings"), this.textRenderer)); + this.buildingScrollableWidget.setMayorScreen(this); this.availableStacks.clear(); if (this.mayorManager.getVillageData() != null && this.client != null && this.client.world != null) { diff --git a/src/main/java/io/fabricatedatelier/mayor/screen/MayorVillageScreen.java b/src/main/java/io/fabricatedatelier/mayor/screen/MayorVillageScreen.java index 8249921..b115f0c 100644 --- a/src/main/java/io/fabricatedatelier/mayor/screen/MayorVillageScreen.java +++ b/src/main/java/io/fabricatedatelier/mayor/screen/MayorVillageScreen.java @@ -2,10 +2,15 @@ import io.fabricatedatelier.mayor.init.KeyBindings; import io.fabricatedatelier.mayor.manager.MayorManager; +import io.fabricatedatelier.mayor.screen.widget.ObjectScrollableWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.SpectatorHud; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerInteractionManager; import net.minecraft.text.Text; import net.minecraft.util.Colors; @@ -14,17 +19,31 @@ public class MayorVillageScreen extends Screen { private final MayorManager mayorManager; + private ObjectScrollableWidget villagerScrollableWidget; + public MayorVillageScreen(MayorManager mayorManager) { super(Text.translatable("mayor.screen.title")); this.mayorManager = mayorManager; } + @Override + protected void init() { + super.init(); + if (mayorManager.getVillageData() != null) { + this.villagerScrollableWidget = this.addDrawableChild(new ObjectScrollableWidget(16, 16, 70, 170, Text.translatable("mayor.screen.villagers", mayorManager.getVillageData().getVillagers().size()), this.textRenderer)); +// this.mayorManager.getVillageData().getVillagers() +// this.villagerScrollableWidget.setObjects(); +// this.client.player.getWorld().getent +// MinecraftClient + } + } + @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); Text wip = Text.of("WIP"); - context.drawText(this.textRenderer, wip, this.width / 2, this.height / 2 - this.textRenderer.getWidth(wip) / 2, Colors.GRAY, false); + context.drawText(this.textRenderer, wip, this.width / 2 - this.textRenderer.getWidth(wip), this.height / 2 / 2, Colors.GRAY, false); if (mayorManager.getVillageData() != null) { int villageMiddleX = this.width / 2; diff --git a/src/main/java/io/fabricatedatelier/mayor/screen/widget/ItemScrollableWidget.java b/src/main/java/io/fabricatedatelier/mayor/screen/widget/ItemScrollableWidget.java index 5027e24..bf8498e 100644 --- a/src/main/java/io/fabricatedatelier/mayor/screen/widget/ItemScrollableWidget.java +++ b/src/main/java/io/fabricatedatelier/mayor/screen/widget/ItemScrollableWidget.java @@ -44,7 +44,7 @@ public void setItemStacks(@Nullable List itemStacks) { } @Nullable - public List getItemStacks(){ + public List getItemStacks() { return this.itemStacks; } @@ -79,6 +79,9 @@ protected void renderContents(DrawContext context, int mouseX, int mouseY, float int row = (int) this.getScrollY() / 18; for (int u = row * 6; u < this.itemStacks.size() && u < ((this.maxRows * 6) + row * 6); u++) { + if (this.itemStacks.get(u).isEmpty()) { + continue; + } context.drawItemWithoutEntity(this.itemStacks.get(u), xSpace, ySpace - this.maxRows * 18); context.drawItemInSlot(this.textRenderer, this.itemStacks.get(u), xSpace, ySpace - this.maxRows * 18); diff --git a/src/main/java/io/fabricatedatelier/mayor/screen/widget/ObjectScrollableWidget.java b/src/main/java/io/fabricatedatelier/mayor/screen/widget/ObjectScrollableWidget.java index 69ec467..0e7ea67 100644 --- a/src/main/java/io/fabricatedatelier/mayor/screen/widget/ObjectScrollableWidget.java +++ b/src/main/java/io/fabricatedatelier/mayor/screen/widget/ObjectScrollableWidget.java @@ -25,7 +25,7 @@ public class ObjectScrollableWidget extends ScrollableWidget { private final Text title; private final TextRenderer textRenderer; - private final MayorScreen mayorScreen; + private MayorScreen mayorScreen; @Nullable private List objects; @@ -38,10 +38,13 @@ public class ObjectScrollableWidget extends ScrollableWidget { @Nullable private Object selectedObject = null; - public ObjectScrollableWidget(int x, int y, int width, int height, Text title, TextRenderer textRenderer, MayorScreen mayorScreen) { + public ObjectScrollableWidget(int x, int y, int width, int height, Text title, TextRenderer textRenderer) { super(x, y, width, height, title); this.title = title; this.textRenderer = textRenderer; + } + + public void setMayorScreen(MayorScreen mayorScreen) { this.mayorScreen = mayorScreen; }