Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Aug 16, 2024
1 parent e3ebb2d commit 81972bb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ 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<Object> objects = new ArrayList<>();
List<Text> texts = new ArrayList<>();
for (int i = 0; i < MayorCategory.BuildingCategory.values().length; i++) {
objects.add(MayorCategory.BuildingCategory.values()[i]);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setItemStacks(@Nullable List<ItemStack> itemStacks) {
}

@Nullable
public List<ItemStack> getItemStacks(){
public List<ItemStack> getItemStacks() {
return this.itemStacks;
}

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> objects;
Expand All @@ -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;
}

Expand Down

0 comments on commit 81972bb

Please sign in to comment.