Crossfire Server, Trunk
SoundsDialog.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 "SoundsDialog.h"
14 #include <QTableWidget>
15 #include <QString>
16 #include <QFile>
17 #include <QTextStream>
18 #include <QVBoxLayout>
19 #include <QDir>
20 #include <QDialogButtonBox>
21 #include <map>
22 #include "assets.h"
23 #include "AssetsManager.h"
24 
25 #include "GameSounds.h"
26 
27 QString SoundsDialog::soundType(const QString &name) const {
29  return GameSounds::tr(GameSounds::gameSounds[name].data());
30  }
31  auto arch = getManager()->archetypes()->first([&] (const auto &at) {
32  return (at->name == name || at->clone.name == name) && (at->clone.type == SKILL || at->clone.type == SPELL || at->clone.type == SPELL_EFFECT);
33  });
34  if (arch) {
35  switch (arch->clone.type) {
36  case SKILL:
37  return tr("skill use");
38  case SPELL:
39  return tr("spell cast");
40  case SPELL_EFFECT:
41  return tr("spell effect");
42  default:
43  return tr("unknown type");
44  }
45  }
46  return tr("unknown");
47 }
48 
49 SoundsDialog::SoundsDialog(const QString &dir, QWidget *parent) : QDialog(parent) {
50  setModal(true);
51  setWindowTitle(tr("Sound information"));
52 
53  QVBoxLayout *l = new QVBoxLayout(this);
54  QTableWidget *table = new QTableWidget();
55  l->addWidget(table);
56  table->setEditTriggers(QAbstractItemView::NoEditTriggers);
57  table->setColumnCount(4);
58  table->setHorizontalHeaderLabels(QStringList(tr("Event")) << tr("Volume") << tr("File") << tr("Type"));
59 
60  auto buttons = new QDialogButtonBox(QDialogButtonBox::Close);
61  connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
62  l->addWidget(buttons);
63 
64  QFile file(QDir(dir).filePath("sounds.conf"));
65  file.open(QIODevice::ReadOnly | QIODevice::Text);
66  QTextStream in(&file);
67  while(!in.atEnd()) {
68  const QString line = in.readLine();
69  if (line.isEmpty() || line.startsWith('#')) {
70  continue;
71  }
72 
73  auto split = line.split(':');
74  if (split.length() != 3) {
75  continue;
76  }
77 
78  int pos = table->rowCount();
79  table->setRowCount(pos + 1);
80  for (int s = 0; s < split.length(); s++) {
81  auto item = new QTableWidgetItem(split[s]);
82  table->setItem(pos, s, item);
83  }
84  table->setItem(pos, split.length(), new QTableWidgetItem(soundType(split[0])));
85  }
86 }
banquet.l
l
Definition: banquet.py:164
AssetsCollection::first
T * first(std::function< bool(const T *)> op)
Definition: AssetsCollection.h:167
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
SoundsDialog::SoundsDialog
SoundsDialog(const QString &dir, QWidget *parent)
Definition: SoundsDialog.cpp:49
AssetsManager.h
mad_mage_user.file
file
Definition: mad_mage_user.py:15
SKILL
@ SKILL
Definition: object.h:148
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
is_valid_types_gen.line
line
Definition: is_valid_types_gen.py:34
GameSounds::gameSounds
static std::map< QString, std::string > gameSounds
Definition: GameSounds.h:36
SoundsDialog.h
navar-midane_time.data
data
Definition: navar-midane_time.py:11
disinfect.count
int count
Definition: disinfect.py:7
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
SoundsDialog::soundType
QString soundType(const QString &name) const
Definition: SoundsDialog.cpp:27
item
Definition: item.py:1
SPELL_EFFECT
@ SPELL_EFFECT
Definition: object.h:220
assets.h
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2606
connect
Definition: connect.py:1
SPELL
@ SPELL
Definition: object.h:219
GameSounds.h
give.name
name
Definition: give.py:27