Crossfire JXClient, Trunk  R20561
Quest.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.quests;
22 
24 import org.jetbrains.annotations.NotNull;
25 
30 public class Quest {
31 
35  @NotNull
37 
41  private final int code;
42 
46  @NotNull
47  private final String title;
48 
52  private final int face;
53 
57  private final boolean replay;
58 
62  private final int parent;
63 
67  private boolean end;
68 
72  @NotNull
73  private String step;
74 
86  public Quest(final int code, @NotNull final String title, final int face, final boolean replay, final int parent, final boolean end, @NotNull final String step) {
87  this.code = code;
88  this.title = title;
89  this.face = face;
90  this.replay = replay;
91  this.parent = parent;
92  this.end = end;
93  this.step = step;
94  }
95 
100  public int getCode() {
101  return code;
102  }
103 
108  @NotNull
109  public String getTitle() {
110  return title;
111  }
112 
117  public int getFace() {
118  return face;
119  }
120 
126  public void setStep(final boolean end, @NotNull final String step) {
127  boolean changed = false;
128 
129  if (this.end != end) {
130  this.end = end;
131  changed = true;
132  }
133 
134  if (this.step.compareTo(step) != 0) {
135  this.step = step;
136  changed = true;
137  }
138 
139  if (changed) {
140  fireChanged();
141  }
142  }
143 
148  @NotNull
149  public String getTooltipText() {
150  final StringBuilder sb = new StringBuilder("<b>");
151  sb.append(title);
152  sb.append("</b>");
153  if (end) {
154  sb.append(" (finished");
155  if (replay) {
156  sb.append(", can be replayed");
157  }
158  sb.append(")");
159  }
160  sb.append("<br>");
161  sb.append(step);
162  return sb.toString();
163  }
164 
168  private void fireChanged() {
169  for (final QuestListener listener : listeners) {
170  listener.questChanged();
171  }
172  }
173 
178  public void addQuestListener(@NotNull final QuestListener listener) {
179  listeners.add(listener);
180  }
181 
186  public void removeQuestListener(@NotNull final QuestListener listener) {
187  listeners.remove(listener);
188  }
189 
190 }
int getCode()
Get the quest&#39;s code.
Definition: Quest.java:100
final String title
Quest title.
Definition: Quest.java:47
Describes an in-game quest.
Definition: Quest.java:30
boolean end
If true, the quest is completed.
Definition: Quest.java:67
Interface for listeners interested in Quest related events.
final int code
Quest internal code.
Definition: Quest.java:41
String step
Description of the current step.
Definition: Quest.java:73
void fireChanged()
Notifies all listeners.
Definition: Quest.java:168
Quest(final int code, @NotNull final String title, final int face, final boolean replay, final int parent, final boolean end, @NotNull final String step)
Create a new quest.
Definition: Quest.java:86
final int parent
Quest internal code of this quest&#39;s parent, 0 if no parent.
Definition: Quest.java:62
void add(@NotNull final T listener)
Adds a listener.
final boolean replay
If true, the quest can be replayed.
Definition: Quest.java:57
int getFace()
Get the quest&#39;s face.
Definition: Quest.java:117
String getTooltipText()
Returns a description for this spell to be used in tooltips.
Definition: Quest.java:149
String getTitle()
Get the quest&#39;s title.
Definition: Quest.java:109
final EventListenerList2< QuestListener > listeners
The QuestListeners to be notified of changes.
Definition: Quest.java:36
void setStep(final boolean end, @NotNull final String step)
Update the quest&#39;s state.
Definition: Quest.java:126
void removeQuestListener(@NotNull final QuestListener listener)
Removes a QuestListener to be notified of changes.
Definition: Quest.java:186
void remove(@NotNull final T listener)
Removes a listener.
void addQuestListener(@NotNull final QuestListener listener)
Adds a QuestListener to be notified of changes.
Definition: Quest.java:178