1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Town picker in player settings implemented

This commit is contained in:
nordsoft 2023-09-11 18:44:55 +02:00
parent 727284c05e
commit 3024aaae30
3 changed files with 34 additions and 31 deletions

View File

@ -151,8 +151,7 @@ void PlayerParams::allowedFactionsCheck(QListWidgetItem * item)
playerInfo.allowedFactions.erase(FactionID(item->data(Qt::UserRole).toInt()));
}
void PlayerParams::on_mainTown_activated(int index)
void PlayerParams::on_mainTown_currentIndexChanged(int index)
{
if(index == 0) //default
{
@ -198,16 +197,12 @@ void PlayerParams::on_townSelect_clicked()
return false;
};
std::vector<std::reference_wrapper<ObjectPickerLayer>> pickers;
pickers.emplace_back(controller.scene(0)->objectPickerView);
if(controller.map()->twoLevel)
pickers.emplace_back(controller.scene(1)->objectPickerView);
for(auto l : pickers)
for(int lvl : {0, 1})
{
l.get().highlight(pred);
l.get().update();
QObject::connect(&l.get(), &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
auto & l = controller.scene(lvl)->objectPickerView;
l.highlight(pred);
l.update();
QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
}
dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->hide();
@ -217,20 +212,25 @@ void PlayerParams::onTownPicked(const CGObjectInstance * obj)
{
dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->show();
std::vector<std::reference_wrapper<ObjectPickerLayer>> pickers;
pickers.emplace_back(controller.scene(0)->objectPickerView);
if(controller.map()->twoLevel)
pickers.emplace_back(controller.scene(1)->objectPickerView);
for(auto l : pickers)
for(int lvl : {0, 1})
{
l.get().clear();
l.get().update();
QObject::disconnect(&l.get(), &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
auto & l = controller.scene(lvl)->objectPickerView;
l.clear();
l.update();
QObject::disconnect(&l, &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
}
if(!obj) //discarded
return;
for(int i = 0; i < ui->mainTown->count(); ++i)
{
auto town = controller.map()->objects.at(ui->mainTown->itemData(i).toInt());
if(town == obj)
{
ui->mainTown->setCurrentIndex(i);
break;
}
}
}

View File

@ -36,7 +36,7 @@ private slots:
void on_radioCpu_toggled(bool checked);
void on_mainTown_activated(int index);
void on_mainTown_currentIndexChanged(int index);
void on_generateHero_stateChanged(int arg1);

View File

@ -121,17 +121,20 @@ void ObjectPickerLayer::highlight(std::function<bool(const CGObjectInstance *)>
if(!map)
return;
for(int j = 0; j < map->height; ++j)
if(scene->level == 0 || map->twoLevel)
{
for(int i = 0; i < map->width; ++i)
for(int j = 0; j < map->height; ++j)
{
auto tl = map->getTile(int3(i, j, scene->level));
auto * obj = tl.topVisitableObj();
if(!obj && !tl.blockingObjects.empty())
obj = tl.blockingObjects.front();
if(obj && predicate(obj))
possibleObjects.insert(obj);
for(int i = 0; i < map->width; ++i)
{
auto tl = map->getTile(int3(i, j, scene->level));
auto * obj = tl.topVisitableObj();
if(!obj && !tl.blockingObjects.empty())
obj = tl.blockingObjects.front();
if(obj && predicate(obj))
possibleObjects.insert(obj);
}
}
}