View Javadoc
1   // %3759572477:hoplugins.trainingExperience.ui%
2   package hoplugins.trainingExperience.ui;
3   
4   import hoplugins.Commons;
5   import hoplugins.TrainingExperience;
6   
7   import hoplugins.commons.utils.PluginProperty;
8   
9   import hoplugins.trainingExperience.constants.Skills;
10  import hoplugins.trainingExperience.ui.bar.StateBar;
11  
12  import plugins.IFuturePlayer;
13  import plugins.IFutureTrainingManager;
14  import plugins.IHOMiniModel;
15  import plugins.ISkillup;
16  import plugins.ISpieler;
17  
18  import java.awt.BorderLayout;
19  import java.awt.Color;
20  import java.awt.GridLayout;
21  
22  import java.util.Iterator;
23  import java.util.List;
24  
25  import javax.swing.JLabel;
26  import javax.swing.JPanel;
27  
28  
29  /***
30   * Panel where are shown future trainings predictions
31   *
32   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
33   */
34  public class PlayerDetailPanel extends JPanel {
35      //~ Instance fields ----------------------------------------------------------------------------
36  
37      private JLabel playerLabel = new JLabel("", JLabel.CENTER); //$NON-NLS-1$
38      private StateBar[][] bars = new StateBar[8][3];
39      private JLabel[] skillLabel = new JLabel[8];
40  
41      //~ Constructors -------------------------------------------------------------------------------
42  
43      /***
44       * Creates the panel and its components
45       */
46      public PlayerDetailPanel() {
47          super();
48          jbInit();
49      }
50  
51      //~ Methods ------------------------------------------------------------------------------------
52  
53      /***
54       * Method that populate this panel for the selected player
55       *
56       * @param spieler player
57       */
58      public void reload(ISpieler spieler) {
59          if (spieler == null) {
60              playerLabel.setText(PluginProperty.getString("PlayerSelect")); //$NON-NLS-1$
61  
62              for (int i = 0; i < 8; i++) {
63                  skillLabel[i].setText(""); //$NON-NLS-1$
64                  bars[i][0].change(0, 0);
65                  bars[i][1].change(0, 0);
66                  bars[i][2].change(0, 0);
67              }
68  
69              return;
70          }
71  
72          // sets player number
73          playerLabel.setText(spieler.getName());
74  
75          // gets the list of user defined future trainings
76          List trainings = TrainingExperience.getTrainPanel().getFutureTrainings();
77  
78          // instantiate a future train manager to calculate the previsions */ 
79          IFutureTrainingManager ftm = Commons.getModel().getFutureTrainingManager(spieler,
80                                                                                   trainings,
81                                                                                   TrainingExperience.getStaffPanel()
82                                                                                                     .getCoTrainerNumber(),
83                                                                                   TrainingExperience.getStaffPanel()
84                                                                                                     .getKeeperTrainerNumber(),
85                                                                                   TrainingExperience.getStaffPanel()
86                                                                                                     .getTrainerLevelNumber());
87  
88          // Add future skillups
89          for (Iterator iter = ftm.getFutureSkillups().iterator(); iter.hasNext();) {
90              ISkillup element = (ISkillup) iter.next();
91  
92              TrainingExperience.getSkillupPanel().addRow(element);
93          }
94  
95          for (int i = 0; i < 8; i++) {
96              int skillIndex = Skills.getSkillAtPosition(i);
97              skillLabel[i].setText(Commons.getModel().getHelper().getNameForSkill(Skills
98                                                                                   .getSkillValue(spieler,
99                                                                                                  skillIndex),
100                                                                                  true));
101 
102             IFuturePlayer fp = ftm.previewPlayer(16);
103             double sub = getSubSkill(spieler, skillIndex);
104             double actual = sub * 100;
105             double max = getPct(skillIndex, fp, spieler, 0);
106             bars[i][0].change((int) actual, (int) max);
107             max = getPct(skillIndex, fp, spieler, 1);
108             bars[i][1].change(0, (int) max);
109             max = getPct(skillIndex, fp, spieler, 2);
110             bars[i][2].change(0, (int) max);
111         }
112 
113         updateUI();
114     }
115 
116     /***
117      * TODO Missing Method Documentation
118      *
119      * @param spieler TODO Missing Method Parameter Documentation
120      * @param skillIndex TODO Missing Method Parameter Documentation
121      *
122      * @return TODO Missing Return Method Documentation
123      */
124     private double getFinalValue(IFuturePlayer spieler, int skillIndex) {
125         switch (skillIndex) {
126             case ISpieler.SKILL_TORWART:
127                 return spieler.getGoalkeeping();
128 
129             case ISpieler.SKILL_TORSCHUSS:
130                 return spieler.getAttack();
131 
132             case ISpieler.SKILL_VERTEIDIGUNG:
133                 return spieler.getDefense();
134 
135             case ISpieler.SKILL_PASSSPIEL:
136                 return spieler.getPassing();
137 
138             case ISpieler.SKILL_SPIELAUFBAU:
139                 return spieler.getPlaymaking();
140 
141             case ISpieler.SKILL_STANDARDS:
142                 return spieler.getSetpieces();
143 
144             case ISpieler.SKILL_KONDITION:
145                 return spieler.getStamina();
146 
147             case ISpieler.SKILL_FLUEGEL:
148                 return spieler.getCross();
149         }
150 
151         return 0;
152     }
153 
154     /***
155      * Method that calculates the training percentace received
156      *
157      * @param skillIndex skill index
158      * @param futurePlayer Future Player status
159      * @param spieler actual player
160      * @param barNumber bar number, used for check with skillup number
161      *
162      * @return the training percentage as calculated
163      */
164     private double getPct(int skillIndex, IFuturePlayer futurePlayer, ISpieler spieler,
165                           int barNumber) {
166         double perc = 0;
167         double initialValue = Skills.getSkillValue(spieler, skillIndex);
168         double finalValue = getFinalValue(futurePlayer, skillIndex);
169         int skillup = (int) finalValue - (int) initialValue;
170 
171         if (skillup >= (barNumber + 1)) {
172             perc = 100;
173         } else if (skillup == barNumber) {
174             perc = 100 * (finalValue % 1);
175         } else {
176             perc = 0;
177         }
178 
179         return perc;
180     }
181 
182     /***
183      * TODO Missing Method Documentation
184      *
185      * @param spieler TODO Missing Method Parameter Documentation
186      * @param skillIndex TODO Missing Method Parameter Documentation
187      *
188      * @return TODO Missing Return Method Documentation
189      */
190     private double getSubSkill(ISpieler spieler, int skillIndex) {
191         return spieler.getSubskill4SkillWithOffset(skillIndex);
192     }
193 
194     /***
195      * Initialize the object layout
196      */
197     private void jbInit() {
198         IHOMiniModel model = Commons.getModel();
199         JPanel mainPanel = model.getGUI().createImagePanel();
200 
201         mainPanel.setOpaque(false);
202         mainPanel.setLayout(new BorderLayout());
203         setOpaque(false);
204         setLayout(new BorderLayout());
205 
206         JPanel namePanel = model.getGUI().createImagePanel();
207 
208         namePanel.setLayout(new BorderLayout());
209         playerLabel.setText(PluginProperty.getString("PlayerSelect")); //$NON-NLS-1$
210         namePanel.add(playerLabel, BorderLayout.CENTER);
211         mainPanel.add(namePanel, BorderLayout.NORTH);
212 
213         JPanel bottom = new JPanel(new GridLayout(9, 5));
214 
215         bottom.setOpaque(false);
216         bottom.add(new JLabel(model.getResource().getProperty("Training"), JLabel.CENTER)); //$NON-NLS-1$+
217         bottom.add(new JLabel(model.getResource().getProperty("Aktuell"), JLabel.CENTER), //$NON-NLS-1$
218                    BorderLayout.WEST); //$NON-NLS-1$+
219         bottom.add(new JLabel(PluginProperty.getString("FirstSkillup"), JLabel.CENTER)); //$NON-NLS-1$
220         bottom.add(new JLabel(PluginProperty.getString("SecondSkillup"), JLabel.CENTER)); //$NON-NLS-1$
221         bottom.add(new JLabel(PluginProperty.getString("ThirdSkillup"), JLabel.CENTER)); //$NON-NLS-1$
222 
223         for (int i = 0; i < 8; i++) {
224             int skillIndex = Skills.getSkillAtPosition(i);
225             bottom.add(new JLabel(Skills.getSkillDescription(skillIndex)));
226 
227             skillLabel[i] = new JLabel(""); //$NON-NLS-1$
228             skillLabel[i].setOpaque(false);
229             bottom.add(skillLabel[i]);
230 
231             for (int j = 0; j < 3; j++) {
232                 JPanel p = new JPanel();
233 
234                 bars[i][j] = new StateBar(0, 0, Color.PINK, Skills.getSkillColor(skillIndex));
235                 bars[i][j].setOpaque(false);
236                 p.add(bars[i][j]);
237                 p.setOpaque(false);
238                 bottom.add(p);
239             }
240         }
241 
242         mainPanel.add(bottom, BorderLayout.CENTER);
243         add(mainPanel, BorderLayout.CENTER);
244     }
245 }