mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Added manual avatar selection to constructed match setup.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -15345,6 +15345,7 @@ forge-gui/src/main/java/forge/gui/home/quest/VSubmenuQuestData.java -text
|
|||||||
forge-gui/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java -text
|
forge-gui/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java -text
|
||||||
forge-gui/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java -text
|
forge-gui/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java -text
|
||||||
forge-gui/src/main/java/forge/gui/home/quest/package-info.java svneol=native#text/plain
|
forge-gui/src/main/java/forge/gui/home/quest/package-info.java svneol=native#text/plain
|
||||||
|
forge-gui/src/main/java/forge/gui/home/sanctioned/AvatarSelector.java -text
|
||||||
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuConstructed.java -text
|
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuConstructed.java -text
|
||||||
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java -text
|
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java -text
|
||||||
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java -text
|
forge-gui/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java -text
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package forge.gui.home.sanctioned;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import forge.gui.WrapLayout;
|
||||||
|
import forge.gui.toolbox.FLabel;
|
||||||
|
import forge.gui.toolbox.FScrollPane;
|
||||||
|
import forge.gui.toolbox.FSkin;
|
||||||
|
import forge.gui.toolbox.FSkin.SkinImage;
|
||||||
|
import forge.view.FDialog;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class AvatarSelector extends FDialog {
|
||||||
|
private List<FLabel> selectables = new ArrayList<FLabel>();
|
||||||
|
private final Map<Integer, SkinImage> avatarMap = FSkin.getAvatars();
|
||||||
|
|
||||||
|
public final void show(final AvatarSelector aSelector) {
|
||||||
|
aSelector.setVisible(true);
|
||||||
|
aSelector.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AvatarSelector(final int currentIndex, final Collection<Integer> usedIndices) {
|
||||||
|
final JPanel pnlAvatarPics = new JPanel(new WrapLayout());
|
||||||
|
|
||||||
|
pnlAvatarPics.setOpaque(false);
|
||||||
|
pnlAvatarPics.setOpaque(false);
|
||||||
|
|
||||||
|
FLabel initialSelection = makeAvatarLabel(avatarMap.get(currentIndex), currentIndex, currentIndex);
|
||||||
|
pnlAvatarPics.add(initialSelection);
|
||||||
|
for (final Integer i : avatarMap.keySet()) {
|
||||||
|
//if (!usedIndices.contains(i)) { // Decided to allow duplicate avatars when manually selecting
|
||||||
|
if (currentIndex != i) {
|
||||||
|
pnlAvatarPics.add(makeAvatarLabel(avatarMap.get(i), i, currentIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int width = (int) (this.getOwner().getWidth() * .8);
|
||||||
|
final int height = (int) (this.getOwner().getHeight() * .8);
|
||||||
|
this.setPreferredSize(new Dimension(width, height));
|
||||||
|
this.setSize(width, height);
|
||||||
|
|
||||||
|
FScrollPane scroller = new FScrollPane(pnlAvatarPics);
|
||||||
|
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
this.add(scroller, "w 90%!, pushy, growy, gap 5% 0 0 0");
|
||||||
|
initialSelection.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private FLabel makeAvatarLabel(final SkinImage img0, final int index0, final int oldIndex) {
|
||||||
|
final FLabel lbl = new FLabel.Builder().icon(img0).iconScaleFactor(0.95).iconAlignX(SwingConstants.CENTER)
|
||||||
|
.iconInBackground(true).hoverable(true).selectable(true).selected(oldIndex == index0)
|
||||||
|
.unhoveredAlpha(oldIndex == index0 ? 0.9f : 0.7f).build();
|
||||||
|
|
||||||
|
final Dimension size = new Dimension(80, 80);
|
||||||
|
lbl.setPreferredSize(size);
|
||||||
|
lbl.setMaximumSize(size);
|
||||||
|
lbl.setMinimumSize(size);
|
||||||
|
lbl.setName("AvatarLabel" + index0);
|
||||||
|
|
||||||
|
if (oldIndex == index0) {
|
||||||
|
lbl.setBorder(new FSkin.LineSkinBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS).alphaColor(255), 3));;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectables.add(lbl);
|
||||||
|
|
||||||
|
return lbl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FLabel> getSelectables() {
|
||||||
|
return this.selectables;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -397,9 +397,13 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
random = MyRandom.getRandom().nextInt(FSkin.getAvatars().size());
|
random = MyRandom.getRandom().nextInt(FSkin.getAvatars().size());
|
||||||
} while (usedAvatars.values().contains(random));
|
} while (usedAvatars.values().contains(random));
|
||||||
|
|
||||||
avatar.setIcon(FSkin.getAvatars().get(random));
|
setAvatar(avatar, playerIndex, random);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAvatar(FLabel avatar, int playerIndex, int newAvatarIndex) {
|
||||||
|
avatar.setIcon(FSkin.getAvatars().get(newAvatarIndex));
|
||||||
avatar.repaintSelf();
|
avatar.repaintSelf();
|
||||||
usedAvatars.put(playerIndex, random);
|
usedAvatars.put(playerIndex, newAvatarIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builds the actual deck panel layouts for each player.
|
/** Builds the actual deck panel layouts for each player.
|
||||||
@@ -696,15 +700,26 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private FMouseAdapter avatarMouseListener = new FMouseAdapter() {
|
private FMouseAdapter avatarMouseListener = new FMouseAdapter() {
|
||||||
|
@SuppressWarnings("serial")
|
||||||
@Override
|
@Override
|
||||||
public void onLeftClick(MouseEvent e) {
|
public void onLeftClick(MouseEvent e) {
|
||||||
FLabel avatar = (FLabel)e.getSource();
|
final FLabel avatar = (FLabel)e.getSource();
|
||||||
int playerIndex = avatarList.indexOf(avatar);
|
final int playerIndex = avatarList.indexOf(avatar);
|
||||||
|
|
||||||
changePlayerFocus(playerIndex);
|
changePlayerFocus(playerIndex);
|
||||||
|
|
||||||
avatar.grabFocus();
|
final AvatarSelector aSel = new AvatarSelector(usedAvatars.get(playerIndex), usedAvatars.values());
|
||||||
// TODO: Do avatar selection, giving current avatar focus for keyboard control
|
for (final FLabel lbl : aSel.getSelectables()) {
|
||||||
|
lbl.setCommand(new Command() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
VSubmenuConstructed.this.setAvatar(avatar, playerIndex, Integer.valueOf(lbl.getName().substring(11)));
|
||||||
|
aSel.setVisible(false);
|
||||||
|
avatar.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
aSel.show(aSel);
|
||||||
|
|
||||||
if (playerIndex < 2) { updateAvatarPrefs(); }
|
if (playerIndex < 2) { updateAvatarPrefs(); }
|
||||||
}
|
}
|
||||||
@@ -716,7 +731,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
|
|||||||
changePlayerFocus(playerIndex);
|
changePlayerFocus(playerIndex);
|
||||||
|
|
||||||
setRandomAvatar(avatar, playerIndex);
|
setRandomAvatar(avatar, playerIndex);
|
||||||
avatar.grabFocus();
|
avatar.requestFocusInWindow();
|
||||||
|
|
||||||
if (playerIndex < 2) { updateAvatarPrefs(); }
|
if (playerIndex < 2) { updateAvatarPrefs(); }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user