Crossfire JXClient, Trunk  R20561
SpellsView.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) 2011 Nicolas Weeger
19  */
20 
21 package com.realtime.crossfire.jxclient.items;
22 
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class SpellsView extends AbstractItemView {
36 
40  @NotNull
42 
46  @NotNull
47  private final FacesManager facesManager;
48 
54  public SpellsView(@NotNull final SpellsManager spellsManager, @NotNull final FacesManager facesManager) {
55  this.spellsManager = spellsManager;
56  this.facesManager = facesManager;
57  spellsManager.addCrossfireSpellChangedListener(new SpellsManagerListener() {
58 
59  @Override
60  public void spellAdded(final int index) {
61  addModifiedRange(index, spellsManager.getSpells());
62  }
63 
64  @Override
65  public void spellRemoved(final int index) {
66  addModifiedRange(index, spellsManager.getSpells());
67  }
68 
69  });
70  facesManager.addFacesManagerListener(face -> {
71  if (spellsManager.displaysFace(face.getFaceNum())) {
72  addModifiedRange(0, spellsManager.getSpells());
73  }
74  });
75  }
76 
80  @Override
81  public int getSize() {
82  return spellsManager.getSpells();
83  }
84 
88  @Nullable
89  @Override
90  public CfItem getItem(final int index) {
91  final Spell spell = spellsManager.getSpell(index);
92  if (spell == null) {
93  return null;
94  }
95  final Face face = facesManager.getFace(spell.getFaceNum());
96  return new CfItem(0, spell.getTag(), 0, 0, face, spell.getName(), spell.getName(), 0, 0, 0, 0);
97  }
98 
99 }
String getName()
Returns the spell name.
Definition: Spell.java:197
Interface for listeners interested in SpellsManager events.
int getSpells()
Returns the number of known spells.
SpellsView(@NotNull final SpellsManager spellsManager, @NotNull final FacesManager facesManager)
Creates a new instance.
Definition: SpellsView.java:54
Manages image information ("faces") needed to display the map view, items, and spell icons...
int getFaceNum()
Returns the face number.
Definition: Spell.java:214
Provides a view of all spells a character knows.
Definition: SpellsView.java:35
int getSize()
Returns the number of items.the number of items
Definition: SpellsView.java:81
Describes a Crossfire spell.
Definition: Spell.java:36
void addModifiedRange(final int firstIndex, final int lastIndex)
Marks a range of slots as modified.
int getTag()
Returns the tag ID.
Definition: Spell.java:132
final FacesManager facesManager
The FacesManager for retrieving face information.
Definition: SpellsView.java:47
CfItem getItem(final int index)
Returns the CfItem in a given slot.the slot index the item ornull if the slot is empty ...
Definition: SpellsView.java:90
Face getFace(int faceNum)
Returns the Face instance for a given face ID.
Abstract base class for ItemView implementing classes.
final SpellsManager spellsManager
The spells to display.
Definition: SpellsView.java:41
The representation of a Crossfire Item, client-side.
Definition: CfItem.java:36
void addFacesManagerListener(@NotNull FacesManagerListener facesManagerListener)
Adds a FacesManagerListener to be notified about updated faces.
Spell getSpell(@NotNull final String spellName)
Returns a Spell instance by spell name.
Maintains a mapping of face numbers to face data.