v0.8.0: added an update notification service

This commit is contained in:
Evan Debenham
2019-11-22 15:05:47 -05:00
parent 2e533b74db
commit 2138ad24ec
24 changed files with 606 additions and 13 deletions
@@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.LanguageButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.PrefsButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.UpdateNotification;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame;
import com.watabou.glwrap.Blending;
@@ -225,6 +226,10 @@ public class TitleScene extends PixelScene {
btnExit.setPos( w - btnExit.width(), 0 );
add( btnExit );
UpdateNotification updInfo = new UpdateNotification();
updInfo.setRect(4, h-BTN_HEIGHT, updInfo.reqWidth() + 6, BTN_HEIGHT-4);
add(updInfo);
fadeIn();
}
@@ -0,0 +1,69 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.services.updates;
public class Updates {
public static UpdateService service;
public static boolean supportsUpdates(){
return service != null;
}
private static boolean updateChecked = false;
public static void checkForUpdate(){
if (!supportsUpdates() || updateChecked) return;
service.checkForUpdate(new UpdateService.UpdateResultCallback() {
@Override
public void onUpdateAvailable(AvailableUpdateData update) {
updateChecked = true;
updateData = update;
}
@Override
public void onNoUpdateFound() {
updateChecked = true;
}
@Override
public void onConnectionFailed() {
updateChecked = false;
}
});
}
public static void launchUpdate( AvailableUpdateData data ){
service.initializeUpdate( data );
}
private static AvailableUpdateData updateData = null;
public static boolean updateAvailable(){
return updateData != null;
}
public static AvailableUpdateData updateData(){
return updateData;
}
}
@@ -0,0 +1,79 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.services.updates.AvailableUpdateData;
import com.shatteredpixel.shatteredpixeldungeon.services.updates.Updates;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.Game;
public class UpdateNotification extends StyledButton {
private static AvailableUpdateData update;
public UpdateNotification(){
super( Chrome.Type.GREY_BUTTON_TR, Messages.get(UpdateNotification.class, "title") );
textColor( Window.SHPX_COLOR );
visible = false;
Updates.checkForUpdate();
}
@Override
public void update() {
super.update();
if (Updates.updateAvailable()){
bg.alpha((float) (0.7f + Math.sin(Game.timeTotal*2)*0.3f));
text.alpha((float) (0.7f + Math.sin(Game.timeTotal*2)*0.3f));
visible = true;
} else {
visible = false;
}
}
@Override
protected void onClick() {
update = Updates.updateData();
ShatteredPixelDungeon.scene().addToFront( new WndUpdate() );
}
public static class WndUpdate extends WndOptions {
public WndUpdate(){
super(
update.versionName == null ? Messages.get(WndUpdate.class,"title") : Messages.get(WndUpdate.class,"versioned_title", update.versionName),
update.desc == null ? Messages.get(WndUpdate.class,"desc") : update.desc,
Messages.get(WndUpdate.class,"button"));
}
@Override
protected void onSelect(int index) {
if (index == 0) {
Updates.launchUpdate(update);
}
}
}
}
@@ -1,3 +1,9 @@
ui.quickslotbutton.select_item=Quickslot an item
ui.toolbar.examine_prompt=Press again to search\nPress a tile to examine
ui.updatenotification.title=Update
ui.updatenotification$wndupdate.title=An Update is Available!
ui.updatenotification$wndupdate.versioned_title=Update Available: %s
ui.updatenotification$wndupdate.desc=Shattered Pixel Dungeon is regularly updated with overhauls to existing game content, or entirely new content!\n\nGame balance is also frequently improved in game updates, so that specific items/heroes/enemies aren't too strong or too weak.\n\nUpdates also include fixes for bugs and other various stability improvements.
ui.updatenotification$wndupdate.button=Go To Update Page