Fix issues when Description were to long to fit in window.

This commit is contained in:
BONNe 2019-01-26 14:46:03 +02:00
parent d6a39b2600
commit 586b076860
13 changed files with 52 additions and 32 deletions

View File

@ -280,7 +280,7 @@ public class EditChallengeGUI extends CommonGUI
return null;
}
return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
}
@ -305,11 +305,12 @@ public class EditChallengeGUI extends CommonGUI
for (Challenge.ChallengeType type : Challenge.ChallengeType.values())
{
values.add((this.challenge.getChallengeType().equals(type) ? "§2" : "§c") +
values.add((this.challenge.getChallengeType().equals(type) ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.admin.descriptions." + type.name().toLowerCase()));
}
name = this.user.getTranslation("challenges.gui.admin.buttons.type");
name = this.user.getTranslation("challenges.gui.admin.buttons.type",
"[value]", this.challenge.getChallengeType().name());
description = values;
if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND))
@ -450,7 +451,7 @@ public class EditChallengeGUI extends CommonGUI
for (World.Environment environment : World.Environment.values())
{
values.add((this.challenge.getEnvironment().contains(environment.name()) ? "§2" : "§c") +
values.add((this.challenge.getEnvironment().contains(environment.name()) ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.admin.descriptions." + environment.name().toLowerCase()));
}
@ -1153,7 +1154,7 @@ public class EditChallengeGUI extends CommonGUI
return null;
}
return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
}

View File

@ -13,11 +13,10 @@ import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.ItemParser;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.ChallengesManager;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.ItemSwitchGUI;
import world.bentobox.challenges.panel.util.NumberGUI;
@ -253,7 +252,7 @@ public class EditLevelGUI extends CommonGUI
return null;
}
return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
}
@ -266,7 +265,7 @@ public class EditLevelGUI extends CommonGUI
{
return new PanelItemBuilder().
name(challenge.getFriendlyName()).
description(challenge.getDescription()).
description(GuiUtils.stringSplit(challenge.getDescription())).
icon(challenge.getIcon()).
clickHandler((panel, user1, clickType, slot) -> {
// Open challenges edit screen.
@ -591,7 +590,7 @@ public class EditLevelGUI extends CommonGUI
return null;
}
return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
}

View File

@ -66,7 +66,7 @@ public class EditSettingsGUI extends CommonGUI
// resetChallenges
panelBuilder.item(19, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.reset")).
description(this.user.getTranslation("challenges.gui.admin.descriptions.reset")).
description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.reset"))).
icon(Material.LAVA_BUCKET).
clickHandler((panel, user1, clickType, i) -> {
this.addon.getChallengesSettings().setResetChallenges(
@ -79,7 +79,7 @@ public class EditSettingsGUI extends CommonGUI
// broadcastMessages
panelBuilder.item(20, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.broadcast")).
description(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast")).
description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast"))).
icon(Material.JUKEBOX).
clickHandler((panel, user1, clickType, i) -> {
this.addon.getChallengesSettings().setBroadcastMessages(
@ -92,7 +92,7 @@ public class EditSettingsGUI extends CommonGUI
// removeCompleteOneTimeChallenges
panelBuilder.item(21, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete")).
description(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete")).
description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete"))).
icon(Material.MAGMA_BLOCK).
clickHandler((panel, user1, clickType, i) -> {
this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges(
@ -105,7 +105,7 @@ public class EditSettingsGUI extends CommonGUI
// addCompletedGlow
panelBuilder.item(22, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.glow")).
description(this.user.getTranslation("challenges.gui.admin.descriptions.glow")).
description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.glow"))).
icon(Material.GLOWSTONE).
clickHandler((panel, user1, clickType, i) -> {
this.addon.getChallengesSettings().setAddCompletedGlow(
@ -118,7 +118,7 @@ public class EditSettingsGUI extends CommonGUI
// freeChallengesAtTheTop
panelBuilder.item(23, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.free-challenges")).
description(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges")).
description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges"))).
icon(Material.FILLED_MAP).
clickHandler((panel, user1, clickType, i) -> {
this.addon.getChallengesSettings().setFreeChallengesFirst(

View File

@ -134,7 +134,7 @@ public class ListChallengesGUI extends CommonGUI
{
PanelItemBuilder itemBuilder = new PanelItemBuilder().
name(challenge.getFriendlyName()).
description(challenge.getDescription()).
description(GuiUtils.stringSplit(challenge.getDescription())).
icon(challenge.getIcon()).
glow(challenge.isDeployed());

View File

@ -134,7 +134,7 @@ public class ListLevelsGUI extends CommonGUI
{
PanelItemBuilder itemBuilder = new PanelItemBuilder().
name(challengeLevel.getFriendlyName()).
description(challengeLevel.getUnlockMessage()).
description(GuiUtils.stringSplit(challengeLevel.getUnlockMessage())).
icon(challengeLevel.getIcon()).
glow(false);

View File

@ -216,7 +216,7 @@ public class ListUsersGUI extends CommonGUI
return new PanelItemBuilder().
name(player.getName()).
icon(Material.BARRIER).
description(this.user.getTranslation("general.errors.player-has-no-island")).
description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"))).
clickHandler((panel, user1, clickType, slot) -> false).
build();
}
@ -258,7 +258,7 @@ public class ListUsersGUI extends CommonGUI
for (int i = 0; i < ViewMode.values().length; i++)
{
values.add((this.modeIndex == i ? "§2" : "§c") +
values.add((this.modeIndex == i ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.admin.descriptions." +
ViewMode.values()[i].name().toLowerCase()));
}
@ -267,7 +267,7 @@ public class ListUsersGUI extends CommonGUI
name(this.user.getTranslation("challenges.gui.admin.buttons.toggle-users",
"[value]",
this.user.getTranslation("challenges.gui.admin.descriptions." + ViewMode.values()[this.modeIndex].name().toLowerCase()))).
description(values).
description(GuiUtils.stringSplit(values)).
icon(Material.STONE_BUTTON).
clickHandler(
(panel, user1, clickType, slot) -> {

View File

@ -5,7 +5,6 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import world.bentobox.bentobox.api.panels.PanelItem;
@ -17,6 +16,7 @@ import world.bentobox.challenges.ChallengesManager;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.TryToComplete;
import world.bentobox.challenges.utils.GuiUtils;
import world.bentobox.challenges.utils.LevelStatus;
@ -320,7 +320,7 @@ public class ChallengesGUI extends CommonGUI
return new PanelItemBuilder().
icon(challenge.getIcon()).
name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()).
description(this.createChallengeDescription(challenge)).
description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))).
clickHandler((panel, user1, clickType, slot) -> {
new TryToComplete(this.addon,
this.user,
@ -496,8 +496,7 @@ public class ChallengesGUI extends CommonGUI
if (level.isUnlocked())
{
icon = level.getLevel().getIcon();
description = Collections.singletonList(
this.user.getTranslation("challenges.navigation", "[level]", name));
description = GuiUtils.stringSplit(this.user.getTranslation("challenges.navigation", "[level]", name));
clickHandler = (panel, user1, clickType, slot) -> {
this.lastSelectedLevel = level;
@ -514,7 +513,7 @@ public class ChallengesGUI extends CommonGUI
{
icon = new ItemStack(Material.BOOK);
description = Collections.singletonList(
description = GuiUtils.stringSplit(
this.user.getTranslation("challenges.to-complete",
"[challengesToDo]", Integer.toString(level.getNumberOfChallengesStillToDo()),
"[thisLevel]", level.getPreviousLevel().getFriendlyName()));

View File

@ -14,6 +14,7 @@ import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.PanelListener;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.utils.GuiUtils;
/**
@ -123,7 +124,7 @@ public class ItemSwitchGUI
return null;
}
return new PanelItem(icon, name, description, false, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false);
}

View File

@ -238,7 +238,7 @@ public class NumberGUI
return null;
}
return new PanelItem(icon, name, description, glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
}

View File

@ -127,7 +127,7 @@ public class SelectChallengeGUI
{
return new PanelItemBuilder().
name(challenge.getFriendlyName()).
description(challenge.getDescription()).
description(GuiUtils.stringSplit(challenge.getDescription())).
icon(challenge.getIcon()).
clickHandler((panel, user1, clickType, slot) -> {
this.consumer.accept(true, challenge);

View File

@ -3,7 +3,10 @@ package world.bentobox.challenges.panel.util;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import net.wesjd.anvilgui.AnvilGUI;
@ -174,7 +177,7 @@ public class StringListGUI
return null;
}
return new PanelItem(icon, name, description, false, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false);
}

View File

@ -6,7 +6,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -385,4 +384,22 @@ public class GuiUtils
return result;
}
/**
* Simple splitter for all strings in list.
* @param stringList - list of string to be split
* @return list of split strings
*/
public static List<String> stringSplit(List<String> stringList)
{
if (stringList.isEmpty())
{
return stringList;
}
List<String> newList = new ArrayList<>(stringList.size());
stringList.stream().map(GuiUtils::stringSplit).forEach(newList::addAll);
return newList;
}
}

View File

@ -134,7 +134,7 @@ challenges:
search-radius: Search radius
settings: Settings
toggle-users: Choose players
type: Challenge Type
type: 'Challenge Type: [value]'
waiver-amount: Waiver Amount
import: Import
choose-challenge-title: Challenges List