SteamWar/SpigotCore
Archiviert
13
0

Add Reopen to SchematicSelector #169

Zusammengeführt
Lixfel hat 4 Commits von re_open_schem_gui nach master 2022-02-09 18:20:03 +01:00 zusammengeführt
2 geänderte Dateien mit 53 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -41,7 +41,8 @@ public class SchematicSelector {
@Getter
private SteamwarUser user;
@Getter
private final Consumer<SchematicNode> callback;
@Setter
private Consumer<SchematicNode> callback;
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
@ -58,6 +59,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<SchematicNode> callback) {
this.player = player;
@ -78,9 +81,22 @@ public class SchematicSelector {
this.user = SteamwarUser.get(0);
}
openList(null);
injectable.onSelectorOpen(this, SchematicSelectorInjectable.OpenFrom.FRESH);
}
public void reOpen() {
openList(lastParent);
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<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) {
@ -140,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()) {

Datei anzeigen

@ -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
}
}