示例#1
0
/**
 * Draws the view of all the facilities in the base, connectors
 * between them and crafts landed in hangars.
 */
void BaseView::draw()
{
	Surface::draw();

	// Draw grid squares
	for (int x = 0; x < 8; ++x)
	{
		for (int y = 0; y < 8; ++y)
		{
			Surface *frame = _texture->getFrame(0);
			frame->setX(x * GRID_SIZE);
			frame->setY(y * GRID_SIZE);
			frame->blit(this);
		}
	}

	std::vector<Craft*>::iterator craft = _base->getCrafts()->begin();

	for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i)
	{
		// Draw facility shape
		int num = 0;
		for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y)
		{
			for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); ++x)
			{
				Surface *frame;

				if ((*i)->getBuildTime() == 0)
					frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num);
				else
					frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num + 2 + (*i)->getRules()->getSize());

				frame->setX(x * GRID_SIZE);
				frame->setY(y * GRID_SIZE);
				frame->blit(this);

				num++;
			}
		}
	}

	for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i)
	{
		// Draw connectors
		if ((*i)->getBuildTime() == 0)
		{
			// Facilities to the right
			int x = (*i)->getX() + (*i)->getRules()->getSize();
			if (x < BASE_SIZE)
			{
				for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y)
				{
					if (_facilities[x][y] != 0 && _facilities[x][y]->getBuildTime() == 0)
					{
						Surface *frame = _texture->getFrame(7);
						frame->setX(x * GRID_SIZE - GRID_SIZE / 2);
						frame->setY(y * GRID_SIZE);
						frame->blit(this);
					}
				}
			}

			// Facilities to the bottom
			int y = (*i)->getY() + (*i)->getRules()->getSize();
			if (y < BASE_SIZE)
			{
				for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); ++x)
				{
					if (_facilities[x][y] != 0 && _facilities[x][y]->getBuildTime() == 0)
					{
						Surface *frame = _texture->getFrame(8);
						frame->setX(x * GRID_SIZE);
						frame->setY(y * GRID_SIZE - GRID_SIZE / 2);
						frame->blit(this);
					}
				}
			}
		}
	}

	for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i)
	{
		// Draw facility graphic
		int num = 0;
		for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); ++y)
		{
			for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); ++x)
			{
				if ((*i)->getRules()->getSize() == 1)
				{
					Surface *frame = _texture->getFrame((*i)->getRules()->getSpriteFacility() + num);
					frame->setX(x * GRID_SIZE);
					frame->setY(y * GRID_SIZE);
					frame->blit(this);
				}

				num++;
			}
		}

		// Draw crafts
		if ((*i)->getBuildTime() == 0 && (*i)->getRules()->getCrafts() > 0 && craft != _base->getCrafts()->end())
		{
			Surface *frame = _texture->getFrame((*craft)->getRules()->getSprite() + 33);
			frame->setX((*i)->getX() * GRID_SIZE + ((*i)->getRules()->getSize() - 1) * GRID_SIZE / 2 + 2);
			frame->setY((*i)->getY() * GRID_SIZE + ((*i)->getRules()->getSize() - 1) * GRID_SIZE / 2 - 4);
			frame->blit(this);
			++craft;
		}

		// Draw time remaining
		if ((*i)->getBuildTime() > 0)
		{
			Text *text = new Text(GRID_SIZE * (*i)->getRules()->getSize(), 16, 0, 0);
			text->setPalette(getPalette());
			text->setFonts(_big, _small);
			text->setX((*i)->getX() * GRID_SIZE);
			text->setY((*i)->getY() * GRID_SIZE + (GRID_SIZE * (*i)->getRules()->getSize() - 16) / 2);
			text->setBig();
			std::wstringstream ss;
			ss << (*i)->getBuildTime();
			text->setAlign(ALIGN_CENTER);
			text->setColor(Palette::blockOffset(13)+5);
			text->setText(ss.str());
			text->blit(this);
			delete text;
		}
	}
}
示例#2
0
/**
 * Initializes all the elements in the test palette screen.
 */
TestPaletteState::TestPaletteState(const std::string &palette, bool highContrast)
{
	// Create objects
	_bg = new Surface(320, 200, 0, 0);
	_btnCancel = new TextButton(60, 9, 240, 190);

	// Set palette
	setPalette(palette);

	add(_bg);
	add(_btnCancel);

	centerAllSurfaces();

	_btnCancel->onMouseClick((ActionHandler)&TestPaletteState::btnCancelClick);
	_btnCancel->onKeyboardPress((ActionHandler)&TestPaletteState::btnCancelClick, Options::keyCancel);

	bool ctrlPressed = SDL_GetModState() & KMOD_CTRL;
	bool shiftPressed = SDL_GetModState() & KMOD_SHIFT;

	// basic palette
	if (ctrlPressed)
	{
		Surface surf = Surface(20, 11, 0, 0);
		surf.setPalette(_bg->getPalette());
		for (int row = 0; row < 16; ++row)
		{
			for (int column = 0; column < 16; ++column)
			{
				int index = row * 16 + column;
				surf.setX(column * 20);
				surf.setY(row * 11);
				surf.drawRect(0, 0, 20, 11, index);
				surf.blit(_bg);
			}
		}
		return;
	}

	// small digits without/with border
	if (shiftPressed)
	{
		NumberText text = NumberText(25, 9, 0, 0);
		text.setPalette(_bg->getPalette());
		text.initText(_game->getMod()->getFont("FONT_BIG"), _game->getMod()->getFont("FONT_SMALL"), _game->getLanguage());
		text.setBordered(highContrast);
		for (int row = 0; row < 22; ++row)
		{
			for (int column = 0; column < 12; ++column)
			{
				int index = row * 12 + column;
				if (index > 255)
				{
					return;
				}
				text.setColor(index);
				text.setX(column * 26);
				text.setY(row * 9);
				text.setValue(index);
				text.blit(_bg);
			}
		}
		return;
	}

	// normal text without/with high contrast
	Text text = Text(25, 9, 0, 0);
	text.setPalette(_bg->getPalette());
	text.initText(_game->getMod()->getFont("FONT_BIG"), _game->getMod()->getFont("FONT_SMALL"), _game->getLanguage());
	text.setHighContrast(highContrast);
	for (int row = 0; row < 22; ++row)
	{
		for (int column = 0; column < 12; ++column)
		{
			int index = row * 12 + column;
			if (index > 255)
			{
				return;
			}
			text.setColor(index);
			text.setX(column * 26);
			text.setY(row * 9);
			std::wostringstream ss;
			ss << index;
			text.setText(ss.str().c_str());
			text.blit(_bg);
		}
	}
}