diff --git a/core/src/main/assets/interfaces/icons.png b/core/src/main/assets/interfaces/icons.png index 23990dd6c..c0f143dbf 100644 Binary files a/core/src/main/assets/interfaces/icons.png and b/core/src/main/assets/interfaces/icons.png differ diff --git a/core/src/main/assets/messages/windows/windows.properties b/core/src/main/assets/messages/windows/windows.properties index 1fa9f8320..c32843c52 100644 --- a/core/src/main/assets/messages/windows/windows.properties +++ b/core/src/main/assets/messages/windows/windows.properties @@ -171,6 +171,9 @@ windows.wndsettings$langstab.transifex=All translation provided by volunteers th windows.wndsettings$langstab.credits=credits windows.wndsettings$langstab.reviewers=reviewers windows.wndsettings$langstab.translators=translators +windows.wndsettings$datatab.news=Check for news +windows.wndsettings$datatab.updates=Check for updates +windows.wndsettings$datatab.wifi=Only check on WiFi windows.wndstartgame.title=Choose Your Hero windows.wndstartgame.huntress_unlock=Defeat the boss on floor 15 to unlock this character diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java index f1caa85dd..cf53e154a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java @@ -253,6 +253,36 @@ public class SPDSettings extends GameSettings { return getBoolean(KEY_SYSTEMFONT, (language() == Languages.KOREAN || language() == Languages.CHINESE || language() == Languages.JAPANESE)); } + + //Connectivity + + public static final String KEY_NEWS = "news"; + public static final String KEY_UPDATES = "updates"; + public static final String KEY_WIFI = "wifi"; + + public static void news(boolean value){ + put(KEY_NEWS, value); + } + + public static boolean news(){ + return getBoolean(KEY_NEWS, true); + } + + public static void updates(boolean value){ + put(KEY_UPDATES, value); + } + + public static boolean updates(){ + return getBoolean(KEY_UPDATES, true); + } + + public static void WiFi(boolean value){ + put(KEY_WIFI, value); + } + + public static boolean WiFi(){ + return getBoolean(KEY_WIFI, true); + } //Window management (desktop only atm) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java index 87b64e714..cb551d68b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java @@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; +import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites; import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball; @@ -241,7 +242,7 @@ public class TitleScene extends PixelScene { public ChangesButton( Chrome.Type type, String label ){ super(type, label); - Updates.checkForUpdate(); + if (SPDSettings.updates()) Updates.checkForUpdate(); } boolean updateShown = false; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/News.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/News.java index 748cbd6b9..7f632ac30 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/News.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/News.java @@ -39,7 +39,7 @@ public class News { if (!supportsNews()) return; if (lastCheck != null && (new Date().getTime() - lastCheck.getTime()) < CHECK_DELAY) return; - service.checkForArticles(new NewsService.NewsResultCallback() { + service.checkForArticles(false, new NewsService.NewsResultCallback() { @Override public void onArticlesFound(ArrayList articles) { lastCheck = new Date(); @@ -73,6 +73,9 @@ public class News { return unread; } - + public static void clearArticles(){ + articles = null; + lastCheck = null; + } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/Updates.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/Updates.java index 4eca65071..8fbc85f58 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/Updates.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/Updates.java @@ -21,6 +21,8 @@ package com.shatteredpixel.shatteredpixeldungeon.services.updates; +import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; + import java.util.Date; public class Updates { @@ -38,7 +40,7 @@ public class Updates { if (!supportsUpdates()) return; if (lastCheck != null && (new Date().getTime() - lastCheck.getTime()) < CHECK_DELAY) return; - service.checkForUpdate(new UpdateService.UpdateResultCallback() { + service.checkForUpdate(!SPDSettings.WiFi(), new UpdateService.UpdateResultCallback() { @Override public void onUpdateAvailable(AvailableUpdateData update) { lastCheck = new Date(); @@ -71,4 +73,9 @@ public class Updates { return updateData; } + public static void clearUpdate(){ + updateData = null; + lastCheck = null; + } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java index b03e4aeef..2d20d2d55 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java @@ -40,7 +40,7 @@ public enum Icons { CLOSE, ARROW, DISPLAY, - //TODO UI, + DATA, AUDIO, //ingame UI icons @@ -125,10 +125,12 @@ public enum Icons { icon.frame( icon.texture.uvRect( 32, 16, 45, 32 ) ); break; //TODO UI icon? - case AUDIO: - icon.frame( icon.texture.uvRect( 64, 16, 77, 28 ) ); + case DATA: + icon.frame( icon.texture.uvRect( 48, 16, 64, 31 ) ); + break; + case AUDIO: + icon.frame( icon.texture.uvRect( 64, 16, 78, 30 ) ); break; - case SKULL: icon.frame( icon.texture.uvRect( 0, 32, 8, 40 ) ); break; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java index 8ac53b344..ec3b6bc1d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java @@ -45,7 +45,8 @@ public class Window extends Group implements Signal.Listener { protected PointerArea blocker; protected ShadowBox shadow; protected NinePatch chrome; - + + public static final int WHITE = 0xFFFFFF; public static final int TITLE_COLOR = 0xFFFF44; public static final int SHPX_COLOR = 0x33BB33; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index ea6389762..1703b0413 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -29,6 +29,8 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Languages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.shatteredpixel.shatteredpixeldungeon.services.news.News; +import com.shatteredpixel.shatteredpixeldungeon.services.updates.Updates; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.ui.CheckBox; import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog; @@ -64,6 +66,7 @@ public class WndSettings extends WndTabbed { private UITab ui; private AudioTab audio; private LangsTab langs; + private DataTab data; public static int last_index = 0; @@ -145,6 +148,20 @@ public class WndSettings extends WndTabbed { }); + data = new DataTab(); + data.setSize(width, 0); + height = Math.max(height, data.height()); + add( data ); + + add( new IconTab(Icons.get(Icons.DATA)){ + @Override + protected void select(boolean value) { + super.select(value); + data.visible = data.active = value; + if (value) last_index = 4; + } + }); + resize(width, (int)Math.ceil(height)); layoutTabs(); @@ -169,7 +186,7 @@ public class WndSettings extends WndTabbed { }); } - private class DisplayTab extends Component { + private static class DisplayTab extends Component { OptionSlider optScale; CheckBox chkSaver; @@ -300,7 +317,7 @@ public class WndSettings extends WndTabbed { } - private class UITab extends Component { + private static class UITab extends Component { RenderedTextBlock barDesc; RedButton btnSplit; RedButton btnGrouped; RedButton btnCentered; @@ -320,28 +337,40 @@ public class WndSettings extends WndTabbed { btnSplit = new RedButton(Messages.get(this, "split")){ @Override protected void onClick() { + textColor(TITLE_COLOR); + btnGrouped.textColor(WHITE); + btnCentered.textColor(WHITE); SPDSettings.toolbarMode(Toolbar.Mode.SPLIT.name()); Toolbar.updateLayout(); } }; + if (SPDSettings.toolbarMode().equals(Toolbar.Mode.SPLIT.name())) btnSplit.textColor(TITLE_COLOR); add(btnSplit); btnGrouped = new RedButton(Messages.get(this, "group")){ @Override protected void onClick() { + btnSplit.textColor(WHITE); + textColor(TITLE_COLOR); + btnCentered.textColor(WHITE); SPDSettings.toolbarMode(Toolbar.Mode.GROUP.name()); Toolbar.updateLayout(); } }; + if (SPDSettings.toolbarMode().equals(Toolbar.Mode.GROUP.name())) btnGrouped.textColor(TITLE_COLOR); add(btnGrouped); btnCentered = new RedButton(Messages.get(this, "center")){ @Override protected void onClick() { + btnSplit.textColor(WHITE); + btnGrouped.textColor(WHITE); + textColor(TITLE_COLOR); SPDSettings.toolbarMode(Toolbar.Mode.CENTER.name()); Toolbar.updateLayout(); } }; + if (SPDSettings.toolbarMode().equals(Toolbar.Mode.CENTER.name())) btnCentered.textColor(TITLE_COLOR); add(btnCentered); chkFlipToolbar = new CheckBox(Messages.get(this, "flip_toolbar")){ @@ -445,7 +474,7 @@ public class WndSettings extends WndTabbed { } - private class AudioTab extends Component { + private static class AudioTab extends Component { OptionSlider optMusic; CheckBox chkMusicMute; @@ -518,7 +547,7 @@ public class WndSettings extends WndTabbed { } - private class LangsTab extends Component{ + private static class LangsTab extends Component{ final static int COLS_P = 3; final static int COLS_L = 4; @@ -735,4 +764,68 @@ public class WndSettings extends WndTabbed { } } + + private static class DataTab extends Component{ + + CheckBox chkNews; + CheckBox chkUpdates; + CheckBox chkWifi; + + @Override + protected void createChildren() { + chkNews = new CheckBox(Messages.get(this, "news")){ + @Override + protected void onClick() { + super.onClick(); + SPDSettings.news(checked()); + News.clearArticles(); + } + }; + chkNews.checked(SPDSettings.news()); + add(chkNews); + + chkUpdates = new CheckBox(Messages.get(this, "updates")){ + @Override + protected void onClick() { + super.onClick(); + SPDSettings.updates(checked()); + Updates.clearUpdate(); + } + }; + chkUpdates.checked(SPDSettings.updates()); + add(chkUpdates); + + if (!DeviceCompat.isDesktop()){ + chkWifi = new CheckBox(Messages.get(this, "wifi")){ + @Override + protected void onClick() { + super.onClick(); + SPDSettings.WiFi(checked()); + } + }; + chkWifi.checked(SPDSettings.WiFi()); + add(chkWifi); + } + } + + @Override + protected void layout() { + if (width > 200){ + chkNews.setRect(0, 0, width/2-1, BTN_HEIGHT); + chkUpdates.setRect(chkNews.right() + GAP_TINY, chkNews.top(), width/2-1, BTN_HEIGHT); + } else { + chkNews.setRect(0, 0, width, BTN_HEIGHT); + chkUpdates.setRect(0, chkNews.bottom()+GAP_TINY, width, BTN_HEIGHT); + } + + float pos = chkUpdates.bottom(); + if (chkWifi != null){ + chkWifi.setRect(0, pos + GAP_TINY, width, BTN_HEIGHT); + pos = chkWifi.bottom(); + } + + height = pos; + + } + } } diff --git a/services/news/debugNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/DebugNews.java b/services/news/debugNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/DebugNews.java index 3b6dcd3ac..a0a3964ee 100644 --- a/services/news/debugNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/DebugNews.java +++ b/services/news/debugNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/DebugNews.java @@ -21,14 +21,19 @@ package com.shatteredpixel.shatteredpixeldungeon.services.news; +import com.watabou.noosa.Game; + import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; public class DebugNews extends NewsService { @Override - public void checkForArticles(NewsResultCallback callback) { + public void checkForArticles(boolean useMetered, NewsResultCallback callback) { + + if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){ + callback.onConnectionFailed(); + } //turn on to test connection failure if (false){ diff --git a/services/news/shatteredNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/ShatteredNews.java b/services/news/shatteredNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/ShatteredNews.java index 69fa86470..4fc00dd6a 100644 --- a/services/news/shatteredNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/ShatteredNews.java +++ b/services/news/shatteredNews/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/ShatteredNews.java @@ -34,9 +34,9 @@ import java.util.Locale; public class ShatteredNews extends NewsService { @Override - public void checkForArticles(NewsResultCallback callback) { + public void checkForArticles(boolean useMetered, NewsResultCallback callback) { - if (!Game.platform.connectedToUnmeteredNetwork()){ + if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){ callback.onConnectionFailed(); } diff --git a/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsService.java b/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsService.java index e950e40ae..a2df6060c 100644 --- a/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsService.java +++ b/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/news/NewsService.java @@ -30,6 +30,6 @@ public abstract class NewsService { public abstract void onConnectionFailed(); } - public abstract void checkForArticles( NewsResultCallback callback ); + public abstract void checkForArticles(boolean useMetered, NewsResultCallback callback); } diff --git a/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/UpdateService.java b/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/UpdateService.java index a7f01d2c8..d6afd7a97 100644 --- a/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/UpdateService.java +++ b/services/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/UpdateService.java @@ -29,7 +29,7 @@ public abstract class UpdateService { public abstract void onConnectionFailed(); } - public abstract void checkForUpdate( UpdateResultCallback callback ); + public abstract void checkForUpdate( boolean useMetered, UpdateResultCallback callback ); public abstract void initializeUpdate( AvailableUpdateData update ); diff --git a/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java b/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java index 0c0c5889c..2937453ae 100644 --- a/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java +++ b/services/updates/debugUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/DebugUpdates.java @@ -30,7 +30,12 @@ public class DebugUpdates extends UpdateService { private static AvailableUpdateData debugUpdateInfo; @Override - public void checkForUpdate(UpdateResultCallback callback) { + public void checkForUpdate(boolean useMetered, UpdateResultCallback callback) { + + if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){ + callback.onConnectionFailed(); + return; + } //turn on to test update UI if (false){ diff --git a/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java b/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java index c601fc01d..64a4d4498 100644 --- a/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java +++ b/services/updates/githubUpdates/src/main/java/com/shatteredpixel/shatteredpixeldungeon/services/updates/GitHubUpdates.java @@ -27,6 +27,7 @@ import com.badlogic.gdx.Net; import com.watabou.noosa.Game; import com.watabou.utils.Bundle; import com.watabou.utils.DeviceCompat; +import com.watabou.utils.GameSettings; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -39,9 +40,9 @@ public class GitHubUpdates extends UpdateService { private static Pattern versionCodePattern = Pattern.compile("internal version number: ([0-9]*)", Pattern.CASE_INSENSITIVE); @Override - public void checkForUpdate(UpdateResultCallback callback) { + public void checkForUpdate(boolean useMetered, UpdateResultCallback callback) { - if (!Game.platform.connectedToUnmeteredNetwork()){ + if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){ callback.onConnectionFailed(); return; }