1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-05 01:26:20 +00:00

Add term.setColour/term.getColour

This commit is contained in:
Lignum 2017-05-05 15:52:21 +02:00
parent 936a531cd5
commit 56c9dec687
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
3 changed files with 106 additions and 33 deletions

View File

@ -29,7 +29,7 @@ public class WidgetTerminal extends Widget
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/termBackground.png" ); private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/termBackground.png" );
private static float TERMINATE_TIME = 0.5f; private static float TERMINATE_TIME = 0.5f;
private IComputerContainer m_computer; private final IComputerContainer m_computer;
private float m_terminateTimer; private float m_terminateTimer;
private float m_rebootTimer; private float m_rebootTimer;
@ -369,6 +369,8 @@ public class WidgetTerminal extends Widget
int startX = xOrigin + getXPosition(); int startX = xOrigin + getXPosition();
int startY = yOrigin + getYPosition(); int startY = yOrigin + getYPosition();
synchronized( m_computer )
{
// Draw the screen contents // Draw the screen contents
IComputer computer = m_computer.getComputer(); IComputer computer = m_computer.getComputer();
Terminal terminal = ( computer != null ) ? computer.getTerminal() : null; Terminal terminal = ( computer != null ) ? computer.getTerminal() : null;
@ -376,8 +378,7 @@ public class WidgetTerminal extends Widget
{ {
// Draw the terminal // Draw the terminal
boolean greyscale = !computer.isColour(); boolean greyscale = !computer.isColour();
synchronized( terminal )
{
Palette palette = terminal.getPalette(); Palette palette = terminal.getPalette();
// Get the data from the terminal first // Get the data from the terminal first
@ -428,9 +429,7 @@ public class WidgetTerminal extends Widget
palette palette
); );
} }
} } else
}
else
{ {
// Draw a black background // Draw a black background
mc.getTextureManager().bindTexture( background ); mc.getTextureManager().bindTexture( background );
@ -439,13 +438,13 @@ public class WidgetTerminal extends Widget
try try
{ {
drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() ); drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
} } finally
finally
{ {
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
} }
} }
} }
}
@Override @Override
public boolean suppressKeyPress( char c, int k ) public boolean suppressKeyPress( char c, int k )

View File

@ -10,11 +10,12 @@ import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.computer.IComputerEnvironment; import dan200.computercraft.core.computer.IComputerEnvironment;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import org.apache.commons.lang3.ArrayUtils;
public class TermAPI implements ILuaAPI public class TermAPI implements ILuaAPI
{ {
private Terminal m_terminal; private final Terminal m_terminal;
private IComputerEnvironment m_environment; private final IComputerEnvironment m_environment;
public TermAPI( IAPIEnvironment _environment ) public TermAPI( IAPIEnvironment _environment )
{ {
@ -67,13 +68,19 @@ public class TermAPI implements ILuaAPI
"getTextColor", "getTextColor",
"getBackgroundColour", "getBackgroundColour",
"getBackgroundColor", "getBackgroundColor",
"blit" "blit",
"setColour",
"setColor",
"getColour",
"getColor",
"resetColour",
"resetColor"
}; };
} }
public static int parseColour( Object[] args, boolean _enableColours ) throws LuaException public static int parseColour( Object[] args, boolean _enableColours ) throws LuaException
{ {
if( args.length != 1 || args[0] == null || !(args[0] instanceof Double) ) if( args.length < 1 || args[0] == null || !(args[0] instanceof Double) )
{ {
throw new LuaException( "Expected number" ); throw new LuaException( "Expected number" );
} }
@ -160,7 +167,7 @@ public class TermAPI implements ILuaAPI
{ {
throw new LuaException( "Expected boolean" ); throw new LuaException( "Expected boolean" );
} }
boolean b = ((Boolean)args[0]).booleanValue(); boolean b = (Boolean) args[ 0 ];
synchronized( m_terminal ) synchronized( m_terminal )
{ {
m_terminal.setCursorBlink( b ); m_terminal.setCursorBlink( b );
@ -270,6 +277,55 @@ public class TermAPI implements ILuaAPI
} }
return null; return null;
} }
case 19:
case 20:
{
// setColour/setColor
if ( args.length < 4 || !(args[0] instanceof Double) || !(args[1] instanceof Double) || !(args[2] instanceof Double) || !(args[3] instanceof Double) ) // toil and trouble
{
throw new LuaException( "Expected number, number, number, number" );
}
if ( !m_environment.isColour() )
{
// Make sure you can't circumvent greyscale terminals with this function.
throw new LuaException( "Colour not supported" );
}
int colour = 15 - parseColour( args, m_environment.isColour() );
float r = ((Double)args[1]).floatValue();
float g = ((Double)args[2]).floatValue();
float b = ((Double)args[3]).floatValue();
synchronized( m_terminal )
{
if( m_terminal.getPalette() != null )
{
m_terminal.getPalette().setColour( colour, r, g, b );
}
}
return null;
}
case 21:
case 22:
{
// getColour/getColor
if (args.length < 1 || !(args[0] instanceof Double))
{
throw new LuaException( "Expected number" );
}
int colour = 15 - parseColour( args, m_environment.isColour() );
synchronized( m_terminal )
{
if ( m_terminal.getPalette() != null )
{
return ArrayUtils.toObject( m_terminal.getPalette().getColour64( colour ) );
}
}
return null;
}
default: default:
{ {
return null; return null;

View File

@ -68,12 +68,30 @@ public class Palette
return null; return null;
} }
public void resetColours() public double[] getColour64( int i )
{ {
for(int i = 0; i < Colour.values().length; ++i) if( i >= 0 && i < colours.length )
{
PaletteColour c = colours[ i ];
return new double[] { (double)c.m_r, (double)c.m_g, (double)c.m_b };
}
return null;
}
public void resetColour( int i )
{
if(i >= 0 && i < colours.length )
{ {
Colour c = Colour.values()[ i ]; Colour c = Colour.values()[ i ];
colours[i] = new PaletteColour( c.getR(), c.getG(), c.getB() ); colours[i] = new PaletteColour( c.getR(), c.getG(), c.getB() );
} }
} }
public void resetColours()
{
for(int i = 0; i < Colour.values().length; ++i)
{
resetColour( i );
}
}
} }