Skip to content

Commit

Permalink
HIHIHIHIHIHIHI this is so cool
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Nov 18, 2023
1 parent 28d9a2a commit 0d1c6a1
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.enjarai.minitardis.block.ModBlocks;
import dev.enjarai.minitardis.block.TardisAware;
import dev.enjarai.minitardis.canvas.ModCanvasUtils;
import dev.enjarai.minitardis.component.DestinationScanner;
import dev.enjarai.minitardis.component.Tardis;
import eu.pb4.mapcanvas.api.core.CanvasColor;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
Expand All @@ -17,12 +16,13 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ClickType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2i;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -149,8 +149,9 @@ private void handleClick(ServerPlayerEntity player, ClickType type, int x, int y
Optional.ofNullable(selectedApp).flatMap(controls::getScreenApp).ifPresentOrElse(app -> {
if (type == ClickType.RIGHT && x >= 96 + 2 && x < 96 + 2 + 28 && y >= 16 + 2 && y < 16 + 2 + 14) {
selectedApp = null;
playClickSound(0.5f);
} else {
app.onClick(controls, player, type, x, y - 16);
app.onClick(controls, this, player, type, x, y - 16);
}
}, () -> {
var apps = controls.getAllApps();
Expand All @@ -162,6 +163,7 @@ private void handleClick(ServerPlayerEntity player, ClickType type, int x, int y
if (x >= appX && x < appX + 24 && y >= appY && y < appY + 24) {
var app = apps.get(i);
selectedApp = app.id();
playClickSound(1.5f);
}
}
}
Expand All @@ -176,4 +178,10 @@ private int getAppX(int i) {
private int getAppY(int i) {
return 16 + 4;
}

public void playClickSound(float pitch) {
if (getWorld() instanceof ServerWorld serverWorld) {
serverWorld.playSound(null, getPos(), SoundEvents.BLOCK_NOTE_BLOCK_BIT.value(), SoundCategory.BLOCKS, 0.5f, pitch);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ModCanvasUtils {
public static final CanvasImage APP_BACKGROUND = loadImage("app_background.png");
public static final CanvasImage SCREEN_SIDE_BUTTON = loadImage("screen_side_button.png");
public static final CanvasImage SCREEN_SIDE_BUTTON_PRESSED = loadImage("screen_side_button_pressed.png");
public static final CanvasImage COORD_WIDGET = loadImage("coord_widget.png");
public static final CanvasImage COORD_WIDGET_X = loadImage("coord_widget_x.png");
public static final CanvasImage COORD_WIDGET_Z = loadImage("coord_widget_z.png");
public static final CanvasImage FACING_WIDGET = loadImage("facing_widget.png");

private static CanvasImage loadImage(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void useZAxis() {
isZAxis = true;
}

public boolean isZAxis() {
return isZAxis;
}

public void resetIterators() {
xIterator = newIterator();
zIterator = newIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public Optional<ScreenApp> getScreenApp(Identifier id) {
}

public List<ScreenApp> getAllApps() {
return ImmutableList.copyOf(screenApps.values());
return screenApps.values().stream().sorted(Comparator.comparing(ScreenApp::id)).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.enjarai.minitardis.component.screen;

import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.component.TardisControl;
import dev.enjarai.minitardis.component.screen.element.AppElement;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
Expand All @@ -23,9 +24,9 @@ public void draw(TardisControl controls, DrawableCanvas canvas) {
}

@Override
public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) {
public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) {
for (var element : children) {
if (element.onClick(controls, player, type, x, y)) {
if (element.onClick(controls, blockEntity, player, type, x, y)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import dev.enjarai.minitardis.MiniTardis;
import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.component.TardisControl;
import eu.pb4.mapcanvas.api.core.CanvasColor;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
Expand All @@ -24,7 +25,7 @@ public void draw(TardisControl controls, DrawableCanvas canvas) {
}

@Override
public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) {
public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import eu.pb4.mapcanvas.api.core.CanvasColor;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
import eu.pb4.mapcanvas.api.utils.CanvasUtils;
import eu.pb4.mapcanvas.impl.view.Rotate90ClockwiseView;
import eu.pb4.mapcanvas.impl.view.RotatedView;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -41,9 +42,14 @@ public void draw(TardisControl controls, DrawableCanvas canvas) {
canvas.set(DestinationScanner.RANGE / 2 - 1, DestinationScanner.RANGE / 2, CanvasColor.ORANGE_HIGH);
canvas.set(DestinationScanner.RANGE / 2 - 1, DestinationScanner.RANGE / 2 - 1, CanvasColor.ORANGE_HIGH);

CanvasUtils.draw(canvas, 96, 64, ModCanvasUtils.COORD_WIDGET);
controls.getTardis().getDestination().ifPresent(destination ->
CanvasUtils.draw(canvas, 96, 64, new RotatedView(ModCanvasUtils.FACING_WIDGET, Math.toRadians(destination.facing().asRotation()), 16, 16)));
CanvasUtils.draw(canvas, 96, 64, controls.getTardis().getDestinationScanner().isZAxis() ? ModCanvasUtils.COORD_WIDGET_Z : ModCanvasUtils.COORD_WIDGET_X);
controls.getTardis().getDestination().ifPresent(destination -> {
DrawableCanvas view = ModCanvasUtils.FACING_WIDGET;
for (int i = 0; i < destination.facing().getHorizontal(); i++) {
view = new Rotate90ClockwiseView(view);
}
CanvasUtils.draw(canvas, 96, 64, view);
});

super.draw(controls, canvas);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.enjarai.minitardis.component.screen;

import com.mojang.serialization.Codec;
import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.component.TardisControl;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -23,7 +24,7 @@ public interface ScreenApp {

void draw(TardisControl controls, DrawableCanvas canvas);

boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y);
boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y);

void drawIcon(TardisControl controls, DrawableCanvas canvas);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.enjarai.minitardis.component.screen.element;

import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.component.TardisControl;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -8,5 +9,5 @@
public interface AppElement {
void draw(TardisControl controls, DrawableCanvas canvas);

boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y);
boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.enjarai.minitardis.component.screen.element;

import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.component.TardisControl;
import eu.pb4.mapcanvas.api.core.DrawableCanvas;
import eu.pb4.mapcanvas.impl.view.SubView;
Expand Down Expand Up @@ -27,12 +28,12 @@ public void draw(TardisControl controls, DrawableCanvas canvas) {
protected abstract void drawElement(TardisControl controls, DrawableCanvas canvas);

@Override
public boolean onClick(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) {
public boolean onClick(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) {
if (x >= this.x && x < this.x + width && y >= this.y && y < this.y + height) {
return onClickElement(controls, player, type, x - this.x, y - this.y);
return onClickElement(controls, blockEntity, player, type, x - this.x, y - this.y);
}
return false;
}

protected abstract boolean onClickElement(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y);
protected abstract boolean onClickElement(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.enjarai.minitardis.component.screen.element;

import dev.enjarai.minitardis.block.console.ConsoleScreenBlockEntity;
import dev.enjarai.minitardis.canvas.ModCanvasUtils;
import dev.enjarai.minitardis.component.TardisControl;
import eu.pb4.mapcanvas.api.core.CanvasColor;
Expand Down Expand Up @@ -31,10 +32,11 @@ protected void drawElement(TardisControl controls, DrawableCanvas canvas) {
}

@Override
protected boolean onClickElement(TardisControl controls, ServerPlayerEntity player, ClickType type, int x, int y) {
protected boolean onClickElement(TardisControl controls, ConsoleScreenBlockEntity blockEntity, ServerPlayerEntity player, ClickType type, int x, int y) {
if (type == ClickType.RIGHT) {
pressedFrames = 2;
clickCallback.accept(controls);
blockEntity.playClickSound(1);
return true;
}
return false;
Expand Down
Binary file not shown.
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 0d1c6a1

Please sign in to comment.