mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Support selecting teams
This commit is contained in:
@@ -125,13 +125,18 @@ public abstract class FDropDown extends FScrollPane {
|
||||
g.drawRect(2, BORDER_COLOR, 0, 0, w, h); //ensure border shows up on all sides
|
||||
}
|
||||
|
||||
protected FDisplayObject getDropDownOwner() {
|
||||
return menuTab;
|
||||
}
|
||||
|
||||
private class Backdrop extends FDisplayObject {
|
||||
private Backdrop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean press(float x, float y) {
|
||||
if (menuTab == null || !menuTab.contains(menuTab.screenToLocalX(x), menuTab.screenToLocalY(y))) {
|
||||
FDisplayObject owner = getDropDownOwner();
|
||||
if (owner == null || !owner.contains(owner.getLeft() + owner.screenToLocalX(x), owner.getTop() + owner.screenToLocalY(y))) {
|
||||
hide(); //auto-hide when backdrop pressed unless over menu tab
|
||||
}
|
||||
return false; //allow press to pass through to object behind backdrop
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FDropDownMenu extends FDropDown {
|
||||
private final List<FMenuItem> items = new ArrayList<FMenuItem>();
|
||||
protected final List<FMenuItem> items = new ArrayList<FMenuItem>();
|
||||
|
||||
public FDropDownMenu() {
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public abstract class FDropDownMenu extends FDropDown {
|
||||
protected abstract void buildMenu();
|
||||
|
||||
@Override
|
||||
protected final ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
|
||||
protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
|
||||
clear();
|
||||
items.clear();
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ import forge.util.NameGenerator;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.utils.ForgePreferences;
|
||||
import forge.utils.ForgePreferences.FPref;
|
||||
import forge.utils.Utils;
|
||||
|
||||
public class ConstructedScreen extends LaunchScreen {
|
||||
private static final FSkinColor PLAYER_BORDER_COLOR = FSkinColor.get(Colors.CLR_THEME).alphaColor(0.8f);
|
||||
@@ -663,14 +662,13 @@ public class ConstructedScreen extends LaunchScreen {
|
||||
private FEventHandler teamChangedHandler = new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
@SuppressWarnings("unchecked")
|
||||
FComboBox<Object> cb = (FComboBox<Object>)e.getSource();
|
||||
Object selection = cb.getSelectedItem();
|
||||
|
||||
if (null == selection) {
|
||||
if (cb.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
if (appliedVariants.contains(GameType.Archenemy)) {
|
||||
String sel = (String) selection;
|
||||
String sel = (String) cb.getSelectedItem();
|
||||
if (sel.contains("Archenemy")) {
|
||||
lastArchenemy = index;
|
||||
for (PlayerPanel pp : playerPanels) {
|
||||
@@ -682,8 +680,7 @@ public class ConstructedScreen extends LaunchScreen {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Integer sel = (Integer) selection;
|
||||
teams.set(index, sel);
|
||||
teams.set(index, cb.getSelectedIndex() + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,12 +3,17 @@ package forge.toolbox;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.toolbox.FEvent.FEventType;
|
||||
import forge.menu.FDropDownMenu;
|
||||
import forge.menu.FMenuItem;
|
||||
import forge.screens.FScreen;
|
||||
import forge.toolbox.FEvent.*;
|
||||
|
||||
public class FComboBox<E> extends FTextField {
|
||||
private final List<E> items = new ArrayList<E>();
|
||||
private E selectedItem;
|
||||
private final DropDown dropDown = new DropDown();
|
||||
|
||||
public FComboBox() {
|
||||
initialize();
|
||||
@@ -107,6 +112,7 @@ public class FComboBox<E> extends FTextField {
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
dropDown.setVisible(!dropDown.isVisible());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -133,4 +139,56 @@ public class FComboBox<E> extends FTextField {
|
||||
protected float getRightPadding() {
|
||||
return getDivotWidth() + 2 * PADDING;
|
||||
}
|
||||
|
||||
private class DropDown extends FDropDownMenu {
|
||||
@Override
|
||||
protected void buildMenu() {
|
||||
for (final E item : FComboBox.this.items) {
|
||||
addItem(new FMenuItem(item.toString(), new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
setSelectedItem(item);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
|
||||
clear();
|
||||
items.clear();
|
||||
|
||||
buildMenu();
|
||||
|
||||
//determine needed width of menu
|
||||
float width = FComboBox.this.getWidth();
|
||||
|
||||
//set bounds for each item
|
||||
float y = 0;
|
||||
for (FMenuItem item : items) {
|
||||
item.setBounds(0, y, width, FMenuItem.HEIGHT);
|
||||
y += FMenuItem.HEIGHT;
|
||||
}
|
||||
|
||||
return new ScrollBounds(width, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateSizeAndPosition() {
|
||||
FScreen screen = Forge.getCurrentScreen();
|
||||
float screenHeight = screen.getHeight();
|
||||
|
||||
float x = FComboBox.this.localToScreenX(0);
|
||||
float y = FComboBox.this.localToScreenY(FComboBox.this.getHeight());
|
||||
|
||||
paneSize = updateAndGetPaneSize(FComboBox.this.getWidth(), screenHeight - y);
|
||||
|
||||
setBounds(Math.round(x), Math.round(y), Math.round(FComboBox.this.getWidth()), Math.round(paneSize.getHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FDisplayObject getDropDownOwner() {
|
||||
return FComboBox.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user