You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.1 KiB
Java
84 lines
3.1 KiB
Java
package net.brokenmoon.redcontrol.screen;
|
|
|
|
import net.brokenmoon.redcontrol.RedControl;
|
|
import net.brokenmoon.redcontrol.RedControlNetworking;
|
|
import net.brokenmoon.redcontrol.blockentities.CpuEntity;
|
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
|
import net.minecraft.client.gui.DrawContext;
|
|
import net.minecraft.client.gui.screen.Screen;
|
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
|
import net.minecraft.network.PacketByteBuf;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
public class CpuScreen extends Screen {
|
|
|
|
private static final Identifier cpuTexture = new Identifier("redcontrol", "gui/cpu.png");
|
|
private static final Identifier poweredButton = new Identifier("redcontrol", "gui/lit_button.png");
|
|
|
|
BlockPos pos;
|
|
CpuEntity cpu;
|
|
|
|
public CpuScreen(Text title, BlockPos blockPos) {
|
|
super(title);
|
|
this.pos = blockPos;
|
|
}
|
|
|
|
public ButtonWidget startButton;
|
|
public ButtonWidget stopButton;
|
|
public ButtonWidget resetButton;
|
|
|
|
@Override
|
|
protected void init() {
|
|
super.init();
|
|
RedControl.LOGGER.info("Created CPU screen");
|
|
cpu = (CpuEntity) client.world.getBlockEntity(pos);
|
|
|
|
startButton = ButtonWidget.builder(Text.literal("Start"), button -> {
|
|
PacketByteBuf byteBuf = PacketByteBufs.create();
|
|
byteBuf.writeBlockPos(pos);
|
|
ClientPlayNetworking.send(RedControlNetworking.CPU_START,byteBuf);
|
|
}).dimensions(width / 2 + 105, 20, 200, 20).build();
|
|
|
|
stopButton = ButtonWidget.builder(Text.literal("Stop"), button -> {
|
|
PacketByteBuf byteBuf = PacketByteBufs.create();
|
|
byteBuf.writeBlockPos(pos);
|
|
ClientPlayNetworking.send(RedControlNetworking.CPU_STOP,byteBuf);
|
|
}).dimensions(width / 2 + 105, 50, 200, 20).build();
|
|
|
|
resetButton = ButtonWidget.builder(Text.literal("Reset"), button -> {
|
|
PacketByteBuf byteBuf = PacketByteBufs.create();
|
|
byteBuf.writeBlockPos(pos);
|
|
ClientPlayNetworking.send(RedControlNetworking.CPU_RESET,byteBuf);
|
|
}).dimensions(width / 2 + 105, 80, 200, 20).build();
|
|
|
|
addDrawableChild(startButton);
|
|
addDrawableChild(stopButton);
|
|
addDrawableChild(resetButton);
|
|
}
|
|
|
|
@Override
|
|
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
super.render(context, mouseX, mouseY, delta);
|
|
int buttonPos = 7;
|
|
if(cpu.isRunning){
|
|
buttonPos = 0;
|
|
} else if(cpu.isResetting || cpu.isReset){
|
|
buttonPos = 14;
|
|
}
|
|
int x = (width - 176) / 2;
|
|
int y = (height - 166) / 2;
|
|
context.drawTexture(cpuTexture,x,y,0,0,176,166);
|
|
context.drawTexture(poweredButton, x + 27, y + 6 + buttonPos, 0, 0, 4, 4);
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldPause() {
|
|
return false;
|
|
}
|
|
}
|