45#include <guichan/font.hpp>
48 Window(
_(
"Create Character"), true, parent),
49 mCharSelectDialog(parent),
56 for (
size_t i = 0; i < items.size(); ++i)
79 mMale->setSelected(
true);
81 mMale->setActionEventId(
"gender");
82 mFemale->setActionEventId(
"gender");
84 mMale->addActionListener(
this);
85 mFemale->addActionListener(
this);
94 strprintf(
_(
"Please distribute %d points"), 99));
99 mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
102 gcn::Rectangle(45, 5, w - 45 - 7,
mNameField->getHeight()));
112 mMale->setPosition(30, 120);
113 mFemale->setPosition(100, 120);
121 auto hairColorLabel =
new Label(
_(
"Hair color:"));
122 auto nextHairColorButton =
new Button(
"",
"nextcolor",
this);
123 auto prevHairColorButton =
new Button(
"",
"prevcolor",
this);
124 prevHairColorButton->setButtonIcon(
"tab_arrows_left.png");
125 nextHairColorButton->setButtonIcon(
"tab_arrows_right.png");
127 hairColorLabel->setPosition(5, 40);
128 prevHairColorButton->setPosition(90, 35);
129 nextHairColorButton->setPosition(165, 35);
131 add(nextHairColorButton);
132 add(prevHairColorButton);
138 auto hairStyleLabel =
new Label(
_(
"Hair style:"));
139 auto nextHairStyleButton =
new Button(
"",
"nextstyle",
this);
140 auto prevHairStyleButton =
new Button(
"",
"prevstyle",
this);
141 prevHairStyleButton->setButtonIcon(
"tab_arrows_left.png");
142 nextHairStyleButton->setButtonIcon(
"tab_arrows_right.png");
144 hairStyleLabel->setPosition(5, 70);
145 prevHairStyleButton->setPosition(90, 64);
146 nextHairStyleButton->setPosition(165, 64);
148 add(nextHairStyleButton);
149 add(prevHairStyleButton);
176 if (event.getId() ==
"create")
184 int characterSlot =
mSlot;
198 hairStyle, hairColor,
204 _(
"Your name needs to be at least 4 characters."),
208 else if (event.getId() ==
"cancel")
212 else if (event.getId() ==
"nextcolor")
217 else if (event.getId() ==
"prevcolor")
222 else if (event.getId() ==
"nextstyle")
227 else if (event.getId() ==
"prevstyle")
232 else if (event.getId() ==
"statslider")
236 else if (event.getId() ==
"gender")
238 if (
mMale->isSelected())
254 int distributedPoints = 0;
261 int value =
static_cast<int>(slider->getValue());
263 valueLabel->setCaption(
toString(value));
264 valueLabel->adjustSize();
267 distributedPoints += value;
271 int pointsLeft =
mMaxPoints - distributedPoints;
283 strprintf(
_(
"Please distribute %d points"), pointsLeft));
288 strprintf(
_(
"Please remove %d points"), -pointsLeft));
301 unsigned available,
unsigned min,
333 h += 20 * labels.size() + 20;
339 for (
unsigned i = 0; i < labels.size(); i++)
341 const int y = 140 + i * 20;
343 auto *attributeLabel =
new Label(labels[i]);
344 attributeLabel->setWidth(70);
345 attributeLabel->setPosition(5, y);
348 auto *attributeSlider =
new Slider(min, max);
349 attributeSlider->setDimension(gcn::Rectangle(75, y, 100, attributeSlider->getHeight()));
350 attributeSlider->setActionEventId(
"statslider");
351 attributeSlider->addActionListener(
this);
352 add(attributeSlider);
355 attributeValue->setPosition(180, y);
384 mMale->setSelected(
false);
388 mMale->setSelected(
true);
void setSprite(unsigned slot, int id, const std::string &color=std::string(), bool isWeapon=false)
Sets visible equipments for this being.
void setGender(Gender gender)
Sets the gender of this being.
void setAttributes(const std::vector< std::string > &labels, unsigned available, unsigned min, unsigned max)
std::vector< int > mAttributes
~CharCreateDialog() override
gcn::RadioButton * mFemale
CharCreateDialog(CharSelectDialog *parent, int slot)
gcn::Label * mAttributesLeft
std::vector< gcn::Label * > mAttributeLabel
gcn::TextField * mNameField
std::vector< gcn::Label * > mAttributeValue
std::vector< gcn::Slider * > mAttributeSlider
gcn::Button * mCancelButton
std::string getName() const
Returns the name of the character to create.
void setDefaultGender(Gender gender)
gcn::Button * mCreateButton
std::vector< int > mHairColorsIds
std::vector< int > mHairStylesIds
void unlock()
Unlocks the dialog, enabling the create character button again.
void action(const gcn::ActionEvent &event) override
Character selection dialog.
std::vector< int > getHairStyleIds(int maxId) const
Returns the available hair style ids.
const std::string & getHairColor(int id) const
std::vector< int > getHairColorIds(int minId, int maxId) const
Returns the available hair color ids.
virtual void newCharacter(const std::string &name, int slot, Gender gender, int hairstyle, int hairColor, const std::vector< int > &stats)=0
virtual void setCharCreateDialog(CharCreateDialog *window)=0
A box showing a player character.
void center()
Positions the window in the center of it's parent.
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
void setContentSize(int width, int height)
Sets the size of this window.
void scheduleDelete()
Schedule this window for deletion.
HairDB hairDB
Hair styles and colors info database.
Net::CharHandler * charHandler
const std::vector< int > & getDefaultItems()
ServerType getNetworkType()
CharHandler * getCharHandler()
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
std::string & trim(std::string &str)
Trims spaces off the end and the beginning of the given string.
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.