public CardPanel getCardPanelForCard(Card card) { CardPanel found = null; Iterator<PlayerPanel> playerPanelIt = players.iterator(); while (playerPanelIt.hasNext() && found == null) { PlayerPanel pPanel = playerPanelIt.next(); CardZonePanel panel = pPanel.getHandPanel(); found = panel.getCardPanelForCard(card); if (found == null) { panel = pPanel.getFieldPanel(); found = panel.getCardPanelForCard(card); } } return found; }
public CardZonePanel getCardZonePanelForCardZone(CardZone zone) { CardZonePanel found = null; Iterator<PlayerPanel> playerPanelIt = players.iterator(); while (playerPanelIt.hasNext() && found == null) { PlayerPanel pPanel = playerPanelIt.next(); CardZonePanel panel = pPanel.getHandPanel(); if (panel.getCardZone().equals(zone)) found = panel; else { panel = pPanel.getFieldPanel(); if (panel.getCardZone().equals(zone)) found = panel; } } return found; }
public void update() { // System.out.println("UPDATING VIEW FOR UPDATE " + Engine.getCurrentTopUpdateID()); refreshPlayers(); refreshPlayerLifeTotals(); refreshPlayerPhases(); refreshHandsVisible(); StateChangeManager changeManager = game.getCurrentStateChangeManager(); HashSet<CardMovement> movements = changeManager.getCardMovement(); for (CardMovement movement : movements) { CardZone beginningZone = movement.getBeginningZone(); CardZone endZone = movement.getEndZone(); Card card = movement.getCardMoved(); // System.out.println(card.getName()); CardPanel cardPanel = getCardPanelForCard(card); CardZonePanel beginZonePanel = getCardZonePanelForCardZone(beginningZone); CardZonePanel endZonePanel = getCardZonePanelForCardZone(endZone); if (cardPanel == null && beginZonePanel == null && endZonePanel == null) { // System.out.println("what is goin on"); // do nothing } else if (beginZonePanel == null && endZonePanel == null) { // System.out.println("something went completely wrong, but..."); } else if (cardPanel == null && endZonePanel == null) { // System.out.println("went from a zone we know of to zone we don't, but the card wasn't // showing in the zone we know before. actually kind of impossible, but too late for us to // do anything"); } else if (cardPanel == null && beginZonePanel == null) { // System.out.println("came to a zone we know from an unknown zone!!!! looks like meat's // back on the menu, boys!!!!!"); // came to a zone we know from an unknown zone!!!! looks like meat's back on the menu, // boys!!!!! endZonePanel.addCardPanel(new CardPanel(card)); } else if (cardPanel == null) { // System.out.println("well, it should have been showing before, but I guess better late // than never!"); endZonePanel.addCardPanel(new CardPanel(card)); } else if (beginZonePanel == null) { // System.out.println("this also shouldn't have happened, very weird."); endZonePanel.addCardPanel(cardPanel); } else if (endZonePanel == null) { // System.out.println("hey there"); // the card is exiting the realm of displayed cardzones. Bon voyage! beginZonePanel.removeCardPanel(cardPanel); } else { // we're displaying every piece involved in this move!!!!! nice!!! beginZonePanel.removeCardPanel(cardPanel); endZonePanel.addCardPanel(cardPanel); } } refreshCardPanels(); // ayayay java needs me to repaint otherwise it waits forever repaint(); }