-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsdisplay.cpp
More file actions
77 lines (66 loc) · 2.18 KB
/
statsdisplay.cpp
File metadata and controls
77 lines (66 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "statsdisplay.h"
#include <QPainter>
#include <QPen>
StatsDisplay::StatsDisplay(int x, int y, std::string name, int max_health, int current_health, int gold, int damage, QColor box_color)
{
x_ = x;
y_ = y;
player_name_ = name;
max_health_ = max_health;
current_health_ = current_health;
gold_ = gold;
box_color_ = box_color;
damage_ = damage;
}
QRectF StatsDisplay::boundingRect() const
{
return QRectF(x_,y_, width_, height_);
}
/*
Coded By: Mikayla Pickett
Function: shape
Params: none
Desc: sets graph as square
Returns: QPainterPath
*/
QPainterPath StatsDisplay::shape() const
{
QPainterPath path;
path.addRect(x_,y_,width_,height_);
return path;
}
/*
Coded By: Mikayla Pickett
Function: Paint
Params: QPainter, QStyleOptionGraphicsItem, QWidget
Desc: allows cell to be drawn, also adds stats to the view incrementally.
Returns: void
*/
void StatsDisplay::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
int distance_between = 20;
QBrush b = painter->brush();
painter->setPen(Qt::GlobalColor::white);
QString title = QString::fromStdString(player_name_ + " Stats");
painter->drawText(QPoint(this->x_, this->y_ - 5), title);
int current_y = this->y_;
int shifted_x = this->x_ + 10;
current_y += distance_between;
QString health = QString::fromStdString("Health: " + std::to_string(current_health_) + "/" + std::to_string(max_health_));
painter->drawText(QPoint(shifted_x, current_y), health);
current_y += distance_between;
QString damage = QString::fromStdString("Damage: " + std::to_string(damage_));
painter->drawText(QPoint(shifted_x, current_y), damage);
current_y += distance_between;
QString gold = QString::fromStdString("Gold: " + std::to_string(gold_));
painter->drawText(QPoint(shifted_x, current_y), gold);
painter->setPen(QPen(box_color_, 2));
painter->drawRect(QRect(this->x_, this->y_, this-> width_, height_));
painter->setBrush(b);
}
void StatsDisplay::StatsUpdated(int max_health, int current_health, int gold, int damage) {
max_health_ = max_health;
current_health_ = current_health;
gold_ = gold;
damage_ = damage;
}