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.label.NewCharModel.getClass_
String getClass_()
Definition: NewCharModel.java:267
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.canExecute
boolean canExecute()
Definition: AccountCreateCharacterCommand.java:85
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.label.NewcharStat
Definition: NewcharStat.java:32
com.realtime.crossfire.jxclient.gui.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.commandCallback
final CommandCallback commandCallback
Definition: AccountCreateCharacterCommand.java:49
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.character.Choice
Definition: Choice.java:34
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand
Definition: AccountCreateCharacterCommand.java:43
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
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)
Definition: AccountCreateCharacterCommand.java:77
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.textinput
Definition: ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getStartingMap
String getStartingMap()
Definition: NewCharModel.java:299
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Definition: CommandCallback.java:33
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getValue
int getValue(@NotNull final NewcharStat stat)
Definition: NewCharModel.java:353
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.newCharModel
final NewCharModel newCharModel
Definition: AccountCreateCharacterCommand.java:67
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.textinput.GUIText.getText
String getText()
Definition: GUIText.java:234
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.guiFactory
final GuiFactory guiFactory
Definition: AccountCreateCharacterCommand.java:61
com.realtime.crossfire.jxclient.gui.gui.Gui.getFirstElement
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_)
Definition: Gui.java:300
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getRace
String getRace()
Definition: NewCharModel.java:235
com.realtime.crossfire.jxclient.gui.label.NewCharModel
Definition: NewCharModel.java:43
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.textinput.GUIText
Definition: GUIText.java:61
com.realtime
com
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setActive
void setActive(final boolean active)
Definition: ActivatableGUIElement.java:115
com.realtime.crossfire.jxclient.character.Choice.getChoices
Map< String, String > getChoices()
Definition: Choice.java:89
com.realtime.crossfire.jxclient.character
Definition: Choice.java:23
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getOptionIndex
int getOptionIndex()
Definition: NewCharModel.java:446
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getOption
Choice getOption()
Definition: NewCharModel.java:438
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.element
final AbstractGUIElement element
Definition: AccountCreateCharacterCommand.java:55
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCharacterCommand.execute
void execute()
Definition: AccountCreateCharacterCommand.java:90
com.realtime.crossfire.jxclient.character.Choice.getChoiceName
String getChoiceName()
Definition: Choice.java:71
com.realtime.crossfire.jxclient.gui.commandlist.GUICommand
Definition: GUICommand.java:29
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback.accountCreateCharacter
void accountCreateCharacter(@NotNull String login, @NotNull Collection< String > attributes)