Crossfire JXClient, Trunk
Shortcut.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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.shortcuts;
24 
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class Shortcut {
36 
40  @NotNull
41  private String command;
42 
47  @Nullable
48  private final Spell spell;
49 
53  @NotNull
55 
62  public Shortcut(@NotNull final String command, @Nullable final Spell spell) {
63  this.command = command;
64  this.spell = spell;
65 
66  if (this.spell != null) {
67  this.spell.addSpellListener(this::fireModifiedEvent);
68  }
69  }
70 
75  @NotNull
76  public String getCommand() {
77  return command;
78  }
79 
85  @Nullable
86  public Spell getSpell() {
87  return spell;
88  }
89 
93  public void dispose() {
94  if (spell != null) {
95  spell.removeSpellListener(this::fireModifiedEvent);
96  }
97  }
98 
103  public void addShortcutListener(@NotNull final ShortcutListener listener) {
104  listeners.add(listener);
105  }
106 
111  public void removeShortcutListener(@NotNull final ShortcutListener listener) {
112  listeners.add(listener);
113  }
114 
118  private void fireModifiedEvent() {
119  for (ShortcutListener listener : listeners) {
120  listener.shortcutModified();
121  }
122  }
123 
128  @NotNull
129  public String getTooltipText() {
130  if (spell != null) {
131  return command+"\n"+spell.getTooltipText();
132  }
133  return command;
134  }
135 
141  public boolean displaysFace(@NotNull final Face face) {
142  return spell != null && face.getFaceNum() == spell.getFaceNum();
143  }
144 
150  public boolean isImmediate() {
151  return command.startsWith("invoke ") || command.startsWith("use_skill ");
152  }
153 
158  public void toggleImmediate() {
159  if (command.startsWith("cast ")) {
160  command = "invoke "+command.substring(5);
162  } else if (command.startsWith("invoke ")) {
163  command = "cast "+command.substring(7);
165  } else if (command.startsWith("ready_skill ")) {
166  command = "use_skill "+command.substring(12);
168  } else if (command.startsWith("use_skill ")) {
169  command = "ready_skill "+command.substring(10);
171  }
172  }
173 
174 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.shortcuts.Shortcut.removeShortcutListener
void removeShortcutListener(@NotNull final ShortcutListener listener)
Definition: Shortcut.java:111
com.realtime.crossfire.jxclient.shortcuts.Shortcut.listeners
final EventListenerList2< ShortcutListener > listeners
Definition: Shortcut.java:54
com.realtime.crossfire.jxclient.shortcuts.Shortcut.Shortcut
Shortcut(@NotNull final String command, @Nullable final Spell spell)
Definition: Shortcut.java:62
com.realtime.crossfire.jxclient.util.EventListenerList2
Definition: EventListenerList2.java:37
com.realtime.crossfire.jxclient.faces
Definition: AbstractFaceQueue.java:23
com.realtime.crossfire.jxclient.spells.Spell.removeSpellListener
void removeSpellListener(@NotNull final SpellListener listener)
Definition: Spell.java:428
com.realtime.crossfire.jxclient.spells.Spell
Definition: Spell.java:37
com.realtime.crossfire.jxclient.shortcuts.Shortcut.toggleImmediate
void toggleImmediate()
Definition: Shortcut.java:158
com.realtime.crossfire.jxclient.shortcuts.ShortcutListener
Definition: ShortcutListener.java:31
com.realtime.crossfire.jxclient.shortcuts.Shortcut.spell
final Spell spell
Definition: Shortcut.java:48
com.realtime.crossfire.jxclient.shortcuts.Shortcut.displaysFace
boolean displaysFace(@NotNull final Face face)
Definition: Shortcut.java:141
com.realtime.crossfire.jxclient.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.shortcuts.Shortcut.getSpell
Spell getSpell()
Definition: Shortcut.java:86
com.realtime.crossfire.jxclient.spells.Spell.getFaceNum
int getFaceNum()
Definition: Spell.java:215
com.realtime.crossfire
com.realtime.crossfire.jxclient.shortcuts.Shortcut.getCommand
String getCommand()
Definition: Shortcut.java:76
com.realtime
com.realtime.crossfire.jxclient.shortcuts.Shortcut.getTooltipText
String getTooltipText()
Definition: Shortcut.java:129
com
com.realtime.crossfire.jxclient.shortcuts.Shortcut
Definition: Shortcut.java:35
com.realtime.crossfire.jxclient.spells.Spell.addSpellListener
void addSpellListener(@NotNull final SpellListener listener)
Definition: Spell.java:420
com.realtime.crossfire.jxclient.spells.Spell.getTooltipText
String getTooltipText()
Definition: Spell.java:357
com.realtime.crossfire.jxclient.shortcuts.Shortcut.isImmediate
boolean isImmediate()
Definition: Shortcut.java:150
com.realtime.crossfire.jxclient.shortcuts.Shortcut.addShortcutListener
void addShortcutListener(@NotNull final ShortcutListener listener)
Definition: Shortcut.java:103
com.realtime.crossfire.jxclient.faces.Face
Definition: Face.java:37
com.realtime.crossfire.jxclient.shortcuts.Shortcut.command
String command
Definition: Shortcut.java:41
com.realtime.crossfire.jxclient.shortcuts.Shortcut.dispose
void dispose()
Definition: Shortcut.java:93
com.realtime.crossfire.jxclient.shortcuts.Shortcut.fireModifiedEvent
void fireModifiedEvent()
Definition: Shortcut.java:118
com.realtime.crossfire.jxclient.spells
Definition: Spell.java:23