From 148653ea4c8420d8b0555ad1860e8291141abfea Mon Sep 17 00:00:00 2001 From: Chaos Date: Fri, 4 Feb 2022 23:09:59 +0100 Subject: [PATCH 1/4] Add Reopen to SchematicSelector --- .../src/de/steamwar/inventory/SchematicSelector.java | 9 +++++++++ .../steamwar/inventory/SchematicSelectorInjectable.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index a007562..d795783 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -58,6 +58,8 @@ public class SchematicSelector { private int depth = 0; private Sorting sorting = Sorting.NAME; private boolean invertSorting = false; + @Getter + private SchematicNode lastParent; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; @@ -77,10 +79,17 @@ public class SchematicSelector { if(publicMode == PublicMode.PUBLIC_ONLY) { this.user = SteamwarUser.get(0); } + injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.FRESH); openList(null); } + public void reOpen() { + injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); + openList(lastParent); + } + private void openList(SchematicNode parent) { + lastParent = parent; List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); if(sdoTrigger) { diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java index 7c4d718..29bd658 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java @@ -42,4 +42,11 @@ public interface SchematicSelectorInjectable { default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} + + default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {} + + enum OpenFrom { + FRESH, + REOPEN + } } From 36b738f565707a3e2903c35446d683f51838ee61 Mon Sep 17 00:00:00 2001 From: Chaos Date: Sat, 5 Feb 2022 11:22:57 +0100 Subject: [PATCH 2/4] Change Order --- .../src/de/steamwar/inventory/SchematicSelector.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index d795783..03931a6 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -79,13 +79,13 @@ public class SchematicSelector { if(publicMode == PublicMode.PUBLIC_ONLY) { this.user = SteamwarUser.get(0); } - injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.FRESH); openList(null); + injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.FRESH); } public void reOpen() { - injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); openList(lastParent); + injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); } private void openList(SchematicNode parent) { From 9be20fd60df94dd1719316430e4b4992376d909d Mon Sep 17 00:00:00 2001 From: Chaos Date: Sat, 5 Feb 2022 12:09:03 +0100 Subject: [PATCH 3/4] Accessible Callback --- .../src/de/steamwar/inventory/SchematicSelector.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 03931a6..db42cb1 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -41,7 +41,8 @@ public class SchematicSelector { @Getter private SteamwarUser user; @Getter - private final Consumer callback; + @Setter + private Consumer callback; private final SelectorTarget target; @Getter private final SelectorFilter filter = new SelectorFilter(); From 9fd44392e1b064bac364bf12a4a4d92e5a2555ed Mon Sep 17 00:00:00 2001 From: Chaos Date: Sat, 5 Feb 2022 12:25:40 +0100 Subject: [PATCH 4/4] Add Reopen dir Up --- .../steamwar/inventory/SchematicSelector.java | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index db42cb1..7676de2 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -89,6 +89,12 @@ public class SchematicSelector { injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); } + public void reOpenDirUp() { + depth--; + openList(dirUp(lastParent)); + injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.REOPEN); + } + private void openList(SchematicNode parent) { lastParent = parent; List nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent)); @@ -150,34 +156,38 @@ public class SchematicSelector { inv.open(); } + private SchematicNode dirUp(SchematicNode parent) { + if(!singleDirOpen) { + if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + return null; + } else { + return getParent(parent); + } + } else { + SchematicNode currentParent = parent; + boolean isMember = false; + do { + sdoTrigger = false; + if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) { + isMember = true; + } + currentParent = getParent(currentParent); + if(currentParent == null) + break; + getSchematicList(currentParent); + } while (sdoTrigger); + if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + return null; + } else { + return currentParent; + } + } + } + private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { depth--; - if(!singleDirOpen) { - if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - openList(null); - } else { - openList(getParent(parent)); - } - } else { - SchematicNode currentParent = parent; - boolean isMember = false; - do { - sdoTrigger = false; - if(NodeMember.getNodeMember(currentParent.getId(), user.getId()) != null) { - isMember = true; - } - currentParent = getParent(currentParent); - if(currentParent == null) - break; - getSchematicList(currentParent); - } while (sdoTrigger); - if(isMember || NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - openList(null); - } else { - openList(currentParent); - } - } + openList(dirUp(parent)); return; } if(node.isDir()) {