2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2021-01-06 17:13:40 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
package dan200.computercraft.client.gui;
|
|
|
|
|
2020-01-22 11:14:30 +00:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.ComputerCraft;
|
2021-06-06 18:32:52 +00:00
|
|
|
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
2021-06-06 18:32:52 +00:00
|
|
|
import dan200.computercraft.client.render.ComputerBorderRenderer;
|
2018-12-29 12:38:19 +00:00
|
|
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
|
|
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
2021-06-06 18:32:52 +00:00
|
|
|
import net.minecraft.client.gui.widget.Widget;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.entity.player.PlayerInventory;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2019-06-21 19:31:28 +00:00
|
|
|
import org.lwjgl.glfw.GLFW;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-06-06 18:32:52 +00:00
|
|
|
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.*;
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_normal.png" );
|
|
|
|
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_advanced.png" );
|
2018-12-23 16:55:25 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final ContainerTurtle container;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
private final ComputerFamily family;
|
|
|
|
private final ClientComputer computer;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
|
|
|
|
private WidgetTerminal terminal;
|
2018-12-23 16:55:25 +00:00
|
|
|
|
2019-06-09 07:58:49 +00:00
|
|
|
public GuiTurtle( ContainerTurtle container, PlayerInventory player, ITextComponent title )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
super( container, player, title );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2021-01-15 16:35:49 +00:00
|
|
|
this.container = container;
|
|
|
|
family = container.getFamily();
|
|
|
|
computer = (ClientComputer) container.getComputer();
|
2018-12-23 16:55:25 +00:00
|
|
|
|
2021-01-09 19:22:58 +00:00
|
|
|
imageWidth = 254;
|
|
|
|
imageHeight = 217;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
protected void init()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
super.init();
|
2021-01-09 19:22:58 +00:00
|
|
|
minecraft.keyboardHandler.setSendRepeatsToGui( true );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
|
2021-06-06 18:32:52 +00:00
|
|
|
terminal = addButton( new WidgetTerminal(
|
|
|
|
computer, leftPos + BORDER + ComputerSidebar.WIDTH, topPos + BORDER,
|
|
|
|
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight
|
|
|
|
) );
|
|
|
|
ComputerSidebar.addButtons( this, computer, this::addButton, leftPos, topPos + BORDER );
|
|
|
|
setFocused( terminal );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-08 12:36:31 +00:00
|
|
|
public void removed()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
super.removed();
|
2021-01-09 19:22:58 +00:00
|
|
|
minecraft.keyboardHandler.setSendRepeatsToGui( false );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
public void tick()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
super.tick();
|
|
|
|
terminal.update();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 19:31:28 +00:00
|
|
|
@Override
|
|
|
|
public boolean keyPressed( int key, int scancode, int modifiers )
|
|
|
|
{
|
|
|
|
// Forward the tab key to the terminal, rather than moving between controls.
|
2021-06-06 18:32:52 +00:00
|
|
|
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminal )
|
2019-06-21 19:31:28 +00:00
|
|
|
{
|
|
|
|
return getFocused().keyPressed( key, scancode, modifiers );
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.keyPressed( key, scancode, modifiers );
|
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
2021-01-09 19:22:58 +00:00
|
|
|
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
boolean advanced = family == ComputerFamily.ADVANCED;
|
2018-12-23 16:55:25 +00:00
|
|
|
|
2020-01-22 11:14:30 +00:00
|
|
|
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
2021-01-09 19:22:58 +00:00
|
|
|
minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
2021-06-06 18:32:52 +00:00
|
|
|
blit( leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, imageWidth, imageHeight );
|
|
|
|
|
|
|
|
minecraft.getTextureManager().bind( advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
|
|
|
|
ComputerSidebar.renderBackground( leftPos, topPos + BORDER );
|
2018-12-23 16:55:25 +00:00
|
|
|
|
2021-06-06 18:32:52 +00:00
|
|
|
int slot = container.getSelectedSlot();
|
|
|
|
if( slot >= 0 )
|
|
|
|
{
|
|
|
|
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
|
|
|
int slotX = slot % 4;
|
|
|
|
int slotY = slot / 4;
|
|
|
|
blit(
|
|
|
|
leftPos + TURTLE_START_X - 2 + slotX * 18, topPos + PLAYER_START_Y - 2 + slotY * 18,
|
|
|
|
0, 217, 24, 24
|
|
|
|
);
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-09-12 14:05:32 +00:00
|
|
|
|
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
public void render( int mouseX, int mouseY, float partialTicks )
|
2017-09-12 14:05:32 +00:00
|
|
|
{
|
2019-06-08 12:36:31 +00:00
|
|
|
renderBackground();
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
super.render( mouseX, mouseY, partialTicks );
|
2021-01-09 19:22:58 +00:00
|
|
|
renderTooltip( mouseX, mouseY );
|
2021-06-06 18:32:52 +00:00
|
|
|
|
|
|
|
for( Widget widget : buttons )
|
|
|
|
{
|
|
|
|
if( widget.isHovered() ) widget.renderToolTip( mouseX, mouseY );
|
|
|
|
}
|
2017-09-12 14:05:32 +00:00
|
|
|
}
|
2019-10-01 17:53:46 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
|
|
|
{
|
|
|
|
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|
|
|
|
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|