Commit 172bf6a6 authored by Drahomír Karchňák's avatar Drahomír Karchňák

Merge branch 'devel' into feature-ranksystem

Conflicts:
	core/external
	core/src/cz/nic/tablexia/screen/gamemenu/pages/GameMenuPage.java
parents f78af54d bf1042b9
......@@ -44,6 +44,7 @@ android {
res.srcDirs = ['res/main']
assets.srcDirs = ['assets']
java.srcDir file('src/main/java')
jniLibs.srcDirs = ['libs']
}
androidTest {
java.srcDir file('src/androidTest/java')
......@@ -156,11 +157,6 @@ tasks.whenTaskAdded { compileTask ->
}
}
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
......
......@@ -3,17 +3,16 @@ import com.badlogic.gdx.tools.texturepacker.TexturePacker
buildscript {
repositories {
//mavenCentral()
jcenter{
url "http://jcenter.bintray.com/"
}
// mavenCentral()
maven { url 'https://jitpack.io' }
jcenter{ url "http://jcenter.bintray.com/" }
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'org.robovm:robovm-gradle-plugin:1.2.0'
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
classpath 'de.felixschulze.gradle:gradle-spoon-plugin:2.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
classpath 'com.novoda:gradle-android-command-plugin:1.3.0'
classpath "com.badlogicgames.gdx:gdx-tools:1.6.1"
}
......@@ -56,13 +55,13 @@ allprojects {
applicationIdDevelSuffix = '.devel'
applicationIdDevel = applicationIdRelease + applicationIdDevelSuffix
gdxVersion = '1.6.1'
gdxUtilsVersion = '0.13.1'
gdxVersion = '1.9.2'
gdxUtilsVersion = '0.13.2'
mbassadorVersion = '1.2.0'
roboVMVersion = '1.7.0'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
aiVersion = '1.4.0'
roboVMVersion = '1.12.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.6.0'
aiVersion = '1.6.0'
sqlDroidVersion = '1.0.3'
sqlLiteJdbcVersion = '3.8.10.1'
guavaVersion = '18.0'
......
Subproject commit 9ea880cda3ffe8eb94b2b7d7bc26f8ab0f154e81
Subproject commit c2a4459f4accce0af85c5edd842da18112303b4d
......@@ -215,8 +215,10 @@ public abstract class TablexiaApplication implements ApplicationListener {
public void resize(int width, int height) {
if (lastScreen != null) lastScreen.resize(width, height);
if (screen != null) screen.resize(width, height);
stage.getViewport().update(width, height, true);
setScreenDimmerBounds();
if (stage != null) {
stage.getViewport().update(width, height, true);
setScreenDimmerBounds();
}
if (screenSizeUnderThreshold != ComponentScaleUtil.isUnderThreshold()) {
ApplicationBus.getInstance().publishAsync(new ScreenSizeThresholdChanged(ComponentScaleUtil.isUnderThreshold()));
......
......@@ -216,16 +216,16 @@ public class TablexiaSettings {
}
public void setGameDifficulty(GameDefinition gameDefinition, GameDifficulty gameDifficulty) {
preferences.putString(getGameDifficultyPreferncesKey(gameDefinition), gameDifficulty.name());
preferences.putString(getGameDifficultyPreferencesKey(gameDefinition), gameDifficulty.name());
preferences.flush();
}
public GameDifficulty getGameDifficulty(GameDefinition gameDefinition) {
return GameDifficulty.valueOf(GameDifficulty.class, preferences.getString(getGameDifficultyPreferncesKey(gameDefinition), GameDifficulty.DEFAULT_DIFFICULTY.name()));
return GameDifficulty.valueOf(GameDifficulty.class, preferences.getString(getGameDifficultyPreferencesKey(gameDefinition), GameDifficulty.DEFAULT_DIFFICULTY.name()));
}
private String getGameDifficultyPreferncesKey(GameDefinition gameDefinition) {
return "GAME_DIFFICULTY_" + gameDefinition.name();
private String getGameDifficultyPreferencesKey(GameDefinition gameDefinition) {
return "GAME_DIFFICULTY_" + gameDefinition.name() + "_" + getSelectedUser().getId();
}
public static Color getDefaultBackgroundColor() {
......
......@@ -18,6 +18,7 @@ import java.util.Map;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.TablexiaAbstractFileManager;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.model.UserDifficultySettingsDAO;
import cz.nic.tablexia.model.game.GameDAO;
import cz.nic.tablexia.model.game.GamePauseDAO;
import cz.nic.tablexia.model.screen.ScreenDAO;
......@@ -130,6 +131,7 @@ public class TablexiaStorage {
statement.execute(GamePauseDAO.CREATE_CONNECTION_TABLE);
statement.execute(SCREEN_STATE_CREATE_TABLE);
statement.execute(ScreenDAO.SCREEN_CREATE_TABLE);
statement.execute(UserDifficultySettingsDAO.CREATE_TABLE);
statement.close();
} catch (SQLException e) {
Log.err(getClass(), "Cannot init Tablexia tables!", e);
......
......@@ -10,8 +10,8 @@ import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.Timer;
import com.google.common.collect.ObjectArrays;
import java.util.Arrays;
......@@ -130,8 +130,8 @@ public class KidnappingGame extends AbstractTablexiaGame<GameState> {
screenResized(0, 0);
}
private void prepareRuleMessage() {
private void prepareRuleMessage() {
ruleMessage = new Group();
//Adds Backgrounds
......@@ -274,9 +274,8 @@ public class KidnappingGame extends AbstractTablexiaGame<GameState> {
final Direction[] directions = DirectionsHelper.getNextDirections(getData().getLastDirectionFrom());
final Arrow[] arrows = map.getDirectionArrow(position, directions);
for (final Arrow a : arrows) {
for (EventListener el : a.getListeners()) {
a.removeListener(el);
}
a.setDisabled(true);
a.clearListeners();
}
map.addAction(Actions.sequence(ReplayAlphaAction.fadeOut(), new PlayExample(actualSoundPack.getExample(this)), Actions.run(new Runnable() {
......
......@@ -21,6 +21,7 @@
package cz.nic.tablexia.game.games.kidnapping.actors;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
......@@ -31,7 +32,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Stack;
*/
public class Arrow extends Stack {
private Image normal, pressed;
private boolean disabled = false;
private boolean disabled = false;
private final Color COLOR_ENABLED = new Color(0x00AADEff);
private final Color COLOR_DISABLED = Color.GRAY;
public Arrow(TextureRegion arrow, TextureRegion arrowPressed) {
addActor(pressed = new Image(arrowPressed));
......@@ -44,13 +47,21 @@ public class Arrow extends Stack {
normal.setVisible(true);
}
public void setDisabled(boolean val) {
this.disabled = val;
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean val) {
if (!val) {
normal.setColor(COLOR_ENABLED);
pressed.setColor(COLOR_ENABLED);
} else {
normal.setColor(COLOR_DISABLED);
pressed.setColor(COLOR_DISABLED);
}
this.disabled = val;
}
public boolean isDisabled() {
return disabled;
}
@Override
public Actor hit(float x, float y, boolean touchable) {
......
......@@ -64,7 +64,7 @@ public class Map extends Group {
public void addTile(Position position, Tile tile) {
int baseX = getBaseX(position);
int baseY = getBaseY(position) + (tile.getTileType().getyOffset() / 2);
int baseY = getBaseY(position) + (tile.getTileType().getYOffset() / 2);
tile.setPosition(baseX, baseY);
tile.setPosition(position);
tileMap.put(position, tile);
......
......@@ -28,15 +28,15 @@ import cz.nic.tablexia.game.common.media.AssetDescription;
*/
public enum TextureTypes implements AssetDescription {
POSITION_CURRENT("zde-jsi"), //
POSITION_CURRENT("position-current"), //
OVERLAY("overlay"), //
EAR("ear"), //
PAPER("papir-pravidla"),
POSITION_LINE_NWSE("lineNWSE-2"), //
POSITION_LINE_NESW("lineNESW-2"), //
PAPER("rules-background"),
POSITION_LINE_NWSE("lineNWSE"), //
POSITION_LINE_NESW("lineNESW"), //
WRONG("spatne"), //
CORRECT("dobre"), //
WRONG("wrong"), //
CORRECT("correct"), //
POSITION_NEXT_NW("arrow-left-top-unpressed"), //
POSITION_NEXT_NE("arrow-right-top-unpressed"), //
......
......@@ -10,29 +10,29 @@ import cz.nic.tablexia.game.common.media.AssetDescription;
public enum TileType implements AssetDescription {
DOME1(1, 1, "domek1", 78), //
DOME2(1, 1, "domek2", 78), //
DOME3(1, 1, "domek3", 78), //
DOME4(1, 1, "domek4", 78), //
DOME5(1, 1, "domek5", 78), //
DOME6(1, 1, "domek6", 78), //
DOME7(1, 1, "domek7", 78), //
DOME8(1, 1, "domek8", 78), //
HRISTE(1, 1, "hriste", 78), //
HOUSE1(1, 1, "house1", 78), //
HOUSE2(1, 1, "house2", 78), //
HOUSE3(1, 1, "house3", 78), //
HOUSE4(1, 1, "house4", 78), //
HOUSE5(1, 1, "house5", 78), //
HOUSE6(1, 1, "house6", 78), //
HOUSE7(1, 1, "house7", 78), //
HOUSE8(1, 1, "house8", 78), //
PLAYGOUND(1, 1, "playground", 78), //
PARK(1, 1, "park", 78), //
POSTA(1, 1, "posta", 78), //
SKOLA(1, 1, "skola", 78), //
VILA1(1, 1, "vila1", 78), //
VILA2(1, 1, "vila2", 78), //
VILA3(1, 1, "vila3", 78), //
VILA4(1, 1, "vila4", 78); //
POST(1, 1, "post", 78), //
SCHOOL(1, 1, "school", 78), //
VILLA1(1, 1, "villa1", 78), //
VILLA2(1, 1, "villa2", 78), //
VILLA3(1, 1, "villa3", 78), //
VILLA4(1, 1, "villa4", 78); //
public static final String BASE_DIR = "tiles/";
private final int swSize, seSize;
private final String name;
private final int yOffset;
private TileType(int sw, int se, String name, int yOffset) {
TileType(int sw, int se, String name, int yOffset) {
this.swSize = sw;
this.seSize = se;
this.name = name;
......@@ -51,7 +51,7 @@ public enum TileType implements AssetDescription {
return BASE_DIR + name;
}
public int getyOffset() {
public int getYOffset() {
return yOffset;
}
......
......@@ -32,6 +32,8 @@ public class ApplicationInternalTextureManager extends TablexiaTextureManager {
public static final String BUTTON_DISABLED = BUTTON_PATH + "tablexiabutton_disabled" + NINE_PATCH_SUFFIX;
public static final String BUTTON_CLOSE_PRESSED = BUTTON_PATH + "closebutton_pressed" + PNG_SUFFIX;
public static final String BUTTON_CLOSE_UNPRESSED = BUTTON_PATH + "closebutton_unpressed" + PNG_SUFFIX;
public static final String BUTTON_YES_ICON = BUTTON_PATH + "yes_icon" + PNG_SUFFIX;
public static final String BUTTON_NO_ICON = BUTTON_PATH + "no_icon" + PNG_SUFFIX;
public enum InternalNinePatch {
......@@ -105,5 +107,7 @@ public class ApplicationInternalTextureManager extends TablexiaTextureManager {
loadTexture(BUTTON_BLUE_PRESSED);
loadTexture(BUTTON_CLOSE_PRESSED);
loadTexture(BUTTON_CLOSE_UNPRESSED);
loadTexture(BUTTON_YES_ICON);
loadTexture(BUTTON_NO_ICON);
}
}
......@@ -71,6 +71,7 @@ public class LocaleSelectBox extends AbstractTablexiaSelectBox<LocaleSelectBox.L
public LocaleSelectBox(float itemHeight) {
super(itemHeight);
ApplicationBus.getInstance().subscribe(this);
setCheckValidity(false);
prepareLocales();
}
......@@ -81,10 +82,12 @@ public class LocaleSelectBox extends AbstractTablexiaSelectBox<LocaleSelectBox.L
List<LocaleItem> localeItems = new ArrayList<LocaleItem>();
for (TablexiaSettings.LocaleDefinition localeDefinition: TablexiaSettings.LocaleDefinition.getEnabledLocaleDefinitions()) {
LocaleItem localeItem = new LocaleItem(localeDefinition);
localeItems.add(localeItem);
if (localeDefinition.equals(TablexiaSettings.getInstance().getLocaleDefinition())) {
selectedLocaleItem = localeItem;
}
else {
localeItems.add(localeItem);
}
}
setItems(localeItems.toArray(new LocaleItem[]{}));
if (selectedLocaleItem != null) {
......@@ -93,6 +96,13 @@ public class LocaleSelectBox extends AbstractTablexiaSelectBox<LocaleSelectBox.L
addCaptureListener(changeListener);
}
@Override
public boolean onSelectBoxItemSelected(LocaleItem item) {
getSelectBoxList().changeToSelected();
prepareLocales();
return true;
}
@Override
protected void drawSelectedItem(Batch batch, float parentAlpha, LocaleItem selected, float width, float height) {
selected.setBounds(getX(), getY(), width, height);
......
......@@ -69,6 +69,7 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
}
};
setCheckValidity(false);
prepareActiveUsers();
}
......@@ -78,14 +79,16 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
List<UserSelectBoxItem> userItems = new ArrayList<UserSelectBoxItem>();
for (User user: UserDAO.selectActiveUsers()) {
UserMenuSelectBoxItemGroup userItem = new UserMenuSelectBoxItemGroup(new UserMenuItem(user), getWidth());
userItems.add(userItem);
if (user.equals(TablexiaSettings.getInstance().getSelectedUser())) {
selectedUserItem = userItem;
//Show rank badge for currently logged user
userItem.setShowBadge(true);
}
else {
userItems.add(userItem);
}
}
userItems.add(new UserMenuNewSelectBoxItemGroup() {
UserMenuNewSelectBoxItemGroup newUserItem = new UserMenuNewSelectBoxItemGroup() {
@Override
public void performAction() {
TablexiaSettings.getInstance().changeUser(null, new TablexiaSettings.LogoutAcceptListener() {
......@@ -100,11 +103,16 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
public User getUser() {
return null;
}
});
};
userItems.add(newUserItem);
setItems(userItems.toArray(new UserSelectBoxItem[]{}));
if (selectedUserItem != null) {
setSelected(selectedUserItem);
}
else {
setSelected(newUserItem);
}
addCaptureListener(changeListener);
}
......
......@@ -20,6 +20,7 @@ import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GamePause;
import cz.nic.tablexia.shared.model.Screen;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.UserDifficultySettings;
import cz.nic.tablexia.util.Log;
/**
......@@ -265,6 +266,12 @@ public class UserDAO {
}
}
if (user.getDifficultySettings() != null) {
for (UserDifficultySettings setting : user.getDifficultySettings()) {
UserDifficultySettingsDAO.saveSettingsForUser(dbUser.getId(), setting.getGameNumber(), setting.getGameDifficulty());
}
}
TablexiaStorage.getInstance().commit();
TablexiaStorage.getInstance().setAutoCommit(true);
......
package cz.nic.tablexia.model;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.TablexiaStorage;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.UserDifficultySettings;
import cz.nic.tablexia.util.Log;
/**
* Created by frantisek on 24.3.16.
*/
public class UserDifficultySettingsDAO {
//////////////////////////// DB ACCESS
public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS user_difficulty_setting (user_id INTEGER NOT NULL, game_number INTEGER NOT NULL, difficulty_number INTEGER NOT NULL, FOREIGN KEY(user_id) REFERENCES user(id), PRIMARY KEY(user_id, game_number))";
public static final String SELECT_SETTINGS_FOR_USER = "SELECT game_number, difficulty_number FROM user_difficulty_setting WHERE user_id = ?";
public static final String SELECT_SETTINGS_FOR_USER_AND_GAME = "SELECT difficulty_number FROM user_difficulty_setting WHERE user_id = ? AND game_number = ?";
public static final String INSERT_SETTING_FOR_USER = "REPLACE INTO user_difficulty_setting(user_id, game_number, difficulty_number) VALUES (?, ?, ?)";
public static List<UserDifficultySettings> getUserSettings(long userId) {
ArrayList<UserDifficultySettings> settings = new ArrayList<UserDifficultySettings>();
try {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(SELECT_SETTINGS_FOR_USER);
statement.setLong(1, userId);
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
settings.add(new UserDifficultySettings(userId, resultSet.getInt("game_number"), resultSet.getInt("difficulty_number")));
}
resultSet.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select users game settings from DB!", e);
}
statement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select users game settings from DB!", e);
}
return settings;
}
public static GameDifficulty getUserSettingsByGame(long userId, int gameNumber) {
GameDifficulty difficulty = GameDifficulty.EASY;
try {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(SELECT_SETTINGS_FOR_USER_AND_GAME);
statement.setLong(1, userId);
statement.setInt(2, gameNumber);
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
difficulty = GameDifficulty.getGameDifficultyForDifficultyNumber(resultSet.getInt("difficulty_number"));
}
} catch (SQLException e) {
Log.err(User.class, "Cannot select users game settings from DB!", e);
}
statement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select users game settings from DB!", e);
}
return difficulty;
}
public static void saveSettingsForUser(long userId, int gameNumber, int difficultyNumber) {
try {
PreparedStatement insertStatement = TablexiaStorage.getInstance().prepareStatement(INSERT_SETTING_FOR_USER);
insertStatement.setLong(1, userId);
insertStatement.setInt(2, gameNumber);
insertStatement.setInt(3, difficultyNumber);
insertStatement.executeUpdate();
insertStatement.close();
} catch (SQLException ex) {
Log.err(UserDifficultySettingsDAO.class, "Cannot insert new user difficulty settings record into DB!", ex);
}
}
}
......@@ -35,6 +35,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
......@@ -104,6 +106,8 @@ public class FormScreen extends AbstractTablexiaScreen<Void> {
private static final int COMMON_INT_CODE_FOR_ENTER = 13;
private static final int ANDROID_INT_CODE_FOR_ENTER = 10;
private static final int TEXT_FIELD_HINT_DELAY = 5000;
public static final String GFX_PATH = "gfx/";
public static final String AVATAR_PATH = GFX_PATH + "avatar/";
public static final String HINT_FINGER_SOUND = "mfx/profil_podpis_prst.mp3";
......@@ -118,6 +122,8 @@ public class FormScreen extends AbstractTablexiaScreen<Void> {
protected Map<FormValidationEnum, Boolean> validations;
protected Set<String> alreadyPlayedHints;
private Group mugshots;
private Timer timer;
private boolean timerSet;
protected TextField nameField;
......@@ -197,12 +203,27 @@ public class FormScreen extends AbstractTablexiaScreen<Void> {
nameField.setFocusTraversal(false);
nameField.setMaxLength(MAX_NAME_LENGTH);
timerSet = false;
nameField.addListener(new InputListener() {
@Override
public boolean keyTyped(InputEvent event, char character) {
// have to check also (int)character because of some bug in iOS keyboard. It returns code Input.Keys.ENTER for every key after "done" button pressed
if(timerSet) timer.cancel();
// have to check also (int)character because of some bug in iOS keyboard. It returns code Input.Keys.ENTER for every key after "done" button pressed
if ((event.getKeyCode() == Input.Keys.ENTER && ((int)character == ANDROID_INT_CODE_FOR_ENTER || (int)character == COMMON_INT_CODE_FOR_ENTER)) || event.getKeyCode() == Input.Keys.TAB) {
validate();
} else {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {