mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-07 09:04:10 +00:00
Set keyHandled on the terminal GUI
This allows us to block JEI processing key events such as "o", meaning the GUI is not constantly toggled when interacting with a turtle. Also clean up the widget code, as there's a lot of functionality here which only is needed in CCEdu.
This commit is contained in:
parent
3e6f6467af
commit
f765b6a487
@ -95,7 +95,7 @@ public class GuiComputer extends GuiContainer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_terminal.keyTyped( c, k );
|
if( m_terminal.keyTyped( c, k ) ) keyHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public class GuiComputer extends GuiContainer
|
|||||||
public void handleKeyboardInput() throws IOException
|
public void handleKeyboardInput() throws IOException
|
||||||
{
|
{
|
||||||
super.handleKeyboardInput();
|
super.handleKeyboardInput();
|
||||||
m_terminal.handleKeyboardInput();
|
if( m_terminal.handleKeyboardInput() ) keyHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,7 +95,7 @@ public class GuiTurtle extends GuiContainer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_terminalGui.keyTyped( c, k );
|
if( m_terminalGui.keyTyped( c, k ) ) keyHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class GuiTurtle extends GuiContainer
|
|||||||
public void handleKeyboardInput() throws IOException
|
public void handleKeyboardInput() throws IOException
|
||||||
{
|
{
|
||||||
super.handleKeyboardInput();
|
super.handleKeyboardInput();
|
||||||
m_terminalGui.handleKeyboardInput();
|
if( m_terminalGui.handleKeyboardInput() ) keyHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawSelectionSlot( boolean advanced )
|
protected void drawSelectionSlot( boolean advanced )
|
||||||
|
@ -20,8 +20,6 @@ import javax.annotation.Nonnull;
|
|||||||
|
|
||||||
public abstract class Widget extends Gui
|
public abstract class Widget extends Gui
|
||||||
{
|
{
|
||||||
private WidgetContainer m_parent;
|
|
||||||
private boolean m_visible;
|
|
||||||
private int m_xPosition;
|
private int m_xPosition;
|
||||||
private int m_yPosition;
|
private int m_yPosition;
|
||||||
private int m_width;
|
private int m_width;
|
||||||
@ -29,64 +27,12 @@ public abstract class Widget extends Gui
|
|||||||
|
|
||||||
protected Widget( int x, int y, int width, int height )
|
protected Widget( int x, int y, int width, int height )
|
||||||
{
|
{
|
||||||
m_parent = null;
|
|
||||||
m_visible = true;
|
|
||||||
m_xPosition = x;
|
m_xPosition = x;
|
||||||
m_yPosition = y;
|
m_yPosition = y;
|
||||||
m_width = width;
|
m_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WidgetContainer getRoot()
|
|
||||||
{
|
|
||||||
if( m_parent != null )
|
|
||||||
{
|
|
||||||
return m_parent.getRoot();
|
|
||||||
}
|
|
||||||
else if( this instanceof WidgetContainer )
|
|
||||||
{
|
|
||||||
return (WidgetContainer)this;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WidgetContainer getParent()
|
|
||||||
{
|
|
||||||
return m_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParent( WidgetContainer parent )
|
|
||||||
{
|
|
||||||
m_parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isObscured()
|
|
||||||
{
|
|
||||||
if( m_parent != null )
|
|
||||||
{
|
|
||||||
Widget parentModalWidget = m_parent.getModalWidget();
|
|
||||||
if( parentModalWidget == null )
|
|
||||||
{
|
|
||||||
return m_parent.isObscured();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (parentModalWidget != this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isVisible()
|
|
||||||
{
|
|
||||||
return m_visible && (m_parent == null || m_parent.isVisible());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVisible( boolean visible )
|
|
||||||
{
|
|
||||||
m_visible = visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getXPosition()
|
public int getXPosition()
|
||||||
{
|
{
|
||||||
return m_xPosition;
|
return m_xPosition;
|
||||||
@ -97,16 +43,6 @@ public abstract class Widget extends Gui
|
|||||||
return m_yPosition;
|
return m_yPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAbsoluteXPosition()
|
|
||||||
{
|
|
||||||
return m_xPosition + (m_parent != null ? m_parent.getAbsoluteXPosition() : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAbsoluteYPosition()
|
|
||||||
{
|
|
||||||
return m_yPosition + (m_parent != null ? m_parent.getAbsoluteYPosition() : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth()
|
public int getWidth()
|
||||||
{
|
{
|
||||||
return m_width;
|
return m_width;
|
||||||
@ -117,18 +53,6 @@ public abstract class Widget extends Gui
|
|||||||
return m_height;
|
return m_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition( int x, int y )
|
|
||||||
{
|
|
||||||
m_xPosition = x;
|
|
||||||
m_yPosition = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resize( int width, int height )
|
|
||||||
{
|
|
||||||
m_width = width;
|
|
||||||
m_height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -137,246 +61,21 @@ public abstract class Widget extends Gui
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawForeground( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void modifyMousePosition( MousePos pos )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleMouseInput( int mouseX, int mouseY )
|
public void handleMouseInput( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleKeyboardInput()
|
public boolean handleKeyboardInput()
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseClicked( int mouseX, int mouseY, int mouseButton )
|
public void mouseClicked( int mouseX, int mouseY, int mouseButton )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void keyTyped( char c, int k )
|
public boolean keyTyped( char c, int k )
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean suppressItemTooltips( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean suppressKeyPress( char c, int k )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawFullImage( int x, int y, int w, int h )
|
|
||||||
{
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
tessellator.getBuffer().begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
|
||||||
tessellator.getBuffer().pos( x + 0, y + h, this.zLevel ).tex( 0.0, 1.0 ).endVertex();
|
|
||||||
tessellator.getBuffer().pos( x + w, y + h, this.zLevel ).tex( 1.0, 1.0 ).endVertex();
|
|
||||||
tessellator.getBuffer().pos( x + w, y + 0, this.zLevel ).tex( 1.0, 0.0 ).endVertex();
|
|
||||||
tessellator.getBuffer().pos( x + 0, y + 0, this.zLevel ).tex( 0.0, 0.0 ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawT3( int x, int y, int w, int h, int u, int v, int uw, int vh )
|
|
||||||
{
|
|
||||||
int partW = uw / 3;
|
|
||||||
|
|
||||||
// Draw first bit
|
|
||||||
super.drawTexturedModalRect( x, y, u, v, partW, vh );
|
|
||||||
|
|
||||||
// Draw middle bits
|
|
||||||
int middleBits = Math.max( (w - 2 * partW) / partW, 0 );
|
|
||||||
for( int j=0; j<middleBits; ++j )
|
|
||||||
{
|
|
||||||
super.drawTexturedModalRect( x + (j + 1) * partW, y, u + partW, v, partW, vh );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw end bit
|
|
||||||
int endW = w - (middleBits + 1) * partW;
|
|
||||||
super.drawTexturedModalRect( x + w - endW, y, u + uw - endW, v, endW, vh );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawT9( int x, int y, int w, int h, int u, int v, int uw, int vh )
|
|
||||||
{
|
|
||||||
int partH = vh / 3;
|
|
||||||
|
|
||||||
// Draw first row
|
|
||||||
drawT3( x, y, w, partH, u, v, uw, partH );
|
|
||||||
|
|
||||||
// Draw middle rows
|
|
||||||
int middleBits = Math.max( (h - 2 * partH) / partH, 0 );
|
|
||||||
for( int j=0; j<middleBits; ++j )
|
|
||||||
{
|
|
||||||
drawT3( x, y + ( j + 1 ) * partH, w, partH, u, v + partH, uw, partH );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw end row
|
|
||||||
int endH = h - (middleBits + 1) * partH;
|
|
||||||
drawT3( x, y + h - endH, w, endH, u, v + vh - endH, uw, endH );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawInsetBorder( int x, int y, int w, int h )
|
|
||||||
{
|
|
||||||
// Draw border
|
|
||||||
try
|
|
||||||
{
|
|
||||||
drawVerticalLine( x, y - 1, y + h - 1, 0xff363636 );
|
|
||||||
drawVerticalLine( x + w - 1, y, y + h, 0xffffffff );
|
|
||||||
drawHorizontalLine( x, x + w - 2, y, 0xff363636 );
|
|
||||||
drawHorizontalLine( x + 1, x + w - 1, y + h - 1, 0xffffffff );
|
|
||||||
drawHorizontalLine( x, x, y + h - 1, 0xff8a8a8a );
|
|
||||||
drawHorizontalLine( x + w - 1, x + w - 1, y, 0xff8a8a8a );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawFlatBorder( int x, int y, int w, int h, int colour )
|
|
||||||
{
|
|
||||||
// Draw border
|
|
||||||
colour = colour | 0xff000000;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
drawVerticalLine( x, y - 1, y + h - 1, colour );
|
|
||||||
drawVerticalLine( x + w - 1, y, y + h, colour );
|
|
||||||
drawHorizontalLine( x, x + w - 2, y, colour );
|
|
||||||
drawHorizontalLine( x + 1, x + w - 1, y + h - 1, colour );
|
|
||||||
drawHorizontalLine( x, x, y + h - 1, colour );
|
|
||||||
drawHorizontalLine( x + w - 1, x + w - 1, y, colour );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawTooltip( String line, int x, int y )
|
|
||||||
{
|
|
||||||
drawTooltip( new String[] { line }, x, y );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawTooltip( String[] lines, int x, int y )
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
FontRenderer fontRenderer = mc.fontRenderer;
|
|
||||||
|
|
||||||
int width = 0;
|
|
||||||
for( String line : lines )
|
|
||||||
{
|
|
||||||
width = Math.max( fontRenderer.getStringWidth( line ), width );
|
|
||||||
}
|
|
||||||
int startX = x + 12;
|
|
||||||
int startY = y - 12;
|
|
||||||
if( startX + width + 4 > mc.currentScreen.width )
|
|
||||||
{
|
|
||||||
startX -= width + 24;
|
|
||||||
if( startX < 24 )
|
|
||||||
{
|
|
||||||
startX = 24;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float oldZLevel = this.zLevel;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.zLevel = 300.0F;
|
|
||||||
|
|
||||||
int height = 10 * lines.length - 2;
|
|
||||||
int j1 = -267386864;
|
|
||||||
this.drawGradientRect( startX - 3, startY - 4, startX + width + 3, startY - 3, j1, j1 );
|
|
||||||
this.drawGradientRect( startX - 3, startY + height + 3, startX + width + 3, startY + height + 4, j1, j1 );
|
|
||||||
this.drawGradientRect( startX - 3, startY - 3, startX + width + 3, startY + height + 3, j1, j1 );
|
|
||||||
this.drawGradientRect( startX - 4, startY - 3, startX - 3, startY + height + 3, j1, j1 );
|
|
||||||
|
|
||||||
this.drawGradientRect( startX + width + 3, startY - 3, startX + width + 4, startY + height + 3, j1, j1 );
|
|
||||||
int k1 = 1347420415;
|
|
||||||
int l1 = ( k1 & 16711422 ) >> 1 | k1 & -16777216;
|
|
||||||
this.drawGradientRect( startX - 3, startY - 3 + 1, startX - 3 + 1, startY + height + 3 - 1, k1, l1 );
|
|
||||||
this.drawGradientRect( startX + width + 2, startY - 3 + 1, startX + width + 3, startY + height + 3 - 1, k1, l1 );
|
|
||||||
this.drawGradientRect( startX - 3, startY - 3, startX + width + 3, startY - 3 + 1, k1, k1 );
|
|
||||||
this.drawGradientRect( startX - 3, startY + height + 2, startX + width + 3, startY + height + 3, l1, l1 );
|
|
||||||
|
|
||||||
GlStateManager.disableDepth();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for( int i = 0; i < lines.length; ++i )
|
|
||||||
{
|
|
||||||
String line = lines[ i ];
|
|
||||||
fontRenderer.drawStringWithShadow( line, startX, startY + i * 10, 0xffffffff );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
GlStateManager.enableDepth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
this.zLevel = oldZLevel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawItemStack( int x, int y, @Nonnull ItemStack stack )
|
|
||||||
{
|
|
||||||
if( !stack.isEmpty() )
|
|
||||||
{
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
GlStateManager.enableLighting();
|
|
||||||
GlStateManager.enableRescaleNormal();
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
|
||||||
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f );
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
RenderItem renderItem = mc.getRenderItem();
|
|
||||||
if( renderItem != null )
|
|
||||||
{
|
|
||||||
renderItem.renderItemAndEffectIntoGUI( stack, x, y );
|
|
||||||
renderItem.renderItemOverlayIntoGUI( mc.fontRenderer, stack, x, y, null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
RenderHelper.disableStandardItemLighting();
|
|
||||||
GlStateManager.disableRescaleNormal();
|
|
||||||
GlStateManager.disableLighting();
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.blendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawString( String s, int x, int y, int color )
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
mc.fontRenderer.drawString( s, x, y, color );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getStringWidth( String s )
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
return mc.fontRenderer.getStringWidth( s );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void playClickSound()
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
mc.getSoundHandler().playSound( PositionedSoundRecord.getMasterRecord( SoundEvents.UI_BUTTON_CLICK, 1.0F ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,336 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package dan200.computercraft.client.gui.widgets;
|
|
||||||
|
|
||||||
import dan200.computercraft.client.gui.widgets.Widget;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class WidgetContainer extends Widget
|
|
||||||
{
|
|
||||||
private ArrayList<Widget> m_widgets;
|
|
||||||
private Widget m_modalWidget;
|
|
||||||
|
|
||||||
public WidgetContainer( int x, int y, int w, int h )
|
|
||||||
{
|
|
||||||
super( x, y, w, h );
|
|
||||||
m_widgets = new ArrayList<>();
|
|
||||||
m_modalWidget = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addWidget( Widget widget )
|
|
||||||
{
|
|
||||||
m_widgets.add( widget );
|
|
||||||
widget.setParent( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModalWidget( Widget widget )
|
|
||||||
{
|
|
||||||
m_modalWidget = widget;
|
|
||||||
if( widget != null )
|
|
||||||
{
|
|
||||||
widget.setParent( this );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Widget getModalWidget()
|
|
||||||
{
|
|
||||||
return m_modalWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
for( Widget m_widget : m_widgets )
|
|
||||||
{
|
|
||||||
m_widget.update();
|
|
||||||
}
|
|
||||||
if( m_modalWidget != null )
|
|
||||||
{
|
|
||||||
m_modalWidget.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.draw(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
(m_modalWidget == null) ? (mouseX - getXPosition()) : -99,
|
|
||||||
(m_modalWidget == null) ? (mouseY - getYPosition()) : -99
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( m_modalWidget != null )
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GlStateManager.translate( 0.0f, 0.0f, 200.0f );
|
|
||||||
m_modalWidget.draw(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawForeground( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.drawForeground(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
(m_modalWidget == null) ? (mouseX - getXPosition()) : -99,
|
|
||||||
(m_modalWidget == null) ? (mouseY - getYPosition()) : -99
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_modalWidget != null )
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GlStateManager.translate( 0.0f, 0.0f, 200.0f );
|
|
||||||
m_modalWidget.drawForeground(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void modifyMousePosition( MousePos pos )
|
|
||||||
{
|
|
||||||
pos.x -= getXPosition();
|
|
||||||
pos.y -= getYPosition();
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.modifyMousePosition( pos );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
m_modalWidget.modifyMousePosition( pos );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos.x += getXPosition();
|
|
||||||
pos.y += getYPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean suppressItemTooltips( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
if( widget.suppressItemTooltips(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() && m_modalWidget.suppressItemTooltips(
|
|
||||||
mc,
|
|
||||||
xOrigin + getXPosition(),
|
|
||||||
yOrigin + getYPosition(),
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean suppressKeyPress( char c, int k )
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
if( widget.suppressKeyPress( c, k ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
if( m_modalWidget.suppressKeyPress( c, k ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseInput( int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.handleMouseInput(
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
m_modalWidget.handleMouseInput(
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardInput()
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.handleKeyboardInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
m_modalWidget.handleKeyboardInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked( int mouseX, int mouseY, int mouseButton )
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.mouseClicked(
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition(),
|
|
||||||
mouseButton
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
m_modalWidget.mouseClicked(
|
|
||||||
mouseX - getXPosition(),
|
|
||||||
mouseY - getYPosition(),
|
|
||||||
mouseButton
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyTyped( char c, int k )
|
|
||||||
{
|
|
||||||
if( m_modalWidget == null )
|
|
||||||
{
|
|
||||||
for( Widget widget : m_widgets )
|
|
||||||
{
|
|
||||||
if( widget.isVisible() )
|
|
||||||
{
|
|
||||||
widget.keyTyped( c, k );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_modalWidget.isVisible() )
|
|
||||||
{
|
|
||||||
m_modalWidget.keyTyped( c, k );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ import java.util.ArrayList;
|
|||||||
public class WidgetTerminal extends Widget
|
public class WidgetTerminal extends Widget
|
||||||
{
|
{
|
||||||
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
|
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
|
||||||
private static float TERMINATE_TIME = 0.5f;
|
private static final float TERMINATE_TIME = 0.5f;
|
||||||
|
|
||||||
private final IComputerContainer m_computer;
|
private final IComputerContainer m_computer;
|
||||||
|
|
||||||
@ -41,7 +41,6 @@ public class WidgetTerminal extends Widget
|
|||||||
|
|
||||||
private boolean m_focus;
|
private boolean m_focus;
|
||||||
private boolean m_allowFocusLoss;
|
private boolean m_allowFocusLoss;
|
||||||
private boolean m_locked;
|
|
||||||
|
|
||||||
private int m_leftMargin;
|
private int m_leftMargin;
|
||||||
private int m_rightMargin;
|
private int m_rightMargin;
|
||||||
@ -69,7 +68,6 @@ public class WidgetTerminal extends Widget
|
|||||||
|
|
||||||
m_focus = false;
|
m_focus = false;
|
||||||
m_allowFocusLoss = true;
|
m_allowFocusLoss = true;
|
||||||
m_locked = false;
|
|
||||||
|
|
||||||
m_leftMargin = leftMargin;
|
m_leftMargin = leftMargin;
|
||||||
m_rightMargin = rightMargin;
|
m_rightMargin = rightMargin;
|
||||||
@ -85,15 +83,10 @@ public class WidgetTerminal extends Widget
|
|||||||
m_focus = m_focus || !allowFocusLoss;
|
m_focus = m_focus || !allowFocusLoss;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked( boolean locked )
|
|
||||||
{
|
|
||||||
m_locked = locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped( char ch, int key )
|
public boolean keyTyped( char ch, int key )
|
||||||
{
|
{
|
||||||
if( m_focus && !m_locked )
|
if( m_focus )
|
||||||
{
|
{
|
||||||
// Ctrl+V for paste
|
// Ctrl+V for paste
|
||||||
if( ch == 22 )
|
if( ch == 22 )
|
||||||
@ -134,13 +127,14 @@ public class WidgetTerminal extends Widget
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular keys normally
|
// Regular keys normally
|
||||||
if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
|
if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
|
||||||
{
|
{
|
||||||
boolean repeat = Keyboard.isRepeatEvent();
|
boolean repeat = Keyboard.isRepeatEvent();
|
||||||
|
boolean handled = false;
|
||||||
if( key > 0 )
|
if( key > 0 )
|
||||||
{
|
{
|
||||||
if( !repeat )
|
if( !repeat )
|
||||||
@ -152,6 +146,7 @@ public class WidgetTerminal extends Widget
|
|||||||
queueEvent( "key", new Object[]{
|
queueEvent( "key", new Object[]{
|
||||||
key, repeat
|
key, repeat
|
||||||
} );
|
} );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
|
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
|
||||||
@ -160,9 +155,14 @@ public class WidgetTerminal extends Widget
|
|||||||
queueEvent( "char", new Object[]{
|
queueEvent( "char", new Object[]{
|
||||||
Character.toString( ch )
|
Character.toString( ch )
|
||||||
} );
|
} );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -179,7 +179,7 @@ public class WidgetTerminal extends Widget
|
|||||||
if( m_focus )
|
if( m_focus )
|
||||||
{
|
{
|
||||||
IComputer computer = m_computer.getComputer();
|
IComputer computer = m_computer.getComputer();
|
||||||
if( !m_locked && computer != null && computer.isColour() && button >= 0 && button <= 2 )
|
if( computer != null && computer.isColour() && button >= 0 && button <= 2 )
|
||||||
{
|
{
|
||||||
Terminal term = computer.getTerminal();
|
Terminal term = computer.getTerminal();
|
||||||
if( term != null )
|
if( term != null )
|
||||||
@ -210,23 +210,27 @@ public class WidgetTerminal extends Widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleKeyboardInput()
|
public boolean handleKeyboardInput()
|
||||||
{
|
{
|
||||||
for( int i=m_keysDown.size()-1; i>=0; --i )
|
boolean handled = false;
|
||||||
|
for( int i = m_keysDown.size() - 1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
int key = m_keysDown.get( i );
|
int key = m_keysDown.get( i );
|
||||||
if( !Keyboard.isKeyDown( key ) )
|
if( !Keyboard.isKeyDown( key ) )
|
||||||
{
|
{
|
||||||
m_keysDown.remove( i );
|
m_keysDown.remove( i );
|
||||||
if( m_focus && !m_locked )
|
if( m_focus )
|
||||||
{
|
{
|
||||||
// Queue the "key_up" event
|
// Queue the "key_up" event
|
||||||
queueEvent( "key_up", new Object[]{
|
queueEvent( "key_up", new Object[]{
|
||||||
key
|
key
|
||||||
} );
|
} );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -247,7 +251,7 @@ public class WidgetTerminal extends Widget
|
|||||||
|
|
||||||
if( m_lastClickButton >= 0 && !Mouse.isButtonDown( m_lastClickButton ) )
|
if( m_lastClickButton >= 0 && !Mouse.isButtonDown( m_lastClickButton ) )
|
||||||
{
|
{
|
||||||
if( m_focus && !m_locked )
|
if( m_focus )
|
||||||
{
|
{
|
||||||
computer.queueEvent( "mouse_up", new Object[]{
|
computer.queueEvent( "mouse_up", new Object[]{
|
||||||
m_lastClickButton + 1, charX + 1, charY + 1
|
m_lastClickButton + 1, charX + 1, charY + 1
|
||||||
@ -262,7 +266,7 @@ public class WidgetTerminal extends Widget
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_focus && !m_locked )
|
if( m_focus )
|
||||||
{
|
{
|
||||||
if( wheelChange < 0 )
|
if( wheelChange < 0 )
|
||||||
{
|
{
|
||||||
@ -294,7 +298,7 @@ public class WidgetTerminal extends Widget
|
|||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
// Handle special keys
|
// Handle special keys
|
||||||
if( m_focus && !m_locked && (Keyboard.isKeyDown( 29 ) || Keyboard.isKeyDown( 157 )) )
|
if( m_focus && (Keyboard.isKeyDown( 29 ) || Keyboard.isKeyDown( 157 )) )
|
||||||
{
|
{
|
||||||
// Ctrl+T for terminate
|
// Ctrl+T for terminate
|
||||||
if( Keyboard.isKeyDown( 20 ) )
|
if( Keyboard.isKeyDown( 20 ) )
|
||||||
@ -446,19 +450,6 @@ public class WidgetTerminal extends Widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean suppressKeyPress( char c, int k )
|
|
||||||
{
|
|
||||||
if( m_focus )
|
|
||||||
{
|
|
||||||
return k != 1; // escape
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void queueEvent( String event )
|
private void queueEvent( String event )
|
||||||
{
|
{
|
||||||
IComputer computer = m_computer.getComputer();
|
IComputer computer = m_computer.getComputer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user