forked from mrkite/minutor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchblockpluginwidget.cpp
More file actions
110 lines (91 loc) · 2.54 KB
/
searchblockpluginwidget.cpp
File metadata and controls
110 lines (91 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "chunk.h"
#include "searchblockpluginwidget.h"
#include "searchresultwidget.h"
#include "ui_searchblockpluginwidget.h"
#include "searchtextwidget.h"
#include <set>
#include <algorithm>
SearchBlockPluginWidget::SearchBlockPluginWidget(QWidget* parent)
: QWidget(parent)
, ui(new Ui::SearchBlockPluginWidget)
{
ui->setupUi(this);
auto idList = BlockIdentifier::Instance().getKnownIds();
QStringList nameList;
nameList.reserve(idList.size());
for (auto id: idList)
{
auto blockInfo = BlockIdentifier::Instance().getBlockInfo(id);
nameList.push_back(blockInfo.getName());
}
nameList.sort(Qt::CaseInsensitive);
ui->verticalLayout->addWidget(stw_blockId = new SearchTextWidget("block id"));
ui->verticalLayout->addWidget(stw_blockName = new SearchTextWidget("block name"));
for (auto name: nameList)
{
stw_blockName->addSuggestion(name);
}
}
SearchBlockPluginWidget::~SearchBlockPluginWidget()
{
delete ui;
}
QWidget &SearchBlockPluginWidget::getWidget()
{
return *this;
}
bool SearchBlockPluginWidget::initSearch()
{
m_searchForIds.clear();
if (stw_blockId->isActive())
{
bool ok = true;
m_searchForIds.insert(stw_blockId->getSearchText().toUInt());
if (!ok)
{
return false;
}
}
if (stw_blockName->isActive())
{
auto idList = BlockIdentifier::Instance().getKnownIds();
for (auto id: idList)
{
auto blockInfo = BlockIdentifier::Instance().getBlockInfo(id);
if (stw_blockName->matches(blockInfo.getName()))
{
m_searchForIds.insert(id);
}
}
}
return (m_searchForIds.size() > 0);
}
SearchPluginI::ResultListT SearchBlockPluginWidget::searchChunk(Chunk &chunk)
{
SearchPluginI::ResultListT results;
if (m_searchForIds.size() == 0)
{
return results;
}
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 256; y++)
{
for (int x = 0; x < 16; x++)
{
const uint blockHid = chunk.getBlockHid(x,y,z);
const auto it = m_searchForIds.find(blockHid);
if (it != m_searchForIds.end())
{
auto info = BlockIdentifier::Instance().getBlockInfo(blockHid);
SearchResultItem item;
item.name = info.getName() + " (" + QString::number(blockHid) + ")";
item.pos = QVector3D(chunk.getChunkX() * 16 + x, y, chunk.getChunkZ() * 16 + z) + QVector3D(0.5,0.5,0.5); // mark center of block, not origin
item.entity = QSharedPointer<Entity>::create(OverlayItem::Point(item.pos));
results.push_back(item);
}
}
}
}
return results;
}