@Override
public Module get() {
// try and be smart about auto selecting a gameplay
if (selected == null) {
// get the default gameplay module from the config. This is likely to have a user triggered selection.
Module defaultGameplayModule = moduleManager.getRegistry().getLatestModuleVersion(
new Name(config.getDefaultModSelection().getDefaultGameplayModuleName()));
if (defaultGameplayModule != null) {
set(defaultGameplayModule);
return selected;
}
// find the first gameplay module that is available
for (Name moduleName : config.getDefaultModSelection().listModules()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
// module is null if it is no longer present
if (module != null && moduleManager.isGameplayModule(module)) {
set(module);
return selected;
}
}
}
return selected;
}
@Override
public void set(Module value) {
setSelectedGameplayModule(selected, value);
selected = value;
}
});
gameplay.setOptionRenderer(new StringTextRenderer<Module>() {
@Override
public String getString(Module value) {
return value.getMetadata().getDisplayName().value();
}
});
UILabel gameplayDescription = find("gameplayDescription", UILabel.class);
gameplayDescription.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
Module selectedModule = gameplay.getSelection();
if (selectedModule != null) {
return selectedModule.getMetadata().getDescription().value();
} else {
return "";
}
}
});
final UIDropdown<WorldGeneratorInfo> worldGenerator = find("worldGenerator", UIDropdown.class);
if (worldGenerator != null) {
worldGenerator.bindOptions(new ReadOnlyBinding<List<WorldGeneratorInfo>>() {
@Override
public List<WorldGeneratorInfo> get() {
// grab all the module names and their dependencies
Set<Name> enabledModuleNames = Sets.newHashSet();
for (Name moduleName : getAllEnabledModuleNames()) {
enabledModuleNames.add(moduleName);
}
List<WorldGeneratorInfo> result = Lists.newArrayList();
for (WorldGeneratorInfo option : worldGeneratorManager.getWorldGenerators()) {
if (enabledModuleNames.contains(option.getUri().getModuleName())) {
result.add(option);
}
}
return result;
}
});
worldGenerator.bindSelection(new Binding<WorldGeneratorInfo>() {
@Override
public WorldGeneratorInfo get() {
// get the default generator from the config. This is likely to have a user triggered selection.
WorldGeneratorInfo info = worldGeneratorManager.getWorldGeneratorInfo(config.getWorldGeneration().getDefaultGenerator());
if (info != null && getAllEnabledModuleNames().contains(info.getUri().getModuleName())) {
return info;
}
// get the default generator from the selected gameplay module
Module selectedGameplayModule = gameplay.getSelection();
if (selectedGameplayModule != null) {
String defaultWorldGenerator = selectedGameplayModule.getMetadata().getExtension(ModuleManager.DEFAULT_WORLD_GENERATOR_EXT, String.class);
if (defaultWorldGenerator != null) {
for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
if (worldGenInfo.getUri().equals(new SimpleUri(defaultWorldGenerator))) {
set(worldGenInfo);
return worldGenInfo;