From bd79f96630263249b5cb071b556f3b7a5c4619c7 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 28 Jan 2022 15:26:28 -0500 Subject: [PATCH] v1.2.0: Added support for item windows centered on inv pane --- .../ui/InventoryPane.java | 30 +++++++++++++++++-- .../shatteredpixeldungeon/ui/Window.java | 20 +++++++------ .../ui/WndTextInput.java | 4 +-- .../windows/WndQuickBag.java | 4 +-- .../windows/WndSettings.java | 2 +- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java index f50b5e244..7eb8c8382 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java @@ -112,7 +112,20 @@ public class InventoryPane extends Component { if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){ updateInventory(); } else { - Game.scene().addToFront(new WndUseItem( null, item ) ); + Window w = new WndUseItem( null, item ); + int xOfs, yOfs; + if (w.height > InventoryPane.this.height - 15){ + yOfs = (camera.height - w.height)/2 - 9; + } else { + yOfs = (int)(InventoryPane.this.y)/2; + } + if (w.width > InventoryPane.this.width - 15){ + xOfs = (camera.width - w.width)/2 - 9; + } else { + xOfs = (int)(InventoryPane.this.x)/2; + } + w.offset(xOfs, yOfs); + Game.scene().addToFront(w); } } }; @@ -140,7 +153,20 @@ public class InventoryPane extends Component { if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){ updateInventory(); } else { - Game.scene().addToFront(new WndUseItem( null, item ) ); + Window w = new WndUseItem( null, item ); + int xOfs, yOfs; + if (w.height > InventoryPane.this.height - 15){ + yOfs = (camera.height - w.height)/2 - 9; + } else { + yOfs = (int)(InventoryPane.this.y)/2; + } + if (w.width > InventoryPane.this.width - 15){ + xOfs = (camera.width - w.width)/2 - 9; + } else { + xOfs = (int)(InventoryPane.this.x)/2; + } + w.offset(xOfs, yOfs); + Game.scene().addToFront(w); } } }; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java index 63cda1278..116259f6f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java @@ -40,6 +40,7 @@ public class Window extends Group implements Signal.Listener { protected int width; protected int height; + protected int xOffset; protected int yOffset; protected PointerArea blocker; @@ -51,21 +52,15 @@ public class Window extends Group implements Signal.Listener { public static final int SHPX_COLOR = 0x33BB33; public Window() { - this( 0, 0, 0, Chrome.get( Chrome.Type.WINDOW ) ); + this( 0, 0, Chrome.get( Chrome.Type.WINDOW ) ); } public Window( int width, int height ) { - this( width, height, 0, Chrome.get( Chrome.Type.WINDOW ) ); + this( width, height, Chrome.get( Chrome.Type.WINDOW ) ); } public Window( int width, int height, NinePatch chrome ) { - this(width, height, 0, chrome); - } - - public Window( int width, int height, int yOffset, NinePatch chrome ) { super(); - - this.yOffset = yOffset; blocker = new PointerArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) { @Override @@ -126,14 +121,21 @@ public class Window extends Group implements Signal.Listener { height + chrome.marginVer() ); camera.resize( (int)chrome.width, (int)chrome.height ); + camera.x = (int)(Game.width - camera.screenWidth()) / 2; + camera.x += xOffset * camera.zoom; + camera.y = (int)(Game.height - camera.screenHeight()) / 2; camera.y += yOffset * camera.zoom; shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height ); } - public void offset( int yOffset ){ + public void offset( int xOffset, int yOffset ){ + camera.x -= this.xOffset * camera.zoom; + this.xOffset = xOffset; + camera.x += xOffset * camera.zoom; + camera.y -= this.yOffset * camera.zoom; this.yOffset = yOffset; camera.y += yOffset * camera.zoom; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/WndTextInput.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/WndTextInput.java index a7f607546..4f2f69caf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/WndTextInput.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/WndTextInput.java @@ -40,9 +40,9 @@ public class WndTextInput extends Window { //need to offset to give space for the soft keyboard if (!DeviceCompat.isDesktop()) { if (PixelScene.landscape()) { - offset(-45); + offset(0, -45); } else { - offset(multiLine ? -60 : -45); + offset(0, multiLine ? -60 : -45); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java index 06af91ab2..051552d8e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndQuickBag.java @@ -56,7 +56,7 @@ public class WndQuickBag extends Window { private static Item bag; public WndQuickBag(Bag bag){ - super(0, 0, 0, Chrome.get(Chrome.Type.TOAST_TR)); + super(0, 0, Chrome.get(Chrome.Type.TOAST_TR)); if( WndBag.INSTANCE != null ){ WndBag.INSTANCE.hide(); @@ -156,7 +156,7 @@ public class WndQuickBag extends Window { int bottom = GameScene.uiCamera.height; //offset to be above the toolbar - offset((int) (bottom/2 - 30 - height/2)); + offset(0, (int) (bottom/2 - 30 - height/2)); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index 980252138..603cfb6e0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -909,7 +909,7 @@ public class WndSettings extends WndTabbed { index += 2; } - Window credits = new Window(0, 0, 0, Chrome.get(Chrome.Type.TOAST)); + Window credits = new Window(0, 0, Chrome.get(Chrome.Type.TOAST)); int w = PixelScene.landscape() ? 120 : 80; if (totalCredits >= 25) w *= 1.5f;