22 package com.realtime.crossfire.jxclient.window;
51 import java.util.HashMap;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
159 private final Map<String, Gui>
dialogs =
new HashMap<>();
168 public void commandDrawextinfoReceived(
final int color,
final int type,
final int subtype, @NotNull
final String message) {
170 throw new IllegalStateException(
"no skin set");
173 @Nullable
final Gui dialog;
174 String effectiveMessage = message;
180 final String[] tmp = message.split(
"\n", 2);
182 effectiveMessage = tmp.length >= 2 ? tmp[1] :
"";
222 if (dialog == null) {
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) {
257 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"account_password");
258 if (passwordField != null) {
265 }
else if (command.equals(
"accountaddplayer") && skin != null) {
268 final GUIText loginField = dialog.getFirstElement(
GUIText.class,
"character_login");
269 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"character_password");
270 final String argumentsLower = arguments.toLowerCase();
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) {
291 final GUIText loginField = dialog.getFirstElement(
GUIText.class,
"account_login");
292 final GUIText passwordField = dialog.getFirstElement(
GUIText.class,
"account_password");
293 final GUIText passwordConfirmField = dialog.getFirstElement(
GUIText.class,
"account_password_confirm");
294 final String argumentsLower = arguments.toLowerCase();
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) {
317 final Gui dialog = skin.
getDialog(
"account_character_new");
318 final GUIText loginField = dialog.getFirstElement(
GUIText.class,
"character_login");
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");
379 if (dialogConnect != null) {
391 public void connected() {
396 public void connectFailed(@NotNull
final String reason) {
398 if (dialogConnect != null) {
426 windowRenderer.setCurrentGui(guiFactory.newGui());
436 public void addDialog(@NotNull
final String name, @NotNull
final Gui dialog) {
518 @SuppressWarnings(
"IfStatementWithIdenticalBranches")
527 }
else if (connected) {
562 throw new IllegalStateException(
"query dialog not set");
570 if (hostname != null) {
572 if (!playerName.isEmpty()) {
575 if (textArea != null) {
580 }
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 boolean[] result =
new boolean[1];
623 if (labelFailure != null) {
627 final String name = dialog.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,
"character_login");
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");
761 throw new IllegalStateException(
"query dialog not set");
764 throw new IllegalStateException(
"skin not set");
788 if (!serverName.isEmpty()) {
798 throw new IllegalStateException(
"keybinding dialog not set");
809 throw new IllegalStateException(
"keybinding dialog not set");
821 if (dialog != null) {
844 if (hostname != null) {
862 if (textArea1 != null) {
868 for (
final Gui dialog :
skin) {
870 if (textArea3 != null) {
889 if (textArea != null && newText != null && !newText.isEmpty()) {
914 @SuppressWarnings(
"NullableProblems")
980 String message = null;
981 switch (clientSocketState) {
983 message =
"Connecting...";
987 message =
"Exchanging version...";
991 message =
"Exchanging configuration...";
995 message =
"Requesting information...";
999 message =
"Starting account session...";
1003 message =
"Joining the game...";
1010 case CONNECT_FAILED:
1011 message =
"Cannot connect to Crossfire server:\n"+param;
1015 assert message != null;
1056 assert
skin != null;
1058 for (
final Gui dialog :
skin) {
1059 dialog.autoSize(width, height);
1075 throw new IllegalStateException(
"skin not set");
1091 if (hostname != null) {
1101 public void selectCharacter(@NotNull
final String accountName, @NotNull
final String characterName) {
1103 if (hostname != null) {
1116 if (textArea != null) {
CommandList getCommandList(@NotNull String name)
Returns a named command list.
START
The start screen is active.
void selectCharacter(@NotNull final String accountName, @NotNull final String characterName)
Updates the selected character name in an account.
Abstract base class for all label classes.
static SettingsEntry< String > getLoginAccountSettingsEntry(@NotNull final String hostname)
Returns the SettingsEntry for the default account name on a server.
static void save(@NotNull final JXCSkin skin, @NotNull final JXCWindowRenderer windowRenderer)
Saves the dialogs state to a file.
Interface for listeners interested gui state changes.
void endRendering()
Ends rendering and reverts the display settings.
void activateDefaultElement()
Activates the first default gui element of this gui.
void setScreenSize(final int screenWidth, final int screenHeight)
Updates the skin's gui elements to a screen size.
void activateMetaserverGui()
Called when the server selection GUI becomes active.
static final int MSG_TYPE_SKILL
drawextinfo message type: message related to using skills.
void setText(@NotNull final String text)
The label text.
Maintains the current GuiState.
void setCurrentGui(@NotNull final Gui gui)
Sets the Gui to display.
Combines a list of GUIElements to for a gui.
DISCONNECT
Disconnect from server.
Encapsulates the message type numbers for drawextinfo messages.
boolean closeDialog(@NotNull final Gui dialog)
Closes a dialog.
Gui getDialogKeyBind()
Returns the key bindings dialog.
final JXCWindowRenderer windowRenderer
The JXCWindowRenderer used to paint the gui.
boolean removeKeyBinding(final boolean perCharacter)
Starts to remove a key binding.
static final int MSG_TYPE_CARD
drawextinfo message type: character did read a card.
void setAccountName(@NotNull final String accountName)
Updates the current account name.
static final int MSG_TYPE_MISC
drawextinfo message type: message that does not fit in any other category.
NEW_CHAR
The new character creation screen is active.
EscAction escPressed(final boolean connected)
The ESC key has been pressed.
void setCharacter(@NotNull final String characterName)
Selects an entry by character name.
Gui dialogDisconnect
The "really disconnect?" dialog.
void setHideInput(final boolean hideInput)
Enables or disables hidden text in the first input field of the queryDialog.
boolean createKeyBinding(final boolean perCharacter, @NotNull final CommandList cmdList)
Adds a key binding.
void updateWindowSize(final int width, final int height)
Sets a new window size.
boolean openDialog(@NotNull final Gui dialog, final boolean autoCloseOnDeactivate)
Opens a dialog.
AbstractLabel dialogConnectLabel
The "message" field within dialogConnect.
CONNECT_FAILED
A connection could not be established.
boolean closeDialog(@NotNull final Gui dialog)
Closes the given dialog.
void openDialog(@NotNull final String name)
Opens a dialog by name.
Gui getMainInterface()
Returns the main window.
static final int MSG_TYPE_MONUMENT
drawextinfo message type: character did read a monument.
String getHostname()
Returns the currently connected server.
Gui getDialogConnect()
Returns the "connection in progress" dialog.
RendererGuiState getGuiState()
Returns the current gui state.
Gui getDialogQuit()
Returns the "really quit?" dialog.
static final int MSG_TYPE_PAPER
drawextinfo message type: character did read a paper.
void updatePlayerName(@NotNull final String playerName)
Sets the current player name.
void updateServerSettings()
Updates server based settings to current screen size.
void toggleDialog(@NotNull final String name)
Toggles a dialog.
boolean windowClosing()
Should be called when the main window is closing.
JXCSkin skin
The currently active skin.
void showGUIStart()
Displays the "start" GUI.
PLAYING
The playing screen is active.
void setActive(final boolean active)
Sets the active state of a GUI element.
final CrossfireFailureListener crossfireFailureListener
The CrossfireFailureListener registered to receive failure messages.
boolean createKeyBinding(final boolean perCharacter, @NotNull final CommandList cmdList)
Starts creating a new key binding.
Gui dialogQuit
The "really quit?" dialog.
void addDialog(@NotNull final String name, @NotNull final Gui dialog)
Adds a dialog for name based lookup.
void showGUIMain()
Displays the "main" GUI.
void hideAccountWindows()
Hides all account-related windows.
final CrossfireServerConnection server
The CrossfireServerConnection instance to monitor.
Gui getMetaInterface()
Returns the server selection window.
Gui getStartInterface()
Returns the start window.
final JXCConnection connection
The JXCConnection to use.
void updateText(@NotNull final CharSequence string)
Sets the displayed text by parsing a string.
void openQueryDialog(@NotNull final String prompt, final int queryType)
Opens the "query" dialog.
A gui element implementing a static text field which may contain media tags.
final TooltipManagerImpl tooltipManager
The TooltipManager for this window.
void detach()
Frees all allocated resources.
CommandList getCommandList(@NotNull final String args)
Returns a named command list.
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
GUIText activateCommandInput()
Activates the command input text field.
Utility class to store or restore the dialog states to/from a file.
CONNECTING
The socket is being established.
static final int MSG_TYPE_COMMAND
drawextinfo message type: response to command processing.
Gui keybindDialog
The keybindings dialog.
void showGUIMeta()
Displays the "server selection" GUI.
static final int MSG_TYPE_ADMIN
drawextinfo message type: general server message.
Renders a Gui instance into a Frame.
final GuiFactory guiFactory
The GuiFactory for creating Gui instances.
void setSkin(@NotNull final JXCSkin skin)
Sets a new skin.
static final int MSG_TYPE_ATTACK
drawextinfo message type: attack related message.
IGNORE
Ignore the key press.
int HIDE_INPUT
Query type: hide input being entered.
GUIText activateCommandInput()
Activates the command input text field.
LOGIN
The login screen is active.
void closeDialogByName(@NotNull final String name)
Closes a dialog by name.
boolean deactivateCommandInput()
Deactivates the command input text field.
void addCrossfireDrawextinfoListener(@NotNull CrossfireDrawextinfoListener listener)
Adds a new listener monitoring the drawextinfo S->C messages.
boolean removeKeyBinding(final boolean perCharacter)
Removes a key binding.
Factory for creating Gui instances.
static final int MSG_TYPE_APPLY
drawextinfo message type: an object was applied.
All defined entries in the settings file.
A GUIHTMLLabel that displays the last received "failure" message.
Interface for listeners interested in the "failure" messages received from the Crossfire server...
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
Gui getDialog(@NotNull final String name)
Returns a dialog by name.
boolean openQuitDialog()
Opens the "quit" dialog.
ACCOUNT
The account management screen is active.
Maintains a set of key/value pairs.
void updateConnectLabel(@NotNull final ClientSocketState clientSocketState, @Nullable final String param)
Updates the "message" field of the connect dialog.
Gui queryDialog
The query dialog.
void activateCommandInput(@Nullable final String newText)
Activates the command input text field.
An Exception thrown if a command does not exist.
Maintains the application's main GUI state.
void attach(@NotNull TooltipManagerImpl tooltipManager)
Attaches this skin to a gui manager.
A GUIList display characters of an account.
void saveKeybindings()
Saves the key bindings to the backing file.
Gui newGui()
Creates a new Gui instance.
QUIT
Quit the application.
All gui states of JXCWindowRenderer.
Gui dialogConnect
The "connect in progress" dialog.
void term()
Terminates the GUI.
static final int MSG_TYPE_SHOP
drawextinfo message type: shop related message.
boolean openDialogByName(@NotNull final String name)
Opens a dialog by name.
void closeTransientDialogs()
Closes all transient dialogs: disconnect, quit, connect, query, and book dialogs. ...
void closeDialog(@NotNull final String name)
Closes the given dialog.
void unsetSkin()
Unsets the current skin.
Gui getDialogQuery()
Returns the dialog for query text input.
static final int MSG_TYPE_SIGN
drawextinfo message type: character did read a sign.
final Settings settings
The Settings to use.
void clearGUI(@NotNull final Gui gui)
Sets a gui to display and clears the display.
Gui getDialogBook(int bookNo)
Returns the popup dialog for readables.
void playerReceived()
A "player" protocol command has been received.
Gui getDialogDisconnect()
Returns the "disconnect from server?" dialog.
static final int MSG_TYPE_ITEM
drawextinfo message type: item related information.
Interface for listeners interested in drawextinfo messages received from the Crossfire server...
Utility class for Swing related functions.
static final int MSG_TYPE_COMMUNICATION
drawextinfo message type: communication between players.
Exception thrown if a skin related problem occurs.
final CrossfireDrawextinfoListener crossfireDrawextinfoListener
The CrossfireDrawextinfoListener attached to server.
static final int MSG_TYPE_MOTD
drawextinfo message type: motd text.
static SettingsEntry< String > getPlayerSettingsEntry(@NotNull final String hostname)
Returns the SettingsEntry for the default character name on a server.
static final int MSG_TYPE_SPELL
drawextinfo message type: spell related information.
boolean escPressed()
Processes a pressed ESC key.
AbstractLabel getTooltipLabel()
Returns the AbstractLabel that is used to display tooltips.
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.
boolean toggleDialog(@NotNull final Gui dialog)
Toggles a dialog: if the dialog is not shown, show it; else hide it.
boolean currentQueryDialogIsNamePrompt
Whether the currently shown query dialog is the character name prompt.
void putString(@NotNull final SettingsEntry<?> key, @NotNull final String value)
Stores a key/value pair.
Action after ESC has been pressed.
static final SettingsEntry< String > SERVER
The server to which the previous connection was made.
void removeCrossfireFailureListener(@NotNull CrossfireFailureListener listener)
Removes a listener to be notified of failure messages.
void setTooltip(@Nullable final Component tooltip)
Sets the tooltip to use, or.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
void setText(@NotNull final String text)
Sets the entered text.
void showCharacters(final int count)
Displays the window with the characters for an account.
A list of GUICommand instances.
void setGuiState(@NotNull final RendererGuiState rendererGuiState)
Sets the current gui state.
void closeQueryDialog()
Closes the "query" dialog.
Interface for listeners interested in query messages received from the Crossfire server.
void setSelectedHostname(@NotNull final String serverName)
Selects a server entry.
void openKeybindDialog()
Opens the keybinding dialog.
String getAccountName()
Returns the current account name.
static final int MSG_TYPE_DIALOG
drawextinfo message type: a NPC/magic mouth/altar/etc.
Connection progress states of the Crossfire server connection.
void manageAccount()
Displays the main account dialog, to let the player login or create a new account.
void addCrossfireFailureListener(@NotNull CrossfireFailureListener listener)
Adds a listener to be notified of failure messages.
static final int MSG_TYPE_ATTRIBUTE
drawextinfo message type: attribute (stats, resistances, etc.) change message.
void closeKeybindDialog()
Closes the keybinding dialog.
static final int MSG_TYPE_VICTIM
drawextinfo message type: something bad is happening to the player.
boolean openDialog(@NotNull final Gui dialog, final boolean autoCloseOnDeactivate)
Opens a dialog.
static void invokeAndWait(@NotNull final Runnable runnable)
Calls SwingUtilities#invokeAndWait(Runnable) if not on the EDT or calls the Runnable directly if on t...
final KeybindingsManager keybindingsManager
The key bindings manager for this window.
static final int MSG_TYPE_BOOK
drawextinfo message type: character did read a book.
Abstract base class for text input fields.
final Map< String, Gui > dialogs
Maps dialog name to dialog instance.
void removeCrossfireDrawextinfoListener(@NotNull CrossfireDrawextinfoListener listener)
Removes the given listener from the list of objects listening to the drawextinfo S->C messages...
void setHideInput(final boolean hideInput)
Enables or disables hidden text.
String getString(@NotNull final SettingsEntry<?> key)
Returns the string associated with the specified key at a node, or.
META
The server selection screen is active.