Skip to content

Commit 98c2ff1

Browse files
v.1.1.0 part 3
- Paged inv working :D - Need to make it so it's easy to use as an API
1 parent c9ff642 commit 98c2ff1

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

src/main/java/de/littleprogrammer/guiapi/commands/SpawnCommand.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import de.littleprogrammer.guiapi.guis.SimpleGui;
55
import de.littleprogrammer.guiapi.components.Button;
66
import de.littleprogrammer.guiapi.components.Text;
7+
import net.md_5.bungee.api.ChatColor;
78
import org.bukkit.command.Command;
89
import org.bukkit.command.CommandExecutor;
910
import org.bukkit.command.CommandSender;
@@ -46,18 +47,18 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
4647
gui.open((Player) commandSender);*/
4748

4849
List<String> stringList = new ArrayList<>();
49-
stringList.add("String 1");
50-
stringList.add("String 2");
51-
stringList.add("String 3");
52-
stringList.add("String 4");
53-
stringList.add("String 5");
54-
stringList.add("String 6");
55-
stringList.add("String 7");
56-
stringList.add("String 8");
57-
stringList.add("String 9");
58-
stringList.add("String 10");
59-
stringList.add("String 11");
60-
stringList.add("String 12");
50+
stringList.add(ChatColor.GOLD.toString() + ChatColor.BOLD + "Some Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
51+
stringList.add(ChatColor.GREEN.toString() + ChatColor.BOLD + "Another Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
52+
stringList.add(ChatColor.RED.toString() + ChatColor.BOLD + "3rd Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
53+
stringList.add(ChatColor.BLUE.toString() + ChatColor.BOLD + "Happy Happy\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
54+
stringList.add(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Yellow?!\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
55+
stringList.add(ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + "6th Content\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
56+
stringList.add(ChatColor.AQUA.toString() + ChatColor.BOLD + "How many are there?\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
57+
stringList.add(ChatColor.GRAY.toString() + ChatColor.BOLD + "Still same text\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
58+
stringList.add(ChatColor.DARK_AQUA.toString() + ChatColor.BOLD + "You can stop now\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
59+
stringList.add(ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD + "Stop...\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
60+
stringList.add(ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Stooooppp!!!\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
61+
stringList.add(ChatColor.DARK_GREEN.toString() + ChatColor.BOLD + "The end.\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
6162

6263
PagedGui pagedGui = new PagedGui("Title", 0);
6364
pagedGui.addContent(stringList);

src/main/java/de/littleprogrammer/guiapi/components/Text.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ public int getSlot() {
100100
public void setSlot(int slot) {
101101
this.slot = slot;
102102
}
103+
104+
public void updateText(String newText) {
105+
textDisplay.setText(newText);
106+
}
103107
}

src/main/java/de/littleprogrammer/guiapi/guis/PagedGui.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void open(Player player) {
4444
for (int i = 0; i < 3; i++) {
4545
System.out.println("Setting of: " + contents.get(i));
4646
if (contents.size() >= i) {
47-
Text text = new Text(contents.get(i + page), i + 1);
47+
Text text = new Text(contents.get(i + page), i + 1).setSize(1f);
4848
text.setGui(this);
4949
texts.add(text);
5050
components.put(text.getUniqueId(), text);
@@ -65,7 +65,8 @@ public void open(Player player) {
6565
rightButton = new Button(">", ">>", 2).onClick(event -> {
6666
if (GuiApi.getInstance().getGuis().get(player.getUniqueId()) instanceof PagedGui) {
6767
PagedGui gui = (PagedGui) GuiApi.getInstance().getGuis().get(player.getUniqueId());
68-
if (gui.getPage() < gui.getTexts().size() - 3) {
68+
System.out.println("Page " + gui.getPage() + " texts size " + contents.size() + " bool " + (gui.getPage() < contents.size() - 3));
69+
if (gui.getPage() < contents.size() - 3) {
6970
gui.changePage(gui.getPage() + 1);
7071
}
7172
}
@@ -109,7 +110,7 @@ public void updatePosition(Location playerLoc) {
109110
}
110111

111112
for (Button button : buttons.values()) {
112-
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, spacing);
113+
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, 35);
113114

114115
TeleportInterpolator teleportInterpolator = new TeleportInterpolator(button.getEntity(), newComponentLocation, 5, 1);
115116
teleportInterpolator.startInterpolation();
@@ -123,7 +124,7 @@ public void updatePosition(Location playerLoc) {
123124
}
124125

125126
for (Button button : buttons.values()) {
126-
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, spacing);
127+
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, 35);
127128

128129
button.getDisplay().setTeleportDuration(5);
129130
button.getDisplay().teleport(newComponentLocation);
@@ -133,7 +134,10 @@ public void updatePosition(Location playerLoc) {
133134
}
134135

135136
private void changePage(int newPage) {
136-
137+
for (int i = 0; i < 3; i++) {
138+
texts.get(i).updateText(contents.get(i + newPage));
139+
}
140+
this.page = newPage;
137141
}
138142

139143
public void setContents(List<String> contents) {

src/main/java/de/littleprogrammer/guiapi/listeners/GuiEvents.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
3939
if (!(component instanceof Button)) return;
4040

4141
Button button = (Button) component;
42-
//System.out.println("Click on button: " + button.getUniqueId());
4342
button.getClickAction().accept(new PlayerInteractEntityEvent(event.getPlayer(), button.getEntity()));
4443
}
4544
}

src/main/java/de/littleprogrammer/guiapi/utils/Calculations.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ public static Location calculateComponentLocation(Gui gui, Component component,
5757
//Is button in row
5858
switch (buttonAmount) {
5959
case 1:
60-
return centerLoc.clone().subtract(0, 0, 0);
60+
return centerLoc.clone().add(0, 1.5, 0);
6161
case 2:
6262
if (text.getSlot() == 1) {
63-
return locations[0];
63+
return locations[0].clone().add(0, 1.5, 0);
6464
} else if (text.getSlot() == 2) {
65-
return locations[1];
65+
return locations[1].add(0, 1.5, 0);
6666
}
6767
break;
6868
case 3:
6969
if (text.getSlot() == 1) {
70-
return locations[0];
70+
return locations[0].add(0, 1.5, 0);
7171
} else if (text.getSlot() == 2) {
72-
return centerLoc.clone().subtract(0, 0, 0);
72+
return centerLoc.clone().add(0, 1.5, 0);
7373
} else if (text.getSlot() == 3) {
74-
return locations[1];
74+
return locations[1].add(0, 1.5, 0);
7575
}
7676
break;
7777
}

0 commit comments

Comments
 (0)