mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-29 21:02:59 +00:00
Initial update to Fabric
This commit is contained in:
@@ -6,23 +6,23 @@
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class FixedWidthFontRenderer
|
||||
{
|
||||
private static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
|
||||
public static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
|
||||
private static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" );
|
||||
public static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/term_background.png" );
|
||||
|
||||
public static final int FONT_HEIGHT = 9;
|
||||
public static final int FONT_WIDTH = 6;
|
||||
@@ -39,7 +39,7 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
private FixedWidthFontRenderer()
|
||||
{
|
||||
m_textureManager = Minecraft.getInstance().getTextureManager();
|
||||
m_textureManager = MinecraftClient.getInstance().getTextureManager();
|
||||
}
|
||||
|
||||
private static void greyscaleify( double[] rgb )
|
||||
@@ -64,12 +64,12 @@ public final class FixedWidthFontRenderer
|
||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||
|
||||
renderer.pos( x, y, 0.0 ).tex( xStart / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.vertex( x, y, 0.0 ).texture( xStart / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).texture( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + FONT_WIDTH, y, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + FONT_WIDTH, y, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).texture( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||
}
|
||||
|
||||
private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
|
||||
@@ -83,12 +83,12 @@ public final class FixedWidthFontRenderer
|
||||
float g = (float) colour[1];
|
||||
float b = (float) colour[2];
|
||||
|
||||
renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + width, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + width, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.vertex( x, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + width, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + width, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
renderer.vertex( x + width, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||
}
|
||||
|
||||
private boolean isGreyScale( int colour )
|
||||
@@ -100,8 +100,8 @@ public final class FixedWidthFontRenderer
|
||||
{
|
||||
// Draw the quads
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder renderer = tessellator.getBuffer();
|
||||
renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR );
|
||||
BufferBuilder renderer = tessellator.getBufferBuilder();
|
||||
renderer.begin( GL11.GL_TRIANGLES, VertexFormats.POSITION_COLOR );
|
||||
if( leftMarginSize > 0.0 )
|
||||
{
|
||||
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
|
||||
@@ -129,17 +129,17 @@ public final class FixedWidthFontRenderer
|
||||
}
|
||||
drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale );
|
||||
}
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableTexture();
|
||||
tessellator.draw();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableTexture();
|
||||
}
|
||||
|
||||
public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p )
|
||||
{
|
||||
// Draw the quads
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder renderer = tessellator.getBuffer();
|
||||
renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR );
|
||||
BufferBuilder renderer = tessellator.getBufferBuilder();
|
||||
renderer.begin( GL11.GL_TRIANGLES, VertexFormats.POSITION_UV_COLOR );
|
||||
for( int i = 0; i < s.length(); i++ )
|
||||
{
|
||||
// Switch colour
|
||||
@@ -195,6 +195,6 @@ public final class FixedWidthFontRenderer
|
||||
public void bindFont()
|
||||
{
|
||||
m_textureManager.bindTexture( FONT );
|
||||
GlStateManager.texParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||
GlStateManager.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
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;
|
||||
@@ -13,16 +14,17 @@ 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 net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.gui.ContainerScreen;
|
||||
import net.minecraft.container.Container;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.StringTextComponent;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiComputer extends GuiContainer
|
||||
public class GuiComputer<T extends Container> extends ContainerScreen<T>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/corners_normal.png" );
|
||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/corners_advanced.png" );
|
||||
private static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( "computercraft", "textures/gui/corners_command.png" );
|
||||
private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/corners_normal.png" );
|
||||
private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/corners_advanced.png" );
|
||||
private static final Identifier BACKGROUND_COMMAND = new Identifier( "computercraft", "textures/gui/corners_command.png" );
|
||||
|
||||
private final ComputerFamily m_family;
|
||||
private final ClientComputer m_computer;
|
||||
@@ -32,9 +34,11 @@ public class GuiComputer extends GuiContainer
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
||||
|
||||
public GuiComputer( T container, PlayerInventory player, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
||||
{
|
||||
super( container );
|
||||
super( container, player, new StringTextComponent( "" ) );
|
||||
|
||||
m_family = family;
|
||||
m_computer = computer;
|
||||
m_termWidth = termWidth;
|
||||
@@ -42,10 +46,10 @@ public class GuiComputer extends GuiContainer
|
||||
terminal = null;
|
||||
}
|
||||
|
||||
public GuiComputer( TileComputer computer )
|
||||
public static GuiComputer<ContainerComputer> create( int id, TileComputer computer, PlayerInventory player )
|
||||
{
|
||||
this(
|
||||
new ContainerComputer( computer ),
|
||||
return new GuiComputer<>(
|
||||
new ContainerComputer( id, computer ), player,
|
||||
computer.getFamily(),
|
||||
computer.createClientComputer(),
|
||||
ComputerCraft.terminalWidth_computer,
|
||||
@@ -54,32 +58,32 @@ public class GuiComputer extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initGui()
|
||||
protected void init()
|
||||
{
|
||||
mc.keyboardListener.enableRepeatEvents( true );
|
||||
minecraft.keyboard.enableRepeatEvents( true );
|
||||
|
||||
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
xSize = termPxWidth + 4 + 24;
|
||||
ySize = termPxHeight + 4 + 24;
|
||||
containerWidth = termPxWidth + 4 + 24;
|
||||
containerHeight = termPxHeight + 4 + 24;
|
||||
|
||||
super.initGui();
|
||||
super.init();
|
||||
|
||||
terminal = new WidgetTerminal( mc, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
|
||||
terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + left, 2 + 12 + top, termPxWidth, termPxHeight );
|
||||
|
||||
children.add( terminalWrapper );
|
||||
setFocused( terminalWrapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
public void removed()
|
||||
{
|
||||
super.onGuiClosed();
|
||||
super.removed();
|
||||
children.remove( terminal );
|
||||
terminal = null;
|
||||
mc.keyboardListener.enableRepeatEvents( false );
|
||||
minecraft.keyboard.enableRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +94,7 @@ public class GuiComputer extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Work out where to draw
|
||||
int startX = terminalWrapper.getX() - 2;
|
||||
@@ -107,34 +111,34 @@ public class GuiComputer extends GuiContainer
|
||||
{
|
||||
case Normal:
|
||||
default:
|
||||
mc.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
||||
break;
|
||||
case Advanced:
|
||||
mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
||||
break;
|
||||
case Command:
|
||||
mc.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
||||
break;
|
||||
}
|
||||
|
||||
drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
|
||||
drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 16 );
|
||||
drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
|
||||
drawTexturedModalRect( endX, endY, 24, 40, 12, 16 );
|
||||
blit( startX - 12, startY - 12, 12, 28, 12, 12 );
|
||||
blit( startX - 12, endY, 12, 40, 12, 16 );
|
||||
blit( endX, startY - 12, 24, 28, 12, 12 );
|
||||
blit( endX, endY, 24, 40, 12, 16 );
|
||||
|
||||
drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
|
||||
drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 16 );
|
||||
blit( startX, startY - 12, 0, 0, endX - startX, 12 );
|
||||
blit( startX, endY, 0, 12, endX - startX, 16 );
|
||||
|
||||
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||
drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
|
||||
blit( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||
blit( endX, startY, 36, 28, 12, endY - startY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
renderBackground( 0 );
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
drawMouseoverTooltip( mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,45 +6,44 @@
|
||||
|
||||
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.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.gui.ContainerScreen;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiDiskDrive extends GuiContainer
|
||||
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
||||
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/disk_drive.png" );
|
||||
|
||||
private final ContainerDiskDrive m_container;
|
||||
|
||||
public GuiDiskDrive( ContainerDiskDrive container )
|
||||
public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory inventory )
|
||||
{
|
||||
super( container );
|
||||
m_container = container;
|
||||
super( container, inventory, ComputerCraft.Blocks.diskDrive.getTextComponent() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||
protected void drawForeground( int par1, int par2 )
|
||||
{
|
||||
String title = m_container.getDiskDrive().getDisplayName().getString();
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
||||
String title = getTitle().getFormattedText();
|
||||
font.draw( title, (containerWidth - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( I18n.translate( "container.inventory" ), 8, (containerHeight - 96) + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
drawMouseoverTooltip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,16 @@ 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
|
||||
public class GuiPocketComputer extends GuiComputer<ContainerPocketComputer>
|
||||
{
|
||||
public GuiPocketComputer( ContainerPocketComputer container )
|
||||
public GuiPocketComputer( ContainerPocketComputer container, PlayerInventory player )
|
||||
{
|
||||
super(
|
||||
container,
|
||||
container, player,
|
||||
getFamily( container.getStack() ),
|
||||
ItemPocketComputer.createClientComputer( container.getStack() ),
|
||||
ComputerCraft.terminalWidth_pocketComputer,
|
||||
|
||||
@@ -6,47 +6,46 @@
|
||||
|
||||
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.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.gui.ContainerScreen;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiPrinter extends GuiContainer
|
||||
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/printer.png" );
|
||||
|
||||
private final ContainerPrinter container;
|
||||
|
||||
public GuiPrinter( ContainerPrinter container )
|
||||
public GuiPrinter( ContainerPrinter container, PlayerInventory player )
|
||||
{
|
||||
super( container );
|
||||
this.container = container;
|
||||
super( container, player, ComputerCraft.Blocks.printer.getTextComponent() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||
protected void drawForeground( int mouseX, int mouseY )
|
||||
{
|
||||
String title = container.getPrinter().getDisplayName().getString();
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
||||
String title = getTitle().getFormattedText();
|
||||
font.draw( title, (containerWidth - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( I18n.translate( "container.inventory" ), 8, containerHeight - 96 + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawBackground( float f, int i, int j )
|
||||
{
|
||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||
|
||||
if( container.isPrinting() ) drawTexturedModalRect( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
|
||||
if( container.isPrinting() ) blit( left + 34, top + 21, 176, 0, 25, 45 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
drawMouseoverTooltip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
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.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.gui.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
|
||||
public class GuiPrintout extends GuiContainer
|
||||
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
{
|
||||
private final boolean m_book;
|
||||
private final int m_pages;
|
||||
@@ -23,11 +24,11 @@ public class GuiPrintout extends GuiContainer
|
||||
private final TextBuffer[] m_colours;
|
||||
private int m_page;
|
||||
|
||||
public GuiPrintout( ContainerHeldItem container )
|
||||
public GuiPrintout( ContainerHeldItem container, PlayerInventory player )
|
||||
{
|
||||
super( container );
|
||||
super( container, player, container.getStack().getDisplayName() );
|
||||
|
||||
ySize = Y_SIZE;
|
||||
containerHeight = Y_SIZE;
|
||||
|
||||
String[] text = ItemPrintout.getText( container.getStack() );
|
||||
m_text = new TextBuffer[text.length];
|
||||
@@ -63,9 +64,9 @@ public class GuiPrintout extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled( double delta )
|
||||
public boolean mouseScrolled( double x, double y, double delta )
|
||||
{
|
||||
if( super.mouseScrolled( delta ) ) return true;
|
||||
if( super.mouseScrolled( x, y, delta ) ) return true;
|
||||
if( delta < 0 )
|
||||
{
|
||||
// Scroll up goes to the next page
|
||||
@@ -84,25 +85,25 @@ public class GuiPrintout extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw the printout
|
||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
GlStateManager.enableDepthTest();
|
||||
|
||||
drawBorder( guiLeft, guiTop, zLevel, m_page, m_pages, m_book );
|
||||
drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
|
||||
drawBorder( left, top, blitOffset, m_page, m_pages, m_book );
|
||||
drawText( left + X_TEXT_MARGIN, top + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
// We must take the background further back in order to not overlap with our printed pages.
|
||||
zLevel--;
|
||||
drawDefaultBackground();
|
||||
zLevel++;
|
||||
blitOffset--;
|
||||
renderBackground();
|
||||
blitOffset++;
|
||||
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
drawMouseoverTooltip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
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;
|
||||
@@ -13,14 +14,14 @@ 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.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.client.gui.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class GuiTurtle extends GuiContainer
|
||||
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" );
|
||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
|
||||
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 ContainerTurtle m_container;
|
||||
|
||||
@@ -30,45 +31,46 @@ public class GuiTurtle extends GuiContainer
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
||||
public GuiTurtle( TileTurtle turtle, ContainerTurtle container, PlayerInventory player )
|
||||
{
|
||||
super( container );
|
||||
super( container, player, turtle.getDisplayName() );
|
||||
|
||||
m_container = container;
|
||||
m_family = turtle.getFamily();
|
||||
m_computer = turtle.getClientComputer();
|
||||
|
||||
xSize = 254;
|
||||
ySize = 217;
|
||||
containerWidth = 254;
|
||||
containerHeight = 217;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initGui()
|
||||
protected void init()
|
||||
{
|
||||
super.initGui();
|
||||
mc.keyboardListener.enableRepeatEvents( true );
|
||||
super.init();
|
||||
minecraft.keyboard.enableRepeatEvents( true );
|
||||
|
||||
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
terminal = new WidgetTerminal(
|
||||
mc, () -> m_computer,
|
||||
minecraft, () -> m_computer,
|
||||
ComputerCraft.terminalWidth_turtle,
|
||||
ComputerCraft.terminalHeight_turtle,
|
||||
2, 2, 2, 2
|
||||
);
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight );
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + left, 2 + 8 + top, termPxWidth, termPxHeight );
|
||||
|
||||
children.add( terminalWrapper );
|
||||
setFocused( terminalWrapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
public void removed()
|
||||
{
|
||||
super.removed();
|
||||
children.remove( terminal );
|
||||
terminal = null;
|
||||
mc.keyboardListener.enableRepeatEvents( false );
|
||||
minecraft.keyboard.enableRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,13 +89,13 @@ public class GuiTurtle extends GuiContainer
|
||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
drawTexturedModalRect( guiLeft + m_container.m_turtleInvStartX - 2 + slotX * 18, guiTop + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
blit( left + m_container.m_turtleInvStartX - 2 + slotX * 18, top + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw term
|
||||
boolean advanced = m_family == ComputerFamily.Advanced;
|
||||
@@ -101,8 +103,8 @@ public class GuiTurtle extends GuiContainer
|
||||
|
||||
// Draw border/inventory
|
||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||
|
||||
drawSelectionSlot( advanced );
|
||||
}
|
||||
@@ -110,8 +112,8 @@ public class GuiTurtle extends GuiContainer
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
drawMouseoverTooltip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
@@ -14,13 +15,12 @@ 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.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.SharedConstants;
|
||||
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;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -29,11 +29,11 @@ import java.util.function.Supplier;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
||||
|
||||
public class WidgetTerminal implements IGuiEventListener
|
||||
public class WidgetTerminal implements Element
|
||||
{
|
||||
private static final float TERMINATE_TIME = 0.5f;
|
||||
|
||||
private final Minecraft client;
|
||||
private final MinecraftClient minecraft;
|
||||
|
||||
private final Supplier<ClientComputer> computer;
|
||||
private final int termWidth;
|
||||
@@ -54,9 +54,9 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
|
||||
private final BitSet keysDown = new BitSet( 256 );
|
||||
|
||||
public WidgetTerminal( Minecraft client, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
||||
public WidgetTerminal( MinecraftClient minecraft, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
||||
{
|
||||
this.client = client;
|
||||
this.minecraft = minecraft;
|
||||
this.computer = computer;
|
||||
this.termWidth = termWidth;
|
||||
this.termHeight = termHeight;
|
||||
@@ -98,7 +98,7 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
|
||||
case GLFW.GLFW_KEY_V:
|
||||
// Ctrl+V for paste
|
||||
String clipboard = client.keyboardListener.getClipboardString();
|
||||
String clipboard = minecraft.keyboard.getClipboard();
|
||||
if( clipboard != null )
|
||||
{
|
||||
// Clip to the first occurrence of \r or \n
|
||||
@@ -118,7 +118,7 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
}
|
||||
|
||||
// Filter the string
|
||||
clipboard = SharedConstants.filterAllowedCharacters( clipboard );
|
||||
clipboard = SharedConstants.stripInvalidChars( clipboard );
|
||||
if( !clipboard.isEmpty() )
|
||||
{
|
||||
// Clip to 512 characters and queue the event
|
||||
@@ -250,14 +250,23 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled( double delta )
|
||||
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
|
||||
{
|
||||
ClientComputer computer = this.computer.get();
|
||||
if( computer == null || !computer.isColour() ) return false;
|
||||
if( computer == null || !computer.isColour() || delta == 0 ) return false;
|
||||
|
||||
if( lastMouseX >= 0 && lastMouseY >= 0 && delta != 0 )
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
{
|
||||
queueEvent( "mouse_scroll", delta < 0 ? 1 : -1, lastMouseX + 1, lastMouseY + 1 );
|
||||
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 );
|
||||
|
||||
lastMouseX = charX;
|
||||
lastMouseY = charY;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -284,7 +293,7 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusChanged( boolean focused )
|
||||
public void onFocusChanged( boolean noClue, boolean focused )
|
||||
{
|
||||
if( !focused )
|
||||
{
|
||||
@@ -384,15 +393,15 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
|
||||
int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
|
||||
|
||||
client.getTextureManager().bindTexture( BACKGROUND );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||
|
||||
Tessellator tesslector = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tesslector.getBuffer();
|
||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
||||
buffer.pos( x, y + height, 0 ).tex( 0 / 256.0, height / 256.0 ).endVertex();
|
||||
buffer.pos( x + width, y + height, 0 ).tex( width / 256.0, height / 256.0 ).endVertex();
|
||||
buffer.pos( x + width, y, 0 ).tex( width / 256.0, 0 / 256.0 ).endVertex();
|
||||
buffer.pos( x, y, 0 ).tex( 0 / 256.0, 0 / 256.0 ).endVertex();
|
||||
BufferBuilder buffer = tesslector.getBufferBuilder();
|
||||
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_UV );
|
||||
buffer.vertex( x, y + height, 0 ).texture( 0 / 256.0, height / 256.0 ).next();
|
||||
buffer.vertex( x + width, y + height, 0 ).texture( width / 256.0, height / 256.0 ).next();
|
||||
buffer.vertex( x + width, y, 0 ).texture( width / 256.0, 0 / 256.0 ).next();
|
||||
buffer.vertex( x, y, 0 ).texture( 0 / 256.0, 0 / 256.0 ).next();
|
||||
tesslector.draw();
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
import net.minecraft.client.gui.Element;
|
||||
|
||||
public class WidgetWrapper implements IGuiEventListener
|
||||
public class WidgetWrapper implements Element
|
||||
{
|
||||
private final IGuiEventListener listener;
|
||||
private final Element listener;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public WidgetWrapper( IGuiEventListener listener, int x, int y, int width, int height )
|
||||
public WidgetWrapper( Element listener, int x, int y, int width, int height )
|
||||
{
|
||||
this.listener = listener;
|
||||
this.x = x;
|
||||
@@ -26,15 +26,16 @@ public class WidgetWrapper implements IGuiEventListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusChanged( boolean b )
|
||||
public void mouseMoved( double x, double y )
|
||||
{
|
||||
listener.focusChanged( b );
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
if( dx >= 0 && dx < width && dy >= 0 && dy < height ) listener.mouseMoved( dx, dy );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFocus()
|
||||
public void onFocusChanged( boolean a, boolean b )
|
||||
{
|
||||
return listener.canFocus();
|
||||
listener.onFocusChanged( a, b );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,9 +60,10 @@ public class WidgetWrapper implements IGuiEventListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled( double delta )
|
||||
public boolean mouseScrolled( double x, double y, double delta )
|
||||
{
|
||||
return listener.mouseScrolled( delta );
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,4 +103,11 @@ public class WidgetWrapper implements IGuiEventListener
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver( double x, double y )
|
||||
{
|
||||
double dx = x - this.x, dy = y - this.y;
|
||||
return dx >= 0 && dx < width && dy >= 0 && dy < height;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user