Crossfire Server, Trunk
TreasurePanel.cpp
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 #include "TreasurePanel.h"
14 #include <QMimeData>
15 #include "assets.h"
16 #include "AssetsManager.h"
19 #include "MimeUtils.h"
20 #include "HelpManager.h"
21 
22 TreasurePanel::TreasurePanel(QWidget* parent) : AssetWrapperPanel(parent) {
23  addSpinBox(tr("Chance:"), "chance", 0, 255, false);
24  addSpinBox(tr("Magic:"), "magic", 0, 255, false);
25  addSpinBox(tr("Count:"), "nrof", 0, 65535, false);
26  myList = addTreasureList(tr("Treasure:"), "list", false);
27  addSpinBox(tr("Magic to generate with:"), "list_magic_value", std::numeric_limits<uint8_t>::min(), std::numeric_limits<uint8_t>::max(), false);
28  addSpinBox(tr("Magic adjustment:"), "list_magic_adjustment", std::numeric_limits<int8_t>::min(), std::numeric_limits<int8_t>::max(), false);
29  myArch = addArchetype(tr("Archetype:"), "arch");
30  addLineEdit(tr("Artifact:"), "artifact", false);
32  setAcceptDrops(true);
33  HelpManager::setHelpId(this, "treasures");
34 }
35 
36 void TreasurePanel::dragEnterEvent(QDragEnterEvent *event) {
37  if (event->mimeData()->hasFormat(MimeUtils::Archetype) || event->mimeData()->hasFormat(MimeUtils::TreasureList)) {
38  event->acceptProposedAction();
39  }
40 }
41 
42 void TreasurePanel::dragMoveEvent(QDragMoveEvent *event) {
43  event->acceptProposedAction();
44 }
45 
46 void TreasurePanel::dropEvent(QDropEvent *event) {
47  auto archs = MimeUtils::extract(event->mimeData(), MimeUtils::Archetype, getManager()->archetypes());
48  if (!archs.empty()) {
49  myArch->setArch(archs.front());
50  event->acceptProposedAction();
51  }
52  auto lists = MimeUtils::extract(event->mimeData(), MimeUtils::TreasureList, getManager()->treasures());
53  if (!lists.empty()) {
54  myList->setList(lists.front());
55  event->acceptProposedAction();
56  }
57 }
AssetWrapperPanel
Definition: AssetWrapperPanel.h:29
MimeUtils::Archetype
static const char * Archetype
Definition: MimeUtils.h:24
TreasurePanel::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *event) override
Definition: TreasurePanel.cpp:36
TreasurePanel::myList
TreasureListComboBox * myList
Definition: TreasurePanel.h:34
AssetsManager.h
AssetWrapperPanel::addLineEdit
QLineEdit * addLineEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:74
TreasureListComboBox.h
TreasureListComboBox::setList
void setList(const treasurelist *list)
Definition: TreasureListComboBox.cpp:37
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:118
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:140
MimeUtils::TreasureList
static const char * TreasureList
Definition: MimeUtils.h:25
HelpManager.h
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:154
say.max
dictionary max
Definition: say.py:148
MimeUtils::extract
static QList< T * > extract(const QMimeData *data, const QString &mime, AssetsCollection< T > *assets)
Definition: MimeUtils.h:31
HelpManager::setHelpId
static void setHelpId(QWidget *widget, const QString &id)
Definition: HelpManager.cpp:58
TreasurePanel.h
ArchetypeComboBox.h
assets.h
TreasurePanel::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *event) override
Definition: TreasurePanel.cpp:42
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:130
MimeUtils.h
animate.event
event
DIALOGCHECK MINARGS 1 MAXARGS 2
Definition: animate.py:17
lists
ignore_list ** lists
Definition: gridarta-types-convert.cpp:73
ArchetypeComboBox::setArch
void setArch(const archetype *arch)
Definition: ArchetypeComboBox.cpp:41
TreasurePanel::myArch
ArchetypeComboBox * myArch
Definition: TreasurePanel.h:33
TreasurePanel::dropEvent
virtual void dropEvent(QDropEvent *event) override
Definition: TreasurePanel.cpp:46
TreasurePanel::TreasurePanel
TreasurePanel(QWidget *parent)
Definition: TreasurePanel.cpp:22