mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 13:13:00 +00:00 
			
		
		
		
	Rewrite printout rendering
- The current page is always centred when rendering in a GUI, with the turned pages moving from the sides. - Pages are no longer evenly distributed from the centre - they follow an exponential decay curve, so ones further out are closer together (a bit like an open book). - Render pages and books in item frames/in-hand (rather than just single pages). This currently does some very dirty things with z values in order to prevent z-fighting. It would be nice to avoid that, though turning off writing to the z buffer causes issues with the bounding box.
This commit is contained in:
		| @@ -6,24 +6,19 @@ | ||||
|  | ||||
| package dan200.computercraft.client.gui; | ||||
|  | ||||
| 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; | ||||
| import org.lwjgl.input.Mouse; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| import static dan200.computercraft.client.render.PrintoutRenderer.*; | ||||
|  | ||||
| public class GuiPrintout extends GuiContainer | ||||
| { | ||||
|     public static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printout.png" ); | ||||
|     public static final int X_SIZE = 172; | ||||
|     public static final int Y_SIZE = 209; | ||||
|      | ||||
|     private final boolean m_book; | ||||
|     private final int m_pages; | ||||
|     private final TextBuffer[] m_text; | ||||
| @@ -33,23 +28,18 @@ public class GuiPrintout extends GuiContainer | ||||
|     public GuiPrintout( ContainerHeldItem container ) | ||||
|     { | ||||
|         super( container ); | ||||
|         m_book = (ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book); | ||||
|  | ||||
|         String[] text = ItemPrintout.getText( container.getStack() ); | ||||
|         m_text = new TextBuffer[ text.length ]; | ||||
|         for( int i=0; i<m_text.length; ++i ) | ||||
|         { | ||||
|             m_text[i] = new TextBuffer( text[i] ); | ||||
|         } | ||||
|         for( int i = 0; i < m_text.length; ++i ) m_text[ i ] = new TextBuffer( text[ i ] ); | ||||
|  | ||||
|         String[] colours = ItemPrintout.getColours( container.getStack() ); | ||||
|         m_colours = new TextBuffer[ colours.length ]; | ||||
|         for( int i=0; i<m_colours.length; ++i ) | ||||
|         { | ||||
|             m_colours[i] = new TextBuffer( colours[i] ); | ||||
|         } | ||||
|         for( int i = 0; i < m_colours.length; ++i ) m_colours[ i ] = new TextBuffer( colours[ i ] ); | ||||
|  | ||||
|         m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 ); | ||||
|         m_page = 0; | ||||
|         m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 ); | ||||
|         m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -77,25 +67,19 @@ public class GuiPrintout extends GuiContainer | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void keyTyped(char c, int k) throws IOException | ||||
|     protected void keyTyped( char c, int k ) throws IOException | ||||
|     { | ||||
|         super.keyTyped( c, k ); | ||||
|  | ||||
|         if( k == 205 ) | ||||
|         { | ||||
|             // Right | ||||
|             if( m_page < m_pages - 1 ) | ||||
|             { | ||||
|                 m_page = m_page + 1; | ||||
|             } | ||||
|             if( m_page < m_pages - 1 ) m_page++; | ||||
|         } | ||||
|         else if( k == 203 ) | ||||
|         { | ||||
|              // Left | ||||
|             if( m_page > 0 ) | ||||
|             { | ||||
|                 m_page = m_page - 1; | ||||
|             } | ||||
|             // Left | ||||
|             if( m_page > 0 ) m_page--; | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -105,21 +89,15 @@ public class GuiPrintout extends GuiContainer | ||||
|         super.handleMouseInput(); | ||||
|  | ||||
|         int mouseWheelChange = Mouse.getEventDWheel(); | ||||
|         if (mouseWheelChange < 0) | ||||
|         if( mouseWheelChange < 0 ) | ||||
|         { | ||||
|             // Up | ||||
|             if( m_page < m_pages - 1 ) | ||||
|             { | ||||
|                 m_page = m_page + 1; | ||||
|             } | ||||
|             if( m_page < m_pages - 1 ) m_page++; | ||||
|         } | ||||
|         else if (mouseWheelChange > 0)  | ||||
|         else if( mouseWheelChange > 0 ) | ||||
|         { | ||||
|             // Down | ||||
|             if( m_page > 0 ) | ||||
|             { | ||||
|                 m_page = m_page - 1; | ||||
|             } | ||||
|             if( m_page > 0 ) m_page--; | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -134,78 +112,20 @@ public class GuiPrintout extends GuiContainer | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void drawScreen(int mouseX, int mouseY, float f) | ||||
|     public void drawScreen( int mouseX, int mouseY, float f ) | ||||
|     { | ||||
|         // Draw background | ||||
|         zLevel = zLevel - 1; | ||||
|         drawDefaultBackground(); | ||||
|          | ||||
|         zLevel = zLevel + 1; | ||||
|  | ||||
|         // Draw the printout | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|         this.mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|          | ||||
|         int startY = (height - Y_SIZE) / 2; | ||||
|         //int startX = (width - X_SIZE) / 2 - (m_page * 8); | ||||
|         int startX = (width - (X_SIZE + (m_pages - 1)*8)) / 2; | ||||
|          | ||||
|         if( m_book ) | ||||
|         { | ||||
|             // Border | ||||
|             drawTexturedModalRect( startX - 8, startY - 8, X_SIZE + 48, 0, 12, Y_SIZE + 24); | ||||
|             drawTexturedModalRect( startX + X_SIZE + (m_pages - 1)*8 - 4, startY - 8, X_SIZE + 48 + 12, 0, 12, Y_SIZE + 24); | ||||
|              | ||||
|             drawTexturedModalRect( startX, startY - 8, 0, Y_SIZE, X_SIZE, 12); | ||||
|             drawTexturedModalRect( startX, startY + Y_SIZE - 4, 0, Y_SIZE + 12, X_SIZE, 12); | ||||
|             for( int n=1; n<m_pages; ++n ) | ||||
|             { | ||||
|                 drawTexturedModalRect( startX + X_SIZE + (n-1)*8, startY - 8, 0, Y_SIZE, 8, 12); | ||||
|                 drawTexturedModalRect( startX + X_SIZE + (n-1)*8, startY + Y_SIZE - 4, 0, Y_SIZE + 12, 8, 12); | ||||
|             } | ||||
|         } | ||||
|              | ||||
|         // Left half | ||||
|         if( m_page == 0 ) | ||||
|         {             | ||||
|             drawTexturedModalRect( startX, startY, 24, 0, X_SIZE / 2, Y_SIZE ); | ||||
|             drawTexturedModalRect( startX, startY, 0, 0, 12, Y_SIZE ); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             drawTexturedModalRect( startX, startY, 0, 0, 12, Y_SIZE ); | ||||
|             for( int n=1; n<m_page; ++n ) | ||||
|             { | ||||
|                 drawTexturedModalRect( startX + n*8, startY, 12, 0, 12, Y_SIZE );                 | ||||
|             } | ||||
|             drawTexturedModalRect( startX + m_page*8, startY, 24, 0, X_SIZE / 2, Y_SIZE ); | ||||
|         } | ||||
|          | ||||
|         // Right half | ||||
|         if( m_page == (m_pages - 1) ) | ||||
|         { | ||||
|             drawTexturedModalRect( startX + m_page*8 + X_SIZE /2, startY, 24 + X_SIZE / 2, 0, X_SIZE / 2, Y_SIZE ); | ||||
|             drawTexturedModalRect( startX + m_page*8 + (X_SIZE - 12), startY, 24 + X_SIZE + 12, 0, 12, Y_SIZE ); | ||||
|         } | ||||
|         else  | ||||
|         { | ||||
|             drawTexturedModalRect( startX + (m_pages - 1)*8 + (X_SIZE - 12), startY, 24 + X_SIZE + 12, 0, 12, Y_SIZE ); | ||||
|             for( int n=m_pages-2; n>=m_page; --n ) | ||||
|             { | ||||
|                 drawTexturedModalRect( startX + n*8 + (X_SIZE - 12), startY, 24 + X_SIZE, 0, 12, Y_SIZE ); | ||||
|             } | ||||
|             drawTexturedModalRect( startX + m_page*8 + X_SIZE /2, startY, 24 + X_SIZE / 2, 0, X_SIZE / 2, Y_SIZE ); | ||||
|         } | ||||
|  | ||||
|         // Draw the text | ||||
|         FixedWidthFontRenderer fontRenderer = (FixedWidthFontRenderer)ComputerCraft.getFixedWidthFontRenderer(); | ||||
|         int x = startX + m_page * 8 + 13; | ||||
|         int y = startY + 11; | ||||
|         for( int line=0; line<ItemPrintout.LINES_PER_PAGE; ++line ) | ||||
|         { | ||||
|             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, Palette.DEFAULT ); | ||||
|             } | ||||
|             y = y + FixedWidthFontRenderer.FONT_HEIGHT; | ||||
|         } | ||||
|         int startY = (height - Y_SIZE) / 2; | ||||
|         int startX = (width - X_SIZE) / 2; | ||||
|  | ||||
|         drawBorder( startX, startY, zLevel, m_page, m_pages, m_book ); | ||||
|         drawText( startX + X_TEXT_MARGIN, startY + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev