Skip to content

Commit

Permalink
Committing to switch machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundaround committed Jul 12, 2024
1 parent 3171057 commit 04deb8d
Show file tree
Hide file tree
Showing 25 changed files with 638 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import me.roundaround.armorstands.ArmorStandsMod;
import me.roundaround.armorstands.client.ArmorStandsClientMod;
import me.roundaround.armorstands.client.gui.MessageRenderer;
import me.roundaround.armorstands.client.gui.MessageRenderer.HasMessageRenderer;
import me.roundaround.armorstands.client.gui.widget.HelpButtonWidget;
import me.roundaround.armorstands.client.gui.widget.IconButtonWidget;
import me.roundaround.armorstands.client.gui.widget.LabelWidget;
import me.roundaround.armorstands.client.gui.widget.NavigationButtonWidget;
import me.roundaround.armorstands.client.network.ClientNetworking;
import me.roundaround.armorstands.mixin.ArmorStandEntityAccessor;
Expand All @@ -17,7 +15,7 @@
import me.roundaround.armorstands.network.ScreenType;
import me.roundaround.armorstands.network.UtilityAction;
import me.roundaround.armorstands.screen.ArmorStandScreenHandler;
import me.roundaround.armorstands.util.HasArmorStand;
import me.roundaround.roundalib.client.gui.GuiUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -37,20 +35,16 @@
import java.util.Objects;
import java.util.Optional;

public abstract class AbstractArmorStandScreen extends HandledScreen<ArmorStandScreenHandler> implements HasArmorStand,
HasMessageRenderer,
public abstract class AbstractArmorStandScreen extends HandledScreen<ArmorStandScreenHandler> implements
PassesEventsThrough {
protected static final Identifier SELECTION_TEXTURE = new Identifier(
ArmorStandsMod.MOD_ID, "textures/gui/selection_frame.png");

protected static final int SCREEN_EDGE_PAD = 4;
protected static final int BETWEEN_PAD = 2;
protected static final int NAV_BUTTON_BOTTOM_PADDING = 1;
protected static final int NAV_BUTTON_SPACING = 0;

protected final ArmorStandEntity armorStand;
protected final MessageRenderer messageRenderer;
protected final ArrayList<LabelWidget> labels = new ArrayList<>();
protected final ArrayList<NavigationButtonWidget> navigationButtons = new ArrayList<>();

protected NavigationButtonWidget activeButton;
Expand All @@ -71,17 +65,10 @@ protected AbstractArmorStandScreen(ArmorStandScreenHandler handler, Text title)

public abstract ScreenType getScreenType();

protected LabelWidget addLabel(LabelWidget label) {
this.labels.add(label);
return label;
}

@Override
public ArmorStandEntity getArmorStand() {
return this.armorStand;
}

@Override
public MessageRenderer getMessageRenderer() {
return this.messageRenderer;
}
Expand Down Expand Up @@ -129,11 +116,6 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
RenderSystem.enableBlend();
((InGameHudAccessor) this.client.inGameHud).invokeRenderVignetteOverlay(drawContext, this.client.getCameraEntity());

// Render labels before all other widgets so they are rendered on bottom
for (LabelWidget label : this.labels) {
label.render(drawContext, adjustedMouseX, adjustedMouseY, delta);
}

super.render(drawContext, adjustedMouseX, adjustedMouseY, delta);

renderActivePageButtonHighlight(drawContext);
Expand Down Expand Up @@ -374,7 +356,6 @@ public void updateDisabledSlotsOnClient(int disabledSlots) {
}

protected void initStart() {
this.labels.clear();
this.navigationButtons.clear();
}

Expand All @@ -383,23 +364,24 @@ protected void initUtilityButtons() {
return;
}

addDrawableChild(new HelpButtonWidget(SCREEN_EDGE_PAD, SCREEN_EDGE_PAD));
addDrawableChild(new IconButtonWidget(SCREEN_EDGE_PAD + IconButtonWidget.WIDTH + BETWEEN_PAD, SCREEN_EDGE_PAD, 14,
Text.translatable("armorstands.utility.copy"),
(button) -> ClientNetworking.sendUtilityActionPacket(UtilityAction.COPY)
));
addDrawableChild(new HelpButtonWidget(GuiUtil.PADDING, GuiUtil.PADDING));
addDrawableChild(
new IconButtonWidget(GuiUtil.PADDING + IconButtonWidget.WIDTH + (GuiUtil.PADDING / 2), GuiUtil.PADDING, 14,
Text.translatable("armorstands.utility.copy"),
(button) -> ClientNetworking.sendUtilityActionPacket(UtilityAction.COPY)
));
addDrawableChild(
new IconButtonWidget(SCREEN_EDGE_PAD + 2 * (IconButtonWidget.WIDTH + BETWEEN_PAD), SCREEN_EDGE_PAD, 15,
Text.translatable("armorstands.utility.paste"),
new IconButtonWidget(GuiUtil.PADDING + 2 * (IconButtonWidget.WIDTH + (GuiUtil.PADDING / 2)), GuiUtil.PADDING,
15, Text.translatable("armorstands.utility.paste"),
(button) -> ClientNetworking.sendUtilityActionPacket(UtilityAction.PASTE)
));
addDrawableChild(
new IconButtonWidget(SCREEN_EDGE_PAD + 3 * (IconButtonWidget.WIDTH + BETWEEN_PAD), SCREEN_EDGE_PAD, 17,
Text.translatable("armorstands.utility.undo"), (button) -> ClientNetworking.sendUndoPacket(false)
new IconButtonWidget(GuiUtil.PADDING + 3 * (IconButtonWidget.WIDTH + (GuiUtil.PADDING / 2)), GuiUtil.PADDING,
17, Text.translatable("armorstands.utility.undo"), (button) -> ClientNetworking.sendUndoPacket(false)
));
addDrawableChild(
new IconButtonWidget(SCREEN_EDGE_PAD + 4 * (IconButtonWidget.WIDTH + BETWEEN_PAD), SCREEN_EDGE_PAD, 18,
Text.translatable("armorstands.utility.redo"), (button) -> ClientNetworking.sendUndoPacket(true)
new IconButtonWidget(GuiUtil.PADDING + 4 * (IconButtonWidget.WIDTH + (GuiUtil.PADDING / 2)), GuiUtil.PADDING,
18, Text.translatable("armorstands.utility.redo"), (button) -> ClientNetworking.sendUndoPacket(true)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.roundaround.armorstands.network.ArmorStandFlag;
import me.roundaround.armorstands.network.ScreenType;
import me.roundaround.armorstands.screen.ArmorStandScreenHandler;
import me.roundaround.roundalib.client.gui.GuiUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.entity.EquipmentSlot;
Expand All @@ -17,8 +18,8 @@
public class ArmorStandInventoryScreen extends AbstractArmorStandScreen {
private static final int BACKGROUND_WIDTH = 176;
private static final int BACKGROUND_HEIGHT = 166;
private static final Identifier CUSTOM_TEXTURE =
new Identifier(ArmorStandsMod.MOD_ID, "textures/gui/container/inventory.png");
private static final Identifier CUSTOM_TEXTURE = new Identifier(
ArmorStandsMod.MOD_ID, "textures/gui/container/inventory.png");

private float mouseX;
private float mouseY;
Expand All @@ -39,16 +40,14 @@ public ScreenType getScreenType() {

@Override
protected void initRight() {
this.showArmsToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer,
ArmorStandFlag.SHOW_ARMS,
ArmorStandFlag.SHOW_ARMS.getValue(this.armorStand),
this.width - SCREEN_EDGE_PAD,
this.height - SCREEN_EDGE_PAD - 2 * FlagToggleWidget.WIDGET_HEIGHT - BETWEEN_PAD));
this.lockInventoryToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer,
ArmorStandFlag.LOCK_INVENTORY,
ArmorStandFlag.LOCK_INVENTORY.getValue(this.armorStand),
this.width - SCREEN_EDGE_PAD,
this.height - SCREEN_EDGE_PAD - FlagToggleWidget.WIDGET_HEIGHT));
this.showArmsToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer, ArmorStandFlag.SHOW_ARMS,
ArmorStandFlag.SHOW_ARMS.getValue(this.armorStand), this.width - GuiUtil.PADDING,
this.height - GuiUtil.PADDING - 2 * FlagToggleWidget.WIDGET_HEIGHT - (GuiUtil.PADDING / 2)
));
this.lockInventoryToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer, ArmorStandFlag.LOCK_INVENTORY,
ArmorStandFlag.LOCK_INVENTORY.getValue(this.armorStand), this.width - GuiUtil.PADDING,
this.height - GuiUtil.PADDING - FlagToggleWidget.WIDGET_HEIGHT
));
}

@Override
Expand All @@ -74,36 +73,19 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
protected void drawBackground(DrawContext drawContext, float delta, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);

drawContext.drawTexture(CUSTOM_TEXTURE,
this.x,
this.y,
0,
0,
BACKGROUND_WIDTH,
BACKGROUND_HEIGHT);
drawContext.drawTexture(CUSTOM_TEXTURE, this.x, this.y, 0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT);

ImmutableList<Pair<Slot, EquipmentSlot>> armorSlots = this.handler.getArmorSlots();
for (int index = 0; index < armorSlots.size(); index++) {
Slot slot = armorSlots.get(index).getFirst();
EquipmentSlot equipmentSlot = armorSlots.get(index).getSecond();
if (ArmorStandScreenHandler.isSlotDisabled(armorStand, equipmentSlot)) {
drawContext.fill(x + slot.x,
this.y + slot.y,
this.x + slot.x + 16,
y + slot.y + 16,
0x80000000);
drawContext.fill(x + slot.x, this.y + slot.y, this.x + slot.x + 16, y + slot.y + 16, 0x80000000);
}
}

InventoryScreen.drawEntity(drawContext,
this.x + 62,
this.y + 8,
this.x + 114,
this.y + 78,
30,
0.0625f,
this.mouseX,
this.mouseY,
this.armorStand);
InventoryScreen.drawEntity(drawContext, this.x + 62, this.y + 8, this.x + 114, this.y + 78, 30, 0.0625f,
this.mouseX, this.mouseY, this.armorStand
);
}
}
Loading

0 comments on commit 04deb8d

Please sign in to comment.