 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.window;
51 import java.util.Collection;
52 import java.util.HashMap;
53 import java.util.Locale;
55 import java.util.concurrent.atomic.AtomicBoolean;
56 import org.jetbrains.annotations.NotNull;
57 import org.jetbrains.annotations.Nullable;
158 private final Map<String, Gui>
dialogs =
new HashMap<>();
167 public void commandDrawextinfoReceived(
final int color,
final int type,
final int subtype, @NotNull
final String message) {
169 throw new IllegalStateException(
"no skin set");
172 @Nullable
final Gui dialog;
173 String effectiveMessage = message;
179 final String[] tmp = message.split(
"\n", 2);
181 effectiveMessage = tmp.length >= 2 ? tmp[1] :
"";
222 if (dialog ==
null) {
230 log.
updateText(effectiveMessage, type, subtype);
233 label.
setText(effectiveMessage);
239 public void setDebugMode(
final boolean printMessageTypes) {
253 public void failure(@NotNull
final String command, @NotNull
final String arguments) {
254 if (command.equals(
"accountlogin") &&
skin !=
null) {
258 if (passwordField !=
null) {
265 }
else if (command.equals(
"accountaddplayer") &&
skin !=
null) {
270 final String argumentsLower = arguments.toLowerCase(Locale.ENGLISH);
271 if (argumentsLower.contains(
"password")) {
272 if (passwordField !=
null) {
276 }
else if (argumentsLower.contains(
"character")) {
277 if (loginField !=
null) {
281 if (passwordField !=
null) {
288 }
else if (command.equals(
"accountnew") &&
skin !=
null) {
294 final String argumentsLower = arguments.toLowerCase(Locale.ENGLISH);
295 if (argumentsLower.contains(
"password")) {
296 if (passwordField !=
null) {
300 if (passwordConfirmField !=
null) {
301 passwordConfirmField.
setText(
"");
303 }
else if (argumentsLower.contains(
"account")) {
304 if (loginField !=
null) {
308 if (passwordField !=
null) {
315 }
else if (command.equals(
"createplayer") &&
skin !=
null) {
319 if (loginField !=
null) {
329 public void clearFailure() {
340 @SuppressWarnings(
"FieldCanBeLocal")
344 public void start() {
353 public void metaserver() {
363 public void preConnecting(@NotNull
final String serverInfo) {
368 public void connecting(@NotNull
final String serverInfo) {
370 throw new IllegalStateException(
"no skin set");
386 public void connecting(@NotNull
final ClientSocketState clientSocketState, @NotNull
final String param) {
391 public void connected() {
396 public void connectFailed(@NotNull
final String reason) {
435 public void addDialog(@NotNull
final String name, @NotNull
final Gui dialog) {
517 @SuppressWarnings(
"StatementWithEmptyBody")
526 }
else if (connected) {
561 throw new IllegalStateException(
"query dialog not set");
569 if (hostname !=
null) {
571 if (!playerName.isEmpty()) {
574 if (textArea !=
null) {
579 }
else if (prompt.startsWith(
"[y] to roll new stats") || prompt.startsWith(
"Welcome, Brave New Warrior!")) {
602 if (dialog !=
null) {
615 private boolean openDialog(@NotNull
final Gui dialog,
final boolean autoCloseOnDeactivate) {
616 final AtomicBoolean result =
new AtomicBoolean();
623 if (labelFailure !=
null) {
627 final String name = dialog.getComponent().getName();
630 case "account_login":
631 final GUIText loginField = dialog.getFirstElement(
GUIText.class,
"account_login");
632 if (loginField ==
null) {
633 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"account_password");
634 if (passwordField !=
null) {
639 if (hostname !=
null) {
641 if (accountName.isEmpty()) {
645 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"account_password");
646 if (passwordField !=
null) {
650 loginField.
setText(accountName);
652 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"account_password");
653 if (passwordField !=
null) {
662 case "account_characters":
664 if (characterList !=
null) {
666 if (accountName !=
null) {
668 if (hostname !=
null) {
670 if (!characterName.isEmpty()) {
678 case "account_character_new":
679 final GUIText characterField = dialog.getFirstElement(
GUIText.class,
"account_character_create");
680 if (characterField !=
null) {
708 throw new IllegalStateException(
"query dialog not set");
721 throw new IllegalStateException(
"skin not set");
742 throw new IllegalStateException(
"skin not set");
762 throw new IllegalStateException(
"query dialog not set");
765 throw new IllegalStateException(
"skin not set");
777 if (!ignoreQueryDialog) {
791 if (!serverName.isEmpty()) {
801 throw new IllegalStateException(
"keybinding dialog not set");
812 throw new IllegalStateException(
"keybinding dialog not set");
824 if (dialog !=
null) {
847 if (hostname !=
null) {
865 if (textArea1 !=
null) {
873 if (textArea3 !=
null) {
892 if (textArea !=
null && newText !=
null && !newText.isEmpty()) {
978 final String message =
switch (clientSocketState) {
979 case CONNECTING ->
"Connecting...";
980 case VERSION ->
"Exchanging version...";
981 case SETUP ->
"Exchanging configuration...";
982 case REQUESTINFO -> param ==
null || param.isEmpty() ?
"Requesting information" :
"Requesting information: "+param;
983 case ACCOUNT_INFO ->
"Starting account session...";
984 case ADDME ->
"Joining the game...";
985 case CONNECTED ->
"Done.";
986 case CONNECT_FAILED ->
"Cannot connect to Crossfire server:\n"+param;
1027 assert
skin !=
null;
1030 dialog.autoSize(width, height);
1046 throw new IllegalStateException(
"skin not set");
1063 throw new IllegalStateException(
"skin not set");
1075 if (hostname !=
null) {
1085 public void selectCharacter(@NotNull
final String accountName, @NotNull
final String characterName) {
1087 if (hostname !=
null) {
1100 if (textArea !=
null) {
1111 dialog.setOpaqueDialogBackground(opaque);
1122 dialog.setShowSentCommands(showSentCommands);
1132 dialog.setShowTimestamps(showTimestamps);
Abstract base class for text input fields.
Interface for listeners interested in the "failure" messages received from the Crossfire server.
Utility class for Swing related functions.
void activateMetaserverGui()
Called when the server selection GUI becomes active.
void showCharacters(final int count)
Displays the window with the characters for an account.
Collection< String > getCommandListNames()
Returns all names of command lists.
CommandList getCommandList(@NotNull String name)
Returns a named command list.
JXCSkin skin
The currently active skin.
void removeCrossfireDrawextinfoListener(@NotNull CrossfireDrawextinfoListener listener)
Removes the given listener from the list of objects listening to the drawextinfo S->C messages.
Combines a list of GUIElements to for a gui.
void selectCharacter(@NotNull final String accountName, @NotNull final String characterName)
Updates the selected character name in an account.
final KeybindingsManager keybindingsManager
The key bindings manager for this window.
int HIDE_INPUT
Query type: hide input being entered.
All defined entries in the settings file.
void toggleDialog(@NotNull final String name)
Toggles a dialog.
Gui dialogDisconnect
The "really disconnect?" dialog.
void setOpaqueDialogBackground(final boolean opaque)
Sets whether the dialog's background is opaque.
START
The start screen is active.
void endRendering()
Ends rendering and reverts the display settings.
static final int MSG_TYPE_MONUMENT
drawextinfo message type: character did read a monument.
void setShowSentCommands(final boolean showSentCommands)
Sets whether the commands sent to the server should be shown in the messages dialog.
void hideAccountWindows()
Hides all account-related windows.
Gui getDialogKeyBind()
Returns the key bindings dialog.
IGNORE
Ignore the key press.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
final CrossfireServerConnection server
The CrossfireServerConnection instance to monitor.
void setCharacter(@NotNull final String characterName)
Selects an entry by character name.
static final int MSG_TYPE_SKILL
drawextinfo message type: message related to using skills.
Gui getMainInterface()
Returns the main window.
void setCurrentGui(@NotNull final Gui gui)
Sets the Gui to display.
void updatePlayerName(@NotNull final String playerName)
Sets the current player name.
Maintains the application's main GUI state.
void addCrossfireDrawextinfoListener(@NotNull CrossfireDrawextinfoListener listener)
Adds a new listener monitoring the drawextinfo S->C messages.
Abstract base class for all label classes.
void setSkin(@NotNull final JXCSkin skin)
Sets a new skin.
void updateConnectLabel(@NotNull final ClientSocketState clientSocketState, @Nullable final CharSequence param)
Updates the "message" field of the connect dialog.
void showGUIMain()
Displays the "main" GUI.
void addDialog(@NotNull final String name, @NotNull final Gui dialog)
Adds a dialog for name based lookup.
void openDialog(@NotNull final String name)
Opens a dialog by name.
Gui getDialogConnect()
Returns the "connection in progress" dialog.
boolean createKeyBinding(final boolean perCharacter, @NotNull final CommandList cmdList)
Adds a key binding.
META
The server selection screen is active.
void openQueryDialog(@NotNull final String prompt, final int queryType)
Opens the "query" dialog.
Gui getDialogQuit()
Returns the "really quit?" dialog.
CommandList getCommandList(@NotNull final String args)
Returns a named command list.
Gui dialogQuit
The "really quit?" dialog.
Interface for listeners interested gui state changes.
boolean openDialog(@NotNull final Gui dialog, final boolean autoCloseOnDeactivate)
Opens a dialog.
static final int MSG_TYPE_MOTD
drawextinfo message type: motd text.
static final int MSG_TYPE_BOOK
drawextinfo message type: character did read a book.
Encapsulates the message type numbers for drawextinfo messages.
CONNECTING
The socket is being established.
LOGIN
The login screen is active.
EscAction escPressed(final boolean connected)
The ESC key has been pressed.
void setSelectedHostname(@NotNull final String serverName)
Selects a server entry.
boolean closeDialog(@NotNull final Gui dialog)
Closes the given dialog.
final JXCWindowRenderer windowRenderer
The JXCWindowRenderer used to paint the gui.
void setTooltip(@Nullable final Component tooltip)
Sets the tooltip to use, or.
final JXCConnection connection
The JXCConnection to use.
Gui getStartInterface()
Returns the start window.
void setHideInput(final boolean hideInput)
Enables or disables hidden text.
void updateWindowSize(final int width, final int height)
Sets a new window size.
static final int MSG_TYPE_SIGN
drawextinfo message type: character did read a sign.
PLAYING
The playing screen is active.
void setHideInput(final boolean hideInput)
Enables or disables hidden text in the first input field of the queryDialog.
Exception thrown if a skin related problem occurs.
GUIText activateCommandInput()
Activates the command input text field.
static final int MSG_TYPE_CARD
drawextinfo message type: character did read a card.
Action after ESC has been pressed.
String getHostname()
Returns the currently connected server.
A GUIList display characters of an account.
static SettingsEntry< String > getLoginAccountSettingsEntry(@NotNull final String hostname)
Returns the SettingsEntry for the default account name on a server.
Gui getMetaInterface()
Returns the server selection window.
static void save(@NotNull final JXCSkin skin, @NotNull final JXCWindowRenderer windowRenderer)
Saves the dialogs state to a file.
void showGUIStart()
Displays the "start" GUI.
boolean openQuitDialog()
Opens the "quit" dialog.
final CrossfireFailureListener crossfireFailureListener
The CrossfireFailureListener registered to receive failure messages.
ACCOUNT
The account management screen is active.
QUIT
Quit the application.
AbstractLabel dialogConnectLabel
The "message" field within dialogConnect.
void detach()
Frees all allocated resources.
boolean deactivateCommandInput()
Deactivates the command input text field.
void addCrossfireFailureListener(@NotNull CrossfireFailureListener listener)
Adds a listener to be notified of failure messages.
static final SettingsEntry< String > SERVER
The server to which the previous connection was made.
boolean removeKeyBinding(final boolean perCharacter)
Removes a key binding.
static final int MSG_TYPE_APPLY
drawextinfo message type: an object was applied.
Gui dialogConnect
The "connect in progress" dialog.
void closeDialogByName(@NotNull final String name)
Closes a dialog by name.
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
static final int MSG_TYPE_COMMAND
drawextinfo message type: response to command processing.
Gui keybindDialog
The keybindings dialog.
static final int MSG_TYPE_MISC
drawextinfo message type: message that does not fit in any other category.
final TooltipManagerImpl tooltipManager
The TooltipManager for this window.
Maintains the current GuiState.
Gui getDialog(@NotNull final String name)
Returns a dialog by name.
Gui queryDialog
The query dialog.
void activateDefaultElement()
Activates the first default gui element of this gui.
static final int MSG_TYPE_ADMIN
drawextinfo message type: general server message.
void setGuiState(@NotNull final RendererGuiState rendererGuiState)
Sets the current gui state.
void showGUIMeta()
Displays the "server selection" GUI.
Utility class to store or restore the dialog states to/from a file.
static final int MSG_TYPE_CLIENT
drawextinfo message type: client originated messages.
boolean openDialog(@NotNull final Gui dialog, final boolean autoCloseOnDeactivate)
Opens a dialog.
An Exception thrown if a command does not exist.
String getAccountName()
Returns the current account name.
boolean openDialogByName(@NotNull final String name)
Opens a dialog by name.
static final int MSG_TYPE_ATTRIBUTE
drawextinfo message type: attribute (stats, resistances, etc.) change message.
boolean removeKeyBinding(final boolean perCharacter)
Starts to remove a key binding.
void setText(@NotNull final String text)
Sets the label text.
Renders a Gui instance into a Frame.
void unsetSkin()
Unsets the current skin.
Interface for listeners interested in query messages received from the Crossfire server.
void attach(@NotNull TooltipManagerImpl tooltipManager)
Attaches this skin to a gui manager.
NEW_CHAR
The new character creation screen is active.
Maintains a set of key/value pairs.
static final int MSG_TYPE_DIALOG
drawextinfo message type: a NPC/magic mouth/altar/etc.
static final int MSG_TYPE_PAPER
drawextinfo message type: character did read a paper.
boolean windowClosing()
Should be called when the main window is closing.
Gui getDialogQuery()
Returns the dialog for query text input.
boolean currentQueryDialogIsNamePrompt
Whether the currently shown query dialog is the character name prompt.
Collection< String > getCommandListNames()
Returns the names of all named command lists.
void updateServerSettings()
Updates server based settings to current screen size.
boolean createKeyBinding(final boolean perCharacter, @NotNull final CommandList cmdList)
Starts creating a new key binding.
Interface for listeners interested in drawextinfo messages received from the Crossfire server.
Gui getDialogBook(int bookNo)
Returns the popup dialog for readables.
void closeQueryDialog()
Closes the "query" dialog.
GuiManager(@NotNull final GuiStateManager guiStateManager, @NotNull final TooltipManagerImpl tooltipManager, @NotNull final Settings settings, @NotNull final CrossfireServerConnection server, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GuiFactory guiFactory, @NotNull final KeybindingsManager keybindingsManager, @NotNull final JXCConnection connection)
Creates a new instance.
Factory for creating Gui instances.
A list of GUICommand instances.
void closeDialog(@NotNull final String name)
Closes the given dialog.
static final int MSG_TYPE_ATTACK
drawextinfo message type: attack related message.
void clearGUI(@NotNull final Gui gui)
Sets a gui to display and clears the display.
Gui getDialogDisconnect()
Returns the "disconnect from server?" dialog.
final Settings settings
The Settings to use.
A GUIHTMLLabel that displays the last received "failure" message.
void setShowTimestamps(final boolean showTimestamps)
Sets whether timestamps shown in the messages dialog.
void term()
Terminates the GUI.
void activateCommandInput(@Nullable final String newText)
Activates the command input text field.
AbstractLabel getTooltipLabel()
Returns the AbstractLabel that is used to display tooltips.
void saveGlobalKeybindings()
Saves the global key bindings to the backing file.
void playerReceived()
A "player" protocol command has been received.
boolean closeDialog(@NotNull final Gui dialog)
Closes a dialog.
void manageAccount()
Displays the main account dialog, to let the player login or create a new account.
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
void removeCrossfireFailureListener(@NotNull CrossfireFailureListener listener)
Removes a listener to be notified of failure messages.
GUIText activateCommandInput()
Activates the command input text field.
void setText(@NotNull final String text)
Sets the entered text.
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_)
Returns the first gui element of this gui belonging to the given class.
void updateText(@NotNull final CharSequence string, final int type, final int subtype)
Sets the displayed text by parsing a string.
RendererGuiState getGuiState()
Returns the current gui state.
boolean escPressed()
Processes a pressed ESC key.
static SettingsEntry< String > getPlayerSettingsEntry(@NotNull final String hostname)
Returns the SettingsEntry for the default character name on a server.
Connection progress states of the Crossfire server connection.
String getString(@NotNull final SettingsEntry<?> key)
Returns the string associated with the specified key at a node, or.
static final int MSG_TYPE_ITEM
drawextinfo message type: item related information.
void putString(@NotNull final SettingsEntry<?> key, @NotNull final String value)
Stores a key/value pair.
void closeTransientDialogs(final boolean ignoreQueryDialog)
Closes all transient dialogs: disconnect, quit, connect, query, and book dialogs.
void closeKeybindDialog()
Closes the keybinding dialog.
final CrossfireDrawextinfoListener crossfireDrawextinfoListener
The CrossfireDrawextinfoListener attached to server.
void setActive(final boolean active)
Sets the active state of a GUI element.
static void invokeAndWait(@NotNull final Runnable runnable)
Calls SwingUtilities#invokeAndWait(Runnable) if not on the EDT or calls the Runnable directly if on t...
A gui element implementing a static text field which may contain media tags.
boolean toggleDialog(@NotNull final Gui dialog)
Toggles a dialog: if the dialog is not shown, show it; else hide it.
final Map< String, Gui > dialogs
Maps dialog name to dialog instance.
void setAccountName(@NotNull final String accountName)
Updates the current account name.
CONNECT_FAILED
A connection could not be established.
DISCONNECT
Disconnect from server.
static final int MSG_TYPE_SHOP
drawextinfo message type: shop related message.
static final int MSG_TYPE_SPELL
drawextinfo message type: spell related information.
void openKeybindDialog()
Opens the keybinding dialog.
static final int MSG_TYPE_COMMUNICATION
drawextinfo message type: communication between players.
static final int MSG_TYPE_VICTIM
drawextinfo message type: something bad is happening to the player.
All gui states of JXCWindowRenderer.