From 24f6d6d730e41bb95d84b9f697441c5c4953c447 Mon Sep 17 00:00:00 2001 From: Fabian Pietsch Date: Wed, 17 Feb 2021 23:31:55 +0100 Subject: [PATCH 1/4] Use channel number (not index) in Router GUI .., for consistency with the Controller GUI. --- .../java/mcjty/xnet/modules/router/client/GuiRouter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java index 6ca82859..822d5315 100644 --- a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java +++ b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java @@ -116,6 +116,7 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local BlockPos controllerPos = channel.getPos(); IChannelType type = channel.getChannelType(); int index = channel.getIndex(); + String num = String.valueOf(index + 1); Panel panel = positional().desiredHeight(30); Panel panel1 = horizontal(0, 0).hint(0, 0, 160, 13); @@ -146,8 +147,8 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local Panel panel3 = horizontal(0, 0).hint(0, 26, 160, 13) .children( - label("Index").color(labelColor), - label(index + " (" + type.getName() + ")")); + label("Num").color(labelColor), + label(num + " (" + type.getName() + ")")); panel.children(panel1, panel2, panel3); return panel; From 68d02348a2df5d7b37d232eb68e6a951a4cc94ad Mon Sep 17 00:00:00 2001 From: Fabian Pietsch Date: Thu, 18 Feb 2021 00:40:16 +0100 Subject: [PATCH 2/4] Represent channel num/type in Router GUI as in Controller GUI --- .../xnet/modules/router/client/GuiRouter.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java index 822d5315..eb147fbd 100644 --- a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java +++ b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java @@ -5,12 +5,15 @@ import mcjty.lib.gui.GenericGuiContainer; import mcjty.lib.gui.Window; import mcjty.lib.gui.widgets.ImageLabel; +import mcjty.lib.gui.widgets.Label; import mcjty.lib.gui.widgets.Panel; import mcjty.lib.gui.widgets.TextField; import mcjty.lib.gui.widgets.WidgetList; import mcjty.lib.typed.TypedMap; import mcjty.lib.varia.BlockPosTools; +import mcjty.rftoolsbase.api.xnet.channels.IChannelSettings; import mcjty.rftoolsbase.api.xnet.channels.IChannelType; +import mcjty.rftoolsbase.api.xnet.gui.IndicatorIcon; import mcjty.xnet.XNet; import mcjty.xnet.client.ControllerChannelClientInfo; import mcjty.xnet.modules.router.RouterModule; @@ -145,10 +148,26 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local label("Pos").color(labelColor), label(BlockPosTools.toString(controllerPos))); + // Represent channel number/type in the same way as + // in GuiController.drawGuiContainerBackgroundLayer(). + Label numTypeLabel = label(num); + IChannelSettings settings = type.createChannel(); + if (settings != null) { + IndicatorIcon icon = settings.getIndicatorIcon(); + if (icon != null) { + numTypeLabel.image(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh()); + } + String indicator = settings.getIndicator(); + if (indicator != null) { + numTypeLabel.text(indicator + num); + } + } + Panel panel3 = horizontal(0, 0).hint(0, 26, 160, 13) .children( label("Num").color(labelColor), - label(num + " (" + type.getName() + ")")); + numTypeLabel, + label("(" + type.getName() + ")")); panel.children(panel1, panel2, panel3); return panel; From 8d1b9cab466c320283c7399d55a55a23077035ea Mon Sep 17 00:00:00 2001 From: Fabian Pietsch Date: Thu, 18 Feb 2021 05:01:09 +0100 Subject: [PATCH 3/4] Reorganize channel rendering in Router GUI: Num on Ch line * Move "Num" line's channel type's textual representation into a tooltip on the new graphical representation. * Move remaining contents of "Num" line from line 3/3 to being part of line 1/3 "Ch" (channel & published name). There is more to come for that line. * Split off published channel name into its own line 2/3, as it has frequently been a problem for me that, when the channel name becomes too long, the published name edit box gets moved "behind" the scroll bar and becomes mostly unuseable. * Move "Pos" line down (to line 3/3) accordingly. --- .../xnet/modules/router/client/GuiRouter.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java index eb147fbd..b8590004 100644 --- a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java +++ b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java @@ -24,6 +24,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; import java.util.List; @@ -128,29 +129,11 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local if (channel.isRemote()) { labelColor = 0xffaa1133; } - panel1.children( - label("Ch").color(labelColor), - label(name), - label(">").color(labelColor)); - if (channel.isRemote()) { - panel1.children(new ImageLabel().image(iconGuiElements, 48, 80).desiredWidth(16)); - } - if (local) { - TextField pubName = new TextField().text(publishedName).desiredWidth(50).desiredHeight(13) - .event((newText) -> updatePublish(controllerPos, index, newText)); - panel1.children(pubName); - } else { - panel1.children(label(publishedName).color(0xff33ff00)); - } - - Panel panel2 = horizontal(0, 0).hint(0, 13, 160, 13) - .children( - label("Pos").color(labelColor), - label(BlockPosTools.toString(controllerPos))); // Represent channel number/type in the same way as // in GuiController.drawGuiContainerBackgroundLayer(). Label numTypeLabel = label(num); + numTypeLabel.tooltips(TextFormatting.GREEN + "Channel type: " + TextFormatting.WHITE + type.getName()); IChannelSettings settings = type.createChannel(); if (settings != null) { IndicatorIcon icon = settings.getIndicatorIcon(); @@ -163,11 +146,28 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local } } + panel1.children( + label("Ch").color(labelColor), + numTypeLabel, + label(name)); + + Panel panel2 = horizontal(0, 0).hint(0, 13, 160, 13) + .children(label("Pub").color(labelColor)); + if (channel.isRemote()) { + panel2.children(new ImageLabel().image(iconGuiElements, 48, 80).desiredWidth(16)); + } + if (local) { + TextField pubName = new TextField().text(publishedName).desiredWidth(50).desiredHeight(13) + .event((newText) -> updatePublish(controllerPos, index, newText)); + panel2.children(pubName); + } else { + panel2.children(label(publishedName).color(0xff33ff00)); + } + Panel panel3 = horizontal(0, 0).hint(0, 26, 160, 13) .children( - label("Num").color(labelColor), - numTypeLabel, - label("(" + type.getName() + ")")); + label("Pos").color(labelColor), + label(BlockPosTools.toString(controllerPos))); panel.children(panel1, panel2, panel3); return panel; From 9e9df436b4093b25d54047b0670124a42031b020 Mon Sep 17 00:00:00 2001 From: Fabian Pietsch Date: Thu, 18 Feb 2021 06:21:39 +0100 Subject: [PATCH 4/4] Reorganize channel rendering in Router GUI: Pos on Ch line * Instead of dumping not-easily-digested block positions to the player, count local/remote Controllers up from 1. Have the block position still available, as tooltip on a new Controller icon before the new Controller short name/number. This could probably be much improved by using the consumer/connector/ network numbers (and/or cable colours), but I currently don't know how to retrieve them. This would increase perceived interoperability with heads-up displays that already give such information when looking at the relevant block. * As we have the position in the tooltip now, plus a replacement for identity checking, get rid of the "Pos" line altogether, so we have only 2 lines per channel, now. --- .../xnet/modules/router/client/GuiRouter.java | 62 ++++++++++++++++--- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java index b8590004..d906c6df 100644 --- a/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java +++ b/src/main/java/mcjty/xnet/modules/router/client/GuiRouter.java @@ -1,13 +1,16 @@ package mcjty.xnet.modules.router.client; import com.mojang.blaze3d.matrix.MatrixStack; +import mcjty.lib.client.GuiTools; import mcjty.lib.container.GenericContainer; import mcjty.lib.gui.GenericGuiContainer; import mcjty.lib.gui.Window; +import mcjty.lib.gui.widgets.BlockRender; import mcjty.lib.gui.widgets.ImageLabel; import mcjty.lib.gui.widgets.Label; import mcjty.lib.gui.widgets.Panel; import mcjty.lib.gui.widgets.TextField; +import mcjty.lib.gui.widgets.Widget; import mcjty.lib.gui.widgets.WidgetList; import mcjty.lib.typed.TypedMap; import mcjty.lib.varia.BlockPosTools; @@ -16,6 +19,7 @@ import mcjty.rftoolsbase.api.xnet.gui.IndicatorIcon; import mcjty.xnet.XNet; import mcjty.xnet.client.ControllerChannelClientInfo; +import mcjty.xnet.modules.controller.ControllerModule; import mcjty.xnet.modules.router.RouterModule; import mcjty.xnet.modules.router.blocks.TileEntityRouter; import mcjty.xnet.modules.router.network.PacketGetLocalChannelsRouter; @@ -26,7 +30,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static mcjty.lib.gui.widgets.Widgets.*; import static mcjty.xnet.modules.router.blocks.TileEntityRouter.*; @@ -96,11 +102,13 @@ private void populateList() { localChannelList.removeChildren(); localChannelList.rowheight(40); int sel = localChannelList.getSelected(); + Map ctrlNums = new HashMap(); for (ControllerChannelClientInfo channel : fromServer_localChannels) { - localChannelList.children(makeChannelLine(channel, true)); + localChannelList.children(makeChannelLine(channel, true, ctrlNums)); } + ctrlNums.clear(); localChannelList.selected(sel); remoteChannelList.removeChildren(); @@ -108,16 +116,30 @@ private void populateList() { sel = remoteChannelList.getSelected(); for (ControllerChannelClientInfo channel : fromServer_remoteChannels) { - remoteChannelList.children(makeChannelLine(channel, false)); + remoteChannelList.children(makeChannelLine(channel, false, ctrlNums)); } + ctrlNums.clear(); remoteChannelList.selected(sel); } - private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local) { + private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local, Map ctrlNums) { String name = channel.getChannelName(); String publishedName = channel.getPublishedName(); BlockPos controllerPos = channel.getPos(); + // @todo, this could be derived from the connector number + sidedness if this info was available; + // the idea of counting the controllers is for the player to not need full block position + // in the GUI anymore to easily be able to identify whether two controllers are the same. + // (The info is still available via tooltips.) + int ctrlNum = 0; + if (ctrlNums.containsKey(controllerPos)) { + ctrlNum = ctrlNums.get(controllerPos); + } + else { + ctrlNum = ctrlNums.size() + 1; + ctrlNums.put(controllerPos, ctrlNum); + } + String ctrlShortName = (local ? "LC" : "RC") + String.valueOf(ctrlNum); IChannelType type = channel.getChannelType(); int index = channel.getIndex(); String num = String.valueOf(index + 1); @@ -130,6 +152,19 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local labelColor = 0xffaa1133; } + // @todo, for non-local channels add something similar with router icon + number, + // with router position (+ name?) as tooltip + BlockRender ctrlBr = new BlockRender().renderItem(ControllerModule.CONTROLLER.get()); + ctrlBr.userObject("block"); // (See drawStackTooltips() below.) + // @todo, have meta-data in even more tooltips + // (e.g., controller cable color, numbers + name from the connectors, + // and/or the same for the relevant router connector) + ctrlBr.tooltips(TextFormatting.GREEN + "Controller position: " + + TextFormatting.WHITE + BlockPosTools.toString(controllerPos)); + panel1.children( + ctrlBr, + label(ctrlShortName)); + // Represent channel number/type in the same way as // in GuiController.drawGuiContainerBackgroundLayer(). Label numTypeLabel = label(num); @@ -164,12 +199,7 @@ private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local panel2.children(label(publishedName).color(0xff33ff00)); } - Panel panel3 = horizontal(0, 0).hint(0, 26, 160, 13) - .children( - label("Pos").color(labelColor), - label(BlockPosTools.toString(controllerPos))); - - panel.children(panel1, panel2, panel3); + panel.children(panel1, panel2); return panel; } @@ -192,4 +222,18 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float v, populateList(); drawWindow(matrixStack); } + + // Much the same as in GuiController. + @Override + protected void drawStackTooltips(MatrixStack matrixStack, int mouseX, int mouseY) { + int x = GuiTools.getRelativeX(this); + int y = GuiTools.getRelativeY(this); + Widget widget = window.getToplevel().getWidgetAtPosition(x, y); + if (widget instanceof BlockRender) { + if ("block".equals(widget.getUserObject())) { + return; // Don't do the normal tooltip rendering + } + } + super.drawStackTooltips(matrixStack, mouseX, mouseY); + } }