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  myArch = addArchetype(tr("Archetype:"), "arch");
29  setAcceptDrops(true);
30  HelpManager::setHelpId(this, "treasures");
31 }
32 
33 void TreasurePanel::dragEnterEvent(QDragEnterEvent *event) {
34  if (event->mimeData()->hasFormat(MimeUtils::Archetype) || event->mimeData()->hasFormat(MimeUtils::TreasureList)) {
35  event->acceptProposedAction();
36  }
37 }
38 
39 void TreasurePanel::dragMoveEvent(QDragMoveEvent *event) {
40  event->acceptProposedAction();
41 }
42 
43 void TreasurePanel::dropEvent(QDropEvent *event) {
44  auto archs = MimeUtils::extract(event->mimeData(), MimeUtils::Archetype, getManager()->archetypes());
45  if (!archs.empty()) {
46  myArch->setArch(archs.front());
47  event->acceptProposedAction();
48  }
49  auto lists = MimeUtils::extract(event->mimeData(), MimeUtils::TreasureList, getManager()->treasures());
50  if (!lists.empty()) {
51  myList->setList(lists.front());
52  event->acceptProposedAction();
53  }
54 }
AssetWrapperPanel
Definition: AssetWrapperPanel.h:26
MimeUtils::Archetype
static const char * Archetype
Definition: MimeUtils.h:24
TreasurePanel::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *event) override
Definition: TreasurePanel.cpp:33
TreasurePanel::myList
TreasureListComboBox * myList
Definition: TreasurePanel.h:31
AssetsManager.h
lists
ignore_list ** lists
Definition: gridarta-types-convert.c:73
TreasureListComboBox.h
TreasureListComboBox::setList
void setList(const treasurelist *list)
Definition: TreasureListComboBox.cpp:37
getManager
AssetsManager * getManager()
Definition: assets.cpp:335
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:112
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:134
MimeUtils::TreasureList
static const char * TreasureList
Definition: MimeUtils.h:25
HelpManager.h
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp: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:39
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:124
MimeUtils.h
animate.event
event
DIALOGCHECK MINARGS 1 MAXARGS 2
Definition: animate.py:17
ArchetypeComboBox::setArch
void setArch(const archetype *arch)
Definition: ArchetypeComboBox.cpp:41
TreasurePanel::myArch
ArchetypeComboBox * myArch
Definition: TreasurePanel.h:30
TreasurePanel::dropEvent
virtual void dropEvent(QDropEvent *event) override
Definition: TreasurePanel.cpp:43
TreasurePanel::TreasurePanel
TreasurePanel(QWidget *parent)
Definition: TreasurePanel.cpp:22