From 06925f9ffc786751f2f1f2bdc0766a422abc05e2 Mon Sep 17 00:00:00 2001 From: Nicolas BARBOTIN Date: Sat, 3 Feb 2018 17:50:42 +0100 Subject: [PATCH] * Preparing rotation thing --- README.md | 3 +- src/main/java/net/montoyo/wd/SharedProxy.java | 8 +- .../net/montoyo/wd/client/ClientProxy.java | 12 +- .../montoyo/wd/client/JSQueryDispatcher.java | 3 + .../wd/client/gui/GuiScreenConfig.java | 24 +- .../wd/client/renderers/ScreenRenderer.java | 17 +- .../net/montoyo/wd/core/ScreenRights.java | 4 +- .../montoyo/wd/entity/TileEntityScreen.java | 39 +- .../net/montoyo/wd/net/CMessageAddScreen.java | 5 +- .../montoyo/wd/net/CMessageScreenUpdate.java | 20 +- .../montoyo/wd/net/SMessageScreenCtrl.java | 39 +- .../net/montoyo/wd/utilities/BlockSide.java | 5 + .../net/montoyo/wd/utilities/Rotation.java | 28 ++ .../assets/webdisplays/gui/screencfg.json | 356 +++++++++--------- .../assets/webdisplays/html/wdlib.js | 18 + .../assets/webdisplays/lang/en_us.lang | 5 + 16 files changed, 390 insertions(+), 196 deletions(-) create mode 100644 src/main/java/net/montoyo/wd/utilities/Rotation.java diff --git a/README.md b/README.md index e6af8da..e51fda2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex * Read config (see "Config elements" below) ### TODO -* Center camera to screen when using keyboard * Top/bottom screen orientation * GuiSetURL2 missing buttons * Automatically add protocol to URLs @@ -32,3 +31,5 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex * Plugin API * The Shop * CC Interface, if CC gets updated... +* Center camera to screen when using keyboard + diff --git a/src/main/java/net/montoyo/wd/SharedProxy.java b/src/main/java/net/montoyo/wd/SharedProxy.java index cb93c5f..292e34e 100644 --- a/src/main/java/net/montoyo/wd/SharedProxy.java +++ b/src/main/java/net/montoyo/wd/SharedProxy.java @@ -15,10 +15,7 @@ import net.montoyo.wd.core.HasAdvancement; import net.montoyo.wd.core.JSServerRequest; import net.montoyo.wd.data.GuiData; import net.montoyo.wd.entity.TileEntityScreen; -import net.montoyo.wd.utilities.BlockSide; -import net.montoyo.wd.utilities.NameUUIDPair; -import net.montoyo.wd.utilities.Vector2i; -import net.montoyo.wd.utilities.Vector3i; +import net.montoyo.wd.utilities.*; import javax.annotation.Nonnull; @@ -63,6 +60,9 @@ public class SharedProxy { public void screenUpdateResolutionInGui(Vector3i pos, BlockSide side, Vector2i res) { } + public void screenUpdateRotationInGui(Vector3i pos, BlockSide side, Rotation rot) { + } + public void displaySetPadURLGui(String padURL) { Log.error("Called SharedProxy.displaySetPadURLGui() on server side..."); } diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index c69394f..67900c3 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -202,6 +202,16 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi } } + @Override + public void screenUpdateRotationInGui(Vector3i pos, BlockSide side, Rotation rot) { + if(mc.currentScreen != null && mc.currentScreen instanceof GuiScreenConfig) { + GuiScreenConfig gsc = (GuiScreenConfig) mc.currentScreen; + + if(gsc.isScreen(pos, side)) + gsc.updateRotation(rot); + } + } + @Override public void displaySetPadURLGui(String padURL) { mc.displayGuiScreen(new GuiSetURL2(padURL)); @@ -288,7 +298,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi /**************************************** RESOURCE MANAGER METHODS ****************************************/ @Override - public void onResourceManagerReload(IResourceManager rm) { + public void onResourceManagerReload(@Nonnull IResourceManager rm) { Log.info("Resource manager reload: clearing GUI cache..."); GuiLoader.clearCache(); } diff --git a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java index a9e3346..bdf6650 100644 --- a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java +++ b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java @@ -347,6 +347,9 @@ public final class JSQueryDispatcher { boolean res = (tes.getScreen(side).owner != null && tes.getScreen(side).owner.uuid.equals(mc.player.getGameProfile().getId())); cb.success("{\"isOwner\":" + (res ? "true}" : "false}")); }); + + register("GetRotation", (cb, tes, side, args) -> cb.success("{\"rotation\":" + tes.getScreen(side).rotation.ordinal() + "}")); + register("GetSide", (cb, tes, side, args) -> cb.success("{\"side\":" + tes.getScreen(side).side.ordinal() + "}")); } } diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java index da00b3b..e0d3270 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java @@ -5,6 +5,7 @@ package net.montoyo.wd.client.gui; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.gui.controls.*; @@ -27,6 +28,7 @@ public class GuiScreenConfig extends WDScreen { private NameUUIDPair[] friends; private int friendRights; private int otherRights; + private Rotation rotation = Rotation.ROT_0; //Autocomplete handling private boolean waitingAC; @@ -96,6 +98,9 @@ public class GuiScreenConfig extends WDScreen { @FillControl private UpgradeGroup ugUpgrades; + @FillControl + private Button btnChangeRot; + private CheckBox[] friendBoxes; private CheckBox[] otherBoxes; @@ -129,6 +134,8 @@ public class GuiScreenConfig extends WDScreen { TileEntityScreen.Screen scr = tes.getScreen(side); if(scr != null) { owner = scr.owner; + rotation = scr.rotation; + tfResX.setText("" + scr.resolution.x); tfResY.setText("" + scr.resolution.y); @@ -139,7 +146,7 @@ public class GuiScreenConfig extends WDScreen { if(owner == null) owner = new NameUUIDPair("???", UUID.randomUUID()); - lblOwner.setLabel(lblOwner.getLabel() + owner.name); + lblOwner.setLabel(lblOwner.getLabel() + ' ' + owner.name); for(NameUUIDPair f : friends) lstFriends.addElementRaw(f.name, f); @@ -147,10 +154,15 @@ public class GuiScreenConfig extends WDScreen { updateRights(friendRights, friendRights, friendBoxes, true); updateRights(otherRights, otherRights, otherBoxes, true); updateMyRights(); + updateRotationStr(); mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(WebDisplays.INSTANCE.soundScreenCfg, 1.0f, 1.0f)); } + private void updateRotationStr() { + btnChangeRot.setLabel(I18n.format("webdisplays.gui.screencfg.rot" + rotation.getAngleAsInt())); + } + private void addFriend(String name) { if(!name.isEmpty()) { requestAutocomplete(name, true); @@ -188,6 +200,10 @@ public class GuiScreenConfig extends WDScreen { addFriend(tfFriend.getText().trim()); else if(ev.getSource() == btnSetRes) clickSetRes(); + else if(ev.getSource() == btnChangeRot) { + Rotation[] rots = Rotation.values(); + WebDisplays.NET_HANDLER.sendToServer(new SMessageScreenCtrl(tes, side, rots[(rotation.ordinal() + 1) % rots.length])); + } } @GuiSubscribe @@ -419,6 +435,7 @@ public class GuiScreenConfig extends WDScreen { flag = (myRights & ScreenRights.CHANGE_RESOLUTION) == 0; tfResX.setDisabled(flag); tfResY.setDisabled(flag); + btnChangeRot.setDisabled(flag); if(flag) btnSetRes.setDisabled(true); @@ -433,4 +450,9 @@ public class GuiScreenConfig extends WDScreen { btnSetRes.setDisabled(true); } + public void updateRotation(Rotation rot) { + rotation = rot; + updateRotationStr(); + } + } diff --git a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java index c8e781a..1364133 100644 --- a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java +++ b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java @@ -14,6 +14,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.ClientProxy; import net.montoyo.wd.entity.TileEntityScreen; +import net.montoyo.wd.utilities.Rotation; import net.montoyo.wd.utilities.Vector3f; import net.montoyo.wd.utilities.Vector3i; @@ -41,7 +42,12 @@ public class ScreenRenderer extends TileEntitySpecialRenderer TileEntityScreen.Screen scr = te.getScreen(i); if(scr.browser == null) { scr.browser = ((ClientProxy) WebDisplays.PROXY).getMCEF().createBrowser(scr.url); - scr.browser.resize(scr.resolution.x, scr.resolution.y); + + if(scr.rotation.isVertical) + scr.browser.resize(scr.resolution.y, scr.resolution.x); + else + scr.browser.resize(scr.resolution.x, scr.resolution.y); + scr.doTurnOnAnim = true; scr.turnOnTime = System.currentTimeMillis(); } @@ -98,9 +104,18 @@ public class ScreenRenderer extends TileEntitySpecialRenderer glScalef(ft, ft, 1.0f); } + if(!scr.rotation.isNull) + glRotatef(scr.rotation.angle, 0.0f, 0.0f, 1.0f); + float sw = ((float) scr.size.x) * 0.5f - 2.f / 16.f; float sh = ((float) scr.size.y) * 0.5f - 2.f / 16.f; + if(scr.rotation.isVertical) { + float tmp = sw; + sw = sh; + sh = tmp; + } + //TODO: Use tesselator glBindTexture(GL_TEXTURE_2D, scr.browser.getTextureID()); glBegin(GL_QUADS); diff --git a/src/main/java/net/montoyo/wd/core/ScreenRights.java b/src/main/java/net/montoyo/wd/core/ScreenRights.java index db04b73..9b6ae36 100644 --- a/src/main/java/net/montoyo/wd/core/ScreenRights.java +++ b/src/main/java/net/montoyo/wd/core/ScreenRights.java @@ -7,11 +7,11 @@ package net.montoyo.wd.core; public abstract class ScreenRights { public static final int CHANGE_URL = 1; - public static final int CLICK = 2; + public static final int CLICK = 2; //Click AND type public static final int MANAGE_FRIEND_LIST = 4; public static final int MANAGE_OTHER_RIGHTS = 8; public static final int MANAGE_UPGRADES = 16; - public static final int CHANGE_RESOLUTION = 32; + public static final int CHANGE_RESOLUTION = 32; //Change resolution AND rotation public static final int NONE = 0; public static final int ALL = 0xFF; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index f6468bb..4e670a5 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -30,6 +30,7 @@ import net.montoyo.wd.net.CMessageJSResponse; import net.montoyo.wd.net.CMessageScreenUpdate; import net.montoyo.wd.net.SMessageRequestTEData; import net.montoyo.wd.utilities.*; +import net.montoyo.wd.utilities.Rotation; import javax.annotation.Nullable; import java.util.*; @@ -41,6 +42,7 @@ public class TileEntityScreen extends TileEntity { public BlockSide side; public Vector2i size; public Vector2i resolution; + public Rotation rotation = Rotation.ROT_0; public String url; private VideoType videoType; public NameUUIDPair owner; @@ -60,6 +62,7 @@ public class TileEntityScreen extends TileEntity { ret.side = BlockSide.values()[tag.getByte("Side")]; ret.size = new Vector2i(tag.getInteger("Width"), tag.getInteger("Height")); ret.resolution = new Vector2i(tag.getInteger("ResolutionX"), tag.getInteger("ResolutionY")); + ret.rotation = Rotation.values()[tag.getByte("Rotation")]; ret.url = tag.getString("URL"); ret.videoType = VideoType.getTypeFromURL(ret.url); @@ -109,6 +112,7 @@ public class TileEntityScreen extends TileEntity { tag.setInteger("Height", size.y); tag.setInteger("ResolutionX", resolution.x); tag.setInteger("ResolutionY", resolution.y); + tag.setByte("Rotation", (byte) rotation.ordinal()); tag.setString("URL", url); if(owner == null) @@ -353,7 +357,7 @@ public class TileEntityScreen extends TileEntity { if(!world.isRemote) { if(screens.isEmpty()) //No more screens: remove tile entity - world.setBlockState(getPos(), WebDisplays.INSTANCE.blockScreen.getDefaultState().withProperty(BlockScreen.hasTE, false)); + world.setBlockState(pos, WebDisplays.INSTANCE.blockScreen.getDefaultState().withProperty(BlockScreen.hasTE, false)); else markDirty(); } @@ -374,7 +378,7 @@ public class TileEntityScreen extends TileEntity { scr.resolution = res; if(world.isRemote) { - WebDisplays.PROXY.screenUpdateResolutionInGui(new Vector3i(getPos()), side, res); + WebDisplays.PROXY.screenUpdateResolutionInGui(new Vector3i(pos), side, res); if(scr.browser != null) { scr.browser.close(); @@ -638,7 +642,7 @@ public class TileEntityScreen extends TileEntity { super.validate(); if(world.isRemote) - Log.info("===> TES( VALIDATE) %s", getPos().toString()); + Log.info("===> TES( VALIDATE) %s", pos.toString()); }*/ @Override @@ -646,7 +650,7 @@ public class TileEntityScreen extends TileEntity { super.invalidate(); if(world.isRemote) { - Log.info("===> TES(INVALIDATE) %s", getPos().toString()); + Log.info("===> TES(INVALIDATE) %s", pos.toString()); onChunkUnload(); } } @@ -801,6 +805,7 @@ public class TileEntityScreen extends TileEntity { WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point()); itemAsUpgrade.onInstall(this, side, player, isCopy); playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, pos, 1.0f, 1.0f); + markDirty(); return true; } @@ -854,6 +859,7 @@ public class TileEntityScreen extends TileEntity { scr.upgrades.remove(idxToRemove); WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.upgrade(this, side), point()); playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, pos, 1.0f, 1.0f); + markDirty(); } else Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString()); } @@ -957,6 +963,31 @@ public class TileEntityScreen extends TileEntity { scr.owner = new NameUUIDPair(newOwner.getGameProfile()); WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.owner(this, side, scr.owner), point()); checkLaserUserRights(scr); + markDirty(); + } + + public void setRotation(BlockSide side, Rotation rot) { + Screen scr = getScreen(side); + if(scr == null) { + Log.error("Trying to change rotation of invalid screen on side %s", side.toString()); + return; + } + + if(world.isRemote) { + boolean oldWasVertical = scr.rotation.isVertical; + scr.rotation = rot; + + WebDisplays.PROXY.screenUpdateRotationInGui(new Vector3i(pos), side, rot); + + if(scr.browser != null && oldWasVertical != rot.isVertical) { + scr.browser.close(); + scr.browser = null; //Will be re-created by renderer + } + } else { + scr.rotation = rot; + WebDisplays.NET_HANDLER.sendToAllAround(CMessageScreenUpdate.rotation(this, side, rot), point()); + markDirty(); + } } } diff --git a/src/main/java/net/montoyo/wd/net/CMessageAddScreen.java b/src/main/java/net/montoyo/wd/net/CMessageAddScreen.java index 23d1ccc..14681da 100644 --- a/src/main/java/net/montoyo/wd/net/CMessageAddScreen.java +++ b/src/main/java/net/montoyo/wd/net/CMessageAddScreen.java @@ -55,6 +55,7 @@ public class CMessageAddScreen implements IMessage, Runnable { screens[i].size = new Vector2i(buf); screens[i].url = ByteBufUtils.readUTF8String(buf); screens[i].resolution = new Vector2i(buf); + screens[i].rotation = Rotation.values()[buf.readByte() & 3]; screens[i].owner = new NameUUIDPair(buf); screens[i].upgrades = new ArrayList<>(); @@ -75,6 +76,7 @@ public class CMessageAddScreen implements IMessage, Runnable { scr.size.writeTo(buf); ByteBufUtils.writeUTF8String(buf, scr.url); scr.resolution.writeTo(buf); + buf.writeByte(scr.rotation.ordinal()); scr.owner.writeTo(buf); buf.writeByte(scr.upgrades.size()); @@ -99,9 +101,10 @@ public class CMessageAddScreen implements IMessage, Runnable { for(TileEntityScreen.Screen entry: screens) { TileEntityScreen.Screen scr = tes.addScreen(entry.side, entry.size, entry.resolution, null, false); + scr.rotation = entry.rotation; scr.url = entry.url; - scr.upgrades = entry.upgrades; scr.owner = entry.owner; + scr.upgrades = entry.upgrades; if(scr.browser != null) scr.browser.loadURL(entry.url); diff --git a/src/main/java/net/montoyo/wd/net/CMessageScreenUpdate.java b/src/main/java/net/montoyo/wd/net/CMessageScreenUpdate.java index 81f25a0..06d8b46 100644 --- a/src/main/java/net/montoyo/wd/net/CMessageScreenUpdate.java +++ b/src/main/java/net/montoyo/wd/net/CMessageScreenUpdate.java @@ -29,6 +29,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable { public static final int UPDATE_UPGRADES = 5; public static final int UPDATE_JS_REDSTONE = 6; public static final int UPDATE_OWNER = 7; + public static final int UPDATE_ROTATION = 8; public static final int MOUSE_CLICK = 0; public static final int MOUSE_UP = 1; @@ -45,6 +46,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable { private ItemStack[] upgrades; private int redstoneLevel; private NameUUIDPair owner; + private Rotation rotation; public CMessageScreenUpdate() { } @@ -132,6 +134,16 @@ public class CMessageScreenUpdate implements IMessage, Runnable { return ret; } + public static CMessageScreenUpdate rotation(TileEntityScreen tes, BlockSide side, Rotation rot) { + CMessageScreenUpdate ret = new CMessageScreenUpdate(); + ret.pos = new Vector3i(tes.getPos()); + ret.side = side; + ret.action = UPDATE_ROTATION; + ret.rotation = rot; + + return ret; + } + @Override public void fromBytes(ByteBuf buf) { pos = new Vector3i(buf); @@ -159,6 +171,8 @@ public class CMessageScreenUpdate implements IMessage, Runnable { redstoneLevel = buf.readByte(); } else if(action == UPDATE_OWNER) owner = new NameUUIDPair(buf); + else if(action == UPDATE_ROTATION) + rotation = Rotation.values()[buf.readByte() & 3]; } @Override @@ -188,6 +202,8 @@ public class CMessageScreenUpdate implements IMessage, Runnable { buf.writeByte(redstoneLevel); } else if(action == UPDATE_OWNER) owner.writeTo(buf); + else if(action == UPDATE_ROTATION) + buf.writeByte(rotation.ordinal()); } @Override @@ -224,7 +240,9 @@ public class CMessageScreenUpdate implements IMessage, Runnable { if(scr != null) scr.owner = owner; - } else + } else if(action == UPDATE_ROTATION) + tes.setRotation(side, rotation); + else Log.warning("===> TODO"); //TODO } diff --git a/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java b/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java index ff25bfd..7b4829b 100644 --- a/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java +++ b/src/main/java/net/montoyo/wd/net/SMessageScreenCtrl.java @@ -37,6 +37,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable { public static final int CTRL_LASER_MOVE = 9; public static final int CTRL_LASER_UP = 10; public static final int CTRL_JS_REQUEST = 11; + public static final int CTRL_SET_ROTATION = 12; private int ctrl; private int dim; @@ -54,6 +55,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable { private int jsReqID; private JSServerRequest jsReqType; private Object[] jsReqData; + private Rotation rotation; public SMessageScreenCtrl() { } @@ -99,6 +101,14 @@ public class SMessageScreenCtrl implements IMessage, Runnable { toRemove = toRem; } + public SMessageScreenCtrl(TileEntityScreen tes, BlockSide side, Rotation rot) { + ctrl = CTRL_SET_ROTATION; + dim = tes.getWorld().provider.getDimension(); + pos = new Vector3i(tes.getPos()); + this.side = side; + rotation = rot; + } + public static SMessageScreenCtrl type(TileEntityScreen tes, BlockSide side, String text, BlockPos soundPos) { SMessageScreenCtrl ret = new SMessageScreenCtrl(); ret.ctrl = CTRL_TYPE; @@ -157,7 +167,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable { ctrl = buf.readByte(); dim = buf.readInt(); pos = new Vector3i(buf); - side = BlockSide.values()[buf.readByte()]; + side = BlockSide.fromInt(buf.readByte()); if(ctrl == CTRL_SET_URL) url = ByteBufUtils.readUTF8String(buf); @@ -183,7 +193,8 @@ public class SMessageScreenCtrl implements IMessage, Runnable { if(jsReqType != null) jsReqData = jsReqType.deserialize(buf); - } + } else if(ctrl == CTRL_SET_ROTATION) + rotation = Rotation.values()[buf.readByte() & 3]; } @Override @@ -215,11 +226,17 @@ public class SMessageScreenCtrl implements IMessage, Runnable { if(!jsReqType.serialize(buf, jsReqData)) throw new RuntimeException("Could not serialize CTRL_JS_REQUEST " + jsReqType); - } + } else if(ctrl == CTRL_SET_ROTATION) + buf.writeByte(rotation.ordinal()); } @Override public void run() { + if(side == null) { + Log.warning("Caught invalid packet from %s (UUID %s) referencing an invalid block side", player.getName(), player.getGameProfile().getId().toString()); + return; + } + try { runUnsafe(); } catch(MissingPermissionException e) { @@ -242,7 +259,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable { TileEntity te = world.getTileEntity(bp); if(te == null || !(te instanceof TileEntityScreen)) { - Log.error("TileEntity at %s is not a screen; can't change url!", pos.toString()); + Log.error("TileEntity at %s is not a screen; can't control it!", pos.toString()); return; } @@ -262,11 +279,14 @@ public class SMessageScreenCtrl implements IMessage, Runnable { tes.removeFriend(player, side, friend); } else if(ctrl == CTRL_SET_RIGHTS) { TileEntityScreen.Screen scr = tes.getScreen(side); - int fr = scr.owner.uuid.equals(player.getGameProfile().getId()) ? friendRights : scr.friendRights; - int or = (scr.rightsFor(player) & ScreenRights.MANAGE_OTHER_RIGHTS) == 0 ? scr.otherRights : otherRights; - if(scr.friendRights != fr || scr.otherRights != or) - tes.setRights(player, side, fr, or); + if(scr != null) { + int fr = scr.owner.uuid.equals(player.getGameProfile().getId()) ? friendRights : scr.friendRights; + int or = (scr.rightsFor(player) & ScreenRights.MANAGE_OTHER_RIGHTS) == 0 ? scr.otherRights : otherRights; + + if(scr.friendRights != fr || scr.otherRights != or) + tes.setRights(player, side, fr, or); + } } else if(ctrl == CTRL_SET_RESOLUTION) { checkPermission(tes, ScreenRights.CHANGE_RESOLUTION); tes.setResolution(side, vec2i); @@ -285,6 +305,9 @@ public class SMessageScreenCtrl implements IMessage, Runnable { Log.warning("Caught invalid JS request from player %s (UUID %s)", player.getName(), player.getGameProfile().getId().toString()); else tes.handleJSRequest(player, side, jsReqID, jsReqType, jsReqData); + } else if(ctrl == CTRL_SET_ROTATION) { + checkPermission(tes, ScreenRights.CHANGE_RESOLUTION); + tes.setRotation(side, rotation); } else Log.info("SMessageScreenCtrl: TODO"); //TODO: other ctrl messages } diff --git a/src/main/java/net/montoyo/wd/utilities/BlockSide.java b/src/main/java/net/montoyo/wd/utilities/BlockSide.java index 87466a8..90b602b 100644 --- a/src/main/java/net/montoyo/wd/utilities/BlockSide.java +++ b/src/main/java/net/montoyo/wd/utilities/BlockSide.java @@ -45,4 +45,9 @@ public enum BlockSide { return div * 2 + rest; } + public static BlockSide fromInt(int s) { + BlockSide[] values = values(); + return (s < 0 || s >= values.length) ? null : values[s]; + } + } diff --git a/src/main/java/net/montoyo/wd/utilities/Rotation.java b/src/main/java/net/montoyo/wd/utilities/Rotation.java new file mode 100644 index 0000000..e098254 --- /dev/null +++ b/src/main/java/net/montoyo/wd/utilities/Rotation.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 BARBOTIN Nicolas + */ + +package net.montoyo.wd.utilities; + +public enum Rotation { + + ROT_0(0.0f, false), + ROT_90(90.0f, true), + ROT_180(180.0f, false), + ROT_270(270.0f, true); + + public final float angle; + public final boolean isVertical; + public final boolean isNull; + + Rotation(float a, boolean v) { + angle = a; + isVertical = v; + isNull = (a == 0.0f); + } + + public int getAngleAsInt() { + return (int) angle; + } + +} diff --git a/src/main/resources/assets/webdisplays/gui/screencfg.json b/src/main/resources/assets/webdisplays/gui/screencfg.json index 7ac56e8..07fd00f 100644 --- a/src/main/resources/assets/webdisplays/gui/screencfg.json +++ b/src/main/resources/assets/webdisplays/gui/screencfg.json @@ -1,186 +1,198 @@ { - "controls": [ + "controls": [ + { + "type": "Label", + "name": "lblOwner", + "label": "$webdisplays.gui.screencfg.owner", + "x": 0, + "y": 0, + "shadowed": true + }, + { + "type": "Label", + "label": "$webdisplays.gui.screencfg.friends", + "x": 0, + "y": 12 + }, + { + "type": "List", + "name": "lstFriends", + "x": 0, + "y": 24, + "width": 100, + "height": 170, + "selectionColor": "red" + }, + { + "type": "TextField", + "name": "tfFriend", + "x": 0, + "y": 198, + "width": 76, + "maxLength": 128 + }, + { + "type": "Button", + "name": "btnAdd", + "x": 80, + "y": 199, + "width": 20, + "label": "+" + }, + { + "type": "Label", + "x": 104, + "y": 12, + "label": "$webdisplays.gui.screencfg.permissions" + }, + { + "type": "ControlGroup", + "name": "grpFriends", + "x": 104, + "y": 24, + "label": "$webdisplays.gui.screencfg.friends", + "width": 150, + "height": 112, + "childs": [ { - "type": "Label", - "name": "lblOwner", - "label": "$webdisplays.gui.screencfg.owner", - "x": 0, - "y": 0, - "shadowed": true + "type": "CheckBox", + "name": "boxFSetUrl", + "x": 0, + "y": 0, + "label": "$webdisplays.gui.screencfg.seturl" }, { - "type": "Label", - "label": "$webdisplays.gui.screencfg.friends", - "x": 0, - "y": 12 + "type": "CheckBox", + "name": "boxFClick", + "x": 0, + "y": 16, + "label": "$webdisplays.gui.screencfg.click" }, { - "type": "List", - "name": "lstFriends", - "x": 0, - "y": 24, - "width": 100, - "height": 170, - "selectionColor": "red" + "type": "CheckBox", + "name": "boxFFriends", + "x": 0, + "y": 32, + "label": "$webdisplays.gui.screencfg.friendlist" }, { - "type": "TextField", - "name": "tfFriend", - "x": 0, - "y": 198, - "width": 76, - "maxLength": 128 + "type": "CheckBox", + "name": "boxFOthers", + "x": 0, + "y": 48, + "label": "$webdisplays.gui.screencfg.otherrights" }, { - "type": "Button", - "name": "btnAdd", - "x": 80, - "y": 199, - "width": 20, - "label": "+" + "type": "CheckBox", + "name": "boxFUpgrades", + "x": 0, + "y": 64, + "label": "$webdisplays.gui.screencfg.mupgrades" }, { - "type": "Label", - "x": 104, - "y": 12, - "label": "$webdisplays.gui.screencfg.permissions" - }, - { - "type": "ControlGroup", - "name": "grpFriends", - "x": 104, - "y": 24, - "label": "$webdisplays.gui.screencfg.friends", - "width": 150, - "height": 112, - "childs": [ - { - "type": "CheckBox", - "name": "boxFSetUrl", - "x": 0, - "y": 0, - "label": "$webdisplays.gui.screencfg.seturl" - }, - { - "type": "CheckBox", - "name": "boxFClick", - "x": 0, - "y": 16, - "label": "$webdisplays.gui.screencfg.click" - }, - { - "type": "CheckBox", - "name": "boxFFriends", - "x": 0, - "y": 32, - "label": "$webdisplays.gui.screencfg.friendlist" - }, - { - "type": "CheckBox", - "name": "boxFOthers", - "x": 0, - "y": 48, - "label": "$webdisplays.gui.screencfg.otherrights" - }, - { - "type": "CheckBox", - "name": "boxFUpgrades", - "x": 0, - "y": 64, - "label": "$webdisplays.gui.screencfg.mupgrades" - }, - { - "type": "CheckBox", - "name": "boxFResolution", - "x": 0, - "y": 80, - "label": "$webdisplays.gui.screencfg.mres" - } - ] - }, - { - "type": "ControlGroup", - "name": "grpOthers", - "x": 104, - "y": 140, - "label": "$webdisplays.gui.screencfg.others", - "width": 150, - "height": 80, - "childs": [ - { - "type": "CheckBox", - "name": "boxOSetUrl", - "x": 0, - "y": 0, - "label": "$webdisplays.gui.screencfg.seturl" - }, - { - "type": "CheckBox", - "name": "boxOClick", - "x": 0, - "y": 16, - "label": "$webdisplays.gui.screencfg.click" - }, - { - "type": "CheckBox", - "name": "boxOUpgrades", - "x": 0, - "y": 32, - "label": "$webdisplays.gui.screencfg.mupgrades" - }, - { - "type": "CheckBox", - "name": "boxOResolution", - "x": 0, - "y": 48, - "label": "$webdisplays.gui.screencfg.mres" - } - ] - }, - { - "type": "Label", - "x": 258, - "y": 12, - "label": "$webdisplays.gui.screencfg.upgrades" - }, - { - "type": "UpgradeGroup", - "name": "ugUpgrades", - "x": 258, - "y": 23 - }, - { - "type": "Label", - "x": 258, - "y": 42, - "label": "$webdisplays.gui.screencfg.resolution" - }, - { - "type": "TextField", - "name": "tfResX", - "x": 260, - "y": 54, - "width": 40, - "maxLength": 4 - }, - { - "type": "TextField", - "name": "tfResY", - "x": 304, - "y": 54, - "width": 40, - "maxLength": 4 - }, - { - "type": "Button", - "name": "btnSetRes", - "x": 260, - "y": 78, - "width": 84, - "label": "$webdisplays.gui.screencfg.setres", - "disabled": true + "type": "CheckBox", + "name": "boxFResolution", + "x": 0, + "y": 80, + "label": "$webdisplays.gui.screencfg.mres" } - ], - - "center": true + ] + }, + { + "type": "ControlGroup", + "name": "grpOthers", + "x": 104, + "y": 140, + "label": "$webdisplays.gui.screencfg.others", + "width": 150, + "height": 80, + "childs": [ + { + "type": "CheckBox", + "name": "boxOSetUrl", + "x": 0, + "y": 0, + "label": "$webdisplays.gui.screencfg.seturl" + }, + { + "type": "CheckBox", + "name": "boxOClick", + "x": 0, + "y": 16, + "label": "$webdisplays.gui.screencfg.click" + }, + { + "type": "CheckBox", + "name": "boxOUpgrades", + "x": 0, + "y": 32, + "label": "$webdisplays.gui.screencfg.mupgrades" + }, + { + "type": "CheckBox", + "name": "boxOResolution", + "x": 0, + "y": 48, + "label": "$webdisplays.gui.screencfg.mres" + } + ] + }, + { + "type": "Label", + "x": 258, + "y": 12, + "label": "$webdisplays.gui.screencfg.upgrades" + }, + { + "type": "UpgradeGroup", + "name": "ugUpgrades", + "x": 258, + "y": 23 + }, + { + "type": "Label", + "x": 258, + "y": 42, + "label": "$webdisplays.gui.screencfg.resolution" + }, + { + "type": "TextField", + "name": "tfResX", + "x": 260, + "y": 54, + "width": 40, + "maxLength": 4 + }, + { + "type": "TextField", + "name": "tfResY", + "x": 304, + "y": 54, + "width": 40, + "maxLength": 4 + }, + { + "type": "Button", + "name": "btnSetRes", + "x": 260, + "y": 78, + "width": 84, + "label": "$webdisplays.gui.screencfg.setres", + "disabled": true + }, + { + "type": "Label", + "x": 258, + "y": 105, + "label": "$webdisplays.gui.screencfg.rotation" + }, + { + "type": "Button", + "name": "btnChangeRot", + "x": 260, + "y": 117, + "width": 84 + } + ], + "center": true } diff --git a/src/main/resources/assets/webdisplays/html/wdlib.js b/src/main/resources/assets/webdisplays/html/wdlib.js index 90f7c06..07f050d 100644 --- a/src/main/resources/assets/webdisplays/html/wdlib.js +++ b/src/main/resources/assets/webdisplays/html/wdlib.js @@ -37,6 +37,24 @@ function wdIsOwner(callback) { }); } +function wdGetRotation(callback) { + //Rotation: 0 is 0deg, 1 is 90deg, 2 is 180deg, and 3 is 270deg + //Rotations are counter-clockwise (trigonometric direction) + + wdExecRequest("GetRotation", function(resp) { + callback(resp.rotation); + }); +} + +function wdGetSide(callback) { + //Side: 0 is Bottom, 1 is Top, 2 is North, 3 is South, 4 is West and 5 is East + //FYI: North is Z-, South Z+, West is X- and East X+ + + wdExecRequest("GetSide", function(resp) { + callback(resp.side); + }); +} + //Requires upgrade: webdisplays:redinput function wdGetRedstoneAt(x, y, callback) { wdExecRequest("GetRedstoneAt(" + x + "," + y + ")", function(resp) { diff --git a/src/main/resources/assets/webdisplays/lang/en_us.lang b/src/main/resources/assets/webdisplays/lang/en_us.lang index b008a66..329002f 100644 --- a/src/main/resources/assets/webdisplays/lang/en_us.lang +++ b/src/main/resources/assets/webdisplays/lang/en_us.lang @@ -61,6 +61,11 @@ webdisplays.gui.screencfg.others=Others webdisplays.gui.screencfg.upgrades=Upgrades: webdisplays.gui.screencfg.resolution=Resolution: webdisplays.gui.screencfg.setres=Set Resolution +webdisplays.gui.screencfg.rotation=Rotation +webdisplays.gui.screencfg.rot0=0° +webdisplays.gui.screencfg.rot90=90° +webdisplays.gui.screencfg.rot180=180° +webdisplays.gui.screencfg.rot270=270° webdisplays.linker.selectScreen=Right click on a screen webdisplays.linker.selectPeripheral=Right click on a peripheral webdisplays.linker.posInfo=Screen pos: %d %d %d