Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Add more keys to keyboard, add close button in gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 19, 2022
1 parent 6d3b6f8 commit b77381d
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 57 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ excluding different guis and no support for DFPWM/playing dynamic audio from spe
![Turtles](https://imgur.com/HQ8hbP9.png)
![Turtle ui](https://imgur.com/1WMDkjJ.png)

## How to use uis
To move mouse pointer you just need to move same way as you would rotate camera.

To input text directly into PC, type `/` and follow it by your input

To run macros/shortcuts, send a message starting with `;` (press tab to list all available).
You can input multiple by separating them with `;`. Some of them take arguments after space (mostly number of reapeats)

To exit guis press Ctrl + Q.

## Downloads:
- Github Releases: https://github.com/PolymerPorts/cc-restitched/releases
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ dependencies {

cctJavadoc 'cc.tweaked:cct-javadoc:1.4.5'

modImplementation include("eu.pb4:sgui:1.1.0+1.19")
modImplementation include("eu.pb4:sgui:1.1.1+1.19")
modImplementation include("eu.pb4:hologram-api:0.2.2+1.19")
modImplementation include("eu.pb4:polymer:0.2.1+1.19")
modImplementation include("fr.catcore:server-translations-api:1.4.14+1.19-rc2")
Expand Down
Binary file added logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
Expand Down Expand Up @@ -178,7 +176,7 @@ public ComputerGui(ServerPlayer player, ComputerDisplayAccess computer) {
int size = 0;

{
this.closeButton = new ImageButton(sideX, sideY + size, GuiTextures.CLOSE_ICON, (x, y, t) -> {
this.closeButton = new ImageButton(sideX, sideY + size, GuiTextures.SHUTDOWN_ICON, (x, y, t) -> {
if (this.getComputer().isOn()) {
this.getComputer().shutdown();
} else {
Expand Down Expand Up @@ -295,18 +293,10 @@ private static BiConsumer<ComputerGui, String> holdKey(int key) {
}

public void render() {

{
boolean isIn = this.closeButton.isIn(this.cursorX / 2, this.cursorY / 2);
if (this.computer.getComputer().isOn()) {
this.closeButton.image = isIn ? GuiTextures.CLOSE_ICON_ACTIVE_HOVER : GuiTextures.CLOSE_ICON_ACTIVE;
} else {
this.closeButton.image = isIn ? GuiTextures.CLOSE_ICON_HOVER : GuiTextures.CLOSE_ICON;
}
}
{
boolean isIn = this.terminateButton.isIn(this.cursorX / 2, this.cursorY / 2);
this.terminateButton.image = isIn ? GuiTextures.TERMINATE_HOVER : GuiTextures.TERMINATE;
if (this.computer.getComputer().isOn()) {
this.closeButton.texture = GuiTextures.SHUTDOWN_ACTIVE;
} else {
this.closeButton.texture = GuiTextures.SHUTDOWN_ICON;
}

super.render();
Expand Down Expand Up @@ -402,13 +392,6 @@ public void onCommandSuggestion(int id, String fullCommand) {

@Override
public boolean onClickEntity(int entityId, EntityInteraction type, boolean isSneaking, @Nullable Vec3 interactionPos) {
//this.player.sendMessage(new TextComponent("x: " + this.cursorX / 2 + " | y: " + this.cursorY / 2), Util.NIL_UUID);
if (type == EntityInteraction.ATTACK) {
this.renderer.click(this.cursorX / 2, this.cursorY / 2, ScreenElement.ClickType.LEFT_DOWN);
} else {
this.renderer.click(this.cursorX / 2, this.cursorY / 2, ScreenElement.ClickType.RIGHT_DOWN);
}

return super.onClickEntity(entityId, type, isSneaking, interactionPos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public MapGui(ServerPlayer player) {
this.virtualDisplay = VirtualDisplay.of(this.canvas, pos.relative(dir).relative(dir.getClockWise(), 2).above(), dir, 0, true);
this.virtualDisplay2 = null;//VirtualDisplay.of(this.canvas, pos.relative(dir.getClockWise(), 2).above(), dir, 0, true);
this.renderer = CanvasRenderer.of(new CanvasImage(this.canvas.getWidth(), this.canvas.getHeight()));
this.renderer.add(new ImageButton(560, 32, GuiTextures.CLOSE_ICON, (a, b, c) -> this.close()));

this.canvas.addPlayer(player);
this.virtualDisplay.addPlayer(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package dan200.computercraft.fabric.poly.render;

import eu.pb4.mapcanvas.api.core.CanvasImage;
import dan200.computercraft.fabric.poly.textures.ButtonTexture;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;

public class ImageButton extends ImageView {
public ButtonTexture texture;
private OnClick callback;

public ImageButton(int x, int y, CanvasImage image, OnClick callback) {
super(x, y, image);
public ImageButton(int x, int y, ButtonTexture image, OnClick callback) {
super(x, y, image.base());
this.texture = image;
this.callback = callback;
}

@Override
public void render(DrawableCanvas canvas, long tick, int mouseX, int mouseY) {
this.image = this.isIn(mouseX, mouseY) ? this.texture.hover() : this.texture.base();
super.render(canvas, tick, mouseX, mouseY);
}

@Override
public void click(int x, int y, ClickType type) {
this.callback.click(x, y, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

public class KeyboardView extends ScreenElement {
private static final Key[][] KEYS = new Key[][] {
new Key[] { k("ESC", Keys.ESCAPE), e(15), k("F1", Keys.F1), k("F2", Keys.F2), k("F3", Keys.F3), k("F4", Keys.F4), e(10), k("F5", Keys.F5), k("F6", Keys.F6), k("F7", Keys.F7), k("F8", Keys.F8), e(10), k("F9", Keys.F9), k("F10", Keys.F10), k("F11", Keys.F11), k("F12", Keys.F12), },
new Key[] { k("~\n`", Keys.GRAVE_ACCENT, '`', '~'), k("!\n1", Keys.NUM_1, '1', '!'), k("@\n2", Keys.NUM_2, '2', '@'), k("#\n3", Keys.NUM_3, '3', '#'), k("$\n4", Keys.NUM_4, '4', '$'), k("%\n5", Keys.NUM_5, '5', '%'), k("^\n6", Keys.NUM_6, '6', '^'), k("&\n7", Keys.NUM_7, '7', '&'), k("*\n8", Keys.NUM_8, '8', '*'), k("(\n9", Keys.NUM_9, '9', '('), k(")\n0", Keys.NUM_0, '0', ')'), k("_\n-", Keys.MINUS, '-', '_'), k("+\n=", Keys.EQUAL), k("<--", Keys.BACKSPACE, 44) },
new Key[] { k("Tab", Keys.TAB, 32), k("Q", Keys.Q), k("W", Keys.W), k("E", Keys.E), k("R", Keys.R), k("T", Keys.T), k("Y", Keys.Y), k("U", Keys.U), k("I", Keys.I), k("O", Keys.O), k("P", Keys.P), k("{\n[", Keys.LEFT_BRACKET, '[', '{'), k("}\n]", Keys.RIGHT_BRACKET, ']', '}'), k("Enter", Keys.ENTER, 32), },
new Key[] { k("ESC", Keys.ESCAPE), e(16), k("F1", Keys.F1), k("F2", Keys.F2), k("F3", Keys.F3), k("F4", Keys.F4), e(12), k("F5", Keys.F5), k("F6", Keys.F6), k("F7", Keys.F7), k("F8", Keys.F8), e(12), k("F9", Keys.F9), k("F10", Keys.F10), k("F11", Keys.F11), k("F12", Keys.F12), e(5), k("Prn", Keys.PRINT_SCREEN), k("SLk", Keys.SCROLL_LOCK), k("⏸", Keys.PAUSE) },
new Key[] { k("~\n`", Keys.GRAVE_ACCENT, '`', '~'), k("!\n1", Keys.NUM_1, '1', '!'), k("@\n2", Keys.NUM_2, '2', '@'), k("#\n3", Keys.NUM_3, '3', '#'), k("$\n4", Keys.NUM_4, '4', '$'), k("%\n5", Keys.NUM_5, '5', '%'), k("^\n6", Keys.NUM_6, '6', '^'), k("&\n7", Keys.NUM_7, '7', '&'), k("*\n8", Keys.NUM_8, '8', '*'), k("(\n9", Keys.NUM_9, '9', '('), k(")\n0", Keys.NUM_0, '0', ')'), k("_\n-", Keys.MINUS, '-', '_'), k("+\n=", Keys.EQUAL), k("<--", Keys.BACKSPACE, 44), e(5), k("Ins", Keys.INSERT), k("Hm", Keys.HOME), k("P⏶", Keys.PAGE_UP) },
new Key[] { k("Tab", Keys.TAB, 32), k("Q", Keys.Q), k("W", Keys.W), k("E", Keys.E), k("R", Keys.R), k("T", Keys.T), k("Y", Keys.Y), k("U", Keys.U), k("I", Keys.I), k("O", Keys.O), k("P", Keys.P), k("{\n[", Keys.LEFT_BRACKET, '[', '{'), k("}\n]", Keys.RIGHT_BRACKET, ']', '}'), k("Enter", Keys.ENTER, 32), e(5), k("Del", Keys.DELETE), k("End", Keys.END), k("P⏷", Keys.PAGE_DOWN) },
new Key[] { k("Caps", Keys.CAPS_LOCK, 38), k("A", Keys.A), k("S", Keys.S), k("D", Keys.D), k("F", Keys.F), k("G", Keys.G), k("H", Keys.H), k("J", Keys.J), k("K", Keys.K), k("L", Keys.L), k(":\n;", Keys.SEMICOLON, ';', ':'), k("\"\n'", Keys.APOSTROPHE, '\'', '"'), k("|\n\\", Keys.BACKSLASH, '\\', '|'), k("", Keys.ENTER, 26) },
new Key[] { k("Shift", Keys.LEFT_SHIFT, 54), k("Z", Keys.Z), k("X", Keys.X), k("C", Keys.C), k("V", Keys.V), k("B", Keys.B), k("N", Keys.N), k("M", Keys.M), k("<\n,", Keys.COMMA, ',', '<'), k(">\n.", Keys.PERIOD, '.', '>'), k("?\n/", Keys.SLASH, '/', '?'), k("Shift", Keys.RIGHT_SHIFT, 54) },
new Key[] { k("Ctrl", Keys.LEFT_CONTROL, 35), k("⛏", Keys.MENU, 30), k("Alt", Keys.LEFT_ALT, 30), k(" ", Keys.SPACE, 24 * 6), k("Alt", Keys.RIGHT_ALT, 30), k("Ctrl", Keys.RIGHT_CONTROL, 36) }
new Key[] { k("Shift", Keys.LEFT_SHIFT, 54), k("Z", Keys.Z), k("X", Keys.X), k("C", Keys.C), k("V", Keys.V), k("B", Keys.B), k("N", Keys.N), k("M", Keys.M), k("<\n,", Keys.COMMA, ',', '<'), k(">\n.", Keys.PERIOD, '.', '>'), k("?\n/", Keys.SLASH, '/', '?'), k("Shift", Keys.RIGHT_SHIFT, 54), e(27), k("▲", Keys.UP) },
new Key[] { k("Ctrl", Keys.LEFT_CONTROL, 33), k("⛏", Keys.MENU, 27), k("Alt", Keys.LEFT_ALT, 27), k(" ", Keys.SPACE, 24 * 6), k("Alt", Keys.RIGHT_ALT, 27), k("⚗", Keys.RIGHT_SUPER, 27), k("Ctrl", Keys.RIGHT_CONTROL, 33), e(5), k("◀", Keys.LEFT), k("▼", Keys.DOWN), k("▶", Keys.RIGHT) }
};

public static final int KEYBOARD_WIDTH = ((Supplier<Integer>)() -> {
Expand Down Expand Up @@ -74,33 +74,26 @@ public KeyboardView(int x, int y, ComputerGui gui) {
public void render(DrawableCanvas canvas, long tick, int mouseX, int mouseY) {
int y = 0;
for (int l = 0; l < KEYS.length; l++) {
int x = (KEYBOARD_WIDTH - LINE_WIDTH[l]) / 2;
int x = 0;//(KEYBOARD_WIDTH - LINE_WIDTH[l]) / 2;
for (var key : KEYS[l]) {
if (key.key() != -1) {
var isHeld = this.gui.input.isKeyDown(key.key());
var a = isHeld ? 1 : 0;

if (key.key() == Keys.ENTER) {
var tX1 = (KEYBOARD_WIDTH - LINE_WIDTH[2]) / 2;
var tX2 = (KEYBOARD_WIDTH - LINE_WIDTH[3]) / 2;

for (var keyTmp : KEYS[2]) {
if (keyTmp.key != Keys.ENTER) {
tX1 += (keyTmp.width() + 2);
}
}
var tX2 = 0;//(KEYBOARD_WIDTH - LINE_WIDTH[3]) / 2;

for (var keyTmp : KEYS[3]) {
if (keyTmp.key != Keys.ENTER) {
tX2 += (keyTmp.width() + 2);
}
}

boolean hover = ScreenElement.isIn(mouseX, mouseY, this.x + tX1 , this.y + 32 - 3, this.x + tX1 + 32, this.y + 32 + 14)
boolean hover = ScreenElement.isIn(mouseX, mouseY, this.x + tX2 , this.y + 32 - 3, this.x + tX2 + 32, this.y + 32 + 14)
|| ScreenElement.isIn(mouseX, mouseY, this.x + tX2 , this.y + 48 - 3, this.x + tX2 + 26, this.y + 48 + 14);

var color = isHeld
? CanvasColor.GRAY_HIGH
? CanvasColor.WHITE_GRAY_LOW
: hover ? CanvasColor.WHITE_GRAY_NORMAL : CanvasColor.WHITE_GRAY_HIGH;

var color2 = isHeld
Expand All @@ -124,7 +117,7 @@ public void render(DrawableCanvas canvas, long tick, int mouseX, int mouseY) {
var hover = ScreenElement.isIn(mouseX, mouseY, this.x + x, this.y + y * 16, this.x + x + key.width(), this.y + y * 16 + 14);

var color = isHeld
? CanvasColor.GRAY_HIGH
? CanvasColor.WHITE_GRAY_LOW
: hover
? CanvasColor.WHITE_GRAY_NORMAL : CanvasColor.WHITE_GRAY_HIGH;

Expand Down Expand Up @@ -171,8 +164,8 @@ public void click(int x, int y, ClickType type) {
var height = KEYS.length;
for (int ly = 0; ly < height; ly++) {
var lys = ly * 16;
if (lys <= y && lys + 14 > y) {
int lxs = (KEYBOARD_WIDTH - LINE_WIDTH[ly]) / 2;
if (lys + 1 <= y && lys + 14 > y) {
int lxs = 0;//(KEYBOARD_WIDTH - LINE_WIDTH[ly]) / 2;
for (var key : KEYS[ly]) {
if (lxs <= x && lxs + key.width() > x) {
var id = key.key();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dan200.computercraft.fabric.poly.textures;

import eu.pb4.mapcanvas.api.core.CanvasImage;

public record ButtonTexture(CanvasImage base, CanvasImage hover) {
public static ButtonTexture of(CanvasImage texture) {
return new ButtonTexture(texture, texture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import java.nio.file.Files;

public class GuiTextures {
public static CanvasImage CLOSE_ICON;
public static CanvasImage CLOSE_ICON_HOVER;
public static CanvasImage CLOSE_ICON_ACTIVE;
public static CanvasImage CLOSE_ICON_ACTIVE_HOVER;
public static CanvasImage TERMINATE;
public static CanvasImage TERMINATE_HOVER;
public static ButtonTexture CLOSE_ICON;
public static ButtonTexture SHUTDOWN_ICON;
public static ButtonTexture SHUTDOWN_ACTIVE;
public static ButtonTexture TERMINATE;

public static ComputerTexture ADVANCED_COMPUTER;
public static ComputerTexture COMPUTER;
Expand All @@ -26,12 +24,12 @@ public class GuiTextures {
{
var buttons = CanvasImage.from(ImageIO.read(Files.newInputStream(texturePath.resolve("gui/buttons.png"))));

CLOSE_ICON = buttons.copy(0, 0, 14, 14);
CLOSE_ICON_HOVER = buttons.copy(0, 14, 14, 14);
CLOSE_ICON_ACTIVE = buttons.copy(14, 0, 14, 14);
CLOSE_ICON_ACTIVE_HOVER = buttons.copy(14, 14, 14, 14);
TERMINATE = buttons.copy(28, 0, 14, 14);
TERMINATE_HOVER = buttons.copy(28, 14, 14, 14);
SHUTDOWN_ICON = new ButtonTexture(buttons.copy(0, 0, 14, 14), buttons.copy(0, 14, 14, 14));
SHUTDOWN_ACTIVE = new ButtonTexture(buttons.copy(14, 0, 14, 14), buttons.copy(14, 14, 14, 14));
TERMINATE = new ButtonTexture(buttons.copy(28, 0, 14, 14), buttons.copy(28, 14, 14, 14));

var buttons2 = CanvasImage.from(ImageIO.read(Files.newInputStream(texturePath.resolve("gui/poly_buttons.png"))));
CLOSE_ICON = new ButtonTexture(buttons2.copy(0, 0, 14, 14), buttons2.copy(0, 14, 14, 14));

ADVANCED_COMPUTER = ComputerTexture.from(CanvasImage.from(ImageIO.read(Files.newInputStream(texturePath.resolve("gui/corners_advanced.png")))));
COMPUTER = ComputerTexture.from(CanvasImage.from(ImageIO.read(Files.newInputStream(texturePath.resolve("gui/corners_normal.png")))));
Expand All @@ -40,6 +38,7 @@ public class GuiTextures {
PRINTED_PAGE = PrintedPageTexture.from(CanvasImage.from(ImageIO.read(Files.newInputStream(texturePath.resolve("gui/printout.png")))));
}


} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b77381d

Please sign in to comment.