From 4950e49a9ac1ad283e00782be4a8a3883bdbcdd6 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 24 Jul 2020 15:49:03 -0400 Subject: [PATCH] v0.8.2: moved supporter window into its own scene --- .../assets/messages/scenes/scenes.properties | 5 + .../scenes/SupporterScene.java | 128 ++++++++++++++++++ .../scenes/TitleScene.java | 14 +- 3 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/SupporterScene.java diff --git a/core/src/main/assets/messages/scenes/scenes.properties b/core/src/main/assets/messages/scenes/scenes.properties index 14bbc26cc..99cb6f9eb 100644 --- a/core/src/main/assets/messages/scenes/scenes.properties +++ b/core/src/main/assets/messages/scenes/scenes.properties @@ -64,6 +64,11 @@ scenes.rankingsscene.no_info=No additional information scenes.startscene.title=Games in Progress scenes.startscene.new=New Game +scenes.supporterscene.title=Support the Game +scenes.supporterscene.supporter_link=Go to Patreon +scenes.supporterscene$supportermessage.patreon=Shattered Pixel Dungeon is a completely free game, which means that I depend on support from generous players in order to keep making it.\n\nIf you're interested in supporting me, the best way to do so is through Patreon. Patreon gives me a consistent income source, and allows me to give something back to those who support me!\n\nPatrons get exclusive blog posts every week which let them know about what I'm working on before anyone else!\n\nYou can take a look at my Patreon page for the most up to date information about benefits, Thank you for your consideration! +scenes.supporterscene$supportermessage.patreon_english=Note that Patreon rewards are only available in English. + scenes.surfacescene.exit=Game Over scenes.titlescene.play=Play diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/SupporterScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/SupporterScene.java new file mode 100644 index 000000000..6ece62b9f --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/SupporterScene.java @@ -0,0 +1,128 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2020 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 + */ + +package com.shatteredpixel.shatteredpixeldungeon.scenes; + +import com.shatteredpixel.shatteredpixeldungeon.Chrome; +import com.shatteredpixel.shatteredpixeldungeon.messages.Languages; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; +import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; +import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; +import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton; +import com.shatteredpixel.shatteredpixeldungeon.ui.Window; +import com.watabou.noosa.Camera; +import com.watabou.noosa.NinePatch; +import com.watabou.noosa.ui.Component; + +public class SupporterScene extends PixelScene { + + @Override + public void create() { + super.create(); + + uiCamera.visible = false; + + int w = Camera.main.width; + int h = Camera.main.height; + + int elementWidth = PixelScene.landscape() ? 200 : 120; + + Archs archs = new Archs(); + archs.setSize(w, h); + add(archs); + + ExitButton btnExit = new ExitButton(); + btnExit.setPos(w - btnExit.width(), 0); + add(btnExit); + + RenderedTextBlock title = PixelScene.renderTextBlock(Messages.get(this, "title"), 9); + title.hardlight(Window.TITLE_COLOR); + title.setPos( + (w - title.width()) / 2f, + (20 - title.height()) / 2f + ); + align(title); + add(title); + + SupporterMessage msg = new SupporterMessage(); + msg.setSize(elementWidth, 0); + add(msg); + + StyledButton link = new StyledButton(Chrome.Type.GREY_BUTTON_TR, Messages.get(this, "supporter_link")); + link.icon(Icons.get(Icons.GOLD)); + link.textColor(Window.TITLE_COLOR); + link.setSize(elementWidth, 20); + add(link); + + float elementHeight = msg.height() + link.height() + 2; + + float top = 16 + (h - 16 - elementHeight)/2f; + float left = (w-elementWidth)/2f; + + msg.setPos(left, top); + align(msg); + + link.setPos(left, msg.bottom()+2); + align(link); + + } + + private static class SupporterMessage extends Component { + + NinePatch bg; + RenderedTextBlock text; + + @Override + protected void createChildren() { + bg = Chrome.get(Chrome.Type.GREY_BUTTON_TR); + add(bg); + + String message = Messages.get(this, "patreon"); + if (Messages.lang() != Languages.ENGLISH){ + message += "\n\n" + Messages.get(this, "patreon_english"); + } + + text = PixelScene.renderTextBlock(message, 6); + add(text); + + } + + @Override + protected void layout() { + bg.x = x; + bg.y = y; + + text.maxWidth((int)width - bg.marginHor()); + text.setPos(x + bg.marginLeft(), y + bg.marginTop()); + + height = (text.bottom()) - y; + + height += bg.marginBottom(); + + bg.size(width, height); + + } + + } + +} 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 e01244867..3863c0d28 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java @@ -338,19 +338,7 @@ public class TitleScene extends PixelScene { @Override protected void onClick() { - WndOptions wnd = new WndOptions(Messages.get(TitleScene.class, "support"), - Messages.get(TitleScene.class, "patreon_body"), - Messages.get(TitleScene.class, "patreon_button")){ - @Override - protected void onSelect(int index) { - if (index == 0){ - DeviceCompat.openURI("https://www.patreon.com/ShatteredPixel"); - } else { - hide(); - } - } - }; - parent.add(wnd); + ShatteredPixelDungeon.switchNoFade(SupporterScene.class); } } }