/** * Removes the given number of scientists from the project if possible. * @param change Number of scientists to subtract. */ void ResearchInfoState::lessByValue(int change) { if (0 >= change) return; int assigned = _project->getAssigned(); if (assigned > 0) { change = std::min(assigned, change); _project->setAssigned(assigned-change); _base->setScientists(_base->getScientists()+change); setAssignedScientist(); } }
/** * Adds the given number of scientists to the project if possible. * @param change Number of scientists to add. */ void ResearchInfoState::moreByValue(int change) { if (0 >= change) return; int freeScientist = _base->getAvailableScientists(); int freeSpaceLab = _base->getFreeLaboratories(); if (freeScientist > 0 && freeSpaceLab > 0) { change = std::min(std::min(freeScientist, freeSpaceLab), change); _project->setAssigned(_project->getAssigned()+change); _base->setScientists(_base->getScientists()-change); setAssignedScientist(); } }
/** * Builds dialog. */ void ResearchInfoState::buildUi() { _screen = false; _window = new Window(this, 230, 140, 45, 30); _txtTitle = new Text(210, 17, 61, 40); _txtAvailableScientist = new Text(210, 9, 61, 60); _txtAvailableSpace = new Text(210, 9, 61, 70); _txtAllocatedScientist = new Text(210, 17, 61, 80); _txtMore = new Text(110, 17, 85, 100); _txtLess = new Text(110, 17, 85, 120); _btnCancel = new TextButton(90, 16, 61, 145); _btnOk = new TextButton(83, 16, 169, 145); _btnMore = new ArrowButton(ARROW_BIG_UP, 13, 14, 195, 100); _btnLess = new ArrowButton(ARROW_BIG_DOWN, 13, 14, 195, 120); _surfaceScientists = new InteractiveSurface(230, 140, 45, 30); _surfaceScientists->onMouseClick((ActionHandler)&ResearchInfoState::handleWheel, 0); // Set palette setPalette("PAL_BASESCAPE", 1); add(_surfaceScientists); add(_window); add(_btnOk); add(_btnCancel); add(_txtTitle); add(_txtAvailableScientist); add(_txtAvailableSpace); add(_txtAllocatedScientist); add(_txtMore); add(_txtLess); add(_btnMore); add(_btnLess); centerAllSurfaces(); // Set up objects _window->setColor(Palette::blockOffset(13)+5); _window->setBackground(_game->getResourcePack()->getSurface("BACK05.SCR")); _txtTitle->setColor(Palette::blockOffset(13)+5); _txtTitle->setBig(); _txtTitle->setText(_rule ? tr(_rule->getName()) : tr(_project->getRules ()->getName())); _txtAvailableScientist->setColor(Palette::blockOffset(13)+5); _txtAvailableScientist->setSecondaryColor(Palette::blockOffset(13)); _txtAvailableSpace->setColor(Palette::blockOffset(13)+5); _txtAvailableSpace->setSecondaryColor(Palette::blockOffset(13)); _txtAllocatedScientist->setColor(Palette::blockOffset(13)+5); _txtAllocatedScientist->setSecondaryColor(Palette::blockOffset(13)); _txtAllocatedScientist->setBig(); _txtMore->setText(tr("STR_INCREASE")); _txtLess->setText(tr("STR_DECREASE")); _txtMore->setColor(Palette::blockOffset(13)+5); _txtLess->setColor(Palette::blockOffset(13)+5); _txtMore->setBig(); _txtLess->setBig(); if (_rule) { _base->addResearch(_project); if (_rule->needItem() && (_game->getRuleset()->getUnit(_rule->getName()) || Options::spendResearchedItems)) { _base->getItems()->removeItem(_rule->getName(), 1); } } setAssignedScientist(); _btnMore->setColor(Palette::blockOffset(13)+5); _btnLess->setColor(Palette::blockOffset(13)+5); _btnMore->onMousePress((ActionHandler)&ResearchInfoState::morePress); _btnMore->onMouseRelease((ActionHandler)&ResearchInfoState::moreRelease); _btnMore->onMouseClick((ActionHandler)&ResearchInfoState::moreClick, 0); _btnLess->onMousePress((ActionHandler)&ResearchInfoState::lessPress); _btnLess->onMouseRelease((ActionHandler)&ResearchInfoState::lessRelease); _btnLess->onMouseClick((ActionHandler)&ResearchInfoState::lessClick, 0); _timerMore = new Timer(250); _timerMore->onTimer((StateHandler)&ResearchInfoState::more); _timerLess = new Timer(250); _timerLess->onTimer((StateHandler)&ResearchInfoState::less); _btnOk->setColor(Palette::blockOffset(13)+10); _btnOk->onMouseClick((ActionHandler)&ResearchInfoState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, Options::keyOk); _btnCancel->setColor(Palette::blockOffset(13)+10); if (_rule) { _btnOk->setText(tr("STR_START_PROJECT")); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onKeyboardPress((ActionHandler)&ResearchInfoState::btnCancelClick, Options::keyCancel); } else { _btnOk->setText(tr("STR_OK")); _btnCancel->setText(tr("STR_CANCEL_PROJECT")); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, Options::keyCancel); } _btnCancel->onMouseClick((ActionHandler)&ResearchInfoState::btnCancelClick); }
/** * Builds dialog. */ void ResearchInfoState::buildUi() { _screen = false; _window = new Window(this, 230, 140, 45, 30); _txtTitle = new Text(210, 17, 61, 40); _txtAvailableScientist = new Text(210, 9, 61, 60); _txtAvailableSpace = new Text(210, 9, 61, 70); _txtAllocatedScientist = new Text(210, 17, 61, 80); _txtMore = new Text(110, 17, 85, 100); _txtLess = new Text(110, 17, 85, 120); _btnCancel = new TextButton(90, 16, 61, 145); _btnOk = new TextButton(90, 16, 169, 145); _btnMore = new ArrowButton(ARROW_BIG_UP, 13, 14, 195, 100); _btnLess = new ArrowButton(ARROW_BIG_DOWN, 13, 14, 195, 120); _surfaceScientists = new InteractiveSurface(230, 140, 45, 30); _surfaceScientists->onMouseClick((ActionHandler)&ResearchInfoState::handleWheel, 0); // Set palette setInterface("allocateResearch"); add(_surfaceScientists); add(_window, "window", "allocateResearch"); add(_btnOk, "button2", "allocateResearch"); add(_btnCancel, "button2", "allocateResearch"); add(_txtTitle, "text", "allocateResearch"); add(_txtAvailableScientist, "text", "allocateResearch"); add(_txtAvailableSpace, "text", "allocateResearch"); add(_txtAllocatedScientist, "text", "allocateResearch"); add(_txtMore, "text", "allocateResearch"); add(_txtLess, "text", "allocateResearch"); add(_btnMore, "button1", "allocateResearch"); add(_btnLess, "button1", "allocateResearch"); centerAllSurfaces(); // Set up objects _window->setBackground(_game->getMod()->getSurface("BACK05.SCR")); _txtTitle->setBig(); _txtTitle->setText(_rule ? tr(_rule->getName()) : tr(_project->getRules()->getName())); _txtAllocatedScientist->setBig(); _txtMore->setText(tr("STR_INCREASE")); _txtLess->setText(tr("STR_DECREASE")); _txtMore->setBig(); _txtLess->setBig(); if (_rule) { _base->addResearch(_project); if (_rule->needItem() && _rule->destroyItem()) { _base->getStorageItems()->removeItem(_rule->getName(), 1); } } setAssignedScientist(); _btnMore->onMousePress((ActionHandler)&ResearchInfoState::morePress); _btnMore->onMouseRelease((ActionHandler)&ResearchInfoState::moreRelease); _btnMore->onMouseClick((ActionHandler)&ResearchInfoState::moreClick, 0); _btnLess->onMousePress((ActionHandler)&ResearchInfoState::lessPress); _btnLess->onMouseRelease((ActionHandler)&ResearchInfoState::lessRelease); _btnLess->onMouseClick((ActionHandler)&ResearchInfoState::lessClick, 0); _timerMore = new Timer(250); _timerMore->onTimer((StateHandler)&ResearchInfoState::more); _timerLess = new Timer(250); _timerLess->onTimer((StateHandler)&ResearchInfoState::less); _btnOk->onMouseClick((ActionHandler)&ResearchInfoState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, Options::keyOk); if (_rule) { _btnOk->setText(tr("STR_START_PROJECT")); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onKeyboardPress((ActionHandler)&ResearchInfoState::btnCancelClick, Options::keyCancel); } else { _btnOk->setText(tr("STR_OK")); _btnCancel->setText(tr("STR_CANCEL_PROJECT")); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, Options::keyCancel); } _btnCancel->onMouseClick((ActionHandler)&ResearchInfoState::btnCancelClick); if (_rule) { // mark new as normal if (_game->getSavedGame()->isResearchRuleStatusNew(_rule->getName())) { _game->getSavedGame()->setResearchRuleStatus(_rule->getName(), RuleResearch::RESEARCH_STATUS_NORMAL); } } }
/** * Builds dialog. */ void ResearchInfoState::buildUi () { _changeValueByMouseWheel = Options::getInt("changeValueByMouseWheel"); int width = 230; int height = 140; int max_width = 320; int max_height = 200; int start_x = (max_width - width) / 2; int start_y = (max_height - height) / 2; _surface = new InteractiveSurface(width, height, start_x, start_y); _surface->onMouseClick((ActionHandler)&ResearchInfoState::handleWheel, 0); int button_x_border = 16; int button_y_border = 10; int button_height = 16; int footer_button_width = width / 2 - (4 + button_x_border); _screen = false; _window = new Window(this, width, height, start_x, start_y); _txtTitle = new Text(width - 2 * button_x_border, button_height, start_x + button_x_border, start_y + button_y_border); _txtAvailableScientist = new Text(width - 2 * button_x_border, button_height, start_x + button_x_border, start_y + 3*button_y_border); _txtAvailableSpace = new Text(width - 2 * button_x_border, button_height, start_x + button_x_border, start_y + 4*button_y_border); _txtAllocatedScientist = new Text(width - 2 * button_x_border, button_height, start_x + button_x_border, start_y + 5*button_y_border); _txtMore = new Text(width - 6 * button_x_border, button_height, start_x + 2.5*button_x_border + 8, start_y + 7*button_y_border); _txtLess = new Text(width - 6 * button_x_border, button_height, start_x + 2.5*button_x_border + 8, start_y + 9*button_y_border); _btnCancel = new TextButton(footer_button_width, button_height, start_x + button_x_border, start_y + height - button_height - button_y_border); _btnOk = new TextButton(footer_button_width, button_height, start_x + button_x_border + footer_button_width + 8, start_y + height - button_height - button_y_border); _btnMore = new ArrowButton(ARROW_BIG_UP, button_x_border - 3, button_height - 2, start_x + 10*button_x_border, start_y + 7*button_y_border); _btnLess = new ArrowButton(ARROW_BIG_DOWN, button_x_border - 3, button_height - 2, start_x + 10*button_x_border, start_y + 9*button_y_border); add(_surface); add(_window); add(_btnOk); add(_btnCancel); add(_txtTitle); add(_txtAvailableScientist); add(_txtAvailableSpace); add(_txtAllocatedScientist); add(_txtMore); add(_txtLess); add(_btnMore); add(_btnLess); centerAllSurfaces(); // Set up objects _window->setColor(Palette::blockOffset(13)+5); _window->setBackground(_game->getResourcePack()->getSurface("BACK05.SCR")); _txtTitle->setColor(Palette::blockOffset(13)+5); _txtTitle->setBig(); _txtTitle->setText(_rule ? _game->getLanguage()->getString(_rule->getName()) : _game->getLanguage()->getString(_project->getRules ()->getName())); _txtAvailableScientist->setColor(Palette::blockOffset(13)+5); _txtAvailableScientist->setSecondaryColor(Palette::blockOffset(13)); _txtAvailableSpace->setColor(Palette::blockOffset(13)+5); _txtAvailableSpace->setSecondaryColor(Palette::blockOffset(13)); _txtAllocatedScientist->setColor(Palette::blockOffset(13)+5); _txtAllocatedScientist->setSecondaryColor(Palette::blockOffset(13)); _txtAllocatedScientist->setBig(); _txtMore->setText(_game->getLanguage()->getString("STR_INCREASE")); _txtLess->setText(_game->getLanguage()->getString("STR_DECREASE")); _txtMore->setColor(Palette::blockOffset(13)+5); _txtLess->setColor(Palette::blockOffset(13)+5); _txtMore->setBig(); _txtLess->setBig(); if (_rule) { _base->addResearch(_project); if (_rule->needItem() && (_game->getRuleset()->getUnit(_rule->getName()) || Options::getBool("researchedItemsWillSpent"))) { _base->getItems()->removeItem(_rule->getName(), 1); } } setAssignedScientist(); _btnMore->setColor(Palette::blockOffset(13)+5); _btnLess->setColor(Palette::blockOffset(13)+5); _btnMore->onMousePress((ActionHandler)&ResearchInfoState::morePress); _btnMore->onMouseRelease((ActionHandler)&ResearchInfoState::moreRelease); _btnMore->onMouseClick((ActionHandler)&ResearchInfoState::moreClick, 0); _btnLess->onMousePress((ActionHandler)&ResearchInfoState::lessPress); _btnLess->onMouseRelease((ActionHandler)&ResearchInfoState::lessRelease); _btnLess->onMouseClick((ActionHandler)&ResearchInfoState::lessClick, 0); _timerMore = new Timer(250); _timerMore->onTimer((StateHandler)&ResearchInfoState::more); _timerLess = new Timer(250); _timerLess->onTimer((StateHandler)&ResearchInfoState::less); _btnOk->setColor(Palette::blockOffset(13)+10); _btnOk->setText(_game->getLanguage()->getString("STR_OK")); _btnOk->onMouseClick((ActionHandler)&ResearchInfoState::btnOkClick); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, (SDLKey)Options::getInt("keyOk")); _btnCancel->setColor(Palette::blockOffset(13)+10); if (_rule) { _btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL")); _btnCancel->onKeyboardPress((ActionHandler)&ResearchInfoState::btnCancelClick, (SDLKey)Options::getInt("keyCancel")); } else { _btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_PROJECT")); _btnOk->onKeyboardPress((ActionHandler)&ResearchInfoState::btnOkClick, (SDLKey)Options::getInt("keyCancel")); } _btnCancel->onMouseClick((ActionHandler)&ResearchInfoState::btnCancelClick); }