UfopaediaStartState::UfopaediaStartState() { _screen = false; // set background window _window = new Window(this, 256, 180, 32, 10, POPUP_BOTH); // set title _txtTitle = new Text(224, 17, 48, 33); // Set palette setInterface("ufopaedia"); add(_window, "window", "ufopaedia"); add(_txtTitle, "text", "ufopaedia"); _btnOk = new TextButton(224, 12, 48, 167); add(_btnOk, "button1", "ufopaedia"); // set buttons const std::vector<std::string> &list = _game->getMod()->getUfopaediaCategoryList(); int y = 50; y -= 13 * (list.size() - 9); for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { TextButton *button = new TextButton(224, 12, 48, y); y += 13; add(button, "button1", "ufopaedia"); button->setText(tr(*i)); button->onMouseClick((ActionHandler)&UfopaediaStartState::btnSectionClick); _btnSections.push_back(button); } if (!_btnSections.empty()) _txtTitle->setY(_btnSections.front()->getY() - _txtTitle->getHeight()); centerAllSurfaces(); _window->setBackground(_game->getMod()->getSurface("BACK01.SCR")); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_UFOPAEDIA")); _btnOk->setText(tr("STR_OK")); _btnOk->onMouseClick((ActionHandler)&UfopaediaStartState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&UfopaediaStartState::btnOkClick, Options::keyCancel); _btnOk->onKeyboardPress((ActionHandler)&UfopaediaStartState::btnOkClick, Options::keyGeoUfopedia); }
Dialog::Dialog(std::shared_ptr<DialogData> p) { using namespace DialogSettings; sizePolicy = WidgetSizePolicy::PREFER; layout._setPos(IntPair{borderSz, borderSz}); layout.setMargins(0, 0, 0, 0); layout.setWidgetAlignment(WidgetAlignmentHoriz::LEFT, WidgetAlignmentVert::TOP); layout.setSpacing(widgetSpacing); // process data assert(p); data = p; assert(!data->title.empty()); assert(!data->message.empty()); assert(!data->buttonText.empty()); TextRenderer* tr = GameData::instance().resources->getDefaultTR(); WidgetText* textTitle = new WidgetText; textTitle->enableBackground(colTitleBg); textTitle->setRenderer(tr); textTitle->setTextColor(colText); textTitle->setText(data->title); WidgetText* textMessage = new WidgetText; textMessage->setRenderer(tr); textMessage->setTextColor(colText); textMessage->setText(data->message); // add buttons HorizontalLayout* hLayout = new HorizontalLayout; hLayout->setWidgetAlignment(WidgetAlignmentHoriz::LEFT, WidgetAlignmentVert::TOP); hLayout->setSpacing(btnSpacing); std::shared_ptr<TextButton::Style> buttonStyle = std::make_shared<TextButton::Style>(); buttonStyle->tr = tr; buttonStyle->outlineSz = 0; buttonStyle->colText = colBtnText; buttonStyle->colBgOut = colBtnBgOut; buttonStyle->colBgOver = colBtnBgOver; buttonStyle->colBgDown = colBtnBgDown; TextButton* button; for (std::size_t i = 0; i < data->buttonText.size(); ++i) { button = new TextButton; button->setStyle(buttonStyle); button->setText(data->buttonText[i]); button->setCallback(std::bind(&self_type::buttonCallback, this, i)); hLayout->add(button); } // add to layout layout.add(textTitle); layout.add(textMessage); layout.add(hLayout); // finalize layout._setParent(this); _resize(getPrefSize(), WidgetResizeFlag::SELF); }
/** * Initializes all the elements in the Psi Training screen. * @param game Pointer to the core game. */ PsiTrainingState::PsiTrainingState() { // Create objects _window = new Window(this, 320, 200, 0, 0); _txtTitle = new Text(300, 17, 10, 16); _btnOk = new TextButton(160, 14, 80, 174); // Set palette setPalette("PAL_BASESCAPE", 7); add(_window); add(_btnOk); add(_txtTitle); // Set up objects _window->setColor(Palette::blockOffset(15)+6); _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR")); _btnOk->setColor(Palette::blockOffset(13)+10); _btnOk->setText(tr("STR_OK")); _btnOk->onMouseClick((ActionHandler)&PsiTrainingState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&PsiTrainingState::btnOkClick, Options::keyCancel); _txtTitle->setColor(Palette::blockOffset(13)+10); _txtTitle->setBig(); _txtTitle->setAlign(ALIGN_CENTER); _txtTitle->setText(tr("STR_PSIONIC_TRAINING")); int buttons = 0; for(std::vector<Base*>::const_iterator b = _game->getSavedGame()->getBases()->begin(); b != _game->getSavedGame()->getBases()->end(); ++b) { if((*b)->getAvailablePsiLabs()) { TextButton *btnBase = new TextButton(160, 14, 80, 40 + 16 * buttons); btnBase->setColor(Palette::blockOffset(15) + 6); btnBase->onMouseClick((ActionHandler)&PsiTrainingState::btnBaseXClick); btnBase->setText((*b)->getName()); add(btnBase); _bases.push_back(*b); _btnBases.push_back(btnBase); ++buttons; if (buttons >= 8) { break; } } } centerAllSurfaces(); }
int InstructionsMenu::addDisabledTextButton(const string &text, int x, int y, bool isHeader) { TextButton *txtBut = new TextButton(); txtBut->setText(text); txtBut->setX(x); txtBut->setY(y); txtBut->setEnabled(false); txtBut->setTextColor(INSTR_R, INSTR_G, INSTR_B); if (isHeader) { txtBut->setTextSize(HEADER_TEXT_SIZE); } else { txtBut->setTextSize(STANDARD_TEXT_SIZE); } m_buttons.push_back(txtBut); return txtBut->getHeight() + BUTTON_SEP; }
void InstructionsMenu::init() { TextButton *txtBut; int yPos; setTitle("Controls"); yPos = initControlsDisplay(); // Init back button. txtBut = new TextButton(); txtBut->setText("Back"); txtBut->setX(txtBut->getCenteredXPos()); txtBut->setY(yPos); m_buttons.push_back(txtBut); yPos += txtBut->getHeight() + BUTTON_SEP; }
/** * Initializes all the elements in the Multiple Targets window. * @param game Pointer to the core game. * @param targets List of targets to display. * @param craft Pointer to craft to retarget (NULL if none). * @param state Pointer to the Geoscape state. */ MultipleTargetsState::MultipleTargetsState(Game *game, std::vector<Target*> targets, Craft *craft, GeoscapeState *state) : State(game), _targets(targets), _craft(craft), _state(state) { _screen = false; if (_targets.size() > 1) { int winHeight = BUTTON_HEIGHT * _targets.size() + SPACING * (_targets.size() - 1) + MARGIN * 2; int winY = (200 - winHeight) / 2; int btnY = winY + MARGIN; // Create objects _window = new Window(this, 136, winHeight, 60, winY, POPUP_VERTICAL); // Set palette setPalette("PAL_GEOSCAPE", 7); add(_window); // Set up objects _window->setColor(Palette::blockOffset(8) + 5); _window->setBackground(_game->getResourcePack()->getSurface("BACK15.SCR")); int y = btnY; for (size_t i = 0; i < _targets.size(); ++i) { TextButton *button = new TextButton(116, BUTTON_HEIGHT, 70, y); button->setColor(Palette::blockOffset(8) + 5); button->setText(_targets[i]->getName(_game->getLanguage())); button->onMouseClick((ActionHandler)&MultipleTargetsState::btnTargetClick); add(button); _btnTargets.push_back(button); y += button->getHeight() + SPACING; } _btnTargets[0]->onKeyboardPress((ActionHandler)&MultipleTargetsState::btnCancelClick, Options::keyCancel); centerAllSurfaces(); } }
void PauseState::init() { sf::Vector2f window( mGame->getTarget()->getSize().x, mGame->getTarget()->getSize().y ); sf::Vector2f boxSize( 500.0f, 230.f ); sf::Vector2f boxPosition( window.x / 2.f - boxSize.x / 2.f, window.y / 2.f - boxSize.y / 2.f ); TextButton* bg = new TextButton(); bg->setSize( boxSize ); bg->setPosition( boxPosition ); bg->setBackgroundColor( sf::Color::Black ); bg->setVisible( true ); mMenu.addItem( "1_BG", bg ); TextButton* resume = new TextButton(); resume->setFont( DEFAULT_FONT ); resume->setText( "Resume" ); resume->setTextColor( sf::Color::White ); resume->setHighlightTextColor( sf::Color::Green ); resume->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 20.f ) ); resume->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); resume->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); resume->setVisible( true ); resume->setClickFunction( []( Menu* menu, Game* game ) { game->popState(); } ); mMenu.addItem( "2_Resume", resume ); // TextButton* restart = new TextButton(); // restart->setFont( DEFAULT_FONT ); // restart->setText( "Restart" ); // restart->setTextColor( sf::Color::White ); // restart->setHighlightTextColor( sf::Color::Green ); // restart->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 90.f ) ); // restart->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); // restart->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); // restart->setVisible( true ); // std::string map = mMap; // restart->setClickFunction( [map]( Menu* menu, Game* game ) // { // std::cout << map << std::endl; // game->popState(); // game->popState(); // game->pushState( new PlayState( map ) ); // } ); // mMenu.addItem( "3_Restart", restart ); TextButton* menu = new TextButton(); menu->setFont( DEFAULT_FONT ); menu->setText( "Return to menu" ); menu->setTextColor( sf::Color::White ); menu->setHighlightTextColor( sf::Color::Green ); menu->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 90.f ) ); menu->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); menu->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); menu->setVisible( true ); menu->setClickFunction( []( Menu* menu, Game* game ) { game->popState(); game->popState(); } ); mMenu.addItem( "4_Menu", menu ); TextButton* quit = new TextButton(); quit->setFont( DEFAULT_FONT ); quit->setText( "Quit" ); quit->setTextColor( sf::Color::White ); quit->setHighlightTextColor( sf::Color::Green ); quit->setPosition( sf::Vector2f( boxPosition.x + 20.f, boxPosition.y + 160.f ) ); quit->setSize( sf::Vector2f( boxSize.x - 40.f, 50.f ) ); quit->setBackgroundColor( sf::Color( 50.f, 50.f, 50.f, 200.f ) ); quit->setVisible( true ); quit->setClickFunction( []( Menu* menu, Game* game ) { game->quit(); } ); mMenu.addItem( "5_Quit", quit ); }