Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder menu screens #2074

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ private void cheapAssetManagerUpdate(Context context, ModuleEnvironment environm
moduleAwareAssetTypeManager.switchEnvironment(environment);
}


public void handleSwitchToPreviewEnvironment(Context context, ModuleEnvironment environment) {
cheapAssetManagerUpdate(context, environment);
ComponentLibrary library = new ComponentLibrary(context);
context.put(ComponentLibrary.class, library);

registerComponents(library, environment);
}

public void handleSwitchBackFromPreviewEnvironment(Context context) {
// The newly created ComponentLibrary instance cannot be invalidated in context
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
cheapAssetManagerUpdate(context, environment);
}


public void handleSwitchToEmptyEnivronment(Context context) {
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
cheapAssetManagerUpdate(context, environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.terasology.engine.modes.loadProcesses.RegisterBiomes;
import org.terasology.engine.modes.loadProcesses.RegisterBlocks;
import org.terasology.engine.modes.loadProcesses.RegisterInputSystem;
import org.terasology.engine.modes.loadProcesses.RegisterMods;
import org.terasology.engine.modes.loadProcesses.RegisterSystems;
import org.terasology.engine.modes.loadProcesses.SetupLocalPlayer;
import org.terasology.engine.modes.loadProcesses.SetupRemotePlayer;
Expand Down Expand Up @@ -170,7 +169,6 @@ private void initClient() {
}

private void initHost() {
loadProcesses.add(new RegisterMods(context, gameManifest));
loadProcesses.add(new CacheTextures());
loadProcesses.add(new InitialiseEntitySystem(context));
loadProcesses.add(new RegisterBlocks(context, gameManifest));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
*/
package org.terasology.rendering.nui.layers.mainMenu;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.config.Config;
import org.terasology.config.ModuleConfig;
import org.terasology.engine.GameEngine;
import org.terasology.engine.SimpleUri;
import org.terasology.engine.TerasologyConstants;
import org.terasology.engine.modes.StateLoading;
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.module.StandardModuleExtension;
import org.terasology.game.GameManifest;
Expand All @@ -33,7 +35,6 @@
import org.terasology.module.Module;
import org.terasology.module.ResolutionResult;
import org.terasology.naming.Name;
import org.terasology.network.NetworkMode;
import org.terasology.registry.In;
import org.terasology.rendering.nui.CoreScreenLayer;
import org.terasology.rendering.nui.UIWidget;
Expand All @@ -55,10 +56,8 @@
import org.terasology.world.internal.WorldInfo;
import org.terasology.world.time.WorldTime;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**
*/
Expand All @@ -80,11 +79,13 @@ public class CreateGameScreen extends CoreScreenLayer {
private Config config;

private boolean loadingAsServer;
private UIText worldName;
private UIText seedValue;

@Override
@SuppressWarnings("unchecked")
public void initialise() {
final UIText worldName = find("worldName", UIText.class);
worldName = find("worldName", UIText.class);
if (worldName != null) {
int gameNum = 1;
for (GameInfo info : GameProvider.getSavedGames()) {
Expand All @@ -101,9 +102,9 @@ public void initialise() {
worldName.setText(DEFAULT_GAME_NAME_PREFIX + gameNum);
}

final UIText seed = find("seed", UIText.class);
if (seed != null) {
seed.setText(new FastRandom().nextString(32));
seedValue = find("seed", UIText.class);
if (seedValue != null) {
seedValue.setText(new FastRandom().nextString(16));
}

final UIDropdown<Module> gameplay = find("gameplay", UIDropdown.class);
Expand Down Expand Up @@ -210,56 +211,21 @@ public void onActivated(UIWidget button) {
}
});

WidgetUtil.trySubscribe(this, "play", new ActivateEventListener() {
@Override
public void onActivated(UIWidget button) {
if (worldGenerator.getSelection() == null) {
MessagePopup errorMessagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
if (errorMessagePopup != null) {
errorMessagePopup.setMessage("No World Generator Selected", "Select a world generator (you may need to activate a mod with a generator first).");
}
} else {
GameManifest gameManifest = new GameManifest();

gameManifest.setTitle(worldName.getText());
gameManifest.setSeed(seed.getText());
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (!result.isSuccess()) {
MessagePopup errorMessagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
if (errorMessagePopup != null) {
errorMessagePopup.setMessage("Invalid Module Selection", "Please review your module seleciton and try again");
}
return;
}
for (Module module : result.getModules()) {
gameManifest.addModule(module.getId(), module.getVersion());
}

float timeOffset = 0.25f + 0.025f; // Time at dawn + little offset to spawn in a brighter env.
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(),
(long) (WorldTime.DAY_LENGTH * timeOffset), worldGenerator.getSelection().getUri());
gameManifest.addWorld(worldInfo);

gameEngine.changeState(new StateLoading(gameManifest, (loadingAsServer) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
}
}
});

UIButton previewSeed = find("previewSeed", UIButton.class);
UIButton previewSeed = find("preview", UIButton.class);
ReadOnlyBinding<Boolean> worldGeneratorSelected = new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return worldGenerator != null && worldGenerator.getSelection() != null;
}
};
previewSeed.bindEnabled(worldGeneratorSelected);
WidgetUtil.trySubscribe(this, "previewSeed", new ActivateEventListener() {
WidgetUtil.trySubscribe(this, "preview", new ActivateEventListener() {
@Override
public void onActivated(UIWidget button) {
PreviewWorldScreen screen = getManager().pushScreen(PreviewWorldScreen.ASSET_URI, PreviewWorldScreen.class);
if (screen != null) {
screen.bindSeed(BindHelper.bindBeanProperty("text", seed, String.class));
screen.setGameManifest(createManifest());
screen.setLoadingAsServer(loadingAsServer);
}
}
});
Expand All @@ -272,6 +238,33 @@ public void onActivated(UIWidget button) {
});
}

private GameManifest createManifest() {
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (!result.isSuccess()) {
MessagePopup errorMessagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
if (errorMessagePopup != null) {
errorMessagePopup.setMessage("Invalid Module Selection", "Please review your module seleciton and try again");
}
throw new IllegalStateException("Invalid Module Selection");
}
GameManifest gameManifest = new GameManifest();
gameManifest.setTitle(worldName.getText());
gameManifest.setSeed(seedValue.getText());
// also bind the value so that changes in other menus are reflected in the text box
seedValue.bindText(BindHelper.bindBeanProperty("seed", gameManifest, String.class));
for (Module module : result.getModules()) {
gameManifest.addModule(module.getId(), module.getVersion());
}

float timeOffset = 0.25f + 0.025f; // Time at dawn + little offset to spawn in a brighter env.
long time = (long) (WorldTime.DAY_LENGTH * timeOffset);
SimpleUri worldGenUri = config.getWorldGeneration().getDefaultGenerator();
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(), time, worldGenUri);
gameManifest.addWorld(worldInfo);
return gameManifest;
}

@Override
public void onOpened() {
super.onOpened();
Expand Down Expand Up @@ -358,10 +351,6 @@ public int compare(Module o1, Module o2) {
return gameplayModules;
}

public boolean isLoadingAsServer() {
return loadingAsServer;
}

public void setLoadingAsServer(boolean loadingAsServer) {
this.loadingAsServer = loadingAsServer;
}
Expand Down
Loading