cell = table.add(button)
.padLeft(24f).padRight(24f)
- .padTop(paddingTop * scaleFactor)
.width(buttonWidth * scaleFactor)
.height(buttonHeight * scaleFactor);
+ if (position.name().startsWith("TOP")) {
+ cell.padTop(paddingTop * scaleFactor);
+ } else if (position.name().startsWith("BOTTOM")) {
+ cell.padBottom(paddingTop * scaleFactor);
+ }
table.row();
stage.addActor(table);
@@ -132,5 +144,6 @@ private enum Position {
TOP_LEFT,
TOP_CENTER,
TOP_RIGHT,
+ BOTTOM_RIGHT,
}
}
diff --git a/core/src/com/cg/zoned/maps/ExternalMapReader.java b/core/src/com/cg/zoned/maps/ExternalMapReader.java
index d90c5c2..364cdac 100644
--- a/core/src/com/cg/zoned/maps/ExternalMapReader.java
+++ b/core/src/com/cg/zoned/maps/ExternalMapReader.java
@@ -18,7 +18,7 @@
*
* Directory to save the .map and the .png preview files
* - On Android: /storage/emulated/0/Android/data/com.cg.zoned/files/ZonedExternalMaps/
- * - On Linux: /home/username/Zoned/ZonedExternalMaps/
+ * - On Linux: /home/username/.zoned/ZonedExternalMaps/
* - On Windows: C:\\Users\\username\\Documents\\Zoned\\ZonedExternalMaps\\
*/
public class ExternalMapReader {
@@ -26,6 +26,7 @@ public class ExternalMapReader {
private FileHandle externalMapDir;
private Array loadedMaps;
+ private boolean enableExternalMapLogging = false;
public ExternalMapReader() {
this.loadedMaps = new Array<>();
@@ -39,12 +40,14 @@ private void setExternalMapDir() {
// - On Desktop (Linux): /home//
// - On Desktop (Windows): C:\Users\\
+ externalMapDir = null;
if (Gdx.app.getType() == Application.ApplicationType.Android) {
+ // Android
externalMapDir = Gdx.files.external("Android/data/com.cg.zoned/files/" + mapDirName);
} else if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
if (Gdx.files.getExternalStoragePath().startsWith("/home")) {
// Linux
- externalMapDir = Gdx.files.external("Zoned/" + mapDirName);
+ externalMapDir = Gdx.files.external(".zoned/" + mapDirName);
} else {
// Windows
externalMapDir = Gdx.files.external("Documents/Zoned/" + mapDirName);
@@ -55,7 +58,7 @@ private void setExternalMapDir() {
externalMapDir.mkdirs(); // Create them folders if they don't exist
} catch (NullPointerException e) {
e.printStackTrace();
- Gdx.app.log(Constants.LOG_TAG, "Failed to create external map directory");
+ Gdx.app.error(Constants.LOG_TAG, "Failed to create external map directory");
}
}
@@ -66,82 +69,110 @@ public void scanAndParseExternalMaps() {
}
}
+ public void parseExternalMap(String mapName) {
+ FileHandle mapFile = externalMapDir.child(mapName + ".map");
+ if (!mapFile.exists() || mapFile.isDirectory()) {
+ return;
+ }
+
+ parseMap(mapFile);
+ }
+
private Array scanExternalMaps() {
Array mapFiles = new Array<>();
try {
- Gdx.app.log(Constants.LOG_TAG, "Scanning for external maps on "
- + Gdx.files.getExternalStoragePath() + externalMapDir.path());
+ if (enableExternalMapLogging) {
+ Gdx.app.log(Constants.LOG_TAG, "Scanning for external maps on "
+ + Gdx.files.getExternalStoragePath() + externalMapDir.path());
+ }
for (FileHandle mapFile : externalMapDir.list(".map")) {
if (!mapFile.isDirectory()) {
- Gdx.app.log(Constants.LOG_TAG, "Map found: " + mapFile.name());
+ if (enableExternalMapLogging) {
+ Gdx.app.log(Constants.LOG_TAG, "Map found: " + mapFile.name());
+ }
mapFiles.add(mapFile);
}
}
-
- Gdx.app.log(Constants.LOG_TAG, "External map scan complete (" + mapFiles.size + " maps found)");
+ if (enableExternalMapLogging) {
+ Gdx.app.log(Constants.LOG_TAG, "External map scan complete (" + mapFiles.size + " maps found)");
+ }
} catch (NullPointerException e) {
e.printStackTrace();
- Gdx.app.log(Constants.LOG_TAG, "NPE during external map scan: " + e.getMessage());
+ Gdx.app.error(Constants.LOG_TAG, "NPE during external map scan: " + e.getMessage());
}
return mapFiles;
}
private void parseScannedMaps(Array mapFiles) {
- Gdx.app.log(Constants.LOG_TAG, "Preparing to parse the scanned maps");
+ if (enableExternalMapLogging) {
+ Gdx.app.log(Constants.LOG_TAG, "Preparing to parse the scanned maps");
+ }
for (FileHandle mapFile : mapFiles) {
- String fileContents = mapFile.readString();
+ parseMap(mapFile);
+ }
+ if (enableExternalMapLogging) {
+ Gdx.app.log(Constants.LOG_TAG, "Map parsing completed");
+ }
+ }
- String mapGrid = null, mapName = mapFile.nameWithoutExtension();
- Array startPosNames = new Array<>();
- int rowCount = 0, colCount = 0;
+ private void parseMap(FileHandle mapFile) {
+ String fileContents = mapFile.readString();
- StringBuilder mapGridBuilder = new StringBuilder();
+ String mapGrid = null, mapName = mapFile.nameWithoutExtension();
+ Array startPosNames = new Array<>();
+ int rowCount = 0, colCount = 0;
- String rowCountPrompt = "Row count:";
- String colCountPrompt = "Col count:";
+ StringBuilder mapGridBuilder = new StringBuilder();
- Pattern startPosPattern = Pattern.compile(
- "(^[" + MapManager.VALID_START_POSITIONS.charAt(0) + "-" + MapManager.VALID_START_POSITIONS.charAt(MapManager.VALID_START_POSITIONS.length() - 1) + "])" +
- ":(.*)",
- Pattern.MULTILINE);
+ String rowCountPrompt = "Row count:";
+ String colCountPrompt = "Col count:";
- String[] fileLines = fileContents.split("\r?\n");
- for (String fileLine : fileLines) {
- if (fileLine.startsWith(rowCountPrompt)) {
- rowCount = Integer.parseInt(fileLine.substring(rowCountPrompt.length()).trim());
- } else if (fileLine.startsWith(colCountPrompt)) {
- colCount = Integer.parseInt(fileLine.substring(colCountPrompt.length()).trim());
- } else {
- Matcher matcher = startPosPattern.matcher(fileLine);
- if (matcher.matches()) {
- char startPosChar = matcher.group(1).trim().charAt(0);
- String startPosName = matcher.group(2).trim();
-
- int index = startPosChar - MapManager.VALID_START_POSITIONS.charAt(0);
- for (int j = startPosNames.size; j <= index; j++) {
- startPosNames.add(null);
- }
-
- startPosNames.set(index, startPosName);
- } else {
- mapGridBuilder.append(fileLine).append('\n');
+ Pattern startPosPattern = Pattern.compile(
+ "(^[" + MapManager.VALID_START_POSITIONS.charAt(0) + "-" + MapManager.VALID_START_POSITIONS.charAt(MapManager.VALID_START_POSITIONS.length() - 1) + "])" +
+ ":(.*)",
+ Pattern.MULTILINE);
+
+ String[] fileLines = fileContents.split("\r?\n");
+ for (String fileLine : fileLines) {
+ if (fileLine.startsWith(rowCountPrompt)) {
+ rowCount = Integer.parseInt(fileLine.substring(rowCountPrompt.length()).trim());
+ } else if (fileLine.startsWith(colCountPrompt)) {
+ colCount = Integer.parseInt(fileLine.substring(colCountPrompt.length()).trim());
+ } else {
+ Matcher matcher = startPosPattern.matcher(fileLine);
+ if (matcher.matches()) {
+ char startPosChar = matcher.group(1).trim().charAt(0);
+ String startPosName = matcher.group(2).trim();
+
+ int index = startPosChar - MapManager.VALID_START_POSITIONS.charAt(0);
+ for (int j = startPosNames.size; j <= index; j++) {
+ startPosNames.add(null);
}
+
+ startPosNames.set(index, startPosName);
+ } else {
+ mapGridBuilder.append(fileLine).append('\n');
}
}
+ }
- mapGrid = mapGridBuilder.toString();
+ mapGrid = mapGridBuilder.toString();
- if (!mapGrid.isEmpty() && mapName != null && rowCount > 0 && colCount > 0) {
- loadedMaps.add(new ExternalMapTemplate(mapName, mapGrid, startPosNames, rowCount, colCount));
+ if (!mapGrid.isEmpty() && mapName != null && rowCount > 0 && colCount > 0) {
+ loadedMaps.add(new ExternalMapTemplate(mapName, mapGrid, startPosNames, rowCount, colCount));
+ if (enableExternalMapLogging) {
Gdx.app.log(Constants.LOG_TAG, "Successfully parsed " + mapFile.name());
- } else {
- Gdx.app.log(Constants.LOG_TAG, "Failed to parse " + mapFile.name());
}
+ } else if (enableExternalMapLogging) {
+ Gdx.app.error(Constants.LOG_TAG, "Failed to parse " + mapFile.name());
}
- Gdx.app.log(Constants.LOG_TAG, "Map parsing completed");
+ }
+
+ public void enableExternalMapLogging(boolean enableExternalMapLogging) {
+ this.enableExternalMapLogging = enableExternalMapLogging;
}
public Array getLoadedMaps() {
diff --git a/core/src/com/cg/zoned/screens/ClientLobbyScreen.java b/core/src/com/cg/zoned/screens/ClientLobbyScreen.java
index ec5b6d7..e25f05e 100644
--- a/core/src/com/cg/zoned/screens/ClientLobbyScreen.java
+++ b/core/src/com/cg/zoned/screens/ClientLobbyScreen.java
@@ -1,9 +1,11 @@
package com.cg.zoned.screens;
+import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
+import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
@@ -26,10 +28,12 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Cell;
import com.cg.zoned.Constants;
import com.cg.zoned.Player;
import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
@@ -86,7 +90,7 @@ public ClientLobbyScreen(final Zoned game, Client client, String name) {
viewport = new ScreenViewport();
stage = new FocusableStage(viewport);
animationManager = new AnimationManager(this.game, this);
- font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
startLocations = new Array<>();
this.clientName = name;
@@ -98,14 +102,19 @@ public void show() {
setUpClientLobbyStage();
setUpMap();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
addPlayer(null, null, null, null, null);
connectionManager.start(clientName);
animationManager.setAnimationListener(new AnimationManager.AnimationListener() {
@Override
public void animationEnd(Stage stage) {
- connectionManager.sendClientNameToServer(clientName);
+ mapManager.loadExternalMaps(new MapManager.OnExternalMapLoadListener() {
+ @Override
+ public void onExternalMapLoaded(Array mapList, int externalMapStartIndex) {
+ connectionManager.sendClientNameToServer(clientName);
+ }
+ });
animationManager.setAnimationListener(null);
}
});
@@ -118,8 +127,8 @@ private void setUpClientLobbyStage() {
//clientLobbyTable.setDebug(true);
clientLobbyTable.center();
- Label onlinePlayersTitle = new Label("Connected Players", game.skin, "themed");
- clientLobbyTable.add(onlinePlayersTitle).pad(20);
+ Label lobbyTitle = new Label("Lobby", game.skin, "themed");
+ clientLobbyTable.add(lobbyTitle).pad(20);
clientLobbyTable.row();
@@ -137,9 +146,9 @@ private void setUpClientLobbyStage() {
clientLobbyTable.row();
readyButton = new TextButton("Ready up", game.skin);
- readyButton.addListener(new ClickListener() {
+ readyButton.addListener(new ChangeListener() {
@Override
- public void clicked(InputEvent event, float x, float y) {
+ public void changed(ChangeEvent event, Actor actor) {
Table playerItem = (Table) playerList.getChild(0);
Label readyLabel = playerItem.findActor("ready-label");
DropDownMenu colorSelector = playerItem.findActor("color-selector");
@@ -150,15 +159,16 @@ public void clicked(InputEvent event, float x, float y) {
readyLabel.setText("Ready");
readyButton.setText("Unready");
- //colorSelector.setDisabled(true); Why is there literally no visual indication for being disabled :/
- //startPosSelector.setDisabled(true);
+ colorSelector.setDisabled(true);
+ startPosSelector.setDisabled(true);
+ // TODO: Polish on this, perhaps?
} else {
readyLabel.setColor(Color.RED);
readyLabel.setText("Not ready");
readyButton.setText("Ready up");
- //colorSelector.setDisabled(false);
- //startPosSelector.setDisabled(false);
+ colorSelector.setDisabled(false);
+ startPosSelector.setDisabled(false);
}
connectionManager.broadcastClientInfo((Table) playerList.getChild(0));
@@ -195,18 +205,21 @@ public void clicked(InputEvent event, float x, float y) {
});
}
+ public void performClick(Actor actor) {
+ InputEvent touchDownEvent = new InputEvent();
+ touchDownEvent.setType(InputEvent.Type.touchDown);
+ actor.fire(touchDownEvent);
+
+ InputEvent touchUpEvent = new InputEvent();
+ touchUpEvent.setType(InputEvent.Type.touchUp);
+ actor.fire(touchUpEvent);
+ }
+
@Override
public void pause() {
if (readyButton.getText().toString().equals("Unready")) {
// Game was minimized in the mobile; so make the player unready
-
- InputEvent touchDownEvent = new InputEvent();
- touchDownEvent.setType(InputEvent.Type.touchDown);
- readyButton.fire(touchDownEvent);
-
- InputEvent touchUpEvent = new InputEvent();
- touchUpEvent.setType(InputEvent.Type.touchUp);
- readyButton.fire(touchUpEvent);
+ performClick(readyButton);
}
}
@@ -279,7 +292,9 @@ public void changed(ChangeEvent event, Actor actor) {
stage.addFocusableActor(colorSelector);
stage.addFocusableActor(startPosSelector);
stage.row();
- stage.setFocusedActor(colorSelector);
+ if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
+ stage.setFocusedActor(colorSelector);
+ }
} else {
Label colorLabel = new Label(color, game.skin);
colorLabel.setName("color-label");
@@ -341,11 +356,31 @@ private void addNewPlayerIntoMap(String name, String color, String startPos) {
}
@Override
- public void mapChanged(String mapName, int[] mapExtraParams) {
+ public FileHandle getExternalMapDir() {
+ return this.mapManager.getExternalMapDir();
+ }
+
+ @Override
+ public void mapChanged(final String mapName, final int[] mapExtraParams, final int mapHash, boolean isNewMap) {
+ if (readyButton.getText().toString().equals("Unready")) {
+ performClick(readyButton);
+ }
+
+ if (isNewMap) {
+ // If true, a new external map was just downloaded from the server
+
+ this.mapManager.loadExternalMap(mapName);
+ this.mapLabel.setText("");
+ }
+
+ setMap(mapName, mapExtraParams, mapHash);
+ }
+
+ private void setMap(String mapName, int[] mapExtraParams, int mapHash) {
startLocations.clear();
MapManager mapManager = this.mapManager;
- if (!loadNewMap(mapManager, mapName, mapExtraParams)) {
+ if (!loadNewMap(mapManager, mapName, mapExtraParams, mapHash)) {
return;
}
@@ -371,6 +406,7 @@ public void mapChanged(String mapName, int[] mapExtraParams) {
resetStartPosLabels(startLocations);
this.mapLabel.setText(mapManager.getPreparedMap().getName());
+ readyButton.setDisabled(false);
}
private void resetStartPosLabels(Array startLocations) {
@@ -387,11 +423,13 @@ private void resetStartPosLabels(Array startLocations) {
}
}
- private boolean loadNewMap(MapManager mapManager, String mapName, int[] mapExtraParams) {
+ private boolean loadNewMap(MapManager mapManager, String mapName, int[] mapExtraParams, int serverMapHash) {
MapEntity map = mapManager.getMap(mapName);
if (map == null) {
- // Should never happen cause server loads a valid internal map before sending it to all the clients
- displayServerError("Unknown map received: '" + mapName + "'");
+ // Server probably selected an external map which is unavailable in the client
+ this.mapLabel.setText("Downloading map '" + mapName + "'");
+ connectionManager.requestMap(mapName);
+ readyButton.setDisabled(true);
return false;
}
@@ -400,6 +438,15 @@ private boolean loadNewMap(MapManager mapManager, String mapName, int[] mapExtra
map.applyExtraParams();
}
+ int clientMapHash = map.getMapData().hashCode();
+ if (clientMapHash != serverMapHash) {
+ // Map in the server and client have the same name, but different contents
+ displayServerError("Server client map content mismatch!\n" +
+ "Looks like the map content for the map '" + mapName + "'\n is different for you and the server\n" +
+ "(Server: " + serverMapHash + ", Client: " + clientMapHash + ")");
+ return false;
+ }
+
try {
mapManager.prepareMap(map);
} catch (InvalidMapCharacter | NoStartPositionsFound | InvalidMapDimensions e) {
@@ -649,7 +696,10 @@ public void dispose() {
for (Texture texture : usedTextures) {
texture.dispose();
}
- map.dispose();
+ if (map != null) {
+ map.dispose();
+ map = null;
+ }
}
private void onBackPressed() {
diff --git a/core/src/com/cg/zoned/screens/CreditsScreen.java b/core/src/com/cg/zoned/screens/CreditsScreen.java
index 6593b65..8d7fbcb 100644
--- a/core/src/com/cg/zoned/screens/CreditsScreen.java
+++ b/core/src/com/cg/zoned/screens/CreditsScreen.java
@@ -24,7 +24,9 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Constants;
+import com.cg.zoned.Preferences;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
import com.cg.zoned.managers.AnimationManager;
@@ -54,7 +56,7 @@ public CreditsScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
@@ -62,7 +64,7 @@ public void show() {
setUpStage();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.fadeInStage(stage);
}
@@ -92,7 +94,7 @@ private void setUpStage() {
addCreditItem(table,
"Powered By",
Gdx.files.internal("icons/ic_libgdx.png"), null,
- "https://libgdx.badlogicgames.com");
+ "https://libgdx.com");
addCreditItem(table,
"Inspired By",
@@ -131,7 +133,7 @@ private void addCreditItem(Table table, FileHandle imageLocation, String title,
gameLogoImage.setScaling(Scaling.fit);
gameLogoImage.getColor().a = .3f;
- final Label titleLabel = new Label(title, game.skin, Constants.FONT_MANAGER.LARGE.getName(), Color.GREEN);
+ final Label titleLabel = new Label(title, game.skin, Assets.FontManager.STYLED_LARGE.getFontName(), Color.GREEN);
titleLabel.setAlignment(Align.center);
Stack stack = new Stack();
@@ -265,9 +267,9 @@ private void addCreditItem(Table table, String title, final String content) {
private void toggleDevMode() {
// owo what's this
- boolean devModeUnlocked = game.preferences.getBoolean(Constants.DEV_MODE_PREFERENCE, false);
+ boolean devModeUnlocked = game.preferences.getBoolean(Preferences.DEV_MODE_PREFERENCE, false);
devModeUnlocked = !devModeUnlocked;
- game.preferences.putBoolean(Constants.DEV_MODE_PREFERENCE, devModeUnlocked);
+ game.preferences.putBoolean(Preferences.DEV_MODE_PREFERENCE, devModeUnlocked);
game.preferences.flush();
Array buttonTexts = new Array<>();
diff --git a/core/src/com/cg/zoned/screens/DevScreen.java b/core/src/com/cg/zoned/screens/DevScreen.java
index 8b41985..c4ea970 100644
--- a/core/src/com/cg/zoned/screens/DevScreen.java
+++ b/core/src/com/cg/zoned/screens/DevScreen.java
@@ -14,7 +14,8 @@
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
-import com.cg.zoned.Constants;
+import com.cg.zoned.Assets;
+import com.cg.zoned.Preferences;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
import com.cg.zoned.managers.AnimationManager;
@@ -46,7 +47,7 @@ public DevScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
@@ -54,7 +55,7 @@ public void show() {
setUpStage();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.fadeInStage(stage);
}
@@ -74,20 +75,20 @@ private void setUpStage() {
screenScrollPane.setOverscroll(false, true);
int maxPlayerCount = 100;
- int currentPlayerCount = game.preferences.getInteger(Constants.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, 2);
+ int currentPlayerCount = game.preferences.getInteger(Preferences.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, 2);
Label splitscreenPlayerCountLabel = new Label("Splitscreen player count", game.skin);
splitscreenPlayerCountSpinner = new Spinner(game.skin,
- game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight(),
+ game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight(),
64f * game.getScaleFactor(),
true);
splitscreenPlayerCountSpinner.generateValueRange(minPlayerCount, maxPlayerCount, game.skin);
splitscreenPlayerCountSpinner.snapToStep(currentPlayerCount - minPlayerCount);
int maxSplitScreenCount = 100;
- int currentSplitScreenCount = game.preferences.getInteger(Constants.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, 2);
+ int currentSplitScreenCount = game.preferences.getInteger(Preferences.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, 2);
Label mapStartPosSplitscreenCountLabel = new Label("Map start position splitscreen count", game.skin);
mapStartPosSplitscreenCountSpinner = new Spinner(game.skin,
- game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight(),
+ game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight(),
64f * game.getScaleFactor(),
true);
mapStartPosSplitscreenCountSpinner.generateValueRange(minSplitScreenCount, maxSplitScreenCount, game.skin);
@@ -148,8 +149,8 @@ public void render(float delta) {
}
private void saveData() {
- game.preferences.putInteger(Constants.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, splitscreenPlayerCountSpinner.getPositionIndex() + minPlayerCount);
- game.preferences.putInteger(Constants.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, mapStartPosSplitscreenCountSpinner.getPositionIndex() + minSplitScreenCount);
+ game.preferences.putInteger(Preferences.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, splitscreenPlayerCountSpinner.getPositionIndex() + minPlayerCount);
+ game.preferences.putInteger(Preferences.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, mapStartPosSplitscreenCountSpinner.getPositionIndex() + minSplitScreenCount);
game.preferences.flush();
}
diff --git a/core/src/com/cg/zoned/screens/GameScreen.java b/core/src/com/cg/zoned/screens/GameScreen.java
index ea6f923..9837368 100644
--- a/core/src/com/cg/zoned/screens/GameScreen.java
+++ b/core/src/com/cg/zoned/screens/GameScreen.java
@@ -19,9 +19,11 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Constants;
import com.cg.zoned.Map;
import com.cg.zoned.Player;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ScoreBar;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.TeamData;
@@ -47,7 +49,7 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
private Map map;
- private ExtendViewport[] playerViewports; // Two viewports in split-screen mode; else one
+ private ExtendViewport[] playerViewports;
private ShapeDrawer shapeDrawer;
private SpriteBatch batch;
@@ -89,7 +91,7 @@ private GameScreen(final Zoned game, MapManager mapManager, Player[] players, Se
this.gameManager = new GameManager(this);
this.gameManager.setUpConnectionManager(server, client);
this.gameManager.setUpDirectionAndPlayerBuffer(players, fullScreenStage,
- game.preferences.getInteger(Constants.CONTROL_PREFERENCE, Constants.PIE_MENU_CONTROL),
+ game.preferences.getInteger(Preferences.CONTROL_PREFERENCE, 0),
game.skin, game.getScaleFactor(), usedTextures);
this.batch = new SpriteBatch();
@@ -99,7 +101,7 @@ private GameScreen(final Zoned game, MapManager mapManager, Player[] players, Se
currentBgColor = new Color(0, 0, 0, bgAlpha);
targetBgColor = new Color(0, 0, 0, bgAlpha);
- BitmapFont playerLabelFont = game.skin.getFont(Constants.FONT_MANAGER.PLAYER_LABEL.getName());
+ BitmapFont playerLabelFont = game.skin.getFont(Assets.FontManager.PLAYER_LABEL_NOSCALE.getFontName());
initViewports(players);
map.createPlayerLabelTextures(players, shapeDrawer, playerLabelFont);
@@ -123,14 +125,14 @@ private void initViewports(Player[] players) {
}
}
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
public void show() {
setUpInputProcessors();
setUpUI();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
}
private void setUpUI() {
@@ -196,11 +198,11 @@ public void render(float delta) {
int highscore = 0;
for (TeamData teamData : gameManager.playerManager.getTeamData()) {
- if (teamData.score > highscore) {
- highscore = teamData.score;
- targetBgColor.set(teamData.color);
+ if (teamData.getScore() > highscore) {
+ highscore = teamData.getScore();
+ targetBgColor.set(teamData.getColor());
targetBgColor.a = bgAlpha;
- } else if (teamData.score == highscore) {
+ } else if (teamData.getScore() == highscore) {
targetBgColor.set(0, 0, 0, bgAlpha);
}
}
@@ -254,14 +256,16 @@ public void render(float delta) {
}
if (showFPSCounter) {
- UITextDisplayer.displayFPS(fullScreenStage.getViewport(), fullScreenStage.getBatch(), font, UITextDisplayer.padding, scoreBars.scoreBarHeight + UITextDisplayer.padding);
+ UITextDisplayer.displayFPS(fullScreenStage.getViewport(), fullScreenStage.getBatch(), font,
+ UITextDisplayer.padding, scoreBars.scoreBarHeight + UITextDisplayer.padding);
}
if (gameManager.gameConnectionManager.isActive) {
float yOffset = scoreBars.scoreBarHeight + UITextDisplayer.padding;
if (!showFPSCounter) {
yOffset = -yOffset + scoreBars.scoreBarHeight + UITextDisplayer.padding;
}
- UITextDisplayer.displayPing(fullScreenStage.getViewport(), fullScreenStage.getBatch(), font, gameManager.gameConnectionManager.getPing(), UITextDisplayer.padding, yOffset);
+ UITextDisplayer.displayPing(fullScreenStage.getViewport(), fullScreenStage.getBatch(), font,
+ gameManager.gameConnectionManager.getPing(), UITextDisplayer.padding, yOffset);
}
fullScreenStage.act(delta);
@@ -283,11 +287,12 @@ private void fadeOutScreen(float delta) {
gameManager.gameConnectionManager.close();
}
- Gdx.app.postRunnable(new Runnable() { // Hopefully fixes the occasional SIGSEGVs around 1 second after transitioning to VictoryScreen
+ // Transition to VictoryScreen after completing rendering the current frame to avoid SIGSEGV crashes
+ Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
dispose();
- game.setScreen(new VictoryScreen(game, gameManager.playerManager, map.rows, map.cols, map.wallCount));
+ game.setScreen(new VictoryScreen(game, gameManager.playerManager));
}
});
}
@@ -322,7 +327,7 @@ private void renderMap(int index, float delta) {
batch.setProjectionMatrix(viewport.getCamera().combined);
batch.begin();
- map.render(players, shapeDrawer, (OrthographicCamera) viewport.getCamera(), delta);
+ map.render(players, index, shapeDrawer, (OrthographicCamera) viewport.getCamera(), delta);
batch.end();
}
diff --git a/core/src/com/cg/zoned/screens/HostJoinScreen.java b/core/src/com/cg/zoned/screens/HostJoinScreen.java
index d747c64..7db000e 100644
--- a/core/src/com/cg/zoned/screens/HostJoinScreen.java
+++ b/core/src/com/cg/zoned/screens/HostJoinScreen.java
@@ -22,8 +22,10 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Constants;
import com.cg.zoned.KryoHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
import com.cg.zoned.managers.AnimationManager;
@@ -40,6 +42,9 @@
public class HostJoinScreen extends ScreenAdapter implements InputProcessor {
final Zoned game;
+ // Bigger buffer as map preview images, which is bigger than text data, are sent
+ private static final int CONNECTION_BUFFER_SIZE = 131072; // 2^17
+
private Array usedTextures = new Array<>();
private FocusableStage stage;
@@ -57,7 +62,7 @@ public HostJoinScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(this.game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
dialogButtonTexts.add("OK");
}
@@ -66,7 +71,7 @@ public HostJoinScreen(final Zoned game) {
public void show() {
setUpStage();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.fadeInStage(stage);
}
@@ -84,14 +89,14 @@ private void setUpStage() {
Image infoImage = new Image(infoIconTexture);
Label infoLabel = new Label("Make sure that all players\nare on the same local network", game.skin);
infoLabel.setAlignment(Align.center);
- infoTable.add(infoImage).height(game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight())
- .width(game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight()).padRight(20f);
+ infoTable.add(infoImage).height(game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight())
+ .width(game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight()).padRight(20f);
infoTable.add(infoLabel).pad(10f);
stage.addActor(infoTable);
Label playerNameLabel = new Label("Player name: ", game.skin, "themed");
final TextField playerNameField = new TextField("", game.skin);
- playerNameField.setText(game.preferences.getString(Constants.NAME_PREFERENCE, null));
+ playerNameField.setText(game.preferences.getString(Preferences.NAME_PREFERENCE, null));
playerNameField.setCursorPosition(playerNameField.getText().length());
table.add(playerNameLabel).right();
table.add(playerNameField).width(playerNameField.getPrefWidth() * game.getScaleFactor()).left();
@@ -121,7 +126,7 @@ public void clicked(InputEvent event, float x, float y) {
String name = playerNameField.getText().trim();
if (!name.isEmpty()) {
- game.preferences.putString(Constants.NAME_PREFERENCE, name);
+ game.preferences.putString(Preferences.NAME_PREFERENCE, name);
game.preferences.flush();
startServerLobby(playerNameField.getText().trim());
@@ -141,7 +146,7 @@ public void clicked(InputEvent event, float x, float y) {
String name = playerNameField.getText().trim();
if (!name.isEmpty()) {
if (searchingLabel.getColor().a == 0) {
- game.preferences.putString(Constants.NAME_PREFERENCE, name);
+ game.preferences.putString(Preferences.NAME_PREFERENCE, name);
game.preferences.flush();
searchingLabel.setText("Searching for servers...");
@@ -179,7 +184,7 @@ public void clicked(InputEvent event, float x, float y) {
}
private void startServerLobby(final String playerName) {
- final Server server = new Server();
+ final Server server = new Server(CONNECTION_BUFFER_SIZE, 2048);
Kryo kryo = server.getKryo();
KryoHelper.registerClasses(kryo);
@@ -199,7 +204,7 @@ private void startServerLobby(final String playerName) {
}
private void startClientLobby(final String playerName, final Label searchingLabel) {
- final Client client = new Client();
+ final Client client = new Client(8192, CONNECTION_BUFFER_SIZE);
Kryo kryo = client.getKryo();
KryoHelper.registerClasses(kryo);
diff --git a/core/src/com/cg/zoned/screens/LoadingScreen.java b/core/src/com/cg/zoned/screens/LoadingScreen.java
index b281453..3bad707 100644
--- a/core/src/com/cg/zoned/screens/LoadingScreen.java
+++ b/core/src/com/cg/zoned/screens/LoadingScreen.java
@@ -26,8 +26,11 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
-import com.cg.zoned.Constants;
+import com.cg.zoned.Assets;
+import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.Zoned;
+import com.cg.zoned.managers.ControlManager;
public class LoadingScreen extends ScreenAdapter {
final Zoned game;
@@ -45,6 +48,26 @@ public class LoadingScreen extends ScreenAdapter {
public LoadingScreen(final Zoned game) {
this.game = game;
game.discordRPCManager.updateRPC("Loading game");
+ initSetup();
+ }
+
+ private void initSetup() {
+ // Set up preferences
+ game.preferences = Gdx.app.getPreferences(Preferences.ZONED_PREFERENCES);
+
+ // Set up Discord RPC
+ if (game.preferences.getBoolean(Preferences.DISCORD_RPC_PREFERENCE, true)) {
+ game.discordRPCManager.initRPC();
+ }
+
+ // Reset player colors
+ PlayerColorHelper.resetPlayerColorAlpha();
+
+ // Validate touch controls
+ if (game.preferences.getInteger(Preferences.CONTROL_PREFERENCE, 0) >= ControlManager.CONTROL_TYPES.length) {
+ game.preferences.putInteger(Preferences.CONTROL_PREFERENCE, 0);
+ game.preferences.flush();
+ }
}
@Override
@@ -62,12 +85,9 @@ public void show() {
assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
assetManager.setLoader(BitmapFont.class, ".otf", new FreetypeFontLoader(resolver));
- generateCustomFont("fonts/austere.otf", Constants.FONT_MANAGER.LARGE);
- generateCustomFont("fonts/glametrix.otf", Constants.FONT_MANAGER.REGULAR);
- generateCustomFont("fonts/bebasneue.otf", Constants.FONT_MANAGER.SMALL);
- generateCustomFont("fonts/bebasneue.otf", Constants.FONT_MANAGER.PLAYER_LABEL);
-
- game.preferences = Gdx.app.getPreferences(Constants.ZONED_PREFERENCES);
+ for (Assets.FontManager font : Assets.FontManager.values()) {
+ generateCustomFont("fonts/" + font.getFontFileName(), font.getFontName(), font.getFontSize());
+ }
}
private void setUpLoadingUI() {
@@ -88,23 +108,23 @@ private void setUpLoadingUI() {
table.add(progressBar).growX()
.padLeft(100f * game.getScaleFactor()).padRight(100f * game.getScaleFactor())
- .padTop(32f * game.getScaleFactor());
+ .padTop(16f * game.getScaleFactor());
stage.addActor(table);
}
- private void generateCustomFont(String fontName, Constants.FONT_MANAGER fontManager) {
+ private void generateCustomFont(String fontFileName, String fontName, int fontSize) {
FreetypeFontLoader.FreeTypeFontLoaderParameter parameter = new FreetypeFontLoader.FreeTypeFontLoaderParameter();
- parameter.fontFileName = fontName;
- if (fontManager.getName().endsWith("noscale")) {
- parameter.fontParameters.size = fontManager.getSize();
+ parameter.fontFileName = fontFileName;
+ if (fontName.endsWith("noscale")) {
+ parameter.fontParameters.size = fontSize;
} else {
- parameter.fontParameters.size = (int) (fontManager.getSize() * game.getScaleFactor());
+ parameter.fontParameters.size = (int) (fontSize * game.getScaleFactor());
}
//Gdx.app.log(Constants.LOG_TAG, "Screen density: " + Gdx.graphics.getDensity());
- String fontId = fontManager.getName() + ".otf";
+ String fontId = fontName + ".otf";
assetManager.load(fontId, BitmapFont.class, parameter);
}
@@ -116,8 +136,8 @@ public void render(float delta) {
if (!loadedFonts) {
ObjectMap fontMap = new ObjectMap<>();
- for (Constants.FONT_MANAGER font : Constants.FONT_MANAGER.values()) {
- fontMap.put(font.getName(), assetManager.get(font.getName() + ".otf", BitmapFont.class));
+ for (Assets.FontManager font : Assets.FontManager.values()) {
+ fontMap.put(font.getFontName(), assetManager.get(font.getFontName() + ".otf", BitmapFont.class));
}
SkinLoader.SkinParameter parameter = new SkinLoader.SkinParameter("neon-skin/neon-ui.atlas", fontMap);
diff --git a/core/src/com/cg/zoned/screens/MainMenuScreen.java b/core/src/com/cg/zoned/screens/MainMenuScreen.java
index 1e4e41d..7ab80a5 100644
--- a/core/src/com/cg/zoned/screens/MainMenuScreen.java
+++ b/core/src/com/cg/zoned/screens/MainMenuScreen.java
@@ -1,5 +1,6 @@
package com.cg.zoned.screens;
+import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
@@ -11,6 +12,7 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -22,13 +24,14 @@
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
-import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
-import com.cg.zoned.Constants;
+import com.cg.zoned.Assets;
+import com.cg.zoned.GameMode;
+import com.cg.zoned.Preferences;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
import com.cg.zoned.managers.AnimationManager;
@@ -50,7 +53,7 @@ public class MainMenuScreen extends ScreenAdapter implements InputProcessor {
private AnimationManager animationManager;
private boolean showFPSCounter;
private BitmapFont font;
- private Texture roundedCornerBgColorTexture;
+ private NinePatch roundedCornerNP;
private ParticleEffect emitterLeft, emitterRight;
@@ -65,13 +68,13 @@ public MainMenuScreen(final Zoned game) {
emitterLeft = new ParticleEffect();
emitterRight = new ParticleEffect();
- font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
public void show() {
setUpMainMenu();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.startMainMenuAnimation(mainStage, mainMenuUIButtons);
animationManager.setAnimationListener(new AnimationManager.AnimationListener() {
@Override
@@ -87,13 +90,14 @@ public void animationEnd(Stage stage) {
new Thread(new Runnable() {
@Override
public void run() {
- final Pixmap pixmap = getRoundedCornerPixmap(Color.GREEN, 480, 640, 50);
- // I suspect pixmap generation caused a noticeable lag so run in a new thread
+ final int radius = 40;
+ final Pixmap pixmap = getRoundedCornerPixmap(Color.GREEN, radius);
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
- roundedCornerBgColorTexture = new Texture(pixmap);
+ Texture roundedCornerBgColorTexture = new Texture(pixmap);
usedTextures.add(roundedCornerBgColorTexture);
+ roundedCornerNP = new NinePatch(roundedCornerBgColorTexture, radius, radius, radius, radius);
pixmap.dispose();
}
});
@@ -107,7 +111,7 @@ private void setUpMainMenu() {
//mainTable.setDebug(true);
mainTable.center();
- Label gameTitle = new Label("ZONED", game.skin, Constants.FONT_MANAGER.LARGE.getName(), Color.GREEN);
+ Label gameTitle = new Label("ZONED", game.skin, Assets.FontManager.STYLED_LARGE.getFontName(), Color.GREEN);
mainTable.add(gameTitle).pad(10f * game.getScaleFactor());
mainTable.row();
@@ -119,7 +123,7 @@ private void setUpMainMenu() {
HoverImageButton settingsButton = uiButtonManager.addSettingsButtonToStage(game.assets.getSettingsButtonTexture());
HoverImageButton creditsButton = uiButtonManager.addCreditsButtonToStage(game.assets.getCreditsButtonTexture());
HoverImageButton devButton = null;
- if (game.preferences.getBoolean(Constants.DEV_MODE_PREFERENCE, false)) {
+ if (game.preferences.getBoolean(Preferences.DEV_MODE_PREFERENCE, false)) {
devButton = uiButtonManager.addDevButtonToStage(game.assets.getDevButtonTexture());
devButton.addListener(new ClickListener() {
@Override
@@ -168,7 +172,9 @@ public void clicked(InputEvent event, float x, float y) {
}
mainMenuUIButtons.add(exitButton);
- mainStage.setFocusedActor(playButton);
+ if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
+ mainStage.setFocusedActor(playButton);
+ }
mainStage.addActor(mainTable);
}
@@ -201,7 +207,7 @@ private HoverImageButton setUpAnimatedPlayButton(Table mainTable) {
playButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
- if (roundedCornerBgColorTexture == null) {
+ if (roundedCornerNP == null) {
// Thread didn't finish loading the pixmap
// Should almost never happen cause processors are hella fast, even mobile ones
return;
@@ -230,47 +236,32 @@ private void setUpPlayMenu() {
playModeTable.add(chooseMode).expandX().pad(20f).colspan(2);
playModeTable.row();
- final int gameModeCount = 2;
-
- TextureRegionDrawable whiteBG = new TextureRegionDrawable(roundedCornerBgColorTexture);
-
- String[] backgroundImageLocations = new String[]{
- "icons/multiplayer_icons/ic_splitscreen_multiplayer.png",
- "icons/multiplayer_icons/ic_local_multiplayer.png",
- };
- String[] modeLabelStrings = new String[]{
- "Splitscreen\nMultiplayer",
- "Local\nNetwork\nMultiplayer",
- };
- final Class[] screenClasses = new Class[]{
- PlayerSetUpScreen.class,
- HostJoinScreen.class,
+ final GameMode[] gameModes = new GameMode[]{
+ new GameMode("Splitscreen\nMultiplayer", "icons/multiplayer_icons/ic_splitscreen_multiplayer.png", PlayerSetUpScreen.class),
+ new GameMode("Local\nNetwork\nMultiplayer", "icons/multiplayer_icons/ic_local_multiplayer.png", HostJoinScreen.class),
};
- if (screenClasses.length != gameModeCount ||
- modeLabelStrings.length != gameModeCount ||
- backgroundImageLocations.length != gameModeCount) {
- throw new IndexOutOfBoundsException("Game mode count does not match asset the count");
- }
-
final float normalAlpha = .15f;
final float hoverAlpha = .3f;
final float clickAlpha = .7f;
- for (int i = 0; i < gameModeCount; i++) {
+ for (int i = 0; i < gameModes.length; i++) {
Table table = new Table();
table.center();
- final Image backgroundColorImage = new Image(whiteBG);
+ final Image backgroundColorImage = new Image(roundedCornerNP);
backgroundColorImage.getColor().a = normalAlpha;
backgroundColorImage.setScaling(Scaling.stretch);
- Texture backgroundImageTexture = new Texture(Gdx.files.internal(backgroundImageLocations[i]));
- usedTextures.add(backgroundImageTexture);
- Image backgroundImage = new Image(backgroundImageTexture);
- backgroundImage.setScaling(Scaling.fit);
- backgroundImage.getColor().a = .3f;
+ Image backgroundImage = null;
+ if (gameModes[i].previewLocation != null) {
+ Texture backgroundImageTexture = new Texture(Gdx.files.internal(gameModes[i].previewLocation));
+ usedTextures.add(backgroundImageTexture);
+ backgroundImage = new Image(backgroundImageTexture);
+ backgroundImage.setScaling(Scaling.fit);
+ backgroundImage.getColor().a = .3f;
+ }
- Label modeLabel = new Label(modeLabelStrings[i], game.skin);
+ Label modeLabel = new Label(gameModes[i].name, game.skin);
modeLabel.setAlignment(Align.center);
final int finalI = i;
@@ -310,18 +301,30 @@ public void clicked(InputEvent event, float x, float y) {
emitterLeft.allowCompletion();
emitterRight.allowCompletion();
try {
- animationManager.fadeOutStage(playModeStage, MainMenuScreen.this, (Screen) screenClasses[finalI].getConstructors()[0].newInstance(game));
+ animationManager.fadeOutStage(playModeStage, MainMenuScreen.this, (Screen) gameModes[finalI].targetClass.getConstructors()[0].newInstance(game));
} catch (Exception e) {
e.printStackTrace();
}
}
});
- Stack stack = new Stack(backgroundColorImage, backgroundImage, modeLabel);
+ Stack stack;
+ if (backgroundImage != null) {
+ stack = new Stack(backgroundColorImage, backgroundImage, modeLabel);
+ } else {
+ stack = new Stack(backgroundColorImage, modeLabel);
+ }
- table.add(stack).expand().pad(40f);
+ float optionPadding = 50f;
+ if (i == 0) {
+ table.add(stack).grow().padLeft(optionPadding).padTop(optionPadding).padBottom(optionPadding).padRight(optionPadding / 2);
+ } else if (i == gameModes.length - 1) {
+ table.add(stack).grow().padLeft(optionPadding / 2).padTop(optionPadding).padBottom(optionPadding).padRight(optionPadding);
+ } else {
+ table.add(stack).grow().padLeft(optionPadding / 2).padTop(optionPadding).padBottom(optionPadding).padRight(optionPadding / 2);
+ }
- playModeTable.add(table).expand().uniform();
+ playModeTable.add(table).grow().uniform();
playModeStage.addFocusableActor(table);
}
@@ -369,7 +372,10 @@ public void resize(int width, int height) {
emitterRight.setPosition(viewport.getWorldWidth(), 0);
}
- private Pixmap getRoundedCornerPixmap(Color color, int width, int height, int radius) {
+ public Pixmap getRoundedCornerPixmap(Color color, int radius) {
+ final int width = 10 + (radius * 2);
+ final int height = 10 + (radius * 2);
+
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
pixmap.fillCircle(radius, radius, radius);
diff --git a/core/src/com/cg/zoned/screens/MapStartPosScreen.java b/core/src/com/cg/zoned/screens/MapStartPosScreen.java
index bd6ef78..e68b33f 100644
--- a/core/src/com/cg/zoned/screens/MapStartPosScreen.java
+++ b/core/src/com/cg/zoned/screens/MapStartPosScreen.java
@@ -27,11 +27,13 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Cell;
import com.cg.zoned.Constants;
import com.cg.zoned.GameTouchPoint;
import com.cg.zoned.Map;
import com.cg.zoned.Player;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
@@ -99,7 +101,7 @@ public MapStartPosScreen(final Zoned game, MapManager mapManager,
this.batch = new SpriteBatch();
this.shapeDrawer = new ShapeDrawer(batch, usedTextures);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
@@ -107,12 +109,13 @@ public void show() {
setUpMap();
setUpStage();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.fadeInStage(stage);
}
private void setUpMap() {
map = new Map(mapGrid, 0, shapeDrawer); // Wall count is unnecessary in this case so 0
+ map.createPlayerLabelTextures(players, shapeDrawer, game.skin.getFont(Assets.FontManager.PLAYER_LABEL_NOSCALE.getFontName()));
mapDarkOverlayColor = new Color(0, 0, 0, 0.8f);
mapViewports = new ExtendViewport[splitScreenCount];
for (int i = 0; i < players.length; i++) {
@@ -143,9 +146,6 @@ private void updateDividerColors(int playerIndex) {
} else {
dividerRightColor[i] = Color.BLACK;
}
-
- dividerLeftColor[i].mul(10);
- dividerRightColor[i].mul(10);
}
}
@@ -169,7 +169,6 @@ private void setUpStage() {
if (i < players.length) {
playerLabels[i] = new Label("Player " + (i + 1), game.skin);
Color labelColor = new Color(players[i].color);
- labelColor.mul(10);
playerLabels[i].setColor(labelColor);
if (alignLeft) {
table.add(playerLabels[i]).padBottom(10f * game.getScaleFactor()).left().expandX();
@@ -348,7 +347,6 @@ public void clicked(InputEvent event, float x, float y) {
playerLabels[i].setText("Player " + (i + playerIndex + 1));
Color labelColor = new Color(players[i + playerIndex].color);
- labelColor.mul(10);
playerLabels[i].setColor(labelColor);
radioButtons[i][(i + playerIndex) % radioButtons[i].length].setChecked(true);
@@ -399,14 +397,16 @@ public void clicked(InputEvent event, float x, float y) {
});
}
- private void focusAndRenderViewport(Viewport viewport, Player player, Vector2 vel, float delta) {
- focusCameraOnPlayer(viewport, player, vel, delta);
+ private void renderMap(int playerIndex, float delta) {
+ int mapViewportIndex = playerIndex - this.playerIndex;
+ Viewport viewport = mapViewports[mapViewportIndex];
+
+ focusCameraOnPlayer(viewport, players[playerIndex], dragOffset[mapViewportIndex], delta);
viewport.apply();
batch.setProjectionMatrix(viewport.getCamera().combined);
-
batch.begin();
- map.render(players, shapeDrawer, (OrthographicCamera) viewport.getCamera(), delta);
+ map.render(players, playerIndex, shapeDrawer, (OrthographicCamera) viewport.getCamera(), delta);
batch.end();
}
@@ -481,7 +481,7 @@ public void render(float delta) {
for (int i = 0; i < mapViewports.length; i++) {
if (playerIndex + i < players.length) {
- focusAndRenderViewport(mapViewports[i], players[playerIndex + i], dragOffset[i], delta);
+ renderMap(playerIndex + i, delta);
}
}
diff --git a/core/src/com/cg/zoned/screens/PlayerSetUpScreen.java b/core/src/com/cg/zoned/screens/PlayerSetUpScreen.java
index a329b0f..2e78e7a 100644
--- a/core/src/com/cg/zoned/screens/PlayerSetUpScreen.java
+++ b/core/src/com/cg/zoned/screens/PlayerSetUpScreen.java
@@ -21,10 +21,12 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Constants;
import com.cg.zoned.MapSelector;
import com.cg.zoned.Player;
import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
@@ -65,12 +67,12 @@ public PlayerSetUpScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(this.game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
this.batch = new SpriteBatch();
this.shapeDrawer = new ShapeDrawer(batch, usedTextures);
- this.playerCount = game.preferences.getInteger(Constants.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, 2);
+ this.playerCount = game.preferences.getInteger(Preferences.SPLITSCREEN_PLAYER_COUNT_PREFERENCE, 2);
this.playerList = new Table();
this.currentBgColors = new Color[this.playerCount];
@@ -85,16 +87,16 @@ public PlayerSetUpScreen(final Zoned game) {
public void show() {
setUpStage();
setUpUIButtons();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.setAnimationListener(new AnimationManager.AnimationListener() {
@Override
public void animationEnd(Stage stage) {
- boolean showTutorialDialogPrompt = game.preferences.getBoolean(Constants.SHOW_TUTORIAL_PREFERENCE, true);
+ boolean showTutorialDialogPrompt = game.preferences.getBoolean(Preferences.SHOW_TUTORIAL_PREFERENCE, true);
if (showTutorialDialogPrompt) {
showTutorialDialog();
- game.preferences.putBoolean(Constants.SHOW_TUTORIAL_PREFERENCE, false);
+ game.preferences.putBoolean(Preferences.SHOW_TUTORIAL_PREFERENCE, false);
game.preferences.flush();
}
}
@@ -181,8 +183,9 @@ public void buttonPressed(Button button) {
final MapSelector mapSelector = new MapSelector(stage, game.getScaleFactor(), game.assets, game.skin);
mapSelector.setUsedTextureArray(usedTextures);
+ mapSelector.getMapManager().enableExternalMapLogging(true);
Spinner mapSpinner = mapSelector.loadMapSelectorSpinner(150 * game.getScaleFactor(),
- game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight() * 3);
+ game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight() * 3);
mapSelector.loadExternalMaps();
table.add(mapSpinner).colspan(NO_OF_COLORS + 1).pad(20 * game.getScaleFactor()).expandX();
table.row();
@@ -236,7 +239,7 @@ private void startGame(Array playerColors, MapManager mapManager) {
players[i].setControlIndex(i % Constants.PLAYER_CONTROLS.length);
}
- int startPosSplitScreenCount = game.preferences.getInteger(Constants.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, 2);
+ int startPosSplitScreenCount = game.preferences.getInteger(Preferences.MAP_START_POS_SPLITSCREEN_COUNT_PREFERENCE, 2);
animationManager.fadeOutStage(stage, this, new MapStartPosScreen(game, mapManager, players, startPosSplitScreenCount, false));
}
diff --git a/core/src/com/cg/zoned/screens/ServerLobbyScreen.java b/core/src/com/cg/zoned/screens/ServerLobbyScreen.java
index b61aab6..1206aa8 100644
--- a/core/src/com/cg/zoned/screens/ServerLobbyScreen.java
+++ b/core/src/com/cg/zoned/screens/ServerLobbyScreen.java
@@ -1,9 +1,11 @@
package com.cg.zoned.screens;
+import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
+import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
@@ -26,11 +28,13 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Cell;
import com.cg.zoned.Constants;
import com.cg.zoned.MapSelector;
import com.cg.zoned.Player;
import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
@@ -38,6 +42,7 @@
import com.cg.zoned.managers.MapManager;
import com.cg.zoned.managers.ServerLobbyConnectionManager;
import com.cg.zoned.managers.UIButtonManager;
+import com.cg.zoned.maps.MapEntity;
import com.cg.zoned.ui.DropDownMenu;
import com.cg.zoned.ui.FocusableStage;
import com.cg.zoned.ui.HoverImageButton;
@@ -81,7 +86,9 @@ public ServerLobbyScreen(final Zoned game, Server server, String name) {
viewport = new ScreenViewport();
stage = new FocusableStage(viewport);
animationManager = new AnimationManager(this.game, this);
- font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
+
+ // TODO: Fix bogus client ip being sent to some clients when a map is changed while a new client was joining
startLocations = new Array<>();
this.serverName = name;
@@ -93,7 +100,7 @@ public void show() {
setUpServerLobbyStage();
setUpMap();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
playerConnected(null);
connectionManager.start();
@@ -107,8 +114,8 @@ private void setUpServerLobbyStage() {
serverLobbyTable.center();
//serverLobbyTable.setDebug(true);
- Label onlinePlayersTitle = new Label("Connected Players", game.skin, "themed");
- serverLobbyTable.add(onlinePlayersTitle).pad(20f);
+ Label lobbyTitle = new Label("Lobby", game.skin, "themed");
+ serverLobbyTable.add(lobbyTitle).pad(20f);
serverLobbyTable.row();
Table scrollTable = new Table();
@@ -124,20 +131,26 @@ private void setUpServerLobbyStage() {
mapSelector = new MapSelector(stage, game.getScaleFactor(), game.assets, game.skin);
mapSelector.setUsedTextureArray(usedTextures);
final Spinner mapSpinner = mapSelector.loadMapSelectorSpinner(150 * game.getScaleFactor(),
- game.skin.getFont(Constants.FONT_MANAGER.REGULAR.getName()).getLineHeight() * 3);
+ game.skin.getFont(Assets.FontManager.REGULAR.getFontName()).getLineHeight() * 3);
final Table mapSelectorTable = new Table();
mapSelectorTable.add(mapSpinner).pad(10f);
final TextButton mapButton = new TextButton(mapSelector.getMapManager().getMapList().get(mapSpinner.getPositionIndex()).getName(), game.skin);
+
+ final Array buttonTexts = new Array<>();
+ buttonTexts.add("Cancel");
+ buttonTexts.add("Set Map");
+
+ final Array focusableDialogButtons = new Array<>();
+ focusableDialogButtons.add(mapSpinner.getLeftButton());
+ focusableDialogButtons.add(mapSpinner.getRightButton());
+
mapButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
final int prevIndex = mapSpinner.getPositionIndex();
- Array buttonTexts = new Array<>();
- buttonTexts.add("Cancel");
- buttonTexts.add("Set Map");
- stage.showDialog(mapSelectorTable, buttonTexts,
+ stage.showDialog(mapSelectorTable, focusableDialogButtons, buttonTexts,
false, game.getScaleFactor(),
new FocusableStage.DialogResultListener() {
@Override
@@ -158,7 +171,7 @@ public void dialogResult(String buttonText) {
}, game.skin);
}
});
- // mapSelector.loadExternalMaps(); Not yet
+ mapSelector.loadExternalMaps();
serverLobbyTable.add(mapButton).width(200f * game.getScaleFactor());
serverLobbyTable.row();
@@ -283,7 +296,9 @@ public void changed(ChangeEvent event, Actor actor) {
stage.addFocusableActor(colorSelector);
stage.addFocusableActor(startPosSelector);
stage.row();
- stage.setFocusedActor(colorSelector);
+ if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
+ stage.setFocusedActor(colorSelector);
+ }
} else {
Label colorLabel = new Label(Constants.PLAYER_COLORS.keySet().iterator().next(), game.skin);
colorLabel.setName("color-label");
@@ -327,7 +342,8 @@ public void updatePlayerDetails(int playerIndex, String clientName) {
Label nameLabel = playerItem.findActor("name-label");
nameLabel.setText(clientName);
- connectionManager.acceptPlayer(playerIndex, mapSelector.getMapManager());
+ connectionManager.acceptPlayer(playerIndex);
+ connectionManager.sendMapDetails(playerIndex, mapSelector.getMapManager());
connectionManager.broadcastPlayerInfo(playerList.getChildren(), -1); // Send info about the new player to other clients and vice-versa
}
@@ -391,6 +407,16 @@ private void mapChanged(Array startLocations) {
connectionManager.sendMapDetails(-1, mapSelector.getMapManager());
}
+ @Override
+ public FileHandle getExternalMapDir() {
+ return this.mapSelector.getMapManager().getExternalMapDir();
+ }
+
+ @Override
+ public MapEntity fetchMap(String mapName) {
+ return this.mapSelector.getMapManager().getMap(mapName);
+ }
+
private void startGame(MapManager mapManager) {
Player[] players = inflatePlayerList(mapManager);
clearMapGrid();
@@ -567,7 +593,10 @@ public void dispose() {
for (Texture texture : usedTextures) {
texture.dispose();
}
- map.dispose();
+ if (map != null) {
+ map.dispose();
+ map = null;
+ }
}
private void onBackPressed() {
diff --git a/core/src/com/cg/zoned/screens/SettingsScreen.java b/core/src/com/cg/zoned/screens/SettingsScreen.java
index 544f398..783d8c9 100644
--- a/core/src/com/cg/zoned/screens/SettingsScreen.java
+++ b/core/src/com/cg/zoned/screens/SettingsScreen.java
@@ -1,5 +1,6 @@
package com.cg.zoned.screens;
+import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
@@ -20,10 +21,13 @@
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
-import com.cg.zoned.Constants;
+import com.cg.zoned.Assets;
+import com.cg.zoned.Preferences;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
+import com.cg.zoned.controls.ControlType;
import com.cg.zoned.managers.AnimationManager;
+import com.cg.zoned.managers.ControlManager;
import com.cg.zoned.managers.UIButtonManager;
import com.cg.zoned.ui.FocusableStage;
import com.cg.zoned.ui.HoverCheckBox;
@@ -48,7 +52,7 @@ public SettingsScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(this.game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
}
@Override
@@ -70,89 +74,113 @@ private void setUpStage() {
ScrollPane screenScrollPane = new ScrollPane(table);
screenScrollPane.setOverscroll(false, true);
- Label controlLabel = new Label("Control scheme", game.skin, "themed");
- Texture controlFlingOffTexture = new Texture(Gdx.files.internal("icons/control_icons/ic_control_fling_off.png"));
- Texture controlFlingOnTexture = new Texture(Gdx.files.internal("icons/control_icons/ic_control_fling_on.png"));
- Texture controlPiemenuOffTexture = new Texture(Gdx.files.internal("icons/control_icons/ic_control_piemenu_off.png"));
- Texture controlPiemenuOnTexture = new Texture(Gdx.files.internal("icons/control_icons/ic_control_piemenu_on.png"));
- usedTextures.add(controlFlingOffTexture);
- usedTextures.add(controlFlingOnTexture);
- usedTextures.add(controlPiemenuOffTexture);
- usedTextures.add(controlPiemenuOnTexture);
- Drawable controlFlingOff = new TextureRegionDrawable(controlFlingOffTexture);
- Drawable controlFlingOn = new TextureRegionDrawable(controlFlingOnTexture);
- Drawable controlPiemenuOff = new TextureRegionDrawable(controlPiemenuOffTexture);
- Drawable controlPiemenuOn = new TextureRegionDrawable(controlPiemenuOnTexture);
- final HoverImageButton flingControl = new HoverImageButton(controlFlingOff, controlFlingOn);
- final HoverImageButton piemenuControl = new HoverImageButton(controlPiemenuOff, controlPiemenuOn);
- final Label flingControlLabel = new Label("Fling", game.skin);
- Label piemenuControlLabel = new Label("Piemenu", game.skin);
- flingControl.setHoverAlpha(.7f);
- piemenuControl.setHoverAlpha(.7f);
- flingControl.setClickAlpha(.4f);
- piemenuControl.setClickAlpha(.4f);
- int currentControl = game.preferences.getInteger(Constants.CONTROL_PREFERENCE, Constants.PIE_MENU_CONTROL);
- if (currentControl == Constants.PIE_MENU_CONTROL) {
- piemenuControl.setChecked(true);
- } else if (currentControl == Constants.FLING_CONTROL) {
- flingControl.setChecked(true);
- }
- flingControl.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- if (piemenuControl.isChecked()) {
- game.preferences.putInteger(Constants.CONTROL_PREFERENCE, Constants.FLING_CONTROL);
- game.preferences.flush();
- piemenuControl.toggle();
- } else {
- flingControl.toggle();
- }
+ ControlType[] controlTypes = ControlManager.CONTROL_TYPES;
+ int currentControl = game.preferences.getInteger(Preferences.CONTROL_PREFERENCE, 0);
+
+ Label controlSchemeLabel = new Label("Control scheme", game.skin, "themed");
+ table.add(controlSchemeLabel).colspan(controlTypes.length).padBottom(10f);
+ table.row();
+
+ final HoverImageButton[] controlButtons = new HoverImageButton[controlTypes.length];
+ final Label[] controlLabels = new Label[controlTypes.length];
+ for (int i = 0; i < controlTypes.length; i++) {
+ ControlType controlType = controlTypes[i];
+
+ Texture controlOffTexture = new Texture(Gdx.files.internal(controlType.controlOffTexturePath));
+ Texture controlOnTexture = new Texture(Gdx.files.internal(controlType.controlOnTexturePath));
+ usedTextures.add(controlOffTexture);
+ usedTextures.add(controlOnTexture);
+
+ Drawable controlOff = new TextureRegionDrawable(controlOffTexture);
+ Drawable controlOn = new TextureRegionDrawable(controlOnTexture);
+
+ controlButtons[i] = new HoverImageButton(controlOff, controlOn);
+ controlLabels[i] = new Label(controlType.controlName, game.skin);
+
+ controlButtons[i].setHoverAlpha(.7f);
+ controlButtons[i].setClickAlpha(.4f);
+
+ if (i == currentControl) {
+ controlButtons[i].setChecked(true);
}
- });
- piemenuControl.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- if (flingControl.isChecked()) {
- game.preferences.putInteger(Constants.CONTROL_PREFERENCE, Constants.PIE_MENU_CONTROL);
- game.preferences.flush();
- flingControl.toggle();
- } else {
- piemenuControl.toggle();
+
+ final int controlIndex = i;
+ controlButtons[i].addListener(new ClickListener() {
+ @Override
+ public void clicked(InputEvent event, float x, float y) {
+ int currentControl = game.preferences.getInteger(Preferences.CONTROL_PREFERENCE, 0);
+ if (controlButtons[currentControl].isChecked()) {
+ game.preferences.putInteger(Preferences.CONTROL_PREFERENCE, controlIndex);
+ game.preferences.flush();
+ controlButtons[currentControl].toggle();
+ } else {
+ controlButtons[controlIndex].toggle();
+ }
}
- }
- });
+ });
+ }
- table.add(controlLabel).colspan(2).padBottom(10f);
- table.row();
- table.add(piemenuControl).padLeft(5f);
- table.add(flingControl).padRight(5f);
+ for (HoverImageButton controlButton : controlButtons) {
+ table.add(controlButton).space(5f);
+ stage.addFocusableActor(controlButton);
+ }
table.row();
- table.add(piemenuControlLabel).padLeft(5f);
- table.add(flingControlLabel).padRight(5f);
+ stage.row();
+ for (Label controlLabel : controlLabels) {
+ table.add(controlLabel).space(5f);
+ }
table.row();
+
final HoverCheckBox showFPS = new HoverCheckBox("Show FPS counter", game.skin);
showFPS.getImageCell().width(showFPS.getLabel().getPrefHeight()).height(showFPS.getLabel().getPrefHeight());
showFPS.getImage().setScaling(Scaling.fill);
- showFPS.setChecked(game.preferences.getBoolean(Constants.FPS_PREFERENCE, false));
+ showFPS.setChecked(game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false));
showFPSCounter = showFPS.isChecked();
showFPS.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
- game.preferences.putBoolean(Constants.FPS_PREFERENCE, showFPS.isChecked());
+ game.preferences.putBoolean(Preferences.FPS_PREFERENCE, showFPS.isChecked());
game.preferences.flush();
showFPSCounter = showFPS.isChecked();
}
});
- table.add(showFPS).colspan(2).padTop(30f);
+ table.add(showFPS).colspan(controlTypes.length).padTop(30f);
+ table.row();
+
+ HoverCheckBox discordRPCSwitch = null;
+ if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
+ discordRPCSwitch = new HoverCheckBox("Enable Discord Rich Presence", game.skin);
+ discordRPCSwitch.getImageCell().width(discordRPCSwitch.getLabel().getPrefHeight()).height(discordRPCSwitch.getLabel().getPrefHeight());
+ discordRPCSwitch.getImage().setScaling(Scaling.fill);
+ discordRPCSwitch.setChecked(game.preferences.getBoolean(Preferences.DISCORD_RPC_PREFERENCE, true));
+ discordRPCSwitch.addListener(new ChangeListener() {
+ @Override
+ public void changed(ChangeEvent event, Actor actor) {
+ HoverCheckBox discordRPCSwitch = (HoverCheckBox) actor;
+ if (discordRPCSwitch.isChecked()) {
+ game.discordRPCManager.initRPC();
+ game.discordRPCManager.updateRPC("Configuring Settings");
+ } else {
+ game.discordRPCManager.shutdownRPC();
+ }
+
+ game.preferences.putBoolean(Preferences.DISCORD_RPC_PREFERENCE, discordRPCSwitch.isChecked());
+ game.preferences.flush();
+ }
+ });
+
+ table.add(discordRPCSwitch).colspan(controlTypes.length).padTop(30f);
+ }
masterTable.add(screenScrollPane).grow();
stage.addActor(masterTable);
- stage.addFocusableActor(piemenuControl);
- stage.addFocusableActor(flingControl);
- stage.row();
- stage.addFocusableActor(showFPS, 2);
+ stage.addFocusableActor(showFPS, controlTypes.length);
+ if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
+ stage.row();
+ stage.addFocusableActor(discordRPCSwitch, controlTypes.length);
+ }
stage.setScrollFocus(screenScrollPane);
}
diff --git a/core/src/com/cg/zoned/screens/TutorialScreen.java b/core/src/com/cg/zoned/screens/TutorialScreen.java
index c3b6dd4..95892c4 100644
--- a/core/src/com/cg/zoned/screens/TutorialScreen.java
+++ b/core/src/com/cg/zoned/screens/TutorialScreen.java
@@ -27,10 +27,13 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
+import com.cg.zoned.Assets;
import com.cg.zoned.Cell;
import com.cg.zoned.Constants;
import com.cg.zoned.Map;
import com.cg.zoned.Player;
+import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.ShapeDrawer;
import com.cg.zoned.TutorialItem;
import com.cg.zoned.UITextDisplayer;
@@ -76,7 +79,7 @@ public TutorialScreen(final Zoned game) {
this.viewport = new ScreenViewport();
this.stage = new FocusableStage(this.viewport);
this.animationManager = new AnimationManager(game, this);
- this.font = game.skin.getFont(Constants.FONT_MANAGER.SMALL.getName());
+ this.font = game.skin.getFont(Assets.FontManager.SMALL.getFontName());
this.batch = new SpriteBatch();
this.shapeDrawer = new ShapeDrawer(batch, usedTextures);
@@ -95,13 +98,13 @@ private void initMap() {
this.mapNoOverlayColor = new Color(0, 0, 0, 0f);
this.drawOverlay = true;
this.players = new Player[1];
- this.players[0] = new Player(Constants.PLAYER_COLORS.get("GREEN"), "Player");
+ this.players[0] = new Player(PlayerColorHelper.getColorFromString("GREEN"), "Player");
this.players[0].position = new Vector2(Math.round(this.mapGrid.length / 2f), Math.round(this.mapGrid[0].length / 2f));
this.players[0].setControlIndex(0);
- this.playerLabelFont = game.skin.getFont(Constants.FONT_MANAGER.PLAYER_LABEL.getName());
+ this.playerLabelFont = game.skin.getFont(Assets.FontManager.PLAYER_LABEL_NOSCALE.getFontName());
this.map.createPlayerLabelTextures(this.players, shapeDrawer, playerLabelFont);
this.controlManager = new ControlManager(players, stage);
- this.controlManager.setUpControls(game.preferences.getInteger(Constants.CONTROL_PREFERENCE),
+ this.controlManager.setUpControls(game.preferences.getInteger(Preferences.CONTROL_PREFERENCE, 0),
false, game.getScaleFactor(), usedTextures);
}
@@ -122,7 +125,7 @@ public void show() {
setUpStage();
setUpBackButton();
- showFPSCounter = game.preferences.getBoolean(Constants.FPS_PREFERENCE, false);
+ showFPSCounter = game.preferences.getBoolean(Preferences.FPS_PREFERENCE, false);
animationManager.fadeInStage(stage);
}
@@ -204,6 +207,11 @@ public void clicked(InputEvent event, float x, float y) {
players[0].position.x = Math.round(players[0].position.x);
players[0].position.y = Math.round(players[0].position.y);
+ if (mapGrid[(int) players[0].position.y][(int) players[0].position.x].cellColor == null) {
+ mapGrid[(int) players[0].position.y][(int) players[0].position.x].cellColor =
+ new Color(players[0].color.r, players[0].color.g, players[0].color.b, 0.1f);
+ }
+
if (tutorialPromptIndex[0] == tutorialPrompts.size) {
togglePlayerInterable(false);
animationManager.fadeOutStage(stage, TutorialScreen.this, new MainMenuScreen(game));
@@ -226,6 +234,7 @@ public void run() {
String mainText = tutorialPrompts.get(tutorialPromptIndex[0]).mainItem;
if (mainText.contains("Walls")) {
generateRandomWalls();
+ map.createMapTexture(shapeDrawer);
}
displayNextTutorialText(mainLabel, subLabel, mainText, tutorialPrompts.get(tutorialPromptIndex[0]).subItem);
diff --git a/core/src/com/cg/zoned/screens/VictoryScreen.java b/core/src/com/cg/zoned/screens/VictoryScreen.java
index 5b5ad79..387286b 100644
--- a/core/src/com/cg/zoned/screens/VictoryScreen.java
+++ b/core/src/com/cg/zoned/screens/VictoryScreen.java
@@ -6,30 +6,39 @@
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
+import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
+import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
+import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
-import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
+import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
+import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
+import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
+import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.Sort;
-import com.badlogic.gdx.utils.StringBuilder;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
-import com.cg.zoned.Constants;
+import com.cg.zoned.Assets;
import com.cg.zoned.PlayerColorHelper;
+import com.cg.zoned.Preferences;
import com.cg.zoned.TeamData;
import com.cg.zoned.UITextDisplayer;
import com.cg.zoned.Zoned;
import com.cg.zoned.managers.AnimationManager;
import com.cg.zoned.managers.PlayerManager;
+import com.cg.zoned.managers.UIButtonManager;
import com.cg.zoned.ui.FocusableStage;
+import com.cg.zoned.ui.HoverImageButton;
import java.text.DecimalFormat;
import java.util.Comparator;
@@ -48,28 +57,41 @@ public class VictoryScreen extends ScreenAdapter implements InputProcessor {
private ParticleEffect trailEffect;
private Array teamData;
- private String[] victoryStrings;
- private Table[] tableRows;
+ private Actor[][] scoreboardActors;
+ private Container