Some more fixes and improvements

This commit is contained in:
Motschen
2022-12-26 22:27:58 +01:00
parent 29982f838d
commit cf917cae64
2 changed files with 19 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import com.igrium.videolib.VideoLib;
import eu.midnightdust.picturesign.config.PictureSignConfig;
import eu.midnightdust.picturesign.render.PictureSignRenderer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
@@ -30,12 +31,17 @@ public class PictureSignClient implements ClientModInitializer {
PictureSignConfig.init("picturesign", PictureSignConfig.class);
KeyBindingHelper.registerKeyBinding(BINDING_COPY_SIGN);
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
ClientLoginConnectionEvents.DISCONNECT.register((handler, client) -> {
PictureSignRenderer.videoPlayers.forEach(id -> {
VideoLib.getInstance().getVideoManager().closePlayer(id);
PictureSignRenderer.videoPlayers.remove(id);
});
});
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((blockEntity, world) -> {
BlockPos pos = blockEntity.getPos();
VideoLib.getInstance().getVideoManager().closePlayer(new Identifier("picturesign", pos.getX() + "." + pos.getY() + "." + pos.getZ()));
PictureSignRenderer.videoPlayers.remove(new Identifier("picturesign", pos.getX() + "." + pos.getY() + "." + pos.getZ()));
});
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!PictureSignClient.BINDING_COPY_SIGN.isPressed()) return;

View File

@@ -4,6 +4,7 @@ import eu.midnightdust.lib.util.MidnightColorUtil;
import eu.midnightdust.lib.util.screen.TexturedOverlayButtonWidget;
import eu.midnightdust.picturesign.PictureSignClient;
import eu.midnightdust.picturesign.config.PictureSignConfig;
import eu.midnightdust.picturesign.util.PictureSignType;
import eu.midnightdust.picturesign.util.PictureURLUtils;
import net.minecraft.block.BlockState;
import net.minecraft.block.SignBlock;
@@ -77,19 +78,23 @@ public class PictureSignHelperScreen extends Screen {
Objects.requireNonNull(client).setScreen(new SignEditScreen(this.sign,false));
}, Text.of("")));
this.addDrawableChild(new ButtonWidget(this.width / 2,this.height / 5 + 70,40,20, Text.of(text[0].startsWith("!PS:") ? "Image" : (text[0].startsWith("!VS:") ? "Video" : "Loop")), (buttonWidget) -> {
if (text[0].startsWith("!PS")) text[0] = "!VS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
else if (text[0].startsWith("!VS")) text[0] = "!LS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
else if (text[0].startsWith("!LS")) text[0] = "!PS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
if (text[0].startsWith("!PS:")) text[0] = "!VS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
else if (text[0].startsWith("!VS:")) text[0] = "!LS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
else if (text[0].startsWith("!LS:")) text[0] = "!PS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
else text[0] = "!PS:" + text[0].replace("!PS:","").replace("!VS:", "").replace("!LS:", "");
buttonWidget.setMessage(Text.of(text[0].startsWith("!PS:") ? "Image" : (text[0].startsWith("!VS:") ? "Video" : "Loop")));
sign.setTextOnRow(0, Text.of(text[0]));
}));
TextFieldWidget linkWidget = new TextFieldWidget(textRenderer,this.width / 2 - 175,this.height / 5 + 13,210,40, Text.of("url"));
TextFieldWidget linkWidget = new TextFieldWidget(textRenderer,this.width / 2 - 175,this.height / 5 + 13,215,40, Text.of("url"));
linkWidget.setMaxLength(900);
linkWidget.setText(PictureURLUtils.getLink(sign));
linkWidget.setChangedListener(s -> {
String[] lines = breakLink(PictureURLUtils.shortenLink(s));
String prefix = "";
if (text[0].startsWith("!PS:")) prefix = "!PS:";
else if (text[0].startsWith("!VS:")) prefix = "!VS:";
else if (text[0].startsWith("!LS:")) prefix = "!LS:";
String[] lines = breakLink(prefix, PictureURLUtils.shortenLink(s));
for (int i = 0; i < 3; i++) {
text[i] = lines[i];
sign.setTextOnRow(i, Text.of(text[i]));
@@ -203,8 +208,8 @@ public class PictureSignHelperScreen extends Screen {
clientPlayNetworkHandler.sendPacket(new UpdateSignC2SPacket(this.sign.getPos(), this.text[0], this.text[1], this.text[2], this.text[3]));
}
}
private String[] breakLink(String link) {
Text linkText = Text.of("!PS:"+link);
private String[] breakLink(String prefix, String link) {
Text linkText = Text.of(prefix+link);
String[] brokenLink = new String[3];
Text line0Text = linkText;
int line0width = line0Text.getString().length();