Gridarta Editor
AbstractMapViewSettings.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapviewsettings;
21 
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27 
32 public abstract class AbstractMapViewSettings implements MapViewSettings {
33 
37  private boolean gridVisible = loadGridVisible();
38 
42  private boolean lightVisible = loadLightVisible();
43 
47  private boolean smoothing = loadSmoothing();
48 
52  private boolean tileStretching = loadTileStretching();
53 
57  private boolean doubleFaces = loadDoubleFaces();
58 
62  private int alphaType = loadAlphaType();
63 
67  private int editType = loadEditType();
68 
72  private boolean autojoin = loadAutojoin();
73 
77  // TODO: use this field (it looks unused but usage is planned)
78  @Nullable
80 
84  // TODO: use this field (it looks unused but usage is planned)
85  @Nullable
87 
91  @NotNull
93 
94  @Override
95  public void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) {
96  listenerList.add(listener);
97  }
98 
99  @Override
100  public void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) {
101  listenerList.remove(listener);
102  }
103 
104  @Override
105  public boolean isGridVisible() {
106  return gridVisible;
107  }
108 
109  @Override
110  public void setGridVisible(final boolean gridVisible) {
111  if (this.gridVisible == gridVisible) {
112  return;
113  }
114 
115  this.gridVisible = gridVisible;
116  saveGridVisible(gridVisible);
118  }
119 
120  @Override
121  public boolean isLightVisible() {
122  return lightVisible;
123  }
124 
125  @Override
126  public void setLightVisible(final boolean lightVisible) {
127  if (this.lightVisible == lightVisible) {
128  return;
129  }
130 
131  this.lightVisible = lightVisible;
132  saveLightVisible(lightVisible);
134  }
135 
136  @Override
137  public boolean isSmoothing() {
138  return smoothing;
139  }
140 
141  @Override
142  public void setSmoothing(final boolean smoothing) {
143  if (this.smoothing == smoothing) {
144  return;
145  }
146 
147  this.smoothing = smoothing;
148  saveSmoothing(smoothing);
150  }
151 
152  @Override
153  public boolean isTileStretching() {
154  return tileStretching;
155  }
156 
157  @Override
158  public void setTileStretching(final boolean tileStretching) {
159  if (this.tileStretching == tileStretching) {
160  return;
161  }
162 
163  this.tileStretching = tileStretching;
164  saveTileStretching(tileStretching);
166  }
167 
168  @Override
169  public boolean isDoubleFaces() {
170  return doubleFaces;
171  }
172 
173  @Override
174  public void setDoubleFaces(final boolean doubleFaces) {
175  if (this.doubleFaces == doubleFaces) {
176  return;
177  }
178 
179  this.doubleFaces = doubleFaces;
180  saveDoubleFaces(doubleFaces);
182  }
183 
184  @Override
185  public boolean isAlphaType(final int v) {
186  return v > 0 && (alphaType & v) == v;
187  }
188 
189  @Override
190  public void setAlphaType(final int v, final boolean state) {
191  if (state) {
192  alphaType |= v;
193  } else {
194  alphaType &= ~v;
195  }
196  saveAlphaType(alphaType);
198  }
199 
200  @Override
201  public void clearAlpha() {
202  alphaType = 0;
203  saveAlphaType(alphaType);
205  }
206 
207  @Override
208  public int getEditType() {
209  return editType;
210  }
211 
217  private void setEditType(final int editType) {
218  if ((this.editType & editType) == editType) {
219  return;
220  }
221 
222  this.editType |= editType;
224  }
225 
226  @Override
227  public void unsetEditType(final int editType) {
228  if ((this.editType & editType) == 0) {
229  return;
230  }
231 
232  this.editType &= ~editType;
234  }
235 
236  @Override
237  public boolean isEditType(final int editType) {
238  final int mask = editType == 0 ? BaseObject.EDIT_TYPE_NONE : editType;
239  return (this.editType & mask) != 0;
240  }
241 
242  @Override
243  public boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject) {
244  return editType == 0 || isEditType(gameObject.getEditType());
245  }
246 
247  @Override
248  public boolean isEditTypeSet() {
249  return (editType & BaseObject.EDIT_TYPE_NONE) == 0 && editType != 0;
250  }
251 
252  @Override
253  public void toggleEditType(final int editType) {
254  if (isEditType(editType)) {
255  unsetEditType(editType);
256  } else {
257  setEditType(editType);
258  }
259  }
260 
261  @Override
262  public boolean isAutojoin() {
263  return autojoin;
264  }
265 
266  @Override
267  public void setAutojoin(final boolean autojoin) {
268  if (this.autojoin == autojoin) {
269  return;
270  }
271 
272  this.autojoin = autojoin;
273  saveAutojoin(autojoin);
275  }
276 
280  private void fireGridVisibleChanged() {
281  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
282  listener.gridVisibleChanged(gridVisible);
283  }
284  }
285 
289  private void fireLightVisibleChanged() {
290  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
291  listener.lightVisibleChanged(lightVisible);
292  }
293  }
294 
298  private void fireSmoothingChanged() {
299  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
300  listener.smoothingChanged(smoothing);
301  }
302  }
303 
308  private void fireTileStretchingChanged() {
309  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
310  listener.tileStretchingChanged(tileStretching);
311  }
312  }
313 
318  private void fireDoubleFacesChanged() {
319  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
320  listener.doubleFacesChanged(doubleFaces);
321  }
322  }
323 
327  private void fireAlphaTypeChanged() {
328  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
329  listener.alphaTypeChanged(alphaType);
330  }
331  }
332 
336  private void fireEditTypeChanged() {
337  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
338  listener.editTypeChanged(editType);
339  }
340  }
341 
345  private void fireAutojoinChanged() {
346  for (final MapViewSettingsListener listener : listenerList.getListeners()) {
347  listener.autojoinChanged(autojoin);
348  }
349  }
350 
355  protected abstract boolean loadGridVisible();
356 
361  protected abstract void saveGridVisible(boolean gridVisible);
362 
367  protected abstract boolean loadLightVisible();
368 
373  protected abstract void saveLightVisible(boolean lightVisible);
374 
379  protected abstract boolean loadSmoothing();
380 
385  protected abstract void saveSmoothing(boolean smoothing);
386 
391  protected abstract boolean loadTileStretching();
392 
397  protected abstract void saveTileStretching(boolean tileStretching);
398 
403  protected abstract boolean loadDoubleFaces();
404 
409  protected abstract void saveDoubleFaces(boolean doubleFaces);
410 
415  protected abstract int loadAlphaType();
416 
421  protected abstract void saveAlphaType(int alphaType);
422 
427  protected abstract int loadEditType();
428 
433  protected abstract boolean loadAutojoin();
434 
439  protected abstract void saveAutojoin(boolean autojoin);
440 
441 }
abstract boolean loadDoubleFaces()
Loads the default value for doubleFaces.
abstract boolean loadGridVisible()
Loads the default value for gridVisible.
abstract boolean loadTileStretching()
Loads the default value for tileStretching.
void setTileStretching(final boolean tileStretching)
Sets the tile-stretching setting.
void fireTileStretchingChanged()
Informs all registered listeners that the tile-stretching setting has changed.
T [] getListeners()
Returns an array of all the listeners.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
void fireAutojoinChanged()
Notify all listeners about changed autojoin.
void fireSmoothingChanged()
Informs all registered listeners that the smoothing setting has changed.
void setSmoothing(final boolean smoothing)
Sets the smoothing setting.
boolean isEditType(final int editType)
Get information on the current state of edit type.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
abstract void saveSmoothing(boolean smoothing)
Saves the smoothing value.
void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener)
Register a MapViewSettingsListener.
boolean isEditTypeSet()
Returns whether a editType value is set so that not all squares are displayed.
abstract void saveDoubleFaces(boolean doubleFaces)
Saves the doubleFaces value.
void fireEditTypeChanged()
Notify all listeners about changed editType.
void setEditType(final int editType)
Set the map view to show squares of the given type.
void setAlphaType(final int v, final boolean state)
Sets whether the specified edit type is to be shown transparent.
void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener)
Unregister a MapViewSettingsListener.
void toggleEditType(final int editType)
Toggle an edit type.
final ViewGameObjectMatcherManager visibilityManager
The visibility settings.
Abstract base class for MapViewSettings implementations.
boolean doubleFaces
Whether double faces should be drawn double height.
Base package of all Gridarta classes.
boolean tileStretching
Whether tile-stretching display is active.
void fireAlphaTypeChanged()
Informs all registered listeners that the alpha type haves changed.
void setGridVisible(final boolean gridVisible)
Set the visibility of the grid.
abstract int loadEditType()
Loads the default value for editType.
void remove(@NotNull final T listener)
Removes a listener.
Interface for event listeners that are interested in changes on MapViewSettings.
boolean isDoubleFaces()
Get whether double faces are drawn double height.
abstract void saveGridVisible(boolean gridVisible)
Saves the gridVisible value.
Container for settings that affect the rendering of maps.
abstract void saveAlphaType(int alphaType)
Saves the alphaType value.
void add(@NotNull final T listener)
Adds a listener.
abstract void saveAutojoin(boolean autojoin)
Saves the autojoin value.
void fireGridVisibleChanged()
Informs all registered listeners that the grid visibility has changed.
int alphaType
Bit field of edit types to show transparent.
final EventListenerList2< MapViewSettingsListener > listenerList
The MapViewSettingsListeners to inform of changes.
boolean isAlphaType(final int v)
Returns whether the specified edit type is to be shown transparent.
abstract void saveLightVisible(boolean lightVisible)
Saves the lightVisible value.
final ViewGameObjectMatcherManager transparencyManager
The transparency settings.
abstract boolean loadLightVisible()
Loads the default value for lightVisible.
void fireDoubleFacesChanged()
Informs all registered listeners that the double faces visibility has changed.
Type-safe version of EventListenerList.
void setAutojoin(final boolean autojoin)
Sets the "autojoin" state.
boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
Get information whether the gameObject is edited.
abstract boolean loadSmoothing()
Loads the default value for smoothing.
boolean isTileStretching()
Returns the tile-stretching setting.
abstract void saveTileStretching(boolean tileStretching)
Saves the tileStretching value.
void unsetEditType(final int editType)
Set the map view to hide squares of the given type.
void setLightVisible(final boolean lightVisible)
Set the visibility of the light.
abstract boolean loadAutojoin()
Loads the default value for autojoin.
abstract int loadAlphaType()
Loads the default value for alphaType.
void setDoubleFaces(final boolean doubleFaces)
Sets whether double faces should be drawn double height.
void fireLightVisibleChanged()
Informs all registered listeners that the light visibility has changed.