Skip to content

Commit

Permalink
Revamp the settings GUI (#916)
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick authored Sep 4, 2021
1 parent 4be0024 commit 9fa901e
Show file tree
Hide file tree
Showing 36 changed files with 1,167 additions and 861 deletions.
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<include>fr.mrmicky:*:*</include>
<include>org.eclipse.jgit:org.eclipse.jgit:*</include>
<include>org.slf4j:slf4j-api:*</include>
<include>fr.minuskube.inv:smart-invs</include>
</includes>
</artifactSet>
<filters>
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tc.oc.pgm;

import com.google.common.collect.Lists;
import fr.minuskube.inv.InventoryManager;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -92,6 +93,7 @@ public class PGMPlugin extends JavaPlugin implements PGM, Listener {
private ScheduledExecutorService executorService;
private ScheduledExecutorService asyncExecutorService;
private VanishManager vanishManager;
private InventoryManager inventoryManager;

public PGMPlugin() {
super();
Expand Down Expand Up @@ -211,6 +213,9 @@ public void onEnable() {
? new VanishManagerImpl(matchManager, executorService)
: new NoopVanishManager();

inventoryManager = new InventoryManager(this);
inventoryManager.init();

if (config.showTabList()) {
matchTabManager = new MatchTabManager(this);
}
Expand Down Expand Up @@ -322,6 +327,11 @@ public VanishManager getVanishManager() {
return vanishManager;
}

@Override
public InventoryManager getInventoryManager() {
return inventoryManager;
}

private void registerCommands() {
final CommandGraph graph =
config.isCommunityMode() ? new CommunityCommandGraph() : new CommandGraph();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import tc.oc.pgm.modules.ModifyBowProjectileMatchModule;
import tc.oc.pgm.modules.ModifyBowProjectileModule;
import tc.oc.pgm.modules.MultiTradeMatchModule;
import tc.oc.pgm.modules.PlayerTimeMatchModule;
import tc.oc.pgm.modules.SoundsMatchModule;
import tc.oc.pgm.modules.ToolRepairMatchModule;
import tc.oc.pgm.modules.ToolRepairModule;
Expand Down Expand Up @@ -159,6 +160,7 @@ static void registerAll() {
register(StatsMatchModule.class, StatsMatchModule::new);
register(MapmakerMatchModule.class, MapmakerMatchModule::new);
register(TNTRenderMatchModule.class, TNTRenderMatchModule::new);
register(PlayerTimeMatchModule.class, PlayerTimeMatchModule::new);

// FIXME: Disabled due to lag - look into future optimization
// register(ProjectileTrailMatchModule.class, ProjectileTrailMatchModule::new);
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/PGM.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import fr.minuskube.inv.InventoryManager;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
Expand Down Expand Up @@ -40,6 +41,8 @@ public interface PGM extends Plugin {

VanishManager getVanishManager();

InventoryManager getInventoryManager();

AtomicReference<PGM> GLOBAL = new AtomicReference<>(null);

static PGM set(PGM pgm) {
Expand Down
76 changes: 63 additions & 13 deletions core/src/main/java/tc/oc/pgm/api/setting/SettingKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,86 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Material;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.modules.PlayerTimeMatchModule;

/**
* A toggleable setting with various possible {@link SettingValue}s.
*
* @see SettingValue
*/
public enum SettingKey {
CHAT("chat", CHAT_TEAM, CHAT_GLOBAL, CHAT_ADMIN), // Changes the default chat channel
CHAT(
"chat",
Material.SIGN,
CHAT_TEAM,
CHAT_GLOBAL,
CHAT_ADMIN), // Changes the default chat channel
DEATH(
Arrays.asList("death", "dms"), DEATH_ALL, DEATH_OWN), // Changes which death messages are seen
PICKER("picker", PICKER_AUTO, PICKER_ON, PICKER_OFF), // Changes when the picker is displayed
JOIN(Arrays.asList("join", "jms"), JOIN_ON, JOIN_OFF), // Changes if join messages are seen
Arrays.asList("death", "dms"),
Material.SKULL_ITEM,
DEATH_ALL,
DEATH_OWN), // Changes which death messages are seen
PICKER(
"picker",
Material.LEATHER_HELMET,
PICKER_AUTO,
PICKER_ON,
PICKER_OFF), // Changes when the picker is displayed
JOIN(
Arrays.asList("join", "jms"),
Material.WOOD_DOOR,
JOIN_ON,
JOIN_OFF), // Changes if join messages are seen
MESSAGE(
Arrays.asList("message", "dm"),
Material.BOOK_AND_QUILL,
MESSAGE_ON,
MESSAGE_OFF), // Changes if direct messages are accepted
OBSERVERS(Arrays.asList("observers", "obs"), OBSERVERS_ON, OBSERVERS_OFF) {
OBSERVERS(Arrays.asList("observers", "obs"), Material.EYE_OF_ENDER, OBSERVERS_ON, OBSERVERS_OFF) {
@Override
public void update(MatchPlayer player) {
player.resetVisibility();
}
}, // Changes if observers are visible
SOUNDS("sounds", SOUNDS_ALL, SOUNDS_DM, SOUNDS_NONE), // Changes when sounds are played
VOTE("vote", VOTE_ON, VOTE_OFF), // Changes if the vote book is shown on cycle
STATS("stats", STATS_ON, STATS_OFF), // Changes if stats are tracked
EFFECTS("effects", EFFECTS_ON, EFFECTS_OFF) // Changes if special particle effects are shown
;
SOUNDS(
"sounds",
Material.NOTE_BLOCK,
SOUNDS_ALL,
SOUNDS_DM,
SOUNDS_NONE), // Changes when sounds are played
VOTE(
"vote",
Material.ENCHANTED_BOOK,
VOTE_ON,
VOTE_OFF), // Changes if the vote book is shown on cycle
STATS("stats", Material.PAPER, STATS_ON, STATS_OFF), // Changes if stats are tracked
EFFECTS(
"effects",
Material.FIREWORK,
EFFECTS_ON,
EFFECTS_OFF), // Changes if special particle effects are shown
TIME(Arrays.asList("time", "theme"), Material.WATCH, TIME_AUTO, TIME_DARK, TIME_LIGHT) {
@Override
public void update(MatchPlayer player) {
PlayerTimeMatchModule.updatePlayerTime(player);
}
}; // Changes player preference for time of day
;

private final List<String> aliases;
private final SettingValue[] values;
private final Material icon;

SettingKey(String name, SettingValue... values) {
this(Collections.singletonList(name), values);
SettingKey(String name, Material icon, SettingValue... values) {
this(Collections.singletonList(name), icon, values);
}

SettingKey(List<String> aliases, SettingValue... values) {
SettingKey(List<String> aliases, Material icon, SettingValue... values) {
checkArgument(!aliases.isEmpty(), "aliases is empty");
this.aliases = ImmutableList.copyOf(aliases);
this.icon = icon;
this.values = values;
}

Expand Down Expand Up @@ -85,6 +126,15 @@ public SettingValue getDefaultValue() {
return getPossibleValues()[0];
}

/**
* Get the {@link Material} used to visually represent this setting in GUI menus.
*
* @return {@link Material} to visually represent setting.
*/
public Material getIconMaterial() {
return icon;
}

@Override
public String toString() {
return getName();
Expand Down
66 changes: 41 additions & 25 deletions core/src/main/java/tc/oc/pgm/api/setting/SettingValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.bukkit.DyeColor;
import tc.oc.pgm.util.StringUtils;

/**
Expand All @@ -14,46 +15,51 @@
* @see SettingKey
*/
public enum SettingValue {
CHAT_TEAM("chat", "team"), // Only send to members on the player's team
CHAT_GLOBAL("chat", "global"), // Send to all players in the same match
CHAT_ADMIN("chat", "admin"), // Send to all server operators
CHAT_TEAM("chat", "team", DyeColor.GREEN), // Only send to members on the player's team
CHAT_GLOBAL("chat", "global", DyeColor.ORANGE), // Send to all players in the same match
CHAT_ADMIN("chat", "admin", DyeColor.RED), // Send to all server operators

DEATH_OWN("death", "own"), // Only send death messages involving self
DEATH_ALL("death", "all"), // Send all death messages, highlight your own
DEATH_OWN("death", "own", DyeColor.RED), // Only send death messages involving self
DEATH_ALL("death", "all", DyeColor.GREEN), // Send all death messages, highlight your own

PICKER_AUTO("picker", "auto"), // Display after cycle, or with permissions.
PICKER_ON("picker", "on"), // Display the picker GUI always
PICKER_OFF("picker", "off"), // Never display the picker GUI
PICKER_AUTO("picker", "auto", DyeColor.ORANGE), // Display after cycle, or with permissions.
PICKER_ON("picker", "on", DyeColor.GREEN), // Display the picker GUI always
PICKER_OFF("picker", "off", DyeColor.RED), // Never display the picker GUI

JOIN_ON("join", "all"), // Send all join messages
JOIN_OFF("join", "none"), // Never send join messages
JOIN_ON("join", "all", DyeColor.ORANGE), // Send all join messages
JOIN_OFF("join", "none", DyeColor.RED), // Never send join messages

MESSAGE_ON("message", "on"), // Always accept direct messages
MESSAGE_OFF("message", "off"), // Never accept direct messages
MESSAGE_ON("message", "on", DyeColor.GREEN), // Always accept direct messages
MESSAGE_OFF("message", "off", DyeColor.RED), // Never accept direct messages

OBSERVERS_ON("observers", "on"), // Show observers
OBSERVERS_OFF("observers", "off"), // Hide observers
OBSERVERS_ON("observers", "on", DyeColor.GREEN), // Show observers
OBSERVERS_OFF("observers", "off", DyeColor.RED), // Hide observers

SOUNDS_ALL("sounds", "all"), // Play all sounds
SOUNDS_DM("sounds", "messages"), // Only play DM sounds
SOUNDS_NONE("sounds", "none"), // Never play sounds
SOUNDS_ALL("sounds", "all", DyeColor.GREEN), // Play all sounds
SOUNDS_DM("sounds", "messages", DyeColor.ORANGE), // Only play DM sounds
SOUNDS_NONE("sounds", "none", DyeColor.RED), // Never play sounds

VOTE_ON("vote", "on"), // Show the vote book on cycle
VOTE_OFF("vote", "off"), // Don't show the vote book on cycle
VOTE_ON("vote", "on", DyeColor.GREEN), // Show the vote book on cycle
VOTE_OFF("vote", "off", DyeColor.RED), // Don't show the vote book on cycle

STATS_ON("stats", "on"), // Track stats
STATS_OFF("stats", "off"), // Don't track stats
STATS_ON("stats", "on", DyeColor.GREEN), // Track stats
STATS_OFF("stats", "off", DyeColor.RED), // Don't track stats

EFFECTS_ON("effects", "on"), // Display special particle effects
EFFECTS_OFF("effects", "off"); // Don't display special particle effects
;
EFFECTS_ON("effects", "on", DyeColor.GREEN), // Display special particle effects
EFFECTS_OFF("effects", "off", DyeColor.RED), // Don't display special particle effects

TIME_AUTO("time", "auto", DyeColor.ORANGE), // Player time is in sync
TIME_DARK("time", "dark", DyeColor.GRAY), // Player time is always set to midday
TIME_LIGHT("time", "light", DyeColor.WHITE); // Player time is always set to midnight

private final String key;
private final String name;
private final DyeColor color;

SettingValue(String group, String name) {
SettingValue(String group, String name, DyeColor color) {
this.key = checkNotNull(group);
this.name = checkNotNull(name);
this.color = checkNotNull(color);
}

/**
Expand All @@ -74,6 +80,16 @@ public String getName() {
return name;
}

/**
* Get {@link DyeColor} related to this setting value .
*
* @see {@link SettingMenu} for usage.
* @return {@link DyeColor} for this setting value.
*/
public DyeColor getColor() {
return color;
}

@Override
public String toString() {
return getName();
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/tc/oc/pgm/command/SettingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@
import tc.oc.pgm.api.setting.SettingValue;
import tc.oc.pgm.api.setting.Settings;
import tc.oc.pgm.observers.ObserverToolsMatchModule;
import tc.oc.pgm.settings.SettingsMenu;
import tc.oc.pgm.util.text.TextFormatter;

// TODO: remove some of these when settings UI is released
public final class SettingCommand {

@Command(
aliases = {"settings", "tools", "observertools", "ot"},
aliases = {"settings"},
desc = "Open the settings menu")
public void settings(MatchPlayer player) {
new SettingsMenu(player);
}

@Command(
aliases = {"tools", "observertools", "ot"},
desc = "Open the observer tools menu")
public void observerTools(MatchPlayer player) {
if (player.isObserving()) {
final ObserverToolsMatchModule tools =
player.getMatch().getModule(ObserverToolsMatchModule.class);
if (tools != null) {
tools.openMenuManual(player);
tools.openMenu(player);
}
} else {
// TODO: reconsider when observer tools become settings
Expand Down
Loading

0 comments on commit 9fa901e

Please sign in to comment.