1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-26 19:37:39 +00:00

fix: sidebar, textures and lang from tweaked

This commit is contained in:
Nikita Savyolov
2021-10-02 00:24:41 +03:00
parent ee82a8d75f
commit 89662bf54a
30 changed files with 707 additions and 387 deletions

View File

@@ -1,5 +1,6 @@
package dan200.computercraft.client.gui;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@@ -23,14 +24,14 @@ public abstract class ComputerScreenBase <T extends ContainerComputerBase> exten
protected final ClientComputer computer;
protected final ComputerFamily family;
protected final int sidebarYOffset = 0;
protected final int sidebarYOffset;
public ComputerScreenBase(T container, PlayerInventory player, Text title, int sidebarYOffset )
{
super( container, player, title );
computer = (ClientComputer) container.getComputer();
family = container.getFamily();
// this.sidebarYOffset = sidebarYOffset;
this.sidebarYOffset = sidebarYOffset;
}
protected abstract WidgetTerminal createTerminal();
@@ -42,7 +43,7 @@ public abstract class ComputerScreenBase <T extends ContainerComputerBase> exten
client.keyboard.setRepeatEvents( true );
terminal = addDrawableChild( createTerminal() );
// ComputerSidebar.addButtons( this, computer, this::addButton, leftPos, topPos + sidebarYOffset );
ComputerSidebar.addButtons( this, computer, this::addDrawableChild, x, y + sidebarYOffset );
setFocused( terminal );
}

View File

@@ -6,29 +6,23 @@
package dan200.computercraft.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.client.render.RenderTypes;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
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 org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
import java.util.List;
import static dan200.computercraft.client.render.ComputerBorderRenderer.*;
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
import static dan200.computercraft.client.render.ComputerBorderRenderer.getTexture;
public final class GuiComputer<T extends ContainerComputerBase> extends ComputerScreenBase<T>
{
@@ -41,7 +35,7 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
this.termWidth = termWidth;
this.termHeight = termHeight;
backgroundWidth = WidgetTerminal.getWidth( termWidth ) + BORDER * 2;
backgroundWidth = WidgetTerminal.getWidth( termWidth ) + BORDER * 2 + ComputerSidebar.WIDTH;
backgroundHeight = WidgetTerminal.getHeight( termHeight ) + BORDER * 2;
}
@@ -64,7 +58,7 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
protected WidgetTerminal createTerminal()
{
return new WidgetTerminal( computer,
x + BORDER, y + BORDER, termWidth, termHeight
x + ComputerSidebar.WIDTH + BORDER, y + BORDER, termWidth, termHeight
);
}
@Override
@@ -73,5 +67,6 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
ComputerBorderRenderer.render(
getTexture(family), terminal.x, terminal.y, getZOffset(),
RenderTypes.FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight() );
ComputerSidebar.renderBackground( stack, x, y + sidebarYOffset );
}
}

View File

@@ -8,6 +8,7 @@ package dan200.computercraft.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@@ -36,7 +37,7 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
super( container, player, title, BORDER );
family = container.getFamily();
backgroundWidth = TEX_WIDTH;
backgroundWidth = TEX_WIDTH + ComputerSidebar.WIDTH;
backgroundHeight = TEX_HEIGHT;
}
@@ -45,7 +46,7 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
protected WidgetTerminal createTerminal()
{
return new WidgetTerminal(
computer, x + BORDER, y + BORDER,
computer, x + BORDER + ComputerSidebar.WIDTH, y + BORDER,
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight
);
}
@@ -55,7 +56,7 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
{
boolean advanced = family == ComputerFamily.ADVANCED;
RenderSystem.setShaderTexture( 0, advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
drawTexture( transform, x, y, 0, 0, TEX_WIDTH, TEX_HEIGHT );
drawTexture( transform, x + ComputerSidebar.WIDTH, y, 0, 0, TEX_WIDTH, TEX_HEIGHT );
// Draw selection slot
int slot = getScreenHandler().getSelectedSlot();
@@ -71,5 +72,6 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
}
RenderSystem.setShaderTexture( 0, advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
ComputerSidebar.renderBackground( transform, x, y + sidebarYOffset );
}
}

View File

@@ -0,0 +1,107 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.gui.widgets;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.command.text.ChatHelpers;
import dan200.computercraft.shared.computer.core.ClientComputer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import java.util.Arrays;
import java.util.function.Consumer;
/**
* Registers buttons to interact with a computer.
*/
public final class ComputerSidebar
{
private static final Identifier TEXTURE = new Identifier( ComputerCraft.MOD_ID, "textures/gui/buttons.png" );
private static final int TEX_SIZE = 64;
private static final int ICON_WIDTH = 12;
private static final int ICON_HEIGHT = 12;
private static final int ICON_MARGIN = 2;
private static final int ICON_TEX_Y_DIFF = 14;
private static final int CORNERS_BORDER = 3;
private static final int FULL_BORDER = CORNERS_BORDER + ICON_MARGIN;
private static final int BUTTONS = 2;
private static final int HEIGHT = (ICON_HEIGHT + ICON_MARGIN * 2) * BUTTONS + CORNERS_BORDER * 2;
public static final int WIDTH = 17;
private ComputerSidebar()
{
}
public static void addButtons(Screen screen, ClientComputer computer, Consumer<ClickableWidget> add, int x, int y )
{
x += CORNERS_BORDER + 1;
y += CORNERS_BORDER + ICON_MARGIN;
add.accept( new DynamicImageButton(
screen, x, y, ICON_WIDTH, ICON_HEIGHT, () -> computer.isOn() ? 15 : 1, 1, ICON_TEX_Y_DIFF,
TEXTURE, TEX_SIZE, TEX_SIZE, b -> toggleComputer( computer ),
() -> computer.isOn() ? Arrays.asList(
new TranslatableText( "gui.computercraft.tooltip.turn_off" ),
ChatHelpers.coloured(new TranslatableText( "gui.computercraft.tooltip.turn_off.key" ), Formatting.GRAY)
) : Arrays.asList(
new TranslatableText( "gui.computercraft.tooltip.turn_on" ),
ChatHelpers.coloured(new TranslatableText( "gui.computercraft.tooltip.turn_off.key" ), Formatting.GRAY)
)
) );
y += ICON_HEIGHT + ICON_MARGIN * 2;
add.accept( new DynamicImageButton(
screen, x, y, ICON_WIDTH, ICON_HEIGHT, 29, 1, ICON_TEX_Y_DIFF,
TEXTURE, TEX_SIZE, TEX_SIZE, b -> computer.queueEvent( "terminate" ),
Arrays.asList(
new TranslatableText( "gui.computercraft.tooltip.terminate" ),
ChatHelpers.coloured(new TranslatableText( "gui.computercraft.tooltip.terminate.key" ), Formatting.GRAY)
)
) );
}
public static void renderBackground(MatrixStack transform, int x, int y )
{
Screen.drawTexture( transform,
x, y, 0, 102, WIDTH, FULL_BORDER,
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
);
Screen.drawTexture( transform,
x, y + FULL_BORDER, WIDTH, HEIGHT - FULL_BORDER * 2,
0, 107, WIDTH, 4,
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
);
Screen.drawTexture( transform,
x, y + HEIGHT - FULL_BORDER, 0, 111, WIDTH, FULL_BORDER,
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
);
}
private static void toggleComputer( ClientComputer computer )
{
if( computer.isOn() )
{
computer.shutdown();
}
else
{
computer.turnOn();
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.gui.widgets;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
* Version of {@link net.minecraft.client.gui.widget.TexturedButtonWidget} which allows changing some properties
* dynamically.
*/
public class DynamicImageButton extends ButtonWidget
{
private final Screen screen;
private final Identifier texture;
private final IntSupplier xTexStart;
private final int yTexStart;
private final int yDiffTex;
private final int textureWidth;
private final int textureHeight;
private final Supplier<List<Text>> tooltip;
public DynamicImageButton(
Screen screen, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
Identifier texture, int textureWidth, int textureHeight,
PressAction onPress, List<Text> tooltip
)
{
this(
screen, x, y, width, height, () -> xTexStart, yTexStart, yDiffTex,
texture, textureWidth, textureHeight,
onPress, () -> tooltip
);
}
public DynamicImageButton(
Screen screen, int x, int y, int width, int height, IntSupplier xTexStart, int yTexStart, int yDiffTex,
Identifier texture, int textureWidth, int textureHeight,
PressAction onPress, Supplier<List<Text>> tooltip
)
{
super( x, y, width, height, LiteralText.EMPTY, onPress );
this.screen = screen;
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
this.xTexStart = xTexStart;
this.yTexStart = yTexStart;
this.yDiffTex = yDiffTex;
this.texture = texture;
this.tooltip = tooltip;
}
@Override
public void renderButton(@Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
{
RenderSystem.setShaderTexture( 0, texture );
RenderSystem.disableDepthTest();
int yTex = yTexStart;
if( isHovered() ) yTex += yDiffTex;
drawTexture( stack, x, y, xTexStart.getAsInt(), yTex, width, height, textureWidth, textureHeight );
RenderSystem.enableDepthTest();
if( isHovered() ) renderToolTip( stack, mouseX, mouseY );
}
@Nonnull
@Override
public Text getMessage()
{
List<Text> tooltip = this.tooltip.get();
return tooltip.isEmpty() ? LiteralText.EMPTY : tooltip.get( 0 );
}
// @Override
public void renderToolTip( @Nonnull MatrixStack stack, int mouseX, int mouseY )
{
List<Text> tooltip = this.tooltip.get();
if( !tooltip.isEmpty() )
{
screen.renderTooltip( stack, tooltip, mouseX, mouseY );
}
}
}

View File

@@ -1,106 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.gui.widgets;
import net.minecraft.client.gui.Element;
public class WidgetWrapper implements Element
{
private final Element listener;
private final int x;
private final int y;
private final int width;
private final int height;
public WidgetWrapper( Element listener, int x, int y, int width, int height )
{
this.listener = listener;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
@Override
public boolean mouseClicked( double x, double y, int button )
{
double dx = x - this.x, dy = y - this.y;
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseClicked( dx, dy, button );
}
@Override
public boolean mouseReleased( double x, double y, int button )
{
double dx = x - this.x, dy = y - this.y;
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseReleased( dx, dy, button );
}
@Override
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
{
double dx = x - this.x, dy = y - this.y;
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseDragged( dx, dy, button, deltaX, deltaY );
}
@Override
public boolean mouseScrolled( double x, double y, double delta )
{
double dx = x - this.x, dy = y - this.y;
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
}
@Override
public boolean keyPressed( int key, int scancode, int modifiers )
{
return listener.keyPressed( key, scancode, modifiers );
}
@Override
public boolean keyReleased( int key, int scancode, int modifiers )
{
return listener.keyReleased( key, scancode, modifiers );
}
@Override
public boolean charTyped( char character, int modifiers )
{
return listener.charTyped( character, modifiers );
}
@Override
public boolean changeFocus( boolean b )
{
return listener.changeFocus( b );
}
@Override
public boolean isMouseOver( double x, double y )
{
double dx = x - this.x, dy = y - this.y;
return dx >= 0 && dx < width && dy >= 0 && dy < height;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
}

View File

@@ -39,7 +39,8 @@ public class ComputerBorderRenderer
private static final int LIGHT_CORNER_Y = 80;
public static final int LIGHT_HEIGHT = 8;
private static final float TEX_SCALE = 1 / 256.0f;
public static final int TEX_SIZE = 256;
private static final float TEX_SCALE = 1 / (float) TEX_SIZE;
static
{

View File

@@ -32,7 +32,6 @@ public class MixinWorld
@Inject( method = "addBlockEntity", at = @At( "HEAD" ) )
public void addBlockEntity( @Nullable BlockEntity entity, CallbackInfo info )
{
System.out.println("addBlockEntity");
if( entity != null && !entity.isRemoved() && entity.getWorld().isInBuildLimit(entity.getPos()) && iteratingTickingBlockEntities )
{
setWorld( entity, this );
@@ -41,7 +40,6 @@ public class MixinWorld
private static void setWorld( BlockEntity entity, Object world )
{
System.out.println("setWorld");
if( entity.getWorld() != world && entity instanceof TileGeneric )
{
entity.setWorld( (World) world ); //TODO why?

View File

@@ -6,6 +6,7 @@
package dan200.computercraft.shared.turtle.inventory;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
@@ -36,7 +37,8 @@ public class ContainerTurtle extends ContainerComputerBase
{
public static final int BORDER = 8;
public static final int PLAYER_START_Y = 134;
public static final int TURTLE_START_X = 175;
public static final int TURTLE_START_X = ComputerSidebar.WIDTH + 175;
public static final int PLAYER_START_X = ComputerSidebar.WIDTH + BORDER;
private final PropertyDelegate properties;
@@ -75,14 +77,14 @@ public class ContainerTurtle extends ContainerComputerBase
{
for( int x = 0; x < 9; x++ )
{
addSlot( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, PLAYER_START_Y + 1 + y * 18 ) );
addSlot( new Slot( playerInventory, x + y * 9 + 9, PLAYER_START_X + x * 18, PLAYER_START_Y + 1 + y * 18 ) );
}
}
// Player hotbar
for( int x = 0; x < 9; x++ )
{
addSlot( new Slot( playerInventory, x, 8 + x * 18, PLAYER_START_Y + 3 * 18 + 5 ) );
addSlot( new Slot( playerInventory, x, PLAYER_START_X + x * 18, PLAYER_START_Y + 3 * 18 + 5 ) );
}
}