v0.9.2: improved logic for buttons inside of scroll areas

This commit is contained in:
Evan Debenham 2021-01-17 18:16:27 -05:00
parent 5be3fe7ba0
commit 412ea03892
6 changed files with 21 additions and 7 deletions

View File

@ -30,9 +30,11 @@ public class PointerArea extends Visual implements Signal.Listener<PointerEvent>
public Visual target;
protected PointerEvent curEvent = null;
//if true, this PointerArea will always block input, even when it is inactive
public boolean blockWhenInactive = false;
public int blockLevel = BLOCK_WHEN_ACTIVE;
public static final int ALWAYS_BLOCK = 0; //Always block input to overlapping elements
public static final int BLOCK_WHEN_ACTIVE = 1; //Only block when active (default)
public static final int NEVER_BLOCK = 2; //Never block (handy for buttons in scroll areas)
public PointerArea( Visual target ) {
super( 0, 0, 0, 0 );
@ -56,7 +58,7 @@ public class PointerArea extends Visual implements Signal.Listener<PointerEvent>
boolean hit = event != null && target.overlapsScreenPoint( (int)event.current.x, (int)event.current.y );
if (!isActive()) {
return (hit && blockWhenInactive);
return (hit && blockLevel == ALWAYS_BLOCK);
}
if (hit) {
@ -81,7 +83,7 @@ public class PointerArea extends Visual implements Signal.Listener<PointerEvent>
}
return returnValue;
return returnValue && blockLevel != NEVER_BLOCK;
} else {

View File

@ -44,7 +44,7 @@ public class ScrollArea extends PointerArea {
boolean hit = event != null && target.overlapsScreenPoint( (int)event.pos.x, (int)event.pos.y );
if (!isActive()) {
return (hit && blockWhenInactive);
return (hit && blockLevel == ALWAYS_BLOCK);
}
if (hit){

View File

@ -261,6 +261,7 @@ public class Visual extends Gizmo {
Camera c = camera();
if (c == null) return false;
if (!c.hitTest(x, y)) return false;
PointF p = c.screenToCamera( x, y );
return overlapsPoint( p.x, p.y );

View File

@ -72,6 +72,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Reflection;
@ -100,6 +101,10 @@ public class QuickRecipe extends Component {
anonymize(in);
ItemSlot curr;
curr = new ItemSlot(in) {
{
hotArea.blockLevel = PointerArea.NEVER_BLOCK;
}
@Override
protected void onClick() {
ShatteredPixelDungeon.scene().addToFront(new WndInfoItem(in));
@ -196,6 +201,8 @@ public class QuickRecipe extends Component {
public arrow( Image icon, int count ){
super( icon );
hotArea.blockLevel = PointerArea.NEVER_BLOCK;
text = new BitmapText( Integer.toString(count), PixelScene.pixelFont);
text.measure();
add(text);

View File

@ -32,6 +32,7 @@ import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
@ -58,6 +59,8 @@ public class TalentButton extends Button {
public TalentButton(int tier, Talent talent, int points, boolean upgradeEnabled){
super();
hotArea.blockLevel = PointerArea.NEVER_BLOCK;
this.tier = tier;
this.talent = talent;
this.pointsInTalent = points;

View File

@ -38,6 +38,7 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Point;
@ -309,7 +310,7 @@ public class Toolbar extends Component {
public Tool( int x, int y, int width, int height ) {
super();
hotArea.blockWhenInactive = true;
hotArea.blockLevel = PointerArea.ALWAYS_BLOCK;
frame(x, y, width, height);
}