Pauses game(when only one player) at pause menu.
package org.terasology.logic.players;
import org.terasology.audio.AudioManager;
+import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.event.ReceiveEvent;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.logic.characters.CharacterComponent;
import org.terasology.logic.characters.events.PlayerDeathEvent;
import org.terasology.network.ClientComponent;
+import org.terasology.network.ClientInfoComponent;
import org.terasology.registry.CoreRegistry;
import org.terasology.registry.In;
import org.terasology.rendering.nui.NUIManager;
@In
private Time time;
-
- //private boolean isPaused=false;
- //private float currTimeDilation=time.getGameTimeDilation();
+ @In
+ private EntityManager entityManager;
@Override
public void initialise() {
@@ -59,20 +60,25 @@ public void initialise() {
nuiManager.getHUD().addHUDElement("toolbar");
}
+ private int getPlayerCount() {
+ int playerCount=entityManager.getCountOfEntitiesWith(ClientInfoComponent.class);
+ return playerCount;
+ }
+
@ReceiveEvent(components = ClientComponent.class)
public void onTogglePause(PauseButton event, EntityRef entity) {
if (event.getState() == ButtonState.DOWN) {
nuiManager.toggleScreen("engine:pauseMenu");
event.consume();
}
-
+ if(getPlayerCount()==2) {
if (!time.isPaused()) {
time.setPaused(true);
- }
- else{
+ } else {
time.setPaused(false);
}
}
+ }
@ReceiveEvent(components = ClientComponent.class)
public void onScreenshotCapture(ScreenshotButton event, EntityRef entity) {
