v0.3.2: added a window class for a forced notification

This commit is contained in:
Evan Debenham 2015-11-03 22:03:13 -05:00
parent 6cc42aa0fa
commit ca4f25fe49
2 changed files with 67 additions and 14 deletions

View File

@ -0,0 +1,56 @@
package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
//a notification window that the player can't get rid of quickly, good for forcibly telling a message
//USE THIS SPARINGLY
public class WndHardNotification extends WndTitledMessage{
RedButton btnOkay;
private double timeLeft;
public WndHardNotification( Image icon, String title, String message, int time) {
this(new IconTitle(icon, title), message, time);
}
public WndHardNotification(Component titlebar, String message, int time) {
super(titlebar, message);
timeLeft = time;
btnOkay = new RedButton("Okay (" + time +")"){
@Override
protected void onClick() {
hide();
}
};
btnOkay.setRect(0, height + GAP, width, 16);
btnOkay.enable(false);
add(btnOkay);
resize(width, (int) btnOkay.bottom());
}
@Override
public void update() {
super.update();
timeLeft -= Game.elapsed;
if (timeLeft <= 0 ){
btnOkay.enable(true);
btnOkay.text("Okay");
} else {
btnOkay.text("Okay (" + (int)Math.ceil(timeLeft) + ")");
}
}
@Override
public void onBackPressed() {
if (timeLeft <= 0 ) super.onBackPressed();
}
}

View File

@ -29,13 +29,10 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndTitledMessage extends Window {
private static final int WIDTH_P = 120;
private static final int WIDTH_L = 144;
private static final int GAP = 2;
private BitmapTextMultiline normal;
private BitmapTextMultiline highlighted;
protected static final int WIDTH_P = 120;
protected static final int WIDTH_L = 144;
protected static final int GAP = 2;
public WndTitledMessage( Image icon, String title, String message ) {
this( new IconTitle( icon, title ), message );
@ -52,26 +49,26 @@ public class WndTitledMessage extends Window {
add( titlebar );
Highlighter hl = new Highlighter( message );
normal = PixelScene.createMultiline( hl.text, 6 );
BitmapTextMultiline normal = PixelScene.createMultiline(hl.text, 6);
normal.maxWidth = width;
normal.measure();
normal.x = titlebar.left();
normal.y = titlebar.bottom() + GAP;
add( normal );
add(normal);
if (hl.isHighlighted()) {
normal.mask = hl.inverted();
highlighted = PixelScene.createMultiline( hl.text, 6 );
BitmapTextMultiline highlighted = PixelScene.createMultiline(hl.text, 6);
highlighted.maxWidth = normal.maxWidth;
highlighted.measure();
highlighted.x = normal.x;
highlighted.y = normal.y;
add( highlighted );
add(highlighted);
highlighted.mask = hl.mask;
highlighted.hardlight( TITLE_COLOR );
highlighted.hardlight(TITLE_COLOR);
}
resize( width, (int)(normal.y + normal.height()) );