Search in sources :

Example 1 with CardIconsPanel

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);
}
Also used : MageCardLocation(mage.cards.MageCardLocation) CardIconsPanel(mage.client.cards.CardIconsPanel)

Example 2 with CardIconsPanel

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)));
}
Also used : HashMap(java.util.HashMap) CardIconsPanel(mage.client.cards.CardIconsPanel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PlayableCountIcon(mage.abilities.icon.system.PlayableCountIcon) CardIcon(mage.abilities.icon.CardIcon) CardIconCategory(mage.abilities.icon.CardIconCategory)

Aggregations

CardIconsPanel (mage.client.cards.CardIconsPanel)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CardIcon (mage.abilities.icon.CardIcon)1 CardIconCategory (mage.abilities.icon.CardIconCategory)1 PlayableCountIcon (mage.abilities.icon.system.PlayableCountIcon)1 MageCardLocation (mage.cards.MageCardLocation)1