Skip to content

Commit

Permalink
Attempt to allow updates from pages
Browse files Browse the repository at this point in the history
  • Loading branch information
NickImpact committed Jul 9, 2018
1 parent 0dc25b1 commit e2ae837
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/nickimpact/impactor/gui/v2/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ public Page define(List<Icon> icons, InventoryDimension dimension, int rOffset,
return this;
}

public Page update(List<Icon> icons, InventoryDimension dimension, int rOffset, int cOffset) {
int capacity = dimension.getRows() * dimension.getColumns();
int pages = icons.isEmpty() ? 1 : icons.size() % capacity == 0 ? icons.size() / capacity : icons.size() / capacity + 1;
for(int i = 1; i <= pages; i++) {
Layout.Builder page = Layout.builder().from(layout).page(icons.subList((i - 1) * capacity, i == pages ? icons.size() : i * capacity), dimension, rOffset, cOffset);
this.views.get(i - 1).define(page.build());
}

return this;
}

private Icon update(Icon icon, Text name, int page, int target) {
icon.getDisplay().offer(Keys.DISPLAY_NAME, name);
icon.getDisplay().setQuantity(target);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/nickimpact/impactor/gui/v2/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private UI(SpongePlugin plugin, Builder builder) {
.build(plugin);
this.plugin = plugin;

this.openAction = builder.openAction;
this.closeAction = builder.closeAction;
}

Expand Down

0 comments on commit e2ae837

Please sign in to comment.