Partially implemented gui for cpu.
parent
18f75240dd
commit
b90fa0e343
@ -1,17 +1,78 @@
|
|||||||
package net.brokenmoon.redcontrol.screen;
|
package net.brokenmoon.redcontrol.screen;
|
||||||
|
|
||||||
import net.brokenmoon.redcontrol.RedControl;
|
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.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.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class CpuScreen extends Screen {
|
public class CpuScreen extends Screen {
|
||||||
public CpuScreen(Text title) {
|
|
||||||
|
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);
|
super(title);
|
||||||
|
this.pos = blockPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ButtonWidget startButton;
|
||||||
|
public ButtonWidget stopButton;
|
||||||
|
public ButtonWidget resetButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
RedControl.LOGGER.info("Created CPU screen");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 997 B |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 393 B |
Loading…
Reference in New Issue