Add an option to hide undeployed challenges from challenge list (#175)

Added new config option "gui-settings.undeployed-view-mode" with 3 values
- 'VISIBLE' - all challenges are visible
- 'HIDDEN' - only deployed challenges are visible
- 'TOGGLEABLE' - users will be able to choose option for themself (not implemented)

Implement functionality in ChallengesGUI, where if option hidden is set, then all undeployed challenges are removed.
Implement ability to edit this option via admin Settings panel.
This commit is contained in:
BONNe 2019-09-05 15:52:14 +03:00 committed by BONNe1704
parent e5ec5d5825
commit 643c5e8f7c
6 changed files with 158 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import world.bentobox.bentobox.database.objects.adapters.Adapter;
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
import world.bentobox.challenges.config.SettingsUtils.ChallengeLore;
import world.bentobox.challenges.config.SettingsUtils.LevelLore;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.database.object.adapters.ChallengeLoreAdapter;
import world.bentobox.challenges.database.object.adapters.LevelLoreAdapter;
@ -82,6 +83,16 @@ public class Settings implements ConfigObject
@ConfigEntry(path = "gui-settings.add-completed-glow")
private boolean addCompletedGlow = true;
@ConfigComment("")
@ConfigComment("This variable allows to choose which Challenges users can see in Challenges GUI.")
@ConfigComment("Valid values are:")
@ConfigComment(" 'VISIBLE' - there will be no hidden challenges. All challenges will be viewable in GUI.")
@ConfigComment(" 'HIDDEN' - shows only deployed challenges.")
@ConfigComment(" 'TOGGLEABLE' - there will be button in GUI that allows users to switch from ALL modes.")
@ConfigComment("TOGGLEABLE - Currently not implemented.")
@ConfigEntry(path = "gui-settings.undeployed-view-mode")
private VisibilityMode visibilityMode = VisibilityMode.VISIBLE;
@ConfigComment("")
@ConfigComment("This allows to change default locked level icon. This option may be")
@ConfigComment("overwritten by each challenge level. If challenge level has specified")
@ -192,7 +203,7 @@ public class Settings implements ConfigObject
// ---------------------------------------------------------------------
// Section: Methods
// Section: Getters
// ---------------------------------------------------------------------
@ -400,6 +411,21 @@ public class Settings implements ConfigObject
}
/**
* This method returns the visibilityMode value.
* @return the value of visibilityMode.
*/
public VisibilityMode getVisibilityMode()
{
return this.visibilityMode;
}
// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
/**
* This method sets the autoSaveTimer object value.
* @param autoSaveTimer the autoSaveTimer object new value.
@ -607,4 +633,15 @@ public class Settings implements ConfigObject
{
this.lifeSpan = lifeSpan;
}
/**
* This method sets the visibilityMode value.
* @param visibilityMode the visibilityMode new value.
*
*/
public void setVisibilityMode(VisibilityMode visibilityMode)
{
this.visibilityMode = visibilityMode;
}
}

View File

@ -28,6 +28,27 @@ public class SettingsUtils
}
/**
* This enum holds all possible values for displaying challenges. It allows to
* enable/disable displaying un-deployed challenges.
*/
public enum VisibilityMode
{
/**
* Show all challenges regardless of their deployment status.
*/
VISIBLE,
/**
* Hide all undeployed challenges in User GUI.
*/
HIDDEN,
/**
* Allows users to switch them on/off in GUI.
*/
TOGGLEABLE
}
/**
* This enum holds all possible values for Challenge Lore Message.
*/

View File

@ -15,10 +15,12 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.NumberGUI;
import world.bentobox.challenges.panel.util.SelectBlocksGUI;
import world.bentobox.challenges.utils.GuiUtils;
import world.bentobox.challenges.utils.Utils;
/**
@ -90,8 +92,9 @@ public class EditSettingsGUI extends CommonGUI
panelBuilder.item(28, this.getSettingsButton(Button.BROADCAST));
panelBuilder.item(20, this.getSettingsButton(Button.GLOW_COMPLETED));
panelBuilder.item(29, this.getSettingsButton(Button.REMOVE_COMPLETED));
panelBuilder.item(11, this.getSettingsButton(Button.GLOW_COMPLETED));
panelBuilder.item(20, this.getSettingsButton(Button.REMOVE_COMPLETED));
panelBuilder.item(29, this.getSettingsButton(Button.VISIBILITY_MODE));
panelBuilder.item(21, this.getSettingsButton(Button.LOCKED_LEVEL_ICON));
panelBuilder.item(30, this.getSettingsButton(Button.FREE_AT_TOP));
@ -490,6 +493,61 @@ public class EditSettingsGUI extends CommonGUI
glow = false;
break;
}
case VISIBILITY_MODE:
{
name = this.user.getTranslation("challenges.gui.buttons.admin.visibility-mode");
List<String> values = new ArrayList<>(5);
values.add(this.user.getTranslation("challenges.gui.descriptions.admin.visibility-mode"));
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.VISIBLE) ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.descriptions.visibility.visible"));
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.HIDDEN) ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.descriptions.visibility.hidden"));
values.add((this.settings.getVisibilityMode().equals(VisibilityMode.TOGGLEABLE) ? "&2" : "&c") +
this.user.getTranslation("challenges.gui.descriptions.visibility.toggleable"));
values.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
"[value]",this.settings.getVisibilityMode().name()));
description = values;
if (this.settings.getVisibilityMode().equals(VisibilityMode.VISIBLE))
{
icon = new ItemStack(Material.OAK_PLANKS);
}
else if (this.settings.getVisibilityMode().equals(VisibilityMode.HIDDEN))
{
icon = new ItemStack(Material.OAK_SLAB);
}
else
{
icon = new ItemStack(Material.OAK_BUTTON);
}
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
{
this.settings.setVisibilityMode(
Utils.getPreviousValue(VisibilityMode.values(),
this.settings.getVisibilityMode()));
}
else
{
this.settings.setVisibilityMode(
Utils.getNextValue(VisibilityMode.values(),
this.settings.getVisibilityMode()));
}
// Rebuild just this icon
panel.getInventory().setItem(slot,
this.getSettingsButton(button).getItem());
return true;
};
glow = false;
break;
}
default:
return new PanelItemBuilder().build();
}
@ -529,7 +587,12 @@ public class EditSettingsGUI extends CommonGUI
GLOW_COMPLETED,
LOCKED_LEVEL_ICON,
ENABLE_TITLE,
TITLE_SHOWTIME
TITLE_SHOWTIME,
/**
* This allows to switch between different challenges visibility modes.
*/
VISIBILITY_MODE
}

View File

@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.ChallengesManager;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.tasks.TryToComplete;
@ -151,6 +152,12 @@ public class ChallengesGUI extends CommonGUI
this.challengesManager.isChallengeComplete(this.user, this.world, challenge));
}
// Remove all undeployed challenges if VisibilityMode is set to Hidden.
if (this.addon.getChallengesSettings().getVisibilityMode().equals(VisibilityMode.HIDDEN))
{
freeChallenges.removeIf(challenge -> !challenge.isDeployed());
}
final int freeChallengesCount = freeChallenges.size();
if (freeChallengesCount > 18)
@ -221,6 +228,12 @@ public class ChallengesGUI extends CommonGUI
this.challengesManager.isChallengeComplete(this.user, this.world, challenge));
}
// Remove all undeployed challenges if VisibilityMode is set to Hidden.
if (this.addon.getChallengesSettings().getVisibilityMode().equals(VisibilityMode.HIDDEN))
{
challenges.removeIf(challenge -> !challenge.isDeployed());
}
final int challengesCount = challenges.size();
if (challengesCount > 18)

View File

@ -43,6 +43,14 @@ gui-settings:
# Add enchanted glow to completed challenges
add-completed-glow: true
#
# This variable allows to choose which Challenges users can see in Challenges GUI.
# Valid values are:
# 'VISIBLE' - there will be no hidden challenges. All challenges will be viewable in GUI.
# 'HIDDEN' - shows only deployed challenges.
# 'TOGGLEABLE' - there will be button in GUI that allows users to switch from ALL modes.
# TOGGLEABLE - Currently not implemented.
undeployed-view-mode: VISIBLE
#
# This allows to change default locked level icon. This option may be
# overwritten by each challenge level. If challenge level has specified
# their locked level icon, then it will be used, instead of this one.

View File

@ -136,6 +136,7 @@ challenges:
glow: 'Glow when completed'
free-at-top: 'Free challenges first'
line-length: 'Lore line length'
visibility-mode: 'Challenge Visibility Mode'
toggle-user-list: 'User List'
remove-selected: 'Remove Selected'
add: 'Add'
@ -263,6 +264,9 @@ challenges:
island-store: 'Allows to enable/disable challenges data storing per island. This means that challenges will be the same on whole team, if this is enabled.|Will NOT convert data on click. PROGRESS WILL BE LOST.'
default-locked-icon: 'Allows to change default locked level icon.|This option can be overwritten by each level.'
gui-mode: 'Allows to enable/disable single challenges GUI.|&2Requires server restart.'
visibility-mode: 'Allows to switch if undeployed challenges should be displayed or not.'
click-to-edit: '&4Click here to edit input.'
edit-text-line: '&6 Edit text message!'
add-text-line: '&6 Add new text message!'
@ -330,6 +334,12 @@ challenges:
increase-by: "&aIncrease completion count by [value]"
reduce-by: "&cReduce completion count by [value]"
visibility:
visible: "All challenges are visible for everyone"
hidden: "Only Deployed challenges are visible."
toggleable: "Allows to toggle if undeployed challenges should be displayed"
challenge-description:
level: '&FLevel: [level]'
completed: '&BCompleted'