@Override public final void onLeftClick(final MouseEvent e) { if (!avatarLabel.isEnabled()) { return; } final FLabel avatar = (FLabel) e.getSource(); lobby.changePlayerFocus(index); avatar.requestFocusInWindow(); final AvatarSelector aSel = new AvatarSelector(playerName, avatarIndex, lobby.getUsedAvatars()); for (final FLabel lbl : aSel.getSelectables()) { lbl.setCommand( new UiCommand() { @Override public void run() { setAvatarIndex(Integer.valueOf(lbl.getName().substring(11))); aSel.setVisible(false); } }); } aSel.setVisible(true); aSel.dispose(); if (index < 2) { lobby.updateAvatarPrefs(); } lobby.firePlayerChangeListener(index); }
@SuppressWarnings("unchecked") @Override public final void actionPerformed(final ActionEvent e) { final FComboBox<Object> cb = (FComboBox<Object>) e.getSource(); cb.requestFocusInWindow(); final Object selection = cb.getSelectedItem(); if (null != selection) { lobby.changePlayerFocus(index); lobby.firePlayerChangeListener(index); } }
private void setRandomAvatar(final boolean fireListeners) { int random = 0; final List<Integer> usedAvatars = lobby.getUsedAvatars(); do { random = MyRandom.getRandom().nextInt(FSkin.getAvatars().size()); } while (usedAvatars.contains(random)); setAvatarIndex(random); if (fireListeners) { lobby.firePlayerChangeListener(index); } }
@Override public final void onRightClick(final MouseEvent e) { if (!avatarLabel.isEnabled()) { return; } lobby.changePlayerFocus(index); avatarLabel.requestFocusInWindow(); setRandomAvatar(); if (index < 2) { lobby.updateAvatarPrefs(); } }
private void updateVariantControlsVisibility() { final boolean isTinyLeaders = lobby.hasVariant(GameType.TinyLeaders); final boolean isCommanderApplied = mayEdit && (lobby.hasVariant(GameType.Commander) || isTinyLeaders); final boolean isPlanechaseApplied = mayEdit && lobby.hasVariant(GameType.Planechase); final boolean isVanguardApplied = mayEdit && lobby.hasVariant(GameType.Vanguard); final boolean isArchenemyApplied = mayEdit && lobby.hasVariant(GameType.Archenemy); final boolean archenemyVisiblity = mayEdit && lobby.hasVariant(GameType.ArchenemyRumble) || (isArchenemyApplied && isArchenemy()); // Commander deck building replaces normal one, so hide it final boolean isDeckBuildingAllowed = mayEdit && !isCommanderApplied && !lobby.hasVariant(GameType.MomirBasic); deckLabel.setVisible(isDeckBuildingAllowed); deckBtn.setVisible(isDeckBuildingAllowed); cmdDeckSelectorBtn.setVisible(isCommanderApplied); cmdDeckEditor.setText(isTinyLeaders ? "TL Deck Editor" : "Commander Deck Editor"); cmdDeckEditor.setVisible(isCommanderApplied); cmdLabel.setVisible(isCommanderApplied); scmDeckSelectorBtn.setVisible(archenemyVisiblity); scmDeckEditor.setVisible(archenemyVisiblity); scmLabel.setVisible(archenemyVisiblity); teamComboBox.setVisible(!isArchenemyApplied); aeTeamComboBox.setVisible(isArchenemyApplied); pchDeckSelectorBtn.setVisible(isPlanechaseApplied); pchDeckEditor.setVisible(isPlanechaseApplied); pchLabel.setVisible(isPlanechaseApplied); vgdSelectorBtn.setVisible(isVanguardApplied); vgdLabel.setVisible(isVanguardApplied); }
@Override public void focusLost(final FocusEvent e) { final Object source = e.getSource(); if (source instanceof FTextField) { // the text box final FTextField nField = (FTextField) source; final String newName = nField.getText().trim(); if (index == 0 && !StringUtils.isBlank(newName) && StringUtils.isAlphanumericSpace(newName) && prefs.getPref(FPref.PLAYER_NAME) != newName) { prefs.setPref(FPref.PLAYER_NAME, newName); prefs.save(); } lobby.firePlayerChangeListener(index); } }
/** * @param index * @return */ private void createNameEditor() { String name; if (index == 0) { name = FModel.getPreferences().getPref(FPref.PLAYER_NAME); if (name.isEmpty()) { name = "Human"; } } else { name = NameGenerator.getRandomName("Any", "Any", lobby.getPlayerNames()); } txtPlayerName.setText(name); txtPlayerName.setFocusable(true); txtPlayerName.setFont(FSkin.getFont(14)); txtPlayerName.addActionListener(lobby.nameListener); txtPlayerName.addFocusListener(nameFocusListener); }
private boolean hasFocusInLobby() { return lobby.hasFocus(index); }
@Override public void focusGained(final FocusEvent e) { lobby.changePlayerFocus(index); }
public PlayerPanel( final VLobby lobby, final boolean allowNetworking, final int index, final LobbySlot slot, final boolean mayEdit, final boolean mayControl) { super(); this.lobby = lobby; this.index = index; this.mayEdit = mayEdit; this.mayControl = mayControl; this.deckLabel = lobby.newLabel("Deck:"); this.scmLabel = lobby.newLabel("Scheme deck:"); this.cmdLabel = lobby.newLabel("Commander deck:"); this.pchLabel = lobby.newLabel("Planar deck:"); this.vgdLabel = lobby.newLabel("Vanguard:"); setLayout(new MigLayout("insets 10px, gap 5px")); // Add a button to players 3+ (or if server) to remove them from the setup closeBtn = createCloseButton(); this.add(closeBtn, "w 20, h 20, pos (container.w-20) 0"); createAvatar(); this.add(avatarLabel, "spany 2, width 80px, height 80px"); createNameEditor(); this.add(lobby.newLabel("Name:"), "w 40px, h 30px, gaptop 5px"); this.add(txtPlayerName, "h 30px, pushx, growx"); nameRandomiser = createNameRandomizer(); this.add(nameRandomiser, "h 30px, w 30px, gaptop 5px"); createPlayerTypeOptions(); this.add(radioHuman, "gapright 5px"); this.add(radioAi, "wrap"); this.add(lobby.newLabel("Team:"), "w 40px, h 30px"); populateTeamsComboBoxes(); // Set these before action listeners are added this.setTeam(slot == null ? index : slot.getTeam()); this.setIsArchenemy(slot != null && slot.isArchenemy()); teamComboBox.addActionListener(teamListener); aeTeamComboBox.addActionListener(teamListener); teamComboBox.addTo(this, variantBtnConstraints + ", pushx, growx, gaptop 5px"); aeTeamComboBox.addTo(this, variantBtnConstraints + ", pushx, growx, gaptop 5px"); createReadyButton(); if (allowNetworking) { this.add(radioOpen, "cell 4 1, ax left, sx 2"); this.add(chkReady, "cell 5 1, ax left, sx 2, wrap"); } this.add(deckLabel, variantBtnConstraints + ", cell 0 2, sx 2, ax right"); this.add( deckBtn, variantBtnConstraints + ", cell 2 2, pushx, growx, wmax 100%-153px, h 30px, spanx 4, wrap"); addHandlersDeckSelector(); this.add(cmdLabel, variantBtnConstraints + ", cell 0 3, sx 2, ax right"); this.add(cmdDeckSelectorBtn, variantBtnConstraints + ", cell 2 3, growx, pushx"); this.add(cmdDeckEditor, variantBtnConstraints + ", cell 3 3, sx 3, growx, wrap"); this.add(scmLabel, variantBtnConstraints + ", cell 0 4, sx 2, ax right"); this.add(scmDeckSelectorBtn, variantBtnConstraints + ", cell 2 4, growx, pushx"); this.add(scmDeckEditor, variantBtnConstraints + ", cell 3 4, sx 3, growx, wrap"); this.add(pchLabel, variantBtnConstraints + ", cell 0 5, sx 2, ax right"); this.add(pchDeckSelectorBtn, variantBtnConstraints + ", cell 2 5, growx, pushx"); this.add(pchDeckEditor, variantBtnConstraints + ", cell 3 5, sx 3, growx, wrap"); this.add(vgdLabel, variantBtnConstraints + ", cell 0 6, sx 2, ax right"); this.add(vgdSelectorBtn, variantBtnConstraints + ", cell 2 6, sx 4, growx, wrap"); addHandlersToVariantsControls(); this.addMouseListener( new FMouseAdapter() { @Override public final void onLeftMouseDown(final MouseEvent e) { avatarLabel.requestFocusInWindow(); } }); this.type = slot == null ? LobbySlotType.LOCAL : slot.getType(); this.setPlayerName(slot == null ? "" : slot.getName()); this.setAvatarIndex(slot == null ? 0 : slot.getAvatarIndex()); update(); }