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())); playerInfo.allowedFactions.erase(FactionID(item->data(Qt::UserRole).toInt()));
} }
void PlayerParams::on_mainTown_currentIndexChanged(int index)
void PlayerParams::on_mainTown_activated(int index)
{ {
if(index == 0) //default if(index == 0) //default
{ {
@ -198,16 +197,12 @@ void PlayerParams::on_townSelect_clicked()
return false; return false;
}; };
std::vector<std::reference_wrapper<ObjectPickerLayer>> pickers; for(int lvl : {0, 1})
pickers.emplace_back(controller.scene(0)->objectPickerView);
if(controller.map()->twoLevel)
pickers.emplace_back(controller.scene(1)->objectPickerView);
for(auto l : pickers)
{ {
l.get().highlight(pred); auto & l = controller.scene(lvl)->objectPickerView;
l.get().update(); l.highlight(pred);
QObject::connect(&l.get(), &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked); l.update();
QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
} }
dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->hide(); 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(); dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->show();
std::vector<std::reference_wrapper<ObjectPickerLayer>> pickers; for(int lvl : {0, 1})
pickers.emplace_back(controller.scene(0)->objectPickerView);
if(controller.map()->twoLevel)
pickers.emplace_back(controller.scene(1)->objectPickerView);
for(auto l : pickers)
{ {
l.get().clear(); auto & l = controller.scene(lvl)->objectPickerView;
l.get().update(); l.clear();
QObject::disconnect(&l.get(), &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked); l.update();
QObject::disconnect(&l, &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
} }
if(!obj) //discarded if(!obj) //discarded
return; 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_radioCpu_toggled(bool checked);
void on_mainTown_activated(int index); void on_mainTown_currentIndexChanged(int index);
void on_generateHero_stateChanged(int arg1); void on_generateHero_stateChanged(int arg1);

View File

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