mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-29 21:02:59 +00:00
remap with yarrnforge
This commit is contained in:
@@ -1,371 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
@SuppressWarnings ({
|
||||
"MethodCallSideOnly",
|
||||
"LocalVariableDeclarationSideOnly",
|
||||
"VariableUseSideOnly"
|
||||
})
|
||||
public final class FixedWidthFontRenderer {
|
||||
private static final Matrix4f IDENTITY = AffineTransformation.identity().getMatrix();
|
||||
|
||||
private static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" );
|
||||
|
||||
public static final int FONT_HEIGHT = 9;
|
||||
public static final int FONT_WIDTH = 6;
|
||||
public static final float WIDTH = 256.0f;
|
||||
|
||||
public static final float BACKGROUND_START = (WIDTH - 6.0f) / WIDTH;
|
||||
public static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH;
|
||||
|
||||
public static final RenderLayer TYPE = Type.MAIN;
|
||||
|
||||
private FixedWidthFontRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
public static float toGreyscale( double[] rgb )
|
||||
{
|
||||
return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3);
|
||||
}
|
||||
|
||||
public static int getColour( char c, Colour def )
|
||||
{
|
||||
return 15 - Terminal.getColour(c, def );
|
||||
}
|
||||
|
||||
private static void drawQuad(Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, float r, float g, float b )
|
||||
{
|
||||
buffer.vertex( transform, x, y, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_START, BACKGROUND_START ).next();
|
||||
buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_START, BACKGROUND_END ).next();
|
||||
buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_END, BACKGROUND_START ).next();
|
||||
buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_END, BACKGROUND_START ).next();
|
||||
buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_START, BACKGROUND_END ).next();
|
||||
buffer.vertex( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).texture( BACKGROUND_END, BACKGROUND_END ).next();
|
||||
}
|
||||
|
||||
private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
|
||||
{
|
||||
double[] colour = palette.getColour( getColour( colourIndex, Colour.Black ) );
|
||||
float r, g, b;
|
||||
if( greyscale )
|
||||
{
|
||||
r = g = b = toGreyscale( colour );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (float) colour[0];
|
||||
g = (float) colour[1];
|
||||
b = (float) colour[2];
|
||||
}
|
||||
|
||||
drawQuad( transform, buffer, x, y, width, height, r, g, b );
|
||||
}
|
||||
|
||||
private static void drawBackground(
|
||||
Matrix4f transform, VertexConsumer renderer, float x, float y,
|
||||
TextBuffer backgroundColour, Palette palette, boolean greyscale,
|
||||
float leftMarginSize, float rightMarginSize, float height
|
||||
)
|
||||
{
|
||||
if( leftMarginSize > 0 )
|
||||
{
|
||||
drawQuad( transform, renderer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) );
|
||||
}
|
||||
|
||||
if( rightMarginSize > 0 )
|
||||
{
|
||||
drawQuad( transform, renderer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) );
|
||||
}
|
||||
|
||||
// Batch together runs of identical background cells.
|
||||
int blockStart = 0;
|
||||
char blockColour = '\0';
|
||||
for( int i = 0; i < backgroundColour.length(); i++ )
|
||||
{
|
||||
char colourIndex = backgroundColour.charAt( i );
|
||||
if( colourIndex == blockColour ) continue;
|
||||
|
||||
if( blockColour != '\0' )
|
||||
{
|
||||
drawQuad( transform, renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour );
|
||||
}
|
||||
|
||||
blockColour = colourIndex;
|
||||
blockStart = i;
|
||||
}
|
||||
|
||||
if( blockColour != '\0' )
|
||||
{
|
||||
drawQuad( transform, renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour );
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawString(
|
||||
Matrix4f transform, VertexConsumer renderer, float x, float y,
|
||||
TextBuffer text, TextBuffer textColour, TextBuffer backgroundColour,
|
||||
Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
if( backgroundColour != null )
|
||||
{
|
||||
drawBackground( transform, renderer, x, y, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT );
|
||||
}
|
||||
|
||||
for( int i = 0; i < text.length(); i++ )
|
||||
{
|
||||
double[] colour = palette.getColour( getColour( textColour.charAt( i ), Colour.Black ) );
|
||||
float r, g, b;
|
||||
if( greyscale )
|
||||
{
|
||||
r = g = b = toGreyscale( colour );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (float) colour[0];
|
||||
g = (float) colour[1];
|
||||
b = (float) colour[2];
|
||||
}
|
||||
|
||||
// Draw char
|
||||
int index = text.charAt( i );
|
||||
if( index > 255 ) index = '?';
|
||||
drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void drawString(
|
||||
float x, float y, TextBuffer text, TextBuffer textColour, TextBuffer backgroundColour,
|
||||
Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
bindFont();
|
||||
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||
drawString( IDENTITY, ((VertexConsumerProvider) renderer).getBuffer( TYPE ), x, y, text, textColour, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize );
|
||||
renderer.draw();
|
||||
}
|
||||
|
||||
public static void drawTerminalWithoutCursor(
|
||||
Matrix4f transform, VertexConsumer buffer, float x, float y,
|
||||
Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
Palette palette = terminal.getPalette();
|
||||
int height = terminal.getHeight();
|
||||
|
||||
// Top and bottom margins
|
||||
drawBackground(
|
||||
transform, buffer, x, y - topMarginSize,
|
||||
terminal.getBackgroundColourLine( 0 ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, topMarginSize
|
||||
);
|
||||
|
||||
drawBackground(
|
||||
transform, buffer, x, y + height * FONT_HEIGHT,
|
||||
terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, bottomMarginSize
|
||||
);
|
||||
|
||||
// The main text
|
||||
for( int i = 0; i < height; i++ )
|
||||
{
|
||||
drawString(
|
||||
transform, buffer, x, y + FixedWidthFontRenderer.FONT_HEIGHT * i,
|
||||
terminal.getLine( i ), terminal.getTextColourLine( i ), terminal.getBackgroundColourLine( i ),
|
||||
palette, greyscale, leftMarginSize, rightMarginSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCursor(
|
||||
Matrix4f transform, VertexConsumer buffer, float x, float y,
|
||||
Terminal terminal, boolean greyscale
|
||||
)
|
||||
{
|
||||
Palette palette = terminal.getPalette();
|
||||
int width = terminal.getWidth();
|
||||
int height = terminal.getHeight();
|
||||
|
||||
int cursorX = terminal.getCursorX();
|
||||
int cursorY = terminal.getCursorY();
|
||||
if(terminal.getCursorBlink() && cursorX >= 0 && cursorX < width && cursorY >= 0 && cursorY < height && FrameInfo.getGlobalCursorBlink() )
|
||||
{
|
||||
double[] colour = palette.getColour( 15 - terminal.getTextColour() );
|
||||
float r, g, b;
|
||||
if( greyscale )
|
||||
{
|
||||
r = g = b = toGreyscale( colour );
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (float) colour[0];
|
||||
g = (float) colour[1];
|
||||
b = (float) colour[2];
|
||||
}
|
||||
|
||||
drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b );
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTerminal(
|
||||
Matrix4f transform, VertexConsumer buffer, float x, float y,
|
||||
Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
drawCursor( transform, buffer, x, y, terminal, greyscale );
|
||||
}
|
||||
|
||||
public static void drawTerminal(
|
||||
Matrix4f transform, float x, float y, Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
bindFont();
|
||||
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||
VertexConsumer buffer = renderer.getBuffer( TYPE );
|
||||
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
renderer.draw( TYPE );
|
||||
}
|
||||
|
||||
public static void drawTerminal(
|
||||
float x, float y, Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
drawTerminal( IDENTITY, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( Matrix4f transform, VertexConsumerProvider renderer, float x, float y, float width, float height )
|
||||
{
|
||||
Colour colour = Colour.Black;
|
||||
drawQuad( transform, renderer.getBuffer( TYPE ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( Matrix4f transform, float x, float y, float width, float height )
|
||||
{
|
||||
bindFont();
|
||||
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||
drawEmptyTerminal( transform, renderer, x, y, width, height );
|
||||
renderer.draw();
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
||||
{
|
||||
drawEmptyTerminal( IDENTITY, x, y, width, height );
|
||||
}
|
||||
|
||||
public static void drawBlocker( Matrix4f transform, VertexConsumerProvider renderer, float x, float y, float width, float height )
|
||||
{
|
||||
Colour colour = Colour.Black;
|
||||
drawQuad( transform, renderer.getBuffer( Type.BLOCKER ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
|
||||
private static void bindFont()
|
||||
{
|
||||
MinecraftClient.getInstance().getTextureManager().bindTexture( FONT );
|
||||
RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||
}
|
||||
|
||||
private static void drawChar( Matrix4f transform, VertexConsumer buffer, float x, float y, int index, float r, float g, float b )
|
||||
{
|
||||
// Short circuit to avoid the common case - the texture should be blank here after all.
|
||||
if( index == '\0' || index == ' ' ) return;
|
||||
|
||||
int column = index % 16;
|
||||
int row = index / 16;
|
||||
|
||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||
|
||||
buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).texture( xStart / WIDTH, yStart / WIDTH ).next();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).next();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).next();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).next();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).next();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).texture( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).next();
|
||||
}
|
||||
|
||||
|
||||
private static void greyscaleify(double[] rgb) {
|
||||
Arrays.fill(rgb, (rgb[0] + rgb[1] + rgb[2]) / 3.0f);
|
||||
}
|
||||
|
||||
public int getStringWidth(String s) {
|
||||
if (s == null) {
|
||||
return 0;
|
||||
}
|
||||
return s.length() * FONT_WIDTH;
|
||||
}
|
||||
|
||||
private static final class Type extends RenderPhase
|
||||
{
|
||||
private static final int GL_MODE = GL11.GL_TRIANGLES;
|
||||
|
||||
private static final VertexFormat FORMAT = VertexFormats.POSITION_COLOR_TEXTURE;
|
||||
|
||||
static final RenderLayer MAIN = RenderLayer.of(
|
||||
"terminal_font", FORMAT, GL_MODE, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( new Texture(FONT, false, false ) ) // blur, minimap
|
||||
.alpha( ONE_TENTH_ALPHA )
|
||||
.lightmap( DISABLE_LIGHTMAP )
|
||||
.writeMaskState( COLOR_MASK )
|
||||
.build( false )
|
||||
);
|
||||
|
||||
static final RenderLayer BLOCKER = RenderLayer.of(
|
||||
"terminal_blocker", FORMAT, GL_MODE, 256,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( new Texture(FONT, false, false ) ) // blur, minimap
|
||||
.alpha( ONE_TENTH_ALPHA )
|
||||
.writeMaskState( DEPTH_MASK )
|
||||
.lightmap( DISABLE_LIGHTMAP )
|
||||
.build( false )
|
||||
);
|
||||
|
||||
private Type( String name, Runnable setup, Runnable destroy )
|
||||
{
|
||||
super( name, setup, destroy );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiComputer<T extends ScreenHandler> extends HandledScreen<T> {
|
||||
private static final MinecraftClient MINECRAFT = MinecraftClient.getInstance();
|
||||
public static final Identifier BACKGROUND_NORMAL = new Identifier(ComputerCraft.MOD_ID, "textures/gui/corners_normal.png");
|
||||
public static final Identifier BACKGROUND_ADVANCED = new Identifier(ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png");
|
||||
public static final Identifier BACKGROUND_COMMAND = new Identifier(ComputerCraft.MOD_ID, "textures/gui/corners_command.png");
|
||||
public static final Identifier BACKGROUND_COLOUR = new Identifier(ComputerCraft.MOD_ID, "textures/gui/corners_colour.png");
|
||||
|
||||
private final ComputerFamily m_family;
|
||||
private final ClientComputer m_computer;
|
||||
private final int m_termWidth;
|
||||
private final int m_termHeight;
|
||||
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
|
||||
public GuiComputer(T container, PlayerInventory player, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight) {
|
||||
super(container, player, new LiteralText(""));
|
||||
|
||||
this.m_family = family;
|
||||
this.m_computer = computer;
|
||||
this.m_termWidth = termWidth;
|
||||
this.m_termHeight = termHeight;
|
||||
this.terminal = null;
|
||||
}
|
||||
|
||||
public static GuiComputer<ContainerComputer> create(int id, TileComputer computer, PlayerInventory player) {
|
||||
return new GuiComputer<>(new ContainerComputer(id, computer),
|
||||
player,
|
||||
computer.getFamily(),
|
||||
computer.createClientComputer(),
|
||||
ComputerCraft.terminalWidth_computer,
|
||||
ComputerCraft.terminalHeight_computer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
MinecraftClient.getInstance().keyboard.setRepeatEvents(true);
|
||||
|
||||
int termPxWidth = this.m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = this.m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
this.backgroundWidth = termPxWidth + 4 + 24;
|
||||
this.backgroundHeight = termPxHeight + 4 + 24;
|
||||
|
||||
super.init();
|
||||
|
||||
this.terminal = new WidgetTerminal(MINECRAFT, () -> this.m_computer, this.m_termWidth, this.m_termHeight, 2, 2, 2, 2);
|
||||
this.terminalWrapper = new WidgetWrapper(this.terminal, 2 + 12 + this.x, 2 + 12 + this.y, termPxWidth, termPxHeight);
|
||||
|
||||
this.children.add(this.terminalWrapper);
|
||||
this.setFocused(this.terminalWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(stack, 0);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(MatrixStack stack, float partialTicks, int mouseX, int mouseY) {
|
||||
// Work out where to draw
|
||||
int startX = this.terminalWrapper.getX() - 2;
|
||||
int startY = this.terminalWrapper.getY() - 2;
|
||||
int endX = startX + this.terminalWrapper.getWidth() + 4;
|
||||
int endY = startY + this.terminalWrapper.getHeight() + 4;
|
||||
|
||||
// Draw terminal
|
||||
this.terminal.draw(this.terminalWrapper.getX(), this.terminalWrapper.getY());
|
||||
|
||||
// Draw a border around the terminal
|
||||
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
switch (this.m_family) {
|
||||
case Normal:
|
||||
default:
|
||||
MINECRAFT.getTextureManager()
|
||||
.bindTexture(BACKGROUND_NORMAL);
|
||||
break;
|
||||
case Advanced:
|
||||
MINECRAFT.getTextureManager()
|
||||
.bindTexture(BACKGROUND_ADVANCED);
|
||||
break;
|
||||
case Command:
|
||||
MINECRAFT.getTextureManager()
|
||||
.bindTexture(BACKGROUND_COMMAND);
|
||||
break;
|
||||
}
|
||||
|
||||
this.drawTexture(stack, startX - 12, startY - 12, 12, 28, 12, 12);
|
||||
this.drawTexture(stack, startX - 12, endY, 12, 40, 12, 12);
|
||||
this.drawTexture(stack, endX, startY - 12, 24, 28, 12, 12);
|
||||
this.drawTexture(stack, endX, endY, 24, 40, 12, 12);
|
||||
|
||||
this.drawTexture(stack, startX, startY - 12, 0, 0, endX - startX, 12);
|
||||
this.drawTexture(stack, startX, endY, 0, 12, endX - startX, 12);
|
||||
|
||||
this.drawTexture(stack, startX - 12, startY, 0, 28, 12, endY - startY);
|
||||
this.drawTexture(stack, endX, startY, 36, 28, 12, endY - startY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double x, double y, int button, double deltaX, double deltaY) {
|
||||
// Make sure drag events are propagated to children
|
||||
return (this.getFocused() != null && this.getFocused().mouseDragged(x, y, button, deltaX, deltaY)) || super.mouseDragged(x, y, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double x, double y, int button) {
|
||||
// Make sure release events are propagated to children
|
||||
return (this.getFocused() != null && this.getFocused().mouseReleased(x, y, button)) || super.mouseReleased(x, y, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scancode, int modifiers) {
|
||||
// When pressing tab, send it to the computer first
|
||||
return (key == GLFW.GLFW_KEY_TAB && this.getFocused() == this.terminalWrapper && this.terminalWrapper.keyPressed(key,
|
||||
scancode,
|
||||
modifiers)) || super.keyPressed(key,
|
||||
scancode,
|
||||
modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
super.removed();
|
||||
this.children.remove(this.terminal);
|
||||
this.terminal = null;
|
||||
MINECRAFT.keyboard.setRepeatEvents(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.terminal.update();
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
||||
import dan200.computercraft.shared.util.Config;
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
public final class GuiConfig {
|
||||
private GuiConfig() {}
|
||||
|
||||
@SuppressWarnings ({
|
||||
"LocalVariableDeclarationSideOnly",
|
||||
"MethodCallSideOnly"
|
||||
})
|
||||
public static Screen getScreen(Screen parentScreen) {
|
||||
Config config = Config.get();
|
||||
ConfigBuilder builder = ConfigBuilder.create()
|
||||
.setParentScreen(parentScreen)
|
||||
.setTitle(new TranslatableText("gui.computercraft.config.title"))
|
||||
.setSavingRunnable(() -> {
|
||||
Config.save();
|
||||
Config.sync();
|
||||
});
|
||||
|
||||
ConfigEntryBuilder entryBuilder = ConfigEntryBuilder.create();
|
||||
|
||||
builder.getOrCreateCategory(key("general"))
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("computer_space_limit"), config.general.computer_space_limit)
|
||||
.setSaveConsumer(v -> config.general.computer_space_limit = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.computer_space_limit)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("floppy_space_limit"), config.general.floppy_space_limit)
|
||||
.setSaveConsumer(v -> config.general.floppy_space_limit = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.floppy_space_limit)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("maximum_open_files"), config.general.maximum_open_files)
|
||||
.setSaveConsumer(v -> config.general.maximum_open_files = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.maximum_open_files)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("disable_lua51_features"), config.general.disable_lua51_features)
|
||||
.setSaveConsumer(v -> config.general.disable_lua51_features = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.disable_lua51_features)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startStrField(key("default_computer_settings"), config.general.default_computer_settings)
|
||||
.setSaveConsumer(v -> config.general.default_computer_settings = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.default_computer_settings)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("debug_enabled"), config.general.debug_enabled)
|
||||
.setSaveConsumer(v -> config.general.debug_enabled = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.debug_enabled)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("log_computer_errors"), config.general.log_computer_errors)
|
||||
.setSaveConsumer(v -> config.general.log_computer_errors = v)
|
||||
.setDefaultValue(Config.defaultConfig.general.log_computer_errors)
|
||||
.build());
|
||||
|
||||
builder.getOrCreateCategory(key("execution"))
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("execution.computer_threads"), config.execution.computer_threads)
|
||||
.setSaveConsumer(v -> config.execution.computer_threads = v)
|
||||
.setDefaultValue(Config.defaultConfig.execution.computer_threads)
|
||||
.setMin(1)
|
||||
.requireRestart()
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startLongField(key("execution.max_main_global_time"), config.execution.max_main_global_time)
|
||||
.setSaveConsumer(v -> config.execution.max_main_global_time = v)
|
||||
.setDefaultValue(Config.defaultConfig.execution.max_main_global_time)
|
||||
.setMin(1)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startLongField(key("execution.max_main_computer_time"), config.execution.max_main_computer_time)
|
||||
.setSaveConsumer(v -> config.execution.max_main_computer_time = v)
|
||||
.setDefaultValue(Config.defaultConfig.execution.max_main_computer_time)
|
||||
.setMin(1)
|
||||
.build());
|
||||
|
||||
builder.getOrCreateCategory(key("http"))
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("http.enabled"), config.http.enabled)
|
||||
.setSaveConsumer(v -> config.http.enabled = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.enabled)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("http.websocket_enabled"), config.http.websocket_enabled)
|
||||
.setSaveConsumer(v -> config.http.websocket_enabled = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.websocket_enabled)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startStrList(key("http.whitelist"), Arrays.asList(config.http.whitelist))
|
||||
.setSaveConsumer(v -> config.http.whitelist = v.toArray(new String[0]))
|
||||
.setDefaultValue(Arrays.asList(Config.defaultConfig.http.whitelist))
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startStrList(key("http.blacklist"), Arrays.asList(config.http.blacklist))
|
||||
.setSaveConsumer(v -> config.http.blacklist = v.toArray(new String[0]))
|
||||
.setDefaultValue(Arrays.asList(Config.defaultConfig.http.blacklist))
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("http.timeout"), config.http.timeout)
|
||||
.setSaveConsumer(v -> config.http.timeout = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.timeout)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("http.max_requests"), config.http.max_requests)
|
||||
.setSaveConsumer(v -> config.http.max_requests = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.max_requests)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startLongField(key("http.max_download"), config.http.max_download)
|
||||
.setSaveConsumer(v -> config.http.max_download = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.max_download)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startLongField(key("http.max_upload"), config.http.max_upload)
|
||||
.setSaveConsumer(v -> config.http.max_upload = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.max_upload)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("http.max_websockets"), config.http.max_websockets)
|
||||
.setSaveConsumer(v -> config.http.max_websockets = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.max_websockets)
|
||||
.setMin(1)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("http.max_websocket_message"), config.http.max_websocket_message)
|
||||
.setSaveConsumer(v -> config.http.max_websocket_message = v)
|
||||
.setDefaultValue(Config.defaultConfig.http.max_websocket_message)
|
||||
.setMin(0)
|
||||
.setMax(Websocket.MAX_MESSAGE_SIZE)
|
||||
.build());
|
||||
|
||||
builder.getOrCreateCategory(key("peripheral"))
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("peripheral.command_block_enabled"), config.peripheral.command_block_enabled)
|
||||
.setSaveConsumer(v -> config.peripheral.command_block_enabled = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.command_block_enabled)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("peripheral.modem_range"), config.peripheral.modem_range)
|
||||
.setSaveConsumer(v -> config.peripheral.modem_range = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.modem_range)
|
||||
.setMin(0)
|
||||
.setMax(Config.MODEM_MAX_RANGE)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("peripheral.modem_high_altitude_range"), config.peripheral.modem_high_altitude_range)
|
||||
.setSaveConsumer(v -> config.peripheral.modem_high_altitude_range = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.modem_high_altitude_range)
|
||||
.setMin(0)
|
||||
.setMax(Config.MODEM_MAX_RANGE)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("peripheral.modem_range_during_storm"), config.peripheral.modem_range_during_storm)
|
||||
.setSaveConsumer(v -> config.peripheral.modem_range_during_storm = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.modem_range_during_storm)
|
||||
.setMin(0)
|
||||
.setMax(Config.MODEM_MAX_RANGE)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("peripheral.modem_high_altitude_range_during_storm"),
|
||||
config.peripheral.modem_high_altitude_range_during_storm)
|
||||
.setSaveConsumer(v -> config.peripheral.modem_high_altitude_range_during_storm = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.modem_high_altitude_range_during_storm)
|
||||
.setMin(0)
|
||||
.setMax(Config.MODEM_MAX_RANGE)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("peripheral.max_notes_per_tick"), config.peripheral.max_notes_per_tick)
|
||||
.setSaveConsumer(v -> config.peripheral.max_notes_per_tick = v)
|
||||
.setDefaultValue(Config.defaultConfig.peripheral.max_notes_per_tick)
|
||||
.setMin(1)
|
||||
.build());
|
||||
|
||||
builder.getOrCreateCategory(key("turtle"))
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("turtle.need_fuel"), config.turtle.need_fuel)
|
||||
.setSaveConsumer(v -> config.turtle.need_fuel = v)
|
||||
.setDefaultValue(Config.defaultConfig.turtle.need_fuel)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("turtle.normal_fuel_limit"), config.turtle.normal_fuel_limit)
|
||||
.setSaveConsumer(v -> config.turtle.normal_fuel_limit = v)
|
||||
.setDefaultValue(Config.defaultConfig.turtle.normal_fuel_limit)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startIntField(key("turtle.advanced_fuel_limit"), config.turtle.advanced_fuel_limit)
|
||||
.setSaveConsumer(v -> config.turtle.advanced_fuel_limit = v)
|
||||
.setDefaultValue(Config.defaultConfig.turtle.advanced_fuel_limit)
|
||||
.setMin(0)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startBooleanToggle(key("turtle.obey_block_protection"), config.turtle.obey_block_protection)
|
||||
.setSaveConsumer(v -> config.turtle.obey_block_protection = v)
|
||||
.setDefaultValue(Config.defaultConfig.turtle.obey_block_protection)
|
||||
.build())
|
||||
|
||||
.addEntry(entryBuilder.startStrList(key("turtle.disabled_actions"), Arrays.asList(config.turtle.disabled_actions))
|
||||
.setSaveConsumer(v -> config.turtle.disabled_actions = v.toArray(new String[0]))
|
||||
.setDefaultValue(Arrays.asList(Config.defaultConfig.turtle.disabled_actions))
|
||||
.build());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static Text key(String name) {
|
||||
return new TranslatableText("gui.computercraft.config." + name);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiDiskDrive extends HandledScreen<ContainerDiskDrive> {
|
||||
private static final Identifier BACKGROUND = new Identifier("computercraft", "textures/gui/disk_drive.png");
|
||||
|
||||
public GuiDiskDrive(ContainerDiskDrive container, PlayerInventory inventory) {
|
||||
super(container, inventory, ComputerCraft.Blocks.diskDrive.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground(int par1, int par2) {
|
||||
String title = this.getTitle().asFormattedString();
|
||||
font.draw(title, (this.backgroundWidth - font.getWidth(title)) / 2.0f, 6, 0x404040);
|
||||
font.draw(I18n.translate("container.inventory"), 8, (this.backgroundHeight - 96) + 2, 0x404040);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
minecraft.getTextureManager()
|
||||
.bindTextureInner(BACKGROUND);
|
||||
blit(this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground();
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GuiPocketComputer extends GuiComputer<ContainerPocketComputer> {
|
||||
public GuiPocketComputer(ContainerPocketComputer container, PlayerInventory player) {
|
||||
super(container,
|
||||
player,
|
||||
getFamily(container.getStack()),
|
||||
ItemPocketComputer.createClientComputer(container.getStack()),
|
||||
ComputerCraft.terminalWidth_pocketComputer,
|
||||
ComputerCraft.terminalHeight_pocketComputer);
|
||||
}
|
||||
|
||||
private static ComputerFamily getFamily(ItemStack stack) {
|
||||
Item item = stack.getItem();
|
||||
return item instanceof ItemPocketComputer ? ((ItemPocketComputer) item).getFamily() : ComputerFamily.Normal;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiPrinter extends HandledScreen<ContainerPrinter> {
|
||||
private static final Identifier BACKGROUND = new Identifier("computercraft", "textures/gui/printer.png");
|
||||
|
||||
public GuiPrinter(ContainerPrinter container, PlayerInventory player) {
|
||||
super(container, player, ComputerCraft.Blocks.printer.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground(int mouseX, int mouseY) {
|
||||
String title = this.getTitle().asFormattedString();
|
||||
font.draw(title, (this.backgroundWidth - font.getWidth(title)) / 2.0f, 6, 0x404040);
|
||||
font.draw(I18n.translate("container.inventory"), 8, this.backgroundHeight - 96 + 2, 0x404040);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(float f, int i, int j) {
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
minecraft.getTextureManager()
|
||||
.bindTextureInner(BACKGROUND);
|
||||
blit(this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight);
|
||||
|
||||
if (this.handler.isPrinting()) {
|
||||
blit(this.x + 34, this.y + 21, 176, 0, 25, 45);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground();
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.X_TEXT_MARGIN;
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.Y_SIZE;
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.Y_TEXT_MARGIN;
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.drawBorder;
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.drawText;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
public class GuiPrintout extends HandledScreen<ContainerHeldItem> {
|
||||
private final boolean m_book;
|
||||
private final int m_pages;
|
||||
private final TextBuffer[] m_text;
|
||||
private final TextBuffer[] m_colours;
|
||||
private int m_page;
|
||||
|
||||
public GuiPrintout(ContainerHeldItem container, PlayerInventory player) {
|
||||
super(container,
|
||||
player,
|
||||
container.getStack()
|
||||
.getName());
|
||||
|
||||
this.backgroundHeight = Y_SIZE;
|
||||
|
||||
String[] text = ItemPrintout.getText(container.getStack());
|
||||
this.m_text = new TextBuffer[text.length];
|
||||
for (int i = 0; i < this.m_text.length; i++) {
|
||||
this.m_text[i] = new TextBuffer(text[i]);
|
||||
}
|
||||
|
||||
String[] colours = ItemPrintout.getColours(container.getStack());
|
||||
this.m_colours = new TextBuffer[colours.length];
|
||||
for (int i = 0; i < this.m_colours.length; i++) {
|
||||
this.m_colours[i] = new TextBuffer(colours[i]);
|
||||
}
|
||||
|
||||
this.m_page = 0;
|
||||
this.m_pages = Math.max(this.m_text.length / ItemPrintout.LINES_PER_PAGE, 1);
|
||||
this.m_book = ((ItemPrintout) container.getStack()
|
||||
.getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scancode, int modifiers) {
|
||||
if (super.keyPressed(key, scancode, modifiers)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == GLFW.GLFW_KEY_RIGHT) {
|
||||
if (this.m_page < this.m_pages - 1) {
|
||||
this.m_page++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == GLFW.GLFW_KEY_LEFT) {
|
||||
if (this.m_page > 0) {
|
||||
this.m_page--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double delta) {
|
||||
if (super.mouseScrolled(x, y, delta)) {
|
||||
return true;
|
||||
}
|
||||
if (delta < 0) {
|
||||
// Scroll up goes to the next page
|
||||
if (this.m_page < this.m_pages - 1) {
|
||||
this.m_page++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (delta > 0) {
|
||||
// Scroll down goes to the previous page
|
||||
if (this.m_page > 0) {
|
||||
this.m_page--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(MatrixStack stack, float partialTicks, int mouseX, int mouseY) {
|
||||
// Draw the printout
|
||||
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
GlStateManager.enableDepthTest();
|
||||
|
||||
drawBorder(this.x, this.y, getZOffset(), this.m_page, this.m_pages, this.m_book);
|
||||
drawText(this.x + X_TEXT_MARGIN, this.y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * this.m_page, this.m_text, this.m_colours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||
// We must take the background further back in order to not overlap with our printed pages.
|
||||
setZOffset(getZOffset() - 1);
|
||||
renderBackground(stack);
|
||||
setZOffset(getZOffset() + 1);
|
||||
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiTurtle extends HandledScreen<ContainerTurtle> {
|
||||
private static final Identifier BACKGROUND_NORMAL = new Identifier("computercraft", "textures/gui/turtle_normal.png");
|
||||
private static final Identifier BACKGROUND_ADVANCED = new Identifier("computercraft", "textures/gui/turtle_advanced.png");
|
||||
private final ComputerFamily m_family;
|
||||
private final ClientComputer m_computer;
|
||||
private ContainerTurtle m_container;
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
public GuiTurtle(TileTurtle turtle, ContainerTurtle container, PlayerInventory player) {
|
||||
super(container, player, turtle.getDisplayName());
|
||||
|
||||
this.m_container = container;
|
||||
this.m_family = turtle.getFamily();
|
||||
this.m_computer = turtle.getClientComputer();
|
||||
|
||||
this.backgroundWidth = 254;
|
||||
this.backgroundHeight = 217;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
client.keyboard.setRepeatEvents(true);
|
||||
|
||||
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
this.terminal = new WidgetTerminal(client, () -> this.m_computer, ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle, 2, 2, 2, 2);
|
||||
this.terminalWrapper = new WidgetWrapper(this.terminal, 2 + 8 + this.x, 2 + 8 + this.y, termPxWidth, termPxHeight);
|
||||
|
||||
this.children.add(this.terminalWrapper);
|
||||
this.setFocused(this.terminalWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double x, double y, int button, double deltaX, double deltaY) {
|
||||
return (this.getFocused() != null && this.getFocused().mouseDragged(x, y, button, deltaX, deltaY)) || super.mouseDragged(x, y, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double x, double y, int button) {
|
||||
return (this.getFocused() != null && this.getFocused().mouseReleased(x, y, button)) || super.mouseReleased(x, y, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scancode, int modifiers) {
|
||||
return (key == GLFW.GLFW_KEY_TAB && this.getFocused() == this.terminalWrapper && this.terminalWrapper.keyPressed(key,
|
||||
scancode,
|
||||
modifiers)) || super.keyPressed(key,
|
||||
scancode,
|
||||
modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed() {
|
||||
super.removed();
|
||||
this.children.remove(this.terminal);
|
||||
this.terminal = null;
|
||||
client.keyboard.setRepeatEvents(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.terminal.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(MatrixStack stack, float partialTicks, int mouseX, int mouseY) {
|
||||
// Draw term
|
||||
boolean advanced = this.m_family == ComputerFamily.Advanced;
|
||||
this.terminal.draw(this.terminalWrapper.getX(), this.terminalWrapper.getY());
|
||||
|
||||
// Draw border/inventory
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
client.getTextureManager()
|
||||
.bindTextureInner(advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL);
|
||||
drawTexture(stack, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight);
|
||||
|
||||
this.drawSelectionSlot(stack, advanced);
|
||||
}
|
||||
|
||||
private void drawSelectionSlot(MatrixStack stack, boolean advanced) {
|
||||
// Draw selection slot
|
||||
int slot = this.m_container.getSelectedSlot();
|
||||
if (slot >= 0) {
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
client.getTextureManager()
|
||||
.bindTextureInner(advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL);
|
||||
drawTexture(stack, this.x + this.m_container.m_turtleInvStartX - 2 + slotX * 18, this.y + this.m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground(stack);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
this.drawMouseoverTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class WidgetTerminal implements Element {
|
||||
private static final float TERMINATE_TIME = 0.5f;
|
||||
|
||||
private final MinecraftClient minecraft;
|
||||
|
||||
private final Supplier<ClientComputer> computer;
|
||||
private final int termWidth;
|
||||
private final int termHeight;
|
||||
private final int leftMargin;
|
||||
private final int rightMargin;
|
||||
private final int topMargin;
|
||||
private final int bottomMargin;
|
||||
private final BitSet keysDown = new BitSet(256);
|
||||
private boolean focused;
|
||||
private float terminateTimer = -1;
|
||||
private float rebootTimer = -1;
|
||||
private float shutdownTimer = -1;
|
||||
private int lastMouseButton = -1;
|
||||
private int lastMouseX = -1;
|
||||
private int lastMouseY = -1;
|
||||
|
||||
public WidgetTerminal(MinecraftClient minecraft, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin,
|
||||
int topMargin, int bottomMargin) {
|
||||
this.minecraft = minecraft;
|
||||
this.computer = computer;
|
||||
this.termWidth = termWidth;
|
||||
this.termHeight = termHeight;
|
||||
this.leftMargin = leftMargin;
|
||||
this.rightMargin = rightMargin;
|
||||
this.topMargin = topMargin;
|
||||
this.bottomMargin = bottomMargin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer == null || !computer.isColour() || button < 0 || button > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if (term != null) {
|
||||
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||
charX = Math.min(Math.max(charX, 0), term.getWidth() - 1);
|
||||
charY = Math.min(Math.max(charY, 0), term.getHeight() - 1);
|
||||
|
||||
computer.mouseClick(button + 1, charX + 1, charY + 1);
|
||||
|
||||
this.lastMouseButton = button;
|
||||
this.lastMouseX = charX;
|
||||
this.lastMouseY = charY;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer == null || !computer.isColour() || button < 0 || button > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if (term != null) {
|
||||
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||
charX = Math.min(Math.max(charX, 0), term.getWidth() - 1);
|
||||
charY = Math.min(Math.max(charY, 0), term.getHeight() - 1);
|
||||
|
||||
if (this.lastMouseButton == button) {
|
||||
computer.mouseUp(this.lastMouseButton + 1, charX + 1, charY + 1);
|
||||
this.lastMouseButton = -1;
|
||||
}
|
||||
|
||||
this.lastMouseX = charX;
|
||||
this.lastMouseY = charY;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double v2, double v3) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer == null || !computer.isColour() || button < 0 || button > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if (term != null) {
|
||||
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||
charX = Math.min(Math.max(charX, 0), term.getWidth() - 1);
|
||||
charY = Math.min(Math.max(charY, 0), term.getHeight() - 1);
|
||||
|
||||
computer.mouseDrag(button + 1, charX + 1, charY + 1);
|
||||
|
||||
this.lastMouseX = charX;
|
||||
this.lastMouseY = charY;
|
||||
this.lastMouseButton = button;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer == null || !computer.isColour() || delta == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Terminal term = computer.getTerminal();
|
||||
if (term != null) {
|
||||
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||
charX = Math.min(Math.max(charX, 0), term.getWidth() - 1);
|
||||
charY = Math.min(Math.max(charY, 0), term.getHeight() - 1);
|
||||
|
||||
computer.mouseScroll(delta < 0 ? 1 : -1, charX + 1, charY + 1);
|
||||
|
||||
this.lastMouseX = charX;
|
||||
this.lastMouseY = charY;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scancode, int modifiers) {
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE) {
|
||||
return false;
|
||||
}
|
||||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0) {
|
||||
switch (key) {
|
||||
case GLFW.GLFW_KEY_T:
|
||||
if (this.terminateTimer < 0) {
|
||||
this.terminateTimer = 0;
|
||||
}
|
||||
return true;
|
||||
case GLFW.GLFW_KEY_S:
|
||||
if (this.shutdownTimer < 0) {
|
||||
this.shutdownTimer = 0;
|
||||
}
|
||||
return true;
|
||||
case GLFW.GLFW_KEY_R:
|
||||
if (this.rebootTimer < 0) {
|
||||
this.rebootTimer = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
case GLFW.GLFW_KEY_V:
|
||||
// Ctrl+V for paste
|
||||
String clipboard = this.minecraft.keyboard.getClipboard();
|
||||
if (clipboard != null) {
|
||||
// Clip to the first occurrence of \r or \n
|
||||
int newLineIndex1 = clipboard.indexOf("\r");
|
||||
int newLineIndex2 = clipboard.indexOf("\n");
|
||||
if (newLineIndex1 >= 0 && newLineIndex2 >= 0) {
|
||||
clipboard = clipboard.substring(0, Math.min(newLineIndex1, newLineIndex2));
|
||||
} else if (newLineIndex1 >= 0) {
|
||||
clipboard = clipboard.substring(0, newLineIndex1);
|
||||
} else if (newLineIndex2 >= 0) {
|
||||
clipboard = clipboard.substring(0, newLineIndex2);
|
||||
}
|
||||
|
||||
// Filter the string
|
||||
clipboard = SharedConstants.stripInvalidChars(clipboard);
|
||||
if (!clipboard.isEmpty()) {
|
||||
// Clip to 512 characters and queue the event
|
||||
if (clipboard.length() > 512) {
|
||||
clipboard = clipboard.substring(0, 512);
|
||||
}
|
||||
this.queueEvent("paste", clipboard);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (key >= 0 && this.terminateTimer < 0 && this.rebootTimer < 0 && this.shutdownTimer < 0) {
|
||||
// Queue the "key" event and add to the down set
|
||||
boolean repeat = this.keysDown.get(key);
|
||||
this.keysDown.set(key);
|
||||
IComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.keyDown(key, repeat);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int key, int scancode, int modifiers) {
|
||||
// Queue the "key_up" event and remove from the down set
|
||||
if (key >= 0 && this.keysDown.get(key)) {
|
||||
this.keysDown.set(key, false);
|
||||
IComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.keyUp(key);
|
||||
}
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case GLFW.GLFW_KEY_T:
|
||||
this.terminateTimer = -1;
|
||||
break;
|
||||
case GLFW.GLFW_KEY_R:
|
||||
this.rebootTimer = -1;
|
||||
break;
|
||||
case GLFW.GLFW_KEY_S:
|
||||
this.shutdownTimer = -1;
|
||||
break;
|
||||
case GLFW.GLFW_KEY_LEFT_CONTROL:
|
||||
case GLFW.GLFW_KEY_RIGHT_CONTROL:
|
||||
this.terminateTimer = this.rebootTimer = this.shutdownTimer = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char ch, int modifiers) {
|
||||
if (ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255) // printable chars in byte range
|
||||
{
|
||||
// Queue the "char" event
|
||||
this.queueEvent("char", Character.toString(ch));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeFocus(boolean reverse) {
|
||||
if (this.focused) {
|
||||
// When blurring, we should make all keys go up
|
||||
for (int key = 0; key < this.keysDown.size(); key++) {
|
||||
if (this.keysDown.get(key)) {
|
||||
this.queueEvent("key_up", key);
|
||||
}
|
||||
}
|
||||
this.keysDown.clear();
|
||||
|
||||
// When blurring, we should make the last mouse button go up
|
||||
if (this.lastMouseButton > 0) {
|
||||
IComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.mouseUp(this.lastMouseButton + 1, this.lastMouseX + 1, this.lastMouseY + 1);
|
||||
}
|
||||
this.lastMouseButton = -1;
|
||||
}
|
||||
|
||||
this.shutdownTimer = this.terminateTimer = this.rebootTimer = -1;
|
||||
}
|
||||
|
||||
this.focused = !this.focused;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void queueEvent(String event, Object... args) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.queueEvent(event, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (this.terminateTimer >= 0 && this.terminateTimer < TERMINATE_TIME && (this.terminateTimer += 0.05f) > TERMINATE_TIME) {
|
||||
this.queueEvent("terminate");
|
||||
}
|
||||
|
||||
if (this.shutdownTimer >= 0 && this.shutdownTimer < TERMINATE_TIME && (this.shutdownTimer += 0.05f) > TERMINATE_TIME) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.rebootTimer >= 0 && this.rebootTimer < TERMINATE_TIME && (this.rebootTimer += 0.05f) > TERMINATE_TIME) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.reboot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void queueEvent(String event) {
|
||||
ClientComputer computer = this.computer.get();
|
||||
if (computer != null) {
|
||||
computer.queueEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(int originX, int originY) {
|
||||
synchronized (this.computer) {
|
||||
// Draw the screen contents
|
||||
ClientComputer computer = this.computer.get();
|
||||
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
||||
if (terminal != null) {
|
||||
// Draw the terminal
|
||||
boolean greyscale = !computer.isColour();
|
||||
Palette palette = terminal.getPalette();
|
||||
|
||||
// Get the data from the terminal first
|
||||
// Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
|
||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||
boolean tblink = terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
|
||||
int tw = terminal.getWidth();
|
||||
int th = terminal.getHeight();
|
||||
int tx = terminal.getCursorX();
|
||||
int ty = terminal.getCursorY();
|
||||
|
||||
// Draw margins
|
||||
TextBuffer emptyLine = new TextBuffer(' ', tw);
|
||||
if (this.topMargin > 0) {
|
||||
fontRenderer.drawString(emptyLine,
|
||||
originX,
|
||||
originY - this.topMargin,
|
||||
terminal.getTextColourLine(0),
|
||||
terminal.getBackgroundColourLine(0), this.leftMargin, this.rightMargin,
|
||||
greyscale,
|
||||
palette);
|
||||
}
|
||||
|
||||
if (this.bottomMargin > 0) {
|
||||
fontRenderer.drawString(emptyLine,
|
||||
originX,
|
||||
originY + this.bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
||||
terminal.getTextColourLine(th - 1),
|
||||
terminal.getBackgroundColourLine(th - 1), this.leftMargin, this.rightMargin,
|
||||
greyscale,
|
||||
palette);
|
||||
}
|
||||
|
||||
// Draw lines
|
||||
int y = originY;
|
||||
for (int line = 0; line < th; line++) {
|
||||
TextBuffer text = terminal.getLine(line);
|
||||
TextBuffer colour = terminal.getTextColourLine(line);
|
||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine(line);
|
||||
fontRenderer.drawString(text, originX, y, colour, backgroundColour, this.leftMargin, this.rightMargin, greyscale, palette);
|
||||
y += FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
if (tblink && tx >= 0 && ty >= 0 && tx < tw && ty < th) {
|
||||
TextBuffer cursor = new TextBuffer('_', 1);
|
||||
TextBuffer cursorColour = new TextBuffer("0123456789abcdef".charAt(terminal.getTextColour()), 1);
|
||||
|
||||
fontRenderer.drawString(cursor,
|
||||
originX + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
||||
originY + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
||||
cursorColour,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
greyscale,
|
||||
palette);
|
||||
}
|
||||
} else {
|
||||
// Draw a black background
|
||||
Colour black = Colour.Black;
|
||||
GlStateManager.color4f(black.getR(), black.getG(), black.getB(), 1.0f);
|
||||
try {
|
||||
int x = originX - this.leftMargin;
|
||||
int y = originY - this.rightMargin;
|
||||
int width = this.termWidth * FixedWidthFontRenderer.FONT_WIDTH + this.leftMargin + this.rightMargin;
|
||||
int height = this.termHeight * FixedWidthFontRenderer.FONT_HEIGHT + this.topMargin + this.bottomMargin;
|
||||
|
||||
this.minecraft.getTextureManager()
|
||||
.bindTextureInner(BACKGROUND);
|
||||
|
||||
Tessellator tesslector = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tesslector.getBuffer();
|
||||
buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE);
|
||||
buffer.vertex(x, y + height, 0)
|
||||
.texture(0 / 256.0f, height / 256.0f)
|
||||
.next();
|
||||
buffer.vertex(x + width, y + height, 0)
|
||||
.texture(width / 256.0f, height / 256.f)
|
||||
.next();
|
||||
buffer.vertex(x + width, y, 0)
|
||||
.texture(width / 256.0f, 0 / 256.0f)
|
||||
.next();
|
||||
buffer.vertex(x, y, 0)
|
||||
.texture(0 / 256.0f, 0 / 256.0f)
|
||||
.next();
|
||||
tesslector.draw();
|
||||
} finally {
|
||||
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import net.minecraft.client.gui.Element;
|
||||
|
||||
public class WidgetWrapper implements Element {
|
||||
private final Element listener;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public WidgetWrapper(Element listener, int x, int y, int width, int height) {
|
||||
this.listener = listener;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(double x, double y) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
if (dx >= 0 && dx < this.width && dy >= 0 && dy < this.height) {
|
||||
this.listener.mouseMoved(dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < this.width && dy >= 0 && dy < this.height && this.listener.mouseClicked(dx, dy, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double x, double y, int button) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < this.width && dy >= 0 && dy < this.height && this.listener.mouseReleased(dx, dy, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double x, double y, int button, double deltaX, double deltaY) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < this.width && dy >= 0 && dy < this.height && this.listener.mouseDragged(dx, dy, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double delta) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < this.width && dy >= 0 && dy < this.height && this.listener.mouseScrolled(dx, dy, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scancode, int modifiers) {
|
||||
return this.listener.keyPressed(key, scancode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int key, int scancode, int modifiers) {
|
||||
return this.listener.keyReleased(key, scancode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int modifiers) {
|
||||
return this.listener.charTyped(character, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeFocus(boolean reverse) {
|
||||
return this.listener.changeFocus(reverse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(double x, double y) {
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < this.width && dy >= 0 && dy < this.height;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user