InventoryItemAlignment
This commit is contained in:
parent
4bdb3f94d5
commit
18db3514e3
.gradle
7.4
checksums
dependencies-accessors
executionHistory
fileHashes
buildOutputCleanup
build/tmp/compileJava
src/main
java/eu/mhsl/minenet/minigames
instance
game/minigame/config
room
util
resources/lang
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,6 +14,7 @@ import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||
@ -77,13 +78,12 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
int offset = 18;
|
||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(config.getAll().size(), 3);
|
||||
for(Option<?> item : config.getAll()) {
|
||||
Vec2d current = itemAlignment.next();
|
||||
System.out.println(current.x + " : " + current.y);
|
||||
map.put((int) (offset + (current.y * 9) + current.x), item);
|
||||
InventoryItemAlignment.ItemOffset current = itemAlignment.next();
|
||||
map.put(offset + current.get(), item);
|
||||
|
||||
setDummyItem(
|
||||
item.getCurrent(),
|
||||
(int) (offset + (current.y * 9) + current.x)
|
||||
offset + current.get()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,8 @@ public class Room extends MineNetInstance implements Spawnable {
|
||||
|
||||
eventNode().addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel);
|
||||
|
||||
eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> unsetRoom(playerDisconnectEvent.getPlayer()));
|
||||
|
||||
setOwner(owner);
|
||||
|
||||
new GameSelector().setInstance(this, new Pos(0.5, 16, 9.5));
|
||||
|
@ -1,17 +1,23 @@
|
||||
package eu.mhsl.minenet.minigames.instance.room.inventory;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.GameList;
|
||||
import eu.mhsl.minenet.minigames.instance.game.GameType;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameConfigurationInventory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import eu.mhsl.minenet.minigames.util.InventoryItemAlignment;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemHideFlag;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
final private Room room;
|
||||
public MinigameTypeSelectInventory(Room room) {
|
||||
@ -19,13 +25,14 @@ public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
this.room = room;
|
||||
|
||||
int typeCount = 0;
|
||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(GameType.values().length, 1);
|
||||
for (GameType type : GameType.values()) {
|
||||
setClickableItem(
|
||||
ItemStack.builder(type.getIcon())
|
||||
.displayName(type.getTitle().asComponent())
|
||||
.lore(type.getDescription().asComponent())
|
||||
.build(),
|
||||
typeCount,
|
||||
itemAlignment.next().get(),
|
||||
itemClick -> {
|
||||
drawGames(type);
|
||||
}
|
||||
@ -44,11 +51,13 @@ public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
for(int i = 18; i <= 53; i++) {
|
||||
setDummyItem(Material.AIR, i);
|
||||
}
|
||||
int gameCount = 18;
|
||||
for (GameList gameList : GameList.values()) {
|
||||
if(!gameList.getType().equals(type)) continue;
|
||||
int offset = 18;
|
||||
|
||||
GameFactory gameFactory = gameList.getFactory();
|
||||
List<GameList> games = Arrays.stream(GameList.values()).filter(gameList -> gameList.getType().equals(type)).toList();
|
||||
|
||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(games.size(), 4);
|
||||
for (GameList game : games) {
|
||||
GameFactory gameFactory = game.getFactory();
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(gameFactory.symbol())
|
||||
@ -56,10 +65,9 @@ public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
.lore(gameFactory.description())
|
||||
.meta(metaBuilder -> metaBuilder.hideFlag(ItemHideFlag.HIDE_ATTRIBUTES))
|
||||
.build(),
|
||||
gameCount,
|
||||
offset + itemAlignment.next().get(),
|
||||
itemClick -> itemClick.getPlayer().openInventory(new GameConfigurationInventory(room, gameFactory))
|
||||
);
|
||||
gameCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,12 @@ public class InventoryItemAlignment {
|
||||
if(x * y < size) throw new RuntimeException("Not enough space for Item alignment");
|
||||
}
|
||||
|
||||
public Vec2d next() {
|
||||
public ItemOffset next() {
|
||||
counter++;
|
||||
|
||||
if(this.size < 9) return new Vec2d(this.row(this.size).get(counter), y/2);
|
||||
if(this.size < 9) return new ItemOffset(this.row(this.size).get(counter), y > 1 ? 1 : 0);
|
||||
//TODO more items?
|
||||
return new Vec2d(0,0);
|
||||
return new ItemOffset(0,0);
|
||||
|
||||
}
|
||||
|
||||
@ -132,4 +132,26 @@ public class InventoryItemAlignment {
|
||||
}
|
||||
}.get(count);
|
||||
}
|
||||
|
||||
public class ItemOffset {
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public ItemOffset(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return x + (z * 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
map;en_us;de_de
|
||||
localName;English;Deutsch
|
||||
name;English;German
|
||||
symbol;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MTQ1Njg3N2Y1NGJmMWFjZTI1MWU0Y2VlNDBkYmE1OTdkMmNjNDAzNjJjYjhmNGVkNzExZTUwYjBiZTViMyJ9fX0=;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3ODk5YjQ4MDY4NTg2OTdlMjgzZjA4NGQ5MTczZmU0ODc4ODY0NTM3NzQ2MjZiMjRiZDhjZmVjYzc3YjNmIn19fQ==
|
||||
sample;The brown fox jumps over the white fence;Der braune Fuchs springt über den weißen Zaun
|
||||
;;
|
||||
ns:common#;;
|
||||
select_language;Please select your prefered Language;Bitte wähle deine bevorzugte Sprache!
|
||||
welcome;Welcome!;Willkommen!
|
||||
map,en_us,de_de
|
||||
localName,English,Deutsch
|
||||
name,English,German
|
||||
symbol,eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MTQ1Njg3N2Y1NGJmMWFjZTI1MWU0Y2VlNDBkYmE1OTdkMmNjNDAzNjJjYjhmNGVkNzExZTUwYjBiZTViMyJ9fX0=,eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3ODk5YjQ4MDY4NTg2OTdlMjgzZjA4NGQ5MTczZmU0ODc4ODY0NTM3NzQ2MjZiMjRiZDhjZmVjYzc3YjNmIn19fQ==
|
||||
sample,The brown fox jumps over the white fence,Der braune Fuchs springt über den weißen Zaun
|
||||
,,
|
||||
ns:common#,,
|
||||
select_language,Please select your prefered Language,Bitte wähle deine bevorzugte Sprache!
|
||||
welcome,Welcome!,Willkommen!
|
||||
asdasd,asd,ads
|
||||
|
|
Loading…
x
Reference in New Issue
Block a user