-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityAttributeWidget.cpp
More file actions
92 lines (81 loc) · 2.6 KB
/
EntityAttributeWidget.cpp
File metadata and controls
92 lines (81 loc) · 2.6 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "EntityAttributeWidget.h"
#include <iostream>
EntityAttributeWidget::EntityAttributeWidget()
{
//animal = weak_ptr<Animal>(); // Avoid random crashes
defaultLabel = new QLabel("No entity selected");
healthLabel = new QLabel();
hungerLabel = new QLabel();
thirstLabel = new QLabel();
fearLabel = new QLabel();
matingLabel = new QLabel();
sexLabel = new QLabel();
ageLabel = new QLabel();
layout = new QVBoxLayout();
layout->addWidget(defaultLabel);
layout->addWidget(healthLabel);
layout->addWidget(hungerLabel);
layout->addWidget(thirstLabel);
layout->addWidget(fearLabel);
layout->addWidget(sexLabel);
layout->addWidget(matingLabel);
layout->addWidget(ageLabel);
healthLabel->setVisible(false);
hungerLabel->setVisible(false);
thirstLabel->setVisible(false);
fearLabel->setVisible(false);
sexLabel->setVisible(false);
matingLabel->setVisible(false);
ageLabel->setVisible(false);
this->setLayout(layout);
}
EntityAttributeWidget::~EntityAttributeWidget()
{
delete layout;
delete defaultLabel;
delete healthLabel;
delete hungerLabel;
delete thirstLabel;
delete fearLabel;
delete sexLabel;
delete matingLabel;
delete ageLabel;
}
void EntityAttributeWidget::setAnimal(std::weak_ptr<Animal> a)
{
animal = a;
update();
}
void EntityAttributeWidget::update()
{
std::shared_ptr<Animal> sharedAnimal = animal.lock();
if(!sharedAnimal)
{
defaultLabel->setVisible(true);
healthLabel->setVisible(false);
hungerLabel->setVisible(false);
thirstLabel->setVisible(false);
fearLabel->setVisible(false);
matingLabel->setVisible(false);
sexLabel->setVisible(false);
ageLabel->setVisible(false);
}
else
{
defaultLabel->setVisible(false);
healthLabel->setVisible(true);
hungerLabel->setVisible(true);
thirstLabel->setVisible(true);
fearLabel->setVisible(true);
matingLabel->setVisible(true);
sexLabel->setVisible(true);
ageLabel->setVisible(true);
healthLabel->setText(healthText + QString::number(sharedAnimal->getHealth()));
hungerLabel->setText(hungerText + QString::number(sharedAnimal->getHunger()));
thirstLabel->setText(thirstText + QString::number(sharedAnimal->getThirst()));
fearLabel->setText(fearText + QString::number(sharedAnimal->getFear()));
sexLabel->setText(sexText + (sharedAnimal->isFemale() ? "Female" : "Male") );
matingLabel->setText(matingText + QString::number(sharedAnimal->getMating()));
ageLabel->setText(ageText + QString::number(sharedAnimal->getAge()));
}
}