From e24c1c3bd0678219c4aa5a785b571784fb7a72cf Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Tue, 6 Aug 2024 04:36:38 +0200 Subject: [PATCH] - add a quick settings popup when creating zones - improve locales support - refactor dbc exceptions handling --- src/noggit/DBC.cpp | 34 +- src/noggit/DBCFile.h | 8 +- src/noggit/Sky.cpp | 262 +++---- src/noggit/rendering/WorldRender.cpp | 19 +- src/noggit/ui/GroundEffectsTool.cpp | 64 +- src/noggit/ui/ZoneIDBrowser.cpp | 641 +++++++++++------- src/noggit/ui/ZoneIDBrowser.h | 4 +- .../ui/tools/LightEditor/LightEditor.cpp | 54 +- .../Ui/MapCreationWizard.cpp | 55 +- .../EditorWindows/SoundEntryPickerWindow.cpp | 205 +++--- .../ZoneIntroMusicPickerWindow.cpp | 85 ++- .../EditorWindows/ZoneMusicPickerWindow.cpp | 124 ++-- .../windows/SoundPlayer/SoundEntryPlayer.cpp | 42 +- 13 files changed, 926 insertions(+), 671 deletions(-) diff --git a/src/noggit/DBC.cpp b/src/noggit/DBC.cpp index 6e1e961f..de2ad1e6 100755 --- a/src/noggit/DBC.cpp +++ b/src/noggit/DBC.cpp @@ -226,11 +226,25 @@ std::string WMOAreaTableDB::getWMOAreaName(int WMOId, int namesetId) int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId); if (areatableid) { - auto rec = gAreaDB.getByID(areatableid); - return rec.getLocalizedString(AreaDB::Name); + // return AreaDB::getAreaFullName(areatableid); // full name with zone + std::string arena_name = ""; + try + { + auto rec = gAreaDB.getByID(areatableid); + arena_name = rec.getLocalizedString(AreaDB::Name); + } + catch (WMOAreaTableDB::NotFound) + { + arena_name = "Unknown location"; + } + return areaName; } else - return "-Local Terrain Area-"; // nullptr? need to get it from terrain + { + // if no areaId is set in the WMOAreaTableDB record, client uses the local terrain area id. + return "-Local Terrain Area-"; + } + } } } @@ -260,14 +274,22 @@ std::vector WMOAreaTableDB::getWMOAreaNames(int WMOId) int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId); if (areatableid) { - auto rec = gAreaDB.getByID(areatableid); - areanamesvect.push_back(rec.getLocalizedString(AreaDB::Name)); + try + { + auto rec = gAreaDB.getByID(areatableid); + areanamesvect.push_back(rec.getLocalizedString(AreaDB::Name)); + } + catch (WMOAreaTableDB::NotFound) + { + areanamesvect.push_back("Unknown location"); + } + } else areanamesvect.push_back("-Local Terrain Area-"); // nullptr? need to get it from terrain } } - // could optimise and break when iterator WmoId is higher than the Wmodid, but this wouldn't support unordered DBCs. + // could optimise and break when iterator WmoId is higher than the Wmodid, but this wouldn't support unordered DBCs. Client does this. } return areanamesvect; } diff --git a/src/noggit/DBCFile.h b/src/noggit/DBCFile.h index f40ab25a..bc66c647 100755 --- a/src/noggit/DBCFile.h +++ b/src/noggit/DBCFile.h @@ -110,6 +110,7 @@ public: void writeLocalizedString(size_t field, const std::string& val, int locale) { assert(field < file.fieldCount); + assert(locale < 16); if (!val.size()) { @@ -181,9 +182,8 @@ public: if (i->getUInt(field) == id) return (*i); } - - LogError << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl; - return *begin(); // return the first entry if it failed + LogDebug << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl; + throw NotFound(); } inline bool CheckIfIdExists(unsigned int id, size_t field = 0) { @@ -205,7 +205,7 @@ public: row_id++; } LogError << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl; - return 0; + throw NotFound(); } Record addRecord(size_t id, size_t id_field = 0); diff --git a/src/noggit/Sky.cpp b/src/noggit/Sky.cpp index 67b00d0b..f892b681 100755 --- a/src/noggit/Sky.cpp +++ b/src/noggit/Sky.cpp @@ -1043,137 +1043,155 @@ void Sky::save_to_dbc() { // Save Light.dbc record // find new empty ID : gLightDB.getEmptyRecordID(); .prob do it when creating new light instead. - DBCFile::Record data = is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); - - // pos = glm::vec3(data->getFloat(LightDB::PositionX) / skymul, data->getFloat(LightDB::PositionY) / skymul, data->getFloat(LightDB::PositionZ) / skymul); - // record.write(1, _curr_sky-> map id - data.write(LightDB::PositionX, pos.x * skymul); - data.write(LightDB::PositionY, pos.y * skymul); - data.write(LightDB::PositionZ, pos.z * skymul); - data.write(LightDB::RadiusInner, r1 * skymul); - data.write(LightDB::RadiusOuter,r2 * skymul); - // data.write(7, Params Id TODO only needed for new entries - - // save LightParams.dbc - // TODO : all params, not just clear. - for (int param_id = 0; param_id < NUM_SkyFloatParamsNames; param_id++) + try { - // skip if no param - if (skyParams[param_id] == nullptr) - continue; + DBCFile::Record data = is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); - // TODO : several lights can use the same param, ask user if he wants to save a copy or edit it for all ? - int lightParam_dbc_id = 0; - if (is_new_record) // not for duplicates - lightParam_dbc_id = gLightParamsDB.getEmptyRecordID(); - else - lightParam_dbc_id = data.getInt(LightDB::DataIDs + param_id); + // pos = glm::vec3(data->getFloat(LightDB::PositionX) / skymul, data->getFloat(LightDB::PositionY) / skymul, data->getFloat(LightDB::PositionZ) / skymul); + // record.write(1, _curr_sky-> map id + data.write(LightDB::PositionX, pos.x * skymul); + data.write(LightDB::PositionY, pos.y * skymul); + data.write(LightDB::PositionZ, pos.z * skymul); + data.write(LightDB::RadiusInner, r1 * skymul); + data.write(LightDB::RadiusOuter,r2 * skymul); + // data.write(7, Params Id TODO only needed for new entries - if (lightParam_dbc_id == 0) - continue; - - int light_int_start = lightParam_dbc_id * NUM_SkyColorNames - 17; - - for (int i = 0; i < NUM_SkyColorNames; ++i) + // save LightParams.dbc + // TODO : all params, not just clear. + for (int param_id = 0; param_id < NUM_SkyFloatParamsNames; param_id++) { - try - { - DBCFile::Record rec = is_new_record ? gLightIntBandDB.addRecord(light_int_start + i) : gLightIntBandDB.getByID(light_int_start + i); - // int entries = rec.getInt(LightIntBandDB::Entries); - int entries = static_cast(skyParams[param_id]->colorRows[i].size()); + // skip if no param + if (skyParams[param_id] == nullptr) + continue; - rec.write(LightIntBandDB::Entries, entries); // nb of entries - - for (int l = 0; l < 16; l++) - { - if (l >= entries) - { - rec.write(LightIntBandDB::Times + l, 0); - rec.write(LightIntBandDB::Values + l, 0); - } - else - { - rec.write(LightIntBandDB::Times + l, skyParams[param_id]->colorRows[i][l].time); - - int rebuilt_color_int = static_cast(skyParams[param_id]->colorRows[i][l].color.z * 255.0f) - + (static_cast(skyParams[param_id]->colorRows[i][l].color.y * 255.0f) << 8) - + (static_cast(skyParams[param_id]->colorRows[i][l].color.x * 255.0f) << 16); - rec.write(LightIntBandDB::Values + l, rebuilt_color_int); - } - } - } - catch (...) - { - LogError << "When trying to intialize sky " << data.getInt(LightDB::ID) << ", there was an error with getting an entry in gLightIntBand (" << i << "). Sorry." << std::endl; - } - } - - int light_float_start = lightParam_dbc_id * NUM_SkyFloatParamsNames - 5; - - for (int i = 0; i < NUM_SkyFloatParamsNames; ++i) - { - try - { - DBCFile::Record rec = is_new_record ? gLightFloatBandDB.addRecord(light_float_start + i) : gLightFloatBandDB.getByID(light_float_start + i); - int entries = static_cast(skyParams[param_id]->floatParams[i].size()); - - rec.write(LightFloatBandDB::Entries, entries); // nb of entries - - // for (int l = 0; l < entries; l++) - for (int l = 0; l < 16; l++) - { - if (l >= entries) - { - rec.write(LightFloatBandDB::Times + l, 0); - rec.write(LightFloatBandDB::Values + l, 0.0f); - } - else - { - rec.write(LightFloatBandDB::Times + l, skyParams[param_id]->floatParams[i][l].time); - rec.write(LightFloatBandDB::Values + l, skyParams[param_id]->floatParams[i][l].value); - } - } - } - catch (...) - { - LogError << "When trying to intialize sky " << data.getInt(LightDB::ID) << ", there was an error with getting an entry in LightFloatBand (" << i << "). Sorry." << std::endl; - } - } - - try - { - DBCFile::Record light_param = gLightParamsDB.getByID(lightParam_dbc_id); - - if (skybox.has_value()) // TODO skybox dbc - { - // light_param.write(LightParamsDB::skybox, TODO); - } + // TODO : several lights can use the same param, ask user if he wants to save a copy or edit it for all ? + int lightParam_dbc_id = 0; + if (is_new_record) // not for duplicates + lightParam_dbc_id = gLightParamsDB.getEmptyRecordID(); else - light_param.write(LightParamsDB::skybox, 0); + lightParam_dbc_id = data.getInt(LightDB::DataIDs + param_id); - light_param.write(LightParamsDB::highlightSky, int(skyParams[param_id]->highlight_sky())); - light_param.write(LightParamsDB::water_shallow_alpha, skyParams[param_id]->river_shallow_alpha()); - light_param.write(LightParamsDB::water_deep_alpha, skyParams[param_id]->river_deep_alpha()); - light_param.write(LightParamsDB::ocean_shallow_alpha, skyParams[param_id]->ocean_shallow_alpha()); - light_param.write(LightParamsDB::ocean_deep_alpha, skyParams[param_id]->ocean_deep_alpha()); - light_param.write(LightParamsDB::glow, skyParams[param_id]->glow()); - } - catch (...) - { - LogError << "When trying to get the skybox for the entry " << lightParam_dbc_id << " in LightParams.dbc. Sad." << std::endl; + if (lightParam_dbc_id == 0) + continue; + + int light_int_start = lightParam_dbc_id * NUM_SkyColorNames - 17; + + for (int i = 0; i < NUM_SkyColorNames; ++i) + { + try + { + DBCFile::Record rec = is_new_record ? gLightIntBandDB.addRecord(light_int_start + i) : gLightIntBandDB.getByID(light_int_start + i); + // int entries = rec.getInt(LightIntBandDB::Entries); + int entries = static_cast(skyParams[param_id]->colorRows[i].size()); + + rec.write(LightIntBandDB::Entries, entries); // nb of entries + + for (int l = 0; l < 16; l++) + { + if (l >= entries) + { + rec.write(LightIntBandDB::Times + l, 0); + rec.write(LightIntBandDB::Values + l, 0); + } + else + { + rec.write(LightIntBandDB::Times + l, skyParams[param_id]->colorRows[i][l].time); + + int rebuilt_color_int = static_cast(skyParams[param_id]->colorRows[i][l].color.z * 255.0f) + + (static_cast(skyParams[param_id]->colorRows[i][l].color.y * 255.0f) << 8) + + (static_cast(skyParams[param_id]->colorRows[i][l].color.x * 255.0f) << 16); + rec.write(LightIntBandDB::Values + l, rebuilt_color_int); + } + } + } + catch (...) + { + assert(false); + LogError << "When trying to save sky colors, sky id : " << data.getInt(LightDB::ID) << std::endl; + } + } + + int light_float_start = lightParam_dbc_id * NUM_SkyFloatParamsNames - 5; + + for (int i = 0; i < NUM_SkyFloatParamsNames; ++i) + { + try + { + DBCFile::Record rec = is_new_record ? gLightFloatBandDB.addRecord(light_float_start + i) : gLightFloatBandDB.getByID(light_float_start + i); + int entries = static_cast(skyParams[param_id]->floatParams[i].size()); + + rec.write(LightFloatBandDB::Entries, entries); // nb of entries + + // for (int l = 0; l < entries; l++) + for (int l = 0; l < 16; l++) + { + if (l >= entries) + { + rec.write(LightFloatBandDB::Times + l, 0); + rec.write(LightFloatBandDB::Values + l, 0.0f); + } + else + { + rec.write(LightFloatBandDB::Times + l, skyParams[param_id]->floatParams[i][l].time); + rec.write(LightFloatBandDB::Values + l, skyParams[param_id]->floatParams[i][l].value); + } + } + } + catch (...) + { + LogError << "Error when trying to save sky float params, sky id : " << data.getInt(LightDB::ID) << std::endl; + } + } + + try + { + DBCFile::Record light_param = gLightParamsDB.getByID(lightParam_dbc_id); + + if (skybox.has_value()) // TODO skybox dbc + { + // light_param.write(LightParamsDB::skybox, TODO); + } + else + light_param.write(LightParamsDB::skybox, 0); + + light_param.write(LightParamsDB::highlightSky, int(skyParams[param_id]->highlight_sky())); + light_param.write(LightParamsDB::water_shallow_alpha, skyParams[param_id]->river_shallow_alpha()); + light_param.write(LightParamsDB::water_deep_alpha, skyParams[param_id]->river_deep_alpha()); + light_param.write(LightParamsDB::ocean_shallow_alpha, skyParams[param_id]->ocean_shallow_alpha()); + light_param.write(LightParamsDB::ocean_deep_alpha, skyParams[param_id]->ocean_deep_alpha()); + light_param.write(LightParamsDB::glow, skyParams[param_id]->glow()); + } + catch (DBCFile::NotFound) + { + assert(false); + LogError << "When trying to get the lightparams for the entry " << lightParam_dbc_id << " in LightParams.dbc" << std::endl; + } } + gLightDB.save(); + gLightIntBandDB.save(); + gLightFloatBandDB.save(); + gLightParamsDB.save(); + gLightSkyboxDB.save(); + + // emit map_dbc_updated(); + + is_new_record = false; + } + catch (DBCFile::AlreadyExists) + { + LogError << "DBCFile::AlreadyExists When trying to add light.dbc record for the entry " << Id << std::endl; + assert(false); + } + catch (DBCFile::NotFound) + { + LogError << "DBCFile::NotFound When trying to add light.dbc record for the entry " << Id << std::endl; + assert(false); + } + catch (...) + { + LogError << "Unknown exception When trying to add light.dbc record for the entry " << Id << std::endl; + assert(false); } - gLightDB.save(); - gLightIntBandDB.save(); - gLightFloatBandDB.save(); - gLightParamsDB.save(); - gLightSkyboxDB.save(); - - // emit map_dbc_updated(); - - is_new_record = false; - - } \ No newline at end of file diff --git a/src/noggit/rendering/WorldRender.cpp b/src/noggit/rendering/WorldRender.cpp index 1fa2f8e8..f83f93e0 100755 --- a/src/noggit/rendering/WorldRender.cpp +++ b/src/noggit/rendering/WorldRender.cpp @@ -1820,12 +1820,19 @@ bool WorldRender::saveMinimap(TileIndex const& tile_idx, MinimapRenderSettings* } // Register in md5translate.trs - std::string map_name = gMapDB.getByID(_world->mapIndex._map_id).getString(MapDB::InternalName); - - auto sstream = std::stringstream(); - sstream << map_name << "\\map" << tile_idx.x << "_" << std::setfill('0') << std::setw(2) << tile_idx.z << ".blp"; - std::string tilename_left = sstream.str(); - _world->mapIndex._minimap_md5translate[map_name][tilename_left] = tex_name; + try + { + std::string map_name = gMapDB.getByID(_world->mapIndex._map_id).getString(MapDB::InternalName); + auto sstream = std::stringstream(); + sstream << map_name << "\\map" << tile_idx.x << "_" << std::setfill('0') << std::setw(2) << tile_idx.z << ".blp"; + std::string tilename_left = sstream.str(); + _world->mapIndex._minimap_md5translate[map_name][tilename_left] = tex_name; + } + catch(MapDB::NotFound) + { + LogError << "SaveMinimap : Couldn't find entry " << _world->mapIndex._map_id << std::endl; + assert(false); + } if (unload) { diff --git a/src/noggit/ui/GroundEffectsTool.cpp b/src/noggit/ui/GroundEffectsTool.cpp index 18309827..95839f76 100644 --- a/src/noggit/ui/GroundEffectsTool.cpp +++ b/src/noggit/ui/GroundEffectsTool.cpp @@ -740,42 +740,46 @@ namespace Noggit return; } - DBCFile::Record GErecord - { - gGroundEffectTextureDB.getByID(effect_id) - }; - - Name = std::to_string(effect_id); - - ID = GErecord.getUInt(GroundEffectTextureDB::ID); - Amount = GErecord.getUInt(GroundEffectTextureDB::Amount); - TerrainType = GErecord.getUInt(GroundEffectTextureDB::TerrainType); - - for (int i = 0; i < 4; ++i) + try { - Weights[i] = GErecord.getUInt(GroundEffectTextureDB::Weights + i); - unsigned const curDoodadId - { - GErecord.getUInt(GroundEffectTextureDB::Doodads + i) - }; + DBCFile::Record GErecord = gGroundEffectTextureDB.getByID(effect_id); + Name = std::to_string(effect_id); + ID = GErecord.getUInt(GroundEffectTextureDB::ID); + Amount = GErecord.getUInt(GroundEffectTextureDB::Amount); + TerrainType = GErecord.getUInt(GroundEffectTextureDB::TerrainType); - if (!curDoodadId) + for (int i = 0; i < 4; ++i) { - continue; - } - - if (!gGroundEffectDoodadDB.CheckIfIdExists(curDoodadId)) - { - continue; - } + Weights[i] = GErecord.getUInt(GroundEffectTextureDB::Weights + i); + unsigned const curDoodadId + { + GErecord.getUInt(GroundEffectTextureDB::Doodads + i) + }; + + if (!curDoodadId) + { + continue; + } - Doodads[i].ID = curDoodadId; - QString filename = gGroundEffectDoodadDB.getByID(curDoodadId).getString(GroundEffectDoodadDB::Filename); + if (!gGroundEffectDoodadDB.CheckIfIdExists(curDoodadId)) + { + continue; + } + + Doodads[i].ID = curDoodadId; + QString filename = gGroundEffectDoodadDB.getByID(curDoodadId).getString(GroundEffectDoodadDB::Filename); - filename.replace(".mdx", ".m2", Qt::CaseInsensitive); - filename.replace(".mdl", ".m2", Qt::CaseInsensitive); + filename.replace(".mdx", ".m2", Qt::CaseInsensitive); + filename.replace(".mdl", ".m2", Qt::CaseInsensitive); - Doodads[i].filename = filename.toStdString(); + Doodads[i].filename = filename.toStdString(); + } + } + catch (GroundEffectTextureDB::NotFound) + { + ID = 0; + assert(false); + LogError << "Couldn't find ground effect Id : " << effect_id << "in GroundEffectTexture.dbc" << std::endl; } } } diff --git a/src/noggit/ui/ZoneIDBrowser.cpp b/src/noggit/ui/ZoneIDBrowser.cpp index 46381a35..860a70fa 100755 --- a/src/noggit/ui/ZoneIDBrowser.cpp +++ b/src/noggit/ui/ZoneIDBrowser.cpp @@ -267,29 +267,75 @@ namespace Noggit void zone_id_browser::add_new_zone() { // create new zone area id - auto new_id = gAreaDB.getEmptyRecordID(); - auto new_record = gAreaDB.addRecord(new_id); - // init some defaults - new_record.write(AreaDB::Continent, mapID); - // get new areabit - new_record.write(AreaDB::AreaBit, gAreaDB.get_new_areabit()); - new_record.write(AreaDB::Flags, 64); // allow dueling, seems to the be the common default for regions - new_record.write(AreaDB::UnderwaterSoundProviderPreferences, 11); // underwater sound pref, usually set + int new_id = gAreaDB.getEmptyRecordID(); - // locale stuff - new_record.writeString(AreaDB::Name, "Unnamed Noggit Zone"); // only write default name for enUS and enGB ? maybe get the client's locale somehow - new_record.writeString(AreaDB::Name + 1, "Unnamed Noggit Zone"); // enGB - new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS + QDialog* zone_create_params = new QDialog(this); + zone_create_params->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + zone_create_params->setWindowTitle("New Zone settings"); + QVBoxLayout* zone_create_params_layout = new QVBoxLayout(zone_create_params); - new_record.write(AreaDB::MinElevation, -500.0f); // loc mask, only verified for enUS - // save dbc instantly ? - gAreaDB.save(); - // add to tree - auto areawidgetitem = add_area(new_id); - // select the new item - _area_tree->clearSelection(); - areawidgetitem->setSelected(true); - open_area_editor();// open the editor + zone_create_params_layout->addWidget(new QLabel("AreaTable Id : ", zone_create_params)); + QSpinBox* params_id_spinbox = new QSpinBox(zone_create_params); + params_id_spinbox->setRange(1, std::numeric_limits::max()); + params_id_spinbox->setValue(new_id); + zone_create_params_layout->addWidget(params_id_spinbox); + + zone_create_params_layout->addWidget(new QLabel("Zone Name : ", zone_create_params)); + QLineEdit* params_name_ledit = new QLineEdit(zone_create_params); + params_name_ledit->setText("Unnamed Noggit Zone"); + zone_create_params_layout->addWidget(params_name_ledit); + + QPushButton* params_okay = new QPushButton("Create new Zone", zone_create_params); + zone_create_params_layout->addWidget(params_okay); + + connect(params_okay, &QPushButton::clicked + , [=]() + { + // check if ID is valid + if (!gAreaDB.CheckIfIdExists(params_id_spinbox->value())) + { + zone_create_params->accept(); + } + else + { + QMessageBox::warning + (nullptr + , "ID already in use" + , "Id is already used, use a different one" + , QMessageBox::Ok + ); + } + }); + + // start popup and wait for ok button + if (zone_create_params->exec() == QDialog::Accepted) + { + auto new_record = gAreaDB.addRecord(params_id_spinbox->value()); // could add a try catch but we already check if id is used before + // init some defaults + new_record.write(AreaDB::Continent, mapID); + // get new areabit + new_record.write(AreaDB::AreaBit, gAreaDB.get_new_areabit()); + unsigned int flags = 0; + flags |= (1 << 6); // Allow Dueling + new_record.write(AreaDB::Flags, flags); + new_record.write(AreaDB::UnderwaterSoundProviderPreferences, 11); // underwater sound pref, usually set + + // locale stuff + // new_record.writeString(AreaDB::Name, params_name_ledit->text().toStdString()); // only write default name for enUS and enGB ? maybe get the client's locale somehow + int locale_id = Noggit::Application::NoggitApplication::instance()->clientData()->getLocaleId(); + new_record.writeLocalizedString(AreaDB::Name, params_name_ledit->text().toStdString(), locale_id); + new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS + + new_record.write(AreaDB::MinElevation, -500.0f); + // save dbc instantly ? + gAreaDB.save(); + // add to tree + auto areawidgetitem = add_area(new_id); + // select the new item + _area_tree->clearSelection(); + areawidgetitem->setSelected(true); + open_area_editor();// open the editor + } } void zone_id_browser::add_new_subzone() @@ -303,43 +349,92 @@ namespace Noggit std::uint32_t selected_parent_area_id = gAreaDB.get_area_parent(selected_areaid); // the selected area's parentid if (selected_parent_area_id) { - // error, parent must not have a parent - QMessageBox messagebox; - messagebox.setIcon(QMessageBox::Information); - messagebox.setWindowIcon(QIcon(":/icon")); - messagebox.setWindowTitle("Wrong Parent type"); - messagebox.setText("The parent must be a Zone, not a Subzone."); - messagebox.exec(); + QMessageBox::information + (nullptr + , "Wrong Parent type" + , "The parent must be a Zone, not a Subzone." + , QMessageBox::Ok + ); return; } - auto new_id = gAreaDB.getEmptyRecordID(); - auto new_record = gAreaDB.addRecord(new_id); - // init some defaults - new_record.write(AreaDB::Continent, mapID); + int new_id = gAreaDB.getEmptyRecordID(); - new_record.write(AreaDB::Region, selected_areaid); // set selecetd area as parent. - // get new areabit - new_record.write(AreaDB::AreaBit, gAreaDB.get_new_areabit()); - new_record.write(AreaDB::Flags, 1073759296); // allow dueling + force area on dynamic transport + enable flight bounds+ subzone flags - new_record.write(AreaDB::UnderwaterSoundProviderPreferences, 11); // underwater sound pref, usually set - // lcoale stuff - new_record.writeString(AreaDB::Name, "Unnamed Noggit Subzone"); // only write default name for enUS and enGB ? maybe get the client's locale somehow - new_record.writeString(AreaDB::Name + 1, "Unnamed Noggit Subzone"); // enGB - new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS + QDialog* zone_create_params = new QDialog(this); + zone_create_params->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + zone_create_params->setWindowTitle("New Zone settings"); + QVBoxLayout* zone_create_params_layout = new QVBoxLayout(zone_create_params); + + zone_create_params_layout->addWidget(new QLabel("AreaTable Id : ", zone_create_params)); + QSpinBox* params_id_spinbox = new QSpinBox(zone_create_params); + params_id_spinbox->setRange(1, std::numeric_limits::max()); + params_id_spinbox->setValue(new_id); + zone_create_params_layout->addWidget(params_id_spinbox); + + zone_create_params_layout->addWidget(new QLabel("Zone Name : ", zone_create_params)); + QLineEdit* params_name_ledit = new QLineEdit(zone_create_params); + params_name_ledit->setText("Unnamed Noggit Zone"); + zone_create_params_layout->addWidget(params_name_ledit); + + QPushButton* params_okay = new QPushButton("Create new Zone", zone_create_params); + zone_create_params_layout->addWidget(params_okay); + + connect(params_okay, &QPushButton::clicked + , [=]() + { + // check if ID is valid + int id = params_id_spinbox->value(); + bool exists = gAreaDB.CheckIfIdExists(params_id_spinbox->value()); + if (exists) + { + QMessageBox::warning + (nullptr + , "ID already in use" + , "Id is already used, use a different one" + , QMessageBox::Ok + ); + } + else + { + zone_create_params->accept(); + } + }); + + // start popup and wait for ok button + if (zone_create_params->exec() == QDialog::Accepted) + { + auto new_record = gAreaDB.addRecord(params_id_spinbox->value()); + // init some defaults + new_record.write(AreaDB::Continent, mapID); + + new_record.write(AreaDB::Region, selected_areaid); // set selecetd area as parent. + // get new areabit + new_record.write(AreaDB::AreaBit, gAreaDB.get_new_areabit()); + unsigned int flags = 0; + flags |= (1 << 6); // Allow Dueling + flags |= (1 << 10); // force area on dynamic transport + flags |= (1 << 14); // enable flight bounds + flags |= (1 << 30); // subzone flag + new_record.write(AreaDB::Flags, flags); // allow dueling + force area on dynamic transport + enable flight bounds+ subzone flags + new_record.write(AreaDB::UnderwaterSoundProviderPreferences, 11); // underwater sound pref, usually set + // lcoale stuff + int locale_id = Noggit::Application::NoggitApplication::instance()->clientData()->getLocaleId(); + new_record.writeLocalizedString(AreaDB::Name, params_name_ledit->text().toStdString(), locale_id); + new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS + + new_record.write(AreaDB::MinElevation, -500.0f); // loc mask, only verified for enUS + // save dbc instantly ? + gAreaDB.save(); + // add to tree + auto areawidgetitem = add_area(new_id); + // select the new item + _area_tree->clearSelection(); + areawidgetitem->setSelected(true); + open_area_editor();// open the editor + } - new_record.write(AreaDB::MinElevation, -500.0f); // loc mask, only verified for enUS - // save dbc instantly ? - gAreaDB.save(); - // add to tree - auto areawidgetitem = add_area(new_id); - // select the new item - _area_tree->clearSelection(); - areawidgetitem->setSelected(true); - open_area_editor();// open the editor } - AreaEditor::AreaEditor(QWidget* parent) : QWidget(parent) { @@ -490,7 +585,8 @@ namespace Noggit auto flags_layout = new QVBoxLayout(area_flags_group); _flags_value_spinbox = new QSpinBox(this); - _flags_value_spinbox->setRange(0, INT_MAX); // uint? + _flags_value_spinbox->setRange(0, INT_MAX); // uint not necessary for wrath because we only have 31 flags. + // for cata+ we'll need all 32 bits instead, might need a line edit flags_layout->addWidget(_flags_value_spinbox); // TODO : update checkboxes when value is changed, temporarly disable it from edit @@ -508,16 +604,15 @@ namespace Noggit // int old_value = _flags_value_spinbox->value(); int new_value = _flags_value_spinbox->value(); if (state) // set bit - new_value |= (1ULL << (i)); + new_value |= (1U << (i)); else // remove bit - new_value &= ~(1ULL << (i)); + new_value &= ~(1U << (i)); _flags_value_spinbox->setValue(new_value); }); } // hide some useless flags to gain space flags_checkboxes[30]->setEnabled(false); // user can't set subzone flag. - flags_checkboxes[30]->setHidden(true); // subzone flag flags_checkboxes[20]->setHidden(true); // tournement realm thingy, useless for pservers flags_checkboxes[17]->setHidden(true); // "Area not in use", prob some blizz dev stuff //************************************// @@ -580,13 +675,21 @@ namespace Noggit _parent_area_label->setText(ss.str().c_str()); // _parent_area_label->setText(std::to_string( tree_selected_id).c_str()); - auto curr_record = gAreaDB.getByID(_area_id_label->text().toInt()); - curr_record.write(AreaDB::Region, tree_selected_id); - // update the tree - parent->buildAreaList(); - // select the item ? - auto item = parent->create_or_get_tree_widget_item(_area_id_label->text().toInt()); - // parent->selected(_area_id_label->text().toInt()); + try + { + auto curr_record = gAreaDB.getByID(_area_id_label->text().toInt()); + curr_record.write(AreaDB::Region, tree_selected_id); + // update the tree + parent->buildAreaList(); + // select the item ? + auto item = parent->create_or_get_tree_widget_item(_area_id_label->text().toInt()); + // parent->selected(_area_id_label->text().toInt()); + } + catch (AreaDB::NotFound) + { + + } + }); connect(save_area_button, &QPushButton::clicked, [=]() { @@ -604,241 +707,253 @@ namespace Noggit void AreaEditor::load_area(int area_id) { - DBCFile::Record record = gAreaDB.getByID(area_id); - // record.getString(AreaDB::Name) - - _area_id_label->setText(QString(std::to_string(area_id).c_str())); - - _areabit = record.getInt(AreaDB::AreaBit); - - _parent_area_id = record.getInt(AreaDB::Region); - - if (_parent_area_id) + try { - std::stringstream ss; - ss << _parent_area_id << "-" << gAreaDB.getAreaFullName(_parent_area_id); - _parent_area_label->setText(ss.str().c_str()); - } - else - _parent_area_label->setText("-NONE-"); + DBCFile::Record record = gAreaDB.getByID(area_id); - // hide some UI if not subzone - _set_parent_button->setHidden(_parent_area_id ? false : true); + _area_id_label->setText(QString(std::to_string(area_id).c_str())); - // _area_name_ledit->setText(record.getString(AreaDB::Name)); - _area_name->fill(record, AreaDB::Name); + _areabit = record.getInt(AreaDB::AreaBit); - _flags_value_spinbox->setValue(record.getInt(AreaDB::Flags)); + _parent_area_id = record.getInt(AreaDB::Region); - std::bitset<32> IntBits(_flags_value_spinbox->value()); - for (int i = 0; i < 31; i++) - flags_checkboxes[i]->setChecked(IntBits[i]); + if (_parent_area_id) + { + std::stringstream ss; + ss << _parent_area_id << "-" << gAreaDB.getAreaFullName(_parent_area_id); + _parent_area_label->setText(ss.str().c_str()); + } + else + _parent_area_label->setText("-NONE-"); - _exploration_level_spinbox->setValue(record.getInt(AreaDB::ExplorationLevel)); + // hide some UI if not subzone + _set_parent_button->setHidden(_parent_area_id ? false : true); - int faction_group_mask = record.getInt(AreaDB::FactionGroup); - switch (faction_group_mask) // hardcoded but can be read from factiongroup.dbc - { - case 2: - _faction_group_combobox->setCurrentIndex(1); - break; - case 4: - _faction_group_combobox->setCurrentIndex(2); + // _area_name_ledit->setText(record.getString(AreaDB::Name)); + _area_name->fill(record, AreaDB::Name); + + _flags_value_spinbox->setValue(record.getInt(AreaDB::Flags)); + + std::bitset<32> IntBits(_flags_value_spinbox->value()); + for (int i = 0; i < 31; i++) + flags_checkboxes[i]->setChecked(IntBits[i]); + + _exploration_level_spinbox->setValue(record.getInt(AreaDB::ExplorationLevel)); + + int faction_group_mask = record.getInt(AreaDB::FactionGroup); + switch (faction_group_mask) // hardcoded but can be read from factiongroup.dbc + { + case 2: + _faction_group_combobox->setCurrentIndex(1); break; - case 6: - _faction_group_combobox->setCurrentIndex(3); - break; - default: - _faction_group_combobox->setCurrentIndex(0); - } + case 4: + _faction_group_combobox->setCurrentIndex(2); + break; + case 6: + _faction_group_combobox->setCurrentIndex(3); + break; + default: + _faction_group_combobox->setCurrentIndex(0); + } - _min_elevation_spinbox->setValue(record.getFloat(AreaDB::MinElevation)); // only 3 known values : -5000, -500, 1000 + _min_elevation_spinbox->setValue(record.getFloat(AreaDB::MinElevation)); // only 3 known values : -5000, -500, 1000 - _ambiant_multiplier->setValue(record.getFloat(AreaDB::AmbientMultiplier) * 100); + _ambiant_multiplier->setValue(record.getFloat(AreaDB::AmbientMultiplier) * 100); - int sound_provider_id = record.getInt(AreaDB::SoundProviderPreferences); - if (sound_provider_id != 0 && gSoundProviderPreferencesDB.CheckIfIdExists(sound_provider_id)) - { - int row_id = gSoundProviderPreferencesDB.getRecordRowId(sound_provider_id); - _sound_provider_preferences_cbbox->setCurrentIndex(row_id + 1); // index 0 = "None" - } - else - _sound_provider_preferences_cbbox->setCurrentIndex(0); - - int underwater_sound_provider_id = record.getInt(AreaDB::UnderwaterSoundProviderPreferences); - if (underwater_sound_provider_id != 0 && gSoundProviderPreferencesDB.CheckIfIdExists(underwater_sound_provider_id)) - { - int row_id = gSoundProviderPreferencesDB.getRecordRowId(underwater_sound_provider_id); - _underwater_sound_provider_preferences_cbbox->setCurrentIndex(row_id + 1); // index 0 = "None" - } - else - _underwater_sound_provider_preferences_cbbox->setCurrentIndex(0); - - int zone_music_id = record.getInt(AreaDB::ZoneMusic); - if (zone_music_id != 0 && gZoneMusicDB.CheckIfIdExists(zone_music_id)) - { - _zone_music_button->setProperty("id", zone_music_id); - auto zone_music_record = gZoneMusicDB.getByID(zone_music_id); - std::stringstream ss; - ss << zone_music_id << "-" << zone_music_record.getString(ZoneMusicDB::Name); - _zone_music_button->setText(ss.str().c_str()); - } - else - { - _zone_music_button->setText("-NONE-"); - _zone_music_button->setProperty("id", 0); - } - - int zone_intro_music_id = record.getInt(AreaDB::ZoneIntroMusicTable); - if (zone_intro_music_id != 0 && gZoneIntroMusicTableDB.CheckIfIdExists(zone_intro_music_id)) - { - _zone_intro_music_button->setProperty("id", zone_intro_music_id); - auto zone_intro_music_record = gZoneIntroMusicTableDB.getByID(zone_intro_music_id); - std::stringstream ss; - ss << zone_intro_music_id << "-" << zone_intro_music_record.getString(ZoneIntroMusicTableDB::Name); - _zone_intro_music_button->setText(ss.str().c_str()); - } - else - { - _zone_intro_music_button->setProperty("id", 0); - _zone_intro_music_button->setText("-NONE-"); - } - - int sound_ambiance_id = record.getInt(AreaDB::SoundAmbience); - if (sound_ambiance_id != 0 && gSoundAmbienceDB.CheckIfIdExists(sound_ambiance_id)) - { - auto sound_ambiance_record = gSoundAmbienceDB.getByID(sound_ambiance_id); - - int day_sound_id = sound_ambiance_record.getInt(SoundAmbienceDB::SoundEntry_day); - if (day_sound_id != 0 && gSoundEntriesDB.CheckIfIdExists(day_sound_id)) + int sound_provider_id = record.getInt(AreaDB::SoundProviderPreferences); + if (sound_provider_id != 0 && gSoundProviderPreferencesDB.CheckIfIdExists(sound_provider_id)) { - auto sound_entry_day_record = gSoundEntriesDB.getByID(day_sound_id); - std::stringstream ss_day; - ss_day << day_sound_id << "-" << sound_entry_day_record.getString(SoundEntriesDB::Name); - _sound_ambiance_day_button->setText(ss_day.str().c_str()); - _sound_ambiance_day_button->setProperty("id", day_sound_id); + int row_id = gSoundProviderPreferencesDB.getRecordRowId(sound_provider_id); + _sound_provider_preferences_cbbox->setCurrentIndex(row_id + 1); // index 0 = "None" + } + else + _sound_provider_preferences_cbbox->setCurrentIndex(0); + + int underwater_sound_provider_id = record.getInt(AreaDB::UnderwaterSoundProviderPreferences); + if (underwater_sound_provider_id != 0 && gSoundProviderPreferencesDB.CheckIfIdExists(underwater_sound_provider_id)) + { + int row_id = gSoundProviderPreferencesDB.getRecordRowId(underwater_sound_provider_id); + _underwater_sound_provider_preferences_cbbox->setCurrentIndex(row_id + 1); // index 0 = "None" + } + else + _underwater_sound_provider_preferences_cbbox->setCurrentIndex(0); + + int zone_music_id = record.getInt(AreaDB::ZoneMusic); + if (zone_music_id != 0 && gZoneMusicDB.CheckIfIdExists(zone_music_id)) + { + _zone_music_button->setProperty("id", zone_music_id); + auto zone_music_record = gZoneMusicDB.getByID(zone_music_id); + std::stringstream ss; + ss << zone_music_id << "-" << zone_music_record.getString(ZoneMusicDB::Name); + _zone_music_button->setText(ss.str().c_str()); + } + else + { + _zone_music_button->setText("-NONE-"); + _zone_music_button->setProperty("id", 0); + } + + int zone_intro_music_id = record.getInt(AreaDB::ZoneIntroMusicTable); + if (zone_intro_music_id != 0 && gZoneIntroMusicTableDB.CheckIfIdExists(zone_intro_music_id)) + { + _zone_intro_music_button->setProperty("id", zone_intro_music_id); + auto zone_intro_music_record = gZoneIntroMusicTableDB.getByID(zone_intro_music_id); + std::stringstream ss; + ss << zone_intro_music_id << "-" << zone_intro_music_record.getString(ZoneIntroMusicTableDB::Name); + _zone_intro_music_button->setText(ss.str().c_str()); + } + else + { + _zone_intro_music_button->setProperty("id", 0); + _zone_intro_music_button->setText("-NONE-"); + } + + int sound_ambiance_id = record.getInt(AreaDB::SoundAmbience); + if (sound_ambiance_id != 0 && gSoundAmbienceDB.CheckIfIdExists(sound_ambiance_id)) + { + auto sound_ambiance_record = gSoundAmbienceDB.getByID(sound_ambiance_id); + + int day_sound_id = sound_ambiance_record.getInt(SoundAmbienceDB::SoundEntry_day); + if (day_sound_id != 0 && gSoundEntriesDB.CheckIfIdExists(day_sound_id)) + { + auto sound_entry_day_record = gSoundEntriesDB.getByID(day_sound_id); + std::stringstream ss_day; + ss_day << day_sound_id << "-" << sound_entry_day_record.getString(SoundEntriesDB::Name); + _sound_ambiance_day_button->setText(ss_day.str().c_str()); + _sound_ambiance_day_button->setProperty("id", day_sound_id); + } + else + { + _sound_ambiance_day_button->setText("-NONE-"); + _sound_ambiance_day_button->setProperty("id", 0); + } + + int night_sound_id = sound_ambiance_record.getInt(SoundAmbienceDB::SoundEntry_night); + if (night_sound_id != 0 && gSoundEntriesDB.CheckIfIdExists(night_sound_id)) + { + auto sound_entry_night_record = gSoundEntriesDB.getByID(night_sound_id); + std::stringstream ss_night; + ss_night << night_sound_id << "-" << sound_entry_night_record.getString(SoundEntriesDB::Name); + _sound_ambiance_night_button->setText(ss_night.str().c_str()); + _sound_ambiance_night_button->setProperty("id", night_sound_id); + } + else + { + _sound_ambiance_night_button->setText("-NONE-"); + _sound_ambiance_night_button->setProperty("id", 0); + } } else { - _sound_ambiance_day_button->setText("-NONE-"); _sound_ambiance_day_button->setProperty("id", 0); - } - - int night_sound_id = sound_ambiance_record.getInt(SoundAmbienceDB::SoundEntry_night); - if (night_sound_id != 0 && gSoundEntriesDB.CheckIfIdExists(night_sound_id)) - { - auto sound_entry_night_record = gSoundEntriesDB.getByID(night_sound_id); - std::stringstream ss_night; - ss_night << night_sound_id << "-" << sound_entry_night_record.getString(SoundEntriesDB::Name); - _sound_ambiance_night_button->setText(ss_night.str().c_str()); - _sound_ambiance_night_button->setProperty("id", night_sound_id); - } - else - { - _sound_ambiance_night_button->setText("-NONE-"); + _sound_ambiance_day_button->setText("-NONE-"); _sound_ambiance_night_button->setProperty("id", 0); + _sound_ambiance_night_button->setText("-NONE-"); } } - else + catch (AreaDB::NotFound) { - _sound_ambiance_day_button->setProperty("id", 0); - _sound_ambiance_day_button->setText("-NONE-"); - _sound_ambiance_night_button->setProperty("id", 0); - _sound_ambiance_night_button->setText("-NONE-"); - } + } } void AreaEditor::save_area() { - DBCFile::Record record = gAreaDB.getByID(_area_id_label->text().toInt()); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); - // record.write(AreaDB::ID, entry_id); - // rewrite mapid ? - record.write(AreaDB::Region, _parent_area_id); - record.write(AreaDB::AreaBit, _areabit); - record.write(AreaDB::Flags, _flags_value_spinbox->value()); - - int SoundProviderPreferences_id = 0; - if (_sound_provider_preferences_cbbox->currentIndex() != 0) + try { - auto rec = gSoundProviderPreferencesDB.getRecord(_sound_provider_preferences_cbbox->currentIndex() - 1); - SoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID); - } - record.write(AreaDB::SoundProviderPreferences, SoundProviderPreferences_id); - - int underwaterSoundProviderPreferences_id = 0; - if (_underwater_sound_provider_preferences_cbbox->currentIndex() != 0) - { - auto rec = gSoundProviderPreferencesDB.getRecord(_underwater_sound_provider_preferences_cbbox->currentIndex() - 1); - underwaterSoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID); - } - record.write(AreaDB::UnderwaterSoundProviderPreferences, underwaterSoundProviderPreferences_id); + DBCFile::Record record = gAreaDB.getByID(_area_id_label->text().toInt()); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); + // record.write(AreaDB::ID, entry_id); + // rewrite mapid ? + record.write(AreaDB::Region, _parent_area_id); + record.write(AreaDB::AreaBit, _areabit); + record.write(AreaDB::Flags, _flags_value_spinbox->value()); - // Ambiance ID. Blizzard stores those as unamed pair - // Just iterate the DBC to see if an entry with our settings already exists, if not create it. - // The reasoning for not having a selector/picker with the existing pairs is that it has less freedom, is harder to use and it's ugly if they don't have a name. - // This doesn't have the option to edit that entry for all its users though. - - int soundambience_day = _sound_ambiance_day_button->property("id").toInt(); - int soundambience_night = _sound_ambiance_night_button->property("id").toInt(); - - if (soundambience_day && !soundambience_night) // if day is set but not night, set night to day - soundambience_night = soundambience_day; - else if (!soundambience_day && soundambience_night) // night to day - soundambience_night = soundambience_day; - - if (soundambience_day && soundambience_night) // check if both day and night are set - { - bool sound_ambiance_exists {false}; - for (DBCFile::Iterator i = gSoundAmbienceDB.begin(); i != gSoundAmbienceDB.end(); ++i) + int SoundProviderPreferences_id = 0; + if (_sound_provider_preferences_cbbox->currentIndex() != 0) { - int day_id = i->getInt(SoundAmbienceDB::SoundEntry_day); - int night_id = i->getInt(SoundAmbienceDB::SoundEntry_night); - if (day_id == soundambience_day && night_id == soundambience_night) + auto rec = gSoundProviderPreferencesDB.getRecord(_sound_provider_preferences_cbbox->currentIndex() - 1); + SoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID); + } + record.write(AreaDB::SoundProviderPreferences, SoundProviderPreferences_id); + + int underwaterSoundProviderPreferences_id = 0; + if (_underwater_sound_provider_preferences_cbbox->currentIndex() != 0) + { + auto rec = gSoundProviderPreferencesDB.getRecord(_underwater_sound_provider_preferences_cbbox->currentIndex() - 1); + underwaterSoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID); + } + record.write(AreaDB::UnderwaterSoundProviderPreferences, underwaterSoundProviderPreferences_id); + + // Ambiance ID. Blizzard stores those as unamed pair + // Just iterate the DBC to see if an entry with our settings already exists, if not create it. + // The reasoning for not having a selector/picker with the existing pairs is that it has less freedom, is harder to use and it's ugly if they don't have a name. + // This doesn't have the option to edit that entry for all its users though. + + int soundambience_day = _sound_ambiance_day_button->property("id").toInt(); + int soundambience_night = _sound_ambiance_night_button->property("id").toInt(); + + if (soundambience_day && !soundambience_night) // if day is set but not night, set night to day + soundambience_night = soundambience_day; + else if (!soundambience_day && soundambience_night) // night to day + soundambience_night = soundambience_day; + + if (soundambience_day && soundambience_night) // check if both day and night are set + { + bool sound_ambiance_exists {false}; + for (DBCFile::Iterator i = gSoundAmbienceDB.begin(); i != gSoundAmbienceDB.end(); ++i) { - record.write(AreaDB::SoundAmbience, i->getInt(SoundAmbienceDB::ID)); - sound_ambiance_exists = true; - break; + int day_id = i->getInt(SoundAmbienceDB::SoundEntry_day); + int night_id = i->getInt(SoundAmbienceDB::SoundEntry_night); + if (day_id == soundambience_day && night_id == soundambience_night) + { + record.write(AreaDB::SoundAmbience, i->getInt(SoundAmbienceDB::ID)); + sound_ambiance_exists = true; + break; + } + } + if (!sound_ambiance_exists) + { + // create new sond entry record with the two ids + auto new_id = gSoundAmbienceDB.getEmptyRecordID(); + auto new_record = gSoundAmbienceDB.addRecord(new_id); + + new_record.write(SoundAmbienceDB::SoundEntry_day, soundambience_day); + new_record.write(SoundAmbienceDB::SoundEntry_night, soundambience_night); + gSoundAmbienceDB.save(); + record.write(AreaDB::SoundAmbience, new_id); } } - if (!sound_ambiance_exists) - { - // create new sond entry record with the two ids - auto new_id = gSoundAmbienceDB.getEmptyRecordID(); - auto new_record = gSoundAmbienceDB.addRecord(new_id); + else + record.write(AreaDB::SoundAmbience, 0); // if night or day isn't set, set to 0 - new_record.write(SoundAmbienceDB::SoundEntry_day, soundambience_day); - new_record.write(SoundAmbienceDB::SoundEntry_night, soundambience_night); - gSoundAmbienceDB.save(); - record.write(AreaDB::SoundAmbience, new_id); - } + + record.write(AreaDB::ZoneMusic, _zone_music_button->property("id").toInt()); + record.write(AreaDB::ZoneIntroMusicTable, _zone_intro_music_button->property("id").toInt()); + + record.write(AreaDB::ExplorationLevel, _exploration_level_spinbox->value()); + + _area_name->toRecord(record, AreaDB::Name); + // update name in the tree + auto parent = static_cast(this->parentWidget()); + auto item = parent->create_or_get_tree_widget_item(_area_id_label->text().toInt()); + std::stringstream ss; + std::string areaName = record.getLocalizedString(AreaDB::Name); + ss << _area_id_label->text().toInt() << "-" << areaName; + item->setText(0, QString(ss.str().c_str())); + + record.write(AreaDB::FactionGroup, _faction_group_combobox->currentIndex() * 2); + record.write(AreaDB::MinElevation, static_cast(_min_elevation_spinbox->value())); + record.write(AreaDB::AmbientMultiplier, _ambiant_multiplier->value() / 100.0f); + record.write(AreaDB::LightId, 0); // never used + + gAreaDB.save(); + + load_area(_area_id_label->text().toInt());// reload ui, especially for night/day ambience } - else - record.write(AreaDB::SoundAmbience, 0); // if night or day isn't set, set to 0 + catch (AreaDB::NotFound) + { - - record.write(AreaDB::ZoneMusic, _zone_music_button->property("id").toInt()); - record.write(AreaDB::ZoneIntroMusicTable, _zone_intro_music_button->property("id").toInt()); - - record.write(AreaDB::ExplorationLevel, _exploration_level_spinbox->value()); - - _area_name->toRecord(record, AreaDB::Name); - // update name in the tree - auto parent = static_cast(this->parentWidget()); - auto item = parent->create_or_get_tree_widget_item(_area_id_label->text().toInt()); - std::stringstream ss; - std::string areaName = record.getLocalizedString(AreaDB::Name); - ss << _area_id_label->text().toInt() << "-" << areaName; - item->setText(0, QString(ss.str().c_str())); - - record.write(AreaDB::FactionGroup, _faction_group_combobox->currentIndex() * 2); - record.write(AreaDB::MinElevation, static_cast(_min_elevation_spinbox->value())); - record.write(AreaDB::AmbientMultiplier, _ambiant_multiplier->value() / 100.0f); - record.write(AreaDB::LightId, 0); // never used - - gAreaDB.save(); - - load_area(_area_id_label->text().toInt()); // reload ui, especially for night/day ambience + } } } diff --git a/src/noggit/ui/ZoneIDBrowser.h b/src/noggit/ui/ZoneIDBrowser.h index 4de56800..1dca0b25 100755 --- a/src/noggit/ui/ZoneIDBrowser.h +++ b/src/noggit/ui/ZoneIDBrowser.h @@ -26,7 +26,7 @@ namespace Noggit namespace Ui { - static std::map area_flags_names = { + static const std::unordered_map area_flags_names = { {0 , "Emit Breath Particles"}, {1 , "Breath Particles Override Parent"}, {2 , "On Map Dungeon"}, @@ -60,7 +60,7 @@ namespace Noggit {28, "Flying not allowed"}, // in 3.3.5 {29, "Only Evaluate Ghost Bind Once"}, {30, "Is Subzone"}, - // {31, "Don't Evaluate Graveyard From Client"} + // {31, "Don't Evaluate Graveyard From Client"} // not used in 3.3.5 }; class AreaEditor : public QWidget diff --git a/src/noggit/ui/tools/LightEditor/LightEditor.cpp b/src/noggit/ui/tools/LightEditor/LightEditor.cpp index b9579b5e..4af9aa5f 100755 --- a/src/noggit/ui/tools/LightEditor/LightEditor.cpp +++ b/src/noggit/ui/tools/LightEditor/LightEditor.cpp @@ -409,35 +409,43 @@ LightEditor::LightEditor(MapView* map_view, QWidget* parent) _curr_sky->curr_sky_param = index; _world->renderer()->skies()->update_sky_colors(_map_view->getCamera()->position, static_cast(_world->time) % 2880); // find how to update sky - DBCFile::Record data = gLightDB.getByID(_curr_sky->Id); - int nb_user = 0; - for (DBCFile::Iterator i = gLightDB.begin(); i != gLightDB.end(); ++i) + try { - for (int l = 0; l < NUM_SkyParamsNames; l++) + DBCFile::Record data = gLightDB.getByID(_curr_sky->Id); + int nb_user = 0; + for (DBCFile::Iterator i = gLightDB.begin(); i != gLightDB.end(); ++i) { - if (i->getInt(LightDB::DataIDs + l) == data.getInt(LightDB::DataIDs + index)) - nb_user++; + for (int l = 0; l < NUM_SkyParamsNames; l++) + { + if (i->getInt(LightDB::DataIDs + l) == data.getInt(LightDB::DataIDs + index)) + nb_user++; + } + } + _nb_param_users->setText("This param is used " + nb_user); + + auto sky_param = _curr_sky->skyParams[index]; + + glow_slider->setSliderPosition(sky_param->glow() * 100); + highlight_sky_checkbox->setCheckState(Qt::CheckState(sky_param->highlight_sky())); + if (_curr_sky->skybox.has_value()) + skybox_model_lineedit->setText(QString::fromStdString(sky_param->skybox.value().model.get()->file_key().filepath())); + // alpha values + shallow_water_alpha_slider->setSliderPosition(sky_param->river_shallow_alpha() * 100); + deep_water_alpha_slider->setSliderPosition(sky_param->river_deep_alpha() * 100); + shallow_ocean_alpha_slider->setSliderPosition(sky_param->ocean_shallow_alpha() * 100); + deep_ocean_alpha_slider->setSliderPosition(sky_param->ocean_deep_alpha() * 100); + // color values + for (int i = 0; i < NUM_SkyColorNames; ++i) + { + LightsPreview[i]->SetPreview(sky_param->colorRows[i]); + //_color_value_Buttons[i]->setText(QString::fromStdString(std::format("{} / 16 values", sky_param->colorRows[i].size()))); } } - _nb_param_users->setText("This param is used " + nb_user); - - auto sky_param = _curr_sky->skyParams[index]; - - glow_slider->setSliderPosition(sky_param->glow() * 100); - highlight_sky_checkbox->setCheckState(Qt::CheckState(sky_param->highlight_sky())); - if (_curr_sky->skybox.has_value()) - skybox_model_lineedit->setText(QString::fromStdString(sky_param->skybox.value().model.get()->file_key().filepath())); - // alpha values - shallow_water_alpha_slider->setSliderPosition(sky_param->river_shallow_alpha() * 100); - deep_water_alpha_slider->setSliderPosition(sky_param->river_deep_alpha() * 100); - shallow_ocean_alpha_slider->setSliderPosition(sky_param->ocean_shallow_alpha() * 100); - deep_ocean_alpha_slider->setSliderPosition(sky_param->ocean_deep_alpha() * 100); - // color values - for (int i = 0; i < NUM_SkyColorNames; ++i) + catch (LightDB::NotFound) { - LightsPreview[i]->SetPreview(sky_param->colorRows[i]); - //_color_value_Buttons[i]->setText(QString::fromStdString(std::format("{} / 16 values", sky_param->colorRows[i].size()))); + assert(false); } + }); connect(SaveCurrentSkyButton, &QPushButton::clicked, [=]() { diff --git a/src/noggit/ui/tools/MapCreationWizard/Ui/MapCreationWizard.cpp b/src/noggit/ui/tools/MapCreationWizard/Ui/MapCreationWizard.cpp index 751f3bbf..db64c42b 100755 --- a/src/noggit/ui/tools/MapCreationWizard/Ui/MapCreationWizard.cpp +++ b/src/noggit/ui/tools/MapCreationWizard/Ui/MapCreationWizard.cpp @@ -639,33 +639,43 @@ void MapCreationWizard::saveCurrentEntry() _world->mapIndex.create_empty_wdl(); // Save Map.dbc record - DBCFile::Record record = _is_new_record ? gMapDB.addRecord(_cur_map_id) : gMapDB.getByID(_cur_map_id); + try + { + DBCFile::Record record = _is_new_record ? gMapDB.addRecord(_cur_map_id) : gMapDB.getByID(_cur_map_id); - record.writeString(MapDB::InternalName, _directory->text().toStdString()); + record.writeString(MapDB::InternalName, _directory->text().toStdString()); - record.write(MapDB::AreaType, _instance_type->itemData(_instance_type->currentIndex()).toInt()); - record.write(MapDB::Flags, _sort_by_size_cat->isChecked() ? 16 : 0 ); - _map_name->toRecord(record, MapDB::Name); + record.write(MapDB::AreaType, _instance_type->itemData(_instance_type->currentIndex()).toInt()); + record.write(MapDB::Flags, _sort_by_size_cat->isChecked() ? 16 : 0 ); + _map_name->toRecord(record, MapDB::Name); - record.write(MapDB::AreaTableID, _area_table_id->value()); - _map_desc_alliance->toRecord(record, MapDB::MapDescriptionAlliance); - _map_desc_horde->toRecord(record, MapDB::MapDescriptionHorde); - record.write(MapDB::LoadingScreen, _loading_screen->value()); - record.write(MapDB::minimapIconScale, static_cast(_minimap_icon_scale->value())); - record.write(MapDB::corpseMapID, _corpse_map_id->itemData(_corpse_map_id->currentIndex()).toInt()); - record.write(MapDB::corpseX, static_cast(_corpse_x->value())); - record.write(MapDB::corpseY, static_cast(_corpse_y->value())); - record.write(MapDB::TimeOfDayOverride, _time_of_day_override->value()); - record.write(MapDB::ExpansionID, _expansion_id->itemData(_expansion_id->currentIndex()).toInt()); - record.write(MapDB::RaidOffset, _raid_offset->value()); - record.write(MapDB::NumberOfPlayers, _max_players->value()); + record.write(MapDB::AreaTableID, _area_table_id->value()); + _map_desc_alliance->toRecord(record, MapDB::MapDescriptionAlliance); + _map_desc_horde->toRecord(record, MapDB::MapDescriptionHorde); + record.write(MapDB::LoadingScreen, _loading_screen->value()); + record.write(MapDB::minimapIconScale, static_cast(_minimap_icon_scale->value())); + record.write(MapDB::corpseMapID, _corpse_map_id->itemData(_corpse_map_id->currentIndex()).toInt()); + record.write(MapDB::corpseX, static_cast(_corpse_x->value())); + record.write(MapDB::corpseY, static_cast(_corpse_y->value())); + record.write(MapDB::TimeOfDayOverride, _time_of_day_override->value()); + record.write(MapDB::ExpansionID, _expansion_id->itemData(_expansion_id->currentIndex()).toInt()); + record.write(MapDB::RaidOffset, _raid_offset->value()); + record.write(MapDB::NumberOfPlayers, _max_players->value()); - gMapDB.save(); + gMapDB.save(); - emit map_dbc_updated(); + emit map_dbc_updated(); - _is_new_record = false; + _is_new_record = false; + } + catch (MapDB::AlreadyExists) + { + } + catch (MapDB::NotFound) + { + + } } void MapCreationWizard::discardChanges() @@ -831,6 +841,11 @@ LocaleDBCEntry::LocaleDBCEntry(QWidget* parent) : QWidget(parent) }; layout->addWidget(_current_locale); + + int locale_id = Noggit::Application::NoggitApplication::instance()->clientData()->getLocaleId(); + _current_locale->setCurrentIndex(locale_id); + setCurrentLocale(_locale_names[locale_id]); + // Connect connect ( _current_locale, &QComboBox::currentTextChanged diff --git a/src/noggit/ui/windows/EditorWindows/SoundEntryPickerWindow.cpp b/src/noggit/ui/windows/EditorWindows/SoundEntryPickerWindow.cpp index f1451c47..551706d8 100644 --- a/src/noggit/ui/windows/EditorWindows/SoundEntryPickerWindow.cpp +++ b/src/noggit/ui/windows/EditorWindows/SoundEntryPickerWindow.cpp @@ -301,8 +301,6 @@ namespace Noggit void SoundEntryPickerWindow::select_entry(int id) { - _entry_id = id; - if (id != 0) { // _picker_listview->setCurrentRow(0); @@ -315,119 +313,134 @@ namespace Noggit return; } - _entry_id_lbl->setText(QString(std::to_string(id).c_str())); - - DBCFile::Record record = gSoundEntriesDB.getByID(id); - - _name_ledit->setText(record.getString(SoundEntriesDB::Name)); - - int sound_type_id = record.getInt(SoundEntriesDB::SoundType); - - int row_id = 0; - for (auto sound_type : sound_types_names) + try { - if (sound_type.first == sound_type_id) + DBCFile::Record record = gSoundEntriesDB.getByID(id); + + _entry_id = id; + _entry_id_lbl->setText(QString(std::to_string(id).c_str())); + + _name_ledit->setText(record.getString(SoundEntriesDB::Name)); + + int sound_type_id = record.getInt(SoundEntriesDB::SoundType); + + int row_id = 0; + for (auto sound_type : sound_types_names) { - _sound_type_cbbox->setCurrentIndex(row_id); - break; + if (sound_type.first == sound_type_id) + { + _sound_type_cbbox->setCurrentIndex(row_id); + break; + } + + row_id++; } - row_id++; + _eax_type_cbbox->setCurrentIndex(record.getInt(SoundEntriesDB::EAXDef)); + _min_distance_spinbox->setValue(record.getFloat(SoundEntriesDB::minDistance)); + _max_distance_spinbox->setValue(record.getFloat(SoundEntriesDB::distanceCutoff)); + _volume_slider->setValue(record.getFloat(SoundEntriesDB::Volume) * 100); + + int flags = record.getInt(SoundEntriesDB::Flags); + + _flag6_checkbox->setChecked((flags & (1 << (6 - 1))) ? true : false); + _flag10_checkbox->setChecked((flags & (1 << (10 - 1))) ? true : false); + _flag11_checkbox->setChecked((flags & (1 << (11 - 1))) ? true : false); + _flag12 = (flags & (1 << (12 - 1))) ? true : false; + + _directory_ledit->setText(record.getString(SoundEntriesDB::FilePath)); + + _files_listview->clear(); + for (int i = 0; i < 10; i++) + { + std::string filename = record.getString(SoundEntriesDB::Filenames + i); + // auto freq = record.getInt(SoundEntriesDB::Freq + i); + + if (filename.empty()) + continue; + + _filenames_ledits[i] = new QLineEdit(); // set parent in the widget class + _filenames_ledits[i]->setText(filename.c_str()); + auto file_widget = new SoundFileWListWidgetItem(_filenames_ledits[i], _directory_ledit->text().toStdString()); + + auto item = new QListWidgetItem(_files_listview); + _files_listview->setItemWidget(item, file_widget); + item->setSizeHint(QSize(_files_listview->width(), _files_listview->height() / 10) ); + + _files_listview->addItem(item); + } + update_files_count(); + + _sound_advanced_id = record.getInt(SoundEntriesDB::soundEntriesAdvancedID); } - - _eax_type_cbbox->setCurrentIndex(record.getInt(SoundEntriesDB::EAXDef)); - _min_distance_spinbox->setValue(record.getFloat(SoundEntriesDB::minDistance)); - _max_distance_spinbox->setValue(record.getFloat(SoundEntriesDB::distanceCutoff)); - _volume_slider->setValue(record.getFloat(SoundEntriesDB::Volume) * 100); - - int flags = record.getInt(SoundEntriesDB::Flags); - - _flag6_checkbox->setChecked((flags & (1 << (6 - 1))) ? true : false); - _flag10_checkbox->setChecked((flags & (1 << (10 - 1))) ? true : false); - _flag11_checkbox->setChecked((flags & (1 << (11 - 1))) ? true : false); - _flag12 = (flags & (1 << (12 - 1))) ? true : false; - - _directory_ledit->setText(record.getString(SoundEntriesDB::FilePath)); - - _files_listview->clear(); - for (int i = 0; i < 10; i++) + catch (SoundEntriesDB::NotFound) { - std::string filename = record.getString(SoundEntriesDB::Filenames + i); - // auto freq = record.getInt(SoundEntriesDB::Freq + i); - if (filename.empty()) - continue; - - _filenames_ledits[i] = new QLineEdit(); // set parent in the widget class - _filenames_ledits[i]->setText(filename.c_str()); - auto file_widget = new SoundFileWListWidgetItem(_filenames_ledits[i], _directory_ledit->text().toStdString()); - - auto item = new QListWidgetItem(_files_listview); - _files_listview->setItemWidget(item, file_widget); - item->setSizeHint(QSize(_files_listview->width(), _files_listview->height() / 10) ); - - _files_listview->addItem(item); } - update_files_count(); - - _sound_advanced_id = record.getInt(SoundEntriesDB::soundEntriesAdvancedID); } void SoundEntryPickerWindow::save_entry(int entry_id) { - DBCFile::Record record = gSoundEntriesDB.getByID(entry_id); - - - record.write(SoundEntriesDB::ID, entry_id); - - int sound_type_id = 0; - int row_id = 0; - for (auto sound_type : sound_types_names) + try { - if (row_id == _sound_type_cbbox->currentIndex()) + DBCFile::Record record = gSoundEntriesDB.getByID(entry_id); + + record.write(SoundEntriesDB::ID, entry_id); + + int sound_type_id = 0; + int row_id = 0; + for (auto sound_type : sound_types_names) { - sound_type_id = sound_type.first; - break; + if (row_id == _sound_type_cbbox->currentIndex()) + { + sound_type_id = sound_type.first; + break; + } + row_id++; } - row_id++; + record.write(SoundEntriesDB::SoundType, sound_type_id); + + record.writeString(SoundEntriesDB::Name, _name_ledit->text().toStdString()); + + // _files_listview->count() + int i = 0; + for (;i < _files_listview->count(); i++) + { + record.writeString(SoundEntriesDB::Filenames + i, _filenames_ledits[i]->text().toStdString()); + record.write(SoundEntriesDB::Freq + i, 1); // TODO. but in 99.9% 1 is fine + } + for (;i < 10; i++) // clean up unset entries + { + record.writeString(SoundEntriesDB::Filenames + i, ""); + record.write(SoundEntriesDB::Freq + i, 0); + } + + record.writeString(SoundEntriesDB::FilePath, _directory_ledit->text().toStdString()); + record.write(SoundEntriesDB::Volume, _volume_slider->value() / 100.0f); // should be a float + + int flags = 0; + if (_flag6_checkbox->isChecked()) + flags |= (1ULL << (5)); + if (_flag10_checkbox->isChecked()) + flags |= (1ULL << (9)); + if (_flag11_checkbox->isChecked()) + flags |= (1ULL << (10)); + if (_flag12) + flags |= (1ULL << (11)); + record.write(SoundEntriesDB::Flags, flags); + + record.write(SoundEntriesDB::minDistance, static_cast(_min_distance_spinbox->value())); + record.write(SoundEntriesDB::distanceCutoff, static_cast(_max_distance_spinbox->value())); + record.write(SoundEntriesDB::EAXDef, _eax_type_cbbox->currentIndex()); + record.write(SoundEntriesDB::soundEntriesAdvancedID, _sound_advanced_id); + + gSoundEntriesDB.save(); } - record.write(SoundEntriesDB::SoundType, sound_type_id); - - record.writeString(SoundEntriesDB::Name, _name_ledit->text().toStdString()); - - // _files_listview->count() - int i = 0; - for (;i < _files_listview->count(); i++) + catch (SoundEntriesDB::NotFound) { - record.writeString(SoundEntriesDB::Filenames + i, _filenames_ledits[i]->text().toStdString()); - record.write(SoundEntriesDB::Freq + i, 1); // TODO. but in 99.9% 1 is fine - } - for (;i < 10; i++) // clean up unset entries - { - record.writeString(SoundEntriesDB::Filenames + i, ""); - record.write(SoundEntriesDB::Freq + i, 0); + } - record.writeString(SoundEntriesDB::FilePath, _directory_ledit->text().toStdString()); - record.write(SoundEntriesDB::Volume, _volume_slider->value() / 100.0f); // should be a float - - int flags = 0; - if (_flag6_checkbox->isChecked()) - flags |= (1ULL << (5)); - if (_flag10_checkbox->isChecked()) - flags |= (1ULL << (9)); - if (_flag11_checkbox->isChecked()) - flags |= (1ULL << (10)); - if (_flag12) - flags |= (1ULL << (11)); - record.write(SoundEntriesDB::Flags, flags); - - record.write(SoundEntriesDB::minDistance, static_cast(_min_distance_spinbox->value())); - record.write(SoundEntriesDB::distanceCutoff, static_cast(_max_distance_spinbox->value())); - record.write(SoundEntriesDB::EAXDef, _eax_type_cbbox->currentIndex()); - record.write(SoundEntriesDB::soundEntriesAdvancedID, _sound_advanced_id); - - gSoundEntriesDB.save(); } void SoundEntryPickerWindow::update_files_count() diff --git a/src/noggit/ui/windows/EditorWindows/ZoneIntroMusicPickerWindow.cpp b/src/noggit/ui/windows/EditorWindows/ZoneIntroMusicPickerWindow.cpp index b5d77da7..fde15010 100644 --- a/src/noggit/ui/windows/EditorWindows/ZoneIntroMusicPickerWindow.cpp +++ b/src/noggit/ui/windows/EditorWindows/ZoneIntroMusicPickerWindow.cpp @@ -196,55 +196,80 @@ namespace Noggit void ZoneIntroMusicPickerWindow::select_entry(int id) { - _entry_id = id; - if (id != 0) - _picker_listview->setCurrentRow(gZoneIntroMusicTableDB.getRecordRowId(id)); + + if (id) + { + try + { + _picker_listview->setCurrentRow(gZoneIntroMusicTableDB.getRecordRowId(id)); + } + catch (ZoneIntroMusicTableDB::NotFound) + { + + } + } else { _picker_listview->setCurrentRow(0); return; } - _entry_id_lbl->setText(QString(std::to_string(id).c_str())); - - DBCFile::Record record = gZoneIntroMusicTableDB.getByID(id); - - _name_ledit->setText(record.getString(ZoneIntroMusicTableDB::Name)); - - int sound_entry = record.getInt(ZoneIntroMusicTableDB::SoundId); - - if (sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(sound_entry)) + try { - DBCFile::Record sound_record = gSoundEntriesDB.getByID(sound_entry); - std::stringstream ss; - ss << sound_entry << "-" << sound_record.getString(SoundEntriesDB::Name); - _sound_button->setText(ss.str().c_str()); - _sound_button->setProperty("id", sound_entry); + DBCFile::Record record = gZoneIntroMusicTableDB.getByID(id); + + _entry_id = id; + _entry_id_lbl->setText(QString(std::to_string(id).c_str())); + + _name_ledit->setText(record.getString(ZoneIntroMusicTableDB::Name)); + + int sound_entry = record.getInt(ZoneIntroMusicTableDB::SoundId); + + if (sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(sound_entry)) + { + DBCFile::Record sound_record = gSoundEntriesDB.getByID(sound_entry); + std::stringstream ss; + ss << sound_entry << "-" << sound_record.getString(SoundEntriesDB::Name); + _sound_button->setText(ss.str().c_str()); + _sound_button->setProperty("id", sound_entry); + } + else + { + _sound_button->setText("-NONE-"); + _sound_button->setProperty("id", 0); + } + + _priority = record.getInt(ZoneIntroMusicTableDB::Priority); // always 1 except for 1 test entry + + _min_delay_spinbox->setValue(record.getInt(ZoneIntroMusicTableDB::MinDelayMinutes)); } - else + catch (ZoneIntroMusicTableDB::NotFound) { - _sound_button->setText("-NONE-"); - _sound_button->setProperty("id", 0); + } - _priority = record.getInt(ZoneIntroMusicTableDB::Priority); // always 1 except for 1 test entry - - _min_delay_spinbox->setValue(record.getInt(ZoneIntroMusicTableDB::MinDelayMinutes)); } void ZoneIntroMusicPickerWindow::save_entry(int entry_id) { - DBCFile::Record record = gZoneIntroMusicTableDB.getByID(entry_id); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); + try + { + DBCFile::Record record = gZoneIntroMusicTableDB.getByID(entry_id); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); - record.write(ZoneIntroMusicTableDB::ID, entry_id); - record.writeString(ZoneIntroMusicTableDB::Name, _name_ledit->text().toStdString()); - record.write(ZoneIntroMusicTableDB::SoundId, _sound_button->property("id").toInt()); - record.write(ZoneIntroMusicTableDB::Priority, _priority); - record.write(ZoneIntroMusicTableDB::MinDelayMinutes, _min_delay_spinbox->value()); + record.write(ZoneIntroMusicTableDB::ID, entry_id); + record.writeString(ZoneIntroMusicTableDB::Name, _name_ledit->text().toStdString()); + record.write(ZoneIntroMusicTableDB::SoundId, _sound_button->property("id").toInt()); + record.write(ZoneIntroMusicTableDB::Priority, _priority); + record.write(ZoneIntroMusicTableDB::MinDelayMinutes, _min_delay_spinbox->value()); - gZoneIntroMusicTableDB.save(); + gZoneIntroMusicTableDB.save(); + } + catch (ZoneIntroMusicTableDB::NotFound) + { + + } } } } diff --git a/src/noggit/ui/windows/EditorWindows/ZoneMusicPickerWindow.cpp b/src/noggit/ui/windows/EditorWindows/ZoneMusicPickerWindow.cpp index 57ee61e0..fe26d1fb 100644 --- a/src/noggit/ui/windows/EditorWindows/ZoneMusicPickerWindow.cpp +++ b/src/noggit/ui/windows/EditorWindows/ZoneMusicPickerWindow.cpp @@ -251,76 +251,96 @@ namespace Noggit } void ZoneMusicPickerWindow::select_entry(int id) { - _entry_id = id; + if (id) + { + try + { + _picker_listview->setCurrentRow(gZoneMusicDB.getRecordRowId(id)); + } + catch (ZoneMusicDB::NotFound) + { - if (id != 0) - _picker_listview->setCurrentRow(gZoneMusicDB.getRecordRowId(id)); + } + } else { _picker_listview->setCurrentRow(0); return; } - _entry_id_lbl->setText(QString(std::to_string(id).c_str())); - - DBCFile::Record record = gZoneMusicDB.getByID(id); - - _name_ledit->setText(record.getString(ZoneMusicDB::Name)); - - int day_sound_entry = record.getInt(ZoneMusicDB::DayMusic); - int night_sound_entry = record.getInt(ZoneMusicDB::NightMusic); - - if (day_sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(day_sound_entry)) // some entries reference sound entries that don't exist + try { - DBCFile::Record day_sound_record = gSoundEntriesDB.getByID(day_sound_entry); - std::stringstream ss_day; - ss_day << day_sound_entry << "-" << day_sound_record.getString(SoundEntriesDB::Name); - _day_music_button->setText(ss_day.str().c_str()); - _day_music_button->setProperty("id", day_sound_entry); + DBCFile::Record record = gZoneMusicDB.getByID(id); + + _entry_id = id; + _entry_id_lbl->setText(QString(std::to_string(id).c_str())); + + _name_ledit->setText(record.getString(ZoneMusicDB::Name)); + + int day_sound_entry = record.getInt(ZoneMusicDB::DayMusic); + int night_sound_entry = record.getInt(ZoneMusicDB::NightMusic); + + if (day_sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(day_sound_entry)) // some entries reference sound entries that don't exist + { + DBCFile::Record day_sound_record = gSoundEntriesDB.getByID(day_sound_entry); + std::stringstream ss_day; + ss_day << day_sound_entry << "-" << day_sound_record.getString(SoundEntriesDB::Name); + _day_music_button->setText(ss_day.str().c_str()); + _day_music_button->setProperty("id", day_sound_entry); + } + else + { + _day_music_button->setText("-NONE-"); + _day_music_button->setProperty("id", 0); + } + + if (night_sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(night_sound_entry)) + { + DBCFile::Record night_sound_record = gSoundEntriesDB.getByID(night_sound_entry); + std::stringstream ss_night; + ss_night << night_sound_entry << "-" << night_sound_record.getString(SoundEntriesDB::Name); + _night_music_button->setText(ss_night.str().c_str()); + _night_music_button->setProperty("id", night_sound_entry); + } + else + { + _night_music_button->setText("-NONE-"); + _night_music_button->setProperty("id", 0); + } + + _day_min_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMinDay)); + _day_max_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMaxDay)); + _night_min_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMinNight)); + _night_max_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMaxNight)); } - else + catch (ZoneMusicDB::NotFound) { - _day_music_button->setText("-NONE-"); - _day_music_button->setProperty("id", 0); + } - - if (night_sound_entry != 0 && gSoundEntriesDB.CheckIfIdExists(night_sound_entry)) - { - DBCFile::Record night_sound_record = gSoundEntriesDB.getByID(night_sound_entry); - std::stringstream ss_night; - ss_night << night_sound_entry << "-" << night_sound_record.getString(SoundEntriesDB::Name); - _night_music_button->setText(ss_night.str().c_str()); - _night_music_button->setProperty("id", night_sound_entry); - } - else - { - _night_music_button->setText("-NONE-"); - _night_music_button->setProperty("id", 0); - } - - _day_min_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMinDay)); - _day_max_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMaxDay)); - _night_min_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMinNight)); - _night_max_interval_spinbox->setValue(record.getInt(ZoneMusicDB::SilenceIntervalMaxNight)); - - } void ZoneMusicPickerWindow::save_entry(int entry_id) { - DBCFile::Record record = gZoneMusicDB.getByID(entry_id); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); + try + { + DBCFile::Record record = gZoneMusicDB.getByID(entry_id); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); - record.write(ZoneMusicDB::ID, entry_id); - record.writeString(ZoneMusicDB::Name, _name_ledit->text().toStdString()); - record.write(ZoneMusicDB::SilenceIntervalMinDay, _day_min_interval_spinbox->value()); - record.write(ZoneMusicDB::SilenceIntervalMaxDay, _day_max_interval_spinbox->value()); - record.write(ZoneMusicDB::SilenceIntervalMinNight, _night_min_interval_spinbox->value()); - record.write(ZoneMusicDB::SilenceIntervalMaxNight, _night_max_interval_spinbox->value()); - record.write(ZoneMusicDB::DayMusic, _day_music_button->property("id").toInt()); - record.write(ZoneMusicDB::NightMusic, _night_music_button->property("id").toInt()); + record.write(ZoneMusicDB::ID, entry_id); + record.writeString(ZoneMusicDB::Name, _name_ledit->text().toStdString()); + record.write(ZoneMusicDB::SilenceIntervalMinDay, _day_min_interval_spinbox->value()); + record.write(ZoneMusicDB::SilenceIntervalMaxDay, _day_max_interval_spinbox->value()); + record.write(ZoneMusicDB::SilenceIntervalMinNight, _night_min_interval_spinbox->value()); + record.write(ZoneMusicDB::SilenceIntervalMaxNight, _night_max_interval_spinbox->value()); + record.write(ZoneMusicDB::DayMusic, _day_music_button->property("id").toInt()); + record.write(ZoneMusicDB::NightMusic, _night_music_button->property("id").toInt()); - gZoneMusicDB.save(); + gZoneMusicDB.save(); + } + catch (ZoneMusicDB::NotFound) + { + + } } } } diff --git a/src/noggit/ui/windows/SoundPlayer/SoundEntryPlayer.cpp b/src/noggit/ui/windows/SoundPlayer/SoundEntryPlayer.cpp index 071fb4c7..37bae57f 100644 --- a/src/noggit/ui/windows/SoundPlayer/SoundEntryPlayer.cpp +++ b/src/noggit/ui/windows/SoundPlayer/SoundEntryPlayer.cpp @@ -130,27 +130,35 @@ namespace Noggit } // get files list - DBCFile::Record sound_entry_record = gSoundEntriesDB.getByID(sound_entry_id); - - _directory_lbl->setText(sound_entry_record.getString(SoundEntriesDB::FilePath)); - - _volume_slider->setValue(sound_entry_record.getFloat(SoundEntriesDB::Volume) * 100); - _media_player->setVolume(sound_entry_record.getFloat(SoundEntriesDB::Volume) * 100); - - for (int fileid = 0; fileid < 10; fileid++) + try { - std::string filename = sound_entry_record.getString(SoundEntriesDB::Filenames + fileid); - if (!filename.empty()) + DBCFile::Record sound_entry_record = gSoundEntriesDB.getByID(sound_entry_id); + + _directory_lbl->setText(sound_entry_record.getString(SoundEntriesDB::FilePath)); + + _volume_slider->setValue(sound_entry_record.getFloat(SoundEntriesDB::Volume) * 100); + _media_player->setVolume(sound_entry_record.getFloat(SoundEntriesDB::Volume) * 100); + + for (int fileid = 0; fileid < 10; fileid++) { - // std::stringstream ss_filepah; - // ss_filepath << directory << "\\" << filename; - // music_files.push_back(ss_filepah.str()); - // music_files.push_back(filename); - _files_listview->addItem(filename.c_str()); + std::string filename = sound_entry_record.getString(SoundEntriesDB::Filenames + fileid); + if (!filename.empty()) + { + // std::stringstream ss_filepah; + // ss_filepath << directory << "\\" << filename; + // music_files.push_back(ss_filepah.str()); + // music_files.push_back(filename); + _files_listview->addItem(filename.c_str()); + } } + _files_listview->setCurrentRow(0); + play_selected_sound(); } - _files_listview->setCurrentRow(0); - play_selected_sound(); + catch (SoundEntriesDB::NotFound) + { + + } + } void SoundEntryPlayer::PlaySingleSoundFile(std::string filepath, std::string dir_path)