Crossfire JXClient, Trunk  R20561
SpellSkillView.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-2012 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.items;
23 
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
36 public class SpellSkillView extends AbstractItemView {
37 
41  @NotNull
43 
47  @NotNull
48  private final FacesManager facesManager;
49 
55  public SpellSkillView(@NotNull final SpellsManager spellsManager, @NotNull final FacesManager facesManager) {
56  this.spellsManager = spellsManager;
57  this.facesManager = facesManager;
58  spellsManager.addCrossfireSpellChangedListener(new SpellsManagerListener() {
59 
60  @Override
61  public void spellAdded(final int index) {
62  addModifiedRange(0, spellsManager.getSpellSkills());
63  }
64 
65  @Override
66  public void spellRemoved(final int index) {
67  addModifiedRange(0, spellsManager.getSpellSkills());
68  }
69 
70  });
71  facesManager.addFacesManagerListener(face -> {
72  if (spellsManager.displaysFace(face.getFaceNum())) {
73  addModifiedRange(0, spellsManager.getSpellSkills());
74  }
75  });
76  }
77 
81  @Override
82  public int getSize() {
83  return spellsManager.getSpellSkills();
84  }
85 
89  @Nullable
90  @Override
91  public CfItem getItem(final int index) {
92  final Skill skill = spellsManager.getSpellSkill(index);
93  if (skill == null) {
94  return new CfItem(0, 0, 0, 0, facesManager.getFace(0), "All skills", "All skills", 0, 0, 0, 0);
95  }
96 
97  final int faceNumber = skill.getFace();
98  final Face face = facesManager.getFace(faceNumber > 0 ? faceNumber : 0);
99  return new CfItem(0, 0, 0, 0, face, skill.toString(), skill.toString(), 0, 0, 0, 0);
100  }
101 
102 }
CfItem getItem(final int index)
Returns the CfItem in a given slot.the slot index the item ornull if the slot is empty ...
int getFace()
Returns the skill's face.
Definition: Skill.java:105
Interface for listeners interested in SpellsManager events.
Manages image information ("faces") needed to display the map view, items, and spell icons...
One skill of the character.
Definition: Skill.java:32
final SpellsManager spellsManager
The spells to display.
void addModifiedRange(final int firstIndex, final int lastIndex)
Marks a range of slots as modified.
int getSpellSkills()
Returns the number of spell skills.
SpellSkillView(@NotNull final SpellsManager spellsManager, @NotNull final FacesManager facesManager)
Creates a new instance.
Face getFace(int faceNum)
Returns the Face instance for a given face ID.
Abstract base class for ItemView implementing classes.
Skill getSpellSkill(final int index)
Returns the specified spell skill.
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.
int getSize()
Returns the number of items.the number of items
final FacesManager facesManager
The FacesManager for retrieving face information.
Maintains a mapping of face numbers to face data.