//private
void MenuHighScoreState::buildMenu(const sf::Font& font)
{
    const float centreX = xy::DefaultSceneSize.x / 2.f;

    const auto& scores = getContext().appInstance.getScores();
    auto list = xy::UI::create<xy::UI::ScoreList>(font);
    list->setAlignment(xy::UI::Alignment::Centre);
    list->setPosition(centreX, 590.f);
    list->setList(scores);
    list->setIndex(getContext().appInstance.getLastScoreIndex());
    m_uiContainer.addControl(list);

    auto upScroll = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/scroll_arrow_vertical.png"));
    upScroll->setAlignment(xy::UI::Alignment::Centre);
    upScroll->setPosition(1310, 470.f);
    upScroll->addCallback([list]()
    {
        list->scroll(list->getVerticalSpacing());
    });
    m_uiContainer.addControl(upScroll);

    auto downScroll = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/scroll_arrow_vertical.png"));
    downScroll->setAlignment(xy::UI::Alignment::Centre);
    downScroll->setRotation(180.f);
    downScroll->setPosition(1310.f, 720.f);
    downScroll->addCallback([list]()
    {
        list->scroll(-list->getVerticalSpacing());
    });
    m_uiContainer.addControl(downScroll);
    
    auto button = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/start_button.png"));
    button->setString("OK");
    button->setAlignment(xy::UI::Alignment::Centre);
    button->setPosition(centreX, 875.f);
    button->addCallback([this]()
    {
        auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage);
        msg->type = xy::Message::UIEvent::MenuClosed;
        msg->value = 0.f;
        msg->stateID = (m_endGame) ? States::ID::HighScoresEnd : States::ID::HighScoresMenu;

        if (m_endGame)
        {
            requestStackClear();
            requestStackPush(States::ID::MenuBackground);
        }
        else
        {
            requestStackPop();
            requestStackPush(States::ID::MenuMain);
        }
        
    });
    m_uiContainer.addControl(button);
}
Exemple #2
0
//private
void ScoreState::buildMenu(const sf::Font& menuFont, const sf::Font& scoreFont)
{
    const auto& scores = getContext().appInstance.getScores();
    auto list = std::make_shared<ui::ScoreList>(scoreFont);
    list->setAlignment(ui::Alignment::Centre);
    list->setPosition(960.f, 590.f);
    list->setList(scores);
    list->setIndex(getContext().appInstance.getLastScoreIndex());
    m_uiContainer.addControl(list);
    
    auto upScroll = std::make_shared<ui::Button>(menuFont, getContext().appInstance.getTexture("assets/images/ui/scroll_arrow_vertical.png"));
    upScroll->setAlignment(ui::Alignment::Centre);
    upScroll->setPosition(1310, 470.f);
    upScroll->setCallback([list]()
    {
        list->scroll(list->getVerticalSpacing());
    });
    m_uiContainer.addControl(upScroll);

    auto downScroll = std::make_shared<ui::Button>(menuFont, getContext().appInstance.getTexture("assets/images/ui/scroll_arrow_vertical.png"));
    downScroll->setAlignment(ui::Alignment::Centre);
    downScroll->setRotation(180.f);
    downScroll->setPosition(1310.f, 720.f);
    downScroll->setCallback([list]()
    {
        list->scroll(-list->getVerticalSpacing());
    });
    m_uiContainer.addControl(downScroll);

    auto applyButton = std::make_shared<ui::Button>(menuFont, getContext().appInstance.getTexture("assets/images/ui/button.png"));
    applyButton->setText("OK");
    applyButton->setAlignment(ui::Alignment::Centre);
    applyButton->setPosition(960.f, 875.f);
    applyButton->setCallback([this]()
    {
        requestStackPop();
        requestStackPush(States::ID::Menu);

        Message msg;
        msg.type = Message::Type::UI;
        msg.ui.type = Message::UIEvent::MenuClosed;
        msg.ui.value = 0.f;
        msg.ui.stateId = States::ID::Score;
        m_messageBus.send(msg);
    });
    m_uiContainer.addControl(applyButton);

}
Exemple #3
0
	bool ColorGrid::init()
	{
		m_nNodes = m_nRows*m_nColumns;
		m_pNodes = new ColorNode[m_nNodes];
		assert(m_pNodes && "New failed to create the sequence array for the grid.");
        
		m_cbRandomSequence = new PaletteIndex[m_nRows*m_nColumns];
		assert(m_cbRandomSequence && "New failed to create the random sequence for the grid.");
        
		fHorizontalSpacing = getHorizontalSpacing();
		fVerticalSpacing = getVerticalSpacing();
		fInitialX = fHorizontalSpacing * 0.5f + m_cbBounds.getMinX();
		fInitialY = fVerticalSpacing * 0.5f + m_cbBounds.getMinY();

		// Note that the origin for the points start in the lower left.
		cocos2d::CCPoint cbCurrentPoint(fInitialX, fInitialY);

		for(int i = 0; i < m_nNodes; i++)
		{
			bool bIsSuccessful = m_pNodes[i].init();
				
			if(bIsSuccessful)
			{
				if(i / m_nRows % 2 == 0)
					cbCurrentPoint.y = fInitialY + ((i % m_nRows) * fVerticalSpacing);
				else
					cbCurrentPoint.y = fInitialY + (fVerticalSpacing / 2) + ((i % m_nRows) * fVerticalSpacing);

				cbCurrentPoint.x = fInitialX + ((i / m_nRows) * fHorizontalSpacing);
				
				m_pNodes[i].setPosition(cbCurrentPoint);
				m_pNodes[i].setParent(this, 1);
				m_pNodes[i].setColor(my_utility::random(m_nColors));
				m_uncaptured_count.tally(m_pNodes[i].getPaletteIndex());
			}
		}

		RandomCapture(m_nInitCapturePercent);

		for(int i = 0; i < m_nComboSize; i++)
		{
			m_pSelectedNodes[i] = 0;
		}

		for(int i = 0; i < m_nComboSize; i++)
		{
			m_pSelectedNodeNumbers[i] = 0;
		}
        
		return true;
	}
Exemple #4
0
	void FlowLayout::layoutChildren()
	{
			int curX = 0;
			int curY = 0;

			int highestWidget = 0;
			int numWidgets = 0;
			int rlOffset = 0;
			int btOffset = 0;
			int numRows = 1;
			int numOnRow = 0;

			std::vector<Widget*> curRow;
			Widget* firstWidget = NULL;

			int lowestPoint = 0;
			for(WidgetArray::iterator it = getChildBegin(); 
				it != getChildEnd(); ++it)
			{
				if(!(*it)->isVisible() && isFilteringVisibility())
				{
					continue;
				}

				if(!firstWidget)
				{
					firstWidget = (*it);
				}

				if(isResizingRowToWidth())
				{
					(*it)->setSize(getInnerWidth(),(*it)->getHeight());
				}

				if((maxOnRow > 0 && numOnRow >= maxOnRow) || isResizingRowToWidth() ||
					(curX + (*it)->getWidth() > getInnerWidth() && numWidgets > 0 && !singleRow))
				{
					numRows++;
					numOnRow = 0;
					curX = 0;
					curY += highestWidget + getVerticalSpacing();
					highestWidget = 0;

					if(center && !curRow.empty())
					{
						int x1 = curRow[0]->getLocation().getX();
						int x2 = curRow.back()->getLocation().getX() +
							curRow.back()->getWidth();

						int w = x2 - x1;
						int centerOffset = (getInnerWidth() - w) / 2;

						for(size_t i = 0; i < curRow.size(); ++i)
						{
							curRow[i]->setLocation(
								curRow[i]->getLocation().getX() + centerOffset,
								curRow[i]->getLocation().getY());
						}
					}

					curRow.clear();
				}
				numOnRow++;

				if(!topToBottom)
				{
					btOffset = getInnerHeight() - (*it)->getHeight() - (curY + curY);
				}
				if(!leftToRight && !center)
				{
					rlOffset = getInnerWidth() - (*it)->getWidth() - (curX + curX);
				}
				(*it)->setLocation(curX + rlOffset,curY + btOffset);
				curX += (*it)->getWidth() + getHorizontalSpacing();
				numWidgets++;

				if((*it)->getHeight() > highestWidget)
				{
					highestWidget = (*it)->getHeight();
				}

				curRow.push_back((*it));

				//find the content height
				int l = (*it)->getLocation().getY() + (*it)->getHeight();
				if(l > lowestPoint)
				{
					lowestPoint = l;
				}
		}

			//code duplication, I know :(
			if(center && !curRow.empty())
			{
				if(alignLastRow && numRows > 1 && firstWidget)
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = firstWidget->getLocation().getX();
					int diff = x2 - x1;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + diff,
							curRow[i]->getLocation().getY());
					}
				}

				else
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = curRow.back()->getLocation().getX() +
						curRow.back()->getWidth();

					int w = x2 - x1;
					int centerOffset = (getInnerWidth() - w) / 2;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + centerOffset,
							curRow[i]->getLocation().getY());
					}
				}
			}

			//set content height
			contentHSz = lowestPoint + getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM);
	}