use of mcjty.xnet.clientinfo.ConnectorClientInfo in project XNet by McJty.
the class TileEntityController method findChannelInfo.
@Nonnull
private List<ChannelClientInfo> findChannelInfo() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
List<ChannelClientInfo> chanList = new ArrayList<>();
for (ChannelInfo channel : channels) {
if (channel != null) {
ChannelClientInfo clientInfo = new ChannelClientInfo(channel.getChannelName(), channel.getType(), channel.getChannelSettings(), channel.isEnabled());
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channel.getConnectors().entrySet()) {
SidedConsumer sidedConsumer = entry.getKey();
ConnectorInfo info = entry.getValue();
if (info.getConnectorSettings() != null) {
BlockPos consumerPos = findConsumerPosition(worldBlob, sidedConsumer.getConsumerId());
if (consumerPos != null) {
SidedPos pos = new SidedPos(consumerPos.offset(sidedConsumer.getSide()), sidedConsumer.getSide().getOpposite());
boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
ConnectorClientInfo ci = new ConnectorClientInfo(pos, sidedConsumer.getConsumerId(), channel.getType(), info.getConnectorSettings());
clientInfo.getConnectors().put(sidedConsumer, ci);
} else {
// Consumer was possibly removed. We might want to remove the entry from our list here?
// @todo
}
}
}
chanList.add(clientInfo);
} else {
chanList.add(null);
}
}
return chanList;
}
use of mcjty.xnet.clientinfo.ConnectorClientInfo in project XNet by McJty.
the class GuiController method populateList.
private void populateList() {
if (!listsReady()) {
return;
}
if (!needsRefresh) {
return;
}
needsRefresh = false;
connectorList.removeChildren();
int sel = connectorList.getSelected();
BlockPos prevPos = null;
String selectedText = searchBar.getText().trim().toLowerCase();
for (ConnectedBlockClientInfo connectedBlock : fromServer_connectedBlocks) {
SidedPos sidedPos = connectedBlock.getPos();
BlockPos coordinate = sidedPos.getPos();
String name = connectedBlock.getName();
String blockUnlocName = connectedBlock.getBlockUnlocName();
String blockName = I18n.format(blockUnlocName).trim();
int color = StyleConfig.colorTextInListNormal;
Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0));
if (!selectedText.isEmpty()) {
if (blockName.toLowerCase().contains(selectedText)) {
panel.setFilledBackground(0xffddeeaa);
}
}
BlockRender br;
if (coordinate.equals(prevPos)) {
br = new BlockRender(mc, this);
} else {
br = new BlockRender(mc, this).setRenderItem(connectedBlock.getConnectedBlock());
prevPos = coordinate;
}
br.setUserObject("block");
panel.addChild(br);
if (!name.isEmpty()) {
br.setTooltips(TextFormatting.GREEN + "Connector: " + TextFormatting.WHITE + name, TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
} else {
br.setTooltips(TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
}
panel.addChild(new Label(mc, this).setText(sidedPos.getSide().getName().substring(0, 1).toUpperCase()).setColor(color).setDesiredWidth(18));
for (int i = 0; i < MAX_CHANNELS; i++) {
Button but = new Button(mc, this).setDesiredWidth(14);
ChannelClientInfo info = fromServer_channels.get(i);
if (info != null) {
ConnectorClientInfo clientInfo = findClientInfo(info, sidedPos);
if (clientInfo != null) {
IndicatorIcon icon = clientInfo.getConnectorSettings().getIndicatorIcon();
if (icon != null) {
but.setImage(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh());
}
String indicator = clientInfo.getConnectorSettings().getIndicator();
but.setText(indicator != null ? indicator : "");
}
}
int finalI = i;
but.addButtonEvent(parent -> {
selectConnectorEditor(sidedPos, finalI);
});
panel.addChild(but);
}
connectorList.addChild(panel);
}
connectorList.setSelected(sel);
}
use of mcjty.xnet.clientinfo.ConnectorClientInfo in project XNet by McJty.
the class GuiController method refreshConnectorEditor.
private void refreshConnectorEditor() {
if (!listsReady()) {
return;
}
if (editingConnector != null && !editingConnector.equals(showingConnector)) {
showingConnector = editingConnector;
connectorEditPanel.removeChildren();
ChannelClientInfo info = fromServer_channels.get(editingChannel);
if (info != null) {
ConnectorClientInfo clientInfo = findClientInfo(info, editingConnector);
if (clientInfo != null) {
EnumFacing side = clientInfo.getPos().getSide();
SidedConsumer sidedConsumer = new SidedConsumer(clientInfo.getConsumerId(), side.getOpposite());
ConnectorClientInfo connectorInfo = info.getConnectors().get(sidedConsumer);
Button remove = new Button(mc, this).setText("x").setTextOffset(0, -1).setTooltips("Remove this connector").setLayoutHint(new PositionalLayout.PositionalHint(151, 1, 9, 10)).addButtonEvent(parent -> removeConnector(editingConnector));
ConnectorEditorPanel editor = new ConnectorEditorPanel(connectorEditPanel, mc, this, editingChannel, editingConnector);
connectorInfo.getConnectorSettings().createGui(editor);
connectorEditPanel.addChild(remove);
editor.setState(connectorInfo.getConnectorSettings());
} else {
Button create = new Button(mc, this).setText("Create").setLayoutHint(new PositionalLayout.PositionalHint(85, 20, 60, 14)).addButtonEvent(parent -> createConnector(editingConnector));
connectorEditPanel.addChild(create);
}
}
} else if (showingConnector != null && editingConnector == null) {
showingConnector = null;
connectorEditPanel.removeChildren();
}
}
Aggregations