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-2023 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 
22 import java.util.Collection;
23 import java.util.concurrent.CopyOnWriteArrayList;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
33 public abstract class AbstractMapViewSettings implements MapViewSettings {
34 
38  private boolean gridVisible = loadGridVisible();
39 
43  private boolean lightVisible = loadLightVisible();
44 
48  private boolean smoothing = loadSmoothing();
49 
53  private boolean tileStretching = loadTileStretching();
54 
58  private boolean doubleFaces = loadDoubleFaces();
59 
63  private int alphaType = loadAlphaType();
64 
68  private int editType = loadEditType();
69 
73  private boolean autojoin = loadAutojoin();
74 
78  // TODO: use this field (it looks unused but usage is planned)
79  @Nullable
81 
85  // TODO: use this field (it looks unused but usage is planned)
86  @Nullable
88 
92  @NotNull
93  private final Collection<MapViewSettingsListener> listenerList = new CopyOnWriteArrayList<>();
94 
95  @Override
96  public void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) {
97  listenerList.add(listener);
98  }
99 
100  @Override
101  public void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) {
102  listenerList.remove(listener);
103  }
104 
105  @Override
106  public boolean isGridVisible() {
107  return gridVisible;
108  }
109 
110  @Override
111  public void setGridVisible(final boolean gridVisible) {
112  if (this.gridVisible == gridVisible) {
113  return;
114  }
115 
116  this.gridVisible = gridVisible;
119  }
120 
121  @Override
122  public boolean isLightVisible() {
123  return lightVisible;
124  }
125 
126  @Override
127  public void setLightVisible(final boolean lightVisible) {
128  if (this.lightVisible == lightVisible) {
129  return;
130  }
131 
132  this.lightVisible = lightVisible;
135  }
136 
137  @Override
138  public boolean isSmoothing() {
139  return smoothing;
140  }
141 
142  @Override
143  public void setSmoothing(final boolean smoothing) {
144  if (this.smoothing == smoothing) {
145  return;
146  }
147 
148  this.smoothing = smoothing;
151  }
152 
153  @Override
154  public boolean isTileStretching() {
155  return tileStretching;
156  }
157 
158  @Override
159  public void setTileStretching(final boolean tileStretching) {
160  if (this.tileStretching == tileStretching) {
161  return;
162  }
163 
164  this.tileStretching = tileStretching;
167  }
168 
169  @Override
170  public boolean isDoubleFaces() {
171  return doubleFaces;
172  }
173 
174  @Override
175  public void setDoubleFaces(final boolean doubleFaces) {
176  if (this.doubleFaces == doubleFaces) {
177  return;
178  }
179 
180  this.doubleFaces = doubleFaces;
183  }
184 
185  @Override
186  public boolean isAlphaType(final int v) {
187  return v > 0 && (alphaType & v) == v;
188  }
189 
190  @Override
191  public void setAlphaType(final int v, final boolean state) {
192  if (state) {
193  alphaType |= v;
194  } else {
195  alphaType &= ~v;
196  }
199  }
200 
201  @Override
202  public void clearAlpha() {
203  alphaType = 0;
206  }
207 
208  @Override
209  public int getEditType() {
210  return editType;
211  }
212 
218  private void setEditType(final int editType) {
219  if ((this.editType & editType) == editType) {
220  return;
221  }
222 
223  this.editType |= editType;
225  }
226 
227  @Override
228  public void unsetEditType(final int editType) {
229  if ((this.editType & editType) == 0) {
230  return;
231  }
232 
233  this.editType &= ~editType;
235  }
236 
237  @Override
238  public boolean isEditType(final int editType) {
239  final int mask = editType == 0 ? BaseObject.EDIT_TYPE_NONE : editType;
240  return (this.editType & mask) != 0;
241  }
242 
243  @Override
244  public boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject) {
245  return editType == 0 || isEditType(gameObject.getEditType());
246  }
247 
248  @Override
249  public boolean isEditTypeSet() {
250  return (editType & BaseObject.EDIT_TYPE_NONE) == 0 && editType != 0;
251  }
252 
253  @Override
254  public void toggleEditType(final int editType) {
255  if (isEditType(editType)) {
257  } else {
259  }
260  }
261 
262  @Override
263  public boolean isAutojoin() {
264  return autojoin;
265  }
266 
267  @Override
268  public void setAutojoin(final boolean autojoin) {
269  if (this.autojoin == autojoin) {
270  return;
271  }
272 
273  this.autojoin = autojoin;
276  }
277 
281  private void fireGridVisibleChanged() {
282  for (final MapViewSettingsListener listener : listenerList) {
283  listener.gridVisibleChanged(gridVisible);
284  }
285  }
286 
290  private void fireLightVisibleChanged() {
291  for (final MapViewSettingsListener listener : listenerList) {
292  listener.lightVisibleChanged(lightVisible);
293  }
294  }
295 
299  private void fireSmoothingChanged() {
300  for (final MapViewSettingsListener listener : listenerList) {
301  listener.smoothingChanged(smoothing);
302  }
303  }
304 
309  private void fireTileStretchingChanged() {
310  for (final MapViewSettingsListener listener : listenerList) {
311  listener.tileStretchingChanged(tileStretching);
312  }
313  }
314 
319  private void fireDoubleFacesChanged() {
320  for (final MapViewSettingsListener listener : listenerList) {
321  listener.doubleFacesChanged(doubleFaces);
322  }
323  }
324 
328  private void fireAlphaTypeChanged() {
329  for (final MapViewSettingsListener listener : listenerList) {
330  listener.alphaTypeChanged(alphaType);
331  }
332  }
333 
337  private void fireEditTypeChanged() {
338  for (final MapViewSettingsListener listener : listenerList) {
339  listener.editTypeChanged(editType);
340  }
341  }
342 
346  private void fireAutojoinChanged() {
347  for (final MapViewSettingsListener listener : listenerList) {
348  listener.autojoinChanged(autojoin);
349  }
350  }
351 
356  protected abstract boolean loadGridVisible();
357 
362  protected abstract void saveGridVisible(boolean gridVisible);
363 
368  protected abstract boolean loadLightVisible();
369 
374  protected abstract void saveLightVisible(boolean lightVisible);
375 
380  protected abstract boolean loadSmoothing();
381 
386  protected abstract void saveSmoothing(boolean smoothing);
387 
392  protected abstract boolean loadTileStretching();
393 
398  protected abstract void saveTileStretching(boolean tileStretching);
399 
404  protected abstract boolean loadDoubleFaces();
405 
410  protected abstract void saveDoubleFaces(boolean doubleFaces);
411 
416  protected abstract int loadAlphaType();
417 
422  protected abstract void saveAlphaType(int alphaType);
423 
428  protected abstract int loadEditType();
429 
434  protected abstract boolean loadAutojoin();
435 
440  protected abstract void saveAutojoin(boolean autojoin);
441 
442 }
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isEditTypeSet
boolean isEditTypeSet()
Returns whether a editType value is set so that not all squares are displayed.
Definition: AbstractMapViewSettings.java:249
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setTileStretching
void setTileStretching(final boolean tileStretching)
Sets the tile-stretching setting.
Definition: AbstractMapViewSettings.java:159
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setEditType
void setEditType(final int editType)
Set the map view to show squares of the given type.
Definition: AbstractMapViewSettings.java:218
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.lightVisible
boolean lightVisible
The visibility of the light.
Definition: AbstractMapViewSettings.java:43
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setAlphaType
void setAlphaType(final int v, final boolean state)
Sets whether the specified edit type is to be shown transparent.
Definition: AbstractMapViewSettings.java:191
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isAutojoin
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Definition: AbstractMapViewSettings.java:263
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isEditType
boolean isEditType(final int editType)
Get information on the current state of edit type.
Definition: AbstractMapViewSettings.java:238
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveSmoothing
abstract void saveSmoothing(boolean smoothing)
Saves the smoothing value.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadAlphaType
abstract int loadAlphaType()
Loads the default value for alphaType.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveDoubleFaces
abstract void saveDoubleFaces(boolean doubleFaces)
Saves the doubleFaces value.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setAutojoin
void setAutojoin(final boolean autojoin)
Sets the "autojoin" state.
Definition: AbstractMapViewSettings.java:268
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireTileStretchingChanged
void fireTileStretchingChanged()
Informs all registered listeners that the tile-stretching setting has changed.
Definition: AbstractMapViewSettings.java:309
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.tileStretching
boolean tileStretching
Whether tile-stretching display is active.
Definition: AbstractMapViewSettings.java:53
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.smoothing
boolean smoothing
Whether smoothing display is active.
Definition: AbstractMapViewSettings.java:48
net.sf
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.removeMapViewSettingsListener
void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener)
Unregister a MapViewSettingsListener.
Definition: AbstractMapViewSettings.java:101
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isGridVisible
boolean isGridVisible()
Get the visibility of the grid.
Definition: AbstractMapViewSettings.java:106
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.getEditType
int getEditType()
Returns the currently set edit type.
Definition: AbstractMapViewSettings.java:209
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadDoubleFaces
abstract boolean loadDoubleFaces()
Loads the default value for doubleFaces.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.gridVisible
boolean gridVisible
The visibility of the grid.
Definition: AbstractMapViewSettings.java:38
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveGridVisible
abstract void saveGridVisible(boolean gridVisible)
Saves the gridVisible value.
net.sf.gridarta.model.mapviewsettings.MapViewSettings
Container for settings that affect the rendering of maps.
Definition: MapViewSettings.java:30
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireAlphaTypeChanged
void fireAlphaTypeChanged()
Informs all registered listeners that the alpha type haves changed.
Definition: AbstractMapViewSettings.java:328
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings
Abstract base class for MapViewSettings implementations.
Definition: AbstractMapViewSettings.java:33
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.addMapViewSettingsListener
void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener)
Register a MapViewSettingsListener.
Definition: AbstractMapViewSettings.java:96
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.doubleFaces
boolean doubleFaces
Whether double faces should be drawn double height.
Definition: AbstractMapViewSettings.java:58
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.listenerList
final Collection< MapViewSettingsListener > listenerList
The MapViewSettingsListeners to inform of changes.
Definition: AbstractMapViewSettings.java:93
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.transparencyManager
final ViewGameObjectMatcherManager transparencyManager
The transparency settings.
Definition: AbstractMapViewSettings.java:80
net.sf.gridarta.model.baseobject.BaseObject.EDIT_TYPE_NONE
int EDIT_TYPE_NONE
Definition: BaseObject.java:36
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setSmoothing
void setSmoothing(final boolean smoothing)
Sets the smoothing setting.
Definition: AbstractMapViewSettings.java:143
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadEditType
abstract int loadEditType()
Loads the default value for editType.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadLightVisible
abstract boolean loadLightVisible()
Loads the default value for lightVisible.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadTileStretching
abstract boolean loadTileStretching()
Loads the default value for tileStretching.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadSmoothing
abstract boolean loadSmoothing()
Loads the default value for smoothing.
net
net.sf.gridarta.model.match
Classes related to matching {GameObjects}, so called { net.sf.gridarta.model.match....
Definition: AndGameObjectMatcher.java:20
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.toggleEditType
void toggleEditType(final int editType)
Toggle an edit type.
Definition: AbstractMapViewSettings.java:254
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveAlphaType
abstract void saveAlphaType(int alphaType)
Saves the alphaType value.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isAlphaType
boolean isAlphaType(final int v)
Returns whether the specified edit type is to be shown transparent.
Definition: AbstractMapViewSettings.java:186
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireEditTypeChanged
void fireEditTypeChanged()
Notify all listeners about changed editType.
Definition: AbstractMapViewSettings.java:337
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireSmoothingChanged
void fireSmoothingChanged()
Informs all registered listeners that the smoothing setting has changed.
Definition: AbstractMapViewSettings.java:299
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setLightVisible
void setLightVisible(final boolean lightVisible)
Set the visibility of the light.
Definition: AbstractMapViewSettings.java:127
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveAutojoin
abstract void saveAutojoin(boolean autojoin)
Saves the autojoin value.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isLightVisible
boolean isLightVisible()
Get the visibility of the light.
Definition: AbstractMapViewSettings.java:122
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireGridVisibleChanged
void fireGridVisibleChanged()
Informs all registered listeners that the grid visibility has changed.
Definition: AbstractMapViewSettings.java:281
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveLightVisible
abstract void saveLightVisible(boolean lightVisible)
Saves the lightVisible value.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isDoubleFaces
boolean isDoubleFaces()
Get whether double faces are drawn double height.
Definition: AbstractMapViewSettings.java:170
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setGridVisible
void setGridVisible(final boolean gridVisible)
Set the visibility of the grid.
Definition: AbstractMapViewSettings.java:111
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isSmoothing
boolean isSmoothing()
Returns the smoothing setting.
Definition: AbstractMapViewSettings.java:138
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isTileStretching
boolean isTileStretching()
Returns the tile-stretching setting.
Definition: AbstractMapViewSettings.java:154
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.isEditType
boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
Get information whether the gameObject is edited.
Definition: AbstractMapViewSettings.java:244
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.alphaType
int alphaType
Bit field of edit types to show transparent.
Definition: AbstractMapViewSettings.java:63
net.sf.gridarta.model
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireLightVisibleChanged
void fireLightVisibleChanged()
Informs all registered listeners that the light visibility has changed.
Definition: AbstractMapViewSettings.java:290
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireDoubleFacesChanged
void fireDoubleFacesChanged()
Informs all registered listeners that the double faces visibility has changed.
Definition: AbstractMapViewSettings.java:319
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.setDoubleFaces
void setDoubleFaces(final boolean doubleFaces)
Sets whether double faces should be drawn double height.
Definition: AbstractMapViewSettings.java:175
net.sf.gridarta.model.mapviewsettings.MapViewSettingsListener
Interface for event listeners that are interested in changes on {}.
Definition: MapViewSettingsListener.java:31
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.saveTileStretching
abstract void saveTileStretching(boolean tileStretching)
Saves the tileStretching value.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.autojoin
boolean autojoin
Whether autojoining is on/off.
Definition: AbstractMapViewSettings.java:73
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.clearAlpha
void clearAlpha()
Clear the transparency.
Definition: AbstractMapViewSettings.java:202
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadAutojoin
abstract boolean loadAutojoin()
Loads the default value for autojoin.
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.editType
int editType
Bit field of edit types to show only.
Definition: AbstractMapViewSettings.java:68
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.visibilityManager
final ViewGameObjectMatcherManager visibilityManager
The visibility settings.
Definition: AbstractMapViewSettings.java:87
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.unsetEditType
void unsetEditType(final int editType)
Set the map view to hide squares of the given type.
Definition: AbstractMapViewSettings.java:228
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.fireAutojoinChanged
void fireAutojoinChanged()
Notify all listeners about changed autojoin.
Definition: AbstractMapViewSettings.java:346
net.sf.gridarta.model.mapviewsettings.AbstractMapViewSettings.loadGridVisible
abstract boolean loadGridVisible()
Loads the default value for gridVisible.
net.sf.gridarta.model.match.ViewGameObjectMatcherManager
Manages GameObjectMatchers.
Definition: ViewGameObjectMatcherManager.java:34