From e4a4c4dafd3b030fd8b3d60f2927a267a97c3179 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 20 Sep 2023 21:45:39 +0200 Subject: [PATCH] feat: 1.18 feats --- .../com/troblecodings/signals/SEProperty.java | 4 - .../signals/blocks/GhostBlock.java | 1 + .../troblecodings/signals/blocks/Post.java | 2 +- .../troblecodings/signals/blocks/Signal.java | 83 ++- .../contentpacks/ChangeConfigParser.java | 11 +- .../contentpacks/ContentPackException.java | 1 - .../contentpacks/DefaultConfigParser.java | 5 +- .../contentpacks/OneSignalConfigParser.java | 20 +- .../contentpacks/SEPropertyParser.java | 4 +- .../contentpacks/SubsidiarySignalParser.java | 6 +- .../troblecodings/signals/core/JsonEnum.java | 6 +- .../signals/core/LinkedPositions.java | 53 +- .../signals/core/LinkingUpdates.java | 13 +- .../signals/core/RenderOverlayInfo.java | 6 +- .../signals/core/SignalProperties.java | 25 +- .../signals/core/SignalPropertiesBuilder.java | 65 ++- .../signals/core/SignalStateListener.java | 2 +- .../signals/core/SubsidiaryHolder.java | 37 ++ .../signals/core/SubsidiaryState.java | 7 +- .../signals/enums/CompareValues.java | 2 +- .../signals/enums/EnumGuiMode.java | 6 +- .../signals/enums/EnumPathUsage.java | 3 +- .../signals/enums/EnumState.java | 5 +- .../signals/enums/ShowTypes.java | 7 + .../signals/guis/ContainerPlacementtool.java | 10 +- .../signals/guis/ContainerSignalBox.java | 85 +-- .../guis/ContainerSignalController.java | 47 +- .../signals/guis/GuiPlacementtool.java | 70 +-- .../signals/guis/GuiSignalBox.java | 337 ++++++++--- .../signals/guis/GuiSignalController.java | 93 +-- .../signals/guis/PreviewSideBar.java | 75 +++ .../troblecodings/signals/guis/SidePanel.java | 550 ++++++++++++++++++ .../troblecodings/signals/guis/UIMenu.java | 10 + .../handler/ClientSignalStateHandler.java | 3 +- .../signals/handler/SignalBoxHandler.java | 14 + .../signals/handler/SignalStateHandler.java | 1 + .../troblecodings/signals/init/OSItems.java | 1 + .../signals/models/CustomModelLoader.java | 7 +- .../signals/parser/FunctionParsingInfo.java | 7 +- .../signals/parser/LogicParser.java | 6 +- .../signals/parser/PredicateHolder.java | 11 - .../signals/properties/BooleanProperty.java | 17 - .../signals/properties/ConfigProperty.java | 35 -- .../signals/properties/FloatProperty.java | 34 -- .../signals/properties/HeightProperty.java | 32 - .../properties/PredicatedPropertyBase.java | 60 ++ .../signals/properties/SignalPair.java | 32 - .../signals/properties/SoundProperty.java | 23 +- .../signals/signalbox/PathwayHolder.java | 5 +- .../signals/signalbox/Point.java | 8 +- .../signals/signalbox/SignalBoxGrid.java | 51 +- .../signals/signalbox/SignalBoxNode.java | 15 +- .../signals/signalbox/SignalBoxPathway.java | 44 +- .../signals/signalbox/SignalBoxUtil.java | 1 + .../signalbox/config/SignalConfig.java | 19 +- 55 files changed, 1424 insertions(+), 653 deletions(-) create mode 100644 src/main/java/com/troblecodings/signals/core/SubsidiaryHolder.java create mode 100644 src/main/java/com/troblecodings/signals/enums/ShowTypes.java create mode 100644 src/main/java/com/troblecodings/signals/guis/PreviewSideBar.java create mode 100644 src/main/java/com/troblecodings/signals/guis/SidePanel.java delete mode 100644 src/main/java/com/troblecodings/signals/properties/BooleanProperty.java delete mode 100644 src/main/java/com/troblecodings/signals/properties/ConfigProperty.java delete mode 100644 src/main/java/com/troblecodings/signals/properties/FloatProperty.java delete mode 100644 src/main/java/com/troblecodings/signals/properties/HeightProperty.java create mode 100644 src/main/java/com/troblecodings/signals/properties/PredicatedPropertyBase.java delete mode 100644 src/main/java/com/troblecodings/signals/properties/SignalPair.java diff --git a/src/main/java/com/troblecodings/signals/SEProperty.java b/src/main/java/com/troblecodings/signals/SEProperty.java index b9b1e6b43..35ea1ee45 100644 --- a/src/main/java/com/troblecodings/signals/SEProperty.java +++ b/src/main/java/com/troblecodings/signals/SEProperty.java @@ -108,10 +108,6 @@ public boolean testMap(final Map t) { return this.deps.test(t); } - public static SEProperty cst(final Object iup) { - return (SEProperty) iup; - } - public JsonEnum getParent() { return parent; } diff --git a/src/main/java/com/troblecodings/signals/blocks/GhostBlock.java b/src/main/java/com/troblecodings/signals/blocks/GhostBlock.java index d0e3022f1..4ecc48659 100644 --- a/src/main/java/com/troblecodings/signals/blocks/GhostBlock.java +++ b/src/main/java/com/troblecodings/signals/blocks/GhostBlock.java @@ -23,6 +23,7 @@ public class GhostBlock extends BasicBlock { public GhostBlock() { super(Properties.of(Material.GLASS).noOcclusion().lightLevel(u -> 1)); registerDefaultState(defaultBlockState()); + // TODO Config Light Level } @Override diff --git a/src/main/java/com/troblecodings/signals/blocks/Post.java b/src/main/java/com/troblecodings/signals/blocks/Post.java index c47839dbb..89f3b9d62 100644 --- a/src/main/java/com/troblecodings/signals/blocks/Post.java +++ b/src/main/java/com/troblecodings/signals/blocks/Post.java @@ -22,4 +22,4 @@ public VoxelShape getShape(final BlockState state, final IBlockReader getter, final BlockPos pos, final ISelectionContext context) { return BOUNDING_BOX; } -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/blocks/Signal.java b/src/main/java/com/troblecodings/signals/blocks/Signal.java index 4775c605b..1bd983f83 100644 --- a/src/main/java/com/troblecodings/signals/blocks/Signal.java +++ b/src/main/java/com/troblecodings/signals/blocks/Signal.java @@ -29,9 +29,7 @@ import com.troblecodings.signals.init.OSItems; import com.troblecodings.signals.items.Placementtool; import com.troblecodings.signals.parser.ValuePack; -import com.troblecodings.signals.properties.BooleanProperty; -import com.troblecodings.signals.properties.FloatProperty; -import com.troblecodings.signals.properties.HeightProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.PredicateProperty; import com.troblecodings.signals.properties.SoundProperty; import com.troblecodings.signals.tileentitys.SignalTileEntity; @@ -78,7 +76,6 @@ public class Signal extends BasicBlock { private final int id; private List signalProperties; private final Map signalPropertiesToInt = new HashMap<>(); - private SEProperty powerProperty = null; public Signal(final SignalProperties prop) { super(Properties.of(Material.STONE).noOcclusion().lightLevel(u -> 1)); @@ -91,6 +88,7 @@ public Signal(final SignalProperties prop) { final SEProperty property = signalProperties.get(i); signalPropertiesToInt.put(property, i); } + // TODO Light Level } public int getID() { @@ -185,9 +183,9 @@ public void destroy(final IWorld worldIn, final BlockPos pos, final BlockState s @SuppressWarnings("unchecked") public int getHeight(final Map map) { - for (final HeightProperty property : this.prop.signalHeights) { - if (property.predicate.test(map)) - return property.height; + for (final PredicateProperty property : this.prop.signalHeights) { + if (property.test(map)) + return property.state; } return this.prop.defaultHeight; } @@ -239,9 +237,9 @@ public void renderScaleOverlay(final RenderOverlayInfo info, final float renderH if (customNameState == null || customNameState.equalsIgnoreCase("FALSE")) return; float customRenderHeight = renderHeight; - for (final FloatProperty property : this.prop.customRenderHeights) { + for (final PredicateProperty property : this.prop.customRenderHeights) { if (property.predicate.test(map)) { - customRenderHeight = property.height; + customRenderHeight = property.state; } if (customRenderHeight == -1) return; @@ -253,9 +251,9 @@ public void renderScaleOverlay(final RenderOverlayInfo info, final float renderH return; } boolean doubleSidedText = false; - for (final BooleanProperty boolProp : this.prop.doubleSidedText) { + for (final PredicateProperty boolProp : this.prop.doubleSidedText) { if (boolProp.predicate.test(map)) { - doubleSidedText = boolProp.doubleSided; + doubleSidedText = boolProp.state; } } final SignalAngel face = state.getValue(Signal.ANGEL); @@ -300,9 +298,9 @@ public void renderOverlay(final RenderOverlayInfo info, final float renderHeight final String customNameState = map.get(CUSTOMNAME); if (customNameState == null || customNameState.equalsIgnoreCase("FALSE")) return; - for (final FloatProperty property : this.prop.customRenderHeights) { + for (final PredicateProperty property : this.prop.customRenderHeights) { if (property.predicate.test(map)) { - customRenderHeight = property.height; + customRenderHeight = property.state; } } if (customRenderHeight == -1) @@ -314,9 +312,9 @@ public void renderOverlay(final RenderOverlayInfo info, final float renderHeight return; } boolean doubleSidedText = false; - for (final BooleanProperty boolProp : this.prop.doubleSidedText) { + for (final PredicateProperty boolProp : this.prop.doubleSidedText) { if (boolProp.predicate.test(map)) { - doubleSidedText = boolProp.doubleSided; + doubleSidedText = boolProp.state; } } final String name = info.tileEntity.getNameWrapper(); @@ -375,31 +373,28 @@ public ActionResultType use(final BlockState state, final World world, final Blo return ActionResultType.FAIL; } final SignalStateInfo stateInfo = new SignalStateInfo(world, pos, this); - if (loadRedstoneOutput(world, stateInfo)) { - world.blockUpdated(pos, state.getBlock()); - return ActionResultType.SUCCESS; - } - final boolean customname = canHaveCustomname(SignalStateHandler.getStates(stateInfo)); - if (!player.getItemInHand(Hand.MAIN_HAND).getItem().equals(OSItems.LINKING_TOOL) + final Map properties = SignalStateHandler.getStates(stateInfo); + final boolean customname = canHaveCustomname(properties); + if (player.getItemInHand(Hand.MAIN_HAND).getItem().equals(OSItems.MANIPULATOR) && (canBeLinked() || customname)) { OpenSignalsMain.handler.invokeGui(Signal.class, player, world, pos, "signal"); return ActionResultType.SUCCESS; } + if (loadRedstoneOutput(world, stateInfo, properties)) { + world.blockUpdated(pos, state.getBlock()); + return ActionResultType.SUCCESS; + } return ActionResultType.FAIL; } @SuppressWarnings("unchecked") - private boolean loadRedstoneOutput(final World worldIn, final SignalStateInfo info) { + private boolean loadRedstoneOutput(final World worldIn, final SignalStateInfo info, + final Map properties) { if (!this.prop.redstoneOutputs.isEmpty()) { - final Map properties = SignalStateHandler.getStates(info); - this.powerProperty = null; for (final ValuePack pack : this.prop.redstoneOutputs) { - if (pack.predicate.test(properties)) { - this.powerProperty = pack.property; - if (properties.containsKey(pack.property)) { - SignalStateHandler.setState(info, powerProperty, - Boolean.toString(!Boolean.valueOf(properties.get(pack.property)))); - } + if (properties.containsKey(pack.property) && pack.predicate.test(properties)) { + SignalStateHandler.setState(info, pack.property, + Boolean.toString(!Boolean.valueOf(properties.get(pack.property)))); return true; } } @@ -407,9 +402,13 @@ private boolean loadRedstoneOutput(final World worldIn, final SignalStateInfo in return false; } + public boolean hasRedstoneOut() { + return !this.prop.redstoneOutputs.isEmpty() || !this.prop.redstoneOutputPacks.isEmpty(); + } + @Override public boolean isSignalSource(final BlockState state) { - return !this.prop.redstoneOutputs.isEmpty(); + return hasRedstoneOut(); } @Override @@ -422,19 +421,19 @@ public int getSignal(final BlockState state, final IBlockReader getter, final Bl @Override public int getDirectSignal(final BlockState blockState, final IBlockReader blockAccess, final BlockPos pos, final Direction side) { - if (this.prop.redstoneOutputs.isEmpty() || this.powerProperty == null - || !(blockAccess instanceof World)) { + if (!hasRedstoneOut() || !(blockAccess instanceof World)) { return 0; } final SignalStateInfo stateInfo = new SignalStateInfo((World) blockAccess, pos, this); - if (SignalStateHandler.getState(stateInfo, powerProperty) - .filter(power -> power.equalsIgnoreCase("false")).isPresent()) { - return 0; - } final Map properties = SignalStateHandler.getStates(stateInfo); - for (final ValuePack pack : this.prop.redstoneOutputs) { - if (pack.predicate.test(properties)) { - return 15; + for (final List valuePacks : ImmutableList.of(this.prop.redstoneOutputPacks, + this.prop.redstoneOutputs)) { + for (final ValuePack pack : valuePacks) { + if (properties.containsKey(pack.property) && pack.predicate.test(properties) + && !properties.get(pack.property) + .equalsIgnoreCase(pack.property.getDefault())) { + return 15; + } } } return 0; @@ -452,7 +451,7 @@ public void getUpdate(final World world, final BlockPos pos) { return; if (sound.duration == 1) { - world.playSound(null, pos, sound.sound, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.playSound(null, pos, sound.state, SoundCategory.BLOCKS, 1.0F, 1.0F); } else { if (world.getBlockTicks().hasScheduledTick(pos, this)) { return; @@ -485,7 +484,7 @@ public void tick(final BlockState state, final ServerWorld world, final BlockPos if (sound.duration <= 1) { return; } - world.playSound(null, pos, sound.sound, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.playSound(null, pos, sound.state, SoundCategory.BLOCKS, 1.0F, 1.0F); world.getBlockTicks().scheduleTick(pos, this, sound.duration); } diff --git a/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java index b88f81598..44d309a77 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/ChangeConfigParser.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.function.Predicate; +import com.google.common.collect.Maps; import com.google.gson.Gson; import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.SEProperty; @@ -13,8 +14,7 @@ import com.troblecodings.signals.parser.FunctionParsingInfo; import com.troblecodings.signals.parser.LogicParser; import com.troblecodings.signals.parser.LogicalParserException; -import com.troblecodings.signals.properties.ConfigProperty; -import com.troblecodings.signals.properties.SignalPair; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; public class ChangeConfigParser { @@ -23,11 +23,10 @@ public class ChangeConfigParser { private Map savedPredicates; private Map> values; - public static final Map> CHANGECONFIGS = new HashMap<>(); + public static final Map, List> CHANGECONFIGS = new HashMap<>(); private static final Gson GSON = new Gson(); - @SuppressWarnings("rawtypes") public static void loadChangeConfigs() { for (final Map.Entry files : OpenSignalsMain.contentPacks @@ -43,7 +42,7 @@ public static void loadChangeConfigs() { + "This config with filename '" + files.getKey() + "' will be skiped!"); continue; } - final SignalPair pair = new SignalPair(start, end); + final Map.Entry pair = Maps.immutableEntry(start, end); if (CHANGECONFIGS.containsKey(pair)) { throw new LogicalParserException("A signalconfig with the signals [" + start.getSignalTypeName() + ", " + end.getSignalTypeName() @@ -60,7 +59,7 @@ public static void loadChangeConfigs() { for (final Map.Entry> entry : parser.values.entrySet()) { String valueToParse = entry.getKey().toLowerCase(); - Predicate predicate = t -> true; + Predicate, Object>> predicate = t -> true; if (valueToParse.contains("map(") && savedPredicates != null && !savedPredicates.isEmpty()) { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/ContentPackException.java b/src/main/java/com/troblecodings/signals/contentpacks/ContentPackException.java index 7b4fc42cc..a3a27fbc2 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/ContentPackException.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/ContentPackException.java @@ -15,5 +15,4 @@ public ContentPackException(final Throwable err) { public ContentPackException(final String message, final Throwable err) { super(message, err); } - } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/contentpacks/DefaultConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/DefaultConfigParser.java index 30dc7e825..079596315 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/DefaultConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/DefaultConfigParser.java @@ -13,7 +13,7 @@ import com.troblecodings.signals.parser.FunctionParsingInfo; import com.troblecodings.signals.parser.LogicParser; import com.troblecodings.signals.parser.LogicalParserException; -import com.troblecodings.signals.properties.ConfigProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; public class DefaultConfigParser { @@ -25,7 +25,6 @@ public class DefaultConfigParser { private static final Gson GSON = new Gson(); - @SuppressWarnings("rawtypes") public static void loadDefaultConfigs() { for (final Map.Entry files : OpenSignalsMain.contentPacks @@ -55,7 +54,7 @@ public static void loadDefaultConfigs() { for (final Map.Entry> entry : parser.values.entrySet()) { String valueToParse = entry.getKey().toLowerCase(); - Predicate predicate = t -> true; + Predicate, Object>> predicate = t -> true; if (valueToParse.contains("map(") && savedPredicates != null && !savedPredicates.isEmpty()) { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalConfigParser.java b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalConfigParser.java index c3dc5d5fe..e6f01e037 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/OneSignalConfigParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/OneSignalConfigParser.java @@ -5,13 +5,14 @@ import java.util.List; import java.util.Map; +import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.blocks.Signal; import com.troblecodings.signals.parser.FunctionParsingInfo; import com.troblecodings.signals.parser.LogicalParserException; -import com.troblecodings.signals.properties.ConfigProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; public class OneSignalConfigParser { @@ -29,7 +30,7 @@ public static void loadOneSignalConfigs() { loadResetConfigs(); } - public static void loadShuntigConfigs() { + private static void loadShuntigConfigs() { for (final Map.Entry files : OpenSignalsMain.contentPacks .getFiles("signalconfigs/shunting")) { final OneSignalConfigParser parser = GSON.fromJson(files.getValue(), @@ -48,14 +49,14 @@ public static void loadShuntigConfigs() { final List propertes = new ArrayList<>(); for (final String property : parser.values) { final String[] value = property.split("\\."); - propertes - .add(new ConfigProperty((SEProperty) info.getProperty(value[0]), value[1])); + propertes.add(new ConfigProperty(t -> true, + ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1]))); } SHUNTINGCONFIGS.put(signal, propertes); } } - public static void loadResetConfigs() { + private static void loadResetConfigs() { for (final Map.Entry files : OpenSignalsMain.contentPacks .getFiles("signalconfigs/reset")) { final OneSignalConfigParser parser = GSON.fromJson(files.getValue(), @@ -75,8 +76,8 @@ public static void loadResetConfigs() { final List propertes = new ArrayList<>(); for (final String property : parser.values) { final String[] value = property.split("\\."); - propertes - .add(new ConfigProperty((SEProperty) info.getProperty(value[0]), value[1])); + propertes.add(new ConfigProperty(t -> true, + ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1]))); } RESETCONFIGS.put(signal, propertes); } @@ -85,8 +86,9 @@ public static void loadResetConfigs() { private static Signal checkSignal(final String signalName, final String filename) { final Signal signal = Signal.SIGNALS.get(signalName.toLowerCase()); if (signal == null) { - throw new ContentPackException("The signal '" + signalName + "' doesn't exists! " - + "Please check " + filename + " where to problem is!"); + throw new ContentPackException( + "The signal '" + signalName + "' doesn't exists! " + "Please check " + filename + + " where to problem is! Valid Signals: " + Signal.SIGNALS.keySet()); } return signal; } diff --git a/src/main/java/com/troblecodings/signals/contentpacks/SEPropertyParser.java b/src/main/java/com/troblecodings/signals/contentpacks/SEPropertyParser.java index 4dace92fd..b20bf0aa6 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/SEPropertyParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/SEPropertyParser.java @@ -22,7 +22,6 @@ public class SEPropertyParser { private int itemDamage = 1; private transient JsonEnum parent; - @SuppressWarnings("unchecked") public SEProperty createSEProperty(final FunctionParsingInfo info) { if (defaultState instanceof Boolean) { parent = JsonEnum.BOOLEAN; @@ -34,7 +33,8 @@ public SEProperty createSEProperty(final FunctionParsingInfo info) { if (parent == null) throw new ContentPackException(String.format("Property[%s], with class %s not found!", - name, enumClass.toLowerCase())); + name, enumClass.toLowerCase()) + " Valid EnumClasses: " + + JsonEnumHolder.PROPERTIES.keySet()); ChangeableStage stage = ChangeableStage.APISTAGE; if (changeableStage != null && !changeableStage.isEmpty()) { diff --git a/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java b/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java index 297fd3617..fe6b66468 100644 --- a/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java +++ b/src/main/java/com/troblecodings/signals/contentpacks/SubsidiarySignalParser.java @@ -10,7 +10,7 @@ import com.troblecodings.signals.blocks.Signal; import com.troblecodings.signals.core.SubsidiaryState; import com.troblecodings.signals.parser.FunctionParsingInfo; -import com.troblecodings.signals.properties.ConfigProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; public class SubsidiarySignalParser { @@ -37,7 +37,7 @@ public static void loadAllSubsidiarySignals() { final Signal signal = Signal.SIGNALS.get(parser.currentSignal.toLowerCase()); if (signal == null) throw new ContentPackException("There doesn't exists a signal with the name '" - + parser.currentSignal + "'!"); + + parser.currentSignal + "'! Valid Signals: " + Signal.SIGNALS.keySet()); if (SUBSIDIARY_SIGNALS.containsKey(signal)) throw new ContentPackException( "There already exists a Subsidiary Config for " + signal + "!"); @@ -70,7 +70,7 @@ private static void convertToProperites(final Signal signal, final FunctionParsi }); final Map properties = SUBSIDIARY_SIGNALS .computeIfAbsent(signal, _u -> new HashMap<>()); - properties.put(enumState, new ConfigProperty(allValues)); + properties.put(enumState, new ConfigProperty(t -> true, allValues)); SUBSIDIARY_SIGNALS.put(signal, properties); } diff --git a/src/main/java/com/troblecodings/signals/core/JsonEnum.java b/src/main/java/com/troblecodings/signals/core/JsonEnum.java index bfc9825dd..79ef01133 100644 --- a/src/main/java/com/troblecodings/signals/core/JsonEnum.java +++ b/src/main/java/com/troblecodings/signals/core/JsonEnum.java @@ -1,6 +1,5 @@ package com.troblecodings.signals.core; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -55,10 +54,7 @@ public String valueToString(final String value) { } public Collection getAllowedValues() { - if (values != null) { - return values; - } - return new ArrayList<>(); + return values; } @Override diff --git a/src/main/java/com/troblecodings/signals/core/LinkedPositions.java b/src/main/java/com/troblecodings/signals/core/LinkedPositions.java index b170db65a..93da2635c 100644 --- a/src/main/java/com/troblecodings/signals/core/LinkedPositions.java +++ b/src/main/java/com/troblecodings/signals/core/LinkedPositions.java @@ -8,11 +8,14 @@ import com.google.common.collect.ImmutableMap; import com.troblecodings.core.NBTWrapper; +import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.blocks.Signal; +import com.troblecodings.signals.contentpacks.SubsidiarySignalParser; import com.troblecodings.signals.enums.LinkType; import com.troblecodings.signals.handler.SignalBoxHandler; import com.troblecodings.signals.handler.SignalStateHandler; import com.troblecodings.signals.handler.SignalStateInfo; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; import com.troblecodings.signals.signalbox.config.SignalConfig; import net.minecraft.util.math.BlockPos; @@ -27,15 +30,19 @@ public class LinkedPositions { private final Map signals; private final Map linkedBlocks; + private final Map> possibleSubsidiaries; public LinkedPositions() { signals = new HashMap<>(); linkedBlocks = new HashMap<>(); + possibleSubsidiaries = new HashMap<>(); } public void addSignal(final BlockPos signalPos, final Signal signal, final World world) { signals.put(signalPos, signal); - SignalConfig.reset(new SignalStateInfo(world, signalPos, signal)); + final SignalStateInfo info = new SignalStateInfo(world, signalPos, signal); + SignalConfig.reset(info); + loadPossibleSubsidiaires(info); } public Signal getSignal(final BlockPos pos) { @@ -50,9 +57,9 @@ public boolean addLinkedPos(final BlockPos pos, final LinkType type) { } public void removeLinkedPos(final BlockPos pos) { - final LinkType type = linkedBlocks.remove(pos); - if (type != null && type.equals(LinkType.SIGNAL)) - signals.remove(pos); + linkedBlocks.remove(pos); + signals.remove(pos); + possibleSubsidiaries.remove(pos); } public boolean isEmpty() { @@ -80,11 +87,12 @@ public void unlink(final BlockPos tilePos, final World world) { public void write(final NBTWrapper wrapper) { final NBTWrapper posWrapper = new NBTWrapper(); - posWrapper.putList(LINKED_POS_LIST, linkedBlocks.entrySet().stream().map(entry -> { - final NBTWrapper item = NBTWrapper.getBlockPosWrapper(entry.getKey()); - entry.getValue().write(item); - return item; - })::iterator); + posWrapper.putList(LINKED_POS_LIST, linkedBlocks.entrySet().stream() + .filter(entry -> !entry.getValue().equals(LinkType.SIGNAL)).map(entry -> { + final NBTWrapper item = NBTWrapper.getBlockPosWrapper(entry.getKey()); + entry.getValue().write(item); + return item; + })::iterator); posWrapper.putList(LINKED_SIGNALS, signals.entrySet().stream().map(entry -> { final NBTWrapper signal = NBTWrapper.getBlockPosWrapper(entry.getKey()); signal.putString(SIGNAL_NAME, entry.getValue().getSignalTypeName()); @@ -114,6 +122,7 @@ public void loadSignals(final World world) { final List signalInfos = new ArrayList<>(); signals.forEach((pos, signal) -> signalInfos.add(new SignalStateInfo(world, pos, signal))); SignalStateHandler.loadSignals(signalInfos); + signalInfos.forEach(this::loadPossibleSubsidiaires); } public void unloadSignals(final World world) { @@ -123,15 +132,37 @@ public void unloadSignals(final World world) { signals.forEach((pos, signal) -> signalInfos.add(new SignalStateInfo(world, pos, signal))); SignalStateHandler.unloadSignals(signalInfos); } - + + private void loadPossibleSubsidiaires(final SignalStateInfo info) { + final Map properties = SignalStateHandler.getStates(info); + final Map subsidiaries = SubsidiarySignalParser.SUBSIDIARY_SIGNALS + .get(info.signal); + if (subsidiaries == null) + return; + final List validStates = new ArrayList<>(); + subsidiaries.forEach((state, config) -> { + for (final SEProperty property : config.state.keySet()) { + if (properties.containsKey(property)) { + validStates.add(state); + break; + } + } + }); + possibleSubsidiaries.put(info.pos, validStates); + } + public List getAllRedstoneIOs() { return linkedBlocks.entrySet().stream() .filter(entry -> !entry.getValue().equals(LinkType.SIGNAL)) .map(entry -> entry.getKey()).collect(Collectors.toList()); } + public Map> getValidSubsidiariesForPos() { + return ImmutableMap.copyOf(possibleSubsidiaries); + } + @Override public String toString() { - return "AllSignals = " + signals + ", AllLinkedPos = " + linkedBlocks; + return "LinkedPos [AllSignals = " + signals + ", AllLinkedPos = " + linkedBlocks + "]"; } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/LinkingUpdates.java b/src/main/java/com/troblecodings/signals/core/LinkingUpdates.java index e692b8ec5..ecbea305e 100644 --- a/src/main/java/com/troblecodings/signals/core/LinkingUpdates.java +++ b/src/main/java/com/troblecodings/signals/core/LinkingUpdates.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import com.google.common.collect.ImmutableList; import com.troblecodings.core.NBTWrapper; @@ -47,12 +48,10 @@ public List getPosToRemove() { private static final String POS_REMOVE = "posRemove"; public void writeNBT(final NBTWrapper wrapper) { - final List addList = new ArrayList<>(); - final List removeList = new ArrayList<>(); - posToAdd.forEach(pos -> addList.add(NBTWrapper.getBlockPosWrapper(pos))); - posToRemove.forEach(pos -> removeList.add(NBTWrapper.getBlockPosWrapper(pos))); - wrapper.putList(POS_ADD, addList); - wrapper.putList(POS_REMOVE, removeList); + wrapper.putList(POS_ADD, posToAdd.stream().map(pos -> NBTWrapper.getBlockPosWrapper(pos)) + .collect(Collectors.toList())); + wrapper.putList(POS_REMOVE, posToRemove.stream() + .map(pos -> NBTWrapper.getBlockPosWrapper(pos)).collect(Collectors.toList())); } public void readNBT(final NBTWrapper wrapper) { @@ -82,6 +81,6 @@ public boolean equals(final Object obj) { @Override public String toString() { - return "LinkingUpdates: PosToAdd: " + posToAdd + ", PosToRemove: " + posToRemove; + return "LinkingUpdates [PosToAdd: " + posToAdd + ", PosToRemove: " + posToRemove + "]"; } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/RenderOverlayInfo.java b/src/main/java/com/troblecodings/signals/core/RenderOverlayInfo.java index 1d58febe4..e04372679 100644 --- a/src/main/java/com/troblecodings/signals/core/RenderOverlayInfo.java +++ b/src/main/java/com/troblecodings/signals/core/RenderOverlayInfo.java @@ -6,6 +6,7 @@ import net.minecraft.client.gui.FontRenderer; public class RenderOverlayInfo { + public final MatrixStack stack; public final double x; public final double y; @@ -13,9 +14,8 @@ public class RenderOverlayInfo { public SignalTileEntity tileEntity; public final FontRenderer font; - public RenderOverlayInfo(final MatrixStack stack, final double x, final double y, final double z, - final FontRenderer fontRenderer) { - super(); + public RenderOverlayInfo(final MatrixStack stack, final double x, final double y, + final double z, final FontRenderer fontRenderer) { this.stack = stack; this.x = x; this.y = y; diff --git a/src/main/java/com/troblecodings/signals/core/SignalProperties.java b/src/main/java/com/troblecodings/signals/core/SignalProperties.java index 5314d84f1..6bddf5f98 100644 --- a/src/main/java/com/troblecodings/signals/core/SignalProperties.java +++ b/src/main/java/com/troblecodings/signals/core/SignalProperties.java @@ -4,9 +4,7 @@ import com.troblecodings.signals.items.Placementtool; import com.troblecodings.signals.parser.ValuePack; -import com.troblecodings.signals.properties.BooleanProperty; -import com.troblecodings.signals.properties.FloatProperty; -import com.troblecodings.signals.properties.HeightProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.PredicateProperty; import com.troblecodings.signals.properties.SoundProperty; public class SignalProperties { @@ -14,28 +12,30 @@ public class SignalProperties { public final Placementtool placementtool; public final float customNameRenderHeight; public final int defaultHeight; - public final List signalHeights; - public final List customRenderHeights; + public final List> signalHeights; + public final List> customRenderHeights; public final float signWidth; public final float offsetX; public final float offsetY; public final float signScale; public final boolean autoscale; - public final List doubleSidedText; + public final List> doubleSidedText; public final int textColor; public final boolean canLink; public final List colors; public final List sounds; public final List redstoneOutputs; + public final List redstoneOutputPacks; public final int defaultItemDamage; public SignalProperties(final Placementtool placementtool, final float customNameRenderHeight, - final int height, final List signalHeights, final float signWidth, - final float offsetX, final float offsetY, final float signScale, final boolean autoscale, - final List doubleSidedText, final int textColor, final boolean canLink, - final List colors, final List renderheights, - final List sounds, final List redstoneOutputs, - final int defaultItemDamage) { + final int height, final List> signalHeights, + final float signWidth, final float offsetX, final float offsetY, final float signScale, + final boolean autoscale, final List> doubleSidedText, + final int textColor, final boolean canLink, final List colors, + final List> renderheights, final List sounds, + final List redstoneOutputs, final int defaultItemDamage, + final List redstoneOutputPacks) { this.placementtool = placementtool; this.customNameRenderHeight = customNameRenderHeight; this.defaultHeight = height; @@ -53,5 +53,6 @@ public SignalProperties(final Placementtool placementtool, final float customNam this.sounds = sounds; this.redstoneOutputs = redstoneOutputs; this.defaultItemDamage = defaultItemDamage; + this.redstoneOutputPacks = redstoneOutputPacks; } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/SignalPropertiesBuilder.java b/src/main/java/com/troblecodings/signals/core/SignalPropertiesBuilder.java index 793656b41..b77aa7171 100644 --- a/src/main/java/com/troblecodings/signals/core/SignalPropertiesBuilder.java +++ b/src/main/java/com/troblecodings/signals/core/SignalPropertiesBuilder.java @@ -3,8 +3,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.contentpacks.ContentPackException; @@ -16,9 +18,7 @@ import com.troblecodings.signals.parser.LogicParser; import com.troblecodings.signals.parser.LogicalParserException; import com.troblecodings.signals.parser.ValuePack; -import com.troblecodings.signals.properties.BooleanProperty; -import com.troblecodings.signals.properties.FloatProperty; -import com.troblecodings.signals.properties.HeightProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.PredicateProperty; import com.troblecodings.signals.properties.SoundProperty; import net.minecraft.util.SoundEvent; @@ -42,6 +42,7 @@ public class SignalPropertiesBuilder { private List colors; private Map sounds; private Map redstoneOutputs; + private Map remoteRedstoneOutputs; private int defaultItemDamage = 1; public SignalProperties build(final FunctionParsingInfo info) { @@ -53,18 +54,17 @@ public SignalProperties build(final FunctionParsingInfo info) { break; } } - if (placementtool == null) - throw new ContentPackException( - "There doesn't exists a placementtool with the name '" + placementToolName - + "'!"); } + if (placementtool == null) + throw new ContentPackException("There doesn't exists a placementtool with the name '" + + placementToolName + "'!"); - final List signalheights = new ArrayList<>(); + final List> signalheights = new ArrayList<>(); if (signalHeights != null) { signalHeights.forEach((property, height) -> { try { - signalheights - .add(new HeightProperty(LogicParser.predicate(property, info), height)); + signalheights.add(new PredicateProperty( + LogicParser.predicate(property, info), height)); } catch (final LogicalParserException e) { OpenSignalsMain.getLogger() .error("Something went wrong during the registry of a predicate in " @@ -74,12 +74,12 @@ public SignalProperties build(final FunctionParsingInfo info) { }); } - final List renderheights = new ArrayList<>(); + final List> renderheights = new ArrayList<>(); if (renderHeights != null) { renderHeights.forEach((property, height) -> { try { - renderheights - .add(new FloatProperty(LogicParser.predicate(property, info), height)); + renderheights.add(new PredicateProperty( + LogicParser.predicate(property, info), height)); } catch (final LogicalParserException e) { OpenSignalsMain.getLogger() .error("Something went wrong during the registry of a predicate in " @@ -112,22 +112,28 @@ public SignalProperties build(final FunctionParsingInfo info) { } } } + final List redstoneValuePacks = new ArrayList<>(); + final List remoteRedstoneValuePacks = new ArrayList<>(); + ImmutableList + .of(Maps.immutableEntry(redstoneOutputs, redstoneValuePacks), + Maps.immutableEntry(remoteRedstoneOutputs, remoteRedstoneValuePacks)) + .forEach((entry) -> { + if (entry.getKey() != null) { + entry.getKey().forEach((key, value) -> { + final Predicate> predicate = LogicParser + .predicate(key, info); + final SEProperty property = (SEProperty) info.getProperty(value); + entry.getValue().add(new ValuePack(property, predicate)); + }); + } + }); - final List rsOutputs = new ArrayList<>(); - if (redstoneOutputs != null) { - for (final Map.Entry outputs : redstoneOutputs.entrySet()) { - final SEProperty property = (SEProperty) info.getProperty(outputs.getValue()); - rsOutputs.add( - new ValuePack(property, LogicParser.predicate(outputs.getKey(), info))); - } - } - - final List doubleText = new ArrayList<>(); + final List> doubleText = new ArrayList<>(); if (doubleSidedText != null) { doubleSidedText.forEach((property, bool) -> { try { - doubleText - .add(new BooleanProperty(LogicParser.predicate(property, info), bool)); + doubleText.add(new PredicateProperty( + LogicParser.predicate(property, info), bool)); } catch (final LogicalParserException e) { OpenSignalsMain.getLogger() .error("Something went wrong during the registry of a predicate in " @@ -140,9 +146,10 @@ public SignalProperties build(final FunctionParsingInfo info) { this.colors = this.colors == null ? new ArrayList<>() : this.colors; return new SignalProperties(placementtool, customNameRenderHeight, defaultHeight, - ImmutableList.copyOf(signalheights), signWidth, offsetX, offsetY, signScale, autoscale, - ImmutableList.copyOf(doubleText), textColor, canLink, colors, ImmutableList.copyOf(renderheights), - ImmutableList.copyOf(soundProperties), ImmutableList.copyOf(rsOutputs), - defaultItemDamage); + ImmutableList.copyOf(signalheights), signWidth, offsetX, offsetY, signScale, + autoscale, ImmutableList.copyOf(doubleText), textColor, canLink, colors, + ImmutableList.copyOf(renderheights), ImmutableList.copyOf(soundProperties), + ImmutableList.copyOf(redstoneValuePacks), defaultItemDamage, + ImmutableList.copyOf(remoteRedstoneValuePacks)); } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/SignalStateListener.java b/src/main/java/com/troblecodings/signals/core/SignalStateListener.java index a52696858..ea4e631af 100644 --- a/src/main/java/com/troblecodings/signals/core/SignalStateListener.java +++ b/src/main/java/com/troblecodings/signals/core/SignalStateListener.java @@ -6,4 +6,4 @@ public interface SignalStateListener { public void update(final SignalStateInfo info, final boolean removed); -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/SubsidiaryHolder.java b/src/main/java/com/troblecodings/signals/core/SubsidiaryHolder.java new file mode 100644 index 000000000..e694c6a83 --- /dev/null +++ b/src/main/java/com/troblecodings/signals/core/SubsidiaryHolder.java @@ -0,0 +1,37 @@ +package com.troblecodings.signals.core; + +import java.util.Objects; + +import com.troblecodings.signals.signalbox.ModeSet; +import com.troblecodings.signals.signalbox.Point; + +public class SubsidiaryHolder { + + public final SubsidiaryEntry entry; + public final Point point; + public final ModeSet modeSet; + + public SubsidiaryHolder(final SubsidiaryEntry entry, final Point point, final ModeSet modeSet) { + this.entry = entry; + this.point = point; + this.modeSet = modeSet; + } + + @Override + public int hashCode() { + return Objects.hash(entry, modeSet, point); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SubsidiaryHolder other = (SubsidiaryHolder) obj; + return Objects.equals(entry, other.entry) && Objects.equals(modeSet, other.modeSet) + && Objects.equals(point, other.point); + } +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/core/SubsidiaryState.java b/src/main/java/com/troblecodings/signals/core/SubsidiaryState.java index e1f6a6952..54e43d25b 100644 --- a/src/main/java/com/troblecodings/signals/core/SubsidiaryState.java +++ b/src/main/java/com/troblecodings/signals/core/SubsidiaryState.java @@ -34,7 +34,7 @@ public void writeNetwork(final WriteBuffer buffer) { public static SubsidiaryState of(final ReadBuffer buffer) { return ALL_STATES.get(buffer.getByteAsInt()); } - + private static final String STATE_ID = "stateID"; public void writeNBT(final NBTWrapper tag) { @@ -61,4 +61,9 @@ public boolean equals(final Object obj) { final SubsidiaryState other = (SubsidiaryState) obj; return id == other.id && Objects.equals(name, other.name); } + + @Override + public String toString() { + return name; + } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/enums/CompareValues.java b/src/main/java/com/troblecodings/signals/enums/CompareValues.java index 048a23111..fabca76b7 100644 --- a/src/main/java/com/troblecodings/signals/enums/CompareValues.java +++ b/src/main/java/com/troblecodings/signals/enums/CompareValues.java @@ -23,7 +23,7 @@ public static CompareValues of(final String name) { return value; } OpenSignalsMain.getLogger() - .warn("The string [" + name + "] is not permitted for the speed function. " + .error("The string [" + name + "] is not permitted for the speed function. " + "EQUALS was taken as default. Please fix this in your pack!"); return EQUALS; } diff --git a/src/main/java/com/troblecodings/signals/enums/EnumGuiMode.java b/src/main/java/com/troblecodings/signals/enums/EnumGuiMode.java index 90228cef6..f1c083d25 100644 --- a/src/main/java/com/troblecodings/signals/enums/EnumGuiMode.java +++ b/src/main/java/com/troblecodings/signals/enums/EnumGuiMode.java @@ -14,9 +14,9 @@ public enum EnumGuiMode { 0, 0.5f, 0.5f, 1 }), END(new float[] { 0.9f, 0.2f, 0.9f, 0.8f - }), PLATFORM(new float[] { - 0, 0.1f, 1, 0.1f, 0, 0.2f, 1, 0.2f - }), BUE(new float[] { + }), PLATFORM(() -> new UILines(new float[] { + 0, 0.15f, 1, 0.15f + }, 3)), BUE(new float[] { 0.3f, 0, 0.3f, 1, 0.7f, 0, 0.7f, 1 }), HP(0), VP(1), RS(2), RA10(3), SH2(4); diff --git a/src/main/java/com/troblecodings/signals/enums/EnumPathUsage.java b/src/main/java/com/troblecodings/signals/enums/EnumPathUsage.java index e7f0ee498..1aa336269 100644 --- a/src/main/java/com/troblecodings/signals/enums/EnumPathUsage.java +++ b/src/main/java/com/troblecodings/signals/enums/EnumPathUsage.java @@ -22,5 +22,4 @@ private EnumPathUsage(final int color) { public int getColor() { return color; } - -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/enums/EnumState.java b/src/main/java/com/troblecodings/signals/enums/EnumState.java index 129bc4f30..e9ac34d39 100644 --- a/src/main/java/com/troblecodings/signals/enums/EnumState.java +++ b/src/main/java/com/troblecodings/signals/enums/EnumState.java @@ -1,6 +1,7 @@ package com.troblecodings.signals.enums; import com.troblecodings.core.interfaces.NamableWrapper; +import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.core.ReadBuffer; public enum EnumState implements NamableWrapper { @@ -24,7 +25,9 @@ public static EnumState of(final String name) { return state; } } - return null; + OpenSignalsMain.getLogger().error("[" + name + + "] is not a valid state of EnumState! [DISABLED] was taken as default!"); + return EnumState.DISABLED; } public static EnumState of(final ReadBuffer buffer) { diff --git a/src/main/java/com/troblecodings/signals/enums/ShowTypes.java b/src/main/java/com/troblecodings/signals/enums/ShowTypes.java new file mode 100644 index 000000000..63e751b1b --- /dev/null +++ b/src/main/java/com/troblecodings/signals/enums/ShowTypes.java @@ -0,0 +1,7 @@ +package com.troblecodings.signals.enums; + +public enum ShowTypes { + + ALL, SIGNAL, INPUT, OUTPUT; + +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/guis/ContainerPlacementtool.java b/src/main/java/com/troblecodings/signals/guis/ContainerPlacementtool.java index 2440a85bc..767b5b554 100644 --- a/src/main/java/com/troblecodings/signals/guis/ContainerPlacementtool.java +++ b/src/main/java/com/troblecodings/signals/guis/ContainerPlacementtool.java @@ -27,19 +27,17 @@ public class ContainerPlacementtool extends ContainerBase implements INetworkSyn public final Map properties = new HashMap<>(); protected int signalID; protected String signalName = ""; - private final PlayerEntity player; private Signal signal; public ContainerPlacementtool(final GuiInfo info) { super(info); info.base = this; - this.player = info.player; info.player.containerMenu = this; } @Override public void sendAllDataToRemote() { - sendItemProperties(player); + sendItemProperties(getInfo().player); } private void sendItemProperties(final PlayerEntity player) { @@ -77,7 +75,7 @@ private void sendItemProperties(final PlayerEntity player) { public void deserializeServer(final ByteBuffer buf) { final ReadBuffer buffer = new ReadBuffer(buf); final int first = buffer.getByteAsInt(); - final ItemStack stack = player.getMainHandItem(); + final ItemStack stack = getInfo().player.getMainHandItem(); final Placementtool tool = (Placementtool) stack.getItem(); if (first == 255) { final int id = buffer.getInt(); @@ -95,7 +93,7 @@ public void deserializeServer(final ByteBuffer buf) { wrapper.putInteger(Placementtool.BLOCK_TYPE_ID, id); this.signal = tool.getObjFromID(id); properties.clear(); - sendItemProperties(player); + sendItemProperties(getInfo().player); } else { final NBTWrapper wrapper = NBTWrapper.getOrCreateWrapper(stack); final SEProperty property = signal.getProperties().get(first); @@ -113,7 +111,7 @@ public void deserializeClient(final ByteBuffer buf) { final ReadBuffer buffer = new ReadBuffer(buf); signalID = buffer.getInt(); final int size = buffer.getByteAsInt(); - final Placementtool tool = (Placementtool) player.getMainHandItem().getItem(); + final Placementtool tool = (Placementtool) getInfo().player.getMainHandItem().getItem(); final Signal signal = tool.getObjFromID(signalID); final List signalProperties = signal.getProperties(); properties.clear(); diff --git a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java index 56506f344..b72487637 100644 --- a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java +++ b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java @@ -1,12 +1,13 @@ package com.troblecodings.signals.guis; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import java.util.stream.Collectors; import com.troblecodings.guilib.ecs.ContainerBase; import com.troblecodings.guilib.ecs.GuiInfo; @@ -16,6 +17,7 @@ import com.troblecodings.signals.core.PosIdentifier; import com.troblecodings.signals.core.ReadBuffer; import com.troblecodings.signals.core.SubsidiaryEntry; +import com.troblecodings.signals.core.SubsidiaryState; import com.troblecodings.signals.core.WriteBuffer; import com.troblecodings.signals.enums.EnumGuiMode; import com.troblecodings.signals.enums.LinkType; @@ -36,14 +38,12 @@ public class ContainerSignalBox extends ContainerBase implements UIClientSync { + protected final Map> possibleSubsidiaries = new HashMap<>(); protected Map> enabledSubsidiaryTypes = new HashMap<>(); protected SignalBoxGrid grid; - private final AtomicReference> propertiesForType = new AtomicReference<>(); - private final AtomicReference> properties = new AtomicReference<>(); - private final AtomicReference> names = new AtomicReference<>(); - private final GuiInfo info; + private final Map propertiesForType = new HashMap<>(); private SignalBoxTileEntity tile; - private Consumer run; + private Consumer infoUpdates; private Consumer> colorUpdates; public ContainerSignalBox(final GuiInfo info) { @@ -53,7 +53,6 @@ public ContainerSignalBox(final GuiInfo info) { tile.add(this); } info.player.containerMenu = this; - this.info = info; } @Override @@ -61,16 +60,26 @@ public void sendAllDataToRemote() { final SignalBoxGrid grid = tile.getSignalBoxGrid(); final WriteBuffer buffer = new WriteBuffer(); buffer.putByte((byte) SignalBoxNetwork.SEND_GRID.ordinal()); - buffer.putBlockPos(info.pos); + buffer.putBlockPos(getInfo().pos); grid.writeNetwork(buffer); - final PosIdentifier identifier = new PosIdentifier(tile.getBlockPos(), info.world); - final Map positions = SignalBoxHandler.getAllLinkedPos(identifier); + final PosIdentifier identifier = new PosIdentifier(tile.getBlockPos(), getInfo().world); + final Map> possibleSubsidiaries = SignalBoxHandler + .getPossibleSubsidiaries(identifier); + final Map positions = SignalBoxHandler.getAllLinkedPos(identifier) + .entrySet().stream().filter(e -> !e.getValue().equals(LinkType.SIGNAL)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + buffer.putInt(possibleSubsidiaries.size()); + possibleSubsidiaries.forEach((pos, list) -> { + buffer.putBlockPos(pos); + buffer.putByte((byte) list.size()); + list.forEach(state -> buffer.putByte((byte) state.getID())); + }); buffer.putInt(positions.size()); positions.forEach((pos, type) -> { buffer.putBlockPos(pos); buffer.putByte((byte) type.ordinal()); }); - OpenSignalsMain.network.sendTo(info.player, buffer.build()); + OpenSignalsMain.network.sendTo(getInfo().player, buffer.build()); } @Override @@ -81,19 +90,31 @@ public void deserializeClient(final ByteBuffer buf) { case SEND_GRID: { final BlockPos pos = buffer.getBlockPos(); if (this.tile == null) { - this.tile = (SignalBoxTileEntity) info.world.getBlockEntity(pos); + this.tile = (SignalBoxTileEntity) getInfo().world.getBlockEntity(pos); } grid = tile.getSignalBoxGrid(); grid.readNetwork(buffer); enabledSubsidiaryTypes = new HashMap<>(grid.getAllSubsidiaries()); + propertiesForType.clear(); + possibleSubsidiaries.clear(); + final int signalSize = buffer.getInt(); + for (int i = 0; i < signalSize; i++) { + final BlockPos signalPos = buffer.getBlockPos(); + propertiesForType.put(signalPos, LinkType.SIGNAL); + final List validSubsidiaries = new ArrayList<>(); + final int listSize = buffer.getByteAsInt(); + for (int j = 0; j < listSize; j++) { + validSubsidiaries + .add(SubsidiaryState.ALL_STATES.get(buffer.getByteAsInt())); + } + possibleSubsidiaries.put(signalPos, validSubsidiaries); + } final int size = buffer.getInt(); - final Map allPos = new HashMap<>(); for (int i = 0; i < size; i++) { final BlockPos blockPos = buffer.getBlockPos(); final LinkType type = LinkType.of(buffer); - allPos.put(blockPos, type); + propertiesForType.put(blockPos, type); } - propertiesForType.set(allPos); update(); break; } @@ -102,11 +123,11 @@ public void deserializeClient(final ByteBuffer buf) { break; } case NO_PW_FOUND: { - run.accept(I18n.get("error.nopathfound")); + infoUpdates.accept(I18n.get("error.nopathfound")); break; } case NO_OUTPUT_UPDATE: { - run.accept(I18n.get("error.nooutputupdate")); + infoUpdates.accept(I18n.get("error.nooutputupdate")); break; } case OUTPUT_UPDATE: { @@ -173,7 +194,7 @@ public void deserializeServer(final ByteBuffer buf) { if (!grid.requestWay(start, end)) { final WriteBuffer error = new WriteBuffer(); error.putByte((byte) SignalBoxNetwork.NO_PW_FOUND.ordinal()); - OpenSignalsMain.network.sendTo(info.player, error.build()); + OpenSignalsMain.network.sendTo(getInfo().player, error.build()); } break; } @@ -200,16 +221,16 @@ public void deserializeServer(final ByteBuffer buf) { if (pos == null) { final WriteBuffer error = new WriteBuffer(); error.putByte((byte) SignalBoxNetwork.NO_OUTPUT_UPDATE.ordinal()); - OpenSignalsMain.network.sendTo(info.player, error.build()); + OpenSignalsMain.network.sendTo(getInfo().player, error.build()); } else { - SignalBoxHandler.updateRedstoneOutput(new PosIdentifier(pos, info.world), + SignalBoxHandler.updateRedstoneOutput(new PosIdentifier(pos, getInfo().world), state); final WriteBuffer sucess = new WriteBuffer(); sucess.putByte((byte) SignalBoxNetwork.OUTPUT_UPDATE.ordinal()); point.writeNetwork(sucess); modeSet.writeNetwork(sucess); sucess.putByte((byte) (state ? 1 : 0)); - OpenSignalsMain.network.sendTo(info.player, sucess.build()); + OpenSignalsMain.network.sendTo(getInfo().player, sucess.build()); } break; } @@ -219,7 +240,7 @@ public void deserializeServer(final ByteBuffer buf) { final SignalBoxNode node = tile.getSignalBoxGrid().getNode(point); node.setAutoPoint(state); SignalBoxHandler.updatePathwayToAutomatic( - new PosIdentifier(tile.getBlockPos(), info.world), point); + new PosIdentifier(tile.getBlockPos(), getInfo().world), point); break; } case SEND_NAME: { @@ -266,37 +287,29 @@ public void removed(final PlayerEntity playerIn) { @Override public PlayerEntity getPlayer() { - return this.info.player; - } - - public Map getProperties() { - return this.properties.get(); - } - - public Map getNames() { - return this.names.get(); + return this.getInfo().player; } public Map getPositionForTypes() { - return this.propertiesForType.get(); + return this.propertiesForType; } @Override public boolean stillValid(final PlayerEntity playerIn) { if (tile.isBlocked() && !tile.isValid(playerIn)) return false; - if (this.info.player == null) { - this.info.player = playerIn; + if (this.getInfo().player == null) { + this.getInfo().player = playerIn; this.tile.add(this); } return true; } protected void setConsumer(final Consumer run) { - this.run = run; + this.infoUpdates = run; } protected void setColorUpdater(final Consumer> updater) { this.colorUpdates = updater; } -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/guis/ContainerSignalController.java b/src/main/java/com/troblecodings/signals/guis/ContainerSignalController.java index d53431b66..f549e609f 100644 --- a/src/main/java/com/troblecodings/signals/guis/ContainerSignalController.java +++ b/src/main/java/com/troblecodings/signals/guis/ContainerSignalController.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; import com.troblecodings.core.interfaces.INetworkSync; import com.troblecodings.guilib.ecs.ContainerBase; @@ -33,10 +32,9 @@ public class ContainerSignalController extends ContainerBase implements UIClientSync, INetworkSync, IChunkLoadable { - private final AtomicReference> reference = new AtomicReference<>(); - private final AtomicReference referenceBlock = new AtomicReference<>(); + private final Map properties = new HashMap<>(); + private Signal currentSignal = null; private List propertiesList; - private final GuiInfo info; private BlockPos linkedPos; private SignalControllerTileEntity controllerEntity; private int currentRSProfile; @@ -51,7 +49,6 @@ public ContainerSignalController(final GuiInfo info) { super(info); info.base = this; info.player.containerMenu = this; - this.info = info; } @Override @@ -60,20 +57,23 @@ public void sendAllDataToRemote() { } private void sendProperitesToClient() { - if (info.pos == null) { + if (getInfo().pos == null) { return; } - controllerEntity = (SignalControllerTileEntity) info.world.getBlockEntity(info.pos); + controllerEntity = (SignalControllerTileEntity) getInfo().world + .getBlockEntity(getInfo().pos); linkedPos = controllerEntity.getLinkedPosition(); if (linkedPos == null) { return; } - referenceBlock.set(controllerEntity.getLinkedSignal()); - final SignalStateInfo stateInfo = new SignalStateInfo(info.world, linkedPos, getSignal()); + currentSignal = controllerEntity.getLinkedSignal(); + final SignalStateInfo stateInfo = new SignalStateInfo(getInfo().world, linkedPos, + getSignal()); final Map properties = SignalStateHandler.getStates(stateInfo); if (properties == null || properties.isEmpty()) return; - reference.set(properties); + this.properties.clear(); + this.properties.putAll(properties); final Map propertiesToSend = new HashMap<>(); properties.forEach((property, value) -> { if ((property.isChangabelAtStage(ChangeableStage.APISTAGE) @@ -133,7 +133,7 @@ private void sendProperitesToClient() { buffer.putByte((byte) (controllerEntity.getProfileRSInput() != -1 ? 1 : 0)); if (controllerEntity.getProfileRSInput() != -1) buffer.putByte(controllerEntity.getProfileRSInput()); - OpenSignalsMain.network.sendTo(info.player, buffer.build()); + OpenSignalsMain.network.sendTo(getInfo().player, buffer.build()); } private void packPropertyToBuffer(final WriteBuffer buffer, final SignalStateInfo stateInfo, @@ -147,17 +147,14 @@ public void deserializeClient(final ByteBuffer buf) { final ReadBuffer buffer = new ReadBuffer(buf); linkedPos = buffer.getBlockPos(); final int signalID = buffer.getInt(); - final Signal signal = Signal.SIGNAL_IDS.get(signalID); - referenceBlock.set(signal); + currentSignal = Signal.SIGNAL_IDS.get(signalID); currentMode = EnumMode.values()[buffer.getByteAsInt()]; final int size = buffer.getByteAsInt(); - final Map properites = new HashMap<>(); - propertiesList = signal.getProperties(); + propertiesList = currentSignal.getProperties(); for (int i = 0; i < size; i++) { final SEProperty property = propertiesList.get(buffer.getByteAsInt()); - properites.put(property, property.getObjFromID(buffer.getByteAsInt())); + properties.put(property, property.getObjFromID(buffer.getByteAsInt())); } - reference.set(properites); lastProfile = buffer.getByteAsInt(); allRSStates.clear(); final int allStatesSize = buffer.getByteAsInt(); @@ -215,7 +212,7 @@ public void deserializeServer(final ByteBuffer buf) { final String value = property.getObjFromID(buffer.getByteAsInt()); if (currentMode.equals(EnumMode.MANUELL)) { SignalStateHandler.setState( - new SignalStateInfo(info.world, linkedPos, getSignal()), property, + new SignalStateInfo(getInfo().world, linkedPos, getSignal()), property, value); } else if (currentMode.equals(EnumMode.SINGLE)) { controllerEntity.updateRedstoneProfile((byte) currentRSProfile, property, @@ -254,8 +251,8 @@ public void deserializeServer(final ByteBuffer buf) { } case UNLINK_INPUT_POS: { final BlockPos linkedInput = controllerEntity.getLinkedRSInput(); - loadChunkAndGetTile(RedstoneIOTileEntity.class, (ServerWorld) info.world, - linkedInput, (tile, _u) -> tile.unlinkController(info.pos)); + loadChunkAndGetTile(RedstoneIOTileEntity.class, (ServerWorld) getInfo().world, + linkedInput, (tile, _u) -> tile.unlinkController(getInfo().pos)); controllerEntity.setLinkedRSInput(null); break; } @@ -268,23 +265,23 @@ private static Direction deserializeDirection(final ReadBuffer buffer) { return Direction.values()[buffer.getByteAsInt()]; } - public Map getReference() { - return reference.get(); + public Map getProperties() { + return properties; } public Signal getSignal() { - return referenceBlock.get(); + return currentSignal; } @Override public PlayerEntity getPlayer() { - return info.player; + return getInfo().player; } @Override public boolean stillValid(final PlayerEntity playerIn) { if (playerIn instanceof PlayerEntity) { - this.info.player = playerIn; + this.getInfo().player = playerIn; } return true; } diff --git a/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java b/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java index 55b9c5930..7d02f44a2 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java @@ -8,16 +8,11 @@ import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; import com.troblecodings.guilib.ecs.GuiInfo; -import com.troblecodings.guilib.ecs.entitys.UIBlockRender; import com.troblecodings.guilib.ecs.entitys.UIBox; import com.troblecodings.guilib.ecs.entitys.UIEntity; import com.troblecodings.guilib.ecs.entitys.UIEnumerable; import com.troblecodings.guilib.ecs.entitys.UITextInput; -import com.troblecodings.guilib.ecs.entitys.input.UIDrag; import com.troblecodings.guilib.ecs.entitys.render.UILabel; -import com.troblecodings.guilib.ecs.entitys.render.UIScissor; -import com.troblecodings.guilib.ecs.entitys.transform.UIIndependentTranslate; -import com.troblecodings.guilib.ecs.entitys.transform.UIRotate; import com.troblecodings.guilib.ecs.entitys.transform.UIScale; import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.SEProperty; @@ -27,7 +22,6 @@ import com.troblecodings.signals.enums.ChangeableStage; import com.troblecodings.signals.items.Placementtool; -import net.minecraft.block.BlockState; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -40,7 +34,7 @@ public class GuiPlacementtool extends GuiBase { public static final int GUI_PLACEMENTTOOL = 0; private final UIEntity list = new UIEntity(); - private final UIBlockRender blockRender = new UIBlockRender(); + private final PreviewSideBar previewSidebar = new PreviewSideBar(-9); private Signal currentSelectedBlock; private final Placementtool tool; private final PlayerEntity player; @@ -63,8 +57,7 @@ public GuiPlacementtool(final GuiInfo info) { private void initInternal() { final UIBox vbox = new UIBox(UIBox.VBOX, 5); this.list.add(vbox); - this.list.setInheritHeight(true); - this.list.setInheritWidth(true); + this.list.setInherits(true); final UIEntity lowerEntity = new UIEntity(); lowerEntity.add(GuiElements.createSpacerH(10)); @@ -76,6 +69,7 @@ private void initInternal() { currentSelectedBlock = tool.getObjFromID(input); this.list.clearChildren(); if (container.signalID != input) { + previewSidebar.clear(); sendSignalId(input); } }); @@ -88,26 +82,10 @@ private void initInternal() { leftSide.add(list); leftSide.add(GuiElements.createPageSelect(vbox)); - final UIEntity blockRenderEntity = new UIEntity(); - blockRenderEntity.setInheritHeight(true); - blockRenderEntity.setWidth(60); - - final UIRotate rotation = new UIRotate(); - rotation.setRotateY(180); - blockRenderEntity.add( - new UIDrag((x, y) -> rotation.setRotateY((float) (rotation.getRotateY() + x)))); - - blockRenderEntity.add(new UIScissor()); - blockRenderEntity.add(new UIIndependentTranslate(35, 150, 40)); - blockRenderEntity.add(rotation); - blockRenderEntity.add(new UIIndependentTranslate(-0.5, -3.5, -0.5)); - blockRenderEntity.add(new UIScale(20, -20, 20)); - blockRenderEntity.add(blockRender); - lowerEntity.add(new UIBox(UIBox.HBOX, 5)); lowerEntity.add(leftSide); - lowerEntity.add(blockRenderEntity); + lowerEntity.add(previewSidebar.get()); lowerEntity.setInheritHeight(true); lowerEntity.setInheritWidth(true); @@ -135,6 +113,7 @@ private void initInternal() { public void of(final SEProperty property, final IntConsumer consumer, final int value) { if (property == null) return; + previewSidebar.addToRenderList(property, value); if (property.isChangabelAtStage(ChangeableStage.GUISTAGE)) { if (property.getParent().equals(JsonEnum.BOOLEAN)) { list.add(GuiElements.createBoolElement(property, consumer, value)); @@ -151,9 +130,7 @@ public void updateFromContainer() { enumerable.setIndex(container.signalID); final List originalProperties = currentSelectedBlock.getProperties(); originalProperties.forEach(property -> { - of(property, - inp -> applyPropertyChanges(currentSelectedBlock.getIDFromProperty(property), - inp), + of(property, inp -> applyPropertyChanges(property, inp), container.properties.get(property)); }); final UIEntity textfield = new UIEntity(); @@ -167,16 +144,18 @@ public void updateFromContainer() { } this.entity.update(); loaded = true; + previewSidebar.update(currentSelectedBlock); } - private void applyPropertyChanges(final int propertyId, final int valueId) { + private void applyPropertyChanges(final SEProperty property, final int valueId) { if (loaded) { + final int propertyId = currentSelectedBlock.getIDFromProperty(property); final WriteBuffer buffer = new WriteBuffer(); buffer.putByte((byte) propertyId); buffer.putByte((byte) valueId); OpenSignalsMain.network.sendTo(player, buffer.build()); + previewSidebar.update(currentSelectedBlock); } - applyModelChanges(); } private void sendSignalId(final int id) { @@ -201,33 +180,4 @@ private void sendName(final String name) { } OpenSignalsMain.network.sendTo(player, buffer.build()); } - - public void applyModelChanges() { - @SuppressWarnings("unused") - final BlockState ebs = currentSelectedBlock.defaultBlockState(); - // Just until the erros are fixed - return; - /* - * final List enumerables = - * this.list.findRecursive(UIEnumerable.class); for (final UIEnumerable - * enumerable : enumerables) { final SEProperty sep = (SEProperty) - * lookup.get(enumerable.getID()); if (sep == null) return; ebs = - * ebs.withProperty(sep, sep.getObjFromID(enumerable.getIndex())); } - * - * final List checkbox = this.list.findRecursive(UICheckBox.class); - * for (final UICheckBox checkb : checkbox) { final SEProperty sep = - * (SEProperty) lookup.get(checkb.getID()); if (sep == null) return; if - * (sep.isChangabelAtStage(ChangeableStage.GUISTAGE)) { ebs = - * ebs.withProperty(sep, checkb.isChecked()); } else if (checkb.isChecked()) { - * ebs = ebs.withProperty(sep, sep.getDefault()); } } - * - * for (final Entry, Optional> prop : - * ebs.getUnlistedProperties() .entrySet()) { final SEProperty property = - * SEProperty.cst(prop.getKey()); if - * (property.isChangabelAtStage(ChangeableStage.APISTAGE_NONE_CONFIG)) { ebs = - * ebs.withProperty(property, property.getDefault()); } } - * - * blockRender.setBlockState(ebs); - */ - } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java b/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java index 0c1db301b..eaab2a541 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java @@ -7,18 +7,19 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; import java.util.stream.Collectors; import com.troblecodings.guilib.ecs.DrawUtil.BoolIntegerables; import com.troblecodings.guilib.ecs.DrawUtil.DisableIntegerable; +import com.troblecodings.guilib.ecs.DrawUtil.EnumIntegerable; import com.troblecodings.guilib.ecs.DrawUtil.SizeIntegerables; import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; import com.troblecodings.guilib.ecs.GuiInfo; import com.troblecodings.guilib.ecs.entitys.UIBox; import com.troblecodings.guilib.ecs.entitys.UIEntity; -import com.troblecodings.guilib.ecs.entitys.UIStack; import com.troblecodings.guilib.ecs.entitys.UITextInput; import com.troblecodings.guilib.ecs.entitys.input.UIClickable; import com.troblecodings.guilib.ecs.entitys.input.UIDrag; @@ -32,14 +33,17 @@ import com.troblecodings.guilib.ecs.entitys.render.UITexture; import com.troblecodings.guilib.ecs.entitys.render.UIToolTip; import com.troblecodings.guilib.ecs.entitys.transform.UIScale; +import com.troblecodings.guilib.ecs.interfaces.IIntegerable; import com.troblecodings.signals.OpenSignalsMain; import com.troblecodings.signals.core.JsonEnumHolder; import com.troblecodings.signals.core.SubsidiaryEntry; +import com.troblecodings.signals.core.SubsidiaryHolder; import com.troblecodings.signals.core.SubsidiaryState; import com.troblecodings.signals.core.WriteBuffer; import com.troblecodings.signals.enums.EnumGuiMode; import com.troblecodings.signals.enums.EnumPathUsage; import com.troblecodings.signals.enums.LinkType; +import com.troblecodings.signals.enums.ShowTypes; import com.troblecodings.signals.enums.SignalBoxNetwork; import com.troblecodings.signals.handler.ClientNameHandler; import com.troblecodings.signals.handler.NameStateInfo; @@ -51,19 +55,22 @@ import com.troblecodings.signals.signalbox.entrys.PathEntryType; import com.troblecodings.signals.signalbox.entrys.PathOptionEntry; +import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; public class GuiSignalBox extends GuiBase { - private static final int SELECTION_COLOR = 0x2900FF00; - private static final int BACKGROUND_COLOR = 0xFF8B8B8B; - private static final int LINE_COLOR = 0xFF5B5B5B; + public static final int SELECTION_COLOR = 0x2900FF00; + // TODO Config + public static final int BACKGROUND_COLOR = ConfigHandler.signalboxBackgroundColor; + public static final int GRID_COLOR = 0xFF5B5B5B; + public static final int EDIT_COLOR = 0x5000A2FF; - private static final float[] ALL_LINES = getLines(); - private static final int TILE_WIDTH = 10; - private static final int TILE_COUNT = 100; + public static final float[] ALL_LINES = getLines(); + public static final int TILE_WIDTH = 10; + public static final int TILE_COUNT = 100; private static float[] getLines() { final float[] lines = new float[2 * (TILE_COUNT + 1) * 4]; @@ -86,16 +93,16 @@ private static float[] getLines() { } private final UIEntity lowerEntity = new UIEntity(); - private final ContainerSignalBox container; + protected final ContainerSignalBox container; private UISignalBoxTile lastTile = null; - @SuppressWarnings("unused") - private Page page = Page.USAGE; private UIEntity mainButton; private final GuiInfo info; private final Map changedModes = new HashMap<>(); private UIEntity plane = null; private boolean allPacketsRecived = false; private final Map allTiles = new HashMap<>(); + private SidePanel helpPage; + private final Map enabledSubsidiaries = new HashMap<>(); public GuiSignalBox(final GuiInfo info) { super(info); @@ -122,9 +129,10 @@ public void update(final String errorString) { } private void resetTileSelection() { - this.entity.findRecursive(UIColor.class).stream() - .filter(color -> color.getColor() == SELECTION_COLOR) + this.entity.findRecursive(UIColor.class).stream().filter( + color -> color.getColor() == SELECTION_COLOR || color.getColor() == EDIT_COLOR) .forEach(color -> color.getParent().remove(color)); + this.lastTile = null; } private void selectLink(final UIEntity parent, final SignalBoxNode node, @@ -168,7 +176,8 @@ private void selectLink(final UIEntity parent, final SignalBoxNode node, } } - private String getSignalInfo(final BlockPos signalPos, final LinkType type) { + public static String getSignalInfo(final BlockPos signalPos, final LinkType type) { + final Minecraft mc = Minecraft.getInstance(); final String customName = ClientNameHandler .getClientName(new NameStateInfo(mc.level, signalPos)); return String.format("%s (x=%d, y=%d. z=%d)", @@ -192,6 +201,7 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, entity.add(modeLabel); parent.add(entity); final Set> entrySet = container.getPositionForTypes().entrySet(); + final ModeSet modeSet = new ModeSet(mode, rotation); switch (mode) { case CORNER: @@ -223,12 +233,86 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, selectLink(parent, node, option, entrySet, LinkType.OUTPUT, PathEntryType.OUTPUT, mode, rotation); - if (option.getEntry(PathEntryType.OUTPUT).isPresent()) - parent.add( - GuiElements.createBoolElement(BoolIntegerables.of("manuell_rs"), e -> { - changeRedstoneOutput(node.getPoint(), new ModeSet(mode, rotation), - e == 1 ? true : false); - }, node.containsManuellOutput(new ModeSet(mode, rotation)) ? 1 : 0)); + if (option.getEntry(PathEntryType.OUTPUT).isPresent()) { + final AtomicBoolean canBeManuelChanged = new AtomicBoolean(true); + for (final Map.Entry entry : node.getModes() + .entrySet()) { + final Optional usage = entry.getValue() + .getEntry(PathEntryType.PATHUSAGE); + if (usage.isPresent() && !usage.get().equals(EnumPathUsage.FREE)) { + canBeManuelChanged.set(false); + break; + } + } + final UILabel currentStatus = new UILabel(I18n.get("info.usage.status") + " : " + + I18n.get("info.usage.status.free")); + currentStatus.setTextColor(new UIEntity().getBasicTextColor()); + final UIEntity statusEntity = new UIEntity(); + statusEntity.setInheritWidth(true); + statusEntity.setHeight(20); + statusEntity.add(new UIScale(1.1f, 1.1f, 1)); + statusEntity.add(currentStatus); + parent.add(GuiElements.createButton(I18n.get("info.usage.manuel"), e1 -> { + final Optional usage = option + .getEntry(PathEntryType.PATHUSAGE); + final UIEntity info = new UIEntity(); + info.setInherits(true); + info.add(new UIBox(UIBox.VBOX, 5)); + info.add(new UIColor(BACKGROUND_COLOR)); + info.add(new UIClickable(_u -> pop(), 1)); + info.add(statusEntity); + final UIEntity textureEntity = new UIEntity(); + textureEntity.setHeight(40); + textureEntity.setWidth(40); + textureEntity.setX(120); + textureEntity.add(new UIToolTip(I18n.get("info.usage.rs.desc"))); + if (canBeManuelChanged.get()) { + if (node.containsManuellOutput(modeSet)) { + textureEntity.add(new UITexture(SidePanel.REDSTONE_ON)); + } else { + textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF)); + } + } else { + if (usage.isPresent() && !usage.get().equals(EnumPathUsage.FREE)) { + textureEntity.add(new UITexture(SidePanel.REDSTONE_ON_BLOCKED)); + } else { + textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF_BLOCKED)); + } + } + info.add(textureEntity); + final UILabel outputStatus = new UILabel( + ((usage.isPresent() && !usage.get().equals(EnumPathUsage.FREE)) + || node.containsManuellOutput(modeSet)) + ? I18n.get("info.usage.rs.true") + : I18n.get("info.usage.rs.false")); + outputStatus.setCenterY(false); + outputStatus.setTextColor(new UIEntity().getBasicTextColor()); + final UIEntity outputEntity = new UIEntity(); + outputEntity.setInheritWidth(true); + outputEntity.setHeight(20); + outputEntity.add(outputStatus); + info.add(outputEntity); + if (canBeManuelChanged.get()) { + info.add(GuiElements.createButton(I18n.get("info.usage.change"), i -> { + final boolean turnOff = node.containsManuellOutput(modeSet); + textureEntity.clear(); + textureEntity.add(new UIToolTip(I18n.get("info.usage.rs.desc"))); + if (turnOff) { + changeRedstoneOutput(node.getPoint(), modeSet, false); + outputStatus.setText(I18n.get("info.usage.rs.false")); + textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF)); + } else { + changeRedstoneOutput(node.getPoint(), modeSet, true); + outputStatus.setText(I18n.get("info.usage.rs.true")); + textureEntity.add(new UITexture(SidePanel.REDSTONE_ON)); + } + })); + } + final UIEntity screen = GuiElements.createScreen(e -> e.add(info)); + push(screen); + })); + parent.add(new UIToolTip(I18n.get("info.usage.manuel.desc"))); + } selectLink(parent, node, option, entrySet, LinkType.INPUT, PathEntryType.BLOCKING, mode, rotation, ".blocking"); @@ -268,20 +352,35 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, final UIEntity list = new UIEntity(); list.setInherits(true); list.add(hbox); - list.add(GuiElements.createButton(I18n.get("btn.return"), a -> { - pop(); - })); - final ModeSet modeSet = new ModeSet(mode, rotation); - SubsidiaryState.ALL_STATES.forEach(state -> { + list.add(GuiElements.createButton(I18n.get("btn.return"), a -> pop())); + final BlockPos pos = option.getEntry(PathEntryType.SIGNAL).get(); + final List subsidiaries = container.possibleSubsidiaries + .getOrDefault(pos, SubsidiaryState.ALL_STATES); + subsidiaries.forEach(state -> { final int defaultValue = container.grid .getSubsidiaryState(node.getPoint(), modeSet, state) ? 0 : 1; list.add(GuiElements.createEnumElement(new SizeIntegerables<>( state.getName(), 2, i -> i == 1 ? "false" : "true"), a -> { final SubsidiaryEntry entry = new SubsidiaryEntry(state, a == 0 ? true : false); - sendSubsidiaryRequest(entry, node, modeSet); + sendSubsidiaryRequest(entry, node.getPoint(), modeSet); container.grid.setClientState(node.getPoint(), modeSet, entry); + final BlockPos signalPos = option + .getEntry(PathEntryType.SIGNAL).orElse(null); + if (signalPos != null) { + if (entry.state) { + enabledSubsidiaries.put(signalPos, + new SubsidiaryHolder(entry, node.getPoint(), + modeSet)); + } else { + enabledSubsidiaries.remove(signalPos); + } + } + pop(); + helpPage.helpUsageMode(enabledSubsidiaries, null, + container.grid.getNodes(), + container.possibleSubsidiaries); pop(); }, defaultValue)); }); @@ -298,7 +397,16 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, default: break; } + } + private void disableSubsidiary(final BlockPos pos, final SubsidiaryHolder holder) { + final SubsidiaryEntry entry = new SubsidiaryEntry(holder.entry.enumValue, false); + sendSubsidiaryRequest(entry, holder.point, holder.modeSet); + container.grid.setClientState(holder.point, holder.modeSet, entry); + enabledSubsidiaries.remove(pos); + helpPage.helpUsageMode(enabledSubsidiaries, null, container.grid.getNodes(), + container.possibleSubsidiaries); + this.resetTileSelection(); } private void tileEdit(final UIEntity tile, final UIMenu menu, final UISignalBoxTile sbt) { @@ -326,15 +434,13 @@ private void tileNormal(final UIEntity tile, final UISignalBoxTile currentTile) } else { if (lastTile == currentTile) { this.resetTileSelection(); - lastTile = null; return; } sendPWRequest(currentTile.getNode()); this.resetTileSelection(); - lastTile = null; } })); - tile.add(new UIClickable(e -> initializePageTileConfig(currentTile.getNode()), 1)); + tile.add(new UIClickable(e -> openNodeShortcuts(currentTile.getNode(), e), 1)); } private void resetSelection(final UIEntity entity) { @@ -345,7 +451,29 @@ private void resetSelection(final UIEntity entity) { entity.findRecursive(UIClickable.class).forEach(click -> click.setVisible(false)); } - private void initializePageTileConfig(final SignalBoxNode node) { + private void openNodeShortcuts(final SignalBoxNode node, final UIEntity entity) { + if (node.isEmpty()) + return; + final AtomicBoolean isAlreadyOpen = new AtomicBoolean(false); + entity.findRecursive(UIColor.class).stream().filter(color -> color.getColor() == EDIT_COLOR) + .forEach(color -> { + color.getParent().remove(color); + helpPage.helpUsageMode(enabledSubsidiaries, null, container.grid.getNodes(), + container.possibleSubsidiaries); + helpPage.setShowHelpPage(false); + isAlreadyOpen.set(true); + this.resetTileSelection(); + }); + if (isAlreadyOpen.get()) + return; + this.resetTileSelection(); + entity.add(new UIColor(EDIT_COLOR)); + helpPage.helpUsageMode(enabledSubsidiaries, node, container.grid.getNodes(), + container.possibleSubsidiaries); + helpPage.setShowHelpPage(true); + } + + protected void initializePageTileConfig(final SignalBoxNode node) { if (node.isEmpty()) return; reset(); @@ -369,28 +497,67 @@ private void initializePageTileConfig(final SignalBoxNode node) { node.forEach(modeSet -> setupModeSettings(list, modeSet.mode, modeSet.rotation, node, node.getOption(modeSet).get())); lowerEntity.add(GuiElements.createPageSelect(box)); - lowerEntity.add(new UIClickable(e -> { - initializeFieldUsage(mainButton); - }, 1)); - pageCheck(Page.TILE_CONFIG); + lowerEntity.add(new UIClickable(e -> initializeFieldUsage(mainButton), 1)); } - private void pageCheck(final Page page) { - this.page = page; - } + private int lastValue = 0; private void initializePageSettings(final UIEntity entity) { + this.initializePageSettings(entity, container.getPositionForTypes()); + } + + private void initializePageSettings(final UIEntity entity, + final Map types) { reset(); - this.pageCheck(Page.SETTINGS); lowerEntity.add(new UIBox(UIBox.VBOX, 2)); lowerEntity.setInheritHeight(true); lowerEntity.setInheritWidth(true); + final IIntegerable sorting = new EnumIntegerable<>(ShowTypes.class); + lowerEntity.add(GuiElements.createEnumElement(sorting, i -> { + lastValue = i; + if (i == -1) + return; + final ShowTypes option = ShowTypes.values()[i]; + switch (option) { + case ALL: { + initializePageSettings(entity); + break; + } + case INPUT: { + initializePageSettings(entity, container.getPositionForTypes().entrySet() + .stream().filter(entry -> entry.getValue().equals(LinkType.INPUT)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + break; + } + case OUTPUT: { + initializePageSettings(entity, container.getPositionForTypes().entrySet() + .stream().filter(entry -> entry.getValue().equals(LinkType.OUTPUT)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + break; + } + case SIGNAL: { + initializePageSettings(entity, container.getPositionForTypes().entrySet() + .stream().filter(entry -> entry.getValue().equals(LinkType.SIGNAL)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + break; + } + default: + break; + } + }, lastValue)); + final UIEntity inputEntity = new UIEntity(); + inputEntity.setInheritWidth(true); + inputEntity.setHeight(20); + final UITextInput input = new UITextInput(""); + inputEntity.add(input); + lowerEntity.add(inputEntity); final UIEntity list = new UIEntity(); final UIBox uibox = new UIBox(UIBox.VBOX, 2); list.add(uibox); - list.setInheritHeight(true); - list.setInheritWidth(true); - container.getPositionForTypes().forEach((p, t) -> { + final Map nameToUIEntity = new HashMap<>(); + list.add(uibox); + list.setInherits(true); + types.forEach((p, t) -> { final String name = getSignalInfo(p, t); final UIEntity layout = new UIEntity(); layout.setHeight(20); @@ -411,18 +578,29 @@ private void initializePageSettings(final UIEntity entity) { list.remove(layout); })); list.add(layout); + nameToUIEntity.put(name.toLowerCase(), layout); }); lowerEntity.add(list); lowerEntity.add(GuiElements.createPageSelect(uibox)); resetSelection(entity); + input.setOnTextUpdate(string -> { + nameToUIEntity.forEach((name, e) -> { + if (!name.contains(string.toLowerCase())) { + list.remove(e); + } else { + list.add(e); + } + }); + }); } private void initializeFieldUsage(final UIEntity entity) { reset(); sendModeChanges(); - initializeFieldTemplate(this::tileNormal); + initializeFieldTemplate(this::tileNormal, false); resetSelection(entity); - this.pageCheck(Page.USAGE); + helpPage.helpUsageMode(enabledSubsidiaries, null, container.grid.getNodes(), + container.possibleSubsidiaries); } private void initializeFieldEdit(final UIEntity entity) { @@ -450,11 +628,14 @@ private void initializeFieldEdit(final UIEntity entity) { final UIMenu menu = new UIMenu(); menu.setVisible(false); initializeFieldTemplate( - (fieldEntity, name) -> this.tileEdit(fieldEntity, menu, name)); + (fieldEntity, name) -> this.tileEdit(fieldEntity, menu, name), true); lowerEntity.add(menu); + menu.setConsumer( + (selection, rotation) -> helpPage.updateNextNode(selection, rotation)); resetSelection(entity); - this.pageCheck(Page.EDIT); resetAllPathways(); + helpPage.updateNextNode(menu.getSelection(), menu.getRotation()); + this.lastTile = null; }); final UIEntity buttonNo = GuiElements.createButton(I18n.get("btn.no"), e -> { pop(); @@ -467,14 +648,10 @@ private void initializeFieldEdit(final UIEntity entity) { selectionEntity.add(buttons); }); push(screen); - pageCheck(Page.CHANGE_MODE); } - private void initializeFieldTemplate(final BiConsumer consumer) { - lowerEntity.add(new UIColor(BACKGROUND_COLOR)); - lowerEntity.add(new UIStack()); - lowerEntity.add(new UIScissor()); - + private void initializeFieldTemplate(final BiConsumer consumer, + final boolean showLines) { plane = new UIEntity(); plane.clearChildren(); plane.setWidth(TILE_COUNT * TILE_WIDTH); @@ -492,9 +669,11 @@ private void initializeFieldTemplate(final BiConsumer plane.setY(plane.getY() + y); plane.update(); }, 2)); - final UILines allLines = new UILines(ALL_LINES, 0.5F); - allLines.setColor(LINE_COLOR); - plane.add(allLines); + if (showLines) { + final UILines allLines = new UILines(ALL_LINES, 0.5F); + allLines.setColor(GRID_COLOR); + plane.add(allLines); + } final UIBox vbox = new UIBox(UIBox.VBOX, 0); vbox.setPageable(false); plane.add(vbox); @@ -533,13 +712,16 @@ private void initializeFieldTemplate(final BiConsumer } plane.add(row); } - lowerEntity.add(plane); - - final UIEntity frame = new UIEntity(); - frame.setInheritHeight(true); - frame.setInheritWidth(true); - frame.add(new UIBorder(0xFF000000, 4)); - lowerEntity.add(frame); + final UIEntity splitter = new UIEntity(); + splitter.add(new UIColor(BACKGROUND_COLOR)); + splitter.add(new UIScissor()); + splitter.add(new UIBorder(0xFF000000, 4)); + splitter.add(plane); + splitter.setInherits(true); + lowerEntity.add(new UIBox(UIBox.HBOX, 2)); + lowerEntity.add(splitter); + helpPage = new SidePanel(lowerEntity, this); + helpPage.setDisableSubdsidiary(this::disableSubsidiary); buildColors(container.grid.getNodes()); } @@ -560,12 +742,13 @@ private void initializeBasicUI() { header.setHeight(20); header.add(new UIBox(UIBox.HBOX, 4)); header.add(titel); - header.add(GuiElements.createSpacerH(80)); + header.add(GuiElements.createSpacerH(40)); header.add( GuiElements.createButton(I18n.get("btn.settings"), this::initializePageSettings)); header.add(GuiElements.createButton(I18n.get("btn.edit"), this::initializeFieldEdit)); mainButton = GuiElements.createButton(I18n.get("btn.main"), this::initializeFieldUsage); header.add(mainButton); + header.add(GuiElements.createSpacerH(5)); resetSelection(mainButton); final UIEntity middlePart = new UIEntity(); @@ -577,7 +760,7 @@ private void initializeBasicUI() { lowerEntity.setInheritHeight(true); lowerEntity.setInheritWidth(true); - initializeFieldTemplate(this::tileNormal); + initializeFieldTemplate(this::tileNormal, false); this.entity.add(GuiElements.createSpacerH(10)); this.entity.add(middlePart); @@ -595,7 +778,7 @@ private void sendPWRequest(final SignalBoxNode currentNode) { OpenSignalsMain.network.sendTo(info.player, buffer.build()); } - private void resetPathwayOnServer(final SignalBoxNode node) { + protected void resetPathwayOnServer(final SignalBoxNode node) { if (!allPacketsRecived) return; final WriteBuffer buffer = new WriteBuffer(); @@ -699,19 +882,20 @@ private void removeBlockPos(final BlockPos pos) { OpenSignalsMain.network.sendTo(info.player, buffer.build()); } - private void sendSubsidiaryRequest(final SubsidiaryEntry entry, final SignalBoxNode node, + protected void sendSubsidiaryRequest(final SubsidiaryEntry entry, final Point point, final ModeSet mode) { if (!allPacketsRecived) return; final WriteBuffer buffer = new WriteBuffer(); buffer.putByte((byte) SignalBoxNetwork.REQUEST_SUBSIDIARY.ordinal()); entry.writeNetwork(buffer); - node.getPoint().writeNetwork(buffer); + point.writeNetwork(buffer); mode.writeNetwork(buffer); OpenSignalsMain.network.sendTo(info.player, buffer.build()); } - private void changeRedstoneOutput(final Point point, final ModeSet mode, final boolean state) { + protected void changeRedstoneOutput(final Point point, final ModeSet mode, + final boolean state) { if (!allPacketsRecived) return; final WriteBuffer buffer = new WriteBuffer(); @@ -722,7 +906,7 @@ private void changeRedstoneOutput(final Point point, final ModeSet mode, final b OpenSignalsMain.network.sendTo(info.player, buffer.build()); } - private void setAutoPoint(final Point point, final byte state) { + protected void setAutoPoint(final Point point, final byte state) { if (!allPacketsRecived) return; final WriteBuffer buffer = new WriteBuffer(); @@ -746,22 +930,31 @@ private void sendName(final Point point, final String name) { } private void reset() { - this.page = Page.NONE; lowerEntity.clear(); } - private static enum Page { - USAGE, EDIT, SETTINGS, TILE_CONFIG, CHANGE_MODE, NONE; - } - @Override public void updateFromContainer() { if (!allPacketsRecived) { + updateEnabledSubsidiaries(); initializeBasicUI(); allPacketsRecived = true; } } + private void updateEnabledSubsidiaries() { + container.enabledSubsidiaryTypes.forEach((point, map) -> map.forEach((modeSet, state) -> { + if (!state.state) + return; + final SignalBoxNode node = container.grid.getNode(point); + if (node == null) + return; + node.getOption(modeSet).get().getEntry(PathEntryType.SIGNAL) + .ifPresent(pos -> enabledSubsidiaries.put(pos, + new SubsidiaryHolder(state, point, modeSet))); + })); + } + private void buildColors(final List nodes) { nodes.forEach(node -> { final UISignalBoxTile tile = allTiles.get(node.getPoint()); diff --git a/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java b/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java index 01b33fca5..2add9d939 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java @@ -11,19 +11,13 @@ import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; import com.troblecodings.guilib.ecs.GuiInfo; -import com.troblecodings.guilib.ecs.entitys.UIBlockRender; import com.troblecodings.guilib.ecs.entitys.UIBox; import com.troblecodings.guilib.ecs.entitys.UIEntity; import com.troblecodings.guilib.ecs.entitys.UIEnumerable; import com.troblecodings.guilib.ecs.entitys.input.UIClickable; -import com.troblecodings.guilib.ecs.entitys.input.UIDrag; import com.troblecodings.guilib.ecs.entitys.render.UIColor; import com.troblecodings.guilib.ecs.entitys.render.UILabel; -import com.troblecodings.guilib.ecs.entitys.render.UIScissor; import com.troblecodings.guilib.ecs.entitys.render.UITexture; -import com.troblecodings.guilib.ecs.entitys.render.UIToolTip; -import com.troblecodings.guilib.ecs.entitys.transform.UIIndependentTranslate; -import com.troblecodings.guilib.ecs.entitys.transform.UIRotate; import com.troblecodings.guilib.ecs.entitys.transform.UIScale; import com.troblecodings.guilib.ecs.interfaces.IIntegerable; import com.troblecodings.signals.OpenSignalsMain; @@ -33,6 +27,8 @@ import com.troblecodings.signals.enums.EnumMode; import com.troblecodings.signals.enums.EnumState; import com.troblecodings.signals.enums.SignalControllerNetwork; +import com.troblecodings.signals.handler.ClientSignalStateHandler; +import com.troblecodings.signals.handler.ClientSignalStateInfo; import com.troblecodings.signals.init.OSBlocks; import com.troblecodings.signals.models.SignalCustomModel; @@ -52,12 +48,13 @@ public class GuiSignalController extends GuiBase { private final ContainerSignalController controller; private final UIEntity lowerEntity = new UIEntity(); - private boolean previewMode = false; private final List holders = new ArrayList<>(); private boolean loaded = false; private final PlayerEntity player; private EnumMode currentMode; private int currentProfile = 0; + private final PreviewSideBar previewSidebar = new PreviewSideBar(-8); + private final PreviewSideBar previewRedstone = new PreviewSideBar(-8); public GuiSignalController(final GuiInfo info) { super(info); @@ -88,8 +85,7 @@ private void initMode(final EnumMode mode) { @SuppressWarnings({ "rawtypes", "unchecked" }) - private void createPageForSide(final Direction face, final UIEntity leftSide, - final UIBlockRender bRender) { + private void createPageForSide(final Direction face, final UIEntity leftSide) { final UIEntity middlePart = new UIEntity(); final IIntegerable profile = SizeIntegerables.of("profile", 32, @@ -98,8 +94,7 @@ private void createPageForSide(final Direction face, final UIEntity leftSide, leftSide.add(GuiElements.createEnumElement(profileEnum, profile, x -> { currentProfile = x; sendRSProfile(x); - updateProfileProperties(middlePart, bRender, profileEnum); - applyModelChange(bRender); + updateProfileProperties(middlePart, profileEnum); }, this.controller.lastProfile)); currentProfile = this.controller.lastProfile; @@ -108,7 +103,7 @@ private void createPageForSide(final Direction face, final UIEntity leftSide, final UIBox boxMode = new UIBox(UIBox.VBOX, 1); middlePart.add(boxMode); - updateProfileProperties(middlePart, bRender, profileEnum); + updateProfileProperties(middlePart, profileEnum); leftSide.add(middlePart); int onIndex = -1; @@ -135,32 +130,37 @@ private void createPageForSide(final Direction face, final UIEntity leftSide, leftSide.add(GuiElements.createPageSelect(boxMode)); } - private void updateProfileProperties(final UIEntity middlePart, final UIBlockRender bRender, - final UIEnumerable profile) { + private void updateProfileProperties(final UIEntity middlePart, final UIEnumerable profile) { middlePart.clearChildren(); profile.setIndex(currentProfile); - final Map properties = controller.allRSStates.containsKey( - currentProfile) ? controller.allRSStates.get(currentProfile) : new HashMap<>(); - controller.getReference().forEach((property, value) -> { + final Map properties = controller.allRSStates + .computeIfAbsent(currentProfile, _u -> new HashMap<>()); + controller.getProperties().forEach((property, value) -> { if (!properties.containsKey(property)) { properties.put(property, "DISABLED"); } }); + ClientSignalStateHandler + .getClientStates(new ClientSignalStateInfo(mc.level, controller.getPos())) + .forEach((property, value) -> { + previewRedstone.addToRenderNormal(property, + property.getParent().getIDFromValue(value)); + }); properties.forEach((property, value) -> { final UIEntity entity = GuiElements .createEnumElement(new DisableIntegerable<>(property), e -> { - applyModelChange(bRender); + previewRedstone.addToRenderNormal(property, e); sendPropertyToServer(property, e); - final Map map = controller.allRSStates - .computeIfAbsent(currentProfile, _u -> new HashMap<>()); if (e == -1) { - map.remove(property); + properties.remove(property); } else { - map.put(property, property.getObjFromID(e)); + properties.put(property, property.getObjFromID(e)); } + previewRedstone.update(controller.getSignal()); }, property.getParent().getIDFromValue(value)); middlePart.add(entity); }); + previewRedstone.update(controller.getSignal()); } private void addSingleRSMode() { @@ -172,8 +172,7 @@ private void addSingleRSMode() { leftSide.add(new UIBox(UIBox.VBOX, 2)); this.lowerEntity.add(leftSide); - final UIBlockRender bRender = new UIBlockRender(); - this.lowerEntity.add(createPreview(bRender)); + this.lowerEntity.add(previewRedstone.get()); final UIEntity rightSide = new UIEntity(); rightSide.setInheritHeight(true); @@ -181,7 +180,7 @@ private void addSingleRSMode() { rightSide.add(new UIBox(UIBox.VBOX, 4)); currentProfile = controller.lastProfile; - createPageForSide(Direction.DOWN, leftSide, bRender); + createPageForSide(Direction.DOWN, leftSide); final Minecraft mc = Minecraft.getInstance(); final BlockState state = OSBlocks.HV_SIGNAL_CONTROLLER.defaultBlockState(); @@ -194,7 +193,7 @@ private void addSingleRSMode() { colors.forEach(c -> c.setColor(0x70000000)); colors.get(e).setColor(0x70FF0000); leftSide.clearChildren(); - createPageForSide(faceing, leftSide, bRender); + createPageForSide(faceing, leftSide); }); rightSide.add(toggle); @@ -282,32 +281,6 @@ private void initInternal() { this.entity.add(new UIBox(UIBox.HBOX, 1)); } - private UIEntity createPreview(final UIBlockRender blockRender) { - final UIToolTip tooltip = new UIToolTip(I18n.get("controller.preview", previewMode)); - - final UIEntity rightSide = new UIEntity(); - rightSide.setWidth(60); - rightSide.setInheritHeight(true); - final UIRotate rotation = new UIRotate(); - rotation.setRotateY(180); - rightSide.add(new UIClickable(e -> { - previewMode = !previewMode; - applyModelChange(blockRender); - tooltip.setDescripton(I18n.get("controller.preview", previewMode)); - }, 1)); - rightSide.add( - new UIDrag((x, y) -> rotation.setRotateY((float) (rotation.getRotateY() + x)))); - rightSide.add(tooltip); - - rightSide.add(new UIScissor()); - rightSide.add(new UIIndependentTranslate(35, 150, 40)); - rightSide.add(rotation); - rightSide.add(new UIIndependentTranslate(-0.5, -3.5, -0.5)); - rightSide.add(new UIScale(20, -20, 20)); - rightSide.add(blockRender); - return rightSide; - } - private void addManuellMode() { final UIEntity list = new UIEntity(); list.setInheritHeight(true); @@ -323,27 +296,28 @@ private void addManuellMode() { leftSide.add(new UIBox(UIBox.VBOX, 5)); lowerEntity.add(leftSide); - final UIBlockRender blockRender = new UIBlockRender(); - lowerEntity.add(createPreview(blockRender)); + previewSidebar.clear(); + lowerEntity.add(previewSidebar.get()); lowerEntity.add(new UIBox(UIBox.HBOX, 1)); holders.clear(); - final Map map = this.controller.getReference(); + final Map map = this.controller.getProperties(); if (map == null) return; map.forEach((property, value) -> { final UIEnumerable enumarable = new UIEnumerable(property.count(), property.getName()); final int index = property.getParent().getIDFromValue(value); list.add(GuiElements.createEnumElement(enumarable, property, e -> { + previewSidebar.addToRenderNormal(property, e); if (loaded) { sendPropertyToServer(property, enumarable.getIndex()); } - applyModelChange(blockRender); + previewSidebar.update(controller.getSignal()); }, index)); holders.add(new UIPropertyEnumHolder(property, enumarable)); }); - applyModelChange(blockRender); + previewSidebar.update(controller.getSignal()); } private void sendAndSetProfile(final Direction facing, final int profile, @@ -423,9 +397,4 @@ public void updateFromContainer() { initInternal(); loaded = true; } - - private void applyModelChange(final UIBlockRender blockRender) { - // TODO new model system - } - } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/guis/PreviewSideBar.java b/src/main/java/com/troblecodings/signals/guis/PreviewSideBar.java new file mode 100644 index 000000000..88e579e91 --- /dev/null +++ b/src/main/java/com/troblecodings/signals/guis/PreviewSideBar.java @@ -0,0 +1,75 @@ +package com.troblecodings.signals.guis; + +import java.util.HashMap; +import java.util.Map; + +import com.troblecodings.guilib.ecs.entitys.UIBlockRender; +import com.troblecodings.guilib.ecs.entitys.UIEntity; +import com.troblecodings.guilib.ecs.entitys.input.UIDrag; +import com.troblecodings.guilib.ecs.entitys.render.UIColor; +import com.troblecodings.guilib.ecs.entitys.render.UIScissor; +import com.troblecodings.signals.SEProperty; +import com.troblecodings.signals.blocks.Signal; +import com.troblecodings.signals.enums.ChangeableStage; +import com.troblecodings.signals.models.ModelInfoWrapper; + +public class PreviewSideBar { + + public static final float MODIFIER = 0.1f; + + private final UIBlockRender blockRender; + private final Map properties = new HashMap<>(); + private final UIEntity blockRenderEntity = new UIEntity(); + + public PreviewSideBar(final float height) { + blockRender = new UIBlockRender(20, height); + blockRenderEntity.setInheritHeight(true); + blockRenderEntity.setWidth(60); + + blockRenderEntity.add(new UIDrag((x, y) -> blockRender + .updateRotation(QuaternionWrapper.fromXYZ(0, (float) x * MODIFIER, 0)))); + + blockRenderEntity.add(new UIScissor()); + blockRenderEntity.add(new UIColor(GuiSignalBox.BACKGROUND_COLOR)); + blockRenderEntity.add(blockRender); + } + + public UIEntity get() { + return blockRenderEntity; + } + + public void addToRenderList(final SEProperty property, final int valueId) { + if (valueId < 0) { + properties.remove(property); + return; + } + if (property.isChangabelAtStage(ChangeableStage.GUISTAGE)) { + properties.put(property, property.getObjFromID(valueId)); + } else if (property.isChangabelAtStage(ChangeableStage.APISTAGE)) { + if (valueId > 0) { + properties.put(property, property.getDefault()); + } else { + properties.remove(property); + } + } else if (property.isChangabelAtStage(ChangeableStage.APISTAGE_NONE_CONFIG)) { + properties.put(property, property.getDefault()); + } + } + + public void addToRenderNormal(final SEProperty property, final int valueId) { + if (valueId < 0) { + properties.put(property, property.getDefault()); + return; + } + properties.put(property, property.getObjFromID(valueId)); + } + + public void clear() { + properties.clear(); + } + + public void update(final Signal signal) { + blockRender.setBlockState(new ModelInfoWrapper(signal, properties)); + } + +} diff --git a/src/main/java/com/troblecodings/signals/guis/SidePanel.java b/src/main/java/com/troblecodings/signals/guis/SidePanel.java new file mode 100644 index 000000000..76b198335 --- /dev/null +++ b/src/main/java/com/troblecodings/signals/guis/SidePanel.java @@ -0,0 +1,550 @@ +package com.troblecodings.signals.guis; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiConsumer; +import java.util.stream.Collectors; + +import com.troblecodings.guilib.ecs.DrawUtil.BoolIntegerables; +import com.troblecodings.guilib.ecs.DrawUtil.SizeIntegerables; +import com.troblecodings.guilib.ecs.GuiElements; +import com.troblecodings.guilib.ecs.entitys.UIBox; +import com.troblecodings.guilib.ecs.entitys.UIEntity; +import com.troblecodings.guilib.ecs.entitys.UIScrollBox; +import com.troblecodings.guilib.ecs.entitys.UITextInput; +import com.troblecodings.guilib.ecs.entitys.input.UIClickable; +import com.troblecodings.guilib.ecs.entitys.input.UIOnUpdate; +import com.troblecodings.guilib.ecs.entitys.input.UIScroll; +import com.troblecodings.guilib.ecs.entitys.render.UIBorder; +import com.troblecodings.guilib.ecs.entitys.render.UIButton; +import com.troblecodings.guilib.ecs.entitys.render.UIColor; +import com.troblecodings.guilib.ecs.entitys.render.UILabel; +import com.troblecodings.guilib.ecs.entitys.render.UIScissor; +import com.troblecodings.guilib.ecs.entitys.render.UITexture; +import com.troblecodings.guilib.ecs.entitys.render.UIToolTip; +import com.troblecodings.guilib.ecs.entitys.transform.UIRotate; +import com.troblecodings.guilib.ecs.entitys.transform.UIScale; +import com.troblecodings.signals.OpenSignalsMain; +import com.troblecodings.signals.core.SubsidiaryEntry; +import com.troblecodings.signals.core.SubsidiaryHolder; +import com.troblecodings.signals.core.SubsidiaryState; +import com.troblecodings.signals.enums.EnumGuiMode; +import com.troblecodings.signals.enums.EnumPathUsage; +import com.troblecodings.signals.handler.ClientNameHandler; +import com.troblecodings.signals.handler.NameStateInfo; +import com.troblecodings.signals.signalbox.ModeSet; +import com.troblecodings.signals.signalbox.Point; +import com.troblecodings.signals.signalbox.SignalBoxNode; +import com.troblecodings.signals.signalbox.entrys.PathEntryType; +import com.troblecodings.signals.signalbox.entrys.PathOptionEntry; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; + +public class SidePanel { + + public static final ResourceLocation REDSTONE_OFF = new ResourceLocation(OpenSignalsMain.MODID, + "gui/textures/redstone_off.png"); + public static final ResourceLocation REDSTONE_OFF_BLOCKED = new ResourceLocation( + OpenSignalsMain.MODID, "gui/textures/redstone_off_blocked.png"); + public static final ResourceLocation REDSTONE_ON = new ResourceLocation(OpenSignalsMain.MODID, + "gui/textures/redstone_on.png"); + public static final ResourceLocation REDSTONE_ON_BLOCKED = new ResourceLocation( + OpenSignalsMain.MODID, "gui/textures/redstone_on_blocked.png"); + + private boolean showHelpPage = false; + private final UIEntity helpPage = new UIEntity(); + private final UIEntity infoEntity = new UIEntity(); + private final UIButton helpPageButton = new UIButton(">"); + private final UIEntity lowerEntity; + private final UIEntity button = new UIEntity(); + private final UIEntity label = new UIEntity(); + private final UIEntity spacerEntity = new UIEntity(); + private final UIEntity helpPageSpacer = new UIEntity(); + private final GuiSignalBox gui; + + private BiConsumer disableSubsidiary; + + public SidePanel(final UIEntity lowerEntity, final GuiSignalBox gui) { + this.lowerEntity = lowerEntity; + this.gui = gui; + + infoEntity.setInherits(true); + infoEntity.add(new UIBox(UIBox.VBOX, 2)); + + helpPage.setInherits(true); + helpPage.add(new UIBox(UIBox.VBOX, 2)); + + final UIRotate rotate = new UIRotate(); + rotate.setRotateZ(90); + label.add(rotate); + final UILabel labelComponent = new UILabel(I18n.get("info.infolabel")); + labelComponent.setTextColor(new UIEntity().getBasicTextColor()); + label.add(labelComponent); + label.setX(2); + + button.setInheritWidth(true); + button.setHeight(20); + button.add(helpPageButton); + button.add(new UIClickable(entity -> { + showHelpPage = !showHelpPage; + addHelpPageToPlane(); + })); + + addHelpPageToPlane(); + + final UIEntity entity = new UIEntity(); + entity.setInherits(true); + entity.add(new UIBox(UIBox.HBOX, 0)); + entity.add(GuiElements.createSpacerH(4)); + entity.add(helpPage); + + spacerEntity.setInheritHeight(true); + spacerEntity.add(new UIBox(UIBox.VBOX, 0)); + spacerEntity.add(button); + spacerEntity.add(entity); + spacerEntity.add(new UIColor(GuiSignalBox.BACKGROUND_COLOR)); + lowerEntity.add(spacerEntity); + + helpPageSpacer.setHeight(30); + } + + public void addHelpPageToPlane() { + if (showHelpPage) { + helpPageButton.setText(I18n.get("info.info") + " >"); + spacerEntity.setWidth(80); + helpPage.clearChildren(); + helpPage.add(infoEntity); + lowerEntity.update(); + } else { + helpPageButton.setText("<"); + helpPage.clearChildren(); + helpPage.add(helpPageSpacer); + helpPage.add(label); + spacerEntity.setWidth(12); + lowerEntity.update(); + } + infoEntity.forEach(entity -> entity.setVisible(showHelpPage)); + label.setVisible(true); + button.setVisible(true); + helpPageSpacer.setVisible(true); + helpPage.update(); + } + + protected void setShowHelpPage(final boolean showHelpPage) { + this.showHelpPage = showHelpPage; + addHelpPageToPlane(); + } + + public void reset() { + + } + + public void add(final UIEntity entity) { + this.helpPage.add(entity); + } + + public void updateNextNode(final int selection, final int rotation) { + infoEntity.clearChildren(); + infoEntity.add(GuiElements.createSpacerV(2)); + infoEntity.add(GuiElements.createLabel(I18n.get("info.nextelement"), + new UIEntity().getBasicTextColor(), 0.8f)); + + final UIEntity preview = new UIEntity(); + preview.setInheritWidth(true); + preview.add(new UIOnUpdate(() -> { + if (preview.getHeight() != preview.getWidth()) { + preview.setHeight(preview.getWidth()); + helpPage.update(); + } + })); + preview.add(new UIColor(0xFFAFAFAF)); + final SignalBoxNode node = new SignalBoxNode(new Point(-1, -1)); + final EnumGuiMode modes = EnumGuiMode.values()[selection]; + node.add(new ModeSet(modes, Rotation.values()[rotation])); + final UISignalBoxTile sbt = new UISignalBoxTile(node); + preview.add(sbt); + preview.add(new UIBorder(new UIEntity().getBasicTextColor())); + + infoEntity.add(preview); + infoEntity.add(GuiElements.createSpacerV(5)); + infoEntity.add(GuiElements.createLabel("[R] = " + I18n.get("info.editor.key.r"), + new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity.add(GuiElements.createLabel("[LMB] = " + I18n.get("info.editor.key.lmb"), + new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity.add(GuiElements.createLabel("[RMB] = " + I18n.get("info.editor.key.rmb"), + new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity.add(GuiElements.createSpacerV(5)); + infoEntity.add(GuiElements.createLabel(I18n.get("info.description"), + new UIEntity().getBasicTextColor(), 0.8f)); + infoEntity.add(GuiElements.createLabel(I18n.get("info." + modes.toString().toLowerCase()), + new UIEntity().getInfoTextColor(), 0.5f)); + addHelpPageToPlane(); + } + + public void helpUsageMode(final Map subsidiaries, + final SignalBoxNode node, final List allNodes, + final Map> possibleSubsidiaries) { + infoEntity.clearChildren(); + + final UIEntity helpScroll = new UIEntity(); + helpScroll.setInheritHeight(true); + helpScroll.setInheritWidth(true); + helpScroll.add(new UIBox(UIBox.HBOX, 0)); + helpScroll.add(new UIScissor()); + infoEntity.add(helpScroll); + + final UIEntity helpList = new UIEntity(); + helpScroll.add(helpList); + helpList.setInheritHeight(true); + helpList.setInheritWidth(true); + + final UIScrollBox helpScrollbox = new UIScrollBox(UIBox.VBOX, 2); + + helpList.add(GuiElements.createLabel(I18n.get("info.keys"), + new UIEntity().getBasicTextColor(), 0.8f)); + helpList.add(GuiElements.createLabel("[LMB] = " + I18n.get("info.usage.key.lmb"), + new UIEntity().getInfoTextColor(), 0.5f)); + helpList.add(GuiElements.createLabel("[RMB] = " + I18n.get("info.usage.key.rmb"), + new UIEntity().getInfoTextColor(), 0.5f)); + + final Minecraft mc = Minecraft.getInstance(); + if (!allNodes.isEmpty()) { + final UIEntity manuelButton = GuiElements.createButton(I18n.get("info.usage.manuel"), + e -> { + final UIEntity screen = GuiElements.createScreen(searchPanel -> { + final UIEntity searchBar = new UIEntity(); + searchBar.setInheritWidth(true); + searchBar.setHeight(20); + final UITextInput input = new UITextInput(""); + searchBar.add(input); + searchPanel.add(searchBar); + + final UIEntity listWithScroll = new UIEntity(); + listWithScroll.setInheritHeight(true); + listWithScroll.setInheritWidth(true); + listWithScroll.add(new UIBox(UIBox.HBOX, 2)); + listWithScroll.add(new UIScissor()); + listWithScroll.add(new UIBorder(0xFF00FFFF)); + searchPanel.add(listWithScroll); + + final UIEntity list = new UIEntity(); + listWithScroll.add(list); + list.setInheritHeight(true); + list.setInheritWidth(true); + + final UIScrollBox scrollbox = new UIScrollBox(UIBox.VBOX, 2); + list.add(scrollbox); + final Map nameToUIEntity = new HashMap<>(); + + allNodes.forEach(currentNode -> { + final UILabel currentStatus = new UILabel( + I18n.format("info.usage.status") + " : " + + I18n.format("info.usage.status.free")); + currentStatus.setTextColor(new UIEntity().getBasicTextColor()); + final UIEntity statusEntity = new UIEntity(); + statusEntity.setInheritWidth(true); + statusEntity.setHeight(20); + statusEntity.add(new UIScale(1.1f, 1.1f, 1)); + statusEntity.add(currentStatus); + final AtomicBoolean canBeManuelChanged = new AtomicBoolean(true); + currentNode.getModes().forEach((mode, entry) -> { + final Optional pathUsage = entry + .getEntry(PathEntryType.PATHUSAGE); + if (pathUsage.isPresent() + && !pathUsage.get().equals(EnumPathUsage.FREE)) { + currentStatus.setText(I18n.format("info.usage.status") + + " : " + I18n.format("info.usage.status.blocked")); + canBeManuelChanged.set(false); + } + if (!entry.containsEntry(PathEntryType.OUTPUT)) + return; + final String name = currentNode.getPoint().toString() + " - " + + ClientNameHandler.getClientName(new NameStateInfo( + mc.world, + entry.getEntry(PathEntryType.OUTPUT).get())); + final UIEntity button = GuiElements.createButton(name, e1 -> { + gui.pop(); + final UIEntity info = new UIEntity(); + info.setInherits(true); + info.add(new UIBox(UIBox.VBOX, 5)); + info.add(new UIClickable(_u -> gui.pop(), 1)); + info.add(new UIColor(GuiSignalBox.BACKGROUND_COLOR)); + info.add(statusEntity); + final UIEntity textureEntity = new UIEntity(); + textureEntity.setHeight(40); + textureEntity.setWidth(40); + textureEntity.setX(120); + textureEntity + .add(new UIToolTip(I18n.get("info.usage.rs.desc"))); + if (canBeManuelChanged.get()) { + if (currentNode.containsManuellOutput(mode)) { + textureEntity.add(new UITexture(REDSTONE_ON)); + } else { + textureEntity.add(new UITexture(REDSTONE_OFF)); + } + } else { + if (pathUsage.isPresent() && !pathUsage.get() + .equals(EnumPathUsage.FREE)) { + textureEntity + .add(new UITexture(REDSTONE_ON_BLOCKED)); + } else { + textureEntity + .add(new UITexture(REDSTONE_OFF_BLOCKED)); + } + } + info.add(textureEntity); + final UILabel outputStatus = new UILabel(((pathUsage + .isPresent() + && !pathUsage.get().equals(EnumPathUsage.FREE)) + || currentNode.containsManuellOutput(mode)) + ? I18n.get("info.usage.rs.true") + : I18n.get("info.usage.rs.false")); + outputStatus.setCenterY(false); + outputStatus + .setTextColor(new UIEntity().getBasicTextColor()); + final UIEntity outputEntity = new UIEntity(); + outputEntity.setInheritWidth(true); + outputEntity.setHeight(20); + outputEntity.add(outputStatus); + info.add(outputEntity); + if (!canBeManuelChanged.get()) { + gui.push(GuiElements + .createScreen(entity -> entity.add(info))); + return; + } + info.add(GuiElements + .createButton(I18n.get("info.usage.change"), i -> { + final boolean turnOff = currentNode + .containsManuellOutput(mode); + textureEntity.clear(); + textureEntity.add(new UIToolTip( + I18n.get("info.usage.rs.desc"))); + if (turnOff) { + gui.changeRedstoneOutput( + currentNode.getPoint(), mode, + false); + outputStatus.setText( + I18n.get("info.usage.rs.false")); + textureEntity + .add(new UITexture(REDSTONE_OFF)); + } else { + gui.changeRedstoneOutput( + currentNode.getPoint(), mode, true); + outputStatus.setText( + I18n.get("info.usage.rs.true")); + textureEntity + .add(new UITexture(REDSTONE_ON)); + } + })); + gui.push(GuiElements + .createScreen(entity -> entity.add(info))); + }); + list.add(button); + nameToUIEntity.put(name.toLowerCase(), button); + + }); + }); + final UIScroll scroll = new UIScroll(); + final UIEntity scrollBar = GuiElements.createScrollBar(scrollbox, 10, + scroll); + scrollbox.setConsumer(size -> { + if (size > list.getHeight()) { + listWithScroll.add(scroll); + listWithScroll.add(scrollBar); + } else { + listWithScroll.remove(scrollBar); + listWithScroll.remove(scroll); + } + }); + input.setOnTextUpdate(string -> { + nameToUIEntity.forEach((name, entity) -> { + if (!name.contains(string.toLowerCase())) { + list.remove(entity); + } else { + list.add(entity); + } + }); + }); + }); + screen.add(new UIClickable(e1 -> gui.pop(), 1)); + gui.push(screen); + }); + manuelButton.setScaleX(0.8f); + manuelButton.setScaleY(0.8f); + manuelButton.setX(5); + helpList.add(manuelButton); + manuelButton.add(new UIToolTip(I18n.get("info.usage.manuel.desc"))); + } + + if (node != null) { + final Map modes = node.getModes(); + final List guiModes = modes.keySet().stream().map(mode -> mode.mode) + .collect(Collectors.toList()); + helpList.add(GuiElements.createLabel(I18n.get("info.usage.node"), + new UIEntity().getBasicTextColor(), 0.8f)); + final UIEntity reset = GuiElements.createButton(I18n.get("button.reset"), + e -> gui.resetPathwayOnServer(node)); + reset.setScaleX(0.8f); + reset.setScaleY(0.8f); + reset.setX(5); + helpList.add(reset); + reset.add(new UIToolTip(I18n.get("button.reset.desc"))); + if (guiModes.contains(EnumGuiMode.HP)) { + final UIEntity entity = GuiElements + .createBoolElement(BoolIntegerables.of("auto_pathway"), e -> { + gui.setAutoPoint(node.getPoint(), (byte) e); + node.setAutoPoint(e == 1 ? true : false); + }, node.isAutoPoint() ? 1 : 0); + entity.setScaleX(0.8f); + entity.setScaleY(0.8f); + entity.setX(5); + helpList.add(entity); + } + for (final Map.Entry mapEntry : modes.entrySet()) { + final ModeSet mode = mapEntry.getKey(); + final PathOptionEntry option = mapEntry.getValue(); + + if (option.containsEntry(PathEntryType.SIGNAL)) { + final BlockPos signalPos = option.getEntry(PathEntryType.SIGNAL).get(); + final String signalName = ClientNameHandler + .getClientName(new NameStateInfo(mc.level, signalPos)); + helpList.add(GuiElements.createLabel( + (signalName.isEmpty() ? "Rotaion: " + mode.rotation.toString() + : signalName) + " - " + mode.mode.toString(), + new UIEntity().getBasicTextColor(), 0.8f)); + final UIEntity entity = GuiElements.createButton(I18n.get("btn.subsidiary"), + e -> { + final UIBox hbox = new UIBox(UIBox.VBOX, 1); + final UIEntity list = new UIEntity(); + list.setInherits(true); + list.add(hbox); + list.add(GuiElements.createButton(I18n.get("btn.return"), + a -> gui.pop())); + final List possibleSubsidiaires = possibleSubsidiaries + .getOrDefault(signalPos, SubsidiaryState.ALL_STATES); + possibleSubsidiaires.forEach(state -> { + final int defaultValue = gui.container.grid.getSubsidiaryState( + node.getPoint(), mode, state) ? 0 : 1; + list.add(GuiElements.createEnumElement( + new SizeIntegerables<>(state.getName(), 2, + i -> i == 1 ? "false" : "true"), + a -> { + final SubsidiaryEntry entry = new SubsidiaryEntry( + state, a == 0 ? true : false); + gui.sendSubsidiaryRequest(entry, node.getPoint(), + mode); + gui.container.grid.setClientState(node.getPoint(), + mode, entry); + if (signalPos != null) { + if (entry.state) { + subsidiaries.put(signalPos, + new SubsidiaryHolder(entry, + node.getPoint(), mode)); + } else { + subsidiaries.remove(signalPos); + } + } + gui.pop(); + helpUsageMode(subsidiaries, node, allNodes, + possibleSubsidiaries); + }, defaultValue)); + }); + final UIEntity screen = GuiElements.createScreen(selection -> { + selection.add(list); + selection.add(GuiElements.createPageSelect(hbox)); + }); + gui.push(screen); + }); + entity.setScaleX(0.8f); + entity.setScaleY(0.8f); + entity.setX(5); + helpList.add(entity); + entity.add(new UIToolTip(I18n.get("btn.subsidiary.desc"))); + } + } + final UIEntity edit = GuiElements.createButton(I18n.get("info.usage.edit"), e -> { + helpUsageMode(subsidiaries, null, allNodes, possibleSubsidiaries); + gui.initializePageTileConfig(node); + }); + edit.setScaleX(0.8f); + edit.setScaleY(0.8f); + edit.setX(5); + helpList.add(edit); + edit.add(new UIToolTip(I18n.get("info.usage.edit.desc"))); + } + + if (!subsidiaries.isEmpty()) { + helpList.add(GuiElements.createLabel(I18n.get("info.usage.subsidiary"), + new UIEntity().getBasicTextColor(), 0.8f)); + subsidiaries.forEach((pos, holder) -> { + final String name = ClientNameHandler + .getClientName(new NameStateInfo(mc.level, pos)); + final UIEntity button = GuiElements.createButton(name, e -> { + final UIEntity screen = GuiElements.createScreen(selectionEntity -> { + final UIBox hbox = new UIBox(UIBox.VBOX, 3); + selectionEntity.add(hbox); + final UIEntity question = new UIEntity(); + final UILabel label = new UILabel( + name + " : " + holder.entry.enumValue.toString().toUpperCase()); + label.setTextColor(0xFFFFFFFF); + question.setScaleX(1.1f); + question.setScaleY(1.1f); + question.add(label); + question.setInherits(true); + final UILabel info = new UILabel(I18n.get("sb.disablesubsidiary")); + info.setTextColor(0xFFFFFFFF); + final UIEntity infoEntity = new UIEntity(); + infoEntity.add(info); + infoEntity.setInherits(true); + selectionEntity.add(question); + selectionEntity.add(infoEntity); + final UIEntity buttons = new UIEntity(); + final UIEntity buttonYes = GuiElements.createButton(I18n.get("btn.yes"), + e1 -> { + gui.pop(); + disableSubsidiary.accept(pos, holder); + }); + final UIEntity buttonNo = GuiElements.createButton(I18n.get("btn.no"), + e2 -> gui.pop()); + buttons.setInherits(true); + final UIBox vbox = new UIBox(UIBox.HBOX, 1); + buttons.add(vbox); + buttons.add(buttonYes); + buttons.add(buttonNo); + selectionEntity.add(buttons); + }); + gui.push(screen); + }); + button.setScaleX(0.8f); + button.setScaleY(0.8f); + button.setX(5); + helpList.add(button); + }); + } + final UIScroll helpScrolling = new UIScroll(); + final UIEntity helpScrollBar = GuiElements.createScrollBar(helpScrollbox, 7, helpScrolling); + helpScrollbox.setConsumer(size -> { + if (size > helpList.getHeight()) { + helpScroll.add(helpScroll); + helpScroll.add(helpScrollBar); + } else { + helpScroll.remove(helpScrollBar); + helpScroll.remove(helpScroll); + } + }); + helpList.add(helpScrollbox); + addHelpPageToPlane(); + } + + public void setDisableSubdsidiary(final BiConsumer consumer) { + this.disableSubsidiary = consumer; + } + +} diff --git a/src/main/java/com/troblecodings/signals/guis/UIMenu.java b/src/main/java/com/troblecodings/signals/guis/UIMenu.java index 0494b2887..03a29fc3e 100644 --- a/src/main/java/com/troblecodings/signals/guis/UIMenu.java +++ b/src/main/java/com/troblecodings/signals/guis/UIMenu.java @@ -1,5 +1,7 @@ package com.troblecodings.signals.guis; +import java.util.function.BiConsumer; + import com.troblecodings.guilib.ecs.entitys.DrawInfo; import com.troblecodings.guilib.ecs.entitys.UIBox; import com.troblecodings.guilib.ecs.entitys.UIComponent; @@ -21,6 +23,8 @@ public class UIMenu extends UIComponent { private double mY; private int selection = 0; private int rotation = 0; + private BiConsumer consumer = (i1, i2) -> { + }; @Override public void draw(final DrawInfo info) { @@ -30,6 +34,10 @@ public void draw(final DrawInfo info) { public void update() { } + public void setConsumer(final BiConsumer consumer) { + this.consumer = consumer; + } + @Override public void postDraw(final DrawInfo info) { if (this.isVisible()) { @@ -76,6 +84,7 @@ public void mouseEvent(final MouseEvent event) { } this.selection = Math.max(0, Math.min(EnumGuiMode.values().length - 1, (int) ((event.x - this.mX) / 22.0f))); + consumer.accept(selection, rotation); this.setVisible(true); break; case RELEASE: @@ -93,6 +102,7 @@ public void keyEvent(final KeyEvent event) { this.rotation++; if (this.rotation >= Rotation.values().length) this.rotation = 0; + consumer.accept(selection, rotation); } } diff --git a/src/main/java/com/troblecodings/signals/handler/ClientSignalStateHandler.java b/src/main/java/com/troblecodings/signals/handler/ClientSignalStateHandler.java index 86bbb71df..d9e914d00 100644 --- a/src/main/java/com/troblecodings/signals/handler/ClientSignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/ClientSignalStateHandler.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import com.google.common.collect.ImmutableMap; import com.troblecodings.core.interfaces.INetworkSync; import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.blocks.Signal; @@ -29,7 +30,7 @@ public class ClientSignalStateHandler implements INetworkSync { public static final Map getClientStates(final ClientSignalStateInfo info) { synchronized (CURRENTLY_LOADED_STATES) { - return CURRENTLY_LOADED_STATES.computeIfAbsent(info, _u -> new HashMap<>()); + return ImmutableMap.copyOf(CURRENTLY_LOADED_STATES.getOrDefault(info, new HashMap<>())); } } diff --git a/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java index af22c6407..0e993b6d3 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java @@ -19,6 +19,7 @@ import com.troblecodings.signals.core.LinkingUpdates; import com.troblecodings.signals.core.PosIdentifier; import com.troblecodings.signals.core.RedstoneUpdatePacket; +import com.troblecodings.signals.core.SubsidiaryState; import com.troblecodings.signals.enums.LinkType; import com.troblecodings.signals.init.OSBlocks; import com.troblecodings.signals.signalbox.PathwayHolder; @@ -186,6 +187,19 @@ public static void relinkAllRedstoneIOs(final PosIdentifier identifier) { holder.getAllRedstoneIOs().forEach(pos -> linkTileToPos(identifier, pos)); } + public static Map> getPossibleSubsidiaries( + final PosIdentifier identifier) { + if (identifier.world.isClientSide) + return new HashMap<>(); + LinkedPositions holder; + synchronized (ALL_LINKED_POS) { + holder = ALL_LINKED_POS.get(identifier); + } + if (holder == null) + return new HashMap<>(); + return holder.getValidSubsidiariesForPos(); + } + public static Signal getSignal(final PosIdentifier identifier, final BlockPos signalPos) { if (identifier.world.isClientSide) return null; diff --git a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java index 384ea352f..5a333b767 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java @@ -167,6 +167,7 @@ public static void setStates(final SignalStateInfo info, final Map getStates(final SignalStateInfo info) { diff --git a/src/main/java/com/troblecodings/signals/init/OSItems.java b/src/main/java/com/troblecodings/signals/init/OSItems.java index ce06153a0..5f8da523e 100644 --- a/src/main/java/com/troblecodings/signals/init/OSItems.java +++ b/src/main/java/com/troblecodings/signals/init/OSItems.java @@ -109,6 +109,7 @@ private OSItems() { public static final Item LAMPS = new Item(new Properties().tab(ItemGroup.TAB_MATERIALS)); public static final Item ELECTRIC_PARTS = new Item( new Properties().tab(ItemGroup.TAB_MATERIALS)); + public static final Item MANIPULATOR = new Item(new Properties().tab(OSTabs.TAB)); public static ArrayList registeredItems = new ArrayList<>(); diff --git a/src/main/java/com/troblecodings/signals/models/CustomModelLoader.java b/src/main/java/com/troblecodings/signals/models/CustomModelLoader.java index 0c69e4432..7051f740e 100644 --- a/src/main/java/com/troblecodings/signals/models/CustomModelLoader.java +++ b/src/main/java/com/troblecodings/signals/models/CustomModelLoader.java @@ -37,7 +37,6 @@ public final class CustomModelLoader implements IModelLoader { private CustomModelLoader() { } - @SuppressWarnings("unchecked") private static void loadExtention(final TextureStats texturestate, final Map extention, final String modelname, final ModelStats states, final Models models, final FunctionParsingInfo info, @@ -54,8 +53,9 @@ private static void loadExtention(final TextureStats texturestate, final Map extentionProperties = extentions.getValue(); final ModelExtention extentionValues = extention.get(extentionName); if (extentionValues == null) - throw new ContentPackException(String - .format("There doesn't exists an extention named [%s]!", extentionName)); + throw new ContentPackException( + String.format("There doesn't exists an extention named [%s]!", + extentionName) + " Valid Extentions: " + extention.keySet()); for (final Map.Entry entry : extentionValues.getExtention() .entrySet()) { @@ -128,7 +128,6 @@ public void prepare() { } - @SuppressWarnings("unchecked") @Override public void onResourceManagerReload(final IResourceManager manager) { registeredModels.clear(); diff --git a/src/main/java/com/troblecodings/signals/parser/FunctionParsingInfo.java b/src/main/java/com/troblecodings/signals/parser/FunctionParsingInfo.java index ad3eefe9e..a3e8d1f63 100644 --- a/src/main/java/com/troblecodings/signals/parser/FunctionParsingInfo.java +++ b/src/main/java/com/troblecodings/signals/parser/FunctionParsingInfo.java @@ -8,6 +8,7 @@ import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.blocks.Signal; +import com.troblecodings.signals.contentpacks.ContentPackException; @SuppressWarnings("rawtypes") public class FunctionParsingInfo { @@ -70,7 +71,8 @@ public Object getProperty(final String propertyName) { }); if (property == null) { throw new LogicalParserException( - String.format("Could not find property=%s in system=%S!", name, signalName)); + String.format("Could not make predicate=%s with system=%S!", argument, + signalName) + " Valid Properties: " + properties); } return property; } @@ -85,6 +87,9 @@ public Object getPredicate() { argument = parts[0]; final SEProperty property = (SEProperty) getProperty(); final String value = parts[1].toUpperCase(); + if (!property.getParent().isValid(new String(value))) + throw new ContentPackException("[" + value + "] is not a valid state of " + property + + "! Valid States: " + property.getParent().getAllowedValues()); return new ValuePack(property, ext -> ext.equals(value)); }); if (predicate == null) diff --git a/src/main/java/com/troblecodings/signals/parser/LogicParser.java b/src/main/java/com/troblecodings/signals/parser/LogicParser.java index 367f91646..eafca0772 100644 --- a/src/main/java/com/troblecodings/signals/parser/LogicParser.java +++ b/src/main/java/com/troblecodings/signals/parser/LogicParser.java @@ -14,7 +14,7 @@ import net.minecraftforge.client.model.data.IModelData; @SuppressWarnings({ - "rawtypes", "unchecked", "deprecation" + "rawtypes", "unchecked" }) public final class LogicParser { @@ -38,7 +38,7 @@ private LogicParser() { objects -> PredicateHolder.hasAndIsNot((SEProperty) objects[0]), SEProperty.class)); TRANSLATION_TABLE.put("check", new MethodInfo(Map.class, "check", - objects -> PredicateHolder.check((ValuePack) objects[0]), ValuePack.class)); + objects -> PredicateHolder.config((ValuePack) objects[0]), ValuePack.class)); TRANSLATION_TABLE.put("config", new MethodInfo(Map.class, "config", objects -> PredicateHolder.config((ValuePack) objects[0]), ValuePack.class)); @@ -145,7 +145,7 @@ public static IntermidiateLogic parse(final String input, final FunctionParsingI return logic; } - public static Predicate predicate(final String input, final FunctionParsingInfo info) { + public static Predicate predicate(final String input, final FunctionParsingInfo info) { return parse(input, info).pop().getPredicate(); } } diff --git a/src/main/java/com/troblecodings/signals/parser/PredicateHolder.java b/src/main/java/com/troblecodings/signals/parser/PredicateHolder.java index 6484deb25..b14969659 100644 --- a/src/main/java/com/troblecodings/signals/parser/PredicateHolder.java +++ b/src/main/java/com/troblecodings/signals/parser/PredicateHolder.java @@ -45,17 +45,6 @@ public static Predicate hasAndIsNot(final SEProperty property) }; } - @Deprecated - @SuppressWarnings("unchecked") - public static Predicate> check(final ValuePack pack) { - return t -> { - final String value = t.get(pack.property); - if (value == null) - return false; - return pack.predicate.test(value.toUpperCase()); - }; - } - @SuppressWarnings("unchecked") public static Predicate> config(final ValuePack pack) { return t -> { diff --git a/src/main/java/com/troblecodings/signals/properties/BooleanProperty.java b/src/main/java/com/troblecodings/signals/properties/BooleanProperty.java deleted file mode 100644 index 3520532a8..000000000 --- a/src/main/java/com/troblecodings/signals/properties/BooleanProperty.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.troblecodings.signals.properties; - -import java.util.function.Predicate; - -@SuppressWarnings("rawtypes") -public class BooleanProperty { - - public final Predicate predicate; - public final boolean doubleSided; - - public BooleanProperty(final Predicate predicate, final boolean doubleSided) { - super(); - this.predicate = predicate; - this.doubleSided = doubleSided; - } - -} diff --git a/src/main/java/com/troblecodings/signals/properties/ConfigProperty.java b/src/main/java/com/troblecodings/signals/properties/ConfigProperty.java deleted file mode 100644 index f1fdb7843..000000000 --- a/src/main/java/com/troblecodings/signals/properties/ConfigProperty.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.troblecodings.signals.properties; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Predicate; - -import com.troblecodings.signals.SEProperty; - -@SuppressWarnings("rawtypes") -public class ConfigProperty { - - public final Predicate predicate; - public Map values; - - public ConfigProperty(final SEProperty property, final String value) { - this(t -> true, property, value); - } - - public ConfigProperty(final Predicate predicate, final SEProperty property, - final String value) { - this.predicate = predicate; - this.values = new HashMap<>(); - this.values.put(property, value); - } - - public ConfigProperty(final Predicate predicate, final Map values) { - this.predicate = predicate; - this.values = values; - } - - public ConfigProperty(final Map values) { - this(t -> true, values); - } - -} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/properties/FloatProperty.java b/src/main/java/com/troblecodings/signals/properties/FloatProperty.java deleted file mode 100644 index fc7d84883..000000000 --- a/src/main/java/com/troblecodings/signals/properties/FloatProperty.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.troblecodings.signals.properties; - -import java.util.Objects; -import java.util.function.Predicate; - -@SuppressWarnings("rawtypes") -public class FloatProperty { - - public final Predicate predicate; - public final float height; - - public FloatProperty(final Predicate predicate, final float height) { - super(); - this.predicate = predicate; - this.height = height; - } - - @Override - public int hashCode() { - return Objects.hash(height, predicate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if ((obj == null) || (getClass() != obj.getClass())) - return false; - final FloatProperty other = (FloatProperty) obj; - return Float.floatToIntBits(height) == Float.floatToIntBits(other.height) - && Objects.equals(predicate, other.predicate); - } - -} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/properties/HeightProperty.java b/src/main/java/com/troblecodings/signals/properties/HeightProperty.java deleted file mode 100644 index 29b6b63f1..000000000 --- a/src/main/java/com/troblecodings/signals/properties/HeightProperty.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.troblecodings.signals.properties; - -import java.util.Objects; -import java.util.function.Predicate; - -@SuppressWarnings("rawtypes") -public class HeightProperty { - - public final Predicate predicate; - public final int height; - - public HeightProperty(final Predicate predicate, final int height) { - super(); - this.predicate = predicate; - this.height = height; - } - - @Override - public int hashCode() { - return Objects.hash(height, predicate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if ((obj == null) || (getClass() != obj.getClass())) - return false; - final HeightProperty other = (HeightProperty) obj; - return height == other.height && Objects.equals(predicate, other.predicate); - } -} diff --git a/src/main/java/com/troblecodings/signals/properties/PredicatedPropertyBase.java b/src/main/java/com/troblecodings/signals/properties/PredicatedPropertyBase.java new file mode 100644 index 000000000..ec30c1d08 --- /dev/null +++ b/src/main/java/com/troblecodings/signals/properties/PredicatedPropertyBase.java @@ -0,0 +1,60 @@ +package com.troblecodings.signals.properties; + +import java.util.Map; +import java.util.Objects; +import java.util.function.Predicate; + +import com.troblecodings.signals.SEProperty; + +public class PredicatedPropertyBase implements Predicate

{ + + public final Predicate

predicate; + public final T state; + + public PredicatedPropertyBase(final Predicate

predicate, final T state) { + this.predicate = Objects.requireNonNull(predicate); + this.state = state; + } + + @SuppressWarnings("unchecked") + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final PredicatedPropertyBase other = (PredicatedPropertyBase) obj; + return Objects.equals(state, other.state); + } + + @Override + public String toString() { + return "PredicatedProperty [state=" + state + "]"; + } + + @Override + public boolean test(final P t) { + return this.predicate.test(t); + } + + // Well because this language is stupid: + public static class PredicateProperty + extends PredicatedPropertyBase> { + + public PredicateProperty(final Predicate> predicate, + final T state) { + super(predicate, state); + } + } + + public static class ConfigProperty + extends PredicatedPropertyBase, Map, Object>> { + + public ConfigProperty(final Predicate, Object>> predicate, + final Map state) { + super(predicate, state); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/properties/SignalPair.java b/src/main/java/com/troblecodings/signals/properties/SignalPair.java deleted file mode 100644 index fa331e8a4..000000000 --- a/src/main/java/com/troblecodings/signals/properties/SignalPair.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.troblecodings.signals.properties; - -import java.util.Objects; - -import com.troblecodings.signals.blocks.Signal; - -public class SignalPair { - - public final Signal start; - public final Signal end; - - public SignalPair(final Signal start, final Signal end) { - super(); - this.start = Objects.requireNonNull(start); - this.end = Objects.requireNonNull(end); - } - - @Override - public int hashCode() { - return Objects.hash(end, start); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if ((obj == null) || (getClass() != obj.getClass())) - return false; - final SignalPair other = (SignalPair) obj; - return Objects.equals(end, other.end) && Objects.equals(start, other.start); - } -} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/properties/SoundProperty.java b/src/main/java/com/troblecodings/signals/properties/SoundProperty.java index 4bf08e7de..79084780d 100644 --- a/src/main/java/com/troblecodings/signals/properties/SoundProperty.java +++ b/src/main/java/com/troblecodings/signals/properties/SoundProperty.java @@ -1,25 +1,20 @@ package com.troblecodings.signals.properties; +import java.util.Map; import java.util.function.Predicate; +import com.troblecodings.signals.SEProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.PredicateProperty; + import net.minecraft.util.SoundEvent; -@SuppressWarnings("rawtypes") -public class SoundProperty { +public class SoundProperty extends PredicateProperty { - public final SoundEvent sound; - public final Predicate predicate; public final int duration; - public SoundProperty() { - this(null, t -> true, -1); - } - - public SoundProperty(final SoundEvent sound, final Predicate predicate, final int duration) { - super(); - this.sound = sound; - this.predicate = predicate; + public SoundProperty(final SoundEvent sound, final Predicate> predicate, + final int duration) { + super(predicate, sound); this.duration = duration; } - -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java b/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java index 95250c471..afcb70370 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java +++ b/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java @@ -36,7 +36,7 @@ public void setWorld(final World world) { this.world = world; startsToPath.values().forEach(pw -> pw.setWorldAndPos(world, tilePos)); } - + public void updatePathwayToAutomatic(final Point point) { final SignalBoxPathway pathway = startsToPath.get(point); if (pathway == null) { @@ -85,7 +85,8 @@ private void updatePrevious(final SignalBoxPathway pathway) { count++; } if (count == 0) { - OpenSignalsMain.getLogger().debug("Could not find previous! " + pathway); + if (OpenSignalsMain.isDebug()) + OpenSignalsMain.getLogger().debug("Could not find previous! " + pathway); } } diff --git a/src/main/java/com/troblecodings/signals/signalbox/Point.java b/src/main/java/com/troblecodings/signals/signalbox/Point.java index 02aad5470..3aa28c01e 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/Point.java +++ b/src/main/java/com/troblecodings/signals/signalbox/Point.java @@ -76,14 +76,14 @@ public String toString() { @Override public void write(final NBTWrapper tag) { - tag.putInteger("x", x); - tag.putInteger("y", y); + tag.putByte("x", (byte) x); + tag.putByte("y", (byte) y); } @Override public void read(final NBTWrapper tag) { - this.x = tag.getInteger("x"); - this.y = tag.getInteger("y"); + this.x = Byte.toUnsignedInt(tag.getByte("x")); + this.y = Byte.toUnsignedInt(tag.getByte("y")); } @Override diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index db7197141..e6ee1a07a 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -6,7 +6,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Function; import java.util.stream.Collectors; import com.google.common.collect.ImmutableList; @@ -24,7 +23,7 @@ import com.troblecodings.signals.handler.SignalBoxHandler; import com.troblecodings.signals.handler.SignalStateHandler; import com.troblecodings.signals.handler.SignalStateInfo; -import com.troblecodings.signals.properties.ConfigProperty; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; import com.troblecodings.signals.signalbox.config.SignalConfig; import com.troblecodings.signals.signalbox.debug.SignalBoxFactory; import com.troblecodings.signals.signalbox.entrys.INetworkSavable; @@ -70,21 +69,22 @@ public void resetAllPathways() { @Override public void write(final NBTWrapper tag) { - tag.putList(NODE_LIST, modeGrid.values().stream().map(node -> { - final NBTWrapper nodeTag = new NBTWrapper(); - node.write(nodeTag); - final Map subsidiaries = enabledSubsidiaryTypes - .get(node.getPoint()); - if (subsidiaries == null) - return nodeTag; - nodeTag.putList(SUBSIDIARY_LIST, subsidiaries.entrySet().stream().map(entry -> { - final NBTWrapper subsidiaryTag = new NBTWrapper(); - entry.getKey().write(subsidiaryTag); - entry.getValue().writeNBT(tag); - return subsidiaryTag; - })::iterator); - return nodeTag; - })::iterator); + tag.putList(NODE_LIST, + modeGrid.values().stream().filter(node -> !node.isEmpty()).map(node -> { + final NBTWrapper nodeTag = new NBTWrapper(); + node.write(nodeTag); + final Map subsidiaries = enabledSubsidiaryTypes + .get(node.getPoint()); + if (subsidiaries == null) + return nodeTag; + nodeTag.putList(SUBSIDIARY_LIST, subsidiaries.entrySet().stream().map(entry -> { + final NBTWrapper subsidiaryTag = new NBTWrapper(); + entry.getKey().write(subsidiaryTag); + entry.getValue().writeNBT(subsidiaryTag); + return subsidiaryTag; + })::iterator); + return nodeTag; + })::iterator); } @Override @@ -101,7 +101,7 @@ public void read(final NBTWrapper tag) { final Map states = new HashMap<>(); subsidiaryTags.forEach(subsidiaryTag -> { final ModeSet mode = new ModeSet(subsidiaryTag); - states.put(mode, SubsidiaryEntry.of(tag)); + states.put(mode, SubsidiaryEntry.of(subsidiaryTag)); }); enabledSubsidiaryTypes.put(node.getPoint(), states); }); @@ -132,10 +132,6 @@ public String toString() { .map(entry -> entry.toString()).collect(Collectors.joining("\n")) + "]"; } - public boolean isEmpty() { - return this.modeGrid.isEmpty(); - } - public SignalBoxNode getNode(final Point point) { return modeGrid.get(point); } @@ -152,15 +148,6 @@ public void putNode(final Point point, final SignalBoxNode node) { modeGrid.put(point, node); } - public SignalBoxNode removeNode(final Point point) { - return modeGrid.remove(point); - } - - public SignalBoxNode computeIfAbsent(final Point point, - final Function funtion) { - return modeGrid.computeIfAbsent(point, funtion); - } - public void putAllNodes(final Map nodes) { modeGrid.putAll(nodes); } @@ -282,7 +269,7 @@ public void updateSubsidiarySignal(final Point point, final ModeSet mode, final SignalStateInfo info = new SignalStateInfo(world, pos.get(), signal); final Map oldProperties = SignalStateHandler.getStates(info); SignalStateHandler.setStates(info, - properties.values.entrySet().stream() + properties.state.entrySet().stream() .filter(propertyEntry -> oldProperties.containsKey(propertyEntry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); states.put(mode, entry); diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxNode.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxNode.java index 4631fa58d..4424fd9af 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxNode.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxNode.java @@ -11,6 +11,7 @@ import java.util.Set; import java.util.stream.Collectors; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.troblecodings.core.NBTWrapper; import com.troblecodings.signals.core.ReadBuffer; @@ -34,7 +35,6 @@ public class SignalBoxNode implements INetworkSavable, Iterable { private final HashMap possibleModes = new HashMap<>(); private final List manuellEnabledOutputs = new ArrayList<>(); private final Point point; - private String identifier; private boolean isAutoPoint = false; private String customText = ""; @@ -44,7 +44,6 @@ public SignalBoxNode() { public SignalBoxNode(final Point point) { this.point = Objects.requireNonNull(point); - this.identifier = point.getX() + "." + point.getY(); } public void add(final ModeSet modeSet) { @@ -192,7 +191,6 @@ public void read(final NBTWrapper compound) { manuellEnabledOutputs.add(modeSet); }); this.point.read(compound); - this.identifier = point.getX() + "." + point.getY(); this.isAutoPoint = compound.getBoolean(IS_AUTO_POINT); this.customText = compound.getString(CUSTOM_NAME); post(); @@ -290,13 +288,6 @@ public Iterator iterator() { return this.possibleModes.keySet().iterator(); } - /** - * @return the identifier - */ - public String getIdentifier() { - return identifier; - } - @Override public void readNetwork(final ReadBuffer buffer) { possibleModes.clear(); @@ -395,4 +386,8 @@ public void setCustomText(final String text) { this.customText = text; } + public Map getModes() { + return ImmutableMap.copyOf(possibleModes); + } + } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 213ac2341..a08a4ab43 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -319,8 +319,13 @@ public void compact(final Point point) { public Optional tryReset(final BlockPos position) { final SignalBoxNode node = this.mapOfResetPositions.get(position); - if (node == null) - return Optional.empty(); + if (node == null) { + if (checkReverseReset(position)) { + return Optional.of(firstPoint); + } else { + return Optional.empty(); + } + } final Point point = node.getPoint(); final AtomicBoolean atomic = new AtomicBoolean(false); foreachEntry((option, cNode) -> { @@ -335,6 +340,41 @@ public Optional tryReset(final BlockPos position) { return Optional.of(point); } + private boolean checkReverseReset(final BlockPos pos) { + final SignalBoxNode firstNode = listOfNodes.get(listOfNodes.size() - 1); + for (final Rotation rot : Rotation.values()) { + if (tryReversReset(pos, firstNode, rot)) { + return true; + } + } + return false; + } + + private boolean tryReversReset(final BlockPos pos, final SignalBoxNode node, + final Rotation rot) { + final AtomicBoolean canReset = new AtomicBoolean(false); + for (final EnumGuiMode mode : Arrays.asList(EnumGuiMode.CORNER, EnumGuiMode.STRAIGHT)) { + node.getOption(new ModeSet(mode, rot)).ifPresent( + entry -> entry.getEntry(PathEntryType.RESETING).ifPresent(blockPos -> { + if (!blockPos.equals(pos)) + return; + final AtomicBoolean atomic = new AtomicBoolean(false); + foreachEntry((option, cNode) -> { + option.getEntry(PathEntryType.BLOCKING).ifPresent(blockingPos -> { + if (isPowerd(blockingPos)) { + atomic.set(true); + } + }); + }); + if (atomic.get()) + return; + canReset.set(true); + this.resetPathway(); + })); + } + return canReset.get(); + } + private boolean isPowerd(final BlockPos pos) { final BlockState state = world.getBlockState(pos); if (state == null || !(state.getBlock() instanceof RedstoneIO)) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxUtil.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxUtil.java index 796c2e6bd..00bba2135 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxUtil.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxUtil.java @@ -17,6 +17,7 @@ public final class SignalBoxUtil { + // TODO Config public static final int FREE_COLOR = 0xFF000000; public static final int SELECTED_COLOR = 0xFF00FF00; public static final int USED_COLOR = 0xFFFF0000; diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index 68b133a5e..9c1c50803 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.stream.Collectors; +import com.google.common.collect.Maps; import com.troblecodings.signals.SEProperty; import com.troblecodings.signals.blocks.Signal; import com.troblecodings.signals.contentpacks.ChangeConfigParser; @@ -13,8 +14,7 @@ import com.troblecodings.signals.enums.PathType; import com.troblecodings.signals.handler.SignalStateHandler; import com.troblecodings.signals.handler.SignalStateInfo; -import com.troblecodings.signals.properties.ConfigProperty; -import com.troblecodings.signals.properties.SignalPair; +import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; public final class SignalConfig { @@ -26,8 +26,8 @@ public static void change(final ConfigInfo info) { if (info.type.equals(PathType.NORMAL)) { if (info.nextinfo != null) { final Signal nextSignal = info.nextinfo.signal; - final SignalPair pair = new SignalPair(currentSignal, nextSignal); - final List values = ChangeConfigParser.CHANGECONFIGS.get(pair); + final List values = ChangeConfigParser.CHANGECONFIGS + .get(Maps.immutableEntry(currentSignal, nextSignal)); if (values != null) { changeIfPresent(values, info); } else { @@ -61,11 +61,8 @@ public static void reset(final SignalStateInfo current) { } } - @SuppressWarnings({ - "rawtypes", "unchecked" - }) private static void changeIfPresent(final List values, final ConfigInfo info) { - final Map object = new HashMap<>(); + final Map, Object> object = new HashMap<>(); final Map oldProperties = SignalStateHandler .getStates(info.currentinfo); if (info.nextinfo != null) { @@ -75,8 +72,8 @@ private static void changeIfPresent(final List values, final Con object.put(String.class, info.zs2Value); final Map propertiesToSet = new HashMap<>(); values.forEach(property -> { - if (property.predicate.test(object)) { - propertiesToSet.putAll(property.values.entrySet().stream() + if (property.test(object)) { + propertiesToSet.putAll(property.state.entrySet().stream() .filter(entry -> oldProperties.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } @@ -91,7 +88,7 @@ private static void loadWithoutPredicate(final List values, final Map oldProperties = SignalStateHandler.getStates(current); final Map propertiesToSet = new HashMap<>(); values.forEach(property -> { - propertiesToSet.putAll(property.values.entrySet().stream() + propertiesToSet.putAll(property.state.entrySet().stream() .filter(entry -> oldProperties.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));