mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Fix code review problems
This commit is contained in:
@@ -33,14 +33,14 @@ RewardsWidget::~RewardsWidget()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> RewardsWidget::getListForType(int typeId)
|
QList<QString> RewardsWidget::getListForType(RewardType typeId)
|
||||||
{
|
{
|
||||||
assert(typeId < rewardTypes.size());
|
assert(typeId < rewardTypes.size());
|
||||||
QList<QString> result;
|
QList<QString> result;
|
||||||
|
|
||||||
switch (typeId) {
|
switch (typeId) {
|
||||||
case 4: //resources
|
case RewardType::RESOURCE:
|
||||||
//to convert string to index WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL,
|
//to convert string to index WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL,
|
||||||
result.append("Wood");
|
result.append("Wood");
|
||||||
result.append("Mercury");
|
result.append("Mercury");
|
||||||
result.append("Ore");
|
result.append("Ore");
|
||||||
@@ -50,13 +50,12 @@ QList<QString> RewardsWidget::getListForType(int typeId)
|
|||||||
result.append("Gold");
|
result.append("Gold");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case RewardType::PRIMARY_SKILL:
|
||||||
for(auto s : PrimarySkill::names)
|
for(auto s : PrimarySkill::names)
|
||||||
result.append(QString::fromStdString(s));
|
result.append(QString::fromStdString(s));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case RewardType::SECONDARY_SKILL:
|
||||||
//abilities
|
|
||||||
for(int i = 0; i < map.allowedAbilities.size(); ++i)
|
for(int i = 0; i < map.allowedAbilities.size(); ++i)
|
||||||
{
|
{
|
||||||
if(map.allowedAbilities[i])
|
if(map.allowedAbilities[i])
|
||||||
@@ -64,8 +63,7 @@ QList<QString> RewardsWidget::getListForType(int typeId)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case RewardType::ARTIFACT:
|
||||||
//arts
|
|
||||||
for(int i = 0; i < map.allowedArtifact.size(); ++i)
|
for(int i = 0; i < map.allowedArtifact.size(); ++i)
|
||||||
{
|
{
|
||||||
if(map.allowedArtifact[i])
|
if(map.allowedArtifact[i])
|
||||||
@@ -73,8 +71,7 @@ QList<QString> RewardsWidget::getListForType(int typeId)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case RewardType::SPELL:
|
||||||
//spells
|
|
||||||
for(int i = 0; i < map.allowedSpell.size(); ++i)
|
for(int i = 0; i < map.allowedSpell.size(); ++i)
|
||||||
{
|
{
|
||||||
if(map.allowedSpell[i])
|
if(map.allowedSpell[i])
|
||||||
@@ -82,8 +79,7 @@ QList<QString> RewardsWidget::getListForType(int typeId)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 9:
|
case RewardType::CREATURE:
|
||||||
//creatures
|
|
||||||
for(auto creature : VLC->creh->objects)
|
for(auto creature : VLC->creh->objects)
|
||||||
{
|
{
|
||||||
result.append(QString::fromStdString(creature->getName()));
|
result.append(QString::fromStdString(creature->getName()));
|
||||||
@@ -99,7 +95,7 @@ void RewardsWidget::on_rewardType_activated(int index)
|
|||||||
ui->rewardList->setEnabled(true);
|
ui->rewardList->setEnabled(true);
|
||||||
assert(index < rewardTypes.size());
|
assert(index < rewardTypes.size());
|
||||||
|
|
||||||
auto l = getListForType(index);
|
auto l = getListForType(RewardType(index));
|
||||||
if(l.empty())
|
if(l.empty())
|
||||||
ui->rewardList->setEnabled(false);
|
ui->rewardList->setEnabled(false);
|
||||||
|
|
||||||
@@ -112,40 +108,40 @@ void RewardsWidget::obtainData()
|
|||||||
if(pandora)
|
if(pandora)
|
||||||
{
|
{
|
||||||
if(pandora->gainedExp > 0)
|
if(pandora->gainedExp > 0)
|
||||||
addReward(0, 0, pandora->gainedExp);
|
addReward(RewardType::EXPERIENCE, 0, pandora->gainedExp);
|
||||||
if(pandora->manaDiff)
|
if(pandora->manaDiff)
|
||||||
addReward(1, 0, pandora->manaDiff);
|
addReward(RewardType::MANA, 0, pandora->manaDiff);
|
||||||
if(pandora->moraleDiff)
|
if(pandora->moraleDiff)
|
||||||
addReward(2, 0, pandora->moraleDiff);
|
addReward(RewardType::MORALE, 0, pandora->moraleDiff);
|
||||||
if(pandora->luckDiff)
|
if(pandora->luckDiff)
|
||||||
addReward(3, 0, pandora->luckDiff);
|
addReward(RewardType::LUCK, 0, pandora->luckDiff);
|
||||||
if(pandora->resources.nonZero())
|
if(pandora->resources.nonZero())
|
||||||
{
|
{
|
||||||
for(Res::ResourceSet::nziterator resiter(pandora->resources); resiter.valid(); ++resiter)
|
for(Res::ResourceSet::nziterator resiter(pandora->resources); resiter.valid(); ++resiter)
|
||||||
addReward(4, resiter->resType, resiter->resVal);
|
addReward(RewardType::RESOURCE, resiter->resType, resiter->resVal);
|
||||||
}
|
}
|
||||||
for(int idx = 0; idx < pandora->primskills.size(); ++idx)
|
for(int idx = 0; idx < pandora->primskills.size(); ++idx)
|
||||||
{
|
{
|
||||||
if(pandora->primskills[idx])
|
if(pandora->primskills[idx])
|
||||||
addReward(5, idx, pandora->primskills[idx]);
|
addReward(RewardType::PRIMARY_SKILL, idx, pandora->primskills[idx]);
|
||||||
}
|
}
|
||||||
assert(pandora->abilities.size() == pandora->abilityLevels.size());
|
assert(pandora->abilities.size() == pandora->abilityLevels.size());
|
||||||
for(int idx = 0; idx < pandora->abilities.size(); ++idx)
|
for(int idx = 0; idx < pandora->abilities.size(); ++idx)
|
||||||
{
|
{
|
||||||
addReward(6, pandora->abilities[idx].getNum(), pandora->abilityLevels[idx]);
|
addReward(RewardType::SECONDARY_SKILL, pandora->abilities[idx].getNum(), pandora->abilityLevels[idx]);
|
||||||
}
|
}
|
||||||
for(auto art : pandora->artifacts)
|
for(auto art : pandora->artifacts)
|
||||||
{
|
{
|
||||||
addReward(7, art.getNum(), 1);
|
addReward(RewardType::ARTIFACT, art.getNum(), 1);
|
||||||
}
|
}
|
||||||
for(auto spell : pandora->spells)
|
for(auto spell : pandora->spells)
|
||||||
{
|
{
|
||||||
addReward(8, spell.getNum(), 1);
|
addReward(RewardType::SPELL, spell.getNum(), 1);
|
||||||
}
|
}
|
||||||
for(int i = 0; i < pandora->creatures.Slots().size(); ++i)
|
for(int i = 0; i < pandora->creatures.Slots().size(); ++i)
|
||||||
{
|
{
|
||||||
if(auto c = pandora->creatures.getCreature(SlotID(i)))
|
if(auto c = pandora->creatures.getCreature(SlotID(i)))
|
||||||
addReward(9, c->getId(), pandora->creatures.getStackCount(SlotID(i)));
|
addReward(RewardType::CREATURE, c->getId(), pandora->creatures.getStackCount(SlotID(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,44 +167,44 @@ bool RewardsWidget::commitChanges()
|
|||||||
int amount = ui->rewardsTable->item(row, 2)->data(Qt::UserRole).toInt();
|
int amount = ui->rewardsTable->item(row, 2)->data(Qt::UserRole).toInt();
|
||||||
switch(typeId)
|
switch(typeId)
|
||||||
{
|
{
|
||||||
case 0:
|
case RewardType::EXPERIENCE:
|
||||||
pandora->gainedExp = amount;
|
pandora->gainedExp = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case RewardType::MANA:
|
||||||
pandora->manaDiff = amount;
|
pandora->manaDiff = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case RewardType::MORALE:
|
||||||
pandora->moraleDiff = amount;
|
pandora->moraleDiff = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case RewardType::LUCK:
|
||||||
pandora->luckDiff = amount;
|
pandora->luckDiff = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case RewardType::RESOURCE:
|
||||||
pandora->resources.at(listId) = amount;
|
pandora->resources.at(listId) = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case RewardType::PRIMARY_SKILL:
|
||||||
pandora->primskills[listId] = amount;
|
pandora->primskills[listId] = amount;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case RewardType::SECONDARY_SKILL:
|
||||||
pandora->abilities.push_back(SecondarySkill(listId));
|
pandora->abilities.push_back(SecondarySkill(listId));
|
||||||
pandora->abilityLevels.push_back(amount);
|
pandora->abilityLevels.push_back(amount);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case RewardType::ARTIFACT:
|
||||||
pandora->artifacts.push_back(ArtifactID(listId));
|
pandora->artifacts.push_back(ArtifactID(listId));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case RewardType::SPELL:
|
||||||
pandora->spells.push_back(SpellID(listId));
|
pandora->spells.push_back(SpellID(listId));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 9:
|
case RewardType::CREATURE:
|
||||||
auto slot = pandora->creatures.getFreeSlot();
|
auto slot = pandora->creatures.getFreeSlot();
|
||||||
if(slot != SlotID() && amount > 0)
|
if(slot != SlotID() && amount > 0)
|
||||||
pandora->creatures.addToSlot(slot, CreatureID(listId), amount);
|
pandora->creatures.addToSlot(slot, CreatureID(listId), amount);
|
||||||
@@ -224,7 +220,7 @@ void RewardsWidget::on_rewardList_activated(int index)
|
|||||||
ui->rewardAmount->setText(QStringLiteral("1"));
|
ui->rewardAmount->setText(QStringLiteral("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewardsWidget::addReward(int typeId, int listId, int amount)
|
void RewardsWidget::addReward(RewardsWidget::RewardType typeId, int listId, int amount)
|
||||||
{
|
{
|
||||||
ui->rewardsTable->setRowCount(++rewards);
|
ui->rewardsTable->setRowCount(++rewards);
|
||||||
|
|
||||||
@@ -266,7 +262,7 @@ void RewardsWidget::addReward(int typeId, int listId, int amount)
|
|||||||
|
|
||||||
void RewardsWidget::on_buttonAdd_clicked()
|
void RewardsWidget::on_buttonAdd_clicked()
|
||||||
{
|
{
|
||||||
addReward(ui->rewardType->currentIndex(), ui->rewardList->currentIndex(), ui->rewardAmount->text().toInt());
|
addReward(RewardType(ui->rewardType->currentIndex()), ui->rewardList->currentIndex(), ui->rewardAmount->text().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,20 +15,6 @@
|
|||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RewardsWidget;
|
class RewardsWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
ui32 gainedExp;
|
|
||||||
si32 manaDiff; //amount of gained / lost mana
|
|
||||||
si32 moraleDiff; //morale modifier
|
|
||||||
si32 luckDiff; //luck modifier
|
|
||||||
TResources resources;//gained / lost resources
|
|
||||||
std::vector<si32> primskills;//gained / lost prim skills
|
|
||||||
std::vector<SecondarySkill> abilities; //gained abilities
|
|
||||||
std::vector<si32> abilityLevels; //levels of gained abilities
|
|
||||||
std::vector<ArtifactID> artifacts; //gained artifacts
|
|
||||||
std::vector<SpellID> spells; //gained spells
|
|
||||||
CCreatureSet creatures; //gained creatures
|
|
||||||
*/
|
|
||||||
|
|
||||||
const std::array<std::string, 10> rewardTypes{"Experience", "Mana", "Morale", "Luck", "Resource", "Primary skill", "Secondary skill", "Artifact", "Spell", "Creature"};
|
const std::array<std::string, 10> rewardTypes{"Experience", "Mana", "Morale", "Luck", "Resource", "Primary skill", "Secondary skill", "Artifact", "Spell", "Creature"};
|
||||||
|
|
||||||
@@ -37,6 +23,11 @@ class RewardsWidget : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum RewardType
|
||||||
|
{
|
||||||
|
EXPERIENCE = 0, MANA, MORALE, LUCK, RESOURCE, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE
|
||||||
|
};
|
||||||
|
|
||||||
explicit RewardsWidget(const CMap &, CGPandoraBox &, QWidget *parent = nullptr);
|
explicit RewardsWidget(const CMap &, CGPandoraBox &, QWidget *parent = nullptr);
|
||||||
~RewardsWidget();
|
~RewardsWidget();
|
||||||
|
|
||||||
@@ -57,8 +48,8 @@ private slots:
|
|||||||
void on_rewardsTable_itemSelectionChanged();
|
void on_rewardsTable_itemSelectionChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addReward(int typeId, int listId, int amount);
|
void addReward(RewardType typeId, int listId, int amount);
|
||||||
QList<QString> getListForType(int typeId);
|
QList<QString> getListForType(RewardType typeId);
|
||||||
|
|
||||||
Ui::RewardsWidget *ui;
|
Ui::RewardsWidget *ui;
|
||||||
CGPandoraBox * pandora;
|
CGPandoraBox * pandora;
|
||||||
|
@@ -140,12 +140,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
graphics = new Graphics(); // should be before curh->init()
|
graphics = new Graphics(); // should be before curh->init()
|
||||||
graphics->load();//must be after Content loading but should be in main thread
|
graphics->load();//must be after Content loading but should be in main thread
|
||||||
|
|
||||||
|
|
||||||
if(!testFile("DATA/new-menu/Background.png", "Cannot find file"))
|
|
||||||
{
|
|
||||||
QApplication::quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->mapView->setScene(controller.scene(0));
|
ui->mapView->setScene(controller.scene(0));
|
||||||
ui->mapView->setController(&controller);
|
ui->mapView->setController(&controller);
|
||||||
ui->mapView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing);
|
ui->mapView->setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing);
|
||||||
@@ -173,7 +167,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
show();
|
show();
|
||||||
|
|
||||||
//Load map from command line
|
//Load map from command line
|
||||||
if(qApp->arguments().size() == 2)
|
if(qApp->arguments().size() >= 2)
|
||||||
openMap(qApp->arguments().at(1));
|
openMap(qApp->arguments().at(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,7 +967,7 @@ void MainWindow::switchDefaultPlayer(const PlayerColor & player)
|
|||||||
ui->actionNeutral->blockSignals(true);
|
ui->actionNeutral->blockSignals(true);
|
||||||
ui->actionNeutral->setChecked(PlayerColor::NEUTRAL == player);
|
ui->actionNeutral->setChecked(PlayerColor::NEUTRAL == player);
|
||||||
ui->actionNeutral->blockSignals(false);
|
ui->actionNeutral->blockSignals(false);
|
||||||
for(int i = 0; i < 8; ++i)
|
for(int i = 0; i < PlayerColor::PLAYER_LIMIT.getNum(); ++i)
|
||||||
{
|
{
|
||||||
getActionPlayer(PlayerColor(i))->blockSignals(true);
|
getActionPlayer(PlayerColor(i))->blockSignals(true);
|
||||||
getActionPlayer(PlayerColor(i))->setChecked(PlayerColor(i) == player);
|
getActionPlayer(PlayerColor(i))->setChecked(PlayerColor(i) == player);
|
||||||
|
@@ -19,10 +19,11 @@
|
|||||||
|
|
||||||
MapController::MapController(MainWindow * m): main(m)
|
MapController::MapController(MainWindow * m): main(m)
|
||||||
{
|
{
|
||||||
_scenes[0].reset(new MapScene(0));
|
for(int i : {0, 1})
|
||||||
_scenes[1].reset(new MapScene(1));
|
{
|
||||||
_miniscenes[0].reset(new MinimapScene(0));
|
_scenes[i].reset(new MapScene(i));
|
||||||
_miniscenes[1].reset(new MinimapScene(1));
|
_miniscenes[i].reset(new MinimapScene(i));
|
||||||
|
}
|
||||||
connectScenes();
|
connectScenes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,23 +73,19 @@ void MapController::repairMap()
|
|||||||
//there might be extra skills, arts and spells not imported from map
|
//there might be extra skills, arts and spells not imported from map
|
||||||
if(VLC->skillh->getDefaultAllowed().size() > map()->allowedAbilities.size())
|
if(VLC->skillh->getDefaultAllowed().size() > map()->allowedAbilities.size())
|
||||||
{
|
{
|
||||||
for(int i = map()->allowedAbilities.size(); i < VLC->skillh->getDefaultAllowed().size(); ++i)
|
map()->allowedAbilities.resize(VLC->skillh->getDefaultAllowed().size());
|
||||||
map()->allowedAbilities.push_back(false);
|
|
||||||
}
|
}
|
||||||
if(VLC->arth->getDefaultAllowed().size() > map()->allowedArtifact.size())
|
if(VLC->arth->getDefaultAllowed().size() > map()->allowedArtifact.size())
|
||||||
{
|
{
|
||||||
for(int i = map()->allowedArtifact.size(); i < VLC->arth->getDefaultAllowed().size(); ++i)
|
map()->allowedArtifact.resize(VLC->arth->getDefaultAllowed().size());
|
||||||
map()->allowedArtifact.push_back(false);
|
|
||||||
}
|
}
|
||||||
if(VLC->spellh->getDefaultAllowed().size() > map()->allowedSpell.size())
|
if(VLC->spellh->getDefaultAllowed().size() > map()->allowedSpell.size())
|
||||||
{
|
{
|
||||||
for(int i = map()->allowedSpell.size(); i < VLC->spellh->getDefaultAllowed().size(); ++i)
|
map()->allowedSpell.resize(VLC->spellh->getDefaultAllowed().size());
|
||||||
map()->allowedSpell.push_back(false);
|
|
||||||
}
|
}
|
||||||
if(VLC->heroh->getDefaultAllowed().size() > map()->allowedHeroes.size())
|
if(VLC->heroh->getDefaultAllowed().size() > map()->allowedHeroes.size())
|
||||||
{
|
{
|
||||||
for(int i = map()->allowedHeroes.size(); i < VLC->heroh->getDefaultAllowed().size(); ++i)
|
map()->allowedHeroes.resize(VLC->heroh->getDefaultAllowed().size());
|
||||||
map()->allowedHeroes.push_back(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fix owners for objects
|
//fix owners for objects
|
||||||
@@ -191,10 +188,11 @@ void MapController::setMap(std::unique_ptr<CMap> cmap)
|
|||||||
|
|
||||||
repairMap();
|
repairMap();
|
||||||
|
|
||||||
_scenes[0].reset(new MapScene(0));
|
for(int i : {0, 1})
|
||||||
_scenes[1].reset(new MapScene(1));
|
{
|
||||||
_miniscenes[0].reset(new MinimapScene(0));
|
_scenes[i].reset(new MapScene(i));
|
||||||
_miniscenes[1].reset(new MinimapScene(1));
|
_miniscenes[i].reset(new MinimapScene(i));
|
||||||
|
}
|
||||||
resetMapHandler();
|
resetMapHandler();
|
||||||
sceneForceUpdate();
|
sceneForceUpdate();
|
||||||
|
|
||||||
@@ -230,10 +228,11 @@ void MapController::resetMapHandler()
|
|||||||
if(!_mapHandler)
|
if(!_mapHandler)
|
||||||
_mapHandler.reset(new MapHandler());
|
_mapHandler.reset(new MapHandler());
|
||||||
_mapHandler->reset(map());
|
_mapHandler->reset(map());
|
||||||
_scenes[0]->initialize(*this);
|
for(int i : {0, 1})
|
||||||
_scenes[1]->initialize(*this);
|
{
|
||||||
_miniscenes[0]->initialize(*this);
|
_scenes[i]->initialize(*this);
|
||||||
_miniscenes[1]->initialize(*this);
|
_miniscenes[i]->initialize(*this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapController::commitTerrainChange(int level, const TerrainId & terrain)
|
void MapController::commitTerrainChange(int level, const TerrainId & terrain)
|
||||||
@@ -321,7 +320,7 @@ bool MapController::discardObject(int level) const
|
|||||||
delete _scenes[level]->selectionObjectsView.newObject;
|
delete _scenes[level]->selectionObjectsView.newObject;
|
||||||
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = 0;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.draw();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -331,7 +330,7 @@ bool MapController::discardObject(int level) const
|
|||||||
void MapController::createObject(int level, CGObjectInstance * obj) const
|
void MapController::createObject(int level, CGObjectInstance * obj) const
|
||||||
{
|
{
|
||||||
_scenes[level]->selectionObjectsView.newObject = obj;
|
_scenes[level]->selectionObjectsView.newObject = obj;
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = 2;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +409,7 @@ void MapController::commitObjectShift(int level)
|
|||||||
|
|
||||||
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = 0;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
|
|
||||||
if(makeShift)
|
if(makeShift)
|
||||||
{
|
{
|
||||||
@@ -444,7 +443,7 @@ void MapController::commitObjectCreate(int level)
|
|||||||
|
|
||||||
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
_scenes[level]->selectionObjectsView.newObject = nullptr;
|
||||||
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
_scenes[level]->selectionObjectsView.shift = QPoint(0, 0);
|
||||||
_scenes[level]->selectionObjectsView.selectionMode = 0;
|
_scenes[level]->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
_scenes[level]->objectsView.draw();
|
_scenes[level]->objectsView.draw();
|
||||||
_scenes[level]->selectionObjectsView.draw();
|
_scenes[level]->selectionObjectsView.draw();
|
||||||
_scenes[level]->passabilityView.update();
|
_scenes[level]->passabilityView.update();
|
||||||
|
@@ -155,11 +155,11 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent)
|
|||||||
{
|
{
|
||||||
sc->selectionObjectsView.shift = QPoint(tile.x, tile.y);
|
sc->selectionObjectsView.shift = QPoint(tile.x, tile.y);
|
||||||
sc->selectionObjectsView.selectObject(sc->selectionObjectsView.newObject);
|
sc->selectionObjectsView.selectObject(sc->selectionObjectsView.newObject);
|
||||||
sc->selectionObjectsView.selectionMode = 2;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
}
|
}
|
||||||
else if(mouseEvent->buttons() & Qt::LeftButton)
|
else if(mouseEvent->buttons() & Qt::LeftButton)
|
||||||
{
|
{
|
||||||
if(sc->selectionObjectsView.selectionMode == 1)
|
if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::SELECTION)
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.selectObjects(tileStart.x, tileStart.y, tile.x, tile.y);
|
sc->selectionObjectsView.selectObjects(tileStart.x, tileStart.y, tile.x, tile.y);
|
||||||
@@ -269,23 +269,23 @@ void MapView::mousePressEvent(QMouseEvent *event)
|
|||||||
if(qApp->keyboardModifiers() & Qt::ControlModifier)
|
if(qApp->keyboardModifiers() & Qt::ControlModifier)
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.deselectObject(obj);
|
sc->selectionObjectsView.deselectObject(obj);
|
||||||
sc->selectionObjectsView.selectionMode = 1;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::SELECTION;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sc->selectionObjectsView.selectionMode = 2;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!(qApp->keyboardModifiers() & Qt::ControlModifier))
|
if(!(qApp->keyboardModifiers() & Qt::ControlModifier))
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.selectionMode = 2;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::MOVEMENT;
|
||||||
sc->selectionObjectsView.selectObject(obj);
|
sc->selectionObjectsView.selectObject(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.clear();
|
sc->selectionObjectsView.clear();
|
||||||
sc->selectionObjectsView.selectionMode = 1;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::SELECTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sc->selectionObjectsView.shift = QPoint(0, 0);
|
sc->selectionObjectsView.shift = QPoint(0, 0);
|
||||||
@@ -312,7 +312,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
break;
|
break;
|
||||||
//switch position
|
//switch position
|
||||||
bool tab = false;
|
bool tab = false;
|
||||||
if(sc->selectionObjectsView.selectionMode == 2)
|
if(sc->selectionObjectsView.selectionMode == SelectionObjectsLayer::MOVEMENT)
|
||||||
{
|
{
|
||||||
if(sc->selectionObjectsView.newObject)
|
if(sc->selectionObjectsView.newObject)
|
||||||
{
|
{
|
||||||
@@ -330,7 +330,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sc->selectionObjectsView.selectionMode = 0;
|
sc->selectionObjectsView.selectionMode = SelectionObjectsLayer::NOTHING;
|
||||||
sc->selectionObjectsView.shift = QPoint(0, 0);
|
sc->selectionObjectsView.shift = QPoint(0, 0);
|
||||||
sc->selectionObjectsView.draw();
|
sc->selectionObjectsView.draw();
|
||||||
tab = true;
|
tab = true;
|
||||||
|
@@ -42,8 +42,7 @@ bool ObjectBrowser::filterAcceptsRow(int source_row, const QModelIndex & source_
|
|||||||
|
|
||||||
result = result & templ->canBePlacedAt(terrain);
|
result = result & templ->canBePlacedAt(terrain);
|
||||||
|
|
||||||
//text filter
|
//if we are here, just text filter will be applied
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
|
|||||||
show();
|
show();
|
||||||
|
|
||||||
int players = 0;
|
int players = 0;
|
||||||
|
const int minAllowedPlayers = 2;
|
||||||
for(auto & p : controller.map()->players)
|
for(auto & p : controller.map()->players)
|
||||||
{
|
{
|
||||||
if(p.canAnyonePlay())
|
if(p.canAnyonePlay())
|
||||||
@@ -23,10 +24,10 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(players < 2)
|
if(players < minAllowedPlayers)
|
||||||
ui->playersCount->setCurrentText("");
|
ui->playersCount->setCurrentText("");
|
||||||
else
|
else
|
||||||
ui->playersCount->setCurrentIndex(players - 2);
|
ui->playersCount->setCurrentIndex(players - minAllowedPlayers);
|
||||||
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
}
|
}
|
||||||
@@ -38,9 +39,10 @@ PlayerSettings::~PlayerSettings()
|
|||||||
|
|
||||||
void PlayerSettings::on_playersCount_currentIndexChanged(int index)
|
void PlayerSettings::on_playersCount_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
assert(index + 2 <= controller.map()->players.size());
|
const auto selectedPlayerCount = index + 2;
|
||||||
|
assert(selectedPlayerCount <= controller.map()->players.size());
|
||||||
|
|
||||||
for(int i = 0; i < index + 2; ++i)
|
for(int i = 0; i < selectedPlayerCount; ++i)
|
||||||
{
|
{
|
||||||
if(i < paramWidgets.size())
|
if(i < paramWidgets.size())
|
||||||
continue;
|
continue;
|
||||||
@@ -52,7 +54,7 @@ void PlayerSettings::on_playersCount_currentIndexChanged(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(!paramWidgets.empty());
|
assert(!paramWidgets.empty());
|
||||||
for(int i = paramWidgets.size() - 1; i >= index + 2; --i)
|
for(int i = paramWidgets.size() - 1; i >= selectedPlayerCount; --i)
|
||||||
{
|
{
|
||||||
auto & p = controller.map()->players[i];
|
auto & p = controller.map()->players[i];
|
||||||
p.canComputerPlay = false;
|
p.canComputerPlay = false;
|
||||||
|
@@ -54,7 +54,7 @@ void GridLayer::update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
painter.setPen(QColor(0, 0, 0, 190));
|
painter.setPen(QColor(0, 0, 0, 190));
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ void PassabilityLayer::update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
|
|
||||||
if(scene->level == 0 || map->twoLevel)
|
if(scene->level == 0 || map->twoLevel)
|
||||||
{
|
{
|
||||||
@@ -116,7 +116,7 @@ void SelectionTerrainLayer::update()
|
|||||||
onSelection();
|
onSelection();
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ void ObjectsLayer::update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
draw(false);
|
draw(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ void ObjectsLayer::draw(bool onlyDirty)
|
|||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
std::set<const CGObjectInstance *> drawen;
|
std::set<const CGObjectInstance *> drawen;
|
||||||
|
|
||||||
@@ -340,8 +340,7 @@ void SelectionObjectsLayer::update()
|
|||||||
selectedObjects.clear();
|
selectedObjects.clear();
|
||||||
onSelection();
|
onSelection();
|
||||||
shift = QPoint();
|
shift = QPoint();
|
||||||
if(newObject)
|
delete newObject;
|
||||||
delete newObject;
|
|
||||||
newObject = nullptr;
|
newObject = nullptr;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
@@ -355,11 +354,11 @@ void SelectionObjectsLayer::draw()
|
|||||||
if(!pixmap)
|
if(!pixmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
painter.setPen(QColor(255, 255, 255));
|
painter.setPen(QColorConstants::White);
|
||||||
|
|
||||||
for(auto * obj : selectedObjects)
|
for(auto * obj : selectedObjects)
|
||||||
{
|
{
|
||||||
@@ -379,7 +378,7 @@ void SelectionObjectsLayer::draw()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//show translation
|
//show translation
|
||||||
if(selectionMode == 2 && (shift.x() || shift.y()))
|
if(selectionMode == SelectionMode::MOVEMENT && (shift.x() || shift.y()))
|
||||||
{
|
{
|
||||||
painter.setOpacity(0.5);
|
painter.setOpacity(0.5);
|
||||||
auto newPos = QPoint(obj->getPosition().x, obj->getPosition().y) + shift;
|
auto newPos = QPoint(obj->getPosition().x, obj->getPosition().y) + shift;
|
||||||
@@ -530,13 +529,8 @@ void MinimapViewLayer::update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap.reset(new QPixmap(map->width, map->height));
|
pixmap.reset(new QPixmap(map->width, map->height));
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
draw();
|
||||||
painter.setPen(QColor(255, 255, 255));
|
|
||||||
painter.drawRect(x, y, w, h);
|
|
||||||
|
|
||||||
redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinimapViewLayer::draw()
|
void MinimapViewLayer::draw()
|
||||||
@@ -544,11 +538,11 @@ void MinimapViewLayer::draw()
|
|||||||
if(!map)
|
if(!map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixmap->fill(QColor(0, 0, 0, 0));
|
pixmap->fill(QColorConstants::Transparent);
|
||||||
|
|
||||||
//maybe not optimal but ok
|
//maybe not optimal but ok
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
painter.setPen(QColor(255, 255, 255));
|
painter.setPen(QColorConstants::White);
|
||||||
painter.drawRect(x, y, w, h);
|
painter.drawRect(x, y, w, h);
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
|
@@ -117,6 +117,11 @@ class SelectionObjectsLayer: public AbstractLayer
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum SelectionMode
|
||||||
|
{
|
||||||
|
NOTHING, SELECTION, MOVEMENT
|
||||||
|
};
|
||||||
|
|
||||||
SelectionObjectsLayer(MapSceneBase* s);
|
SelectionObjectsLayer(MapSceneBase* s);
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
@@ -135,7 +140,7 @@ public:
|
|||||||
QPoint shift;
|
QPoint shift;
|
||||||
CGObjectInstance * newObject;
|
CGObjectInstance * newObject;
|
||||||
//FIXME: magic number
|
//FIXME: magic number
|
||||||
int selectionMode = 0; //0 - nothing, 1 - selection, 2 - movement
|
SelectionMode selectionMode = SelectionMode::NOTHING;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectionMade(bool anythingSlected);
|
void selectionMade(bool anythingSlected);
|
||||||
|
Reference in New Issue
Block a user