예제 #1
0
/*
=================================================================================================================================================================
This class is a scroll window which displays the different rooms for using.
=================================================================================================================================================================
*/
ObjectMenu::ObjectMenu(const sf::Texture& bottomMenuTexture, TextureManager& textures)
: Object(bottomMenuTexture)
, x(45)
, y(365)
, emptyRoomSmButton     (textures.getTexture(RES_TXR_ROOMS_EMPTY_SM),       sf::Vector2f(x, y))   //Button
, emptyRoomLgButton     (textures.getTexture(RES_TXR_ROOMS_EMPTY_LG),       sf::Vector2f(x + 45 * 1, y)             )
, emptyRoomSmWdButton   (textures.getTexture(RES_TXR_ROOMS_EMPTY_SM_WD),    sf::Vector2f(x + 45 * 3, y)             )
, emptyRoomSmTlButton   (textures.getTexture(RES_TXR_ROOMS_EMPTY_SM_TL),    sf::Vector2f(x + 45 * 5, y)             )
, emptyRoomHugeButton   (textures.getTexture(RES_TXR_ROOMS_EMPTY_HG),       sf::Vector2f(x + 45 * 7, y)             )
, cannonRoomUpButton    (textures.getTexture(RES_TXR_ROOMS_CANNON),         sf::Vector2f(x + 45 * 1, y + 160 * 1)   )
, recruitButton         (textures.getTexture(RES_TXR_UNITS_RECRUIT),        sf::Vector2f(x, y)                      )
{
    mSprite.setPosition(0, 340);
    recruitButton.setTextureRect(sf::IntRect(0, 0, 38, 38 ) );
}
예제 #2
0
const sf::Texture* GuiHelper::getUnitTexture(UNITTYPES type, int playerId)
{
	std::string textureName = "p" + std::to_string(playerId);

	switch(type)
    {
    case EUT_SWORDMAN:
        textureName += "swordman";
        break;
    case EUT_ARCHER:
        textureName += "archer";
        break;
    case EUT_SPEARMAN:
        textureName += "spearman";
        break;
    case EUT_LADDERCARRIER:
        textureName += "laddercarrier";
        break;
    default:
        textureName = "";
        break;
    }

    TextureManager* textureManager = TextureManager::getInstance();
    const sf::Texture* texture = textureName != "" ? textureManager->getTexture(textureName) : textureManager->getFallbackTexture();
    return texture;
}
예제 #3
0
CharacterSelectionMenu::CharacterSelectionMenu() : Menu()
{
    this->listAvatars = new vector<sf::Sprite*>();
    this->listValidation = new vector<bool>(NUMBER_FIGHTERS, false);

    Button * button;
    int indexLine = 0, indexColumn = 0;
    vector<bool> * active = new vector<bool>(NUMBER_FIGHTERS, true);
    sf::Sprite * sprite;
    TextureManager * textureManager = GameManager::getInstance()->getTextureManager();
    CharacterManager * characterManager = GameManager::getInstance()->getCharacterManager();
    Position * position;
	for (int i = 0; i < NUMBER_CHARACTERDATA; ++i)
    {
        indexColumn = i % NUMBER_CHARACTER_BY_LINE;
        indexLine = (int)(i / NUMBER_CHARACTER_BY_LINE);
        for (unsigned int j = 0; j < NUMBER_FIGHTERS; ++j)
        {
            position = new Position(POSITION_FIRST_CHARACTER_X + indexColumn * OFFSET_CHARACTER_X, POSITION_FIRST_CHARACTER_Y + indexLine * OFFSET_CHARACTER_Y);
            if (characterManager->getCharactersDataIndex()->size() > j)
            {
                if (characterManager->getCharactersDataIndex()->at(j) == i)
                    this->listButtons->push_back(new Button("", position, true, true, false, j));
                else
                    this->listButtons->push_back(new Button("", position, true, false, false, j));
                active->at(j) = false;
            }
            else
            {
                this->listButtons->push_back(new Button("", position, true, active->at(j), false, j));
                active->at(j) = false;
            }
            button = this->listButtons->at(this->listButtons->size() - 1);
            button->setAction(&Menu::actionValidateCharacter);
            button->setActionMove(&Menu::listMove);
        }

        this->listAvatars->push_back(new sf::Sprite());
        sprite = this->listAvatars->at(this->listAvatars->size() - 1);
        sprite->setTexture(*textureManager->getTexture(characterDataArray[i].getPathAvatar()));
        sprite->setPosition((float)(position->getX() - sprite->getTextureRect().width / 2), (float)(position->getY() - sprite->getTextureRect().height / 2));
    }
    characterManager->getCharactersDataIndex()->clear();

    // Button back
	this->listButtons->push_back(new Button("Back", new Position(POSITION_BACK_X, POSITION_BACK_Y), true, false, true, 0));
	button = this->listButtons->at(this->listButtons->size() - 1);
	button->setAction(&Menu::actionBack);
	button->setActionMove(&Menu::classicMove);

	this->title->setString("SELECT YOUR FIGHTER");
	this->title->setFont(*(GameManager::getInstance()->getFontManager()->getFont(TITLE_PLAYER_FONT)));
	this->title->setScale((float)TITLE_PLAYER_SCALE_X, (float)TITLE_PLAYER_SCALE_Y);
	this->title->setPosition((float)(POSITION_TITLE_PLAYER_X), (float)(POSITION_TITLE_PLAYER_Y));
    this->title->setColor(sf::Color(TITLE_PLAYER_COLOR_RED, TITLE_PLAYER_COLOR_GREEN, TITLE_PLAYER_COLOR_BLUE));

	this->spriteMenu->setTexture(*GameManager::getInstance()->getTextureManager()->getTexture(FILE_MENU_SELECTION));
}
 TextureAtlas::TextureAtlas(TextureManager &textureManager, InputSource::Ref inputSource, bool useMipmap)
 :
 textureManager(textureManager)
 {
     XmlTree doc(inputSource->loadDataSource());
     
     auto texturePath = doc.getChild("TextureAtlas").getAttributeValue<string>("imagePath");
     auto textureSource = inputSource->getSubSource(texturePath);
     
     texture = textureManager.getTexture(textureSource, useMipmap);
     float width = texture->getWidth();
     float height = texture->getHeight();
     
     // ---
     
     for (auto spriteElement = doc.begin("TextureAtlas/sprite"); spriteElement != doc.end(); ++spriteElement)
     {
         auto spritePath = spriteElement->getAttributeValue<string>("n");
         
         auto x = spriteElement->getAttributeValue<float>("x");
         auto y = spriteElement->getAttributeValue<float>("y");
         auto w = spriteElement->getAttributeValue<float>("w");
         auto h = spriteElement->getAttributeValue<float>("h");
         auto rotated = spriteElement->hasAttribute("r");
         
         float ox, oy;
         float ow, oh;
         
         if (rotated)
         {
             oy = spriteElement->getAttributeValue<float>("oX", 0);
             ox = spriteElement->getAttributeValue<float>("oY", 0);
             ow = spriteElement->getAttributeValue<float>("oW", h);
             oh = spriteElement->getAttributeValue<float>("oH", w);
         }
         else
         {
             ox = spriteElement->getAttributeValue<float>("oX", 0);
             oy = spriteElement->getAttributeValue<float>("oY", 0);
             ow = spriteElement->getAttributeValue<float>("oW", w);
             oh = spriteElement->getAttributeValue<float>("oH", h);
         }
         
         float u1 = x / width;
         float v1 = y / height;
         
         float u2 = (x + w) / width;
         float v2 = (y + h) / height;
         
         sprites[spritePath] = make_shared<Sprite>(texture, w, h, ox, oy, ow, oh, rotated, u1, v1, u2, v2);
     }
 }
예제 #5
0
BasicEnemy::BasicEnemy(TextureManager& texMan)
{
	basicEnemyTexture = texMan.getTexture("BasicEnemy.png");
	setTexture(basicEnemyTexture);
	hspeed = -4.0f;
	collision.setPointCount(4);
	collision.setPosition(getPosition());
	collision.setPoint(0, sf::Vector2f(0, 0));
	collision.setPoint(1, sf::Vector2f(32, 0));
	collision.setPoint(2, sf::Vector2f(32, 32));
	collision.setPoint(3, sf::Vector2f(0, 32));
	grav = 0.0f;
	kill = true;
}
예제 #6
0
void Player::createAnimations(TextureManager& textureManager)
{
    sf::Texture& texture = textureManager.getTexture(TextureID::PlayerTexture);
    mAnimationManager.createAnimation(PlayerAnimationStay, texture, 0, mNumber * 64, 64, 64, 1, 1, 64, false, true);
    mAnimationManager.createAnimation(PlayerAnimationMove, texture, 64, mNumber * 64, 64, 64, 3, 5, 64, false, true);
    mAnimationManager.createAnimation(PlayerAnimationDie, texture, 64 * 4, mNumber * 64, 64, 64, 7, 5, 64, false, false);
    mAnimationManager.setAnimation(PlayerAnimationStay);

    mSprite.setTexture(texture);
    mSprite.setTextureRect(sf::IntRect(0,258 + mNumber * 22,18,18));

    mShield.setTexture(texture);
    mShield.setTextureRect(sf::IntRect(0,344,64,64));
}
예제 #7
0
void RenderDevice::unbindTextureUnits(Material* material)
{
    TextureUnitMap& units = material->textureUnits;
    TextureManager* textureManager = activeContext->textureManager;

    TextureUnitMap::ConstIterator it;
    for( it = units.Begin(); it != units.End(); it++ )
    {
        const TextureUnit& unit = it->second;
        const ImageHandle& handle = unit.image;

        Texture* texture = textureManager->getTexture(handle).get();
        if( !texture ) continue;

        renderBackend->setupTextureUnit(texture, unit);
        renderBackend->unbindTexture(texture);
    }
}
예제 #8
0
	IngameWindow::IngameWindow(Engine* engine, GuiHandler* guihandler)
	: engine(engine),
	  guihandler(guihandler),
	  // TODO: Dynamic size
	  endturnbutton(new namelessgui::Button(guihandler->getRenderWindow(), 100.0, 40.0)),
	  playernamelabel(new namelessgui::Label(guihandler->getRenderWindow(), 100.0, 40.0)),

	  unitplainsquare(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  healthsprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  unitattacksprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  unitdefensesprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  movementsprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),

	  terrainplainsquare(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  terrainattacksprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),
	  terraindefensesprite(new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32)),

	  defaultfont(new sf::Font()),

	  healthtext(new namelessgui::Label(guihandler->getRenderWindow())),
	  unitattacktext(new namelessgui::Label(guihandler->getRenderWindow())),
	  unitdefensetext(new namelessgui::Label(guihandler->getRenderWindow())),
	  unitmovementtext(new namelessgui::Label(guihandler->getRenderWindow())),
	  terrainattacktext(new namelessgui::Label(guihandler->getRenderWindow())),
	  terraindefensetext(new namelessgui::Label(guihandler->getRenderWindow()))
	{
		defaultfont->loadFromFile("./res/font/Knigqst.ttf");
		playernamelabel->setFont(*defaultfont);
		playernamelabel->setCharacterSize(25);
		playernamelabel->setText("Player name");
		playernamelabel->setPosition(625.0, 0.0);
		playernamelabel->setColor(sf::Color::White);
		addWidget(playernamelabel);

		TextureManager* texturemanager = TextureManager::getInstance();

		setPosition(620, 0);
		setSize(sf::Vector2f(200, 600));

		// set up sprites for unit information
		sf::Vector2f unitspritepos(630, 40);

		unitplainsquare->setTexture(*texturemanager->getTexture("plainsquare"));
		unitplainsquare->setPosition(unitspritepos);
		unitplainsquare->setScale(1.5, 1.5);
		addWidget(unitplainsquare);

		for(int i =  0; i < EUT_NUMBEROFUNITTYPES * 2; ++i)
		{
			unitimages[i] = new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32);
			unitimages[i]->setPosition(unitspritepos.x, unitspritepos.y);
			unitimages[i]->setScale(1.5, 1.5);
			this->addWidget(unitimages[i]);
			unitimages[i]->setVisible(true);
		}
		unitimages[EUT_SWORDMAN]->setTexture(*texturemanager->getTexture("p1swordman"));
		unitimages[EUT_SPEARMAN]->setTexture(*texturemanager->getTexture("p1spearman"));
		unitimages[EUT_ARCHER]->setTexture(*texturemanager->getTexture("p1archer"));
		std::cout << EUT_NUMBEROFUNITTYPES * 2 - 1 << std::endl;
		unitimages[EUT_NUMBEROFUNITTYPES + EUT_SWORDMAN]->setTexture(*texturemanager->getTexture("p2swordman"));
		unitimages[EUT_NUMBEROFUNITTYPES + EUT_SPEARMAN]->setTexture(*texturemanager->getTexture("p2spearman"));
		unitimages[EUT_NUMBEROFUNITTYPES + EUT_ARCHER]->setTexture(*texturemanager->getTexture("p2archer"));

		healthsprite->setTexture(*texturemanager->getTexture("health"));
		healthsprite->setPosition(unitspritepos.x + 52, unitspritepos.y);
		addWidget(healthsprite);

		unitattacksprite->setTexture(*texturemanager->getTexture("attack"));
		unitattacksprite->setPosition(unitspritepos.x + 52, unitspritepos.y + 70);
		addWidget(unitattacksprite);

		unitdefensesprite->setTexture(*texturemanager->getTexture("defense"));
		unitdefensesprite->setPosition(unitspritepos.x + 52, unitspritepos.y + 105);
		addWidget(unitdefensesprite);

		movementsprite->setTexture(*texturemanager->getTexture("movement"));
		movementsprite->setPosition(unitspritepos.x + 52,unitspritepos.y + 35);
		addWidget(movementsprite);

		// set up sprites for terrain information
		sf::Vector2f terrainspritepos(630, 210);
		for(int i = 0; i < ET_NUMBEROFTERRAINTYPES; ++i)
		{
			terrainimages[i] = new namelessgui::SpriteWidget(guihandler->getRenderWindow(), 32, 32);
			terrainimages[i]->setPosition(terrainspritepos.x, terrainspritepos.y);
			terrainimages[i]->setScale(1.5, 1.5);
			this->addWidget(terrainimages[i]);
		}
		terrainimages[ET_WOOD]->setTexture(*texturemanager->getTexture("wood"));
		terrainimages[ET_HILL]->setTexture(*texturemanager->getTexture("hill"));
		terrainimages[ET_WALL]->setTexture(*texturemanager->getTexture("wall"));

		terrainplainsquare->setTexture(*texturemanager->getTexture("plainsquare"));
		terrainplainsquare->setPosition(terrainspritepos);
		terrainplainsquare->setScale(1.5, 1.5);
		addWidget(terrainplainsquare);

		terrainattacksprite->setTexture(*texturemanager->getTexture("attack"));
		terrainattacksprite->setPosition(terrainspritepos.x + 52, terrainspritepos.y);
		addWidget(terrainattacksprite);

		terraindefensesprite->setTexture(*texturemanager->getTexture("defense"));
		terraindefensesprite->setPosition(terrainspritepos.x + 52, terrainspritepos.y + 35);
		addWidget(terraindefensesprite);

		// Set up text widgets
		healthtext->setFont(*defaultfont);
		healthtext->setCharacterSize(30);
		healthtext->setPosition(unitspritepos.x + 90, unitspritepos.y - 3);
		addWidget(healthtext);

		unitmovementtext->setFont(*defaultfont);
		unitmovementtext->setCharacterSize(30);
		unitmovementtext->setPosition(unitspritepos.x + 90, unitspritepos.y + 32);
		addWidget(unitmovementtext);

		unitattacktext->setFont(*defaultfont);
		unitattacktext->setCharacterSize(30);
		unitattacktext->setPosition(unitspritepos.x + 90, unitspritepos.y + 64);
		addWidget(unitattacktext);

		unitdefensetext->setFont(*defaultfont);
		unitdefensetext->setCharacterSize(30);
		unitdefensetext->setPosition(unitspritepos.x + 90, unitspritepos.y + 98);
		addWidget(unitdefensetext);

		terrainattacktext->setFont(*defaultfont);
		terrainattacktext->setPosition(terrainspritepos.x + 90, terrainspritepos.y - 3);
		terrainattacktext->setCharacterSize(30);
		addWidget(terrainattacktext);

		terraindefensetext->setFont(*defaultfont);
		terraindefensetext->setPosition(terrainspritepos.x + 90, terrainspritepos.y + 32);
		terraindefensetext->setCharacterSize(30);
		addWidget(terraindefensetext);

		endturnbutton->setText("End turn!");
		endturnbutton->setTextures(texturemanager->getTexture("nextbutton"),
			texturemanager->getTexture("nextbutton_active"),
			texturemanager->getTexture("nextbutton_hover"));
		endturnbutton->setPosition(sf::Vector2f(700, 560));
		endturnbutton->setScale(sf::Vector2f(1, 1));
		endturnbutton->signalclicked.connect(std::bind(&IngameWindow::changeplayerbuttonClicked, this));
		addWidget(endturnbutton);
	}
예제 #9
0
	DeployWindow::DeployWindow(Engine* engine, GuiHandler* guihandler, IngameWindow* ingamewindow)
	: engine(engine),
	  ingamewindow(ingamewindow),
	  buttongroup(new namelessgui::ButtonGroup()),
	  // TODO dynamic size
	  startbutton(new namelessgui::Button(guihandler->getRenderWindow(), 150.0, 40.0)),
	  defaultfont(new sf::Font()),
	  title(new namelessgui::Label(guihandler->getRenderWindow()))
	{
		setPosition(620, 0);
		setSize(sf::Vector2f(200, 600));

		defaultfont->loadFromFile("./res/font/Knigqst.ttf");
		title->setFont(*defaultfont);
		title->setText("Deployment");
		// TODO dynamic positioning
		title->setPosition(630, 0);
		addWidget(title);

		TextureManager* texturemgr = TextureManager::getInstance();
		for(int i = 0; i < BUTTONCOUNT; ++i)
		{
			// TODO dynamic size
			radiobuttons[i] = new namelessgui::RadioToggleButton(guihandler->getRenderWindow(), buttongroup, 120.0, 50.0);
			radiobuttons[i]->setScale(1.5, 1.5);

			// Set positions
			// TODO dynamic positioning
			float x = 650;
			float y = 35 + i * 50;
			radiobuttons[i]->setPosition(x, y);

			addWidget(radiobuttons[i]);
		}
		radiobuttons[0]->setTextures(texturemgr->getTexture("p1swordman"),
			texturemgr->getTexture("p1swordman"),
			texturemgr->getTexture("p1swordman"));
		radiobuttons[1]->setTextures(texturemgr->getTexture("p1archer"),
			texturemgr->getTexture("p1archer"),
			texturemgr->getTexture("p1archer"));
		radiobuttons[2]->setTextures(texturemgr->getTexture("p1spearman"),
			texturemgr->getTexture("p1spearman"),
			texturemgr->getTexture("p1spearman"));
		radiobuttons[3]->setTextures(texturemgr->getTexture("p2swordman"),
			texturemgr->getTexture("p2swordman"),
			texturemgr->getTexture("p2swordman"));
		radiobuttons[4]->setTextures(texturemgr->getTexture("p2archer"),
			texturemgr->getTexture("p2archer"),
			texturemgr->getTexture("p2archer"));
		radiobuttons[5]->setTextures(texturemgr->getTexture("p2spearman"),
			texturemgr->getTexture("p2spearman"),
			texturemgr->getTexture("p2spearman"));
		radiobuttons[6]->setTextures(texturemgr->getTexture("wood"),
			texturemgr->getTexture("wood"),
			texturemgr->getTexture("wood"));
		radiobuttons[6]->setText("Wood");
		radiobuttons[7]->setTextures(texturemgr->getTexture("hill"),
			texturemgr->getTexture("hill"),
			texturemgr->getTexture("hill"));
		radiobuttons[7]->setText("Hill");
		radiobuttons[8]->setTextures(texturemgr->getTexture("wall"),
			texturemgr->getTexture("wall"),
			texturemgr->getTexture("wall"));
		radiobuttons[8]->setText("Tower");
		radiobuttons[9]->setTextures(texturemgr->getTexture("plainsquare"),
			texturemgr->getTexture("plainsquare"),
			texturemgr->getTexture("plainsquare"));
		radiobuttons[9]->setText("No Terrain");

		startbutton->setTextures(texturemgr->getTexture("startbutton"),
			texturemgr->getTexture("startbutton"),
			texturemgr->getTexture("startbutton"));
		startbutton->setPosition(sf::Vector2f(650, 560));
		startbutton->signalclicked.connect(
			std::bind(&DeployWindow::startbuttonClicked, this));
		addWidget(startbutton);
	}
예제 #10
0
const Texture* R_LoadTexture(const char* name)
{
	texhandle_t texhandle = texturemanager.getHandle(name, Texture::TEX_PATCH);
	return texturemanager.getTexture(texhandle);
}