Skip to content

Commit

Permalink
Merge pull request #22 from Placeblock/dev-simpleclickfix
Browse files Browse the repository at this point in the history
Dev simpleclickfix
  • Loading branch information
Placeblock authored Sep 10, 2023
2 parents f5a74aa + 7f2ccb4 commit d621ee0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "de.codelix"
version = "1.3.6"
version = "1.3.6a"

var isReleaseVersion = !version.toString().endsWith("SNAPSHOT")
var artifactID = "BetterInventories"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public List<ItemStack> render() {
*/
public GUISection getSectionAt(Vector2d position) {
if (position == null) return null;
for (ChildData<C> childData : this.content) {
for (int i = this.content.size()-1; i >= 0; i--) {
ChildData<C> childData = this.content.get(i);
Vector2d pos = childData.getPosition();
C section = childData.getChild();
if (pos.getX() <= position.getX() && pos.getX() + section.getWidth() - 1 >= position.getX()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,29 @@ public void resizeTest() {
}
}

@Test
public void controlsTest() {
ChestGUI gui = new ChestGUIBuilder(this.plugin)
.height(3)
.title(Component.empty())
.build();
PaginatorGUIPane paginator = new PaginatorBuilder(gui)
.adoptMinMax(gui.getCanvas())
.defaultControls(PaginatorControlsPosition.SPACE_EVENLY)
.build();
paginator.addItems(Collections.nCopies(40, new GUIItem(gui, new ItemStack(Material.DIAMOND_BLOCK))));
gui.getCanvas().setSection(paginator);
gui.update();
assert paginator.getPages() == 2;
assert paginator.getCurrentPage() == 0;
paginator.nextPage();
assert paginator.getCurrentPage() == 1;
paginator.nextPage();
assert paginator.getCurrentPage() == 0;
paginator.previousPage();
assert paginator.getCurrentPage() == 1;
paginator.previousPage();
assert paginator.getCurrentPage() == 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.placeblock.betterinventories;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.MockPlugin;
import de.placeblock.betterinventories.builder.content.GUIButtonBuilder;
import de.placeblock.betterinventories.builder.content.SimpleGUIPaneBuilder;
import de.placeblock.betterinventories.builder.gui.ChestGUIBuilder;
import de.placeblock.betterinventories.content.item.GUIButton;
import de.placeblock.betterinventories.content.item.GUIItem;
import de.placeblock.betterinventories.content.pane.impl.simple.SimpleGUIPane;
import de.placeblock.betterinventories.gui.impl.ChestGUI;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class SimpleGUIPaneTest {
private MockPlugin plugin;

@BeforeEach
public void setup() {
MockBukkit.getOrCreateMock();
this.plugin = MockBukkit.createMockPlugin();
}

@Test
public void zIndexTest() {
ChestGUI chestGUI = new ChestGUIBuilder(this.plugin)
.height(3)
.title(Component.empty())
.build();
SimpleGUIPane pane = new SimpleGUIPaneBuilder(chestGUI)
.adoptMinMax(chestGUI.getCanvas())
.build();
chestGUI.getCanvas().setSection(pane);
SimpleGUIPane fillPane = new SimpleGUIPaneBuilder(chestGUI)
.adoptMinMax(chestGUI.getCanvas())
.build();
fillPane.fill(new GUIItem(chestGUI, new ItemStack(Material.CHEST)));
pane.setSection(fillPane);
GUIButton button = new GUIButtonBuilder(chestGUI)
.item(new ItemStack(Material.DIAMOND))
.build();
pane.setSectionAt(2, button);
chestGUI.update();
assert chestGUI.getClickedSection(2).equals(button);
}

}

0 comments on commit d621ee0

Please sign in to comment.