Crossfire Resources Editor
crossfire-crossfire-server
utils
cre
artifacts
AssetWithArtifacts.h
Go to the documentation of this file.
1
/*
2
* Crossfire -- cooperative multi-player graphical RPG and adventure game
3
*
4
* Copyright (c) 2022 the Crossfire Development Team
5
*
6
* Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7
* welcome to redistribute it under certain conditions. For details, please
8
* see COPYING and LICENSE.
9
*
10
* The authors can be reached via e-mail at <crossfire@metalforge.org>.
11
*/
12
13
#ifndef ASSET_WITH_ARTIFACTS_H
14
#define ASSET_WITH_ARTIFACTS_H
15
16
#include "
assets/AssetWrapper.h
"
17
#include "
artifacts/ArtifactWrapper.h
"
18
#include "global.h"
19
20
class
ResourcesManager
;
21
25
template
<
class
T>
26
class
AssetWithArtifacts
:
public
AssetTWrapper
<T> {
27
public
:
28
AssetWithArtifacts
(
AssetWrapper
*parent,
const
QString &panelName, T* item,
ResourcesManager
*resources)
29
:
AssetTWrapper
<T>(parent, panelName, item),
mySpecificItem
(nullptr),
myResources
(resources) {
30
}
31
32
virtual
~AssetWithArtifacts
() {
33
for
(
auto
art :
myArtifacts
) {
34
delete
art;
35
}
36
}
37
38
virtual
int
childrenCount
()
const override
{
39
return
myArtifacts
.size();
40
}
41
42
virtual
AssetWrapper
*
child
(
int
child
)
override
{
43
if
(
child
>= 0 &&
child
<
static_cast<
int
>
(
myArtifacts
.size())) {
44
return
myArtifacts
[
child
];
45
}
46
return
nullptr
;
47
}
48
virtual
int
childIndex
(
AssetWrapper
*
child
)
override
{
49
auto
pos = std::find(
myArtifacts
.begin(),
myArtifacts
.end(),
child
);
50
if
(pos !=
myArtifacts
.end()) {
51
return
(pos -
myArtifacts
.begin());
52
}
53
return
-1;
54
}
55
56
protected
:
57
const
object
*
mySpecificItem
;
58
ResourcesManager
*
myResources
;
59
std::vector<ArtifactWrapper *>
myArtifacts
;
60
61
void
setSpecificItem
(
const
object
*item,
bool
notify) {
62
mySpecificItem
= item;
63
updateArtifacts
(notify);
64
}
65
66
void
updateArtifacts
(
bool
notify) {
67
std::vector<ArtifactWrapper *> artifacts;
68
if
(
mySpecificItem
) {
69
auto
list = find_artifactlist(
mySpecificItem
->type);
70
if
(list) {
71
for
(
auto
art : list->items) {
72
if
(legal_artifact_combination(
mySpecificItem
, art)) {
73
auto
wrap =
new
ArtifactWrapper
(
this
, art,
myResources
);
74
wrap->setSpecificItem(
mySpecificItem
);
75
artifacts.push_back(wrap);
76
}
77
}
78
}
79
}
80
81
if
(notify)
82
this->
markModified
(
AssetWrapper::BeforeLayoutChange
);
83
std::swap(
myArtifacts
, artifacts);
84
if
(notify)
85
this->
markModified
(
AssetWrapper::AfterLayoutChange
);
86
87
for
(
auto
art : artifacts) {
88
delete
art;
89
}
90
}
91
};
92
93
#endif
/* ASSET_WITH_ARTIFACTS_H */
AssetWithArtifacts::myResources
ResourcesManager * myResources
Definition:
AssetWithArtifacts.h:58
AssetWithArtifacts::childrenCount
virtual int childrenCount() const override
Definition:
AssetWithArtifacts.h:38
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition:
AssetWrapper.h:55
AssetWrapper::BeforeLayoutChange
@ BeforeLayoutChange
Definition:
AssetWrapper.h:33
ArtifactWrapper
Definition:
ArtifactWrapper.h:24
AssetWrapper
Definition:
AssetWrapper.h:25
AssetWithArtifacts::child
virtual AssetWrapper * child(int child) override
Definition:
AssetWithArtifacts.h:42
AssetWithArtifacts::~AssetWithArtifacts
virtual ~AssetWithArtifacts()
Definition:
AssetWithArtifacts.h:32
AssetTWrapper
Definition:
AssetWrapper.h:98
ResourcesManager
Definition:
ResourcesManager.h:80
AssetWithArtifacts::updateArtifacts
void updateArtifacts(bool notify)
Definition:
AssetWithArtifacts.h:66
AssetWithArtifacts::AssetWithArtifacts
AssetWithArtifacts(AssetWrapper *parent, const QString &panelName, T *item, ResourcesManager *resources)
Definition:
AssetWithArtifacts.h:28
AssetWithArtifacts::myArtifacts
std::vector< ArtifactWrapper * > myArtifacts
Definition:
AssetWithArtifacts.h:59
AssetWithArtifacts::setSpecificItem
void setSpecificItem(const object *item, bool notify)
Definition:
AssetWithArtifacts.h:61
AssetWithArtifacts::mySpecificItem
const object * mySpecificItem
Definition:
AssetWithArtifacts.h:57
AssetWithArtifacts::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition:
AssetWithArtifacts.h:48
ArtifactWrapper.h
AssetWithArtifacts
Definition:
AssetWithArtifacts.h:26
AssetWrapper.h
AssetWrapper::AfterLayoutChange
@ AfterLayoutChange
Definition:
AssetWrapper.h:33
Generated by
1.8.17