moving across to the generic interface for populating the map selection view

This commit is contained in:
Alister
2021-12-23 17:33:22 +00:00
parent f28a7c3824
commit 6dadcc2a43
12 changed files with 88 additions and 107 deletions

View File

@@ -51,28 +51,19 @@
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <blizzard-database-library/include/BlizzardDatabaseRecord.h>
bool World::IsEditableWorld(int pMapId)
bool World::IsEditableWorld(BlizzardDatabaseLib::Structures::BlizzardDatabaseRow& record)
{
ZoneScoped;
std::string lMapName;
try
{
DBCFile::Record map = gMapDB.getByID((unsigned int)pMapId);
lMapName = map.getString(MapDB::InternalName);
}
catch (int)
{
LogError << "Did not find map with id " << pMapId << ". This is NOT editable.." << std::endl;
return false;
}
std::string lMapName = record.Columns["Directory"].Value;
std::stringstream ssfilename;
ssfilename << "World\\Maps\\" << lMapName << "\\" << lMapName << ".wdt";
if (!Noggit::Application::NoggitApplication::instance()->clientData()->exists(ssfilename.str()))
{
Log << "World " << pMapId << ": " << lMapName << " has no WDT file!" << std::endl;
Log << "World " << record.RecordId << ": " << lMapName << " has no WDT file!" << std::endl;
return false;
}

View File

@@ -29,6 +29,7 @@
#include <unordered_set>
#include <vector>
#include <array>
#include <noggit/project/ApplicationProject.h>
namespace Noggit
{
@@ -347,7 +348,7 @@ public:
// used after the uid fix all
void unload_every_model_and_wmo_instance();
static bool IsEditableWorld(int pMapId);
static bool IsEditableWorld(BlizzardDatabaseLib::Structures::BlizzardDatabaseRow& record);
void clearHeight(glm::vec3 const& pos);
void clearAllModelsOnADT(TileIndex const& tile);

View File

@@ -30,7 +30,9 @@ int main(int argc, char *argv[])
auto noggit = Noggit::Application::NoggitApplication::instance();
noggit->Initalize(argc, argv);
noggit->Start();
auto projectSelectionPage = std::make_unique<Noggit::Ui::Windows::noggitRedProjectPage>(noggit);
projectSelectionPage->show();
return qApplication.exec();
}

View File

@@ -112,12 +112,6 @@ namespace Noggit::Application
}
void NoggitApplication::Start()
{
projectSelectionPage = std::make_unique<Noggit::Ui::Windows::noggitRedProjectPage>(this);
projectSelectionPage->show();
}
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> NoggitApplication::GetConfiguration()
{
return _applicationConfiguration;

View File

@@ -45,10 +45,9 @@ namespace Noggit::Application {
return &inst;
}
BlizzardArchive::ClientData* clientData() { return _client_data.get(); };
void clientData(std::shared_ptr<BlizzardArchive::ClientData> data) { _client_data = data; };
BlizzardArchive::ClientData* clientData() { return _client_data.get(); }
void clientData(std::shared_ptr<BlizzardArchive::ClientData> data) { _client_data = data; }
void Start();
void Initalize(int argc, char* argv[]);
std::shared_ptr<Noggit::Application::NoggitApplicationConfiguration> GetConfiguration();
static void TerminationHandler();

View File

@@ -29,9 +29,8 @@
using namespace Noggit::Ui::Tools::MapCreationWizard::Ui;
MapCreationWizard::MapCreationWizard(QWidget* parent) : Noggit::Ui::widget(parent)
MapCreationWizard::MapCreationWizard(std::shared_ptr<Project::NoggitProject> project, QWidget* parent) : Noggit::Ui::widget(parent), _project(project)
{
auto layout = new QHBoxLayout(this);
// Left side
@@ -69,20 +68,27 @@ MapCreationWizard::MapCreationWizard(QWidget* parent) : Noggit::Ui::widget(paren
_corpse_map_id->setItemData(0, QVariant (-1));
// Fill selector combo
const auto& table = std::string("map");
auto mapTable = _project->ClientDatabase->LoadTable(table);
int count = 0;
for (DBCFile::Iterator i = gMapDB.begin(); i != gMapDB.end(); ++i)
auto iterator = mapTable.Records();
while (iterator.HasRecords())
{
int map_id = i->getInt(MapDB::MapID);
std::string name = i->getLocalizedString(MapDB::Name);
int area_type = i->getUInt(MapDB::AreaType);
auto record = iterator.Next();
if (area_type < 0 || area_type > 4 || !World::IsEditableWorld(map_id))
continue;
int map_id = record.RecordId;
std::string name = record.Columns["MapName_lang"].Value;
int area_type = std::stoi(record.Columns["InstanceType"].Value);
_corpse_map_id->addItem(QString::number(map_id) + " - " + QString::fromUtf8 (name.c_str()));
_corpse_map_id->setItemData(count + 1, QVariant (map_id));
if (area_type < 0 || area_type > 4 || !World::IsEditableWorld(record))
continue;
count++;
_corpse_map_id->addItem(QString::number(map_id) + " - " + QString::fromUtf8(name.c_str()));
_corpse_map_id->setItemData(count + 1, QVariant(map_id));
count++;
}
auto add_btn = new QPushButton("New",this);

View File

@@ -81,7 +81,7 @@ namespace Noggit
Q_OBJECT
public:
MapCreationWizard(QWidget *parent = nullptr);
MapCreationWizard(std::shared_ptr<Project::NoggitProject> project, QWidget *parent = nullptr);
~MapCreationWizard();
void wheelEvent(QWheelEvent *event) override;
@@ -91,6 +91,7 @@ namespace Noggit
void map_dbc_updated();
private:
std::shared_ptr<Project::NoggitProject> _project;
Noggit::Ui::minimap_widget* _minimap_widget;
int _selected_map;
QGroupBox* _map_settings;

View File

@@ -6,8 +6,8 @@
using namespace Noggit::Ui::Tools::PresetEditor::Ui;
using namespace Noggit::Ui;
PresetEditorWidget::PresetEditorWidget(QWidget *parent)
: QMainWindow(parent, Qt::Window)
PresetEditorWidget::PresetEditorWidget(std::shared_ptr<Project::NoggitProject> project, QWidget *parent)
: QMainWindow(parent, Qt::Window), _project(project)
{
setWindowTitle("Preset Editor");
@@ -72,24 +72,30 @@ PresetEditorWidget::PresetEditorWidget(QWidget *parent)
// Fill selector combo
ui->worldSelector->addItem("None");
ui->worldSelector->setItemData(0, QVariant(-1));
const auto& table = std::string("map");
auto mapTable = _project->ClientDatabase->LoadTable(table);
int count = 1;
for (DBCFile::Iterator i = gMapDB.begin(); i != gMapDB.end(); ++i)
auto iterator = mapTable.Records();
while (iterator.HasRecords())
{
int map_id = i->getInt(MapDB::MapID);
std::string name = i->getLocalizedString(MapDB::Name);
int area_type = i->getUInt(MapDB::AreaType);
auto record = iterator.Next();
if (area_type < 0 || area_type > 4 || !World::IsEditableWorld(map_id))
continue;
int map_id = record.RecordId;
std::string name = record.Columns["MapName_lang"].Value;
int area_type = std::stoi(record.Columns["InstanceType"].Value);
ui->worldSelector->addItem(QString::number(map_id) + " - " + QString::fromUtf8 (name.c_str()));
ui->worldSelector->setItemData(count, QVariant(map_id), Qt::UserRole);
if (area_type < 0 || area_type > 4 || !World::IsEditableWorld(record))
continue;
auto map_internal_name = i->getString(MapDB::InternalName);
ui->worldSelector->setItemData(count, QVariant(QString::fromStdString(map_internal_name)), Qt::UserRole + 1);
ui->worldSelector->addItem(QString::number(map_id) + " - " + QString::fromUtf8(name.c_str()));
ui->worldSelector->setItemData(count, QVariant(map_id), Qt::UserRole);
count++;
auto map_internal_name = record.Columns["Directory"].Value;
ui->worldSelector->setItemData(count, QVariant(QString::fromStdString(map_internal_name)), Qt::UserRole + 1);
count++;
}
// Handle minimap widget

View File

@@ -19,12 +19,12 @@ namespace Noggit
class PresetEditorWidget : public QMainWindow
{
public:
PresetEditorWidget(QWidget* parent = nullptr);
PresetEditorWidget(std::shared_ptr<Project::NoggitProject> project, QWidget* parent = nullptr);
~PresetEditorWidget();
private:
void setupConnectsCommon();
std::shared_ptr<Project::NoggitProject> _project;
::Ui::PresetEditor* ui;
::Ui::PresetEditorOverlay* viewport_overlay_ui;
QFileSystemModel* _model;

View File

@@ -65,7 +65,7 @@ namespace Noggit::Ui
setWindowTitle (QString::fromStdString (title.str()));
setWindowIcon (QIcon (":/icon"));
OpenDBs();
//OpenDBs();
setCentralWidget (_null_widget);
createBookmarkList();
@@ -115,11 +115,7 @@ namespace Noggit::Ui
_menuBar->adjustSize();
if (_project->ProjectVersion == Noggit::Project::ProjectVersion::SL)
build_menu(true);
else
build_menu(false);
build_menu();
}
void main_window::check_uid_then_enter_map
@@ -199,6 +195,9 @@ namespace Noggit::Ui
_world.reset();
auto table = _project->ClientDatabase->LoadTable("Map");
auto record = table.Record(mapID);
for (DBCFile::Iterator it = gMapDB.begin(); it != gMapDB.end(); ++it)
{
if (it->getInt(MapDB::MapID) == mapID)
@@ -214,7 +213,7 @@ namespace Noggit::Ui
LogError << "Map with ID " << mapID << " not found. Failed loading." << std::endl;
}
void main_window::build_menu(bool isShadowlands)
void main_window::build_menu()
{
_stack_widget = new StackedWidget(this);
_stack_widget->setAutoResize(true);
@@ -259,7 +258,7 @@ namespace Noggit::Ui
layout->addWidget (entry_points_tabs);
build_map_lists(isShadowlands);
build_map_lists();
qulonglong bookmark_index (0);
for (auto entry : mBookmarks)
@@ -315,12 +314,12 @@ namespace Noggit::Ui
right_side->addTab(minimap_holder, "Enter map");
minimap_holder->setAccessibleName("main_menu_minimap_holder");
_map_creation_wizard = new Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard(this);
_map_creation_wizard = new Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard(_project,this);
_map_wizard_connection = connect(_map_creation_wizard, &Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard::map_dbc_updated
,[=]
{
build_map_lists(isShadowlands);
build_map_lists();
}
);
@@ -333,55 +332,37 @@ namespace Noggit::Ui
_minimap->adjustSize();
}
void Noggit::Ui::main_window::build_map_lists(bool isShadowlands)
void Noggit::Ui::main_window::build_map_lists()
{
std::array<QListWidget*, 5> type_to_table
{{_continents_table, _dungeons_table, _raids_table, _battlegrounds_table, _arenas_table}};
std::array<QListWidget*, 5> type_to_table
{{_continents_table, _dungeons_table, _raids_table, _battlegrounds_table, _arenas_table}};
for (auto& table : type_to_table)
{
table->clear();
}
for (auto& table : type_to_table)
{
table->clear();
}
const auto& table = std::string("map");
auto mapTable = _project->ClientDatabase->LoadTable(table);
if(isShadowlands)
{
const auto& table = std::string("map");
auto mapTable = _project->ClientDatabase->LoadTable(table);
auto iterator = mapTable.Records();
while (iterator.HasRecords())
{
auto record = iterator.Next();
MapEntry e;
e.mapID = record.RecordId;
e.name = record.Columns["MapName_lang"].Value;
e.areaType = std::stoi(record.Columns["InstanceType"].Value);
auto iterator = mapTable.Records();
while (iterator.HasRecords())
{
if (e.areaType < 0 || e.areaType > 4 || !World::IsEditableWorld(record))
continue;
auto record = iterator.Next();
MapEntry e;
e.mapID = record.RecordId;
e.name = record.Columns["MapName_lang"].Value;
e.areaType = std::stoi(record.Columns["InstanceType"].Value);
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()),
type_to_table[e.areaType]));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
if (e.areaType < 0 || e.areaType > 4)
continue;
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
}
else
{
for (DBCFile::Iterator i = gMapDB.begin(); i != gMapDB.end(); ++i)
{
MapEntry e;
e.mapID = i->getInt(MapDB::MapID);
e.name = i->getLocalizedString(MapDB::Name);
e.areaType = i->getUInt(MapDB::AreaType);
if (e.areaType < 0 || e.areaType > 4 || !World::IsEditableWorld(e.mapID))
continue;
auto item(new QListWidgetItem(QString::number(e.mapID) + " - " + QString::fromUtf8(e.name.c_str()), type_to_table[e.areaType]));
item->setData(Qt::UserRole, QVariant(e.mapID));
}
}
_project->ClientDatabase->UnloadTable(table);
}

View File

@@ -34,12 +34,12 @@ namespace Noggit
void prompt_exit(QCloseEvent* event);
void prompt_uid_fix_failure();
void build_map_lists(bool isShadowlands);
void build_map_lists();
QMenuBar* _menuBar;
std::unordered_set<QWidget*> displayed_widgets;
void build_menu(bool isShadowlands);
void build_menu();
signals:
void exit_prompt_opened();
void map_selected(int map_id);

View File

@@ -19,7 +19,7 @@ namespace Noggit
, [=]
{
parent->setEnabled(true);
parent->build_menu(true);
parent->build_menu();
hide();
}
);
@@ -28,7 +28,7 @@ namespace Noggit
, [=]
{
parent->setEnabled(true);
parent->build_menu(false);
parent->build_menu();
hide();
}
);