Crossfire JXClient, Trunk  R20561
NewCharacterInformation.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.character;
23 
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
34 
40 
44  @NotNull
45  private final List<StartingMap> startingMaps = new ArrayList<>();
46 
50  @NotNull
51  private final List<String> raceList = new ArrayList<>();
52 
56  @NotNull
57  private final List<String> classList = new ArrayList<>();
58 
62  @NotNull
63  private final Map<String, ClassRaceInfo> raceInfo = new HashMap<>();
64 
68  @NotNull
69  private final Map<String, ClassRaceInfo> classInfo = new HashMap<>();
70 
74  @NotNull
75  private NewCharInfo newCharInfo = new NewCharInfo(0, 0, 0, Collections.<String>emptyList(), false, false, false);
76 
80  @NotNull
82 
87  public void setStartingMaps(@NotNull final Collection<StartingMap> startingMaps) {
88  this.startingMaps.clear();
89  this.startingMaps.addAll(startingMaps);
90  }
91 
97  public void addNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener) {
98  newCharacterInformationListeners.add(newCharacterInformationListener);
99  }
100 
106  public void removeNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener) {
107  newCharacterInformationListeners.remove(newCharacterInformationListener);
108  }
109 
115  @NotNull
116  public List<StartingMap> getStartingMaps() {
117  return Collections.unmodifiableList(startingMaps);
118  }
119 
124  public void setRaceList(@NotNull final String[] raceList) {
125  this.raceList.clear();
126  this.raceList.addAll(Arrays.asList(raceList));
127  for (final NewCharacterInformationListener newCharacterInformationListener : newCharacterInformationListeners) {
128  newCharacterInformationListener.raceListChanged();
129  }
130  }
131 
136  @NotNull
137  public Iterable<String> getRaceList() {
138  return Collections.unmodifiableList(raceList);
139  }
140 
145  public void setClassList(@NotNull final String[] classList) {
146  this.classList.clear();
147  this.classList.addAll(Arrays.asList(classList));
148  for (final NewCharacterInformationListener newCharacterInformationListener : newCharacterInformationListeners) {
149  newCharacterInformationListener.classListChanged();
150  }
151  }
152 
157  @NotNull
158  public Iterable<String> getClassesList() {
159  return Collections.unmodifiableList(classList);
160  }
161 
166  public void addRaceInfo(@NotNull final ClassRaceInfo classRaceInfo) {
167  raceInfo.put(classRaceInfo.getArchName(), classRaceInfo);
168  for (final NewCharacterInformationListener newCharacterInformationListener : newCharacterInformationListeners) {
169  newCharacterInformationListener.raceInfoChanged(classRaceInfo.getArchName());
170  }
171  }
172 
178  @Nullable
179  public ClassRaceInfo getRaceInfo(@NotNull final String race) {
180  return raceInfo.get(race);
181  }
182 
187  public void addClassInfo(@NotNull final ClassRaceInfo classInfo) {
188  this.classInfo.put(classInfo.getArchName(), classInfo);
189  for (final NewCharacterInformationListener newCharacterInformationListener : newCharacterInformationListeners) {
190  newCharacterInformationListener.classInfoChanged(classInfo.getArchName());
191  }
192  }
193 
200  @Nullable
201  public ClassRaceInfo getClassInfo(@NotNull final String className) {
202  return classInfo.get(className);
203  }
204 
209  @NotNull
211  return newCharInfo;
212  }
213 
218  public void setNewCharInfo(@NotNull final NewCharInfo newCharInfo) {
219  this.newCharInfo = newCharInfo;
220  }
221 
222 }
void setNewCharInfo(@NotNull final NewCharInfo newCharInfo)
Sets the NewCharInfo instance for character creation.
void addClassInfo(@NotNull final ClassRaceInfo classInfo)
Sets or updates a class info.
Iterable< String > getClassesList()
Returns all defined classes available for character creation.
void addNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Registers a NewCharacterInformationListener to be notified of changes.
General information for creating new characters.
final EventListenerList2< NewCharacterInformationListener > newCharacterInformationListeners
All registered character listeners.
void setRaceList(@NotNull final String[] raceList)
Sets the races available for character creation.
final List< String > raceList
The races available for character creation.
NewCharInfo newCharInfo
The NewCharInfo for creating new characters.
List< StartingMap > getStartingMaps()
Returns all defined StartingMap entries available for character creation.
void removeNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Unregisters a NewCharacterInformationListener not to be notified of changes.
void add(@NotNull final T listener)
Adds a listener.
final List< String > classList
The classes available for character creation.
void setStartingMaps(@NotNull final Collection< StartingMap > startingMaps)
Sets the StartingMap entries available for character creation.
Iterable< String > getRaceList()
Returns all defined races available for character creation.
One possible class or race for character creation.
ClassRaceInfo getClassInfo(@NotNull final String className)
Returns a class info by class name.
final List< StartingMap > startingMaps
The StartingMap entries available for character creation.
final Map< String, ClassRaceInfo > raceInfo
The defined races for character creation.
void addRaceInfo(@NotNull final ClassRaceInfo classRaceInfo)
Sets or updates a ClassRaceInfo.
ClassRaceInfo getRaceInfo(@NotNull final String race)
Returns a ClassRaceInfo by race name.
void remove(@NotNull final T listener)
Removes a listener.
NewCharInfo getNewCharInfo()
Returns the NewCharInfo instance for character creation.
void setClassList(@NotNull final String[] classList)
Sets the classes available for character creation.
Interface for listeners interested in NewCharacterInformation related events.
final Map< String, ClassRaceInfo > classInfo
The defined classes for character creation.