v0.7.4: reworked the title scene

This commit is contained in:
Evan Debenham 2019-07-11 01:57:12 -04:00
parent 23048dc4d8
commit 79eb1b11df
12 changed files with 271 additions and 291 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -29,7 +29,9 @@ public class Chrome {
TOAST,
TOAST_TR,
WINDOW,
BUTTON,
RED_BUTTON,
GREY_BUTTON,
GREY_BUTTON_TR,
TAG,
GEM,
SCROLL,
@ -47,12 +49,16 @@ public class Chrome {
return new NinePatch( Asset, 22, 0, 18, 18, 5 );
case TOAST_TR:
return new NinePatch( Asset, 40, 0, 18, 18, 5 );
case BUTTON:
case RED_BUTTON:
return new NinePatch( Asset, 58, 0, 6, 6, 2 );
case GREY_BUTTON:
return new NinePatch( Asset, 58, 6, 6, 6, 2 );
case TAG:
return new NinePatch( Asset, 22, 18, 16, 14, 3 );
case GEM:
return new NinePatch( Asset, 0, 32, 32, 32, 13 );
case GREY_BUTTON_TR:
return new NinePatch( Asset, 53, 20, 9, 9, 5 );
case SCROLL:
return new NinePatch( Asset, 32, 32, 32, 32, 5, 11, 5, 11 );
case TAB_SET:

View File

@ -494,7 +494,7 @@ public class AlchemyScene extends PixelScene {
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.BUTTON );
bg = Chrome.get( Chrome.Type.RED_BUTTON);
add( bg );
slot = new ItemSlot() {

View File

@ -22,6 +22,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;
@ -29,20 +30,19 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites;
import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ChangesButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
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.windows.WndOptions;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.DeviceCompat;
public class TitleScene extends PixelScene {
@ -99,23 +99,7 @@ public class TitleScene extends PixelScene {
signs.y = title.y;
add( signs );
DashboardItem btnBadges = new DashboardItem( Messages.get(this, "badges"), 3 ) {
@Override
protected void onClick() {
ShatteredPixelDungeon.switchNoFade( BadgesScene.class );
}
};
add(btnBadges);
DashboardItem btnAbout = new DashboardItem( Messages.get(this, "about"), 1 ) {
@Override
protected void onClick() {
ShatteredPixelDungeon.switchNoFade( AboutScene.class );
}
};
add( btnAbout );
DashboardItem btnPlay = new DashboardItem( Messages.get(this, "play"), 0 ) {
TitleButton btnPlay = new TitleButton(Messages.get(this, "enter")){
@Override
protected void onClick() {
if (GamesInProgress.checkAll().size() == 0){
@ -135,40 +119,97 @@ public class TitleScene extends PixelScene {
return super.onLongClick();
}
};
btnPlay.icon(Icons.get(Icons.ENTER));
add(btnPlay);
DashboardItem btnRankings = new DashboardItem( Messages.get(this, "rankings"), 2 ) {
TitleButton btnSupport = new TitleButton(Messages.get(this, "support")){
@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);
}
};
btnSupport.icon(Icons.get(Icons.GOLD));
add(btnSupport);
TitleButton btnRankings = new TitleButton(Messages.get(this, "rankings")){
@Override
protected void onClick() {
ShatteredPixelDungeon.switchNoFade( RankingsScene.class );
}
};
btnRankings.icon(Icons.get(Icons.RANKINGS));
add(btnRankings);
TitleButton btnBadges = new TitleButton(Messages.get(this, "badges")){
@Override
protected void onClick() {
ShatteredPixelDungeon.switchNoFade( BadgesScene.class );
}
};
btnBadges.icon(Icons.get(Icons.BADGES));
add(btnBadges);
TitleButton btnChanges = new TitleButton(Messages.get(this, "changes")){
@Override
protected void onClick() {
ChangesScene.changesSelected = 0;
ShatteredPixelDungeon.switchNoFade( ChangesScene.class );
}
};
btnChanges.icon(Icons.get(Icons.CHANGES));
add(btnChanges);
TitleButton btnAbout = new TitleButton(Messages.get(this, "about")){
@Override
protected void onClick() {
ShatteredPixelDungeon.switchNoFade( AboutScene.class );
}
};
btnAbout.icon(Icons.get(Icons.SHPX));
add(btnAbout);
final int BTN_HEIGHT = 21;
int GAP = (int)(h - topRegion - (SPDSettings.landscape() ? 3 : 4)*BTN_HEIGHT)/3;
GAP /= SPDSettings.landscape() ? 3 : 4;
GAP = Math.max(GAP, 2);
if (SPDSettings.landscape()) {
btnRankings .setPos( w / 2 - btnRankings.width(), topRegion );
btnBadges .setPos( w / 2, topRegion );
btnPlay .setPos( btnRankings.left() - btnPlay.width(), topRegion );
btnAbout .setPos( btnBadges.right(), topRegion );
btnPlay.setRect(title.x-50, topRegion+GAP, ((title.width()+100)/2)-1, BTN_HEIGHT);
align(btnPlay);
btnSupport.setRect(btnPlay.right()+2, btnPlay.top(), btnPlay.width(), BTN_HEIGHT);
btnRankings.setRect(btnPlay.left() + (btnPlay.width()*.33f)+1, btnPlay.bottom()+ GAP, (btnPlay.width()*.67f)-1, BTN_HEIGHT);
btnBadges.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT);
btnChanges.setRect(btnRankings.left(), btnRankings.bottom() + GAP, btnRankings.width(), BTN_HEIGHT);
btnAbout.setRect(btnChanges.right()+2, btnChanges.top(), btnRankings.width(), BTN_HEIGHT);
} else {
btnPlay.setPos( w / 2 - btnPlay.width(), topRegion );
btnRankings.setPos( w / 2, btnPlay.top() );
btnBadges.setPos( w / 2 - btnBadges.width(), btnPlay.top() + DashboardItem.SIZE );
btnAbout.setPos( w / 2, btnBadges.top() );
btnPlay.setRect(title.x, topRegion+GAP, title.width(), BTN_HEIGHT);
align(btnPlay);
btnRankings.setRect(btnPlay.left(), btnPlay.bottom()+ GAP, (btnPlay.width()/2)-1, BTN_HEIGHT);
btnBadges.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT);
btnChanges.setRect(btnRankings.left(), btnRankings.bottom()+ GAP, btnRankings.width(), BTN_HEIGHT);
btnAbout.setRect(btnChanges.right()+2, btnChanges.top(), btnChanges.width(), BTN_HEIGHT);
btnSupport.setRect(btnPlay.left(), btnAbout.bottom()+ GAP, btnPlay.width(), BTN_HEIGHT);
}
BitmapText version = new BitmapText( "v " + Game.version + "", pixelFont);
BitmapText version = new BitmapText( "v" + Game.version, pixelFont);
version.measure();
version.hardlight( 0x888888 );
version.x = w - version.width() - 4;
version.y = h - version.height() - 2;
add( version );
Button changes = new ChangesButton();
changes.setPos( version.x + version.width() - changes.width(),
version.y - changes.height());
add( changes );
int pos = 2;
PrefsButton btnPrefs = new PrefsButton();
@ -194,57 +235,15 @@ public class TitleScene extends PixelScene {
add( fb );
}
private static class DashboardItem extends Button {
private static class TitleButton extends StyledButton {
public static final float SIZE = 48;
private static final int IMAGE_SIZE = 32;
private Image image;
private RenderedText label;
public DashboardItem( String text, int index ) {
super();
image.frame( image.texture.uvRect( index * IMAGE_SIZE, 0, (index + 1) * IMAGE_SIZE, IMAGE_SIZE ) );
this.label.text( text );
setSize( SIZE, SIZE );
public TitleButton( String label ){
this(label, 9);
}
@Override
protected void createChildren() {
super.createChildren();
image = new Image( Assets.DASHBOARD );
add( image );
label = renderText( 9 );
add( label );
public TitleButton( String label, int size ){
super(Chrome.Type.GREY_BUTTON_TR, label, size);
}
@Override
protected void layout() {
super.layout();
image.x = x + (width - image.width()) / 2;
image.y = y;
align(image);
label.x = x + (width - label.width()) / 2;
label.y = image.y + image.height() +2;
align(label);
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 1, 1, 0.8f );
}
@Override
protected void onTouchUp() {
image.resetColor();
}
}
}

View File

@ -1,74 +0,0 @@
/*
* 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.Assets;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.ChangesScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class ChangesButton extends Button {
protected Image image;
public ChangesButton() {
super();
width = image.width;
height = image.height;
}
@Override
protected void createChildren() {
super.createChildren();
image = Icons.NOTES.get();
add( image );
}
@Override
protected void layout() {
super.layout();
image.x = x;
image.y = y;
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
image.resetColor();
}
@Override
protected void onClick() {
ChangesScene.changesSelected = 0;
ShatteredPixelDungeon.switchNoFade(ChangesScene.class);
}
}

View File

@ -36,7 +36,6 @@ public enum Icons {
TARGET,
MASTERY,
WATA,
SHPX,
WARRIOR,
MAGE,
ROGUE,
@ -58,7 +57,13 @@ public enum Icons {
LANGS,
CHALLENGE_OFF,
CHALLENGE_ON,
RESUME;
RESUME,
ENTER,
GOLD,
RANKINGS,
BADGES,
CHANGES,
SHPX;
public Image get() {
return get( this );
@ -94,9 +99,6 @@ public enum Icons {
case WATA:
icon.frame( icon.texture.uvRect( 30, 16, 45, 26 ) );
break;
case SHPX:
icon.frame( icon.texture.uvRect( 64, 44, 80, 60 ) );
break;
case WARRIOR:
icon.frame( icon.texture.uvRect( 0, 29, 16, 45 ) );
break;
@ -148,11 +150,8 @@ public enum Icons {
case EXIT:
icon.frame( icon.texture.uvRect( 108, 0, 124, 16 ) );
break;
case NOTES:
icon.frame( icon.texture.uvRect( 79, 40, 94, 56 ) );
break;
case LANGS:
icon.frame( icon.texture.uvRect( 95, 42, 107, 51 ) );
icon.frame( icon.texture.uvRect( 109, 16, 121, 25 ) );
break;
case CHALLENGE_OFF:
icon.frame( icon.texture.uvRect( 78, 12, 92, 24 ) );
@ -163,6 +162,24 @@ public enum Icons {
case RESUME:
icon.frame( icon.texture.uvRect( 13, 53, 24, 64 ) );
break;
case ENTER:
icon.frame( icon.texture.uvRect( 66, 26, 83, 43 ) );
break;
case GOLD:
icon.frame( icon.texture.uvRect( 83, 26, 100, 42 ) );
break;
case RANKINGS:
icon.frame( icon.texture.uvRect( 100, 26, 117, 43 ) );
break;
case BADGES:
icon.frame( icon.texture.uvRect( 66, 46, 83, 63 ) );
break;
case CHANGES:
icon.frame( icon.texture.uvRect( 83, 47, 100, 62 ) );
break;
case SHPX:
icon.frame( icon.texture.uvRect( 100, 46, 116, 62 ) );
break;
}
return icon;
}

View File

@ -91,7 +91,7 @@ public abstract class OptionSlider extends Component {
protected void createChildren() {
super.createChildren();
add( BG = Chrome.get(Chrome.Type.BUTTON));
add( BG = Chrome.get(Chrome.Type.RED_BUTTON));
BG.alpha(0.5f);
add(title = PixelScene.renderText(9));
@ -99,7 +99,7 @@ public abstract class OptionSlider extends Component {
add(this.maxTxt = PixelScene.renderText(6));
add(sliderBG = new ColorBlock(1, 1, 0xFF222222));
sliderNode = Chrome.get(Chrome.Type.BUTTON);
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
sliderNode.size(5, 9);
touchArea = new TouchArea(0, 0, 0, 0){

View File

@ -21,131 +21,16 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class RedButton extends Button {
protected NinePatch bg;
protected RenderedText text;
protected Image icon;
public class RedButton extends StyledButton {
public RedButton( String label ) {
this(label, 9);
}
public RedButton( String label, int size ){
super();
text = PixelScene.renderText( size );
text.text( label );
add( text );
}
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.BUTTON );
add( bg );
}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
float componentWidth = 0;
if (icon != null) componentWidth += icon.width() + 2;
if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2;
text.x = x + (width() + componentWidth)/2f - text.width() - 1;
text.y = y + (height() - text.baseLine()) / 2f;
PixelScene.align(text);
}
if (icon != null) {
icon.x = x + (width() - componentWidth)/2f + 1;
icon.y = y + (height() - icon.height()) / 2f;
PixelScene.align(icon);
super( Chrome.Type.RED_BUTTON, label, size);
}
}
@Override
protected void onTouchDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
bg.resetColor();
}
public void enable( boolean value ) {
active = value;
text.alpha( value ? 1.0f : 0.3f );
}
public void text( String value ) {
text.text( value );
layout();
}
public void textColor( int value ) {
text.hardlight( value );
}
public void icon( Image icon ) {
if (this.icon != null) {
remove( this.icon );
}
this.icon = icon;
if (this.icon != null) {
add( this.icon );
layout();
}
}
public Image icon(){
return icon;
}
public float reqWidth() {
float reqWidth = 0;
if (icon != null){
reqWidth += icon.width() + 2;
}
if (text != null && !text.text().equals("")){
reqWidth += text.width() + 2;
}
return reqWidth;
}
public float reqHeight() {
float reqHeight = 0;
if (icon != null){
reqHeight = Math.max(icon.height() + 4, reqHeight);
}
if (text != null && !text.text().equals("")){
reqHeight = Math.max(text.baseLine() + 4, reqHeight);
}
return reqHeight;
}
}

View File

@ -0,0 +1,147 @@
/*
* 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.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
//simple button which support a background chrome, text, and an icon.
public class StyledButton extends Button {
protected NinePatch bg;
protected RenderedText text;
protected Image icon;
public StyledButton(Chrome.Type type, String label ) {
this(type, label, 9);
}
public StyledButton(Chrome.Type type, String label, int size ){
super();
bg = Chrome.get( type );
add( bg );
text = PixelScene.renderText( size );
text.text( label );
add( text );
}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
float componentWidth = 0;
if (icon != null) componentWidth += icon.width() + 2;
if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2;
text.x = x + (width() + componentWidth)/2f - text.width() - 1;
text.y = y + (height() - text.baseLine()) / 2f;
PixelScene.align(text);
}
if (icon != null) {
icon.x = x + (width() - componentWidth)/2f + 1;
icon.y = y + (height() - icon.height()) / 2f;
PixelScene.align(icon);
}
}
@Override
protected void onTouchDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
bg.resetColor();
}
public void enable( boolean value ) {
active = value;
text.alpha( value ? 1.0f : 0.3f );
}
public void text( String value ) {
text.text( value );
layout();
}
public void textColor( int value ) {
text.hardlight( value );
}
public void icon( Image icon ) {
if (this.icon != null) {
remove( this.icon );
}
this.icon = icon;
if (this.icon != null) {
add( this.icon );
layout();
}
}
public Image icon(){
return icon;
}
public float reqWidth() {
float reqWidth = 0;
if (icon != null){
reqWidth += icon.width() + 2;
}
if (text != null && !text.text().equals("")){
reqWidth += text.width() + 2;
}
return reqWidth;
}
public float reqHeight() {
float reqHeight = 0;
if (icon != null){
reqHeight = Math.max(icon.height() + 4, reqHeight);
}
if (text != null && !text.text().equals("")){
reqHeight = Math.max(text.baseLine() + 4, reqHeight);
}
return reqHeight;
}
}

View File

@ -130,7 +130,7 @@ public class WndBlacksmith extends Window {
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.BUTTON );
bg = Chrome.get( Chrome.Type.RED_BUTTON);
add( bg );
slot = new ItemSlot() {