diff --git a/forge-gui-mobile/src/forge/itemmanager/views/ItemListView.java b/forge-gui-mobile/src/forge/itemmanager/views/ItemListView.java index 2891e1260be..f0421f1ac4e 100644 --- a/forge-gui-mobile/src/forge/itemmanager/views/ItemListView.java +++ b/forge-gui-mobile/src/forge/itemmanager/views/ItemListView.java @@ -34,6 +34,7 @@ import forge.toolbox.FCheckBox; import forge.toolbox.FEvent; import forge.toolbox.FEvent.FEventHandler; import forge.toolbox.FList; + import org.apache.commons.lang3.StringUtils; import java.util.*; @@ -275,8 +276,7 @@ public final class ItemListView extends ItemView { } @Override - public boolean tap(Entry value, float x, float y, int count) { - Integer index = list.getIndexOf(value); + public boolean tap(Integer index, Entry value, float x, float y, int count) { if (allowMultipleSelections) { if (selectedIndices.contains(index)) { selectedIndices.remove(index); @@ -299,7 +299,18 @@ public final class ItemListView extends ItemView { } @Override - public void drawValue(Graphics g, Entry value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, Entry value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + if (allowMultipleSelections) { + if (pressed) { //if multi-select mode, draw SEL_COLOR when pressed + g.fillRect(SEL_COLOR, x - FList.PADDING, y - FList.PADDING, w + 2 * FList.PADDING, h + 2 * FList.PADDING); + } + //draw checkbox, with it checked based on whether item is selected + float checkBoxSize = h / 2; + float padding = checkBoxSize / 2; + w -= checkBoxSize + padding; + FCheckBox.drawCheckBox(g, selectedIndices.contains(index), x + w, y + padding, checkBoxSize, checkBoxSize); + w -= padding; + } renderer.drawValue(g, value, font, foreColor, pressed, x + 1, y, w - 2, h); //x + 1 and w - 2 to account for left and right borders } }); @@ -321,8 +332,8 @@ public final class ItemListView extends ItemView { @Override protected FSkinColor getItemFillColor(int index) { - if (selectedIndices.contains(index)) { - return SEL_COLOR; + if (!allowMultipleSelections && selectedIndices.contains(index)) { + return SEL_COLOR; //don't show SEL_COLOR if in multi-select mode } if (index % 2 == 1) { return ALT_ROW_COLOR; diff --git a/forge-gui-mobile/src/forge/screens/constructed/ConstructedScreen.java b/forge-gui-mobile/src/forge/screens/constructed/ConstructedScreen.java index f6e23d48350..6a5f9ab05a5 100644 --- a/forge-gui-mobile/src/forge/screens/constructed/ConstructedScreen.java +++ b/forge-gui-mobile/src/forge/screens/constructed/ConstructedScreen.java @@ -1053,13 +1053,13 @@ public class ConstructedScreen extends LaunchScreen { } @Override - public boolean tap(Variant value, float x, float y, int count) { + public boolean tap(Integer index, Variant value, float x, float y, int count) { value.toggle(); return true; } @Override - public void drawValue(Graphics g, Variant value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, Variant value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { String text = value.gameType.toString(); float totalHeight = h; h = font.getMultiLineBounds(text).height + 5; diff --git a/forge-gui-mobile/src/forge/screens/settings/FilesPage.java b/forge-gui-mobile/src/forge/screens/settings/FilesPage.java index 31f67a78cb4..9bcabe81bb3 100644 --- a/forge-gui-mobile/src/forge/screens/settings/FilesPage.java +++ b/forge-gui-mobile/src/forge/screens/settings/FilesPage.java @@ -81,13 +81,13 @@ public class FilesPage extends TabPage { } @Override - public boolean tap(FilesItem value, float x, float y, int count) { + public boolean tap(Integer index, FilesItem value, float x, float y, int count) { value.select(); return true; } @Override - public void drawValue(Graphics g, FilesItem value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, FilesItem value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items x += offset; y += offset; diff --git a/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java b/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java index 05e1d62cb00..d8d65ffd748 100644 --- a/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java +++ b/forge-gui-mobile/src/forge/screens/settings/SettingsPage.java @@ -268,7 +268,7 @@ public class SettingsPage extends TabPage { lstOptions = add(new FList(options)); lstOptions.setListItemRenderer(new FList.DefaultListItemRenderer() { @Override - public boolean tap(String value, float x, float y, int count) { + public boolean tap(Integer index, String value, float x, float y, int count) { if (!value.equals(currentValue)) { valueChanged(value); } @@ -277,7 +277,7 @@ public class SettingsPage extends TabPage { } @Override - public void drawValue(Graphics g, String value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, String value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items x += offset; y += offset; @@ -316,13 +316,13 @@ public class SettingsPage extends TabPage { } @Override - public boolean tap(Setting value, float x, float y, int count) { + public boolean tap(Integer index, Setting value, float x, float y, int count) { value.select(); return true; } @Override - public void drawValue(Graphics g, Setting value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, Setting value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items x += offset; y += offset; diff --git a/forge-gui-mobile/src/forge/toolbox/DualListBox.java b/forge-gui-mobile/src/forge/toolbox/DualListBox.java index a45bc18525f..40e2c44edc0 100644 --- a/forge-gui-mobile/src/forge/toolbox/DualListBox.java +++ b/forge-gui-mobile/src/forge/toolbox/DualListBox.java @@ -365,8 +365,7 @@ public class DualListBox extends FDialog { } @Override - public boolean tap(T value, float x, float y, int count) { - Integer index = ChoiceList.this.getIndexOf(value); + public boolean tap(Integer index, T value, float x, float y, int count) { selectedIndices.clear(); selectedIndices.add(index); if (renderer.tap(value, x, y, count)) { @@ -379,7 +378,7 @@ public class DualListBox extends FDialog { } @Override - public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { renderer.drawValue(g, value, font, foreColor, pressed, x, y, w, h); } }); diff --git a/forge-gui-mobile/src/forge/toolbox/FCheckBox.java b/forge-gui-mobile/src/forge/toolbox/FCheckBox.java index 5ceb1eaf6f4..31cc99133d7 100644 --- a/forge-gui-mobile/src/forge/toolbox/FCheckBox.java +++ b/forge-gui-mobile/src/forge/toolbox/FCheckBox.java @@ -36,7 +36,7 @@ public class FCheckBox extends FLabel { @Override public void draw(Graphics g, float x, float y, float w, float h) { - drawCheckBox(g, BOX_COLOR, CHECK_COLOR, isSelected(), x, y, w, h); + drawCheckBox(g, isSelected(), x, y, w, h); } } @@ -45,6 +45,9 @@ public class FCheckBox extends FLabel { drawContent(g, getWidth(), getHeight(), false); } + public static void drawCheckBox(Graphics g, boolean isChecked, float x, float y, float w, float h) { + drawCheckBox(g, BOX_COLOR, CHECK_COLOR, isChecked, x, y, w, h); + } public static void drawCheckBox(Graphics g, FSkinColor boxColor, FSkinColor checkColor, boolean isChecked, float x, float y, float w, float h) { g.drawRect(Utils.scaleMin(1), boxColor, x, y, w, h); if (isChecked) { diff --git a/forge-gui-mobile/src/forge/toolbox/FGroupList.java b/forge-gui-mobile/src/forge/toolbox/FGroupList.java index 77c6cd40cd2..1ba0731d8af 100644 --- a/forge-gui-mobile/src/forge/toolbox/FGroupList.java +++ b/forge-gui-mobile/src/forge/toolbox/FGroupList.java @@ -243,7 +243,7 @@ public class FGroupList extends FScrollPane { } public boolean tap(float x, float y, int count) { - return renderer.tap(value, x, y, count); + return renderer.tap(-1, value, x, y, count); } @Override @@ -256,7 +256,7 @@ public class FGroupList extends FScrollPane { g.fillRect(fillColor, 0, 0, w, h); } - renderer.drawValue(g, value, font, FList.FORE_COLOR, pressed, FList.PADDING, FList.PADDING, w - 2 * FList.PADDING, h - 2 * FList.PADDING); + renderer.drawValue(g, -1, value, font, FList.FORE_COLOR, pressed, FList.PADDING, FList.PADDING, w - 2 * FList.PADDING, h - 2 * FList.PADDING); if (drawLineSeparators()) { g.drawLine(1, FList.LINE_COLOR, 0, h, w, h); diff --git a/forge-gui-mobile/src/forge/toolbox/FList.java b/forge-gui-mobile/src/forge/toolbox/FList.java index 41344efedce..3269f5bdffb 100644 --- a/forge-gui-mobile/src/forge/toolbox/FList.java +++ b/forge-gui-mobile/src/forge/toolbox/FList.java @@ -135,7 +135,7 @@ public class FList extends FScrollPane implements Iterable { E item = getItemAt(index); if (item == null) { return false; } - return renderer.tap(item, x, y - getItemTop(index), count); + return renderer.tap(index, item, x, y - getItemTop(index), count); } private float getItemTop(int index) { @@ -187,7 +187,7 @@ public class FList extends FScrollPane implements Iterable { g.fillRect(fillColor, 0, y, w, itemHeight); } - renderer.drawValue(g, items.get(i), font, FORE_COLOR, pressedIndex == i, PADDING, y + PADDING, valueWidth, valueHeight); + renderer.drawValue(g, i, items.get(i), font, FORE_COLOR, pressedIndex == i, PADDING, y + PADDING, valueWidth, valueHeight); y += itemHeight; @@ -214,8 +214,8 @@ public class FList extends FScrollPane implements Iterable { public static abstract class ListItemRenderer { public abstract float getItemHeight(); - public abstract boolean tap(V value, float x, float y, int count); - public abstract void drawValue(Graphics g, V value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h); + public abstract boolean tap(Integer index, V value, float x, float y, int count); + public abstract void drawValue(Graphics g, Integer index, V value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h); } public static class DefaultListItemRenderer extends ListItemRenderer { @@ -225,12 +225,12 @@ public class FList extends FScrollPane implements Iterable { } @Override - public boolean tap(V value, float x, float y, int count) { + public boolean tap(Integer index, V value, float x, float y, int count) { return false; } @Override - public void drawValue(Graphics g, V value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, V value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) { g.drawText(value.toString(), font, color, x, y, w, h, false, HAlignment.LEFT, true); } } diff --git a/forge-gui-mobile/src/forge/toolbox/ListChooser.java b/forge-gui-mobile/src/forge/toolbox/ListChooser.java index 73937a6e736..ce6bbef9b5c 100644 --- a/forge-gui-mobile/src/forge/toolbox/ListChooser.java +++ b/forge-gui-mobile/src/forge/toolbox/ListChooser.java @@ -378,8 +378,7 @@ public class ListChooser extends FContainer { } @Override - public boolean tap(T value, float x, float y, int count) { - Integer index = ChoiceList.this.getIndexOf(value); + public boolean tap(Integer index, T value, float x, float y, int count) { if (allowMultipleSelections) { if (selectedIndices.contains(index)) { selectedIndices.remove(index); @@ -403,7 +402,18 @@ public class ListChooser extends FContainer { } @Override - public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + public void drawValue(Graphics g, Integer index, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) { + if (allowMultipleSelections) { + if (pressed) { //if multi-select mode, draw SEL_COLOR when pressed + g.fillRect(SEL_COLOR, x - FList.PADDING, y - FList.PADDING, w + 2 * FList.PADDING, h + 2 * FList.PADDING); + } + //draw checkbox, with it checked based on whether item is selected + float checkBoxSize = h / 2; + float padding = checkBoxSize / 2; + w -= checkBoxSize + padding; + FCheckBox.drawCheckBox(g, selectedIndices.contains(index), x + w, y + padding, checkBoxSize, checkBoxSize); + w -= padding; + } renderer.drawValue(g, value, font, foreColor, pressed, x, y, w, h); } }); @@ -422,8 +432,8 @@ public class ListChooser extends FContainer { @Override protected FSkinColor getItemFillColor(int index) { - if (selectedIndices.contains(index)) { - return SEL_COLOR; + if (!allowMultipleSelections && selectedIndices.contains(index)) { + return SEL_COLOR; //don't show SEL_COLOR if in multi-select mode } if (index % 2 == 1) { return ALT_ITEM_COLOR;