Skip to content

KPageInventory

Devin Fritz edited this page May 28, 2024 · 1 revision

KPageInvetories can be used to easily navigate through multiple pages inside your inventory. To enable this, KIA allows you to add pages to your inventory. Before we look at how to build pages, lets look at how to build the inventory.

Building the inventory

val inventory = kPageInventory(sender, 5.rows) {
}

Currently the default inventory type is always chest. This is not changeable, because the pages have not been adjusted yet.

Pages

To build pages, please take a look at here.

KIA currently supports 2 types of pages:

  • Static Pages
  • Normal Pages

Static Pages

Static pages are meant to serve a static info display for the user, and will not be included inside the default pagination. Therefore can be used as an entry point for the inventory. As an example, you can use a static page, for your main page like the following:

val inventory = kPageInventory(sender, 5.rows) {
    mainPage = addStaticPage("Main") { 
    }
}

Static pages need an identifier, so you can navigate back to them at any point.

Normal Pages

Normal pages will be included inside the pagination cycle. The pagination cycle will be in the same order, as the pages have been added to the inventory. As an example:

val inventory = kPageInventory(sender, 5.rows) {
    addPage {} // Page 1
    addPage {} // Page 2
    addPage {} // Page 3
}

The cycle will look like the following:

Page 1 -> Page 2 -> Page 3 -> Loop (if enabled)

The pages are implemented as a list, so removing a page will just change the cycle. In the example of removing page 2: Page 1 -> Page 3 -> Loop (if enabled)

Looping

When using the default builder, the looping attribute will be enabled, this means when the user extends the page cycle, it will loop back to the beginning or the back of it. To influence this behaviour you can use the looping property like the following:

val inventory = kPageInventory(sender, 5.rows) {
    looping = false
}

Remember current page

The KPageInventory also allows you to save the current page index the user is on when saved. To enable this feature you can do the following:

val inventory = kPageInventory(sender, 5.rows) {
   savePageWhenClosed = true
}

Keep in mind, to actually make use of this feature, you need to reopen the same inventory reference to the user.

Inventory events

Currently the following events are supported:

val inventory = kPageInventory(sender, 5.rows) {
    onOpen {
        //your code
    }

    onClose {
        //your code
    }
}

Inventories

Item management

Utility

Clone this wiki locally