mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Merge branch 'ui-improvements' into 'master'
UI Improvements See merge request core-developers/forge!1130
This commit is contained in:
@@ -147,27 +147,72 @@ public final class DeckManager extends ItemManager<DeckProxy> implements IHasGam
|
|||||||
return new DeckSearchFilter(this);
|
return new DeckSearchFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, HashMap> buildHierarchy(String path) {
|
||||||
|
if (path.startsWith("/")) {
|
||||||
|
path = path.substring(1);
|
||||||
|
}
|
||||||
|
Map hierarchy = new HashMap();
|
||||||
|
String[] components = path.split("/", 2);
|
||||||
|
Map value = new HashMap();
|
||||||
|
if (components.length > 1) {
|
||||||
|
value = buildHierarchy(components[1]);
|
||||||
|
}
|
||||||
|
hierarchy.put("/" + components[0], value);
|
||||||
|
return hierarchy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// borrowed from: https://stackoverflow.com/a/46052477
|
||||||
|
private void merge(Map<String, HashMap> mapLeft, Map<String, HashMap> mapRight) {
|
||||||
|
// go over all the keys of the right map
|
||||||
|
for (String key : mapRight.keySet()) {
|
||||||
|
// if the left map already has this key, merge the maps that are behind that key
|
||||||
|
if (mapLeft.containsKey(key)) {
|
||||||
|
merge(mapLeft.get(key), mapRight.get(key));
|
||||||
|
} else {
|
||||||
|
// otherwise just add the map under that key
|
||||||
|
mapLeft.put(key, mapRight.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildNestedMenu(Map tree, JMenu menu, String parentPath) {
|
||||||
|
if (tree.size() > 0) {
|
||||||
|
for (final Object key : tree.keySet()) {
|
||||||
|
String fullPath = key.toString();
|
||||||
|
if (parentPath != null) {
|
||||||
|
fullPath = parentPath + key.toString();
|
||||||
|
}
|
||||||
|
String finalFullPath = fullPath;
|
||||||
|
GuiUtils.addMenuItem(menu, key.toString(), null, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
addFilter(new DeckFolderFilter(DeckManager.this, finalFullPath));
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
Map value = (Map) tree.get(key);
|
||||||
|
if (value.size() > 0) {
|
||||||
|
final JMenu submenu = GuiUtils.createMenu(key.toString());
|
||||||
|
buildNestedMenu(value, submenu, finalFullPath);
|
||||||
|
menu.add(submenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildAddFilterMenu(final JMenu menu) {
|
protected void buildAddFilterMenu(final JMenu menu) {
|
||||||
GuiUtils.addSeparator(menu); //separate from current search item
|
GuiUtils.addSeparator(menu); //separate from current search item
|
||||||
|
|
||||||
final SortedSet<String> folders = new TreeSet<String>();
|
Map hierarchy = new HashMap();
|
||||||
for (final Entry<DeckProxy, Integer> deckEntry : getPool()) {
|
for (final Entry<DeckProxy, Integer> deckEntry : getPool()) {
|
||||||
final String path = deckEntry.getKey().getPath();
|
final String path = deckEntry.getKey().getPath();
|
||||||
if (StringUtils.isNotEmpty(path)) { //don't include root folder as option
|
if (StringUtils.isNotEmpty(path)) { //don't include root folder as option
|
||||||
folders.add(path);
|
merge(hierarchy, buildHierarchy(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final JMenu folder = GuiUtils.createMenu("Folder");
|
final JMenu folder = GuiUtils.createMenu("Folder");
|
||||||
if (folders.size() > 0) {
|
if (hierarchy.size() > 0) {
|
||||||
for (final String f : folders) {
|
buildNestedMenu(hierarchy, folder, null);
|
||||||
GuiUtils.addMenuItem(folder, f, null, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
addFilter(new DeckFolderFilter(DeckManager.this, f));
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
folder.setEnabled(false);
|
folder.setEnabled(false);
|
||||||
|
|||||||
@@ -71,21 +71,22 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCardSelected(final Card card, final List<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) {
|
protected boolean onCardSelected(final Card card, final List<Card> otherCardsToSelect, final ITriggerEvent triggerEvent) {
|
||||||
if (otherCardsToSelect != null) {
|
if (card.getManaAbilities().size() == 1) {
|
||||||
for (Card c : otherCardsToSelect) {
|
activateManaAbility(card, card.getManaAbilities().get(0));
|
||||||
for (SpellAbility sa : c.getManaAbilities()) {
|
} else {
|
||||||
if (sa.canPlay()) {
|
SpellAbilityView spellAbilityView;
|
||||||
delaySelectCards.add(c);
|
HashMap<SpellAbilityView, SpellAbility> spellAbilityViewMap = new HashMap<>();
|
||||||
break;
|
for (SpellAbility sa : card.getManaAbilities()) {
|
||||||
|
spellAbilityViewMap.put(sa.getView(), sa);
|
||||||
|
}
|
||||||
|
List<SpellAbilityView> choices = new ArrayList<>(spellAbilityViewMap.keySet());
|
||||||
|
spellAbilityView = getController().getGui().getAbilityToPlay(card.getView(), choices, triggerEvent);
|
||||||
|
if (spellAbilityView != null) {
|
||||||
|
activateManaAbility(card, spellAbilityViewMap.get(spellAbilityView));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!card.getManaAbilities().isEmpty() && activateManaAbility(card, manaCost)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return activateDelayedCard();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getActivateAction(Card card) {
|
public String getActivateAction(Card card) {
|
||||||
@@ -105,7 +106,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
delaySelectCards.clear(); //clear delayed cards if mana cost already paid
|
delaySelectCards.clear(); //clear delayed cards if mana cost already paid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (activateManaAbility(delaySelectCards.poll(), manaCost)) {
|
if (activateManaAbility(delaySelectCards.poll())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return activateDelayedCard();
|
return activateDelayedCard();
|
||||||
@@ -114,7 +115,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
@Override
|
@Override
|
||||||
public boolean selectAbility(final SpellAbility ab) {
|
public boolean selectAbility(final SpellAbility ab) {
|
||||||
if (ab != null && ab.isManaAbility()) {
|
if (ab != null && ab.isManaAbility()) {
|
||||||
return activateManaAbility(ab.getHostCard(), manaCost, ab);
|
return activateManaAbility(ab.getHostCard(), ab);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -165,10 +166,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean activateManaAbility(final Card card, ManaCostBeingPaid manaCost) {
|
protected boolean activateManaAbility(final Card card) {
|
||||||
return activateManaAbility(card, manaCost, null);
|
return activateManaAbility(card, null);
|
||||||
}
|
}
|
||||||
protected boolean activateManaAbility(final Card card, ManaCostBeingPaid manaCost, SpellAbility chosenAbility) {
|
protected boolean activateManaAbility(final Card card, SpellAbility chosenAbility) {
|
||||||
if (locked) {
|
if (locked) {
|
||||||
System.err.print("Should wait till previous call to playAbility finishes.");
|
System.err.print("Should wait till previous call to playAbility finishes.");
|
||||||
return false;
|
return false;
|
||||||
@@ -231,7 +232,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abilitiesMap.isEmpty() || (chosenAbility != null && !abilitiesMap.containsKey(chosenAbility))) {
|
if (abilitiesMap.isEmpty() || (chosenAbility != null && !abilitiesMap.containsKey(chosenAbility.getView()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user