00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package com.realtime.crossfire.jxclient.quests;
00022
00023 import com.realtime.crossfire.jxclient.util.EventListenerList2;
00024 import org.jetbrains.annotations.NotNull;
00025
00030 public class Quest {
00031
00035 @NotNull
00036 private final EventListenerList2<QuestListener> listeners = new EventListenerList2<QuestListener>(QuestListener.class);
00037
00041 private final int code;
00042
00046 @NotNull
00047 private final String title;
00048
00052 private final int face;
00053
00057 private final boolean replay;
00058
00059
00063 private final int parent;
00064
00068 private boolean end;
00069
00073 @NotNull
00074 private String step;
00075
00086 public Quest(final int code, @NotNull final String title, final int face, final boolean replay, final int parent, final boolean end, @NotNull String step) {
00087 this.code = code;
00088 this.title = title;
00089 this.face = face;
00090 this.replay = replay;
00091 this.parent = parent;
00092 this.end = end;
00093 this.step = step;
00094 }
00095
00100 public int getCode() {
00101 return this.code;
00102 }
00103
00108 @NotNull
00109 public String getTitle() {
00110 return this.title;
00111 }
00112
00117 public int getFace() {
00118 return this.face;
00119 }
00120
00126 public void setStep(boolean end, @NotNull final String step) {
00127 boolean changed = false;
00128
00129 if (this.end != end) {
00130 this.end = end;
00131 changed = true;
00132 }
00133
00134 if (this.step.compareTo(step) != 0) {
00135 this.step = step;
00136 changed = true;
00137 }
00138
00139 if (changed) {
00140 fireChanged();
00141 }
00142 }
00143
00148 @NotNull
00149 public String getTooltipText() {
00150 final StringBuilder sb = new StringBuilder("<b>");
00151 sb.append(title);
00152 sb.append("</b>");
00153 if (end) {
00154 sb.append(" (finished");
00155 if (replay) {
00156 sb.append(", can be replayed");
00157 }
00158 sb.append(")");
00159 }
00160 if (step != null) {
00161 sb.append("<br>");
00162 sb.append(step);
00163 }
00164 return sb.toString();
00165 }
00166
00170 private void fireChanged() {
00171 for (final QuestListener listener : listeners.getListeners()) {
00172 listener.questChanged();
00173 }
00174 }
00175
00180 public void addQuestListener(@NotNull final QuestListener listener) {
00181 listeners.add(listener);
00182 }
00183
00188 public void removeQuestListener(@NotNull final QuestListener listener) {
00189 listeners.remove(listener);
00190 }
00191
00192 }