diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 12335f9f5..d84d7d456 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -8,6 +8,7 @@ package dan200.computercraft.client.gui; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Colour; +import dan200.computercraft.shared.util.Palette; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; @@ -31,28 +32,37 @@ public class FixedWidthFontRenderer m_textureManager = textureManager; } - private void drawChar( VertexBuffer renderer, double x, double y, int index, int color ) + private void drawChar( VertexBuffer renderer, double x, double y, int index, int color, Palette p ) { int column = index % 16; int row = index / 16; - Colour colour = Colour.values()[ 15 - color ]; - renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + + float[] colour = p.getColour( 15 - color ); + float r = colour[0]; + float g = colour[1]; + float b = colour[2]; + + renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); + renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); + renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); + renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); } - private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width ) + private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width, Palette p ) { - Colour colour = Colour.values()[ 15 - color ]; - renderer.pos( x, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + float[] colour = p.getColour( 15 - color ); + float r = colour[0]; + float g = colour[1]; + float b = 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(); } private boolean isGreyScale( int colour ) @@ -60,7 +70,7 @@ public class FixedWidthFontRenderer return (colour == 0 || colour == 15 || colour == 7 || colour == 8); } - public void drawStringBackgroundPart( int x, int y, TextBuffer backgroundColour, double leftMarginSize, double rightMarginSize, boolean greyScale ) + public void drawStringBackgroundPart( int x, int y, TextBuffer backgroundColour, double leftMarginSize, double rightMarginSize, boolean greyScale, Palette p ) { // Draw the quads Tessellator tessellator = Tessellator.getInstance(); @@ -73,7 +83,7 @@ public class FixedWidthFontRenderer { colour1 = 15; } - drawQuad( renderer, x - leftMarginSize, y, colour1, leftMarginSize ); + drawQuad( renderer, x - leftMarginSize, y, colour1, leftMarginSize, p ); } if( rightMarginSize > 0.0 ) { @@ -82,7 +92,7 @@ public class FixedWidthFontRenderer { colour2 = 15; } - drawQuad( renderer, x + backgroundColour.length() * FONT_WIDTH, y, colour2, rightMarginSize ); + drawQuad( renderer, x + backgroundColour.length() * FONT_WIDTH, y, colour2, rightMarginSize, p ); } for( int i = 0; i < backgroundColour.length(); i++ ) { @@ -91,14 +101,14 @@ public class FixedWidthFontRenderer { colour = 15; } - drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH ); + drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p ); } GlStateManager.disableTexture2D(); tessellator.draw(); GlStateManager.enableTexture2D(); } - public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale ) + public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p ) { // Draw the quads Tessellator tessellator = Tessellator.getInstance(); @@ -119,12 +129,12 @@ public class FixedWidthFontRenderer { index = (int)'?'; } - drawChar( renderer, x + i * FONT_WIDTH, y, index, colour ); + drawChar( renderer, x + i * FONT_WIDTH, y, index, colour, p ); } tessellator.draw(); } - public void drawString( TextBuffer s, int x, int y, TextBuffer textColour, TextBuffer backgroundColour, double leftMarginSize, double rightMarginSize, boolean greyScale ) + public void drawString( TextBuffer s, int x, int y, TextBuffer textColour, TextBuffer backgroundColour, double leftMarginSize, double rightMarginSize, boolean greyScale, Palette p ) { // Draw background if( backgroundColour != null ) @@ -133,7 +143,7 @@ public class FixedWidthFontRenderer m_textureManager.bindTexture( background ); // Draw the quads - drawStringBackgroundPart( x, y, backgroundColour, leftMarginSize, rightMarginSize, greyScale ); + drawStringBackgroundPart( x, y, backgroundColour, leftMarginSize, rightMarginSize, greyScale, p ); } // Draw text @@ -143,7 +153,7 @@ public class FixedWidthFontRenderer m_textureManager.bindTexture( font ); // Draw the quads - drawStringTextPart( x, y, s, textColour, greyScale ); + drawStringTextPart( x, y, s, textColour, greyScale, p ); } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java index 75c8f97d0..209e459ab 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.media.inventory.ContainerHeldItem; import dan200.computercraft.shared.media.items.ItemPrintout; +import dan200.computercraft.shared.util.Palette; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ResourceLocation; @@ -204,7 +205,7 @@ public class GuiPrintout extends GuiContainer int lineIdx = ItemPrintout.LINES_PER_PAGE * m_page + line; if( lineIdx >= 0 && lineIdx < m_text.length ) { - fontRenderer.drawString( m_text[lineIdx], x, y, m_colours[lineIdx], null, 0, 0, false ); + fontRenderer.drawString( m_text[lineIdx], x, y, m_colours[lineIdx], null, 0, 0, false, new Palette() ); } y = y + FixedWidthFontRenderer.FONT_HEIGHT; } diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java index 7325c9944..397ae2c61 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -13,6 +13,7 @@ import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IComputerContainer; import dan200.computercraft.shared.util.Colour; +import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; @@ -377,6 +378,8 @@ public class WidgetTerminal extends Widget boolean greyscale = !computer.isColour(); synchronized( terminal ) { + 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)ComputerCraft.getFixedWidthFontRenderer(); @@ -393,11 +396,11 @@ public class WidgetTerminal extends Widget TextBuffer emptyLine = new TextBuffer( ' ', tw ); if( m_topMargin > 0 ) { - fontRenderer.drawString( emptyLine, x, startY, terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), m_leftMargin, m_rightMargin, greyscale ); + fontRenderer.drawString( emptyLine, x, startY, terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), m_leftMargin, m_rightMargin, greyscale, palette ); } if( m_bottomMargin > 0 ) { - fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + ( th - 1 ) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale ); + fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + ( th - 1 ) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette ); } // Draw lines @@ -406,7 +409,7 @@ public class WidgetTerminal extends Widget TextBuffer text = terminal.getLine(line); TextBuffer colour = terminal.getTextColourLine( line ); TextBuffer backgroundColour = terminal.getBackgroundColourLine( line ); - fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale ); + fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale, palette ); y += FixedWidthFontRenderer.FONT_HEIGHT; } @@ -421,7 +424,8 @@ public class WidgetTerminal extends Widget startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty, cursorColour, null, 0, 0, - greyscale + greyscale, + palette ); } } diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 9b0129a46..a1ea0e87f 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -14,6 +14,7 @@ import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.DirectionUtil; +import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; @@ -48,6 +49,8 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer= 0 && i < colours.length ) + { + colours[ i ] = new PaletteColour( r, g, b ); + } + } + + public void setColour(int i, Colour colour) + { + setColour( i, colour.getR(), colour.getG(), colour.getB() ); + } + + public float[] getColour( int i ) + { + if( i >= 0 && i < colours.length ) + { + PaletteColour c = colours[ i ]; + return new float[] { c.m_r, c.m_g, c.m_b }; + } + return null; + } + + public void resetColours() + { + for(int i = 0; i < Colour.values().length; ++i) + { + Colour c = Colour.values()[ i ]; + colours[i] = new PaletteColour( c.getR(), c.getG(), c.getB() ); + } + } +}