public ModifyPlayerPopup(Player playerPassed, Screen callerScreen, Team team) { cancel.addActionListener( (ActionEvent e) -> { Cain.dispose(); }); save.addActionListener( (ActionEvent e) -> { player.name = name.getText(); if (player.globalIndex == -1) { player.savePlayer(); } else { Global.Players.set(player.globalIndex, player); player.writePlayer(); } if (team != null) { team.addPlayer(player); } callerScreen.refresh(); Cain.dispose(); }); if (playerPassed != null) { // We're editing a current player player = playerPassed; for (Hero hero : player.getPlayList()) { JLabel heroLabel = new JLabel(hero.portraitSmall); heroLabel.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { player.removeHero(hero); refresh(); } }); heroes.add(heroLabel); } name.setText(player.name); } else { // This is a new Player Cain.setTitle("Add a player"); player = new Player("New Player"); } addHeroes.setMargin(new Insets(0, 0, 0, 0)); addHeroes.addActionListener( (ActionEvent e) -> { pool = new PoolBuilder(false, "small", new Returner(), player.getPlayList()); back = new JButton("Cancel"); back.addActionListener( (ActionEvent p) -> { inner.removeAll(); popup.dispose(); }); JLabel note = new JLabel("Right click to add multiple heroes."); inner.add(back, "wrap"); inner.add(note, "wrap"); inner.add(pool.pool, "growx"); popup.add(inner); popup.setSize(700, 500); popup.setLocation(MouseInfo.getPointerInfo().getLocation()); popup.setVisible(true); }); name.setFont(new Font("Ariel", Font.PLAIN, 20)); name.select(0, name.getText().length()); heroes.setBorder(BorderFactory.createLineBorder(Color.black)); south.add(addHeroes); south.add(new JLabel("Heroes")); south.add(heroes, "span, grow"); south.add(cancel, "span, right, split 2"); south.add(save, "span, right"); Enoch.add(name); Enoch.add(south); Cain.add(Enoch); Cain.setMinimumSize(new Dimension(400, 350)); Cain.setVisible(true); }
void drawScreen() { Eve.add(back, "span 2"); Eve.add(info, "spany 2, grow"); Eve.add(addB); Eve.add(label); Eve.add(viewScroll, "span, grow"); switch (type) { case "team": label.setText("Teams:"); if (Global.Teams.isEmpty()) { view.add(new JLabel("No teams to display")); } else { for (Team team : Global.Teams) { JPanel thisTeam = team.teamPreview(); JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16)); modify.setMargin(new Insets(0, 0, 0, 0)); modify.addActionListener( (ActionEvent e) -> { called = new ModifyTeamScreen(team, this); called.Switch(); }); JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16)); delete.setMargin(new Insets(0, 0, 0, 0)); delete.addActionListener( (ActionEvent e) -> { Object[] options = {"Yes", "No"}; JFrame frame = new JFrame(); int answer = JOptionPane.showOptionDialog( frame, "Are you sure you would like to delete team \"" + team.name + "?\"", "Confirm Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, Global.QUESTIONPIC, options, options[1]); if (answer == 0) { team.delete(); refresh(); } }); thisTeam.add(delete, "east"); thisTeam.add(modify, "east"); thisTeam.setBorder(BorderFactory.createLineBorder(Color.black)); view.add(thisTeam, "growx"); } } break; case "player": label.setText("Players:"); if (Global.Players.isEmpty()) { view.add(new JLabel("No players to display")); } else { for (Player player : Global.Players) { JPanel thisPlayer = player.playerPreview(); JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16)); modify.setMargin(new Insets(0, 0, 0, 0)); modify.addActionListener( (ActionEvent e) -> { new ModifyPlayerPopup(player, this, null); }); JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16)); delete.setMargin(new Insets(0, 0, 0, 0)); delete.addActionListener( (ActionEvent e) -> { Object[] options = {"I didn't like him anyways...", "No"}; JFrame frame = new JFrame(); int answer = JOptionPane.showOptionDialog( frame, "Are you sure you would like to delete \"" + player.name + "?\"", "Confirm Delete", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, Global.QUESTIONPIC, options, options[1]); if (answer == 0) { player.delete(); refresh(); } }); thisPlayer.add(delete, "east"); thisPlayer.add(modify, "east"); thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black)); view.add(thisPlayer, "growx"); } } break; } }