From 179935fb87e1580570a4ce108eb4c87e17f1e510 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 25 Jun 2015 00:00:37 -0400 Subject: [PATCH] v0.3.1: implemented a new toolbar UI including more minimum resolution width, options for up to 4 quickslots, and ui flip support. --- assets/toolbar.png | Bin 4071 -> 3869 bytes .../shatteredpixeldungeon/Preferences.java | 1 + .../ShatteredPixelDungeon.java | 5 + .../scenes/PixelScene.java | 2 +- .../shatteredpixeldungeon/ui/Toolbar.java | 189 +++++++++++------- .../windows/WndSettings.java | 39 ++-- 6 files changed, 149 insertions(+), 87 deletions(-) diff --git a/assets/toolbar.png b/assets/toolbar.png index 59f251ed3de8528a12558cc72747c99502eb82a3..04c503d9056273fbe6d5f75b0c75798856a5af3a 100644 GIT binary patch delta 1175 zcmV;I1Zex`ADtesmkNId83F?wu|+Zs000DKNkl&Vs2EC)BvsHtAmIo55afgN?CGjtcXIr3&-a!4PqOV9Yrfth3G9xVZii ztIobyX?55blZ%(6)oE+pK$$RboG;v+xiq=nWq0evK0kQ4=Xrl}&zC&U^U3e|J-;{r zpf`F%f(4eml!njG*j7(Si4HGAnLc+RC1Q8yUI!|`oJR+~k%W|JiTHGO2K7EK(n7|T zdRZ|i(Ox%321iYsGex_R6?3Q*b4ro~NwUNNK-M-(-%34-cAKL4#FLL(ww?q43-!!g z0|Ed6;NbyaEEazO05r9}zMxOG{Lcsgl?6am;Ubh;6uB*LexRiTftC*3{#(Leqz{Yf zESK`oc!0V1PXGYA)(HTZojSIlJ^ai4Xt%m%HHLnSU`x2e@Gth_)FoB>+2{Rbd4SNi z^+>12ALt7I5D!o;05>ki(6n)r=D_a#N3gN!B>=#gvGaeZu35c6M{98t@gx9%<2Y46 z&+`C)hUa{`0SLDRaNuB%s;@QZK|FPL$pHAF|1jk1bzMEJ)OUC8wf_+S0CU&=)O_k$ z&{8E4PlDq(W%EO!kfI^?C*nz6T6;eJ1P2cGfMr>H^~JYfSr#t$8pMV&2)6~6>~vsp)Wth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1kcVr_J2_EbB#H+*%W~y^st2*I;Wt z4O{c+fD`B4FIWALGXX=+1Q`0JVd$Ioo9x(i@o4>NI3OoUW09B>-uV*i0rYx3%x1G^ zJK%p)t1mu1*6=t1Ju?@!2k^!OM?9bk(F1s|cDKt3n&wXFxBYwzwIy4G#Q?wm%{%V< ziw{=M7NFPb(b(81c(4pwT7N-hxe}e->~!wY`h93U`2lEpEwN)@W!+)XTY%f;6tp#I zcW(B3XQ9VH)pjlH*Nvi%mJtD#Qdu=_n9g}TLBBmF zWWF`#0obe#$oA9*5p3umZK__$3KD;)B4`kJfAImHOI*)+4}P>}ctO|$fIkLEQ*2}z z+_yfEI~3!pa!ac)*mE9l=au5xL{G?k9sPp=%03-oO0-$LqRB1@hP>>gZ%{mFk#1t{&Xy;ol k&gJBtusJaK=pv2(0N1l%zG_k=mjD0&07*qoM6N<$f^m?Oe*gdg diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java b/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java index 73cb2928a..59e2fbabc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java @@ -37,6 +37,7 @@ enum Preferences { public static final String KEY_LAST_CLASS = "last_class"; public static final String KEY_CHALLENGES = "challenges"; 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_BRIGHTNESS = "brightness"; public static final String KEY_VERSION = "version"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java b/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java index f1bed5147..12b559383 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java @@ -319,6 +319,11 @@ public class ShatteredPixelDungeon extends Game { public static void quickSlots( int value ){ Preferences.INSTANCE.put( Preferences.KEY_QUICKSLOTS, value ); } 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 ) { Preferences.INSTANCE.put( Preferences.KEY_INTRO, value ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index 70a166df7..4e04c53bc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -42,7 +42,7 @@ import com.watabou.utils.BitmapCache; public class PixelScene extends Scene { // 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; // Minimum virtual display size for landscape orientation diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index 96294e64a..60177cd75 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -54,110 +54,149 @@ public class Toolbar extends Component { private Tool btnWait; private Tool btnSearch; - private Tool btnInfo; - private Tool btnResume; private Tool btnInventory; - private Tool btnQuick; - private Tool btnQuick2; + private Tool[] btnQuick; - public static int QuickSlots; + public static int slots; + public static boolean flipped; private PickedUpItem pickedUp; private boolean lastEnabled = true; + private static boolean examining = false; public Toolbar() { super(); - QuickSlots = ShatteredPixelDungeon.quickSlots(); - + slots = ShatteredPixelDungeon.quickSlots(); + flipped = ShatteredPixelDungeon.flippedUI(); + height = btnInventory.height(); } @Override protected void createChildren() { - add( btnWait = new Tool( 0, 7, 20, 25 ) { + add(btnWait = new Tool(24, 0, 20, 26) { @Override protected void onClick() { - Dungeon.hero.rest( false ); - }; - protected boolean onLongClick() { - Dungeon.hero.rest( true ); - return true; - }; - } ); - - add( btnSearch = new Tool( 20, 7, 20, 25 ) { - @Override - protected void onClick() { - Dungeon.hero.search( true ); + Dungeon.hero.rest(false); } - } ); - - add( btnInfo = new Tool( 40, 7, 21, 25 ) { - @Override - protected void onClick() { - GameScene.selectCell( informer ); - } - } ); - /* - add( btnResume = new Tool( 61, 7, 21, 24 ) { - @Override - protected void onClick() { - Dungeon.hero.resume(); - } - } ); - */ - - add( btnInventory = new Tool( 82, 7, 23, 25 ) { - private GoldIndicator gold; - @Override - protected void onClick() { - GameScene.show( new WndBag( Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null ) ); - } + ; + protected boolean onLongClick() { - GameScene.show( new WndCatalogus() ); + Dungeon.hero.rest(true); return true; - }; + } + + ; + }); + + add(btnSearch = new Tool(44, 0, 20, 26) { + @Override + protected void onClick() { + if (!examining) { + GameScene.selectCell(informer); + examining = true; + } else { + informer.onSelect(null); + Dungeon.hero.search(true); + } + } + + protected boolean onLongClick() { + Dungeon.hero.search(true); + return true; + } + }); + + btnQuick = new Tool[4]; + + 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; + + @Override + protected void onClick() { + GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null)); + } + + protected boolean onLongClick() { + GameScene.show(new WndCatalogus()); + return true; + } + + ; + @Override protected void createChildren() { super.createChildren(); gold = new GoldIndicator(); - add( gold ); - }; + add(gold); + } + + ; + @Override protected void layout() { super.layout(); - gold.fill( this ); - }; - } ); - - add( btnQuick = new QuickslotTool( 105, 7, 22, 25, 0) ); + gold.fill(this); + } - btnQuick2 = new QuickslotTool( 105, 7, 22, 25, 1); - - add( pickedUp = new PickedUpItem() ); + ; + }); + + add(pickedUp = new PickedUpItem()); } @Override protected void layout() { - btnWait.setPos( x, y ); - btnSearch.setPos( btnWait.right(), y ); - btnInfo.setPos( btnSearch.right(), y ); - //btnResume.setPos( btnInfo.right(), y ); - btnQuick.setPos( width - btnQuick.width(), y ); - btnQuick2.setPos( btnQuick.left() - btnQuick2.width(), y ); - if (QuickSlots == 2){ - add(btnQuick2); - btnQuick2.visible = btnQuick2.active = true; - btnInventory.setPos( btnQuick2.left() - btnInventory.width(), y ); + + + int[] visible = new int[4]; + + for(int i = 0; i <= 3; i++) + visible[i] = (int)((slots > i) ? y+2 : y+25); + + for(int i = 0; i <= 3; i++) + btnQuick[i].visible = slots > i; + + 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 { - remove(btnQuick2); - btnQuick2.visible = btnQuick2.active = false; - btnInventory.setPos( btnQuick.left() - btnInventory.width(), y ); + btnWait.setPos(width - btnWait.width(), y); + btnSearch.setPos(btnWait.left() - btnSearch.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 @@ -174,14 +213,14 @@ public class Toolbar extends Component { } } - //btnResume.visible = Dungeon.hero.lastAction != null; - 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... - if ((QuickSlots == 1) == btnQuick2.visible){ + //check if visible slots or UI flipping has changed. + if ((slots == 0 && btnQuick[0].visible) || (slots != 0 && !btnQuick[slots-1].visible)){ + layout(); + } else if (flipped && btnWait.left() == 0 || !flipped && btnInventory.left() == 0){ layout(); } } @@ -195,6 +234,8 @@ public class Toolbar extends Component { private static CellSelector.Listener informer = new CellSelector.Listener() { @Override public void onSelect( Integer cell ) { + + examining = false; if (cell == null) { return; @@ -321,7 +362,7 @@ public class Toolbar extends Component { @Override protected void layout() { super.layout(); - slot.setRect( x + 1, y + 2, width - 2, height - 2 ); + slot.setRect( x + 2, y + 2, width - 4, height - 3 ); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index 9cc8adc9a..99557e5a1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -22,6 +22,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; +import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.noosa.Camera; import com.watabou.noosa.audio.Sample; 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_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_LAND = "Switch to landscape"; @@ -108,7 +109,7 @@ public class WndSettings extends Window { @Override protected void onClick() { super.onClick(); - ShatteredPixelDungeon.immerse( checked() ); + ShatteredPixelDungeon.immerse(checked()); } }; btnImmersive.setRect( 0, btnScaleUp.bottom() + GAP, WIDTH, BTN_HEIGHT ); @@ -163,23 +164,37 @@ public class WndSettings extends Window { ShatteredPixelDungeon.brightness(checked()); } }; - btnBrightness.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); - btnBrightness.checked( ShatteredPixelDungeon.brightness() ); - add( btnBrightness ); + btnBrightness.setRect(0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT); + btnBrightness.checked(ShatteredPixelDungeon.brightness()); + add(btnBrightness); - CheckBox btnQuickSlot = new CheckBox( TXT_QUICKSLOT ) { + RedButton btnQuickSlot = new RedButton( Utils.format(TXT_QUICKSLOT, ShatteredPixelDungeon.quickSlots()) ) { @Override protected void onClick() { super.onClick(); - ShatteredPixelDungeon.quickSlots(checked() ? 2 : 1); - Toolbar.QuickSlots = checked() ? 2 : 1; + int quickslots = ShatteredPixelDungeon.quickSlots()+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.checked( ShatteredPixelDungeon.quickSlots() == 2 ); - add( btnQuickSlot ); + btnQuickSlot.setRect(0, btnBrightness.bottom() + GAP, WIDTH, BTN_HEIGHT); + add(btnQuickSlot); + + 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)btnQuickSlot.bottom() ); + resize( WIDTH, (int)btnFlipUI.bottom() ); } }