Crossfire JXClient, Trunk
AccountCreateCharacterCommand.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.gui.commands;
24 
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.Iterator;
37 import org.jetbrains.annotations.NotNull;
38 
43 public class AccountCreateCharacterCommand implements GUICommand {
44 
48  @NotNull
50 
54  @NotNull
55  private final AbstractGUIElement element;
56 
60  @NotNull
61  private final GuiFactory guiFactory;
62 
66  @NotNull
67  private final NewCharModel newCharModel;
68 
77  public AccountCreateCharacterCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory, @NotNull final NewCharModel newCharModel) {
78  this.commandCallback = commandCallback;
79  element = button;
80  this.guiFactory = guiFactory;
81  this.newCharModel = newCharModel;
82  }
83 
84  @Override
85  public boolean canExecute() {
86  return true;
87  }
88 
89  @Override
90  public void execute() {
91  final Gui gui = guiFactory.getGui(element);
92  if (gui == null) {
93  return;
94  }
95 
96  final GUIText loginField = gui.getFirstElement(GUIText.class, "account_character_create");
97  if (loginField == null) {
98  return;
99  }
100 
101  final String login = loginField.getText();
102  if (login.isEmpty()) {
103  loginField.setActive(true);
104  return;
105  }
106 
107  final Collection<String> attributes = new ArrayList<>();
108  attributes.add("race "+newCharModel.getRace());
109  attributes.add("class "+newCharModel.getClass_());
110  for (final NewcharStat stat : NewcharStat.values()) {
111  attributes.add(stat.getStatName()+" "+newCharModel.getValue(stat));
112  }
113  attributes.add("starting_map "+newCharModel.getStartingMap());
114  final Choice option = newCharModel.getOption();
115  if (option != null) {
116  final int optionIndex = newCharModel.getOptionIndex();
117  final Iterator<String> it = option.getChoices().keySet().iterator();
118  for (int i = 0; i < optionIndex; i++) {
119  it.next();
120  }
121  attributes.add("choice "+option.getChoiceName()+" "+it.next());
122  }
123  commandCallback.accountCreateCharacter(login, attributes);
124  }
125 
126 }
com.realtime.crossfire.jxclient.gui.textinput.GUIText
Abstract base class for text input fields.
Definition: GUIText.java:61
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.newCharModel
final NewCharModel newCharModel
The global NewCharModel instance.
Definition: AccountCreateCharacterCommand.java:67
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.gui.Gui
Combines a list of GUIElements to for a gui.
Definition: Gui.java:49
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Returns the Gui an element is part of.
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.commandlist.GUICommand
An executable command.
Definition: GUICommand.java:29
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getValue
int getValue(@NotNull final NewcharStat stat)
Returns the base points for a stat.
Definition: NewCharModel.java:353
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.guiFactory
final GuiFactory guiFactory
The global GuiFactory instance.
Definition: AccountCreateCharacterCommand.java:61
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Abstract base class for GUI elements to be shown in Guis.
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.character.Choice.getChoiceName
String getChoiceName()
Returns the choice identification.
Definition: Choice.java:71
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.element
final AbstractGUIElement element
The AbstractGUIElement to find the Gui containing the fields.
Definition: AccountCreateCharacterCommand.java:55
com.realtime.crossfire.jxclient.gui.textinput
Definition: ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getOptionIndex
int getOptionIndex()
Return the selected character option.
Definition: NewCharModel.java:446
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback.accountCreateCharacter
void accountCreateCharacter(@NotNull String login, @NotNull Collection< String > attributes)
Creates a character.
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getClass_
String getClass_()
Returns the selected class.
Definition: NewCharModel.java:267
com.realtime.crossfire.jxclient.character.Choice
A choice for character creation.
Definition: Choice.java:34
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.execute
void execute()
Executes the command.
Definition: AccountCreateCharacterCommand.java:90
com.realtime.crossfire.jxclient.gui.label.NewCharModel
General information for creating new characters.
Definition: NewCharModel.java:43
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.commandCallback
final CommandCallback commandCallback
The CommandCallback to use.
Definition: AccountCreateCharacterCommand.java:49
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.AccountCreateCharacterCommand
AccountCreateCharacterCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory, @NotNull final NewCharModel newCharModel)
Creates a new instance.
Definition: AccountCreateCharacterCommand.java:77
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.canExecute
boolean canExecute()
Returns whether this command may be executed.
Definition: AccountCreateCharacterCommand.java:85
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Interface that defines callback functions needed by commands.
Definition: CommandCallback.java:33
com.realtime
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getRace
String getRace()
Returns the selected race.
Definition: NewCharModel.java:235
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getOption
Choice getOption()
Returns the character options.
Definition: NewCharModel.java:438
com
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand
A GUICommand sending a character creation request.
Definition: AccountCreateCharacterCommand.java:43
com.realtime.crossfire.jxclient.gui.gui.Gui.getFirstElement
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_)
Returns the first gui element of this gui belonging to the given class.
Definition: Gui.java:291
com.realtime.crossfire.jxclient.gui.textinput.GUIText.getText
String getText()
Returns the entered text.
Definition: GUIText.java:234
com.realtime.crossfire.jxclient.character
Definition: Choice.java:23
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getStartingMap
String getStartingMap()
Returns the selected starting map.
Definition: NewCharModel.java:299
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setActive
void setActive(final boolean active)
Sets the active state of a GUI element.
Definition: ActivatableGUIElement.java:115
com.realtime.crossfire.jxclient.character.Choice.getChoices
Map< String, String > getChoices()
Returns the choices.
Definition: Choice.java:89
com.realtime.crossfire.jxclient.gui.label.NewcharStat
A stat value.
Definition: NewcharStat.java:32