mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Better menu switching for Androids
This commit is contained in:
parent
c04b293d62
commit
3826993be2
@ -930,7 +930,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
public void openScriptEditor(Player p, final Block b) throws Exception {
|
public void openScriptEditor(Player p, final Block b) throws Exception {
|
||||||
ChestMenu menu = new ChestMenu("&eScript Editor");
|
ChestMenu menu = new ChestMenu("&eScript Editor");
|
||||||
|
|
||||||
menu.addItem(2, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDliZjZkYjRhZWRhOWQ4ODIyYjlmNzM2NTM4ZThjMThiOWE0ODQ0Zjg0ZWI0NTUwNGFkZmJmZWU4N2ViIn19fQ=="), "&2> Edit Script", "", "&aEdits your current Script"),
|
menu.addItem(1, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDliZjZkYjRhZWRhOWQ4ODIyYjlmNzM2NTM4ZThjMThiOWE0ODQ0Zjg0ZWI0NTUwNGFkZmJmZWU4N2ViIn19fQ=="), "&2> Edit Script", "", "&aEdits your current Script"),
|
||||||
(pl, slot, item, action) -> {
|
(pl, slot, item, action) -> {
|
||||||
try {
|
try {
|
||||||
openScript(pl, b, BlockStorage.getLocationInfo(b.getLocation(), "script"));
|
openScript(pl, b, BlockStorage.getLocationInfo(b.getLocation(), "script"));
|
||||||
@ -941,7 +941,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
menu.addItem(4, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTcxZDg5NzljMTg3OGEwNTk4N2E3ZmFmMjFiNTZkMWI3NDRmOWQwNjhjNzRjZmZjZGUxZWExZWRhZDU4NTIifX19"), "&4> Create new Script", "", "&cDeletes your current Script", "&cand creates a blank one"),
|
menu.addItem(3, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTcxZDg5NzljMTg3OGEwNTk4N2E3ZmFmMjFiNTZkMWI3NDRmOWQwNjhjNzRjZmZjZGUxZWExZWRhZDU4NTIifX19"), "&4> Create new Script", "", "&cDeletes your current Script", "&cand creates a blank one"),
|
||||||
(pl, slot, item, action) -> {
|
(pl, slot, item, action) -> {
|
||||||
try {
|
try {
|
||||||
openScript(pl, b, "START-TURN_LEFT-REPEAT");
|
openScript(pl, b, "START-TURN_LEFT-REPEAT");
|
||||||
@ -952,7 +952,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
menu.addItem(6, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzAxNTg2ZTM5ZjZmZmE2M2I0ZmIzMDFiNjVjYTdkYThhOTJmNzM1M2FhYWI4OWQzODg2NTc5MTI1ZGZiYWY5In19fQ=="), "&6> Download a Script", "", "&eDownload a Script from the Server", "&eYou can edit or simply use it"),
|
menu.addItem(5, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzAxNTg2ZTM5ZjZmZmE2M2I0ZmIzMDFiNjVjYTdkYThhOTJmNzM1M2FhYWI4OWQzODg2NTc5MTI1ZGZiYWY5In19fQ=="), "&6> Download a Script", "", "&eDownload a Script from the Server", "&eYou can edit or simply use it"),
|
||||||
(pl, slot, item, action) -> {
|
(pl, slot, item, action) -> {
|
||||||
try {
|
try {
|
||||||
openScriptDownloader(pl, b, 1);
|
openScriptDownloader(pl, b, 1);
|
||||||
@ -963,6 +963,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
menu.addItem(8, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTE4NWM5N2RiYjgzNTNkZTY1MjY5OGQyNGI2NDMyN2I3OTNhM2YzMmE5OGJlNjdiNzE5ZmJlZGFiMzVlIn19fQ=="), "&6> Back", "", "&7Return to the Android's interface"),
|
||||||
|
(pl, slot, item, action) -> {
|
||||||
|
try {
|
||||||
|
BlockStorage.getInventory(b).open(p);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
menu.open(p);
|
menu.open(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,10 +981,11 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
ChestMenu menu = new ChestMenu("&eScript Editor");
|
ChestMenu menu = new ChestMenu("&eScript Editor");
|
||||||
final String[] commands = script.split("-");
|
final String[] commands = script.split("-");
|
||||||
|
|
||||||
menu.addItem(0, ScriptPart.START.toItemStack());
|
menu.addItem(0, new CustomItem(ScriptPart.START.toItemStack(), ScriptPart.START.toItemStack().getItemMeta().getDisplayName(), "", "&7\u21E8 &eLeft Click &7to return to the Android's interface"));
|
||||||
menu.addMenuClickHandler(0,
|
menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
|
||||||
(pl, slot, item, action) -> false
|
BlockStorage.getInventory(b).open(pl);
|
||||||
);
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 1; i < commands.length; i++) {
|
for (int i = 1; i < commands.length; i++) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
@ -992,10 +1004,11 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addItem(i + additional, ScriptPart.REPEAT.toItemStack());
|
menu.addItem(i + additional, new CustomItem(ScriptPart.REPEAT.toItemStack(), ScriptPart.REPEAT.toItemStack().getItemMeta().getDisplayName(), "", "&7\u21E8 &eLeft Click &7to return to the Android's interface"));
|
||||||
menu.addMenuClickHandler(i + additional,
|
menu.addMenuClickHandler(i + additional, (pl, slot, item, action) -> {
|
||||||
(pl, slot, item, action) -> false
|
BlockStorage.getInventory(b).open(pl);
|
||||||
);
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ItemStack stack = ScriptPart.valueOf(commands[i]).toItemStack();
|
ItemStack stack = ScriptPart.valueOf(commands[i]).toItemStack();
|
||||||
@ -1056,7 +1069,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openScriptDownloader(final Player p, final Block b, final int page) throws Exception {
|
private void openScriptDownloader(final Player p, final Block b, final int page) throws Exception {
|
||||||
final ChestMenu menu = new ChestMenu("Slimefun Guide");
|
final ChestMenu menu = new ChestMenu("Android Scripts");
|
||||||
|
|
||||||
menu.addMenuOpeningHandler(
|
menu.addMenuOpeningHandler(
|
||||||
(pl) -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HAT, 0.7F, 0.7F)
|
(pl) -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HAT, 0.7F, 0.7F)
|
||||||
@ -1088,8 +1101,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
menu.addItem(49, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTA1YTJjYWI4YjY4ZWE1N2UzYWY5OTJhMzZlNDdjOGZmOWFhODdjYzg3NzYyODE5NjZmOGMzY2YzMWEzOCJ9fX0="), "&eUpload a Script", "", "&6Click &7to upload your Android's Script", "&7to the Database"));
|
menu.addItem(48, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTA1YTJjYWI4YjY4ZWE1N2UzYWY5OTJhMzZlNDdjOGZmOWFhODdjYzg3NzYyODE5NjZmOGMzY2YzMWEzOCJ9fX0="), "&eUpload a Script", "", "&6Click &7to upload your Android's Script", "&7to the Database"));
|
||||||
menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
|
menu.addMenuClickHandler(48, (pl, slot, item, action) -> {
|
||||||
final String code = BlockStorage.getLocationInfo(b.getLocation(), "script");
|
final String code = BlockStorage.getLocationInfo(b.getLocation(), "script");
|
||||||
int num = 1;
|
int num = 1;
|
||||||
|
|
||||||
@ -1131,8 +1144,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
menu.addItem(52, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&rNext Page \u21E8", "", "&7(" + page + " / " + pages + ")"));
|
menu.addItem(50, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&rNext Page \u21E8", "", "&7(" + page + " / " + pages + ")"));
|
||||||
menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
|
menu.addMenuClickHandler(50, (pl, slot, item, action) -> {
|
||||||
int next = page + 1;
|
int next = page + 1;
|
||||||
if (next > pages) next = 1;
|
if (next > pages) next = 1;
|
||||||
if (next != page) {
|
if (next != page) {
|
||||||
@ -1145,6 +1158,16 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
menu.addItem(53, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTE4NWM5N2RiYjgzNTNkZTY1MjY5OGQyNGI2NDMyN2I3OTNhM2YzMmE5OGJlNjdiNzE5ZmJlZGFiMzVlIn19fQ=="), "&6> Back", "", "&7Return to the Android's interface"));
|
||||||
|
menu.addMenuClickHandler(53, (pl, slot, item, action) -> {
|
||||||
|
try {
|
||||||
|
openScriptEditor(pl, b);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
int category_index = 45 * (page - 1);
|
int category_index = 45 * (page - 1);
|
||||||
for (int i = 0; i < 45; i++) {
|
for (int i = 0; i < 45; i++) {
|
||||||
int target = category_index + i;
|
int target = category_index + i;
|
||||||
|
@ -74,4 +74,5 @@ public enum ScriptPart {
|
|||||||
public AndroidType getRequiredType() {
|
public AndroidType getRequiredType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user