- add a quick settings popup when creating zones

- improve locales support
- refactor dbc exceptions handling
This commit is contained in:
T1ti
2024-08-06 04:36:38 +02:00
parent 4f4da1021e
commit e24c1c3bd0
13 changed files with 926 additions and 671 deletions

View File

@@ -226,11 +226,25 @@ std::string WMOAreaTableDB::getWMOAreaName(int WMOId, int namesetId)
int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId); int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId);
if (areatableid) if (areatableid)
{ {
auto rec = gAreaDB.getByID(areatableid); // return AreaDB::getAreaFullName(areatableid); // full name with zone
return rec.getLocalizedString(AreaDB::Name); 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 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<std::string> WMOAreaTableDB::getWMOAreaNames(int WMOId)
int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId); int areatableid = i->getUInt(WMOAreaTableDB::AreaTableRefId);
if (areatableid) if (areatableid)
{ {
auto rec = gAreaDB.getByID(areatableid); try
areanamesvect.push_back(rec.getLocalizedString(AreaDB::Name)); {
auto rec = gAreaDB.getByID(areatableid);
areanamesvect.push_back(rec.getLocalizedString(AreaDB::Name));
}
catch (WMOAreaTableDB::NotFound)
{
areanamesvect.push_back("Unknown location");
}
} }
else else
areanamesvect.push_back("-Local Terrain Area-"); // nullptr? need to get it from terrain 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; return areanamesvect;
} }

View File

@@ -110,6 +110,7 @@ public:
void writeLocalizedString(size_t field, const std::string& val, int locale) void writeLocalizedString(size_t field, const std::string& val, int locale)
{ {
assert(field < file.fieldCount); assert(field < file.fieldCount);
assert(locale < 16);
if (!val.size()) if (!val.size())
{ {
@@ -181,9 +182,8 @@ public:
if (i->getUInt(field) == id) if (i->getUInt(field) == id)
return (*i); return (*i);
} }
LogDebug << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl;
LogError << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl; throw NotFound();
return *begin(); // return the first entry if it failed
} }
inline bool CheckIfIdExists(unsigned int id, size_t field = 0) inline bool CheckIfIdExists(unsigned int id, size_t field = 0)
{ {
@@ -205,7 +205,7 @@ public:
row_id++; row_id++;
} }
LogError << "Tried to get a not existing row in " << filename << " (ID = " << id << ")!" << std::endl; 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); Record addRecord(size_t id, size_t id_field = 0);

View File

@@ -1043,137 +1043,155 @@ void Sky::save_to_dbc()
{ {
// Save Light.dbc record // Save Light.dbc record
// find new empty ID : gLightDB.getEmptyRecordID(); .prob do it when creating new light instead. // 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); try
// 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++)
{ {
// skip if no param DBCFile::Record data = is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id);
if (skyParams[param_id] == nullptr)
continue;
// TODO : several lights can use the same param, ask user if he wants to save a copy or edit it for all ? // pos = glm::vec3(data->getFloat(LightDB::PositionX) / skymul, data->getFloat(LightDB::PositionY) / skymul, data->getFloat(LightDB::PositionZ) / skymul);
int lightParam_dbc_id = 0; // record.write(1, _curr_sky-> map id
if (is_new_record) // not for duplicates data.write(LightDB::PositionX, pos.x * skymul);
lightParam_dbc_id = gLightParamsDB.getEmptyRecordID(); data.write(LightDB::PositionY, pos.y * skymul);
else data.write(LightDB::PositionZ, pos.z * skymul);
lightParam_dbc_id = data.getInt(LightDB::DataIDs + param_id); 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) // save LightParams.dbc
continue; // TODO : all params, not just clear.
for (int param_id = 0; param_id < NUM_SkyFloatParamsNames; param_id++)
int light_int_start = lightParam_dbc_id * NUM_SkyColorNames - 17;
for (int i = 0; i < NUM_SkyColorNames; ++i)
{ {
try // skip if no param
{ if (skyParams[param_id] == nullptr)
DBCFile::Record rec = is_new_record ? gLightIntBandDB.addRecord(light_int_start + i) : gLightIntBandDB.getByID(light_int_start + i); continue;
// int entries = rec.getInt(LightIntBandDB::Entries);
int entries = static_cast<int>(skyParams[param_id]->colorRows[i].size());
rec.write(LightIntBandDB::Entries, entries); // nb of entries // 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;
for (int l = 0; l < 16; l++) if (is_new_record) // not for duplicates
{ lightParam_dbc_id = gLightParamsDB.getEmptyRecordID();
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<int>(skyParams[param_id]->colorRows[i][l].color.z * 255.0f)
+ (static_cast<int>(skyParams[param_id]->colorRows[i][l].color.y * 255.0f) << 8)
+ (static_cast<int>(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<int>(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);
}
else 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())); if (lightParam_dbc_id == 0)
light_param.write(LightParamsDB::water_shallow_alpha, skyParams[param_id]->river_shallow_alpha()); continue;
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()); int light_int_start = lightParam_dbc_id * NUM_SkyColorNames - 17;
light_param.write(LightParamsDB::ocean_deep_alpha, skyParams[param_id]->ocean_deep_alpha());
light_param.write(LightParamsDB::glow, skyParams[param_id]->glow()); for (int i = 0; i < NUM_SkyColorNames; ++i)
} {
catch (...) try
{ {
LogError << "When trying to get the skybox for the entry " << lightParam_dbc_id << " in LightParams.dbc. Sad." << std::endl; 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<int>(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<int>(skyParams[param_id]->colorRows[i][l].color.z * 255.0f)
+ (static_cast<int>(skyParams[param_id]->colorRows[i][l].color.y * 255.0f) << 8)
+ (static_cast<int>(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<int>(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;
} }

View File

@@ -1820,12 +1820,19 @@ bool WorldRender::saveMinimap(TileIndex const& tile_idx, MinimapRenderSettings*
} }
// Register in md5translate.trs // Register in md5translate.trs
std::string map_name = gMapDB.getByID(_world->mapIndex._map_id).getString(MapDB::InternalName); try
{
auto sstream = std::stringstream(); std::string map_name = gMapDB.getByID(_world->mapIndex._map_id).getString(MapDB::InternalName);
sstream << map_name << "\\map" << tile_idx.x << "_" << std::setfill('0') << std::setw(2) << tile_idx.z << ".blp"; auto sstream = std::stringstream();
std::string tilename_left = sstream.str(); sstream << map_name << "\\map" << tile_idx.x << "_" << std::setfill('0') << std::setw(2) << tile_idx.z << ".blp";
_world->mapIndex._minimap_md5translate[map_name][tilename_left] = tex_name; 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) if (unload)
{ {

View File

@@ -740,42 +740,46 @@ namespace Noggit
return; return;
} }
DBCFile::Record GErecord try
{
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)
{ {
Weights[i] = GErecord.getUInt(GroundEffectTextureDB::Weights + i); DBCFile::Record GErecord = gGroundEffectTextureDB.getByID(effect_id);
unsigned const curDoodadId Name = std::to_string(effect_id);
{ ID = GErecord.getUInt(GroundEffectTextureDB::ID);
GErecord.getUInt(GroundEffectTextureDB::Doodads + i) Amount = GErecord.getUInt(GroundEffectTextureDB::Amount);
}; TerrainType = GErecord.getUInt(GroundEffectTextureDB::TerrainType);
if (!curDoodadId) for (int i = 0; i < 4; ++i)
{ {
continue; Weights[i] = GErecord.getUInt(GroundEffectTextureDB::Weights + i);
} unsigned const curDoodadId
{
if (!gGroundEffectDoodadDB.CheckIfIdExists(curDoodadId)) GErecord.getUInt(GroundEffectTextureDB::Doodads + i)
{ };
continue;
} if (!curDoodadId)
{
continue;
}
Doodads[i].ID = curDoodadId; if (!gGroundEffectDoodadDB.CheckIfIdExists(curDoodadId))
QString filename = gGroundEffectDoodadDB.getByID(curDoodadId).getString(GroundEffectDoodadDB::Filename); {
continue;
}
Doodads[i].ID = curDoodadId;
QString filename = gGroundEffectDoodadDB.getByID(curDoodadId).getString(GroundEffectDoodadDB::Filename);
filename.replace(".mdx", ".m2", Qt::CaseInsensitive); filename.replace(".mdx", ".m2", Qt::CaseInsensitive);
filename.replace(".mdl", ".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;
} }
} }
} }

View File

@@ -267,29 +267,75 @@ namespace Noggit
void zone_id_browser::add_new_zone() void zone_id_browser::add_new_zone()
{ {
// create new zone area id // create new zone area id
auto new_id = gAreaDB.getEmptyRecordID(); int 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
// locale stuff QDialog* zone_create_params = new QDialog(this);
new_record.writeString(AreaDB::Name, "Unnamed Noggit Zone"); // only write default name for enUS and enGB ? maybe get the client's locale somehow zone_create_params->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
new_record.writeString(AreaDB::Name + 1, "Unnamed Noggit Zone"); // enGB zone_create_params->setWindowTitle("New Zone settings");
new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS QVBoxLayout* zone_create_params_layout = new QVBoxLayout(zone_create_params);
new_record.write(AreaDB::MinElevation, -500.0f); // loc mask, only verified for enUS zone_create_params_layout->addWidget(new QLabel("AreaTable Id : ", zone_create_params));
// save dbc instantly ? QSpinBox* params_id_spinbox = new QSpinBox(zone_create_params);
gAreaDB.save(); params_id_spinbox->setRange(1, std::numeric_limits<int>::max());
// add to tree params_id_spinbox->setValue(new_id);
auto areawidgetitem = add_area(new_id); zone_create_params_layout->addWidget(params_id_spinbox);
// select the new item
_area_tree->clearSelection(); zone_create_params_layout->addWidget(new QLabel("Zone Name : ", zone_create_params));
areawidgetitem->setSelected(true); QLineEdit* params_name_ledit = new QLineEdit(zone_create_params);
open_area_editor();// open the editor 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() 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 std::uint32_t selected_parent_area_id = gAreaDB.get_area_parent(selected_areaid); // the selected area's parentid
if (selected_parent_area_id) if (selected_parent_area_id)
{ {
// error, parent must not have a parent QMessageBox::information
QMessageBox messagebox; (nullptr
messagebox.setIcon(QMessageBox::Information); , "Wrong Parent type"
messagebox.setWindowIcon(QIcon(":/icon")); , "The parent must be a Zone, not a Subzone."
messagebox.setWindowTitle("Wrong Parent type"); , QMessageBox::Ok
messagebox.setText("The parent must be a Zone, not a Subzone."); );
messagebox.exec();
return; return;
} }
auto new_id = gAreaDB.getEmptyRecordID(); int new_id = gAreaDB.getEmptyRecordID();
auto new_record = gAreaDB.addRecord(new_id);
// init some defaults
new_record.write(AreaDB::Continent, mapID);
new_record.write(AreaDB::Region, selected_areaid); // set selecetd area as parent. QDialog* zone_create_params = new QDialog(this);
// get new areabit zone_create_params->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
new_record.write(AreaDB::AreaBit, gAreaDB.get_new_areabit()); zone_create_params->setWindowTitle("New Zone settings");
new_record.write(AreaDB::Flags, 1073759296); // allow dueling + force area on dynamic transport + enable flight bounds+ subzone flags QVBoxLayout* zone_create_params_layout = new QVBoxLayout(zone_create_params);
new_record.write(AreaDB::UnderwaterSoundProviderPreferences, 11); // underwater sound pref, usually set
// lcoale stuff zone_create_params_layout->addWidget(new QLabel("AreaTable Id : ", zone_create_params));
new_record.writeString(AreaDB::Name, "Unnamed Noggit Subzone"); // only write default name for enUS and enGB ? maybe get the client's locale somehow QSpinBox* params_id_spinbox = new QSpinBox(zone_create_params);
new_record.writeString(AreaDB::Name + 1, "Unnamed Noggit Subzone"); // enGB params_id_spinbox->setRange(1, std::numeric_limits<int>::max());
new_record.write(AreaDB::Name + 16, 16712190); // loc mask, only verified for enUS 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) AreaEditor::AreaEditor(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
@@ -490,7 +585,8 @@ namespace Noggit
auto flags_layout = new QVBoxLayout(area_flags_group); auto flags_layout = new QVBoxLayout(area_flags_group);
_flags_value_spinbox = new QSpinBox(this); _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); flags_layout->addWidget(_flags_value_spinbox);
// TODO : update checkboxes when value is changed, temporarly disable it from edit // 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 old_value = _flags_value_spinbox->value();
int new_value = _flags_value_spinbox->value(); int new_value = _flags_value_spinbox->value();
if (state) // set bit if (state) // set bit
new_value |= (1ULL << (i)); new_value |= (1U << (i));
else // remove bit else // remove bit
new_value &= ~(1ULL << (i)); new_value &= ~(1U << (i));
_flags_value_spinbox->setValue(new_value); _flags_value_spinbox->setValue(new_value);
}); });
} }
// hide some useless flags to gain space // hide some useless flags to gain space
flags_checkboxes[30]->setEnabled(false); // user can't set subzone flag. 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[20]->setHidden(true); // tournement realm thingy, useless for pservers
flags_checkboxes[17]->setHidden(true); // "Area not in use", prob some blizz dev stuff 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(ss.str().c_str());
// _parent_area_label->setText(std::to_string( tree_selected_id).c_str()); // _parent_area_label->setText(std::to_string( tree_selected_id).c_str());
auto curr_record = gAreaDB.getByID(_area_id_label->text().toInt()); try
curr_record.write(AreaDB::Region, tree_selected_id); {
// update the tree auto curr_record = gAreaDB.getByID(_area_id_label->text().toInt());
parent->buildAreaList(); curr_record.write(AreaDB::Region, tree_selected_id);
// select the item ? // update the tree
auto item = parent->create_or_get_tree_widget_item(_area_id_label->text().toInt()); parent->buildAreaList();
// parent->selected(_area_id_label->text().toInt()); // 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, [=]() { connect(save_area_button, &QPushButton::clicked, [=]() {
@@ -604,241 +707,253 @@ namespace Noggit
void AreaEditor::load_area(int area_id) void AreaEditor::load_area(int area_id)
{ {
DBCFile::Record record = gAreaDB.getByID(area_id); try
// 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)
{ {
std::stringstream ss; DBCFile::Record record = gAreaDB.getByID(area_id);
ss << _parent_area_id << "-" << gAreaDB.getAreaFullName(_parent_area_id);
_parent_area_label->setText(ss.str().c_str());
}
else
_parent_area_label->setText("-NONE-");
// hide some UI if not subzone _area_id_label->setText(QString(std::to_string(area_id).c_str()));
_set_parent_button->setHidden(_parent_area_id ? false : true);
// _area_name_ledit->setText(record.getString(AreaDB::Name)); _areabit = record.getInt(AreaDB::AreaBit);
_area_name->fill(record, AreaDB::Name);
_flags_value_spinbox->setValue(record.getInt(AreaDB::Flags)); _parent_area_id = record.getInt(AreaDB::Region);
std::bitset<32> IntBits(_flags_value_spinbox->value()); if (_parent_area_id)
for (int i = 0; i < 31; i++) {
flags_checkboxes[i]->setChecked(IntBits[i]); 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); // _area_name_ledit->setText(record.getString(AreaDB::Name));
switch (faction_group_mask) // hardcoded but can be read from factiongroup.dbc _area_name->fill(record, AreaDB::Name);
{
case 2: _flags_value_spinbox->setValue(record.getInt(AreaDB::Flags));
_faction_group_combobox->setCurrentIndex(1);
break; std::bitset<32> IntBits(_flags_value_spinbox->value());
case 4: for (int i = 0; i < 31; i++)
_faction_group_combobox->setCurrentIndex(2); 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; break;
case 6: case 4:
_faction_group_combobox->setCurrentIndex(3); _faction_group_combobox->setCurrentIndex(2);
break; break;
default: case 6:
_faction_group_combobox->setCurrentIndex(0); _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); int sound_provider_id = record.getInt(AreaDB::SoundProviderPreferences);
if (sound_provider_id != 0 && gSoundProviderPreferencesDB.CheckIfIdExists(sound_provider_id)) 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))
{ {
auto sound_entry_day_record = gSoundEntriesDB.getByID(day_sound_id); int row_id = gSoundProviderPreferencesDB.getRecordRowId(sound_provider_id);
std::stringstream ss_day; _sound_provider_preferences_cbbox->setCurrentIndex(row_id + 1); // index 0 = "None"
ss_day << day_sound_id << "-" << sound_entry_day_record.getString(SoundEntriesDB::Name); }
_sound_ambiance_day_button->setText(ss_day.str().c_str()); else
_sound_ambiance_day_button->setProperty("id", day_sound_id); _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 else
{ {
_sound_ambiance_day_button->setText("-NONE-");
_sound_ambiance_day_button->setProperty("id", 0); _sound_ambiance_day_button->setProperty("id", 0);
} _sound_ambiance_day_button->setText("-NONE-");
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); _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() void AreaEditor::save_area()
{ {
DBCFile::Record record = gAreaDB.getByID(_area_id_label->text().toInt()); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id); try
// 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)
{ {
auto rec = gSoundProviderPreferencesDB.getRecord(_sound_provider_preferences_cbbox->currentIndex() - 1); DBCFile::Record record = gAreaDB.getByID(_area_id_label->text().toInt()); // is_new_record ? gLightDB.addRecord(Id) : gLightDB.getByID(Id);
SoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID); // record.write(AreaDB::ID, entry_id);
} // rewrite mapid ?
record.write(AreaDB::SoundProviderPreferences, SoundProviderPreferences_id); record.write(AreaDB::Region, _parent_area_id);
record.write(AreaDB::AreaBit, _areabit);
int underwaterSoundProviderPreferences_id = 0; record.write(AreaDB::Flags, _flags_value_spinbox->value());
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 int SoundProviderPreferences_id = 0;
// Just iterate the DBC to see if an entry with our settings already exists, if not create it. if (_sound_provider_preferences_cbbox->currentIndex() != 0)
// 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 day_id = i->getInt(SoundAmbienceDB::SoundEntry_day); auto rec = gSoundProviderPreferencesDB.getRecord(_sound_provider_preferences_cbbox->currentIndex() - 1);
int night_id = i->getInt(SoundAmbienceDB::SoundEntry_night); SoundProviderPreferences_id = rec.getInt(SoundProviderPreferencesDB::ID);
if (day_id == soundambience_day && night_id == soundambience_night) }
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)); int day_id = i->getInt(SoundAmbienceDB::SoundEntry_day);
sound_ambiance_exists = true; int night_id = i->getInt(SoundAmbienceDB::SoundEntry_night);
break; 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) else
{ record.write(AreaDB::SoundAmbience, 0); // if night or day isn't set, set to 0
// 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); record.write(AreaDB::ZoneMusic, _zone_music_button->property("id").toInt());
gSoundAmbienceDB.save(); record.write(AreaDB::ZoneIntroMusicTable, _zone_intro_music_button->property("id").toInt());
record.write(AreaDB::SoundAmbience, new_id);
} record.write(AreaDB::ExplorationLevel, _exploration_level_spinbox->value());
_area_name->toRecord(record, AreaDB::Name);
// update name in the tree
auto parent = static_cast<zone_id_browser*>(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<float>(_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 catch (AreaDB::NotFound)
record.write(AreaDB::SoundAmbience, 0); // if night or day isn't set, set to 0 {
}
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<zone_id_browser*>(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<float>(_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
} }
} }

View File

@@ -26,7 +26,7 @@ namespace Noggit
namespace Ui namespace Ui
{ {
static std::map <int, std::string> area_flags_names = { static const std::unordered_map <int, std::string> area_flags_names = {
{0 , "Emit Breath Particles"}, {0 , "Emit Breath Particles"},
{1 , "Breath Particles Override Parent"}, {1 , "Breath Particles Override Parent"},
{2 , "On Map Dungeon"}, {2 , "On Map Dungeon"},
@@ -60,7 +60,7 @@ namespace Noggit
{28, "Flying not allowed"}, // in 3.3.5 {28, "Flying not allowed"}, // in 3.3.5
{29, "Only Evaluate Ghost Bind Once"}, {29, "Only Evaluate Ghost Bind Once"},
{30, "Is Subzone"}, {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 class AreaEditor : public QWidget

View File

@@ -409,35 +409,43 @@ LightEditor::LightEditor(MapView* map_view, QWidget* parent)
_curr_sky->curr_sky_param = index; _curr_sky->curr_sky_param = index;
_world->renderer()->skies()->update_sky_colors(_map_view->getCamera()->position, static_cast<int>(_world->time) % 2880); // find how to update sky _world->renderer()->skies()->update_sky_colors(_map_view->getCamera()->position, static_cast<int>(_world->time) % 2880); // find how to update sky
DBCFile::Record data = gLightDB.getByID(_curr_sky->Id); try
int nb_user = 0;
for (DBCFile::Iterator i = gLightDB.begin(); i != gLightDB.end(); ++i)
{ {
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)) for (int l = 0; l < NUM_SkyParamsNames; l++)
nb_user++; {
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); catch (LightDB::NotFound)
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]); assert(false);
//_color_value_Buttons[i]->setText(QString::fromStdString(std::format("{} / 16 values", sky_param->colorRows[i].size())));
} }
}); });
connect(SaveCurrentSkyButton, &QPushButton::clicked, [=]() { connect(SaveCurrentSkyButton, &QPushButton::clicked, [=]() {

View File

@@ -639,33 +639,43 @@ void MapCreationWizard::saveCurrentEntry()
_world->mapIndex.create_empty_wdl(); _world->mapIndex.create_empty_wdl();
// Save Map.dbc record // 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::AreaType, _instance_type->itemData(_instance_type->currentIndex()).toInt());
record.write(MapDB::Flags, _sort_by_size_cat->isChecked() ? 16 : 0 ); record.write(MapDB::Flags, _sort_by_size_cat->isChecked() ? 16 : 0 );
_map_name->toRecord(record, MapDB::Name); _map_name->toRecord(record, MapDB::Name);
record.write(MapDB::AreaTableID, _area_table_id->value()); record.write(MapDB::AreaTableID, _area_table_id->value());
_map_desc_alliance->toRecord(record, MapDB::MapDescriptionAlliance); _map_desc_alliance->toRecord(record, MapDB::MapDescriptionAlliance);
_map_desc_horde->toRecord(record, MapDB::MapDescriptionHorde); _map_desc_horde->toRecord(record, MapDB::MapDescriptionHorde);
record.write(MapDB::LoadingScreen, _loading_screen->value()); record.write(MapDB::LoadingScreen, _loading_screen->value());
record.write(MapDB::minimapIconScale, static_cast<float>(_minimap_icon_scale->value())); record.write(MapDB::minimapIconScale, static_cast<float>(_minimap_icon_scale->value()));
record.write(MapDB::corpseMapID, _corpse_map_id->itemData(_corpse_map_id->currentIndex()).toInt()); record.write(MapDB::corpseMapID, _corpse_map_id->itemData(_corpse_map_id->currentIndex()).toInt());
record.write(MapDB::corpseX, static_cast<float>(_corpse_x->value())); record.write(MapDB::corpseX, static_cast<float>(_corpse_x->value()));
record.write(MapDB::corpseY, static_cast<float>(_corpse_y->value())); record.write(MapDB::corpseY, static_cast<float>(_corpse_y->value()));
record.write(MapDB::TimeOfDayOverride, _time_of_day_override->value()); record.write(MapDB::TimeOfDayOverride, _time_of_day_override->value());
record.write(MapDB::ExpansionID, _expansion_id->itemData(_expansion_id->currentIndex()).toInt()); record.write(MapDB::ExpansionID, _expansion_id->itemData(_expansion_id->currentIndex()).toInt());
record.write(MapDB::RaidOffset, _raid_offset->value()); record.write(MapDB::RaidOffset, _raid_offset->value());
record.write(MapDB::NumberOfPlayers, _max_players->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() void MapCreationWizard::discardChanges()
@@ -831,6 +841,11 @@ LocaleDBCEntry::LocaleDBCEntry(QWidget* parent) : QWidget(parent)
}; };
layout->addWidget(_current_locale); 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
connect ( _current_locale, &QComboBox::currentTextChanged connect ( _current_locale, &QComboBox::currentTextChanged

View File

@@ -301,8 +301,6 @@ namespace Noggit
void SoundEntryPickerWindow::select_entry(int id) void SoundEntryPickerWindow::select_entry(int id)
{ {
_entry_id = id;
if (id != 0) if (id != 0)
{ {
// _picker_listview->setCurrentRow(0); // _picker_listview->setCurrentRow(0);
@@ -315,119 +313,134 @@ namespace Noggit
return; return;
} }
_entry_id_lbl->setText(QString(std::to_string(id).c_str())); try
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)
{ {
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); if (sound_type.first == sound_type_id)
break; {
_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);
} }
catch (SoundEntriesDB::NotFound)
_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);
} }
void SoundEntryPickerWindow::save_entry(int entry_id) void SoundEntryPickerWindow::save_entry(int entry_id)
{ {
DBCFile::Record record = gSoundEntriesDB.getByID(entry_id); try
record.write(SoundEntriesDB::ID, entry_id);
int sound_type_id = 0;
int row_id = 0;
for (auto sound_type : sound_types_names)
{ {
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; if (row_id == _sound_type_cbbox->currentIndex())
break; {
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<float>(_min_distance_spinbox->value()));
record.write(SoundEntriesDB::distanceCutoff, static_cast<float>(_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); catch (SoundEntriesDB::NotFound)
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<float>(_min_distance_spinbox->value()));
record.write(SoundEntriesDB::distanceCutoff, static_cast<float>(_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() void SoundEntryPickerWindow::update_files_count()

View File

@@ -196,55 +196,80 @@ namespace Noggit
void ZoneIntroMusicPickerWindow::select_entry(int id) 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 else
{ {
_picker_listview->setCurrentRow(0); _picker_listview->setCurrentRow(0);
return; return;
} }
_entry_id_lbl->setText(QString(std::to_string(id).c_str())); try
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))
{ {
DBCFile::Record sound_record = gSoundEntriesDB.getByID(sound_entry); DBCFile::Record record = gZoneIntroMusicTableDB.getByID(id);
std::stringstream ss;
ss << sound_entry << "-" << sound_record.getString(SoundEntriesDB::Name); _entry_id = id;
_sound_button->setText(ss.str().c_str()); _entry_id_lbl->setText(QString(std::to_string(id).c_str()));
_sound_button->setProperty("id", sound_entry);
_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) 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.write(ZoneIntroMusicTableDB::ID, entry_id);
record.writeString(ZoneIntroMusicTableDB::Name, _name_ledit->text().toStdString()); record.writeString(ZoneIntroMusicTableDB::Name, _name_ledit->text().toStdString());
record.write(ZoneIntroMusicTableDB::SoundId, _sound_button->property("id").toInt()); record.write(ZoneIntroMusicTableDB::SoundId, _sound_button->property("id").toInt());
record.write(ZoneIntroMusicTableDB::Priority, _priority); record.write(ZoneIntroMusicTableDB::Priority, _priority);
record.write(ZoneIntroMusicTableDB::MinDelayMinutes, _min_delay_spinbox->value()); record.write(ZoneIntroMusicTableDB::MinDelayMinutes, _min_delay_spinbox->value());
gZoneIntroMusicTableDB.save(); gZoneIntroMusicTableDB.save();
}
catch (ZoneIntroMusicTableDB::NotFound)
{
}
} }
} }
} }

View File

@@ -251,76 +251,96 @@ namespace Noggit
} }
void ZoneMusicPickerWindow::select_entry(int id) 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 else
{ {
_picker_listview->setCurrentRow(0); _picker_listview->setCurrentRow(0);
return; return;
} }
_entry_id_lbl->setText(QString(std::to_string(id).c_str())); try
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
{ {
DBCFile::Record day_sound_record = gSoundEntriesDB.getByID(day_sound_entry); DBCFile::Record record = gZoneMusicDB.getByID(id);
std::stringstream ss_day;
ss_day << day_sound_entry << "-" << day_sound_record.getString(SoundEntriesDB::Name); _entry_id = id;
_day_music_button->setText(ss_day.str().c_str()); _entry_id_lbl->setText(QString(std::to_string(id).c_str()));
_day_music_button->setProperty("id", day_sound_entry);
_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) 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.write(ZoneMusicDB::ID, entry_id);
record.writeString(ZoneMusicDB::Name, _name_ledit->text().toStdString()); record.writeString(ZoneMusicDB::Name, _name_ledit->text().toStdString());
record.write(ZoneMusicDB::SilenceIntervalMinDay, _day_min_interval_spinbox->value()); record.write(ZoneMusicDB::SilenceIntervalMinDay, _day_min_interval_spinbox->value());
record.write(ZoneMusicDB::SilenceIntervalMaxDay, _day_max_interval_spinbox->value()); record.write(ZoneMusicDB::SilenceIntervalMaxDay, _day_max_interval_spinbox->value());
record.write(ZoneMusicDB::SilenceIntervalMinNight, _night_min_interval_spinbox->value()); record.write(ZoneMusicDB::SilenceIntervalMinNight, _night_min_interval_spinbox->value());
record.write(ZoneMusicDB::SilenceIntervalMaxNight, _night_max_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::DayMusic, _day_music_button->property("id").toInt());
record.write(ZoneMusicDB::NightMusic, _night_music_button->property("id").toInt()); record.write(ZoneMusicDB::NightMusic, _night_music_button->property("id").toInt());
gZoneMusicDB.save(); gZoneMusicDB.save();
}
catch (ZoneMusicDB::NotFound)
{
}
} }
} }
} }

View File

@@ -130,27 +130,35 @@ namespace Noggit
} }
// get files list // get files list
DBCFile::Record sound_entry_record = gSoundEntriesDB.getByID(sound_entry_id); try
_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::string filename = sound_entry_record.getString(SoundEntriesDB::Filenames + fileid); DBCFile::Record sound_entry_record = gSoundEntriesDB.getByID(sound_entry_id);
if (!filename.empty())
_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; std::string filename = sound_entry_record.getString(SoundEntriesDB::Filenames + fileid);
// ss_filepath << directory << "\\" << filename; if (!filename.empty())
// music_files.push_back(ss_filepah.str()); {
// music_files.push_back(filename); // std::stringstream ss_filepah;
_files_listview->addItem(filename.c_str()); // 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); catch (SoundEntriesDB::NotFound)
play_selected_sound(); {
}
} }
void SoundEntryPlayer::PlaySingleSoundFile(std::string filepath, std::string dir_path) void SoundEntryPlayer::PlaySingleSoundFile(std::string filepath, std::string dir_path)