Esempio n. 1
0
void Character::changeCharacter()
{
	characterColour = Color3B(UTIL::randomNumber(0.0f, 256.0f), UTIL::randomNumber(0.0f, 256.0f), UTIL::randomNumber(0.0f, 256.0f));
	body->setColor(characterColour);
	armLeg->setColor(characterColour);

	hair->setSpriteFrame("haircut" + UTIL::intToString(hairID.at(currentCharacterID)) + "_0.png");
	mouth->setSpriteFrame("mouth" + UTIL::intToString(mouthID.at(currentCharacterID)) + "_open.png");
	body->setSpriteFrame("body" + UTIL::intToString(bodyID.at(currentCharacterID))  + ".png");
	eyes->setSpriteFrame("eyes" + UTIL::intToString(eyeID.at(currentCharacterID))  + ".png");

	updateHair();
}
Esempio n. 2
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
                                   const int slot) :
    // TRANSLATORS: char create dialog name
    Window(_("New Character"), Modal_true, parent, "charcreate.xml"),
    ActionListener(),
    KeyListener(),
    mCharSelectDialog(parent),
    mNameField(new TextField(this, "")),
    // TRANSLATORS: char create dialog label
    mNameLabel(new Label(this, _("Name:"))),
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mNextHairColorButton(new Button(this, _(">"), "nextcolor", this)),
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mPrevHairColorButton(new Button(this, _("<"), "prevcolor", this)),
    // TRANSLATORS: char create dialog label
    mHairColorLabel(new Label(this, _("Hair color:"))),
    mHairColorNameLabel(new Label(this, "")),
    // TRANSLATORS: char create dialog button
    mNextHairStyleButton(new Button(this, _(">"), "nextstyle", this)),
    // TRANSLATORS: char create dialog button
    mPrevHairStyleButton(new Button(this, _("<"), "prevstyle", this)),
    // TRANSLATORS: char create dialog label
    mHairStyleLabel(new Label(this, _("Hair style:"))),
    mHairStyleNameLabel(new Label(this, "")),
    mNextRaceButton(nullptr),
    mPrevRaceButton(nullptr),
    mRaceLabel(nullptr),
    mRaceNameLabel(nullptr),
    mNextLookButton(nullptr),
    mPrevLookButton(nullptr),
    mLookLabel(nullptr),
    mLookNameLabel(nullptr),
    // TRANSLATORS: char create dialog button
    mActionButton(new Button(this, _("^"), "action", this)),
    // TRANSLATORS: char create dialog button
    mRotateButton(new Button(this, _(">"), "rotate", this)),
    mAttributeSlider(),
    mAttributeLabel(),
    mAttributeValue(),
    mAttributesLeft(new Label(this,
        // TRANSLATORS: char create dialog label
        strprintf(_("Please distribute %d points"), 99))),
    // TRANSLATORS: char create dialog button
    mCreateButton(new Button(this, _("Create"), "create", this)),
    // TRANSLATORS: char create dialog button
    mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
    mPlayer(new Being(BeingId_zero,
            ActorType::Player,
            BeingTypeId_zero,
            nullptr)),
    mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
        "charcreate_selectedplayerbox.xml")),
    mGenderStrip(nullptr),
    mMaxPoints(0),
    mUsedPoints(0),
    mRace(CharDB::getMinRace()),
    mLook(0),
    mMinLook(CharDB::getMinLook()),
    mMaxLook(CharDB::getMaxLook()),
    mMinRace(CharDB::getMinRace()),
    mMaxRace(CharDB::getMaxRace()),
    mHairStyle(0),
    mHairColor(0),
    mSlot(slot),
    mDefaultGender(Gender::FEMALE),
    mGender(Gender::UNSPECIFIED),
    maxHairColor(CharDB::getMaxHairColor()),
    minHairColor(CharDB::getMinHairColor()),
    maxHairStyle(CharDB::getMaxHairStyle()),
    minHairStyle(CharDB::getMinHairStyle()),
    mAction(0),
    mDirection(0)
{
    setStickyButtonLock(true);
    setSticky(true);
    setWindowName("NewCharacter");

    const int w = 480;
    const int h = 350;
    setContentSize(w, h);

    mPlayer->setGender(Gender::MALE);
    const std::vector<int> &items = CharDB::getDefaultItems();
    int i = 1;
    for (std::vector<int>::const_iterator it = items.begin(),
         it_end = items.end();
         it != it_end; ++ it, i ++)
    {
        mPlayer->setSprite(i, *it);
    }

    if (!maxHairColor)
        maxHairColor = ColorDB::getHairSize();
    if (!maxHairStyle)
        maxHairStyle = mPlayer->getNumOfHairstyles();

    if (maxHairStyle)
    {
        mHairStyle = (static_cast<unsigned int>(rand())
            % maxHairStyle) + minHairStyle;
    }
    else
    {
        mHairStyle = 0;
    }
    if (maxHairColor)
    {
        mHairColor = (static_cast<unsigned int>(rand())
            % maxHairColor) + minHairColor;
    }
    else
    {
        mHairColor = 0;
    }

    mNameField->setMaximum(24);

    if (serverFeatures->haveRaceSelection())
    {
        // TRANSLATORS: char create dialog button
        mNextRaceButton = new Button(this, _(">"), "nextrace", this);
        // TRANSLATORS: char create dialog button
        mPrevRaceButton = new Button(this, _("<"), "prevrace", this);
        // TRANSLATORS: char create dialog label
        mRaceLabel = new Label(this, _("Race:"));
        mRaceNameLabel = new Label(this, "");
    }
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        // TRANSLATORS: char create dialog button
        mNextLookButton = new Button(this, _(">"), "nextlook", this);
        // TRANSLATORS: char create dialog button
        mPrevLookButton = new Button(this, _("<"), "prevlook", this);
        // TRANSLATORS: char create dialog label
        mLookLabel = new Label(this, _("Look:"));
        mLookNameLabel = new Label(this, "");
    }

    if (serverFeatures->haveCreateCharGender())
    {
        const int size = config.getIntValue("fontSize");
        mGenderStrip = new TabStrip(this,
            "gender_" + getWindowName(),
            size + 16);
        mGenderStrip->setPressFirst(false);
        mGenderStrip->addActionListener(this);
        mGenderStrip->setActionEventId("gender_");
        // TRANSLATORS: one char size female character gender
        mGenderStrip->addButton(_("F"), "f", false);
        // TRANSLATORS: one char size male character gender
        mGenderStrip->addButton(_("M"), "m", false);
        // TRANSLATORS: one char size unknown character gender
        mGenderStrip->addButton(_("U"), "u", true);
        mGenderStrip->setVisible(Visible_true);
        add(mGenderStrip);

        mGenderStrip->setPosition(385, 130);
        mGenderStrip->setWidth(500);
        mGenderStrip->setHeight(50);
    }

    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mPlayerBox->setDimension(Rect(360, 0, 110, 90));
    mActionButton->setPosition(385, 100);
    mRotateButton->setPosition(415, 100);

    mNameLabel->setPosition(5, 2);
    mNameField->setDimension(
            Rect(60, 2, 300, mNameField->getHeight()));

    const int leftX = 120;
    const int rightX = 300;
    const int labelX = 5;
    const int nameX = 145;
    int y = 30;

    mPrevHairColorButton->setPosition(leftX, y);
    mNextHairColorButton->setPosition(rightX, y);
    y += 5;
    mHairColorLabel->setPosition(labelX, y);
    mHairColorNameLabel->setPosition(nameX, y);
    y += 24;
    mPrevHairStyleButton->setPosition(leftX, y);
    mNextHairStyleButton->setPosition(rightX, y);
    y += 5;
    mHairStyleLabel->setPosition(labelX, y);
    mHairStyleNameLabel->setPosition(nameX, y);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        y += 24;
        if (mPrevLookButton)
            mPrevLookButton->setPosition(leftX, y);
        if (mNextLookButton)
            mNextLookButton->setPosition(rightX, y);
        y += 5;
        if (mLookLabel)
            mLookLabel->setPosition(labelX, y);
        if (mLookNameLabel)
            mLookNameLabel->setPosition(nameX, y);  // 93
    }
    if (serverFeatures->haveRaceSelection())
    {
        y += 24;
        if (mPrevRaceButton)
            mPrevRaceButton->setPosition(leftX, y);
        if (mNextRaceButton)
            mNextRaceButton->setPosition(rightX, y);
        y += 5;
        if (mRaceLabel)
            mRaceLabel->setPosition(labelX, y);
        if (mRaceNameLabel)
            mRaceNameLabel->setPosition(nameX, y);
    }

    updateSliders();
    setButtonsPosition(w, h);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mHairColorNameLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mHairStyleNameLabel);
    add(mActionButton);
    add(mRotateButton);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        add(mNextLookButton);
        add(mPrevLookButton);
        add(mLookLabel);
        add(mLookNameLabel);
    }

    if (serverFeatures->haveRaceSelection())
    {
        add(mNextRaceButton);
        add(mPrevRaceButton);
        add(mRaceLabel);
        add(mRaceNameLabel);
    }

    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    center();
    setVisible(Visible_true);
    mNameField->requestFocus();

    updateHair();
    if (serverFeatures->haveRaceSelection())
        updateRace();
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
        updateLook();
    updatePlayer();

    addKeyListener(this);
}
Esempio n. 3
0
void Character::createCharacter(cocos2d::Layer *layerToSpawn, FoodSpawner &foodSpawner)
{
    SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    characterBatch = SpriteBatchNode::create("Atlases/characters.png");
    cache->addSpriteFramesWithFile("Atlases/characters.plist");

    bodyID.push_back(3);
	hairID.push_back(2);
	eyeID.push_back(1);
	mouthID.push_back(0);

    currentCharacterID = 0;

    //BodyID
	std::ostringstream bodyIDStr;
	bodyIDStr << bodyID.at(currentCharacterID);

    //EyeID
	std::ostringstream eyeIDStr;
	eyeIDStr << eyeID.at(currentCharacterID);

	 //HairID
	std::ostringstream hairIDStr;
	hairIDStr << hairID.at(currentCharacterID);

	 //MouthID
	std::ostringstream mouthIDStr;
	mouthIDStr << mouthID.at(currentCharacterID);

	body = Sprite::createWithSpriteFrameName("body" + bodyIDStr.str() + ".png");
	body->setPosition(Vec2(0, 0));
	characterBatch->addChild(body, 10);

	eyes = Sprite::createWithSpriteFrameName("eyes" + eyeIDStr.str() + ".png");
	eyes->setPosition(Vec2(0, 64));
	characterBatch->addChild(eyes, 11);

	hair = Sprite::createWithSpriteFrameName("haircut" + hairIDStr.str() + "_0.png");
	hair->setPosition(Vec2(0, 96));
	hair->setScale(1.06f);
	characterBatch->addChild(hair, 14);

	mouth = Sprite::createWithSpriteFrameName("mouth" + mouthIDStr.str() + "_open.png");
	mouth->setPosition(Vec2(0, 54));
	characterBatch->addChild(mouth, 13);

	armLeg = Sprite::createWithSpriteFrameName("armLegDown.png");
	armLeg->setPosition(Vec2(0, 0));
	characterBatch->addChild(armLeg, 11);

	Size visibleSize = Director::getInstance()->getVisibleSize();
	characterBatch->setPosition(visibleSize.width/2, (body->getSpriteFrame()->getOriginalSizeInPixels().height / 4));
	characterBatch->setScale(2);

    layerToSpawn->addChild(characterBatch);

    isBouncingUp = false;
    currentTime = 0;
    characterStates = CharacterStates::IDLE;

    updateHair();

	//Lerp length for jumping/idling
	idleLenght = 0.4f;
	flyLength = 0.35f;

	//Idle points that it lerps between
	idle0Pos = Vec2(visibleSize.width/2, 0);
	idle1Pos = Vec2(visibleSize.width/2, -64);

	//Set eatpoint
	eatPoint = Vec2(visibleSize.width/2, visibleSize.height - (foodSpawner.offsetFromCenter/2));
}
Esempio n. 4
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
    Window(_("Create Character"), true, parent),
    mCharSelectDialog(parent),
    mSlot(slot)
{
    mPlayer = new Being(0, ActorSprite::PLAYER, 0, NULL);
    mPlayer->setGender(GENDER_MALE);

    mHairStylesIds = hairDB.getHairStyleIds(
        Net::getCharHandler()->getCharCreateMaxHairStyleId());
    mHairStyleId = rand() * mHairStylesIds.size() / RAND_MAX;

    mHairColorsIds = hairDB.getHairColorIds(
        Net::getCharHandler()->getCharCreateMaxHairColorId());
    mHairColorId = rand() * mHairColorsIds.size() / RAND_MAX;

    updateHair();

    mNameField = new TextField("");
    mNameLabel = new Label(_("Name:"));

    mNextHairColorButton = new Button("", "nextcolor", this);
    mPrevHairColorButton = new Button("", "prevcolor", this);
    mPrevHairColorButton->setButtonIcon("tab_arrows_left.png");
    mNextHairColorButton->setButtonIcon("tab_arrows_right.png");

    mHairColorLabel = new Label(_("Hair color:"));
    mNextHairStyleButton = new Button("", "nextstyle", this);
    mPrevHairStyleButton = new Button("", "prevstyle", this);
    mPrevHairStyleButton->setButtonIcon("tab_arrows_left.png");
    mNextHairStyleButton->setButtonIcon("tab_arrows_right.png");

    mHairStyleLabel = new Label(_("Hair style:"));
    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);
    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(
            strprintf(_("Please distribute %d points"), 99));

    int w = 200;
    int h = 330;
    setContentSize(w, h);
    mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
    mNameLabel->setPosition(5, 5);
    mNameField->setDimension(
            gcn::Rectangle(45, 5, w - 45 - 7, mNameField->getHeight()));
    mPrevHairColorButton->setPosition(90, 35);
    mNextHairColorButton->setPosition(165, 35);
    mHairColorLabel->setPosition(5, 40);
    mPrevHairStyleButton->setPosition(90, 64);
    mNextHairStyleButton->setPosition(165, 64);
    mHairStyleLabel->setPosition(5, 70);
    mAttributesLeft->setPosition(15, 280);
    updateSliders();
    mCancelButton->setPosition(
            w - 5 - mCancelButton->getWidth(),
            h - 5 - mCancelButton->getHeight());
    mCreateButton->setPosition(
            mCancelButton->getX() - 5 - mCreateButton->getWidth(),
            h - 5 - mCancelButton->getHeight());

    mMale->setPosition(30, 120);
    mFemale->setPosition(100, 120);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    add(mMale);
    add(mFemale);

    center();
    setVisible(true);
    mNameField->requestFocus();
}
Esempio n. 5
0
void CharCreateDialog::action(const ActionEvent &event)
{
    const std::string &id = event.getId();
    if (id == "create")
    {
        if (getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
            for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
            {
                atts.push_back(static_cast<int>(
                    mAttributeSlider[i]->getValue()));
            }

            const int characterSlot = mSlot;

            charServerHandler->newCharacter(getName(),
                characterSlot,
                mGender,
                mHairStyle,
                mHairColor,
                static_cast<unsigned char>(mRace),
                static_cast<unsigned char>(mLook),
                atts);
        }
        else
        {
            CREATEWIDGET(OkDialog,
                // TRANSLATORS: char creation error
                _("Error"),
                // TRANSLATORS: char creation error
                _("Your name needs to be at least 4 characters."),
                // TRANSLATORS: ok dialog button
                _("OK"),
                DialogType::ERROR,
                Modal_true,
                ShowCenter_true,
                nullptr,
                260);
        }
    }
    else if (id == "cancel")
    {
        scheduleDelete();
    }
    else if (id == "nextcolor")
    {
        mHairColor ++;
        updateHair();
    }
    else if (id == "prevcolor")
    {
        mHairColor --;
        updateHair();
    }
    else if (id == "nextstyle")
    {
        mHairStyle ++;
        updateHair();
    }
    else if (id == "prevstyle")
    {
        mHairStyle --;
        updateHair();
    }
    else if (id == "nextrace")
    {
        mRace ++;
        updateRace();
    }
    else if (id == "prevrace")
    {
        mRace --;
        updateRace();
    }
    else if (id == "nextlook")
    {
        mLook ++;
        updateLook();
    }
    else if (id == "prevlook")
    {
        mLook --;
        updateLook();
    }
    else if (id == "statslider")
    {
        updateSliders();
    }
    else if (id == "action")
    {
        mAction ++;
        if (mAction >= 5)
            mAction = 0;
        updatePlayer();
    }
    else if (id == "rotate")
    {
        mDirection ++;
        if (mDirection >= 4)
            mDirection = 0;
        updatePlayer();
    }
    else if (id == "gender_m")
    {
        mGender = Gender::MALE;
        mPlayer->setGender(Gender::MALE);
    }
    else if (id == "gender_f")
    {
        mGender = Gender::FEMALE;
        mPlayer->setGender(Gender::FEMALE);
    }
    else if (id == "gender_u")
    {
        mGender = Gender::UNSPECIFIED;
        mPlayer->setGender(mDefaultGender);
    }
}
Esempio n. 6
0
void CharCreateDialog::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "create")
    {
        if (Net::getNetworkType() == ServerInfo::MANASERV
            || getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
            for (unsigned i = 0; i < mAttributeSlider.size(); i++)
            {
                atts.push_back((int) mAttributeSlider[i]->getValue());
            }

            int characterSlot = mSlot;
            // On Manaserv, the slots start at 1, so we offset them.
            if (Net::getNetworkType() == ServerInfo::MANASERV)
                ++characterSlot;

            // Should avoid the most common crash case
            int hairStyle = mHairStylesIds.empty() ?
                0 : mHairStylesIds.at(mHairStyleId);
            int hairColor = mHairColorsIds.empty() ?
                0 : mHairColorsIds.at(mHairColorId);
            Net::getCharHandler()->newCharacter(getName(), characterSlot,
                                                mFemale->isSelected(),
                                                hairStyle, hairColor, atts);
        }
        else
        {
            new OkDialog(_("Error"),
                         _("Your name needs to be at least 4 characters."),
                         true,  this);
        }
    }
    else if (event.getId() == "cancel")
        scheduleDelete();
    else if (event.getId() == "nextcolor")
    {
        ++mHairColorId;
        updateHair();
    }
    else if (event.getId() == "prevcolor")
    {
        --mHairColorId;
        updateHair();
    }
    else if (event.getId() == "nextstyle")
    {
        ++mHairStyleId;
        updateHair();
    }
    else if (event.getId() == "prevstyle")
    {
        --mHairStyleId;
        updateHair();
    }
    else if (event.getId() == "statslider")
    {
        updateSliders();
    }
    else if (event.getId() == "gender")
    {
        if (mMale->isSelected())
            mPlayer->setGender(GENDER_MALE);
        else
            mPlayer->setGender(GENDER_FEMALE);
    }
}
Esempio n. 7
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
    Window(_("New Character"), true, parent, "charcreate.xml"),
    mCharSelectDialog(parent),
    mRace(0),
    mSlot(slot),
    mAction(0),
    mDirection(0)
{
    setStickyButtonLock(true);
    setSticky(true);
    setWindowName("NewCharacter");

    mPlayer = new Being(0, ActorSprite::PLAYER, mRace, nullptr);
    mPlayer->setGender(GENDER_MALE);

    maxHairColor = CharDB::getMaxHairColor();
    minHairColor = CharDB::getMinHairColor();
    if (!maxHairColor)
        maxHairColor = ColorDB::getHairSize();

    maxHairStyle = CharDB::getMaxHairStyle();
    minHairStyle = CharDB::getMinHairStyle();
    if (!maxHairStyle)
        maxHairStyle = mPlayer->getNumOfHairstyles();

    mHairStyle = (rand() % maxHairStyle) + minHairStyle;
    mHairColor = (rand() % maxHairColor) + minHairColor;

    mNameField = new TextField("");
    mNameField->setMaximum(24);
    mNameLabel = new Label(_("Name:"));
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    mNextHairColorButton = new Button(_(">"), "nextcolor", this);
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    mPrevHairColorButton = new Button(_("<"), "prevcolor", this);
    mHairColorLabel = new Label(_("Hair color:"));
    mHairColorNameLabel = new Label("");
    mNextHairStyleButton = new Button(_(">"), "nextstyle", this);
    mPrevHairStyleButton = new Button(_("<"), "prevstyle", this);
    mHairStyleLabel = new Label(_("Hair style:"));
    mHairStyleNameLabel = new Label("");
    mActionButton = new Button(_("^"), "action", this);
    mRotateButton = new Button(_(">"), "rotate", this);

    if (serverVersion >= 2)
    {
        mNextRaceButton = new Button(_(">"), "nextrace", this);
        mPrevRaceButton = new Button(_("<"), "prevrace", this);
        mRaceLabel = new Label(_("Race:"));
        mRaceNameLabel = new Label("");
    }

    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");
    mOther = new RadioButton(_("Other"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");
    mOther->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);
    mOther->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);
    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(
            strprintf(_("Please distribute %d points"), 99));

    int w = 480;
    int h = 350;
    setContentSize(w, h);
    mPlayerBox->setDimension(gcn::Rectangle(350, 40, 110, 90));
    mActionButton->setPosition(375, 140);
    mRotateButton->setPosition(405, 140);

    mNameLabel->setPosition(5, 10);
    mNameField->setDimension(
            gcn::Rectangle(60, 10, 300, mNameField->getHeight()));

    int leftX = 120;
    int rightX = 300;
    int labelX = 5;
    int nameX = 145;
    mPrevHairColorButton->setPosition(leftX, 40);
    mNextHairColorButton->setPosition(rightX, 40);
    mHairColorLabel->setPosition(labelX, 45);
    mHairColorNameLabel->setPosition(nameX, 45);
    mPrevHairStyleButton->setPosition(leftX, 69);
    mNextHairStyleButton->setPosition(rightX, 69);
    mHairStyleLabel->setPosition(labelX, 74);
    mHairStyleNameLabel->setPosition(nameX, 74);

    if (serverVersion >= 2)
    {
        mPrevRaceButton->setPosition(leftX, 103);
        mNextRaceButton->setPosition(rightX, 103);
        mRaceLabel->setPosition(labelX, 108);
        mRaceNameLabel->setPosition(nameX, 108);
    }

    mAttributesLeft->setPosition(15, 280);
    updateSliders();
    mCancelButton->setPosition(
            w / 2,
            h - 5 - mCancelButton->getHeight());
    mCreateButton->setPosition(
            mCancelButton->getX() - 5 - mCreateButton->getWidth(),
            h - 5 - mCancelButton->getHeight());

    mMale->setPosition(30, 120);
    mFemale->setPosition(100, 120);
    mOther->setPosition(170, 120);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mHairColorNameLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mHairStyleNameLabel);
    add(mActionButton);
    add(mRotateButton);

    if (serverVersion >= 2)
    {
        add(mNextRaceButton);
        add(mPrevRaceButton);
        add(mRaceLabel);
        add(mRaceNameLabel);
    }

    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    add(mMale);
    add(mFemale);
    add(mOther);

    center();
    setVisible(true);
    mNameField->requestFocus();

    updateHair();
    if (serverVersion >= 2)
        updateRace();

    updatePlayer();

    addKeyListener(this);
}
Esempio n. 8
0
void CharCreateDialog::action(const gcn::ActionEvent &event)
{
    const std::string id = event.getId();
    if (id == "create")
    {
        if (
#ifdef MANASERV_SUPPORT
            Net::getNetworkType() == ServerInfo::MANASERV ||
#endif
            getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
            for (unsigned i = 0; i < mAttributeSlider.size(); i++)
            {
                atts.push_back(static_cast<int>(
                    mAttributeSlider[i]->getValue()));
            }

            int characterSlot = mSlot;
#ifdef MANASERV_SUPPORT
            // On Manaserv, the slots start at 1, so we offset them.
            if (Net::getNetworkType() == ServerInfo::MANASERV)
                ++characterSlot;
#endif

            Net::getCharHandler()->newCharacter(getName(), characterSlot,
                mFemale->isSelected(), mHairStyle, mHairColor, mRace, atts);
        }
        else
        {
            new OkDialog(_("Error"),
                _("Your name needs to be at least 4 characters."),
                DIALOG_ERROR, true,  this);
        }
    }
    else if (id == "cancel")
    {
        scheduleDelete();
    }
    else if (id == "nextcolor")
    {
        mHairColor ++;
        updateHair();
    }
    else if (id == "prevcolor")
    {
        mHairColor --;
        updateHair();
    }
    else if (id == "nextstyle")
    {
        mHairStyle ++;
        updateHair();
    }
    else if (id == "prevstyle")
    {
        mHairStyle --;
        updateHair();
    }
    else if (id == "nextrace")
    {
        mRace ++;
        updateRace();
    }
    else if (id == "prevrace")
    {
        mRace --;
        updateRace();
    }
    else if (id == "statslider")
    {
        updateSliders();
    }
    else if (id == "gender")
    {
        if (mMale->isSelected())
            mPlayer->setGender(GENDER_MALE);
        else
            mPlayer->setGender(GENDER_FEMALE);
    }
    else if (id == "action")
    {
        mAction ++;
        if (mAction >= 5)
            mAction = 0;
        updatePlayer();
    }
    else if (id == "rotate")
    {
        mDirection ++;
        if (mDirection >= 4)
            mDirection = 0;
        updatePlayer();
    }
}
CharCreateDialog::CharCreateDialog(Window *parent, int slot):
    Window(_("Create Character"), true, parent),
    mSlot(slot)
{
    mPlayer = new Player(0, 0, NULL);
    mPlayer->setGender(GENDER_MALE);

    ResourceManager *resman = ResourceManager::getInstance();
    mBackGround = resman->getImage("graphics/elektrik/gui_login_window.png");

    gcn::Label *girisLabel = new gcn::Label(_("-=KARAKTER OLUŞTUR=-"));
    girisLabel->setPosition(150,140);
    girisLabel->setFont(font_bas_b_1_16);
    girisLabel->setForegroundColor(gcn::Color(0xaa,0xbb,0xcc));
    girisLabel->adjustSize();
    add(girisLabel);

    int numberOfHairColors = ColorDB::size();

    srand((unsigned)time(0));
    mHairStyle = rand() % mPlayer->getNumOfHairstyles();
    mHairColor = rand() % numberOfHairColors;
    updateHair();

    mNameField = new TextField("");
    mNameLabel = new Label(_("Name:"));
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    mNextHairColorButton = new Button(_(">"), "nextcolor", this);
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    mPrevHairColorButton = new Button(_("<"), "prevcolor", this);
    mHairColorLabel = new Label(_("Hair color:"));
    mNextHairStyleButton = new Button(_(">"), "nextstyle", this);
    mPrevHairStyleButton = new Button(_("<"), "prevstyle", this);
    mHairStyleLabel = new Label(_("Hair style:"));
    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);

    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(strprintf(_("Please distribute %d points"), 99));

    int w = 200;
    int h = 330;


    ContainerPlacer place;
    place = getPlacer(5,15);
    place(0,0,mNameLabel);
    place(1,0,mNameField,2);
    place = getPlacer(5,16);
    place(0,0,mHairColorLabel);
    place(1,0,mPrevHairColorButton);
    place(2,0,mPlayerBox,1,10).setPadding(3);
    place(3,0,mNextHairColorButton);
    place(0,1,mHairStyleLabel);
    place(1,1,mPrevHairStyleButton);
    place(3,1,mNextHairStyleButton);
    reflowLayout(350,335);

    mCreateButton->setPosition(200,345);
    mCancelButton->setPosition(260,345);
    mCancelButton->setWidth(mCreateButton->getWidth());

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mCreateButton);
    add(mCancelButton);
//    add(mAttributesLeft);
//    add(mMale);
//    add(mFemale);

    setSize(573,507);
    center();
    setVisible(true);
    mNameField->requestFocus();
}
Esempio n. 10
0
void CharCreateDialog::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "create")
    {
        if (getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
//            for (unsigned i = 0; i < mAttributeSlider.size(); i++)
//            {
//                atts.push_back((int) mAttributeSlider[i]->getValue());
//            }
            atts.push_back(9);
            atts.push_back(9);
            atts.push_back(9);
            atts.push_back(1);
            atts.push_back(1);
            atts.push_back(1);
            Net::getCharHandler()->newCharacter(getName(), mSlot,
                                                mFemale->isSelected(), mHairStyle,
                                                mHairColor, atts);
        }
        else
        {
            new OkDialog(_("Error"),
                         _("Your name needs to be at least 4 characters."),
                         this);
        }
    }
    else if (event.getId() == "cancel")
        scheduleDelete();
    else if (event.getId() == "nextcolor")
    {
        mHairColor++;
        updateHair();
    }
    else if (event.getId() == "prevcolor")
    {
        mHairColor--;
        updateHair();
    }
    else if (event.getId() == "nextstyle")
    {
        mHairStyle++;
        updateHair();
    }
    else if (event.getId() == "prevstyle")
    {
        mHairStyle--;
        updateHair();
    }
    else if (event.getId() == "statslider") {
        updateSliders();
    }
    else if (event.getId() == "gender") {
        if (mMale->isSelected()) {
            mPlayer->setGender(GENDER_MALE);
        } else {
            mPlayer->setGender(GENDER_FEMALE);
        }
    }
}