use of mage.client.cards.CardIconsPanel in project mage by magefree.
the class MageLayer method contains.
@Override
public boolean contains(int x, int y) {
// TODO: is it work with multi layer?
// Mouse coords checking to find a child component under the mouse (example: show card hint on mouse over or button click)
// Swing uses relative coords here (0,0 is component's top left corner)
// WARNING, when you fail a parent coord check then all childs goes to ignore (example: top layer miss check,
// then no card panel get it and no card hints on mouse over)
MageCardLocation needLocation = this.getCardLocation();
// TODO: added contains support for icons hint
// implement idea: use custom "contains" methods for all components structure: from top layer to icon label
// another implement idea: save last AffineTransforms from paint method, translate it to current component and check coords (most accurate method)
// extra size for icons (workaround to fix tooltips over icons)
Rectangle iconsOffset = new Rectangle(0, 0);
if (this.iconsPanels.stream().anyMatch(Component::isVisible)) {
CardIconsPanel samplePanel = this.iconsPanels.stream().findFirst().get();
iconsOffset.x = -samplePanel.getHalfSize();
iconsOffset.y = -samplePanel.getHalfSize();
iconsOffset.height = samplePanel.getHalfSize();
iconsOffset.width = samplePanel.getHalfSize();
}
Rectangle normalRect = new Rectangle(needLocation.getCardRelativeX() + iconsOffset.x, needLocation.getCardRelativeY() + iconsOffset.y, needLocation.getCardWidth() + iconsOffset.width, needLocation.getCardHeight() + iconsOffset.height);
Rectangle animatedRect = animateCoords(this, normalRect);
// debug draw just for color info, real draw will be transformed/animated with card, so you can look at draw rect
if (DebugUtil.GUI_CARD_DRAW_MOUSE_CONTAINS_BOUNDS) {
this.mainLayerDebug.setBounds(animatedRect.x, animatedRect.y, animatedRect.width, animatedRect.height);
if (animatedRect.contains(x, y)) {
this.mainLayerDebug.setBorder(BorderFactory.createLineBorder(Color.green));
} else {
this.mainLayerDebug.setBorder(BorderFactory.createLineBorder(Color.MAGENTA));
}
}
return animatedRect.contains(x, y);
}
use of mage.client.cards.CardIconsPanel in project mage by magefree.
the class MageLayer method updateCardIcons.
private void updateCardIcons(CardView card) {
Map<CardIconsPanel, List<CardIcon>> newIcons = new HashMap<>();
this.iconsPanels.forEach(panel -> newIcons.put(panel, new ArrayList<>()));
List<CardIcon> allIcons = new ArrayList<>();
// main icons
allIcons.addAll(card.getCardIcons());
// playable icons
if (card.getPlayableStats().getPlayableImportantAmount() > 0) {
allIcons.add(new PlayableCountIcon(card.getPlayableStats()));
}
// create panels
allIcons.forEach(cardIcon -> {
CardIconCategory category = cardIcon.getIconType().getCategory();
// debug panel must take all icons (position depends on render settings)
if (iconsDebugPanel != null) {
newIcons.get(iconsDebugPanel).add(cardIcon);
}
// playable panel (bottom left corner)
if (iconsPlayablePanel != null && category == CardIconCategory.PLAYABLE_COUNT) {
newIcons.get(iconsPlayablePanel).add(cardIcon);
}
// abilities panel (left side)
if (iconsAbilitiesPanel != null && category == CardIconCategory.ABILITY) {
newIcons.get(iconsAbilitiesPanel).add(cardIcon);
}
// commander panel (top center)
if (iconsCommanderPanel != null && category == CardIconCategory.COMMANDER) {
newIcons.get(iconsCommanderPanel).add(cardIcon);
}
});
this.iconsPanels.forEach(panel -> panel.updateIcons(newIcons.get(panel)));
}
Aggregations