Skip to content

Commit ba66412

Browse files
committed
[Impl] Add suggestions to name edits of "loot_table" and "tag" entry
types LootTable: - Now allow "empty" loot context in writing JSON. StringIndexMap: - Fix the stringOf() method returns an empty string at index 0.
1 parent b422d56 commit ba66412

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

src/datawidgetcontroller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ int StringIndexMap::indexOf(const QString &str) const {
324324
}
325325

326326
QString StringIndexMap::stringOf(const int index) const {
327-
return (index > 0 && index < m_indexToString.size())
327+
return (index >= 0 && index < m_indexToString.size())
328328
? m_indexToString.at(index) : QString();
329329
}
330330

src/loottable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ void LootTable::fromJson(QJsonObject &&root) {
7373
QJsonObject LootTable::toJson() const {
7474
QJsonObject root;
7575

76-
if (ui->lootTableTypeCombo->currentIndex() == 0) {
77-
return {};
78-
}
76+
// if (ui->lootTableTypeCombo->currentIndex() == 0) {
77+
// return {};
78+
// }
7979
const QString &&type = QStringLiteral("minecraft:") +
8080
types[ui->lootTableTypeCombo->currentIndex()];
8181

src/loottableentry.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212

1313
LootTableEntry::LootTableEntry(QWidget *parent) :
14-
QTabWidget(parent), ui(new Ui::LootTableEntry),
15-
m_typeCtrl(nullptr, "type") {
14+
QTabWidget(parent), m_typeCtrl(nullptr, "type"),
15+
ui(new Ui::LootTableEntry) {
1616
ui->setupUi(this);
1717
setTabEnabled(ENTRIES_TAB, false);
1818

@@ -33,6 +33,20 @@ LootTableEntry::LootTableEntry(QWidget *parent) :
3333
ui->itemSlot->setAcceptMultiple(false);
3434
ui->itemSlot->setAcceptTag(false);
3535

36+
m_lootTableModel.setRegistry(QStringLiteral("loot_table"),
37+
GameInfoModel::PrependPrefix |
38+
GameInfoModel::DontShowIcons);
39+
m_lootTableModel.setDatapackCategory(QStringLiteral("loot_tables"), true);
40+
ui->tableNameEdit->setCompleter(m_lootTableModel.createCompleter());
41+
42+
m_itemTagModel.setInfo(QStringLiteral(
43+
"tag/item"),
44+
GameInfoModel::PrependPrefix |
45+
GameInfoModel::DontShowIcons |
46+
GameInfoModel::ForceKeyAsName);
47+
m_itemTagModel.setDatapackCategory(QStringLiteral("tags/items"), true);
48+
ui->tagNameEdit->setCompleter(m_itemTagModel.createCompleter());
49+
3650
m_typeCtrl.setWidget(ui->multiPageWidget);
3751
m_controller.addMapping(QStringLiteral("functions"),
3852
ui->functionsInterface);

src/loottableentry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LOOTTABLEENTRY_H
33

44
#include "datawidgetcontroller.h"
5+
#include "gameinfomodel.h"
56

67
#include <QTabWidget>
78
#include <QHBoxLayout>
@@ -34,6 +35,8 @@ private /*slots*/ :
3435
void updateConditionsTab(int size);
3536

3637
private:
38+
GameInfoModel m_lootTableModel;
39+
GameInfoModel m_itemTagModel;
3740
DataWidgetControllerRecord m_controller;
3841
DataWidgetControllerMultiPageWidget m_typeCtrl;
3942
Ui::LootTableEntry *ui;

src/tagselectordialog.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@
1111

1212
TagSelectorDialog::TagSelectorDialog(QWidget *parent,
1313
CodeFile::FileType type) :
14-
QDialog(parent),
15-
ui(new Ui::TagSelectorDialog) {
14+
QDialog(parent), ui(new Ui::TagSelectorDialog) {
1615
ui->setupUi(this);
1716

1817
filterModel.setParent(ui->tagListView);
1918
model.setParent(this);
20-
setupTagTreeView(type);
19+
setupTagView(type);
2120
connect(ui->tagFilterBox, &QLineEdit::textChanged,
2221
this, [this](const QString &input) {
2322
filterModel.setFilterRegularExpression(input);
2423
});
2524

2625
connect(ui->tagListView->selectionModel(),
2726
&QItemSelectionModel::selectionChanged,
28-
this,
29-
&TagSelectorDialog::checkOK);
27+
this, &TagSelectorDialog::checkOK);
3028

3129
connect(ui->tagListView->selectionModel(),
3230
&QItemSelectionModel::selectionChanged,
33-
this,
34-
&TagSelectorDialog::showDetails);
31+
this, &TagSelectorDialog::showDetails);
3532

3633
selectButton = new QPushButton(tr("Select"), this);
3734
ui->buttonBox->removeButton(ui->buttonBox->button(QDialogButtonBox::Ok));
@@ -46,15 +43,15 @@ TagSelectorDialog::~TagSelectorDialog() {
4643
delete ui;
4744
}
4845

49-
void TagSelectorDialog::setupTagTreeView(
46+
void TagSelectorDialog::setupTagView(
5047
CodeFile::FileType type = CodeFile::ItemTag) {
5148
model.setParent(ui->tagListView);
5249
filterModel.setSourceModel(&model);
5350
filterModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
5451
filterModel.setFilterRole(Qt::DisplayRole);
5552
ui->tagListView->setModel(&filterModel);
5653

57-
QString tagStr = QStringLiteral("tag/");
54+
QString &&tagStr = QStringLiteral("tag/");
5855
switch (type) {
5956
case CodeFile::BlockTag:
6057
tagStr += QStringLiteral("block");
@@ -80,22 +77,22 @@ void TagSelectorDialog::setupTagTreeView(
8077
break;
8178
}
8279

83-
auto tagStrSplited = tagStr.split('/');
80+
auto &&tagStrSplited = tagStr.split('/');
8481
std::transform(tagStrSplited.cbegin(), tagStrSplited.cend(),
8582
tagStrSplited.begin(), [](const QString &str) -> QString {
8683
return str + 's';
8784
});
88-
auto tagDir = tagStrSplited.join('/');
85+
const QString &tagDir = tagStrSplited.join('/');
8986

90-
auto fileIDList = Glhp::fileIdList(QDir::currentPath(), tagDir);
87+
const auto &fileIDList = Glhp::fileIdList(QDir::currentPath(), tagDir);
9188
for (const auto &id : fileIDList) {
9289
model.appendRow(new QStandardItem(id));
9390
}
9491

95-
MCRTagInfo = Game::getInfo(tagStr);
92+
m_tagInfo = Game::getInfo(tagStr);
9693

97-
auto tagIter = MCRTagInfo.constBegin();
98-
while ((tagIter != MCRTagInfo.constEnd())) {
94+
auto tagIter = m_tagInfo.constBegin();
95+
while ((tagIter != m_tagInfo.constEnd())) {
9996
auto *item = new QStandardItem(
10097
QStringLiteral("minecraft:") + tagIter.key());
10198
model.appendRow(item);
@@ -104,34 +101,31 @@ void TagSelectorDialog::setupTagTreeView(
104101
}
105102

106103
QString TagSelectorDialog::getInternalSelectedID() {
107-
auto indexes = ui->tagListView->selectionModel()->selectedIndexes();
104+
const auto indexes = ui->tagListView->selectionModel()->selectedIndexes();
108105

109106
if (indexes.isEmpty()) return QString();
110107

111-
QStandardItem *item =
108+
const QStandardItem *item =
112109
model.itemFromIndex(filterModel.mapToSource(indexes[0]));
113110
auto id = item->text();
114111
return id;
115112
}
116113

117114
QString TagSelectorDialog::getSelectedID() {
118-
const auto &&internalID = getInternalSelectedID();
119-
const auto &id = internalID;
120-
121-
return '#' + id;
115+
return '#' + getInternalSelectedID();
122116
}
123117

124118
void TagSelectorDialog::checkOK() {
125119
selectButton->setEnabled(!getInternalSelectedID().isEmpty());
126120
}
127121

128122
void TagSelectorDialog::showDetails() {
129-
auto id = getInternalSelectedID();
123+
QString &&id = getInternalSelectedID();
130124

131125
if (!id.isEmpty()) {
132126
Glhp::removePrefix(id, "minecraft:"_QL1);
133-
if (MCRTagInfo.contains(id)) {
134-
const auto details = MCRTagInfo[id].toString();
127+
if (m_tagInfo.contains(id)) {
128+
const auto details = m_tagInfo[id].toString();
135129
ui->tagDetailsLabel->setText(details);
136130
return;
137131
}

src/tagselectordialog.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef TAGSELECTORDIALOG_H
22
#define TAGSELECTORDIALOG_H
33

4-
#include "mainwindow.h"
54
#include "codefile.h"
65

76
#include <QDialog>
@@ -13,8 +12,7 @@ namespace Ui {
1312
class TagSelectorDialog;
1413
}
1514

16-
class TagSelectorDialog : public QDialog
17-
{
15+
class TagSelectorDialog : public QDialog {
1816
Q_OBJECT
1917

2018
public:
@@ -31,11 +29,11 @@ protected slots:
3129
private:
3230
QSortFilterProxyModel filterModel;
3331
QStandardItemModel model;
34-
QVariantMap MCRTagInfo;
32+
QVariantMap m_tagInfo;
3533
Ui::TagSelectorDialog *ui;
3634
QPushButton *selectButton = nullptr;
3735

38-
void setupTagTreeView(CodeFile::FileType type);
36+
void setupTagView(CodeFile::FileType type);
3937
QString getInternalSelectedID();
4038
};
4139

0 commit comments

Comments
 (0)