-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add <SubPages /> tag and document it. (#7326)
Fixes #7195
- Loading branch information
Showing
31 changed files
with
358 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/appeng/client/guidebook/compiler/tags/SubPagesCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package appeng.client.guidebook.compiler.tags; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import appeng.client.guidebook.PageAnchor; | ||
import appeng.client.guidebook.compiler.PageCompiler; | ||
import appeng.client.guidebook.document.block.AlignItems; | ||
import appeng.client.guidebook.document.block.LytBlock; | ||
import appeng.client.guidebook.document.block.LytBlockContainer; | ||
import appeng.client.guidebook.document.block.LytHBox; | ||
import appeng.client.guidebook.document.block.LytList; | ||
import appeng.client.guidebook.document.block.LytListItem; | ||
import appeng.client.guidebook.document.block.LytParagraph; | ||
import appeng.client.guidebook.document.flow.LytFlowLink; | ||
import appeng.client.guidebook.navigation.NavigationNode; | ||
import appeng.client.guidebook.scene.LytItemImage; | ||
import appeng.libs.mdast.mdx.model.MdxJsxElementFields; | ||
|
||
public class SubPagesCompiler extends BlockTagCompiler { | ||
private static final Comparator<NavigationNode> ALPHABETICAL_COMPARATOR = Comparator | ||
.comparing(NavigationNode::title); | ||
|
||
@Override | ||
public Set<String> getTagNames() { | ||
return Set.of("SubPages"); | ||
} | ||
|
||
@Override | ||
protected void compile(PageCompiler compiler, LytBlockContainer parent, MdxJsxElementFields el) { | ||
var pageIdStr = el.getAttributeString("id", null); | ||
var showIcons = MdxAttrs.getBoolean(compiler, parent, el, "icons", false); | ||
var alphabetical = MdxAttrs.getBoolean(compiler, parent, el, "alphabetical", false); | ||
|
||
var navigationTree = compiler.getPageCollection().getNavigationTree(); | ||
|
||
// Find the page in the tree, if it's explicitly set to empty, show the root nav | ||
List<NavigationNode> subNodes; | ||
if ("".equals(pageIdStr)) { | ||
subNodes = navigationTree.getRootNodes(); | ||
} else { | ||
ResourceLocation pageId; | ||
try { | ||
pageId = pageIdStr == null ? compiler.getPageId() : compiler.resolveId(pageIdStr); | ||
} catch (Exception e) { | ||
parent.appendError(compiler, "Invalid id", el); | ||
return; | ||
} | ||
|
||
var node = navigationTree.getNodeById(pageId); | ||
if (node == null) { | ||
parent.appendError(compiler, "Couldn't find page " + pageId + " in the navigation tree", el); | ||
return; // Not found in navigation tree | ||
} | ||
|
||
subNodes = node.children(); | ||
} | ||
|
||
if (alphabetical) { | ||
subNodes = new ArrayList<>(subNodes); | ||
subNodes.sort(ALPHABETICAL_COMPARATOR); | ||
} | ||
|
||
var list = new LytList(false, 0); | ||
for (var childNode : subNodes) { | ||
if (!childNode.hasPage()) { | ||
continue; | ||
} | ||
|
||
var listItem = new LytListItem(); | ||
var listItemPar = new LytParagraph(); | ||
|
||
var link = new LytFlowLink(); | ||
link.setClickCallback(guideScreen -> guideScreen.navigateTo(PageAnchor.page(childNode.pageId()))); | ||
link.appendText(childNode.title()); | ||
listItemPar.append(link); | ||
|
||
LytBlock listItemBlock = listItemPar; | ||
|
||
if (showIcons && !childNode.icon().isEmpty()) { | ||
var lytHBox = new LytHBox(); | ||
|
||
var icon = new LytItemImage(); | ||
icon.setItem(childNode.icon()); | ||
lytHBox.append(icon); | ||
lytHBox.append(listItemPar); | ||
lytHBox.setAlignItems(AlignItems.CENTER); | ||
listItemBlock = lytHBox; | ||
} | ||
|
||
listItem.append(listItemBlock); | ||
list.append(listItem); | ||
} | ||
parent.append(list); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/appeng/client/guidebook/document/block/AlignItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package appeng.client.guidebook.document.block; | ||
|
||
public enum AlignItems { | ||
CENTER, | ||
START, | ||
END | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/appeng/client/guidebook/document/block/LytAxis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package appeng.client.guidebook.document.block; | ||
|
||
public enum LytAxis { | ||
HORIZONTAL, | ||
VERTICAL | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/appeng/client/guidebook/document/block/LytAxisBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package appeng.client.guidebook.document.block; | ||
|
||
/** | ||
* A box that just aligns its content along the vertical or horizontal axis. | ||
*/ | ||
public abstract class LytAxisBox extends LytBox { | ||
private int gap; | ||
|
||
private AlignItems alignItems = AlignItems.START; | ||
|
||
public AlignItems getAlignItems() { | ||
return alignItems; | ||
} | ||
|
||
public void setAlignItems(AlignItems alignItems) { | ||
this.alignItems = alignItems; | ||
} | ||
|
||
public int getGap() { | ||
return gap; | ||
} | ||
|
||
public void setGap(int gap) { | ||
this.gap = gap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.