From d778ba6e03fa1f2e2c3f44571438b1fe50049d54 Mon Sep 17 00:00:00 2001 From: Alex Emelyanov Date: Sat, 6 Apr 2024 13:40:46 +0300 Subject: [PATCH] New connector gui features, translate controller gui, #551 fix --- .../modules/cables/client/GuiConnector.java | 72 +++++++++++++++---- .../controller/client/GuiController.java | 45 ++++++++++-- .../java/mcjty/xnet/utils/I18nConstants.java | 5 +- .../resources/assets/xnet/lang/en_us.json | 5 +- .../resources/assets/xnet/lang/ru_ru.json | 12 ++-- 5 files changed, 113 insertions(+), 26 deletions(-) diff --git a/src/main/java/mcjty/xnet/modules/cables/client/GuiConnector.java b/src/main/java/mcjty/xnet/modules/cables/client/GuiConnector.java index da6a930c..f7b257f2 100644 --- a/src/main/java/mcjty/xnet/modules/cables/client/GuiConnector.java +++ b/src/main/java/mcjty/xnet/modules/cables/client/GuiConnector.java @@ -4,16 +4,28 @@ import mcjty.lib.container.GenericContainer; import mcjty.lib.gui.GenericGuiContainer; import mcjty.lib.gui.Window; +import mcjty.lib.gui.layout.HorizontalAlignment; +import mcjty.lib.gui.layout.VerticalAlignment; +import mcjty.lib.gui.widgets.BlockRender; +import mcjty.lib.gui.widgets.Label; import mcjty.lib.gui.widgets.Panel; import mcjty.lib.gui.widgets.TextField; import mcjty.lib.gui.widgets.ToggleButton; +import mcjty.lib.network.PacketRequestDataFromServer; import mcjty.lib.typed.TypedMap; import mcjty.lib.varia.OrientationTools; import mcjty.xnet.modules.cables.CableModule; +import mcjty.xnet.modules.cables.ConnectorType; import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import mcjty.xnet.setup.XNetMessages; +import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.EnumProperty; import javax.annotation.Nonnull; @@ -22,6 +34,7 @@ import static mcjty.lib.gui.widgets.Widgets.vertical; import static mcjty.xnet.apiimpl.Constants.TAG_NAME; import static mcjty.xnet.modules.cables.blocks.ConnectorTileEntity.CMD_ENABLE; +import static mcjty.xnet.modules.cables.blocks.ConnectorTileEntity.CMD_GET_NAME; import static mcjty.xnet.modules.cables.blocks.ConnectorTileEntity.PARAM_ENABLED; import static mcjty.xnet.modules.cables.blocks.ConnectorTileEntity.PARAM_FACING; import static mcjty.xnet.utils.I18nConstants.CONNECTOR_NAME_TOOLTIP; @@ -30,10 +43,11 @@ public class GuiConnector extends GenericGuiContainer { - public static final int WIDTH = 220; - public static final int HEIGHT = 50; + public static final int WIDTH = 230; + public static final int HEIGHT = 60; private final ToggleButton[] toggleButtons = new ToggleButton[6]; + private final BlockRender[] connectedBlockRenders = new BlockRender[6]; // public GuiConnector(AdvancedConnectorTileEntity te, EmptyContainer container, PlayerInventory inventory) { // this((ConnectorTileEntity) te, container, inventory); @@ -41,7 +55,11 @@ public class GuiConnector extends GenericGuiContainer { sendServerCommandTyped(XNetMessages.INSTANCE, CMD_ENABLE, TypedMap.builder() @@ -72,14 +116,16 @@ public void init() { .put(PARAM_ENABLED, toggleButtons[facing.ordinal()].isPressed()) .build()); }); - toggleButtons[facing.ordinal()].pressed(tileEntity.isEnabled(facing)); - togglePanel.children(toggleButtons[facing.ordinal()]); + boolean isEnabled = !tileEntity.getBlockState().getValue(EnumProperty.create(facing.getName(), ConnectorType.class)).equals(ConnectorType.NONE); + toggleButtons[facing.ordinal()].pressed(isEnabled); + directionNamesPanel.children(toggleButtons[facing.ordinal()]); } - toplevel.children(togglePanel); - + directionBlocksPanel.children(connectedBlockRenders); + directionValuesPanel.children(directionBlocksPanel, directionNamesPanel); + directionsPanel.children(directionValuesPanel); + toplevel.children(directionsPanel); toplevel.bounds(leftPos, topPos, WIDTH, HEIGHT); window = new Window(this, toplevel); - window.bind(XNetMessages.INSTANCE, TAG_NAME, tileEntity, TAG_NAME); } diff --git a/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java b/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java index 66e22f47..86d9014a 100644 --- a/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java +++ b/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java @@ -35,6 +35,7 @@ import mcjty.xnet.client.ChannelClientInfo; import mcjty.xnet.client.ConnectedBlockClientInfo; import mcjty.xnet.client.ConnectorClientInfo; +import mcjty.xnet.modules.controller.ChannelInfo; import mcjty.xnet.modules.controller.ControllerModule; import mcjty.xnet.modules.controller.blocks.TileEntityController; import mcjty.xnet.setup.Config; @@ -101,6 +102,8 @@ import static mcjty.xnet.utils.I18nConstants.CONNECTOR_REMOVE_TOOLTIP; import static mcjty.xnet.utils.I18nConstants.CREATE_LABEL; import static mcjty.xnet.utils.I18nConstants.DOUBLE_CLICK_HIGHLIGHT; +import static mcjty.xnet.utils.I18nConstants.EDIT_CHANNEL_TOOLTIP_EXIST_FORMATTED; +import static mcjty.xnet.utils.I18nConstants.EDIT_CHANNEL_TOOLTIP_NOT_EXIST_FORMATTED; import static mcjty.xnet.utils.I18nConstants.ERROR_COPY; import static mcjty.xnet.utils.I18nConstants.ERROR_LARGE_COPY; import static mcjty.xnet.utils.I18nConstants.ERROR_NOTHING_SELECTED; @@ -195,9 +198,18 @@ public void doubleClick(int index) { } }); + ChannelInfo[] channels = tileEntity.getChannels(); for (int i = 0 ; i < MAX_CHANNELS ; i++) { String name = TAG_CHANNEL + (i+1); channelButtons[i] = window.findChild(name); + if (channels[i] == null) { + channelButtons[i].tooltips(EDIT_CHANNEL_TOOLTIP_NOT_EXIST_FORMATTED.i18n(i + 1)); + } else { + channelButtons[i] + .tooltips(I18nUtils.getSplitedTooltip( + EDIT_CHANNEL_TOOLTIP_EXIST_FORMATTED.i18n(i + 1, channels[i].getType().getName())) + ); + } } energyBar = window.findChild(WIDGET_ENERGY_BAR); @@ -321,23 +333,40 @@ private void createConnector(SidedPos sidedPos) { } private void removeChannel() { + int selectedChannel = getSelectedChannel(); + if (selectedChannel == -1) { + return; + } showMessage(minecraft, this, getWindowManager(), 50, 50, - ChatFormatting.RED + String.format(MESSAGE_CONFIRM_REMOVE_CHANNEL_FORMATTED.i18n(), (getSelectedChannel() + 1)), + ChatFormatting.RED + MESSAGE_CONFIRM_REMOVE_CHANNEL_FORMATTED.i18n((selectedChannel + 1)), () -> { sendServerCommandTyped(XNetMessages.INSTANCE, TileEntityController.CMD_REMOVECHANNEL, TypedMap.builder() - .put(PARAM_INDEX, getSelectedChannel()) + .put(PARAM_INDEX, selectedChannel) .build()); + + channelButtons[selectedChannel].tooltips(EDIT_CHANNEL_TOOLTIP_NOT_EXIST_FORMATTED.i18n(selectedChannel + 1)); refresh(); }); } private void createChannel(String typeId) { + int selectedChannel = getSelectedChannel(); + if (selectedChannel == -1) { + return; + } sendServerCommandTyped(XNetMessages.INSTANCE, TileEntityController.CMD_CREATECHANNEL, TypedMap.builder() - .put(PARAM_INDEX, getSelectedChannel()) + .put(PARAM_INDEX, selectedChannel) .put(PARAM_TYPE, typeId) .build()); + IChannelType type = XNet.xNetApi.findType(typeId); + if (type != null) { + channelButtons[selectedChannel].tooltips(I18nUtils.getSplitedTooltip( + EDIT_CHANNEL_TOOLTIP_EXIST_FORMATTED.i18n((selectedChannel + 1), type.getName())) + ); + } + refresh(); } @@ -370,7 +399,7 @@ private void refreshChannelEditor() { ChannelClientInfo info = tileEntity.clientChannels.get(editingChannel); if (info != null) { ChannelEditorPanel editor = new ChannelEditorPanel(channelEditPanel, minecraft, this, editingChannel); - editor.label(String.format(CHANNEL_LABEL_FORMATTED.i18n(), (editingChannel + 1))) + editor.label(CHANNEL_LABEL_FORMATTED.i18n(editingChannel + 1)) .shift(5) .toggle(TAG_ENABLED, CHANNEL_ENABLE_TOOLTIP.i18n(), info.isEnabled()) .shift(5) @@ -492,7 +521,7 @@ private void pasteConnector() { String type = root.get(TAG_TYPE).getAsString(); IChannelType channelType = XNet.xNetApi.findType(type); if (channelType == null) { - showMessage(minecraft, this, getWindowManager(), 50, 50, ChatFormatting.RED + String.format(ERROR_UNS_CH_FORMATTED.i18n(), type)); + showMessage(minecraft, this, getWindowManager(), 50, 50, ChatFormatting.RED + ERROR_UNS_CH_FORMATTED.i18n(type)); return; } @@ -527,7 +556,7 @@ private void pasteChannel() { String type = root.get(TAG_TYPE).getAsString(); IChannelType channelType = XNet.xNetApi.findType(type); if (channelType == null) { - showMessage(minecraft, this, getWindowManager(), 50, 50, ChatFormatting.RED + String.format(ERROR_UNS_CH_FORMATTED.i18n(), type)); + showMessage(minecraft, this, getWindowManager(), 50, 50, ChatFormatting.RED + ERROR_UNS_CH_FORMATTED.i18n(type)); return; } PacketServerCommandTyped packet = new PacketServerCommandTyped(tileEntity.getBlockPos(), tileEntity.getDimension(), CMD_PASTECHANNEL.name(), TypedMap.builder() @@ -736,6 +765,10 @@ protected void renderBg(@Nonnull PoseStack matrixStack, float v, int x1, int x2) String channel = String.valueOf(i + 1); ChannelClientInfo info = tileEntity.clientChannels.get(i); if (info != null) { + channelButtons[i] + .tooltips(I18nUtils.getSplitedTooltip( + EDIT_CHANNEL_TOOLTIP_EXIST_FORMATTED.i18n((i + 1), info.getType().getName())) + ); IndicatorIcon icon = info.getChannelSettings().getIndicatorIcon(); if (icon != null) { channelButtons[i].image(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh()); diff --git a/src/main/java/mcjty/xnet/utils/I18nConstants.java b/src/main/java/mcjty/xnet/utils/I18nConstants.java index b46a026a..0cd435da 100644 --- a/src/main/java/mcjty/xnet/utils/I18nConstants.java +++ b/src/main/java/mcjty/xnet/utils/I18nConstants.java @@ -98,7 +98,10 @@ public enum I18nConstants { ERROR_COPY("xnet.error.copy"), ERROR_READ_COPY("xnet.error.read.copy"), ERROR_LARGE_COPY("xnet.error.large.copy"), - ERROR_UNS_CH_FORMATTED("xnet.uns.ch.formatted"); + ERROR_UNS_CH_FORMATTED("xnet.uns.ch.formatted"), + + EDIT_CHANNEL_TOOLTIP_EXIST_FORMATTED("xnet.channel.edit.tooltip.exist"), + EDIT_CHANNEL_TOOLTIP_NOT_EXIST_FORMATTED("xnet.channel.edit.tooltip.notexist"); private final String langKey; diff --git a/src/main/resources/assets/xnet/lang/en_us.json b/src/main/resources/assets/xnet/lang/en_us.json index d024b43d..a84c38b1 100644 --- a/src/main/resources/assets/xnet/lang/en_us.json +++ b/src/main/resources/assets/xnet/lang/en_us.json @@ -211,5 +211,8 @@ "xnet.connector.upgrade": "Sneak right click this on a|normal connector to upgrade it|to an advanced connector", "xnet.connector.was.upgraded": "Connector was upgraded", "xnet.connector.already.advanced": "This connector is already advanced!", - "xnet.connector.use.it.to.upgrade": "Use this item on a connector to upgrade it!" + "xnet.connector.use.it.to.upgrade": "Use this item on a connector to upgrade it!", + + "xnet.channel.edit.tooltip.exist": "Edit channel %d|Type: %s", + "xnet.channel.edit.tooltip.notexist": "Edit channel %d" } \ No newline at end of file diff --git a/src/main/resources/assets/xnet/lang/ru_ru.json b/src/main/resources/assets/xnet/lang/ru_ru.json index feeef8d1..f0b629c5 100644 --- a/src/main/resources/assets/xnet/lang/ru_ru.json +++ b/src/main/resources/assets/xnet/lang/ru_ru.json @@ -77,7 +77,7 @@ "message.xnet.redstone_proxy_upd.gold": "Эта версия обновляет блок!", "xnet.channel.energy": "Энергия", - "xnet.channel.fluid": "Жидкость", + "xnet.channel.fluid": "Жидкости", "xnet.channel.item": "Предметы", "xnet.channel.logic": "Редстоун", "xnet.min": "Мин", @@ -144,9 +144,9 @@ "xnet.index.label": "Индекс", "xnet.double.click.highlight": "(двойной клик для выделения)", "xnet.enum.channelmode.priority": "Приоритет", - "xnet.enum.channelmode.priority.tooltip": "Режим распределения предметов|По приоритету(выше-раньше)", - "xnet.enum.channelmode.roundrobin": "Круговой", - "xnet.enum.channelmode.roundrobin.tooltip": "Режим распределения предметов|Круговое распределение", + "xnet.enum.channelmode.priority.tooltip": "Режим распределения предметов|По приоритету (выше-раньше)", + "xnet.enum.channelmode.roundrobin": "Равномерно", + "xnet.enum.channelmode.roundrobin.tooltip": "Режим распределения предметов|Равномерное распределение", "xnet.enum.insextmode.ins": "Помещать", "xnet.enum.insextmode.ins.tooltip": "Помещать в подключенный блок", "xnet.enum.insextmode.ext": "Извлекать", @@ -199,5 +199,7 @@ "xnet.connector.upgrade": "ПКМ сидя по коннектору|чтобы улучшить его|до продвинутого", "xnet.connector.was.upgraded": "Коннектор улучшен", "xnet.connector.already.advanced": "Коннектор уже улучшен!", - "xnet.connector.use.it.to.upgrade": "Используйте этот предмет, чтобы улучшить коннектор!" + "xnet.connector.use.it.to.upgrade": "Используйте этот предмет, чтобы улучшить коннектор!", + "xnet.channel.edit.tooltip.exist": "Настроить канал %d|Тип: %s", + "xnet.channel.edit.tooltip.notexist": "Настроить канал %d" }