/** * Controls Swing components of a player's field instance. * * @param player0   {@link forge.game.player.Player} * @param v0   {@link forge.screens.match.views.VField} * @param playerViewer */ public CField(final PlayerView player0, final VField v0) { this.player = player0; this.view = v0; final ZoneAction handAction = new ZoneAction(player, ZoneType.Hand, MatchConstants.HUMANHAND); final ZoneAction libraryAction = new ZoneAction(player, ZoneType.Library, MatchConstants.HUMANLIBRARY); final ZoneAction exileAction = new ZoneAction(player, ZoneType.Exile, MatchConstants.HUMANEXILED); final ZoneAction graveAction = new ZoneAction(player, ZoneType.Graveyard, MatchConstants.HUMANGRAVEYARD); final ZoneAction flashBackAction = new ZoneAction(player, ZoneType.Flashback, MatchConstants.HUMANFLASHBACK); Function<Byte, Void> manaAction = new Function<Byte, Void>() { public Void apply(Byte colorCode) { if (CField.this.player.getLobbyPlayer() == Singletons.getControl().getGuiPlayer()) { MatchUtil.getHumanController().useMana(colorCode.byteValue()); } return null; } }; view.getDetailsPanel() .setupMouseActions( handAction, libraryAction, exileAction, graveAction, flashBackAction, manaAction); }
@Override public void populate() { // Dev mode disabled? Remove from parent cell if exists. if (!ForgePreferences.DEV_MODE) { if (VDev.SINGLETON_INSTANCE.getParentCell() != null) { final DragCell parent = VDev.SINGLETON_INSTANCE.getParentCell(); parent.removeDoc(VDev.SINGLETON_INSTANCE); VDev.SINGLETON_INSTANCE.setParentCell(null); // If dev mode was first tab, the new first tab needs re-selecting. if (parent.getDocs().size() > 0) { parent.setSelected(parent.getDocs().get(0)); } } } // Dev mode enabled? May already by added, or put in message cell by default. else { if (VDev.SINGLETON_INSTANCE.getParentCell() == null) { VPrompt.SINGLETON_INSTANCE.getParentCell().addDoc(VDev.SINGLETON_INSTANCE); } } // Clear previous match views if screen was previously closed if (wasClosed) { wasClosed = false; } else { // focus first enabled Prompt button if returning to match screen if (getBtnOK().isEnabled()) { getBtnOK().requestFocusInWindow(); } else if (getBtnCancel().isEnabled()) { getBtnCancel().requestFocusInWindow(); } } // Add extra players alternatively to existing user/AI field panels. for (int i = 2; i < lstFields.size(); i++) { // If already in layout, no need to add again. VField vField = lstFields.get(i); if (vField.getParentCell() == null) { lstFields.get(i % 2).getParentCell().addDoc(vField); } } // Add extra players alternatively to existing user/AI field panels. for (int i = 2; i < lstCommands.size(); i++) { // If already in layout, no need to add again. VCommand cmdView = lstCommands.get(i); if (cmdView.getParentCell() == null) { lstCommands.get(i % 2).getParentCell().addDoc(cmdView); } } // Add extra hands to existing hand panel. for (int i = 1; i < lstHands.size(); i++) { // If already in layout, no need to add again. if (lstHands.get(i).getParentCell() == null) { // if i == 0, we get NPE in two lines DragCell cellWithHand = lstHands.get(0).getParentCell(); cellWithHand.addDoc(lstHands.get(i)); } } // Remove any hand panels that aren't needed anymore for (int i = EDocID.Hands.length - 1; i >= lstHands.size(); i--) { DragCell cellWithHand = EDocID.Hands[i].getDoc().getParentCell(); if (cellWithHand != null) { cellWithHand.removeDoc(EDocID.Hands[i].getDoc()); EDocID.Hands[i].setDoc(new VEmptyDoc(EDocID.Hands[i])); } } // Fill in gaps SwingUtilities.invokeLater( new Runnable() { @Override public void run() { for (final DragCell c : FView.SINGLETON_INSTANCE.getDragCells()) { if (c.getDocs().isEmpty()) { SRearrangingUtil.fillGap(c); FView.SINGLETON_INSTANCE.removeDragCell(c); } } } }); }