map creation improvements:
- add default light.dbc entry - add default map name - set default directory name to an unused one - fix loc string flags - when a map is created select and load it - init max uid to skip the UID popup for new maps - correctly reset the map render grid
This commit is contained in:
@@ -107,7 +107,7 @@ public:
|
||||
file.stringSize += static_cast<std::uint32_t>(val.size() + 1);
|
||||
}
|
||||
|
||||
void writeLocalizedString(size_t field, const std::string& val, int locale)
|
||||
void writeLocalizedString(size_t field, const std::string& val, unsigned int locale)
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
assert(locale < 16);
|
||||
|
||||
@@ -246,11 +246,14 @@ void map_horizon::update_minimap_tile(int y, int x, bool has_data = false )
|
||||
}
|
||||
}
|
||||
|
||||
void map_horizon::set_minimap(const MapIndex* const index)
|
||||
void map_horizon::set_minimap(const MapIndex* const index, bool set_empty)
|
||||
{
|
||||
_qt_minimap = QImage(16 * 64, 16 * 64, QImage::Format_ARGB32);
|
||||
_qt_minimap.fill(Qt::transparent);
|
||||
|
||||
if (set_empty)
|
||||
return;
|
||||
|
||||
for (int y(0); y < 64; ++y)
|
||||
{
|
||||
for (int x(0); x < 64; ++x)
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
void update_minimap_tile(int y, int x, bool has_data);
|
||||
|
||||
void set_minimap(const MapIndex* const index);
|
||||
void set_minimap(const MapIndex* const index, bool set_empty = false);
|
||||
|
||||
void remove_horizon_tile(int y, int x);
|
||||
|
||||
|
||||
@@ -635,9 +635,39 @@ void MapCreationWizard::saveCurrentEntry()
|
||||
_world->mapIndex.set_sort_models_by_size_class(_sort_by_size_cat->isChecked());
|
||||
_world->mapIndex.saveChanged(_world, true);
|
||||
_world->mapIndex.save(); // save wdt file
|
||||
// create default wdl
|
||||
|
||||
if (_is_new_record)
|
||||
_world->mapIndex.create_empty_wdl();
|
||||
{
|
||||
_world->mapIndex.create_empty_wdl(); // create default wdl
|
||||
|
||||
// save default maxguid to avoid the uid fix popup
|
||||
_world->mapIndex.saveMaxUID();
|
||||
|
||||
// TODO save mapdifficulty.dbc
|
||||
//
|
||||
|
||||
// save default global light.dbc entry for new maps
|
||||
try
|
||||
{
|
||||
int new_id = gLightDB.getEmptyRecordID();
|
||||
DBCFile::Record record = gLightDB.addRecord(new_id);
|
||||
record.write(LightDB::Map, _cur_map_id);
|
||||
// positions and falloffs should be defaulted to 0
|
||||
// set some default light params to the same as eastern kingdom
|
||||
record.write(LightDB::DataIDs + 0, 12);// CLEAR
|
||||
record.write(LightDB::DataIDs + 1, 13);// CLEAR_WATER,
|
||||
record.write(LightDB::DataIDs + 2, 10);// STORM,
|
||||
record.write(LightDB::DataIDs + 3, 13);// STORM_WATER,
|
||||
record.write(LightDB::DataIDs + 4, 4);// DEATH,
|
||||
|
||||
gLightDB.save();
|
||||
}
|
||||
catch (LightDB::AlreadyExists)
|
||||
{
|
||||
assert(false);
|
||||
LogError << "Light.dbc entry already exists, failed to add record" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Save Map.dbc record
|
||||
try
|
||||
@@ -665,17 +695,28 @@ void MapCreationWizard::saveCurrentEntry()
|
||||
|
||||
gMapDB.save();
|
||||
|
||||
emit map_dbc_updated();
|
||||
// reloads map list, and selects the new map
|
||||
emit map_dbc_updated(_cur_map_id);
|
||||
|
||||
_is_new_record = false;
|
||||
}
|
||||
catch (MapDB::AlreadyExists)
|
||||
{
|
||||
|
||||
QMessageBox::information(this
|
||||
, "Error"
|
||||
, QString("A map with Id %1 already exists").arg(_cur_map_id)
|
||||
, QMessageBox::Ok
|
||||
);
|
||||
}
|
||||
catch (MapDB::NotFound)
|
||||
{
|
||||
LogError << "Map.dbc entry " << _cur_map_id << " was not found" << std::endl;
|
||||
|
||||
QMessageBox::information(this
|
||||
, "Error"
|
||||
, QString("Map.dbc entry %1 was not found").arg(_cur_map_id)
|
||||
, QMessageBox::Ok
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,10 +749,25 @@ void MapCreationWizard::addNewMap()
|
||||
delete _world;
|
||||
}
|
||||
|
||||
_world = new World("New_Map", _cur_map_id, Noggit::NoggitRenderContext::MAP_VIEW, true);
|
||||
// default to a new internal map name that isn't already used, or default world will load existing files
|
||||
std::string const base_name = "New_Map";
|
||||
std::string internal_map_name = base_name;
|
||||
int id = gMapDB.findMapName(internal_map_name);
|
||||
|
||||
int suffix = 1;
|
||||
while (id >= 0) {
|
||||
internal_map_name = base_name + std::to_string(suffix); // Append the current suffix to the base name
|
||||
id = gMapDB.findMapName(internal_map_name); // Check if the name exists
|
||||
suffix++; // Increment the suffix for the next iteration
|
||||
}
|
||||
|
||||
_world = new World(internal_map_name, _cur_map_id, Noggit::NoggitRenderContext::MAP_VIEW, true);
|
||||
// hack to reset the minimap if there is an existing WDL with the same path(happens when removing a map from map.dbc but not the files
|
||||
_world->horizon.set_minimap(&_world->mapIndex, true);
|
||||
|
||||
_minimap_widget->world(_world);
|
||||
|
||||
_directory->setText("New_Map");
|
||||
_directory->setText(internal_map_name.c_str());
|
||||
_directory->setEnabled(true);
|
||||
|
||||
_is_big_alpha->setChecked(true);
|
||||
@@ -721,7 +777,7 @@ void MapCreationWizard::addNewMap()
|
||||
|
||||
_instance_type->setCurrentIndex(0);
|
||||
|
||||
_map_name->clear();
|
||||
_map_name->setDefaultLocValue("Unnamed Noggit Map");
|
||||
_area_table_id->setValue(0);
|
||||
|
||||
_map_desc_alliance->clear();
|
||||
@@ -905,6 +961,18 @@ void LocaleDBCEntry::toRecord(DBCFile::Record &record, size_t field)
|
||||
record.write(field + 16, _flags->value());
|
||||
}
|
||||
|
||||
void LocaleDBCEntry::setDefaultLocValue(const std::string& text)
|
||||
{
|
||||
// set the default locale's widget text and select it, but don't write data.
|
||||
|
||||
int locale_id = Noggit::Application::NoggitApplication::instance()->clientData()->getLocaleId();
|
||||
_current_locale->setCurrentIndex(locale_id);
|
||||
setCurrentLocale(_locale_names[locale_id]);
|
||||
|
||||
// fill default locale's line edit
|
||||
setValue(text, locale_id);
|
||||
}
|
||||
|
||||
void LocaleDBCEntry::clear()
|
||||
{
|
||||
for (int loc = 0; loc < 16; ++loc)
|
||||
|
||||
@@ -40,6 +40,11 @@ namespace Noggit
|
||||
void setValue(const std::string& val, int locale)
|
||||
{
|
||||
_widget_map.at(_locale_names[locale])->setText(QString::fromStdString(val));
|
||||
|
||||
if (!val.empty() && _flags->value() == 0)
|
||||
{
|
||||
_flags->setValue(16712190); // default flags when there is text
|
||||
}
|
||||
}
|
||||
|
||||
std::string getValue(int locale) { return _widget_map.at(_locale_names[locale])->text().toStdString(); };
|
||||
@@ -48,6 +53,7 @@ namespace Noggit
|
||||
void fill(BlizzardDatabaseLib::Structures::BlizzardDatabaseRow& record, std::string columnName);
|
||||
void clear();
|
||||
void toRecord(DBCFile::Record& record, size_t field);
|
||||
void setDefaultLocValue(const std::string& text);
|
||||
|
||||
private:
|
||||
QComboBox* _current_locale;
|
||||
@@ -89,7 +95,7 @@ namespace Noggit
|
||||
void destroyFakeWorld() { if(_world) delete _world; _world = nullptr; _minimap_widget->world (nullptr); };
|
||||
void addNewMap();
|
||||
signals:
|
||||
void map_dbc_updated();
|
||||
void map_dbc_updated(int new_map = 0);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Project::NoggitProject> _project;
|
||||
|
||||
@@ -467,11 +467,28 @@ namespace Noggit::Ui::Windows
|
||||
_map_creation_wizard = new Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard(_project, this);
|
||||
|
||||
_map_wizard_connection = connect(_map_creation_wizard,
|
||||
&Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard::map_dbc_updated, [=]
|
||||
&Noggit::Ui::Tools::MapCreationWizard::Ui::MapCreationWizard::map_dbc_updated,
|
||||
[this](int map_id)
|
||||
{
|
||||
_buildMapListComponent->buildMapList(this);
|
||||
}
|
||||
);
|
||||
|
||||
// if a new map was added select it
|
||||
if (map_id)
|
||||
{
|
||||
for (int i = 0; i < _continents_table->count(); ++i)
|
||||
{
|
||||
QListWidgetItem* item = _continents_table->item(i);
|
||||
if (item && item->data(Qt::UserRole).toInt() == map_id)
|
||||
{
|
||||
_continents_table->setCurrentItem(item);
|
||||
_continents_table->scrollToItem(item);
|
||||
_right_side->setCurrentIndex(0); // swap to "enter map" tab
|
||||
loadMap(map_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_right_side->addTab(_map_creation_wizard, "Edit map");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user