Skip to content

Commit

Permalink
changed some enemyOverview size relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipagaxi committed Mar 22, 2024
1 parent ae4b5c8 commit 4e8ce88
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/include/UIComponents/UIStats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UIStats: public UIComponent {
void updateHealth(int value);

private:
UIBox actorStatsBox = UIBox(sf::Color(51, 25, 0, 150), "borders/borderBox.png");
UIBox actorStatsBox = UIBox(sf::Color(51, 25, 0, 150), "borders/border_stats.png");
sf::Text actorName;
sf::Text actorHealthLabel;
sf::Text actorAttackStrengthLabel;
Expand Down
1 change: 1 addition & 0 deletions src/include/UIElements/UIBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UIBox : UIElement {
sf::Vector2f getPosition() override;
sf::FloatRect getSize() override;
void scale(float x, float y) override;
void setBackgroundMargin(float x, float y);

private:
sf::RectangleShape backgroundREC;
Expand Down
3 changes: 0 additions & 3 deletions src/main/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ GameState::GameState(sf::RenderWindow &window, ActivityEnum activity) {
}

void GameState::setCurrentActivity(std::unique_ptr<Activity> newActivity) {
std::cout << "set activity called" << std::endl;
//this->currentActivity.release();
this->currentActivity = std::move(newActivity);
//this->currentActivity = newActivity;
}
12 changes: 9 additions & 3 deletions src/main/UIComponents/UIStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ UIStats::UIStats(GameState &gameState, Actor actor) {
sf::Color statsLabelFontColor = sf::Color::White;
int numStats = 2;
sf::Vector2f actorStatsBoxPosition = this->actorStatsBox.getPosition();
this->statsTextHeight = windowSize.y * 0.015;;
this->statsTextHeight = windowSize.y * 0.015;

float scale = (windowSize.y * 0.4) / this->actorStatsBox.getSize().height;
this->actorStatsBox.scale(scale, scale);

sf::FloatRect actorStatsBoxSize = this->actorStatsBox.getSize();
this->actorStatsBox.setBackgroundMargin(actorStatsBoxSize.width * 0.1, actorStatsBoxSize.height * 0.04);

this->actorName.setFont(gameState.mainFont);
this->actorName.setString(actor.name);
Expand Down Expand Up @@ -66,8 +72,8 @@ void UIStats::setPosition(float x, float y) {

sf::Vector2f actorStatsBoxPosition = this->actorStatsBox.getPosition();
sf::FloatRect actorStatsBoxSize = this->actorStatsBox.getSize();
float statsLabelPosX = actorStatsBoxPosition.x + actorStatsBoxSize.width * 0.1;
float statsValuePosX = actorStatsBoxPosition.x + actorStatsBoxSize.width * 0.4;
float statsLabelPosX = actorStatsBoxPosition.x + actorStatsBoxSize.width * 0.2;
float statsValuePosX = actorStatsBoxPosition.x + actorStatsBoxSize.width * 0.45;
float statsOffsetY = actorStatsBoxSize.height * 0.25;
float statsSeparationPaddingY = actorStatsBoxSize.height * 0.05;

Expand Down
11 changes: 11 additions & 0 deletions src/main/UIElements/UIBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ sf::Vector2f UIBox::getPosition() {
void UIBox::scale(float x, float y) {
this->borderSP.scale(sf::Vector2f(x, y));
this->backgroundREC.scale(sf::Vector2f(x, y));
}

//
void UIBox::setBackgroundMargin(float x, float y) {
sf::Vector2f backgroundRECSize = this->backgroundREC.getSize();
sf::Vector2f currentScale = this->backgroundREC.getScale();
std::cout << "Stats size (old): " << backgroundRECSize.x << ", " << backgroundRECSize.y << std::endl;
sf::Vector2f newSize = sf::Vector2f(backgroundRECSize.x - (2*x / currentScale.x), backgroundRECSize.y - (2*y / currentScale.y));
std::cout << "Stats size (new): " << newSize.x << ", " << newSize.y << std::endl;
this->backgroundREC.setSize(newSize);
this->backgroundREC.setOrigin(newSize.x * 0.5, newSize.y * 0.5);
}
37 changes: 20 additions & 17 deletions src/main/UI_Objects/UIEnemyOverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@ UIEnemyOverview::UIEnemyOverview(GameState &gameState, Enemy enemy): statsCompon
sf::Vector2u windowSize = gameState.gameWindow->getSize();

sf::FloatRect boxRect = this->backgroundBox.getSize();
this->backgroundBox.setPosition(windowSize.x * 0.51, windowSize.y * 0.1);
sf::Vector2f overviewPos = sf::Vector2f(windowSize.x * 0.51, windowSize.y * 0.1);
this->backgroundBox.setPosition(overviewPos.x, overviewPos.y);

float relativeOuterPaddingStatBoxes = 0.05;
sf::FloatRect statsBoxSize = this->statsComponent.getSize();
this->statsComponent.setPosition(windowSize.x * (1.0 - relativeOuterPaddingStatBoxes) - statsBoxSize.width, windowSize.y * 0.35);

this->colorPicker.scale(0.6, 0.6);
this->colorPicker.setColorBox(this->creature.colorPicPath, this->creature.colorPicBorderPath);
this->colorPicker.setPosition(windowSize.x * 0.6, windowSize.y * 0.35);
sf::Vector2f colorPickerPos = this->colorPicker.getPosition();
sf::FloatRect colorPickerSize = this->colorPicker.getSize();

this->pickedColorText.setFont(gameState.mainFont);
this->pickedColorText.setString("(0, 0, 0)");
this->pickedColorText.setCharacterSize(gameState.gameWindow->getSize().y*0.04);
this->pickedColorText.setFillColor(sf::Color::Yellow);
sf::FloatRect textRec = this->pickedColorText.getGlobalBounds();
this->pickedColorText.setOrigin(textRec.width/2, textRec.height/2);
this->pickedColorText.setPosition(colorPickerPos.x + colorPickerSize.width*0.5, colorPickerPos.y + colorPickerSize.height + windowSize.y*0.02);

sf::FloatRect creatureFrameRect = this->creatureFrame.getSize();
float creatureBoxScale = (windowSize.x*0.22)/creatureFrameRect.width;
this->creatureFrame.scale(creatureBoxScale, creatureBoxScale);
creatureFrameRect = this->creatureFrame.getSize();
this->creatureFrame.setPosition(colorPickerPos.x + colorPickerSize.width*0.5 - creatureFrameRect.width/2.f, windowSize.y * 0.14);
float creatureFrameMargin = boxRect.width * 0.05;
sf::Vector2f creatureFramePos = sf::Vector2f(overviewPos.x + creatureFrameMargin, overviewPos.y + creatureFrameMargin);
this->creatureFrame.setPosition(creatureFramePos.x, creatureFramePos.y);

sf::Vector2f creatureFramePos = this->creatureFrame.getPosition();
this->creatureBackgroundTX.loadFromFile(RESOURCE_PATH "actor_landscape_backgrounds/forest.png");
this->creatureBackgroundSP.setTexture(this->creatureBackgroundTX);
sf::FloatRect creatureBackgroundRect = this->creatureBackgroundSP.getGlobalBounds();
this->creatureBackgroundSP.setOrigin(creatureBackgroundRect.width/2.f, creatureBackgroundRect.height/2.f);
this->creatureBackgroundSP.setPosition(creatureFramePos.x + creatureFrameRect.width/2.f, creatureFramePos.y + creatureFrameRect.height/2.f);
this->creatureBackgroundSP.scale(creatureBoxScale, creatureBoxScale);

float colorPickerScale = creatureFrameRect.width / colorPicker.getSize().width;
this->colorPicker.scale(colorPickerScale, colorPickerScale);
this->colorPicker.setColorBox(this->creature.colorPicPath, this->creature.colorPicBorderPath);
sf::Vector2f colorPickerPos = sf::Vector2f(creatureFramePos.x, creatureFramePos.y + creatureFrameRect.height + boxRect.height * 0);
this->colorPicker.setPosition(colorPickerPos.x, colorPickerPos.y);
sf::FloatRect colorPickerSize = this->colorPicker.getSize();

this->pickedColorText.setFont(gameState.mainFont);
this->pickedColorText.setString("(0, 0, 0)");
this->pickedColorText.setCharacterSize(gameState.gameWindow->getSize().y*0.04);
this->pickedColorText.setFillColor(sf::Color::Yellow);
sf::FloatRect textRec = this->pickedColorText.getGlobalBounds();
this->pickedColorText.setOrigin(textRec.width/2, textRec.height/2);
this->pickedColorText.setPosition(colorPickerPos.x + colorPickerSize.width*0.5, colorPickerPos.y + colorPickerSize.height + windowSize.y*0.02);
}

void UIEnemyOverview::draw(sf::RenderWindow &gameWindow) {
Expand Down
Binary file added src/resources/borders/border_stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4e8ce88

Please sign in to comment.