-
Notifications
You must be signed in to change notification settings - Fork 30
Navigating Between Views
Navigating between views using InventoryFramework is pretty simple and straightforward, but there's some "little things" that you must understand about Data Transitivity and Shared Contexts before really diving into it.
- Basic Usage
openForPlayervs.openForEveryone- Creating Flows with
back()andonResume - Understaing Data Transitivity
Let's get started with the most basic usage of navigation between views, we have the following views:
// A.java
@Override
public void onInit(ViewConfigBuilder config) {
config.title("A");
}
@Override
public void onFirstRender(RenderContext render) {
// Moves player to "B" view on click
render.firstSlot(new ItemStack(Material.DIAMOND))
.onClick(click -> click.openForPlayer(B.class));
}
// B.java
@Override
public void onInit(ViewConfigBuilder config) {
config.title("B");
}
@Override
public void onFirstRender(RenderContext render) {
// Moves player to back to "A" view on click
render.firstSlot(new ItemStack(Material.REDSTONE))
.onClick(click -> click.openForPlayer(A.class));
}Take a look inside the onClick method of each item, we have a openForPlayer method, that method is responsible for opening a view to the player that clicked on the item. Its signature is similar to ViewFrame's open but without the view class parameter. Pretty simple.
It is possible to return to the previous screen using .back() the name of this is "Browsing History" as soon as a screen is opened from another this function will take the player back to the previous screen.
class A extends View {
@Override
public void onFirstRender(RenderContext render) {
// Moves player to "B" view on click
render.firstSlot(...).onClick(click -> click.open(B.class));
}
}
class B extends View {
@Override
public void onFirstRender(RenderContext render) {
// Moves player back to "A" view
render.firstSlot(...).onClick(click -> click.back());
}
}Data transitivity during navigation between screens can simplify data resolution so that it is not necessary to re-declare each piece of data at each navigation.
In the "Opening and Closing" in Basic Usage or "Initial State" in Advanced State Management teaches you how to apply initial data when a view is opened, this data disappears when the view closes, however, you can keep it in case of transition from one screen to another.
- Installation
- Introduction
- Advanced Usage
- Built-In Features
- Extra Features
- Anvil Input
- Proxy Inventory