Coverage report for gui


src/
File: src/render/scenes/world/WorldDraw.cpp
Date: 2024-06-25 10:57:02
Lines:
0/95
0.0%
Functions:
0/5
0.0%
Branches:
0/210
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy
4 ** File description:
5 ** world
6 */
7
8 #include "World.hpp"
9 #include "../../core/Core.hpp"
10 #include "../../../utils/Random.hpp"
11
12 void World::draw(sf::RenderWindow &window)
13 {
14 _sprites["background"]->draw(window);
15 if (_core->_funMode)
16 for (auto &starling : _starlings) {
17 _sprites["starling"]->setPosition(starling._pos);
18 _sprites["starling"]->setRotation(starling._rotation);
19 _sprites["starling"]->draw(window);
20 }
21 _view.setCenter(_pos + _tmpOffset + _offset);
22 _viewRect = sf::FloatRect(
23 _view.getCenter().x - _view.getSize().x / 2 - 50,
24 _view.getCenter().y - _view.getSize().y / 2 - 50,
25 _view.getSize().x + 100,
26 _view.getSize().y + 100
27 );
28 window.setView(_view);
29
30 iterateWorld([&](int i, int j) {
31 layer1(i, j);
32 });
33 iterateWorld([&](int i, int j) {
34 layer2(i, j);
35 });
36 window.setView(window.getDefaultView());
37 _worldUi.draw(window);
38 _chat->setPosition(sf::Vector2f(
39 50,
40 window.getSize().y - 50
41 ));
42 _chat->draw(window);
43 }
44
45 void World::layer1(int i, int j)
46 {
47 if (_viewRect.contains(_chuncks[i][j].getMiddle()) == false)
48 return;
49 sf::RenderWindow &window = _core->getWindow();
50 _sprite->_sprite.setPosition(
51 _chuncks[i][j]._pos.x,
52 _chuncks[i][j]._pos.y + _chuncks[i][j]._yOffset
53 );
54 window.draw(_sprite->_sprite);
55 if (i == _hoveredTile.x && j == _hoveredTile.y && !_isDragging) {
56 _sprites["hover1"]->_sprite.setPosition(
57 _chuncks[i][j]._pos.x,
58 _chuncks[i][j]._pos.y + _chuncks[i][j]._yOffset
59 );
60 window.draw(_sprites["hover1"]->_sprite);
61 }
62
63 std::map<int, Egg> eggs = _core->_data.getEggs();
64 for (auto &egg : eggs) {
65 if (egg.second.getState() != EggStatus::HATCHED &&
66 egg.second.getPos()[0] == i && egg.second.getPos()[1] == j) {
67 _sprites["hoverEgg"]->_sprite.setPosition(
68 _chuncks[i][j]._pos.x,
69 _chuncks[i][j]._pos.y + _chuncks[i][j]._yOffset
70 );
71 _sprites["hoverEgg"]->setColor(sf::Color(98, 151, 50));
72 window.draw(_sprites["hoverEgg"]->_sprite);
73 }
74 }
75 }
76
77 void World::layer2(int i, int j)
78 {
79 if (_viewRect.contains(_chuncks[i][j].getMiddle()) == false)
80 return;
81 sf::RenderWindow &window = _core->getWindow();
82 if (!drawBuilding(window, i, j) && !drawTrantorian(window, i, j))
83 _chuncks[i][j].draw(window);
84 bool incantation = false;
85 for (auto &lvlUpAnim : _lvlUpAnims)
86 if (lvlUpAnim.getTile().x == i && lvlUpAnim.getTile().y == j) {
87 lvlUpAnim.draw(window);
88 incantation = true;
89 }
90 if (!incantation && _selectedTile.x == i && _selectedTile.y == j) {
91 _sprites["halo1"]->_sprite.setPosition(
92 _chuncks[i][j]._pos.x,
93 _chuncks[i][j]._pos.y + _chuncks[i][j]._yOffset - TILE_SIZE_Y / 2
94 );
95 window.draw(_sprites["halo1"]->_sprite);
96 }
97 for (auto &bubble : _bubbles) {
98 if (i == bubble.getPos().x && j == bubble.getPos().y) {
99 _sprites["bubble"]->_sprite.setPosition(
100 _chuncks[i][j].getMiddle());
101 window.draw(_sprites["bubble"]->_sprite);
102 _bubbleText.setString(bubble.getMessage());
103 _bubbleText.setPosition(
104 _chuncks[i][j].getMiddle().x + 25,
105 _chuncks[i][j].getMiddle().y + -50
106 );
107 window.draw(_bubbleText);
108 }
109 }
110 }
111
112 bool World::drawBuilding(sf::RenderWindow &window, int i, int j)
113 {
114 bool ret = false;
115 if (_buildings[i][j] != 0 &&
116 _worldUi.getPanelState() != WorldUi::panelState::FLAG &&
117 _worldUi.getPanelState() != WorldUi::panelState::TRANTORIAN) {
118 _sprites["buildings"]->_sprite.setPosition(
119 _chuncks[i][j]._pos.x,
120 _chuncks[i][j]._pos.y + _chuncks[i][j]._yOffset - TILE_SIZE_Y / 2
121 );
122 _sprites["buildings"]->setFrame(_buildings[i][j] - 1);
123 window.draw(_sprites["buildings"]->_sprite);
124 ret = true;
125 }
126 return ret;
127 }
128
129 bool World::drawTrantorian(sf::RenderWindow &window, int i, int j)
130 {
131 bool ret = false;
132 int index = 0;
133
134 for (auto &trantorian : _trantorians) {
135 if (trantorian.getTile().x == i && trantorian.getTile().y == j) {
136 trantorian.draw(window);
137 if (trantorian.isDead())
138 continue;
139 ret = true;
140 if (trantorian.getTile().x == i && trantorian.getTile().y == j) {
141 if ((_worldUi.getPanelState() == WorldUi::panelState::TRANTORIAN &&
142 index == _worldUi._idPlayer) ||
143 (_worldUi.getPanelState() == WorldUi::panelState::FLAG &&
144 trantorian._team == _teams[_worldUi._idTeam])) {
145 _sprites["aura"]->_sprite.setPosition(trantorian.getPos() + sf::Vector2f(0, -40));
146 _sprites["aura"]->setColor(_teamsColor[trantorian._teamIndex > 5 ? 5 : trantorian._teamIndex]);
147 _sprites["aura"]->setScale(_zoom);
148
149 window.draw(_sprites["aura"]->_sprite);
150 }
151 }
152 if (_zoom > 0.6f)
153 continue;
154 _sprites["lvlbanner"]->_sprite.setPosition(trantorian.getPos());
155 _sprites["lvlbanner"]->setFrame(trantorian._level - 1);
156 _sprites["lvlbanner"]->setColor(_teamsColor[trantorian._teamIndex > 5 ? 5 : trantorian._teamIndex]);
157 window.draw(_sprites["lvlbanner"]->_sprite);
158 }
159 index++;
160 }
161 return ret;
162 }
163