only load world once in mapcreationwizard instead of loading two copies in NoggitWindows+mapcreationwizard

This commit is contained in:
T1ti
2024-10-29 03:08:17 +01:00
parent f6a9c2943a
commit cd17c9fb9f
5 changed files with 134 additions and 94 deletions

View File

@@ -562,35 +562,58 @@ void MapCreationWizard::populateNameSet(WMOInstance& instance)
std::string MapCreationWizard::getDifficultyString() std::string MapCreationWizard::getDifficultyString()
{ {
if (_instance_type->itemData(_instance_type->currentIndex()).toInt() == 1 && _difficulty_max_players->value() == 5) // dungeon int instance_type = _instance_type->itemData(_instance_type->currentIndex()).toInt();
int difficulty_type = _difficulty_type->currentIndex();
assert(instance_type == 1 || instance_type == 2);
/*
| Name | Entry Condition | Difficulty Entry 1 | Difficulty Entry 2 | Difficulty Entry 3 |
|--------------------|----------------------|-------------------------|-------------------------|-------------------------|
| Normal Creature | Different than 0 | 0 | 0 | 0 |
| Dungeon Creature | Normal Dungeon | Heroic Dungeon | 0 | 0 |
| Raid Creature | 10man Normal Raid | 25man Normal Raid | 10man Heroic Raid | 25man Heroic Raid |
| Battleground | 51-59 | 60-69 | 70-79 | 80 |
*/
if (instance_type == 1 && _difficulty_max_players->value() == 5) // dungeon
{ {
if (_difficulty_type->currentIndex() == 0) if (difficulty_type == 0)
return "DUNGEON_DIFFICULTY_5PLAYER"; return "DUNGEON_DIFFICULTY_5PLAYER";
else else if (difficulty_type == 1)
return "DUNGEON_DIFFICULTY_5PLAYER_HEROIC"; return "DUNGEON_DIFFICULTY_5PLAYER_HEROIC";
else
return "Unsupported difficulty for 5 men dungeon";
} }
else if (_instance_type->itemData(_instance_type->currentIndex()).toInt() == 2) else if (instance_type == 2) // raid
{ {
switch (_difficulty_max_players->value()) switch (_difficulty_max_players->value())
{ {
case 10: case 10:
if (_difficulty_type->currentIndex() == 0) if (difficulty_type == 0)
return "RAID_DIFFICULTY_10PLAYER"; return "RAID_DIFFICULTY_10PLAYER";
else else if (difficulty_type == 2)
return "RAID_DIFFICULTY_10PLAYER_HEROIC"; return "RAID_DIFFICULTY_10PLAYER_HEROIC";
break;
case 20: case 20:
if (_difficulty_type->currentIndex() == 0) if (difficulty_type == 0)
return "RAID_DIFFICULTY_20PLAYER"; return "RAID_DIFFICULTY_20PLAYER";
break;
case 25: case 25:
// in BC 25men was difficulty 0, after the 10men mode in wrath it is difficulty 1 // in BC 25men was difficulty 0, after the 10men mode in wrath it is difficulty 1
if (_difficulty_type->currentIndex() == (0 || 1)) // maybe instead check if a difficulty 25 already exists if (difficulty_type == 0 || difficulty_type == 1) // maybe instead check if a difficulty 25 already exists
return "RAID_DIFFICULTY_25PLAYER"; return "RAID_DIFFICULTY_25PLAYER";
else else if (difficulty_type == 3)
return "RAID_DIFFICULTY_25PLAYER_HEROIC"; return "RAID_DIFFICULTY_25PLAYER_HEROIC";
break;
case 40: case 40:
if (difficulty_type == 0)
return "RAID_DIFFICULTY_40PLAYER"; return "RAID_DIFFICULTY_40PLAYER";
break;
default:
return "invalid player count";
} }
} }
assert(false);
return ""; return "";
} }
@@ -598,6 +621,8 @@ void MapCreationWizard::selectMap(int map_id)
{ {
_is_new_record = false; _is_new_record = false;
// int map_id = world->getMapID();
auto table = _project->ClientDatabase->LoadTable("Map", readFileAsIMemStream); auto table = _project->ClientDatabase->LoadTable("Map", readFileAsIMemStream);
auto record = table.Record(map_id); auto record = table.Record(map_id);
@@ -605,9 +630,14 @@ void MapCreationWizard::selectMap(int map_id)
if (_world) if (_world)
{ {
delete _world; // delete _world;
_world.reset();
} }
// auto noggitWindow = reinterpret_cast<Noggit::Ui::Windows::NoggitWindow*>(parent());
// _world = world;
auto directoryName = record.Columns["Directory"].Value; auto directoryName = record.Columns["Directory"].Value;
auto instanceType = record.Columns["InstanceType"].Value; auto instanceType = record.Columns["InstanceType"].Value;
@@ -622,7 +652,8 @@ void MapCreationWizard::selectMap(int map_id)
// auto timeOffset = record.Columns["TimeOffset"].Value; // auto timeOffset = record.Columns["TimeOffset"].Value;
auto raidOffset = record.Columns["RaidOffset"].Value; auto raidOffset = record.Columns["RaidOffset"].Value;
_world = new World(directoryName, map_id, Noggit::NoggitRenderContext::MAP_VIEW); // _world = new World(directoryName, map_id, Noggit::NoggitRenderContext::MAP_VIEW);
_world = std::make_unique<World>(directoryName, map_id, Noggit::NoggitRenderContext::MAP_VIEW);
// check if map has a wdl and prompt to create a new one // check if map has a wdl and prompt to create a new one
std::stringstream filename; std::stringstream filename;
@@ -637,13 +668,13 @@ void MapCreationWizard::selectMap(int map_id)
bool answer = prompt.exec() == QMessageBox::StandardButton::Yes; bool answer = prompt.exec() == QMessageBox::StandardButton::Yes;
if (answer) if (answer)
{ {
_world->horizon.save_wdl(_world, true); _world->horizon.save_wdl(_world.get(), true);
_world->horizon.set_minimap(&_world->mapIndex); _world->horizon.set_minimap(&_world->mapIndex);
// _world = new World(directoryName, map_id, Noggit::NoggitRenderContext::MAP_VIEW); // refresh minimap // _world = new World(directoryName, map_id, Noggit::NoggitRenderContext::MAP_VIEW); // refresh minimap
} }
} }
_minimap_widget->world(_world); _minimap_widget->world(_world.get());
_directory->setText(QString::fromStdString(directoryName)); _directory->setText(QString::fromStdString(directoryName));
_directory->setEnabled(false); _directory->setEnabled(false);
@@ -837,7 +868,7 @@ void MapCreationWizard::saveCurrentEntry()
{ {
_world->mapIndex.removeGlobalWmo(); _world->mapIndex.removeGlobalWmo();
} }
_world->mapIndex.saveChanged(_world, true); _world->mapIndex.saveChanged(_world.get(), true);
_world->mapIndex.save(); // save wdt file _world->mapIndex.save(); // save wdt file
if (_is_new_record) if (_is_new_record)
@@ -939,7 +970,7 @@ void MapCreationWizard::discardChanges()
MapCreationWizard::~MapCreationWizard() MapCreationWizard::~MapCreationWizard()
{ {
delete _world; // delete _world;
disconnect(_connection); disconnect(_connection);
} }
@@ -950,7 +981,8 @@ void MapCreationWizard::addNewMap()
if (_world) if (_world)
{ {
delete _world; // delete _world;
_world.reset();
} }
// default to a new internal map name that isn't already used, or default world will load existing files // default to a new internal map name that isn't already used, or default world will load existing files
@@ -965,11 +997,13 @@ void MapCreationWizard::addNewMap()
suffix++; suffix++;
} }
_world = new World(internal_map_name, _cur_map_id, Noggit::NoggitRenderContext::MAP_VIEW, true); // _world = new World(internal_map_name, _cur_map_id, Noggit::NoggitRenderContext::MAP_VIEW, true);
_world = std::make_unique<World>(internal_map_name, _cur_map_id, Noggit::NoggitRenderContext::MAP_VIEW, true);
// hack to reset the minimap if there is an existing WDL with the same path(happens when removing a map from map.dbc but not the files // hack to reset the minimap if there is an existing WDL with the same path(happens when removing a map from map.dbc but not the files
_world->horizon.set_minimap(&_world->mapIndex, true); _world->horizon.set_minimap(&_world->mapIndex, true);
_minimap_widget->world(_world); _minimap_widget->world(_world.get());
_directory->setText(internal_map_name.c_str()); _directory->setText(internal_map_name.c_str());
_directory->setEnabled(true); _directory->setEnabled(true);

View File

@@ -96,8 +96,12 @@ namespace Noggit
~MapCreationWizard(); ~MapCreationWizard();
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void destroyFakeWorld() { if(_world) delete _world; _world = nullptr; _minimap_widget->world (nullptr); }; // void destroyFakeWorld() { if(_world) _world.reset(); _world = nullptr; _minimap_widget->world (nullptr); };
void addNewMap(); void addNewMap();
World* getWorld() { return _world.get(); };
std::unique_ptr<World> _world;
signals: signals:
void map_dbc_updated(int new_map = 0); void map_dbc_updated(int new_map = 0);
@@ -160,8 +164,6 @@ namespace Noggit
WmoEntryTab _wmoEntryTab; WmoEntryTab _wmoEntryTab;
World* _world = nullptr;
bool _is_new_record = false; bool _is_new_record = false;
int _cur_map_id = -1; int _cur_map_id = -1;

View File

@@ -149,6 +149,10 @@ namespace Noggit::Ui::Windows
) )
{ {
QSettings settings; QSettings settings;
assert(getWorld());
unsigned int world_map_id = getWorld()->getMapID();
#ifdef USE_MYSQL_UID_STORAGE #ifdef USE_MYSQL_UID_STORAGE
bool use_mysql = settings.value("project/mysql/enabled", false).toBool(); bool use_mysql = settings.value("project/mysql/enabled", false).toBool();
@@ -158,23 +162,23 @@ namespace Noggit::Ui::Windows
valid_conn = mysql::testConnection(true); valid_conn = mysql::testConnection(true);
} }
if ((valid_conn && mysql::hasMaxUIDStoredDB(_world->getMapID())) if ((valid_conn && mysql::hasMaxUIDStoredDB(world_map_id))
|| uid_storage::hasMaxUIDStored(_world->getMapID()) || uid_storage::hasMaxUIDStored(world_map_id)
) )
{ {
_world->mapIndex.loadMaxUID(); getWorld()->mapIndex.loadMaxUID();
enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::none, from_bookmark); enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::none, from_bookmark);
} }
#else #else
if (uid_storage::hasMaxUIDStored(_world->getMapID())) if (uid_storage::hasMaxUIDStored(world_map_id))
{ {
if (settings.value("uid_startup_check", true).toBool()) if (settings.value("uid_startup_check", true).toBool())
{ {
enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::max_uid, from_bookmark); enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::max_uid, from_bookmark);
} else } else
{ {
_world->mapIndex.loadMaxUID(); getWorld()->mapIndex.loadMaxUID();
enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::none, from_bookmark); enterMapAt(pos, camera_pitch, camera_yaw, uid_fix_mode::none, from_bookmark);
} }
} }
@@ -199,19 +203,21 @@ namespace Noggit::Ui::Windows
bool from_bookmark bool from_bookmark
) )
{ {
if (_world->mapIndex.hasAGlobalWMO()) World* world = getWorld();
if (world->mapIndex.hasAGlobalWMO())
{ {
// enter at mdoel's position // enter at mdoel's position
// pos = glm::vec3(_world->mWmoEntry[0], _world->mWmoEntry.pos[1], _world->mWmoEntry.pos[2]); // pos = glm::vec3(_world->mWmoEntry[0], _world->mWmoEntry.pos[1], _world->mWmoEntry.pos[2]);
// better, enter at model's max extent, facing toward min extent // better, enter at model's max extent, facing toward min extent
auto min_extent = glm::vec3(_world->mWmoEntry.extents[0][0], _world->mWmoEntry.extents[0][1], _world->mWmoEntry.extents[0][2]); auto min_extent = glm::vec3(world->mWmoEntry.extents[0][0], world->mWmoEntry.extents[0][1], world->mWmoEntry.extents[0][2]);
auto max_extent = glm::vec3(_world->mWmoEntry.extents[1][0], _world->mWmoEntry.extents[1][1] * 2, _world->mWmoEntry.extents[1][2]); auto max_extent = glm::vec3(world->mWmoEntry.extents[1][0], world->mWmoEntry.extents[1][1] * 2, world->mWmoEntry.extents[1][2]);
float dx = min_extent.x - max_extent.x; float dx = min_extent.x - max_extent.x;
float dy = min_extent.z - max_extent.z; // flipping z and y works better for some reason float dy = min_extent.z - max_extent.z; // flipping z and y works better for some reason
float dz = min_extent.y - max_extent.y; float dz = min_extent.y - max_extent.y;
pos = { _world->mWmoEntry.pos[0], _world->mWmoEntry.pos[1], _world->mWmoEntry.pos[2] }; pos = { world->mWmoEntry.pos[0], world->mWmoEntry.pos[1], world->mWmoEntry.pos[2] };
camera_yaw = math::degrees(math::radians(std::atan2(dx, dy))); camera_yaw = math::degrees(math::radians(std::atan2(dx, dy)));
@@ -221,8 +227,8 @@ namespace Noggit::Ui::Windows
} }
_map_creation_wizard->destroyFakeWorld(); // _map_creation_wizard->destroyFakeWorld();
_map_view = (new MapView(camera_yaw, camera_pitch, pos, this, _project, std::move(_world), uid_fix, from_bookmark)); _map_view = (new MapView(camera_yaw, camera_pitch, pos, this, _project, std::move(_map_creation_wizard->_world), uid_fix, from_bookmark));
connect(_map_view, &MapView::uid_fix_failed, [this]() connect(_map_view, &MapView::uid_fix_failed, [this]()
{ promptUidFixFailure(); }); { promptUidFixFailure(); });
connect(_settings, &settings::saved, [this]() connect(_settings, &settings::saved, [this]()
@@ -277,20 +283,24 @@ namespace Noggit::Ui::Windows
void NoggitWindow::loadMap(int map_id) void NoggitWindow::loadMap(int map_id)
{ {
_minimap->world(nullptr); // _minimap->world(nullptr);
// World is now created only here in
// void MapCreationWizard::selectMap(int map_id)
emit mapSelected(map_id);
/*
_world.reset(); _world.reset();
auto table = _project->ClientDatabase->LoadTable("Map", readFileAsIMemStream); auto table = _project->ClientDatabase->LoadTable("Map", readFileAsIMemStream);
auto record = table.Record(map_id); auto record = table.Record(map_id);
_world = std::make_unique<World>(record.Columns["Directory"].Value, map_id, Noggit::NoggitRenderContext::MAP_VIEW); _world = std::make_unique<World>(record.Columns["Directory"].Value, map_id, Noggit::NoggitRenderContext::MAP_VIEW);
_minimap->world(_world.get()); */
_minimap->world(getWorld());
_project->ClientDatabase->UnloadTable("Map"); _project->ClientDatabase->UnloadTable("Map");
emit mapSelected(map_id);
} }
void NoggitWindow::buildMenu() void NoggitWindow::buildMenu()
@@ -434,13 +444,14 @@ namespace Noggit::Ui::Windows
auto& entry(_project->Bookmarks.at(item->data(Qt::UserRole).toInt())); auto& entry(_project->Bookmarks.at(item->data(Qt::UserRole).toInt()));
_world.reset(); _map_creation_wizard->_world.reset();
for (DBCFile::Iterator it = gMapDB.begin(); it != gMapDB.end(); ++it) for (DBCFile::Iterator it = gMapDB.begin(); it != gMapDB.end(); ++it)
{ {
if (it->getInt(MapDB::MapID) == entry.map_id) if (it->getInt(MapDB::MapID) == entry.map_id)
{ {
_world = std::make_unique<World>(it->getString(MapDB::InternalName), // emit mapSelected(map_id); to update UI
_map_creation_wizard->_world = std::make_unique<World>(it->getString(MapDB::InternalName),
entry.map_id, Noggit::NoggitRenderContext::MAP_VIEW); entry.map_id, Noggit::NoggitRenderContext::MAP_VIEW);
check_uid_then_enter_map(entry.position, math::degrees(entry.camera_pitch), math::degrees(entry.camera_yaw), check_uid_then_enter_map(entry.position, math::degrees(entry.camera_pitch), math::degrees(entry.camera_yaw),
true true
@@ -458,7 +469,7 @@ namespace Noggit::Ui::Windows
QObject::connect(_minimap, &minimap_widget::map_clicked, [this](::glm::vec3 const& pos) QObject::connect(_minimap, &minimap_widget::map_clicked, [this](::glm::vec3 const& pos)
{ {
if (_world->mapIndex.hasAGlobalWMO()) // skip uid check if (getWorld()->mapIndex.hasAGlobalWMO()) // skip uid check
enterMapAt(pos, math::degrees(30.f), math::degrees(90.f), uid_fix_mode::none, false); enterMapAt(pos, math::degrees(30.f), math::degrees(90.f), uid_fix_mode::none, false);
else else
check_uid_then_enter_map(pos, math::degrees(30.f), math::degrees(90.f)); check_uid_then_enter_map(pos, math::degrees(30.f), math::degrees(90.f));

View File

@@ -50,13 +50,14 @@ namespace Noggit::Ui::Windows
QToolBar* _app_toolbar; QToolBar* _app_toolbar;
// std::unique_ptr<World> _world;
std::unordered_set<QWidget*> displayed_widgets; std::unordered_set<QWidget*> displayed_widgets;
void buildMenu(); void buildMenu();
signals: signals:
void exitPromptOpened(); void exitPromptOpened();
void mapSelected(int map_id); void mapSelected(int map_id);
private: private:
std::unique_ptr<Component::BuildMapListComponent> _buildMapListComponent; std::unique_ptr<Component::BuildMapListComponent> _buildMapListComponent;
std::shared_ptr<Application::NoggitApplicationConfiguration> _applicationConfiguration; std::shared_ptr<Application::NoggitApplicationConfiguration> _applicationConfiguration;
@@ -66,6 +67,7 @@ namespace Noggit::Ui::Windows
void handleEventMapListContextMenuPinMap(int mapId, std::string MapName); void handleEventMapListContextMenuPinMap(int mapId, std::string MapName);
void handleEventMapListContextMenuUnpinMap(int mapId); void handleEventMapListContextMenuUnpinMap(int mapId);
World* getWorld() { return _map_creation_wizard->getWorld(); };
void loadMap (int map_id); void loadMap (int map_id);
@@ -98,8 +100,6 @@ namespace Noggit::Ui::Windows
void applyFilterSearch(const QString& name, int type, int expansion, bool wmo_maps); void applyFilterSearch(const QString& name, int type, int expansion, bool wmo_maps);
std::unique_ptr<World> _world;
bool map_loaded = false; bool map_loaded = false;
bool exit_to_project_selection = false; bool exit_to_project_selection = false;

View File

@@ -11,24 +11,19 @@ namespace Noggit::Ui::Widget
auto layout = QGridLayout(); auto layout = QGridLayout();
QIcon icon; QIcon icon;
if (_map_data.expansion_id == 0) switch (_map_data.expansion_id)
icon = QIcon(":/icon-classic"); {
if (_map_data.expansion_id == 1) case 0: icon = QIcon(":/icon-classic"); break;
icon = QIcon(":/icon-burning"); case 1: icon = QIcon(":/icon-burning"); break;
if (_map_data.expansion_id == 2) case 2: icon = QIcon(":/icon-wrath"); break;
icon = QIcon(":/icon-wrath"); case 3: icon = QIcon(":/icon-cata"); break;
if (_map_data.expansion_id == 3) case 4: icon = QIcon(":/icon-panda"); break;
icon = QIcon(":/icon-cata"); case 5: icon = QIcon(":/icon-warlords"); break;
if (_map_data.expansion_id == 4) case 6: icon = QIcon(":/icon-legion"); break;
icon = QIcon(":/icon-panda"); case 7: icon = QIcon(":/icon-battle"); break;
if (_map_data.expansion_id == 5) case 8: icon = QIcon(":/icon-shadow"); break;
icon = QIcon(":/icon-warlords"); default: break;
if (_map_data.expansion_id == 6) }
icon = QIcon(":/icon-legion");
if (_map_data.expansion_id == 7)
icon = QIcon(":/icon-battle");
if (_map_data.expansion_id == 8)
icon = QIcon(":/icon-shadow");
_map_icon = new QLabel("", parent); _map_icon = new QLabel("", parent);
_map_icon->setPixmap(icon.pixmap(QSize(32, 32))); _map_icon->setPixmap(icon.pixmap(QSize(32, 32)));
@@ -54,18 +49,16 @@ namespace Noggit::Ui::Widget
_map_id->setAutoFillBackground(true); _map_id->setAutoFillBackground(true);
auto instance_type = QString("Unknown"); auto instance_type = QString("Unknown");
if (_map_data.map_type_id == 0) switch (_map_data.map_type_id)
instance_type = QString("Continent"); {
if (_map_data.map_type_id == 1) case 0: instance_type = "Continent"; break;
instance_type = QString("Dungeon"); case 1: instance_type = "Dungeon"; break;
if (_map_data.map_type_id == 2) case 2: instance_type = "Raid"; break;
instance_type = QString("Raid"); case 3: instance_type = "Battleground"; break;
if (_map_data.map_type_id == 3) case 4: instance_type = "Arena"; break;
instance_type = QString("Battleground"); case 5: instance_type = "Scenario"; break;
if (_map_data.map_type_id == 4) default: instance_type = "Unknown"; break;
instance_type = QString("Arena"); }
if (_map_data.map_type_id == 5)
instance_type = QString("Scenario");
_map_instance_type = new QLabel(instance_type, this); _map_instance_type = new QLabel(instance_type, this);
_map_instance_type->setGeometry(150, 15, 125, 20); _map_instance_type->setGeometry(150, 15, 125, 20);