Crossfire JXClient, Trunk  R20561
GuiManager.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-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.window;
23 
51 import java.util.HashMap;
52 import java.util.Map;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
55 
60 public class GuiManager {
61 
65  @Nullable
66  private JXCSkin skin;
67 
71  @NotNull
73 
77  @NotNull
78  private final GuiFactory guiFactory;
79 
83  @Nullable
84  private Gui queryDialog;
85 
89  @Nullable
90  private Gui keybindDialog;
91 
95  @NotNull
97 
102  @Nullable
103  private Gui dialogQuit;
104 
109  @Nullable
111 
116  @Nullable
118 
123  @Nullable
125 
130 
134  @NotNull
136 
140  @NotNull
141  private final Settings settings;
142 
146  @NotNull
147  private final JXCConnection connection;
148 
152  @NotNull
154 
158  @NotNull
159  private final Map<String, Gui> dialogs = new HashMap<>();
160 
164  @NotNull
166 
167  @Override
168  public void commandDrawextinfoReceived(final int color, final int type, final int subtype, @NotNull final String message) {
169  if (skin == null) {
170  throw new IllegalStateException("no skin set");
171  }
172 
173  @Nullable final Gui dialog;
174  String effectiveMessage = message;
175  switch (type) {
177  dialog = skin.getDialogBook(1);
178  final AbstractLabel title = dialog.getFirstElementEndingWith(AbstractLabel.class, "_title");
179  if (title != null) {
180  final String[] tmp = message.split("\n", 2);
181  title.setText(tmp[0]);
182  effectiveMessage = tmp.length >= 2 ? tmp[1] : "";
183  }
184  break;
185 
191  dialog = null;
192  break;
193 
195  /*
196  * We do not display a MOTD dialog, because it interferes with the
197  * query dialog that gets displayed just after it.
198  */
199  dialog = null;
200  break;
201 
214  dialog = null;
215  break;
216 
217  default:
218  dialog = null;
219  break;
220  }
221 
222  if (dialog == null) {
223  return;
224  }
225 
226  final AbstractLabel label = dialog.getFirstElementNotEndingWith(AbstractLabel.class, "_title");
227  if (label == null) {
228  final GUILabelLog log = dialog.getFirstElement(GUILabelLog.class);
229  if (log != null) {
230  log.updateText(effectiveMessage);
231  }
232  } else {
233  label.setText(effectiveMessage);
234  }
235  openDialog(dialog, false);
236  }
237 
238  @Override
239  public void setDebugMode(final boolean printMessageTypes) {
240  // ignore
241  }
242 
243  };
244 
249  @NotNull
251 
252  @Override
253  public void failure(@NotNull final String command, @NotNull final String arguments) {
254  if (command.equals("accountlogin") && skin != null) {
255  try {
256  final Gui dialog = skin.getDialog("account_login");
257  final GUIText passwordField = dialog.getFirstElement(GUIText.class, "account_password");
258  if (passwordField != null) {
259  passwordField.setText("");
260  passwordField.setActive(true);
261  }
262  } catch (final JXCSkinException ignored) {
263  // ignore if dialog doesn't exist
264  }
265  } else if (command.equals("accountaddplayer") && skin != null) {
266  try {
267  final Gui dialog = skin.getDialog("account_link");
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) {
273  passwordField.setText("");
274  passwordField.setActive(true);
275  }
276  } else if (argumentsLower.contains("character")) {
277  if (loginField != null) {
278  loginField.setActive(true);
279  }
280  } else {
281  if (passwordField != null) {
282  passwordField.setActive(true);
283  }
284  }
285  } catch (final JXCSkinException ignored) {
286  // ignore if dialog doesn't exist
287  }
288  } else if (command.equals("accountnew") && skin != null) {
289  try {
290  final Gui dialog = skin.getDialog("account_create");
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) {
297  passwordField.setText("");
298  passwordField.setActive(true);
299  }
300  if (passwordConfirmField != null) {
301  passwordConfirmField.setText("");
302  }
303  } else if (argumentsLower.contains("account")) {
304  if (loginField != null) {
305  loginField.setActive(true);
306  }
307  } else {
308  if (passwordField != null) {
309  passwordField.setActive(true);
310  }
311  }
312  } catch (final JXCSkinException ignored) {
313  // ignore if dialog doesn't exist
314  }
315  } else if (command.equals("createplayer") && skin != null) {
316  try {
317  final Gui dialog = skin.getDialog("account_character_new");
318  final GUIText loginField = dialog.getFirstElement(GUIText.class, "character_login");
319  if (loginField != null) {
320  loginField.setActive(true);
321  }
322  } catch (final JXCSkinException ignored) {
323  // ignore if dialog doesn't exist
324  }
325  }
326  }
327 
328  @Override
329  public void clearFailure() {
330  // ignore
331  }
332 
333  };
334 
339  @NotNull
340  @SuppressWarnings("FieldCanBeLocal")
342 
343  @Override
344  public void start() {
346  server.removeCrossfireDrawextinfoListener(crossfireDrawextinfoListener);
347  server.removeCrossfireFailureListener(crossfireFailureListener);
348  windowRenderer.setGuiState(RendererGuiState.START);
349  showGUIStart();
350  }
351 
352  @Override
353  public void metaserver() {
355  server.removeCrossfireDrawextinfoListener(crossfireDrawextinfoListener);
356  server.removeCrossfireFailureListener(crossfireFailureListener);
357  windowRenderer.setGuiState(RendererGuiState.META);
358  showGUIMeta();
360  }
361 
362  @Override
363  public void preConnecting(@NotNull final String serverInfo) {
364  // ignore
365  }
366 
367  @Override
368  public void connecting(@NotNull final String serverInfo) {
369  if (skin == null) {
370  throw new IllegalStateException("no skin set");
371  }
372 
374  windowRenderer.updateServerSettings();
375  server.addCrossfireDrawextinfoListener(crossfireDrawextinfoListener);
376  server.addCrossfireFailureListener(crossfireFailureListener);
377  windowRenderer.setGuiState(RendererGuiState.LOGIN);
378  showGUIMain();
379  if (dialogConnect != null) {
380  openDialog(dialogConnect, false);
382  }
383  }
384 
385  @Override
386  public void connecting(@NotNull final ClientSocketState clientSocketState) {
387  updateConnectLabel(clientSocketState, null);
388  }
389 
390  @Override
391  public void connected() {
393  }
394 
395  @Override
396  public void connectFailed(@NotNull final String reason) {
398  if (dialogConnect != null) {
399  openDialog(dialogConnect, false);
401  }
402  }
403 
404  };
405 
417  public 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) {
418  this.tooltipManager = tooltipManager;
419  this.settings = settings;
420  this.server = server;
421  this.windowRenderer = windowRenderer;
422  this.guiFactory = guiFactory;
423  this.keybindingsManager = keybindingsManager;
424  this.connection = connection;
425  guiStateManager.addGuiStateListener(guiStateListener);
426  windowRenderer.setCurrentGui(guiFactory.newGui());
427  queryDialog = guiFactory.newGui();
428  keybindDialog = guiFactory.newGui();
429  }
430 
436  public void addDialog(@NotNull final String name, @NotNull final Gui dialog) {
437  dialogs.put(name, dialog);
438  }
439 
443  public void playerReceived() {
445  openDialogByName("messages"); // hack for race selection
446  }
448  }
449 
454  public void manageAccount() {
455  if (dialogConnect != null) {
457  }
460  openDialogByName("account_login");
461  }
462 
467  public void showCharacters(final int count) {
470  }
472  if (count == 0) {
473  openDialogByName("account_character_new");
474  } else {
475  openDialogByName("account_characters");
476  }
477  }
478 
482  public void hideAccountWindows() {
483  closeDialogByName("account_login");
484  closeDialogByName("account_create");
485  closeDialogByName("account_characters");
486  closeDialogByName("account_link");
487  closeDialogByName("account_character_new");
488  closeDialogByName("account_password");
489  }
490 
495  public boolean openQuitDialog() {
498  }
499 
500  if (dialogQuit == null) {
501  return false;
502  }
503 
504  if (dialogDisconnect != null) {
506  }
507  assert dialogQuit != null;
508  openDialog(dialogQuit, false);
509  return true;
510  }
511 
518  @SuppressWarnings("IfStatementWithIdenticalBranches")
519  public EscAction escPressed(final boolean connected) {
521  assert keybindDialog != null;
523  } else if (windowRenderer.deactivateCommandInput()) {
524  // ignore
525  } else if (skin != null && closeDialog(skin.getDialogBook(1))) {
526  // ignore
527  } else if (connected) {
528  if (dialogDisconnect == null) {
529  return EscAction.DISCONNECT;
530  }
531  if (openDialog(dialogDisconnect, false)) {
532  if (dialogQuit != null) {
534  }
535  } else {
536  assert dialogDisconnect != null;
538  }
539  } else {
540  if (dialogQuit == null) {
541  return EscAction.QUIT;
542  }
543  if (openDialog(dialogQuit, false)) {
544  if (dialogDisconnect != null) {
546  }
547  } else {
548  assert dialogQuit != null;
550  }
551  }
552  return EscAction.IGNORE;
553  }
554 
560  public void openQueryDialog(@NotNull final String prompt, final int queryType) {
561  if (queryDialog == null) {
562  throw new IllegalStateException("query dialog not set");
563  }
564 
565  openDialog(queryDialog, false);
567  currentQueryDialogIsNamePrompt = prompt.startsWith("What is your name?");
569  final String hostname = connection.getHostname();
570  if (hostname != null) {
571  final String playerName = settings.getString(SettingsEntries.getPlayerSettingsEntry(hostname));
572  if (!playerName.isEmpty()) {
573  assert queryDialog != null;
574  final GUIText textArea = queryDialog.getFirstElement(GUIText.class);
575  if (textArea != null) {
576  textArea.setText(playerName);
577  }
578  }
579  }
580  } else if (prompt.startsWith("[y] to roll new stats") || prompt.startsWith("Welcome, Brave New Warrior!")) {
582  if (openDialogByName("new_char")) {
583  closeDialogByName("messages");
584  closeDialogByName("status");
585  } else {
586  // fallback: open both message and status dialogs if this skin
587  // does not define a login dialog
588  openDialogByName("messages");
589  openDialogByName("status");
590  }
591  assert queryDialog != null;
592  openDialog(queryDialog, false); // raise dialog
593  }
594  }
595 
600  public void openDialog(@NotNull final String name) {
601  final Gui dialog = dialogs.get(name);
602  if (dialog != null) {
603  openDialog(dialog, false);
604  }
605  }
606 
615  private boolean openDialog(@NotNull final Gui dialog, final boolean autoCloseOnDeactivate) {
616  final boolean[] result = new boolean[1];
618  result[0] = windowRenderer.openDialog(dialog, autoCloseOnDeactivate);
619  if (dialog == queryDialog) {
620  setHideInput(false);
621  } else {
622  final AbstractLabel labelFailure = dialog.getFirstElement(GUILabelFailure.class);
623  if (labelFailure != null) {
624  labelFailure.setText("");
625  }
626 
627  final String name = dialog.getName();
628  if (name != null) {
629  switch (name) {
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) {
635  passwordField.setText("");
636  }
637  } else {
638  final String hostname = connection.getHostname();
639  if (hostname != null) {
640  final String accountName = settings.getString(SettingsEntries.getLoginAccountSettingsEntry(hostname));
641  if (accountName.isEmpty()) {
642  loginField.setText("");
643  loginField.setActive(true);
644 
645  final GUIText passwordField = dialog.getFirstElement(GUIText.class, "account_password");
646  if (passwordField != null) {
647  passwordField.setText("");
648  }
649  } else {
650  loginField.setText(accountName);
651 
652  final GUIText passwordField = dialog.getFirstElement(GUIText.class, "account_password");
653  if (passwordField != null) {
654  passwordField.setText("");
655  passwordField.setActive(true);
656  }
657  }
658  }
659  }
660  break;
661 
662  case "account_characters":
663  final GUICharacterList characterList = dialog.getFirstElement(GUICharacterList.class);
664  if (characterList != null) {
665  final String accountName = server.getAccountName();
666  if (accountName != null) {
667  final String hostname = connection.getHostname();
668  if (hostname != null) {
669  final String characterName = settings.getString(SettingsEntries.getLoginAccountSettingsEntry(hostname, accountName));
670  if (!characterName.isEmpty()) {
671  characterList.setCharacter(characterName);
672  }
673  }
674  }
675  }
676  break;
677 
678  case "account_character_new":
679  final GUIText characterField = dialog.getFirstElement(GUIText.class, "character_login");
680  if (characterField != null) {
681  characterField.setText("");
682  characterField.setActive(true);
683  }
684  break;
685  }
686  }
687  }
688  });
689  return result[0];
690  }
691 
696  public void toggleDialog(@NotNull final String name) {
697  final Gui dialog = dialogs.get(name);
698  if (dialog != null && windowRenderer.toggleDialog(dialog) && dialog == queryDialog) {
699  setHideInput(false);
700  }
701  }
702 
706  public void closeQueryDialog() {
707  if (queryDialog == null) {
708  throw new IllegalStateException("query dialog not set");
709  }
710 
712  }
713 
719  private boolean openDialogByName(@NotNull final String name) {
720  if (skin == null) {
721  throw new IllegalStateException("skin not set");
722  }
723 
724  final Gui dialog;
725  try {
726  dialog = skin.getDialog(name);
727  } catch (final JXCSkinException ignored) {
728  //System.err.println(ex.getLocalizedMessage());
729  return false;
730  }
731 
732  openDialog(dialog, false);
733  return true;
734  }
735 
740  private void closeDialogByName(@NotNull final String name) {
741  if (skin == null) {
742  throw new IllegalStateException("skin not set");
743  }
744 
745  final Gui dialog;
746  try {
747  dialog = skin.getDialog(name);
748  } catch (final JXCSkinException ignored) {
749  // ignore
750  return;
751  }
752  closeDialog(dialog);
753  }
754 
759  private void closeTransientDialogs() {
760  if (queryDialog == null) {
761  throw new IllegalStateException("query dialog not set");
762  }
763  if (skin == null) {
764  throw new IllegalStateException("skin not set");
765  }
766 
767  if (dialogDisconnect != null) {
769  }
770  if (dialogQuit != null) {
772  }
773  if (dialogConnect != null) {
775  }
776  assert queryDialog != null;
778  assert skin != null;
780  }
781 
786  private void activateMetaserverGui() {
787  final String serverName = settings.getString(SettingsEntries.SERVER);
788  if (!serverName.isEmpty()) {
790  }
791  }
792 
796  private void openKeybindDialog() {
797  if (keybindDialog == null) {
798  throw new IllegalStateException("keybinding dialog not set");
799  }
800 
801  openDialog(keybindDialog, false);
802  }
803 
807  public void closeKeybindDialog() {
808  if (keybindDialog == null) {
809  throw new IllegalStateException("keybinding dialog not set");
810  }
811 
813  }
814 
819  public void closeDialog(@NotNull final String name) {
820  final Gui dialog = dialogs.get(name);
821  if (dialog != null) {
822  windowRenderer.closeDialog(dialog);
823  }
824  }
825 
832  public boolean closeDialog(@NotNull final Gui dialog) {
833  return windowRenderer.closeDialog(dialog);
834  }
835 
841  public void updatePlayerName(@NotNull final String playerName) {
843  final String hostname = connection.getHostname();
844  if (hostname != null) {
846  }
847  }
848  }
849 
858  @Nullable
860  // check visible dialogs
861  final GUIText textArea1 = windowRenderer.activateCommandInput();
862  if (textArea1 != null) {
863  return textArea1;
864  }
865 
866  // check invisible dialogs
867  assert skin != null;
868  for (final Gui dialog : skin) {
869  final GUIText textArea3 = JXCWindowRenderer.activateCommandInput(dialog);
870  if (textArea3 != null) {
871  openDialog(dialog, true);
872  return textArea3;
873  }
874  }
875 
876  return null;
877  }
878 
887  public void activateCommandInput(@Nullable final String newText) {
888  final GUIText textArea = activateCommandInput();
889  if (textArea != null && newText != null && !newText.isEmpty()) {
890  textArea.setText(newText);
891  }
892  }
893 
897  public void unsetSkin() {
898  if (skin != null) {
899  skin.detach();
901  skin = null;
902  }
903 
904  queryDialog = null;
905  keybindDialog = null;
906  dialogQuit = null;
907  dialogDisconnect = null;
908  }
909 
914  @SuppressWarnings("NullableProblems")
915  public void setSkin(@NotNull final JXCSkin skin) {
916  this.skin = skin;
924  dialogConnectLabel = dialogConnect == null ? null : dialogConnect.getFirstElement(AbstractLabel.class, "message");
925  }
926 
930  private void showGUIStart() {
932  assert skin != null;
935  }
936 
940  private void showGUIMeta() {
942  assert skin != null;
943  final Gui newGui = skin.getMetaInterface();
945  newGui.activateDefaultElement();
947  }
948 
952  private void showGUIMain() {
954  assert skin != null;
955  final Gui newGui = skin.getMainInterface();
958  }
959 
963  public void term() {
965  if (skin != null) {
967  }
969  }
970 
978  private void updateConnectLabel(@NotNull final ClientSocketState clientSocketState, @Nullable final String param) {
979  if (dialogConnectLabel != null) {
980  String message = null;
981  switch (clientSocketState) {
982  case CONNECTING:
983  message = "Connecting...";
984  break;
985 
986  case VERSION:
987  message = "Exchanging version...";
988  break;
989 
990  case SETUP:
991  message = "Exchanging configuration...";
992  break;
993 
994  case REQUESTINFO:
995  message = "Requesting information...";
996  break;
997 
998  case ACCOUNT_INFO:
999  message = "Starting account session...";
1000  break;
1001 
1002  case ADDME:
1003  message = "Joining the game...";
1004  break;
1005 
1006  case CONNECTED:
1007  message = "Done.";
1008  break;
1009 
1010  case CONNECT_FAILED:
1011  message = "Cannot connect to Crossfire server:\n"+param;
1012  break;
1013  }
1014 
1015  assert message != null;
1016  dialogConnectLabel.setText(message);
1017  }
1018  }
1019 
1026  public boolean createKeyBinding(final boolean perCharacter, @NotNull final CommandList cmdList) {
1027  final boolean result = keybindingsManager.createKeyBinding(perCharacter, cmdList);
1028  if (result) {
1030  }
1031  return result;
1032  }
1033 
1040  public boolean removeKeyBinding(final boolean perCharacter) {
1041  final boolean result = keybindingsManager.removeKeyBinding(perCharacter);
1042  if (result) {
1044  }
1045  return result;
1046  }
1047 
1053  public void updateWindowSize(final int width, final int height) {
1054  if (skin != null) {
1055  skin.setScreenSize(width, height);
1056  assert skin != null;
1058  for (final Gui dialog : skin) {
1059  dialog.autoSize(width, height);
1060  }
1061  tooltipManager.setScreenSize(width, height);
1062  });
1063  }
1064  }
1065 
1072  @NotNull
1073  public CommandList getCommandList(@NotNull final String args) throws NoSuchCommandException {
1074  if (skin == null) {
1075  throw new IllegalStateException("skin not set");
1076  }
1077 
1078  try {
1079  return skin.getCommandList(args);
1080  } catch (final JXCSkinException ex) {
1081  throw new NoSuchCommandException(ex.getMessage(), ex);
1082  }
1083  }
1084 
1089  public void setAccountName(@NotNull final String accountName) {
1090  final String hostname = connection.getHostname();
1091  if (hostname != null) {
1093  }
1094  }
1095 
1101  public void selectCharacter(@NotNull final String accountName, @NotNull final String characterName) {
1102  final String hostname = connection.getHostname();
1103  if (hostname != null) {
1104  settings.putString(SettingsEntries.getLoginAccountSettingsEntry(hostname, accountName), characterName);
1105  }
1106  }
1107 
1113  private void setHideInput(final boolean hideInput) {
1114  assert queryDialog != null;
1115  final GUIText textArea = queryDialog.getFirstElement(GUIText.class);
1116  if (textArea != null) {
1117  textArea.setHideInput(hideInput);
1118  }
1119  }
1120 
1124  public enum EscAction {
1125 
1130 
1135 
1139  QUIT
1140 
1141  }
1142 
1143 }
CommandList getCommandList(@NotNull String name)
Returns a named command list.
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.
Definition: Gui.java:202
void setScreenSize(final int screenWidth, final int screenHeight)
Updates the skin&#39;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.
void setCurrentGui(@NotNull final Gui gui)
Sets the Gui to display.
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
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.
Definition: GuiManager.java:72
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.
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.
Definition: GuiManager.java:66
void showGUIStart()
Displays the "start" GUI.
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.
Definition: JXCSkin.java:40
GUIText activateCommandInput()
Activates the command input text field.
Utility class to store or restore the dialog states to/from a file.
static final int MSG_TYPE_COMMAND
drawextinfo message type: response to command processing.
void showGUIMeta()
Displays the "server selection" GUI.
static final int MSG_TYPE_ADMIN
drawextinfo message type: general server message.
final GuiFactory guiFactory
The GuiFactory for creating Gui instances.
Definition: GuiManager.java:78
void setSkin(@NotNull final JXCSkin skin)
Sets a new skin.
static final int MSG_TYPE_ATTACK
drawextinfo message type: attack related message.
GUIText activateCommandInput()
Activates the command input text field.
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.
Definition: GuiFactory.java:34
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.
Definition: Settings.java:43
void updateConnectLabel(@NotNull final ClientSocketState clientSocketState, @Nullable final String param)
Updates the "message" field of the connect dialog.
void activateCommandInput(@Nullable final String newText)
Activates the command input text field.
Maintains the application&#39;s main GUI state.
Definition: GuiManager.java:60
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.
Definition: GuiFactory.java:54
Gui dialogConnect
The "connect in progress" dialog.
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.
void setScreenSize(final int windowWidth, final int windowHeight)
Updates the current window size.
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.
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.
Definition: Settings.java:124
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.
Definition: GUIText.java:205
void showCharacters(final int count)
Displays the window with the characters for an account.
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.
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.
Definition: GuiManager.java:96
static final int MSG_TYPE_BOOK
drawextinfo message type: character did read a book.
Abstract base class for text input fields.
Definition: GUIText.java:57
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.
Definition: GUIText.java:512
String getString(@NotNull final SettingsEntry<?> key)
Returns the string associated with the specified key at a node, or.
Definition: Settings.java:79