mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-26 23:42:18 +00:00
Gui fixes
- Makes GuiTurtle extend from GuiComputer - Fixes #51 - Fixes grayed background surrounding interface not rendering for computers
This commit is contained in:
parent
921802e6c9
commit
104a317163
@ -28,17 +28,17 @@ import javax.annotation.Nonnull;
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
|
||||
|
||||
public final class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<T>
|
||||
public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<T>
|
||||
{
|
||||
private final ComputerFamily family;
|
||||
private final ClientComputer computer;
|
||||
protected final ComputerFamily family;
|
||||
protected final ClientComputer computer;
|
||||
private final int termWidth;
|
||||
private final int termHeight;
|
||||
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
protected WidgetTerminal terminal;
|
||||
protected WidgetWrapper terminalWrapper;
|
||||
|
||||
private GuiComputer( T container, PlayerInventory player, Text title, int termWidth, int termHeight )
|
||||
protected GuiComputer( T container, PlayerInventory player, Text title, int termWidth, int termHeight )
|
||||
{
|
||||
super( container, player, title );
|
||||
this.family = container.getFamily();
|
||||
@ -63,30 +63,34 @@ public final class GuiComputer<T extends ContainerComputerBase> extends HandledS
|
||||
return new GuiComputer<>( container, inventory, component, container.getWidth(), container.getHeight() );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
protected void initTerminal(int border, int widthExtra, int heightExtra) {
|
||||
this.client.keyboard.setRepeatEvents( true );
|
||||
|
||||
int termPxWidth = this.termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = this.termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
this.backgroundWidth = termPxWidth + MARGIN * 2 + BORDER * 2;
|
||||
this.backgroundHeight = termPxHeight + MARGIN * 2 + BORDER * 2;
|
||||
this.backgroundWidth = termPxWidth + MARGIN * 2 + border * 2 + widthExtra;
|
||||
this.backgroundHeight = termPxHeight + MARGIN * 2 + border * 2 + heightExtra;
|
||||
|
||||
super.init();
|
||||
|
||||
this.terminal = new WidgetTerminal( this.client, () -> this.computer, this.termWidth, this.termHeight, MARGIN, MARGIN, MARGIN, MARGIN );
|
||||
this.terminalWrapper = new WidgetWrapper( this.terminal, MARGIN + BORDER + this.x, MARGIN + BORDER + this.y, termPxWidth, termPxHeight );
|
||||
this.terminalWrapper = new WidgetWrapper( this.terminal, MARGIN + border + this.x, MARGIN + border + this.y, termPxWidth, termPxHeight );
|
||||
|
||||
this.children.add( this.terminalWrapper );
|
||||
this.setFocused( this.terminalWrapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
this.initTerminal(BORDER, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
this.renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
this.drawMouseoverTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
|
@ -8,74 +8,36 @@ package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiTurtle extends HandledScreen<ContainerTurtle>
|
||||
public class GuiTurtle extends GuiComputer<ContainerTurtle>
|
||||
{
|
||||
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 final ComputerFamily family;
|
||||
private final ClientComputer computer;
|
||||
private final ContainerTurtle container;
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
public GuiTurtle( ContainerTurtle container, PlayerInventory player, Text title )
|
||||
{
|
||||
super( container, player, title );
|
||||
super( container, player, title, ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight);
|
||||
|
||||
this.container = container;
|
||||
this.family = container.getFamily();
|
||||
this.computer = (ClientComputer) container.getComputer();
|
||||
|
||||
this.backgroundWidth = 254;
|
||||
this.backgroundHeight = 217;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
super.init();
|
||||
this.client.keyboard.setRepeatEvents( true );
|
||||
|
||||
int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
this.terminal = new WidgetTerminal( this.client, () -> this.computer, ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight, 2, 2, 2, 2 );
|
||||
this.terminalWrapper = new WidgetWrapper( this.terminal, 2 + 8 + this.x, 2 + 8 + this.y, termPxWidth, termPxHeight );
|
||||
|
||||
this.children.add( this.terminalWrapper );
|
||||
this.setFocused( this.terminalWrapper );
|
||||
this.initTerminal(8, 0, 80);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
this.renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
this.drawMouseoverTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
public void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw term
|
||||
Identifier texture = this.family == ComputerFamily.ADVANCED ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL;
|
||||
@ -100,38 +62,4 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
|
||||
24 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
||||
{
|
||||
return (this.getFocused() != null && this.getFocused().mouseDragged( x, y, button, deltaX, deltaY )) || super.mouseDragged( x, y, button, deltaX, deltaY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||
{
|
||||
// Forward the tab key to the terminal, rather than moving between controls.
|
||||
if( key == GLFW.GLFW_KEY_TAB && this.getFocused() != null && this.getFocused() == this.terminalWrapper )
|
||||
{
|
||||
return this.getFocused().keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
return super.keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed()
|
||||
{
|
||||
super.removed();
|
||||
this.children.remove( this.terminal );
|
||||
this.terminal = null;
|
||||
this.client.keyboard.setRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
super.tick();
|
||||
this.terminal.update();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user