Crossfire JXClient, Trunk  R20561
QuestsView.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 
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
34 public class QuestsView extends AbstractItemView {
35 
39  @NotNull
41 
45  @NotNull
46  private final FacesManager facesManager;
47 
53  public QuestsView(@NotNull final QuestsManager questsManager, @NotNull final FacesManager facesManager) {
54  this.questsManager = questsManager;
55  this.facesManager = facesManager;
56  questsManager.addCrossfireQuestChangedListener(index -> addModifiedRange(index, questsManager.getQuests()));
57  facesManager.addFacesManagerListener(face -> {
58  if (questsManager.displaysFace(face.getFaceNum())) {
59  addModifiedRange(0, questsManager.getQuests());
60  }
61  });
62  }
63 
67  @Override
68  public int getSize() {
69  return questsManager.getQuests();
70  }
71 
75  @Nullable
76  @Override
77  public CfItem getItem(final int index) {
78  final Quest quest = questsManager.getQuest(index);
79  if (quest == null) {
80  return null;
81  }
82  final Face face = facesManager.getFace(quest.getFace());
83  return new CfItem(0, quest.getCode(), 0, 0, face, quest.getTitle(), quest.getTitle(), 0, 0, 0, 0);
84  }
85 
86 }
QuestsView(@NotNull final QuestsManager questsManager, @NotNull final FacesManager facesManager)
Creates a new instance.
Definition: QuestsView.java:53
Provides a view of all quests a character is doing.
Definition: QuestsView.java:34
int getCode()
Get the quest's code.
Definition: Quest.java:100
Describes an in-game quest.
Definition: Quest.java:30
Manages image information ("faces") needed to display the map view, items, and spell icons...
int getQuests()
Returns the number of current quests.
int getSize()
Returns the number of items.the number of items
Definition: QuestsView.java:68
void addModifiedRange(final int firstIndex, final int lastIndex)
Marks a range of slots as modified.
final QuestsManager questsManager
The quests to display.
Definition: QuestsView.java:40
CfItem getItem(final int index)
Returns the CfItem in a given slot.the slot index the item ornull if the slot is empty ...
Definition: QuestsView.java:77
int getFace()
Get the quest's face.
Definition: Quest.java:117
final FacesManager facesManager
The FacesManager for retrieving face information.
Definition: QuestsView.java:46
String getTitle()
Get the quest's title.
Definition: Quest.java:109
Face getFace(int faceNum)
Returns the Face instance for a given face ID.
Abstract base class for ItemView implementing classes.
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.
Quest getQuest(final int index)
Returns a Quest instance by index.
Maintains a mapping of face numbers to face data.