v0.3.1: implemented a new toolbar UI including more minimum resolution width, options for up to 4 quickslots, and ui flip support.

This commit is contained in:
Evan Debenham 2015-06-25 00:00:37 -04:00 committed by Evan Debenham
parent 107033eb62
commit 179935fb87
6 changed files with 149 additions and 87 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -37,6 +37,7 @@ enum Preferences {
public static final String KEY_LAST_CLASS = "last_class"; public static final String KEY_LAST_CLASS = "last_class";
public static final String KEY_CHALLENGES = "challenges"; public static final String KEY_CHALLENGES = "challenges";
public static final String KEY_QUICKSLOTS = "quickslots"; public static final String KEY_QUICKSLOTS = "quickslots";
public static final String KEY_FLIPPEDUI = "flipped_ui";
public static final String KEY_INTRO = "intro"; public static final String KEY_INTRO = "intro";
public static final String KEY_BRIGHTNESS = "brightness"; public static final String KEY_BRIGHTNESS = "brightness";
public static final String KEY_VERSION = "version"; public static final String KEY_VERSION = "version";

View File

@ -320,6 +320,11 @@ public class ShatteredPixelDungeon extends Game {
public static int quickSlots(){ return Preferences.INSTANCE.getInt( Preferences.KEY_QUICKSLOTS, 1); } public static int quickSlots(){ return Preferences.INSTANCE.getInt( Preferences.KEY_QUICKSLOTS, 1); }
public static void flippedUI( boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_FLIPPEDUI, value ); }
public static boolean flippedUI(){ return Preferences.INSTANCE.getBoolean(Preferences.KEY_FLIPPEDUI, false); }
public static void intro( boolean value ) { public static void intro( boolean value ) {
Preferences.INSTANCE.put( Preferences.KEY_INTRO, value ); Preferences.INSTANCE.put( Preferences.KEY_INTRO, value );
} }

View File

@ -42,7 +42,7 @@ import com.watabou.utils.BitmapCache;
public class PixelScene extends Scene { public class PixelScene extends Scene {
// Minimum virtual display size for portrait orientation // Minimum virtual display size for portrait orientation
public static final float MIN_WIDTH_P = 128; public static final float MIN_WIDTH_P = 144;
public static final float MIN_HEIGHT_P = 224; public static final float MIN_HEIGHT_P = 224;
// Minimum virtual display size for landscape orientation // Minimum virtual display size for landscape orientation

View File

@ -54,22 +54,22 @@ public class Toolbar extends Component {
private Tool btnWait; private Tool btnWait;
private Tool btnSearch; private Tool btnSearch;
private Tool btnInfo;
private Tool btnResume;
private Tool btnInventory; private Tool btnInventory;
private Tool btnQuick; private Tool[] btnQuick;
private Tool btnQuick2;
public static int QuickSlots; public static int slots;
public static boolean flipped;
private PickedUpItem pickedUp; private PickedUpItem pickedUp;
private boolean lastEnabled = true; private boolean lastEnabled = true;
private static boolean examining = false;
public Toolbar() { public Toolbar() {
super(); super();
QuickSlots = ShatteredPixelDungeon.quickSlots(); slots = ShatteredPixelDungeon.quickSlots();
flipped = ShatteredPixelDungeon.flippedUI();
height = btnInventory.height(); height = btnInventory.height();
} }
@ -77,87 +77,126 @@ public class Toolbar extends Component {
@Override @Override
protected void createChildren() { protected void createChildren() {
add( btnWait = new Tool( 0, 7, 20, 25 ) { add(btnWait = new Tool(24, 0, 20, 26) {
@Override @Override
protected void onClick() { protected void onClick() {
Dungeon.hero.rest( false ); Dungeon.hero.rest(false);
}; }
;
protected boolean onLongClick() { protected boolean onLongClick() {
Dungeon.hero.rest( true ); Dungeon.hero.rest(true);
return true; return true;
}; }
} );
add( btnSearch = new Tool( 20, 7, 20, 25 ) { ;
});
add(btnSearch = new Tool(44, 0, 20, 26) {
@Override @Override
protected void onClick() { protected void onClick() {
Dungeon.hero.search( true ); if (!examining) {
GameScene.selectCell(informer);
examining = true;
} else {
informer.onSelect(null);
Dungeon.hero.search(true);
}
} }
} );
add( btnInfo = new Tool( 40, 7, 21, 25 ) { protected boolean onLongClick() {
@Override Dungeon.hero.search(true);
protected void onClick() { return true;
GameScene.selectCell( informer );
} }
} ); });
/* btnQuick = new Tool[4];
add( btnResume = new Tool( 61, 7, 21, 24 ) {
@Override
protected void onClick() {
Dungeon.hero.resume();
}
} );
*/
add( btnInventory = new Tool( 82, 7, 23, 25 ) { add( btnQuick[3] = new QuickslotTool( 64, 0, 22, 24, 3) );
add( btnQuick[2] = new QuickslotTool( 64, 0, 22, 24, 2) );
add(btnQuick[1] = new QuickslotTool(64, 0, 22, 24, 1));
add(btnQuick[0] = new QuickslotTool(64, 0, 22, 24, 0));
add(btnInventory = new Tool(0, 0, 24, 26) {
private GoldIndicator gold; private GoldIndicator gold;
@Override @Override
protected void onClick() { protected void onClick() {
GameScene.show( new WndBag( Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null ) ); GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null));
} }
protected boolean onLongClick() { protected boolean onLongClick() {
GameScene.show( new WndCatalogus() ); GameScene.show(new WndCatalogus());
return true; return true;
}; }
;
@Override @Override
protected void createChildren() { protected void createChildren() {
super.createChildren(); super.createChildren();
gold = new GoldIndicator(); gold = new GoldIndicator();
add( gold ); add(gold);
}; }
;
@Override @Override
protected void layout() { protected void layout() {
super.layout(); super.layout();
gold.fill( this ); gold.fill(this);
}; }
} );
add( btnQuick = new QuickslotTool( 105, 7, 22, 25, 0) ); ;
});
btnQuick2 = new QuickslotTool( 105, 7, 22, 25, 1); add(pickedUp = new PickedUpItem());
add( pickedUp = new PickedUpItem() );
} }
@Override @Override
protected void layout() { protected void layout() {
btnWait.setPos( x, y );
btnSearch.setPos( btnWait.right(), y );
btnInfo.setPos( btnSearch.right(), y ); int[] visible = new int[4];
//btnResume.setPos( btnInfo.right(), y );
btnQuick.setPos( width - btnQuick.width(), y ); for(int i = 0; i <= 3; i++)
btnQuick2.setPos( btnQuick.left() - btnQuick2.width(), y ); visible[i] = (int)((slots > i) ? y+2 : y+25);
if (QuickSlots == 2){
add(btnQuick2); for(int i = 0; i <= 3; i++)
btnQuick2.visible = btnQuick2.active = true; btnQuick[i].visible = slots > i;
btnInventory.setPos( btnQuick2.left() - btnInventory.width(), y );
if (!flipped) {
btnWait.setPos(x, y);
btnSearch.setPos(btnWait.right(), y);
btnInventory.setPos(width - btnInventory.width(), y);
int ofs = (slots == 4 && btnInventory.left() - btnSearch.right() < 90) ? 2 : 0;
btnQuick[0].setPos(btnInventory.left() - btnQuick[0].width() + ofs, visible[0]);
btnQuick[1].setPos(btnQuick[0].left() - btnQuick[1].width() + ofs, visible[1]);
btnQuick[2].setPos(btnQuick[1].left() - btnQuick[2].width() + ofs, visible[2]);
btnQuick[3].setPos(btnQuick[2].left() - btnQuick[3].width() + ofs, visible[3]);
} else { } else {
remove(btnQuick2); btnWait.setPos(width - btnWait.width(), y);
btnQuick2.visible = btnQuick2.active = false; btnSearch.setPos(btnWait.left() - btnSearch.width(), y);
btnInventory.setPos( btnQuick.left() - btnInventory.width(), y );
btnInventory.setPos(x, y);
int ofs = (slots == 4 && btnSearch.left() - btnInventory.right() < 90) ? 2 : 0;
btnQuick[0].setPos(btnInventory.right() - ofs, visible[0]);
btnQuick[1].setPos(btnQuick[0].right() - ofs, visible[1]);
btnQuick[2].setPos(btnQuick[1].right() - ofs, visible[2]);
btnQuick[3].setPos(btnQuick[2].right() - ofs, visible[3]);
} }
} }
@Override @Override
@ -174,14 +213,14 @@ public class Toolbar extends Component {
} }
} }
//btnResume.visible = Dungeon.hero.lastAction != null;
if (!Dungeon.hero.isAlive()) { if (!Dungeon.hero.isAlive()) {
btnInventory.enable( true ); btnInventory.enable(true);
} }
//If we have 2 slots, and 2nd one isn't visible, or we have 1, and 2nd one is visible... //check if visible slots or UI flipping has changed.
if ((QuickSlots == 1) == btnQuick2.visible){ if ((slots == 0 && btnQuick[0].visible) || (slots != 0 && !btnQuick[slots-1].visible)){
layout();
} else if (flipped && btnWait.left() == 0 || !flipped && btnInventory.left() == 0){
layout(); layout();
} }
} }
@ -196,6 +235,8 @@ public class Toolbar extends Component {
@Override @Override
public void onSelect( Integer cell ) { public void onSelect( Integer cell ) {
examining = false;
if (cell == null) { if (cell == null) {
return; return;
} }
@ -321,7 +362,7 @@ public class Toolbar extends Component {
@Override @Override
protected void layout() { protected void layout() {
super.layout(); super.layout();
slot.setRect( x + 1, y + 2, width - 2, height - 2 ); slot.setRect( x + 2, y + 2, width - 4, height - 3 );
} }
@Override @Override

View File

@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
@ -45,7 +46,7 @@ public class WndSettings extends Window {
private static final String TXT_BRIGHTNESS = "Brightness"; private static final String TXT_BRIGHTNESS = "Brightness";
private static final String TXT_QUICKSLOT = "Second QuickSlot"; private static final String TXT_QUICKSLOT = "QuickSlots: %s";
private static final String TXT_SWITCH_PORT = "Switch to portrait"; private static final String TXT_SWITCH_PORT = "Switch to portrait";
private static final String TXT_SWITCH_LAND = "Switch to landscape"; private static final String TXT_SWITCH_LAND = "Switch to landscape";
@ -108,7 +109,7 @@ public class WndSettings extends Window {
@Override @Override
protected void onClick() { protected void onClick() {
super.onClick(); super.onClick();
ShatteredPixelDungeon.immerse( checked() ); ShatteredPixelDungeon.immerse(checked());
} }
}; };
btnImmersive.setRect( 0, btnScaleUp.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnImmersive.setRect( 0, btnScaleUp.bottom() + GAP, WIDTH, BTN_HEIGHT );
@ -163,23 +164,37 @@ public class WndSettings extends Window {
ShatteredPixelDungeon.brightness(checked()); ShatteredPixelDungeon.brightness(checked());
} }
}; };
btnBrightness.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnBrightness.setRect(0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT);
btnBrightness.checked( ShatteredPixelDungeon.brightness() ); btnBrightness.checked(ShatteredPixelDungeon.brightness());
add( btnBrightness ); add(btnBrightness);
CheckBox btnQuickSlot = new CheckBox( TXT_QUICKSLOT ) { RedButton btnQuickSlot = new RedButton( Utils.format(TXT_QUICKSLOT, ShatteredPixelDungeon.quickSlots()) ) {
@Override @Override
protected void onClick() { protected void onClick() {
super.onClick(); super.onClick();
ShatteredPixelDungeon.quickSlots(checked() ? 2 : 1); int quickslots = ShatteredPixelDungeon.quickSlots()+1;
Toolbar.QuickSlots = checked() ? 2 : 1; if (quickslots == 5) quickslots = 0;
ShatteredPixelDungeon.quickSlots(quickslots);
this.text(Utils.format(TXT_QUICKSLOT, quickslots));
Toolbar.slots = quickslots;
} }
}; };
btnQuickSlot.setRect( 0, btnBrightness.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnQuickSlot.setRect(0, btnBrightness.bottom() + GAP, WIDTH, BTN_HEIGHT);
btnQuickSlot.checked( ShatteredPixelDungeon.quickSlots() == 2 ); add(btnQuickSlot);
add( btnQuickSlot );
resize( WIDTH, (int)btnQuickSlot.bottom() ); CheckBox btnFlipUI = new CheckBox("Flip Toolbar") {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.flippedUI(checked());
Toolbar.flipped = checked();
}
};
btnFlipUI.setRect( 0, btnQuickSlot.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnFlipUI.checked(ShatteredPixelDungeon.flippedUI());
add(btnFlipUI);
resize( WIDTH, (int)btnFlipUI.bottom() );
} }
} }