LCOV - code coverage report
Current view: top level - client - GraphicCard.cpp (source / functions) Hit Total Coverage
Test: code-coverage.info.cleaned Lines: 0 67 0.0 %
Date: 2023-01-28 00:08:57 Functions: 0 5 0.0 %

          Line data    Source code
       1             : #include <client.hpp>
       2             : #include <iostream>
       3             : 
       4             : #define ACTION_INDEX 15
       5             : #define PRIORITY_INDEX 11
       6             : 
       7             : const sf::Color VALIDATE_BUTTON_COLOR = sf::Color(255, 255, 255, 100);
       8             : const std::vector<std::string> typeOfPriorityCards = {"economy", "army", "science", "culture", "industry"};
       9             : 
      10             : using namespace client;
      11             : 
      12           0 : GraphicCard::GraphicCard(const std::string &path, const Json::Value &dataNumber, const float windowLength, const float windowWidth, int index, sf::Font &font)
      13             : {
      14           0 :     this->windowLength = windowLength;
      15           0 :     this->windowWidth = windowWidth;
      16           0 :     texture = std::make_unique<TextureDisplayer>(path);
      17           0 :     texture->addSprite();
      18           0 :     texture->setImageType((HudTextureType)(index + PRIORITY_INDEX)); // +7 to go to the priority cards in the HudTextureType (enum class)
      19           0 :     type = typeOfPriorityCards[index];
      20           0 :     difficulty = index;
      21             : 
      22           0 :     priorityScale = dataNumber["priority-card-proportion"].asFloat() / (float(texture->getWidth()) / windowLength);
      23           0 :     upScaleProportion = dataNumber["priority-card-up-scale"].asFloat();
      24           0 :     yBodyOffset = dataNumber["body-y-proportion"].asFloat() * windowWidth;
      25             : 
      26           0 :     texture->setHudSpritePosition(priorityScale, windowLength, windowWidth, 0, index);
      27             : 
      28           0 :     int validateButtonPosX = texture->getSprite().getPosition().x + dataNumber["validate-button-offset-x"].asInt();
      29           0 :     int validateButtonPosY = texture->getSprite().getPosition().y + dataNumber["validate-button-offset-y"].asInt();
      30             : 
      31           0 :     validateButton = std::make_unique<Button>(
      32           0 :         sf::Vector2f(dataNumber["validate-button-size-x"].asInt(), dataNumber["validate-button-size-y"].asInt()),
      33           0 :         sf::Vector2f(validateButtonPosX, validateButtonPosY),
      34             :         VALIDATE_BUTTON_COLOR,
      35           0 :         false);
      36             : 
      37           0 :     validateButton->setText(
      38           0 :         dataNumber["validate-button-size-text"].asInt(),
      39           0 :         sf::Vector2f(0, dataNumber["validate-button-offset-text-y"].asInt()),
      40             :         "Play",
      41             :         font);
      42           0 : }
      43             : 
      44           0 : GraphicCard::GraphicCard(const std::string &path, float actionProportion, const float windowLength, const float windowWidth, int actionCardNumber, int index)
      45             : {
      46           0 :     texture = std::make_unique<TextureDisplayer>(path);
      47           0 :     texture->addSprite();
      48           0 :     texture->setImageType((HudTextureType)(actionCardNumber + ACTION_INDEX)); // +11 to go to the action cards in the HudTextureType (enum class)
      49             : 
      50           0 :     priorityScale = actionProportion / (float(texture->getWidth()) / windowLength);
      51           0 :     upScaleProportion = 0;
      52           0 :     yBodyOffset = 0;
      53           0 :     this->windowLength = windowLength;
      54           0 :     this->windowWidth = windowWidth;
      55             : 
      56           0 :     texture->setHudSpritePosition(priorityScale, windowLength, windowWidth, 0, index);
      57           0 : }
      58             : 
      59             : /*!
      60             :  * @brief Move up a priority card when we click on it
      61             :  */
      62           0 : void GraphicCard::moveUpPriorityCard()
      63             : {
      64             :     int yPos;
      65             :     int xPos;
      66             :     int xTitlePos;
      67             :     int xBodyPosition;
      68             : 
      69           0 :     if (isUp)
      70             :     {
      71           0 :         yPos = windowWidth - texture->getHeight() * priorityScale + upScaleProportion * windowWidth;
      72             :     }
      73             :     else
      74             :     {
      75           0 :         yPos = windowWidth - texture->getHeight() * priorityScale;
      76             :     }
      77           0 :     isUp = !isUp;
      78             : 
      79           0 :     xPos = texture->getSprite().getPosition().x;
      80           0 :     xTitlePos = title->getPosition().x;
      81           0 :     xBodyPosition = body->getPosition().x;
      82             : 
      83           0 :     texture->getSprite().setPosition(xPos, yPos);
      84           0 :     title->setPosition(xTitlePos, yPos);
      85           0 :     body->setPosition(xBodyPosition, yPos + yBodyOffset);
      86           0 : }
      87             : 
      88             : /*!
      89             :  * @brief Set position of all the different texts on a priority card
      90             :  * @param text text to set position
      91             :  * @param refXOffset x position from where the x offset begin
      92             :  * @param refYOffset y position from where the y offset begin
      93             :  * @param xOffset x offset
      94             :  * @param yOffset y offset
      95             :  */
      96           0 : void GraphicCard::setPositionPriorityCardTexts(sf::Text& text, int refXOffset, int refYOffset, int xOffset, int yOffset) 
      97             : {
      98           0 :     int xPos = refXOffset + xOffset;
      99           0 :     int yPos = refYOffset + yOffset;
     100             : 
     101           0 :     text.setPosition(xPos, yPos);
     102           0 : }
     103             : 
     104             : 
     105             : /*!
     106             :  * @brief Move all the elements of a priority card if we move one (title, body, play button, ...)
     107             :  * @param dataNumber json file that contains all the data necessary to move the elements
     108             :  */
     109           0 : void GraphicCard::movePriorityCardElements(const Json::Value &dataNumber)
     110             : {
     111           0 :     int cardPosX = texture->getSprite().getPosition().x;
     112           0 :     int cardPosY = texture->getSprite().getPosition().y;
     113             : 
     114             :     // title
     115           0 :     setPositionPriorityCardTexts(*title, cardPosX, cardPosY, (texture->getWidth() - title->getLocalBounds().width) / 2, 0);
     116             : 
     117             :     // body
     118           0 :     int xBodyOffset = dataNumber["body-x-proportion"].asFloat() * windowLength;
     119           0 :     int yBodyOffset = dataNumber["body-y-proportion"].asFloat() * windowWidth;
     120           0 :     setPositionPriorityCardTexts(*body, cardPosX, cardPosY, xBodyOffset, yBodyOffset);
     121             : 
     122             :     // Text box
     123           0 :     int xBoxOffset = dataNumber["box-x-number-offset-proportion"].asFloat() * windowLength;
     124           0 :     setPositionPriorityCardTexts(*nbOfBoxesText, cardPosX, nbOfBoxesText->getPosition().y, xBoxOffset, 0);
     125             : 
     126             :     // validate button rect
     127           0 :     int validateButtonPosX = cardPosX + dataNumber["validate-button-offset-x"].asInt();
     128           0 :     int validateButtonPosY = validateButton->buttonRect->getPosition().y;
     129           0 :     validateButton->buttonRect->setPosition(validateButtonPosX, validateButtonPosY);
     130             : 
     131             : 
     132             :     // validate button text
     133           0 :     auto textSize = validateButton->buttonText->getGlobalBounds();
     134           0 :     int xButtonTextOffset = (dataNumber["validate-button-size-x"].asInt() - textSize.width) / 2;
     135           0 :     int yButtonTextOffset = (dataNumber["validate-button-size-y"].asInt() - textSize.height) / 2 - textSize.height / 2 + dataNumber["validate-button-offset-text-y"].asInt();
     136           0 :     setPositionPriorityCardTexts(*validateButton->buttonText, validateButtonPosX, validateButtonPosY, xButtonTextOffset, yButtonTextOffset);
     137             : 
     138           0 : }
     139             : 

Generated by: LCOV version 1.14