void CharCreateDialog::updateRace()
{
    if (mRace < mMinRace)
        mRace = mMaxRace;
    else if (mRace > mMaxRace)
        mRace = mMinRace;

    updateLook();
}
Example #2
0
//------------------------------------------------------------------------------
//!
void
ValueEditor::format( const char* fmt )
{
   if( _format == fmt ) return;

   _format = fmt;

   updateLook();
}
Example #3
0
PerspectiveCamera::PerspectiveCamera() : Camera()
{
    resetLook();
    _center = Point3(4.0,2.0,4.0);
    _yRot = 225;
    _upRot = 45;
    _distance = _center.length();
    updateLook();
    _center = -lookDir();
    //updateLook();
    //moveType = MoveType::NOT_MOVING;
}
Example #4
0
//------------------------------------------------------------------------------
//!
void
ValueEditor::onChar( const Event& ev )
{
   Widget::onChar( ev );
   if( !_inEdit ) return;

   if( isprint( ev.value() ) )
   {
      char chr = (char)ev.value();
      if( _cursor < _editText.size() )
         _editText.insert( _cursor, chr );
      else
         _editText += chr;
      ++_cursor;

      updateLook();
   }
}
Example #5
0
//------------------------------------------------------------------------------
//!
void
ValueEditor::onKeyPress( const Event& ev )
{
   Widget::onKeyPress( ev );
   if( !_inEdit ) return;

   switch( ev.value() )
   {
      case Key::BACKSPACE:
         if( _cursor > 0 )
         {
            --_cursor;
            _editText.erase( _cursor );
         }
         break;
      case Key::RETURN:
         Core::releaseFocus( this );
         break;
      case Key::ESC:
         _editText.format( _format.cstr(), _value );
         Core::releaseFocus( this );
         break;
      case Key::END:
         _cursor = uint(_editText.size());
         break;
      case Key::HOME:
         _cursor = 0;
         break;
      case Key::LEFT_ARROW:
         if( _cursor > 0 ) --_cursor;
         break;
      case Key::RIGHT_ARROW:
         if( _cursor < _editText.size() ) ++_cursor;
         break;
      case Key::DELETE:
         if( _cursor < _editText.size() ) _editText.erase( _cursor );
         break;
      default:
         return;
   }
   updateLook();
}
Example #6
0
//------------------------------------------------------------------------------
//!
void
ValueEditor::value( float val, bool update )
{
   // Set the value to be in the range.
   val = CGM::clamp( val, _minValue, _maxValue );

   // Convert to integer.
   if( _integer ) val = CGM::round( val );

   if( val == _value ) return;

   _value = val;

   if( update && eventsEnabled() )
   {
      _onModify.exec( _value );
      execute( _onModifyRef, this, _value );
   }

   updateLook();
}
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);
}
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);
    }
}