From 4fcf108cd342f81f5a8a61bfbbcb542726bd580b Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 14 Feb 2022 21:03:12 -0500 Subject: [PATCH] v1.2.0: added right click menu functionality to the old bag window v1.2.0: added right click menu functionality to the old bag window --- .../ui/RightClickMenu.java | 11 +++---- .../shatteredpixeldungeon/windows/WndBag.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java index 5311ea878..8d344de2f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/RightClickMenu.java @@ -88,9 +88,8 @@ public class RightClickMenu extends Component { super.onClick(); if (item != null){ item.execute(Dungeon.hero, options[finalI]); - } else { - onSelect(finalI); } + onSelect(finalI); RightClickMenu.this.destroy(); RightClickMenu.this.killAndErase(); } @@ -128,11 +127,11 @@ public class RightClickMenu extends Component { width = icon.width + 2 + titleText.width()+bg.marginVer(); - if (x + width > camera.width){ - x -= (x + width - camera.width); + if (x + width > (camera.width + camera.scroll.x)){ + x -= (x + width - (camera.width + camera.scroll.x)); } - if (y + height > camera.height){ - y -= (y + height - camera.height); + if (y + height > (camera.height + camera.scroll.y)){ + y -= (y + height - (camera.height + camera.scroll.y)); } bg.x = x; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index e36b91a43..92ec483a2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -45,15 +45,18 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.InventorySlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; +import com.shatteredpixel.shatteredpixeldungeon.ui.RightClickMenu; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.watabou.gltextures.TextureCache; import com.watabou.input.KeyBindings; import com.watabou.input.KeyEvent; +import com.watabou.input.PointerEvent; import com.watabou.noosa.BitmapText; import com.watabou.noosa.ColorBlock; import com.watabou.noosa.Game; import com.watabou.noosa.Image; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PointF; public class WndBag extends WndTabbed { @@ -291,6 +294,34 @@ public class WndBag extends WndTabbed { } } + @Override + protected void onRightClick() { + if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){ + + hide(); + + } else if (selector != null) { + + hide(); + selector.onSelect( item ); + + } else { + + RightClickMenu r = new RightClickMenu(item){ + @Override + public void onSelect(int index) { + WndBag.this.hide(); + } + }; + parent.addToFront(r); + r.camera = camera(); + PointF mousePos = PointerEvent.currentHoverPos(); + mousePos = camera.screenToCamera((int)mousePos.x, (int)mousePos.y); + r.setPos(mousePos.x-3, mousePos.y-3); + + } + } + @Override protected boolean onLongClick() { if (selector == null && item.defaultAction != null) {