Fix image view selection

This commit is contained in:
drdev
2014-05-22 23:58:07 +00:00
parent 013e291321
commit d074a5ff38
2 changed files with 58 additions and 45 deletions

View File

@@ -544,6 +544,20 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
return groups.get(groups.size() - 1).getBottom() + PADDING;
}
@Override
protected boolean onScrollerTap(float x, float y, int count) {
ItemInfo item = getItemAtPoint(x, y);
if (count == 1) {
selectItem(item);
}
else if (count == 2) {
if (item != null && item.selected) {
itemManager.activateSelectedItems();
}
}
return true;
}
private ItemInfo getItemAtPoint(float x, float y) {
for (int i = groups.size() - 1; i >= 0; i--) {
Group group = groups.get(i);
@@ -682,6 +696,35 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
}
private boolean selectItem(ItemInfo item) {
if (item == null) {
if (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown()) {
clearSelection();
onSelectionChange();
}
return false;
}
if (item.selected) {
if (KeyInputAdapter.isCtrlKeyDown()) {
item.selected = false;
selectedIndices.remove((Object)item.index);
onSelectionChange();
item.group.scrollIntoView(item);
return true;
}
}
if (!allowMultipleSelections || (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown())) {
clearSelection();
}
selectedIndices.add(0, item.index);
item.selected = true;
onSelectionChange();
item.group.scrollIntoView(item);
getScroller().scrollIntoView(item);
return true;
}
@Override
public void scrollSelectionIntoView() {
if (selectedIndices.isEmpty()) { return; }
@@ -782,23 +825,14 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
btnExpandCollapseAll.updateIsAllCollapsed();
clearSelection(); //must clear selection since indices and visible items will be changing
updateLayout(false);
}
else if (count == 1) {
selectItem(getItemAtPoint(x + getLeft(), y + getTop()));
}
else if (count == 2) {
ItemInfo item = getItemAtPoint(x + getLeft(), y + getTop());
if (item != null && item.selected) {
itemManager.activateSelectedItems();
}
}
return true;
}
return false;
}
@Override
public boolean longPress(float x, float y) {
ItemInfo item = getItemAtPoint(x + getLeft(), y + getTop());
selectItem(item);
if (item != null && item.item instanceof IPaperCard) {
CardZoom.show(Card.getCardForUi((IPaperCard) item.item));
return true;
@@ -806,35 +840,6 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
return false;
}
private boolean selectItem(ItemInfo item) {
if (item == null) {
if (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown()) {
clearSelection();
onSelectionChange();
}
return false;
}
if (item.selected) {
if (KeyInputAdapter.isCtrlKeyDown()) {
item.selected = false;
selectedIndices.remove((Object)item.index);
onSelectionChange();
item.group.scrollIntoView(item);
return true;
}
}
if (!allowMultipleSelections || (!KeyInputAdapter.isCtrlKeyDown() && !KeyInputAdapter.isShiftKeyDown())) {
clearSelection();
}
selectedIndices.add(0, item.index);
item.selected = true;
onSelectionChange();
item.group.scrollIntoView(item);
getScroller().scrollIntoView(item);
return true;
}
//provide special override for this function to account for special ItemInfo positioning logic
@Override
public Vector2 getChildRelativePosition(FDisplayObject child) {

View File

@@ -53,12 +53,20 @@ public abstract class ItemView<T extends InventoryItem> {
return new ScrollBounds(visibleWidth, ItemView.this.getScrollHeight());
}
@Override
public boolean tap(float x, float y, int count) {
return onScrollerTap(x, y, count);
}
@Override
public void drawOverlay(Graphics g) {
g.drawRect(1.5f, BORDER_COLOR, 0, 0, getWidth(), getHeight());
}
}
protected boolean onScrollerTap(float x, float y, int count) {
return false;
}
protected abstract float getScrollHeight();
protected abstract float layoutOptionsPanel(float visibleWidth, float height);