EditBox * TDDHelper::createEditBox(Node *parent, Point position, Size size) { Scale9Sprite *bg = Scale9Sprite::create(); // empty sprite 9 bg->addChild(LayerColor::create(Color4B::WHITE, size.width, size.height)); // Add the background layer Point layerPos = Point(position); layerPos.x -= size.width / 2; layerPos.y -= size.height / 2; float scale = getBestScale(); // Add the Edit box EditBox *edit = EditBox::create(size, bg); edit->setPosition(position); edit->setFont(TDD_FONT_NAME, (int)(scale * TDD_EDITBOX_FONT_SIZE)); edit->setFontColor(TDD_EDITBOX_TEXT_COLOR); if(parent != NULL) { parent->addChild(edit); } return edit; }
void PersonalityQuiz::createnamecap(){ Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); std::string abc("ENTER YOUR NAME!"); ui::Text* EnterNameText = ui::Text::create(abc, "Arial", 30); EnterNameText->setColor(Color3B::BLACK); EnterNameText->setPosition(Point(visibleSize.width/2 + 150, visibleSize.height/2 - 100)); EnterNameText->setName("ResultDesc"); EnterNameText->setTextAreaSize(Size(600,200)); EnterNameText->setVisible(true); this->addChild(EnterNameText,2); EditBox *EnterName = EditBox::create(Size(350,50), Scale9Sprite::create("New-Game-textbox.png")); EnterName->setPosition(Vec2(visibleSize.width / 2, + visibleSize.height / 2 - 130)); EnterName->setInputMode(cocos2d::extension::EditBox::InputMode::SINGLE_LINE); EnterName->setMaxLength(20); EnterName->setFontColor(Color3B::BLACK); EnterName->setPlaceHolder(" "); EnterName->setReturnType(EditBox::KeyboardReturnType::DONE); EnterName->setName("NameBox"); this->addChild(EnterName,3); }
EditBox* TuiManager::createEditBox(float tag, const char* file, int inputMode, int inputFlag, float x, float y, float w, float h, float rotation){ EditBox *pEditBox = NULL; if(m_isUseSpriteFrame){ pEditBox = EditBox::create(Size(w,h),Scale9Sprite::createWithSpriteFrameName(file)); }else{ pEditBox = EditBox::create(Size(w,h),Scale9Sprite::create(file)); } pEditBox->setInputMode((EditBox::InputMode)inputMode); pEditBox->setInputFlag((EditBox::InputFlag)inputFlag); pEditBox->setRotation(rotation); pEditBox->setPosition(Point(x,-y)); pEditBox->setTag(tag); return pEditBox; }
IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info) { mDynamicToolTipBox->setVisible(true); std::string caption = info.caption; std::string image = info.icon; int imageSize = (image != "") ? 32 : 0; std::string text = info.text; // remove the first newline (easier this way) if (text.size() > 0 && text[0] == '\n') text.erase(0, 1); const ESM::Enchantment* enchant; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); if (info.enchant != "") { enchant = store.enchants.search(info.enchant); if (enchant->data.type == ESM::Enchantment::CastOnce) text += "\n" + store.gameSettings.search("sItemCastOnce")->str; else if (enchant->data.type == ESM::Enchantment::WhenStrikes) text += "\n" + store.gameSettings.search("sItemCastWhenStrikes")->str; else if (enchant->data.type == ESM::Enchantment::WhenUsed) text += "\n" + store.gameSettings.search("sItemCastWhenUsed")->str; else if (enchant->data.type == ESM::Enchantment::ConstantEffect) text += "\n" + store.gameSettings.search("sItemCastConstant")->str; } // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); const IntPoint padding(8, 8); const int imageCaptionHPadding = (caption != "" ? 8 : 0); const int imageCaptionVPadding = (caption != "" ? 4 : 0); std::string realImage = "icons\\" + image; findImageExtension(realImage); EditBox* captionWidget = mDynamicToolTipBox->createWidget<EditBox>("NormalText", IntCoord(0, 0, 300, 300), Align::Left | Align::Top, "ToolTipCaption"); captionWidget->setProperty("Static", "true"); captionWidget->setCaption(caption); IntSize captionSize = captionWidget->getTextSize(); int captionHeight = std::max(caption != "" ? captionSize.height : 0, imageSize); EditBox* textWidget = mDynamicToolTipBox->createWidget<EditBox>("SandText", IntCoord(0, captionHeight+imageCaptionVPadding, 300, 300-captionHeight-imageCaptionVPadding), Align::Stretch, "ToolTipText"); textWidget->setProperty("Static", "true"); textWidget->setProperty("MultiLine", "true"); textWidget->setProperty("WordWrap", "true"); textWidget->setCaption(text); textWidget->setTextAlign(Align::HCenter | Align::Top); IntSize textSize = textWidget->getTextSize(); captionSize += IntSize(imageSize, 0); // adjust for image IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); if (!info.effects.empty()) { Widget* effectArea = mDynamicToolTipBox->createWidget<Widget>("", IntCoord(0, totalSize.height, 300, 300-totalSize.height), Align::Stretch, "ToolTipEffectArea"); IntCoord coord(0, 6, totalSize.width, 24); /** * \todo * the various potion effects should appear in the tooltip depending if the player * has enough skill in alchemy to know about the effects of this potion. */ Widgets::MWEffectListPtr effectsWidget = effectArea->createWidget<Widgets::MWEffectList> ("MW_StatName", coord, Align::Default, "ToolTipEffectsWidget"); effectsWidget->setWindowManager(mWindowManager); effectsWidget->setEffectList(info.effects); std::vector<MyGUI::WidgetPtr> effectItems; effectsWidget->createEffectWidgets(effectItems, effectArea, coord, true, Widgets::MWEffectList::EF_NoTarget); totalSize.height += coord.top-6; totalSize.width = std::max(totalSize.width, coord.width); } if (info.enchant != "") { Widget* enchantArea = mDynamicToolTipBox->createWidget<Widget>("", IntCoord(0, totalSize.height, 300, 300-totalSize.height), Align::Stretch, "ToolTipEnchantArea"); IntCoord coord(0, 6, totalSize.width, 24); Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget<Widgets::MWEffectList> ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget"); enchantWidget->setWindowManager(mWindowManager); enchantWidget->setEffectList(Widgets::MWEffectList::effectListFromESM(&enchant->effects)); std::vector<MyGUI::WidgetPtr> enchantEffectItems; int flag = (enchant->data.type == ESM::Enchantment::ConstantEffect) ? Widgets::MWEffectList::EF_Constant : 0; enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, flag); totalSize.height += coord.top-6; totalSize.width = std::max(totalSize.width, coord.width); if (enchant->data.type == ESM::Enchantment::WhenStrikes || enchant->data.type == ESM::Enchantment::WhenUsed) { /// \todo store the current enchantment charge somewhere int charge = enchant->data.charge; const int chargeWidth = 204; TextBox* chargeText = enchantArea->createWidget<TextBox>("SandText", IntCoord(0, 0, 10, 18), Align::Default, "ToolTipEnchantChargeText"); chargeText->setCaption(store.gameSettings.search("sCharges")->str); const int chargeTextWidth = chargeText->getTextSize().width + 5; const int chargeAndTextWidth = chargeWidth + chargeTextWidth; totalSize.width = std::max(totalSize.width, chargeAndTextWidth); chargeText->setCoord((totalSize.width - chargeAndTextWidth)/2, coord.top+6, chargeTextWidth, 18); IntCoord chargeCoord; if (totalSize.width < chargeWidth) { totalSize.width = chargeWidth; chargeCoord = IntCoord(0, coord.top+6, chargeWidth, 18); } else { chargeCoord = IntCoord((totalSize.width - chargeAndTextWidth)/2 + chargeTextWidth, coord.top+6, chargeWidth, 18); } Widgets::MWDynamicStatPtr chargeWidget = enchantArea->createWidget<Widgets::MWDynamicStat> ("MW_ChargeBar", chargeCoord, Align::Default, "ToolTipEnchantCharge"); chargeWidget->setValue(charge, charge); totalSize.height += 24; } } captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (captionHeight-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); captionWidget->setPosition (captionWidget->getPosition() + padding); textWidget->setPosition (textWidget->getPosition() + IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter if (image != "") { ImageBox* imageWidget = mDynamicToolTipBox->createWidget<ImageBox>("ImageBox", IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize), Align::Left | Align::Top, "ToolTipImage"); imageWidget->setImageTexture(realImage); imageWidget->setPosition (imageWidget->getPosition() + padding); } totalSize += IntSize(padding.left*2, padding.top*2); return totalSize; }
bool GameJoltLoginLayer::init(std::function<void()> closeFunc) { if (!LayerColor::initWithColor(ccc4(0, 0, 0, kOverlayOpacity))) return false; _closeFunc = closeFunc; Size inputSize = CCSizeMake(this->getContentSize().width * 0.3f, 40); auto gjLogo = Sprite::create("gamejolt_logo.png"); gjLogo->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.75f)); gjLogo->getTexture()->setAliasTexParameters(); EditBox *loginEditBox = EditBox::create(inputSize, Scale9Sprite::create("editboxbg.png")); loginEditBox->setAnchorPoint(ccp(0.5f, 0.5f)); loginEditBox->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.62f)); loginEditBox->setFontColor(ccBLACK); loginEditBox->setPlaceHolder("Username"); loginEditBox->setReturnType(kKeyboardReturnTypeDone); //_loginEditBox->setDelegate(this); EditBox *tokenEditBox = EditBox::create(inputSize, Scale9Sprite::create("editboxbg.png")); tokenEditBox->setAnchorPoint(ccp(0.5f, 0.5f)); tokenEditBox->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.52f)); tokenEditBox->setFontColor(ccBLACK); tokenEditBox->setPlaceHolder("Token"); tokenEditBox->setReturnType(kKeyboardReturnTypeDone); //_tokenEditBox->setDelegate(this); if (UserDefault::sharedUserDefault()->getBoolForKey("Logged", false)) { string loggedUser = UserDefault::sharedUserDefault()->getStringForKey("LoggedUser"); string loggedToken = UserDefault::sharedUserDefault()->getStringForKey("LoggedToken"); loginEditBox->setText(loggedUser.c_str()); tokenEditBox->setText(loggedToken.c_str()); } auto loginLabel = LabelBMFont::create("Login", "MainFont.fnt", 100, kTextAlignmentCenter); auto cancelLabel = LabelBMFont::create("Cancel", "MiniFont.fnt", 100, kTextAlignmentCenter); auto logoutLabel = LabelBMFont::create("Logout", "MiniFont.fnt", 100, kTextAlignmentCenter); loginLabel->setColor(greenLabelColor); cancelLabel->setColor(yellowLabelColor); logoutLabel->setColor(redLabelColor); auto loginMenuItem = MenuItemLabel::create(loginLabel, [this, loginEditBox, tokenEditBox](Object *object) { GameJolt::getInstance()->login(loginEditBox->getText(), tokenEditBox->getText()); this->getCloseFunc()(); this->removeFromParentAndCleanup(true); }); auto cancelMenuItem = MenuItemLabel::create(cancelLabel, [this](Object *object) { this->getCloseFunc()(); this->removeFromParentAndCleanup(true); }); auto logoutMenuItem = MenuItemLabel::create(logoutLabel, [this](Object *object) { GameJolt::getInstance()->logout(); this->getCloseFunc()(); this->removeFromParentAndCleanup(true); }); auto menu = Menu::create(cancelMenuItem, loginMenuItem, logoutMenuItem, NULL); menu->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.4f)); menu->alignItemsHorizontallyWithPadding(80); auto notice = LabelBMFont::create("Warning:\nThe token is NOT your password.\nGet yours on GameJolt.com!", "MiniFont.fnt", this->getContentSize().width, kTextAlignmentCenter); notice->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.11f)); this->addChild(gjLogo); this->addChild(loginEditBox); this->addChild(tokenEditBox); this->addChild(menu); this->addChild(notice); return true; }