Skip to content

Commit

Permalink
Editor: Improve the pointer casts at level objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed Oct 15, 2024
1 parent 84a8f72 commit a75af69
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 88 deletions.
58 changes: 38 additions & 20 deletions Editor/editing/_scenes/level/items/item_bgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
if(((ItemBGO *) SelItem)->m_data.id == oldID)
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
if(b->m_data.id == oldID)
selectedList.push_back(SelItem);
}
}
Expand All @@ -215,8 +217,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(LevelBGO::Background2, ((ItemBGO *) SelItem)->m_data.z_offset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(LevelBGO::Background2, b->m_data.z_offset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_LAYER, QVariant(LevelBGO::Background2));
Expand All @@ -228,8 +232,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(LevelBGO::Background1, ((ItemBGO *) SelItem)->m_data.z_offset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(LevelBGO::Background1, b->m_data.z_offset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_LAYER, QVariant(LevelBGO::Background1));
Expand All @@ -241,8 +247,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(LevelBGO::ZDefault, ((ItemBGO *) SelItem)->m_data.z_offset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(LevelBGO::ZDefault, b->m_data.z_offset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_LAYER, QVariant(LevelBGO::ZDefault));
Expand All @@ -254,8 +262,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(LevelBGO::Foreground1, ((ItemBGO *) SelItem)->m_data.z_offset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(LevelBGO::Foreground1, b->m_data.z_offset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_LAYER, QVariant(LevelBGO::Foreground1));
Expand All @@ -267,8 +277,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(LevelBGO::Foreground2, ((ItemBGO *) SelItem)->m_data.z_offset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(LevelBGO::Foreground2, b->m_data.z_offset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_LAYER, QVariant(LevelBGO::Foreground2));
Expand All @@ -287,8 +299,10 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->setZMode(((ItemBGO *) SelItem)->m_data.z_mode, newzOffset);
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->setZMode(b->m_data.z_mode, newzOffset);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_Z_OFFSET, QVariant(newzOffset));
Expand Down Expand Up @@ -351,8 +365,9 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
ItemBGO *item = (ItemBGO *)SelItem;
if((!sameID) || (item->m_data.id == oldID))
ItemBGO *item = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(item);
if(!sameID || item->m_data.id == oldID)
{
oldData.bgo.push_back(item->m_data);
item->transformTo(transformTO);
Expand All @@ -368,8 +383,9 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
ItemBGO *item = (ItemBGO *)SelItem;
if((!sameID) || (item->m_data.id == oldID))
ItemBGO *item = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(item);
if(!sameID || item->m_data.id == oldID)
{
oldData.bgo.push_back(item->m_data);
LevelBlock block;
Expand Down Expand Up @@ -451,9 +467,11 @@ void ItemBGO::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "BGO")
{
selData.bgo.push_back(((ItemBGO *)SelItem)->m_data);
((ItemBGO *) SelItem)->m_data.meta.custom_params = ch;
((ItemBGO *) SelItem)->arrayApply();
ItemBGO *b = qgraphicsitem_cast<ItemBGO *>(SelItem);
Q_ASSERT(b);
selData.bgo.push_back(b->m_data);
b->m_data.meta.custom_params = ch;
b->arrayApply();
}
}
m_scene->m_history->addChangeSettings(selData, new BgoHistory_UserData(), ch);
Expand Down
44 changes: 28 additions & 16 deletions Editor/editing/_scenes/level/items/item_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
ItemBlock *item = (ItemBlock *)SelItem;
if((!sameID) || (item->m_data.id == oldID))
ItemBlock *item = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(item);
if(!sameID || item->m_data.id == oldID)
{
oldData.blocks.push_back(item->m_data);
item->transformTo(transformTO);
Expand All @@ -282,8 +283,9 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
ItemBlock *item = (ItemBlock *)SelItem;
if((!sameID) || (item->m_data.id == oldID))
ItemBlock *item = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(item);
if(!sameID || item->m_data.id == oldID)
{
oldData.blocks.push_back(item->m_data);
LevelBGO bgo;
Expand Down Expand Up @@ -381,8 +383,10 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
selData.blocks.push_back(((ItemBlock *) SelItem)->m_data);
((ItemBlock *) SelItem)->setInvisible(invis->isChecked());
ItemBlock *b = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(b);
selData.blocks.push_back(b->m_data);
b->setInvisible(invis->isChecked());
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_INVISIBLE, QVariant(invis->isChecked()));
Expand All @@ -395,8 +399,10 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
selData.blocks.push_back(((ItemBlock *) SelItem)->m_data);
((ItemBlock *) SelItem)->setSlippery(slipp->isChecked());
ItemBlock *b = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(b);
selData.blocks.push_back(b->m_data);
b->setSlippery(slipp->isChecked());
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_SLIPPERY, QVariant(invis->isChecked()));
Expand Down Expand Up @@ -428,10 +434,12 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
//((ItemBlock *) SelItem)->blockData.npc_id = selected_npc;
//((ItemBlock *) SelItem)->arrayApply();
selData.blocks.push_back(((ItemBlock *) SelItem)->m_data);
((ItemBlock *) SelItem)->setIncludedNPC(selected_npc);
ItemBlock *b = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(b);
//b->blockData.npc_id = selected_npc;
//b->arrayApply();
selData.blocks.push_back(b->m_data);
b->setIncludedNPC(selected_npc);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_CHANGENPC, QVariant(selected_npc));
Expand Down Expand Up @@ -468,7 +476,9 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
if(((ItemBlock *) SelItem)->m_data.id == oldID)
ItemBlock *b = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(b);
if(b->m_data.id == oldID)
selectedList.push_back(SelItem);
}
}
Expand All @@ -494,9 +504,11 @@ void ItemBlock::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "Block")
{
selData.blocks.push_back(((ItemBlock *)SelItem)->m_data);
((ItemBlock *) SelItem)->m_data.meta.custom_params = ch;
((ItemBlock *) SelItem)->arrayApply();
ItemBlock *b = qgraphicsitem_cast<ItemBlock*>(SelItem);
Q_ASSERT(b);
selData.blocks.push_back(b->m_data);
b->m_data.meta.custom_params = ch;
b->arrayApply();
}
}
m_scene->m_history->addChangeSettings(selData, new BlockHistory_UserData(), ch);
Expand Down
68 changes: 47 additions & 21 deletions Editor/editing/_scenes/level/items/item_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
ItemNPC *sItem = (ItemNPC *)SelItem;
ItemNPC *sItem = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);

if((!sameID) || (sItem->m_data.id == oldID))
{
oldData.npc.push_back(sItem->m_data);
Expand All @@ -283,6 +285,7 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
cancelTransform:
;
}

delete npcList;
if(!newData.npc.isEmpty())
m_scene->m_history->addTransform(newData, oldData);
Expand All @@ -295,6 +298,7 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
0, 0, 0, 0, 0, m_scene->m_subWindow);
npcList->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
npcList->setGeometry(util::alignToScreenCenter(npcList->size()));

if(npcList->exec() == QDialog::Accepted)
{
//apply to all selected items.
Expand All @@ -306,12 +310,15 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->setIncludedNPC(selected_npc);
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->setIncludedNPC(selected_npc);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_CHANGENPC, QVariant(selected_npc));
}

delete npcList;
}
else if(selected == copyArrayID)
Expand Down Expand Up @@ -359,6 +366,7 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
LogDebug(QString("NPC.txt path 1: %1").arg(NPCpath1));
LogDebug(QString("NPC.txt path 2: %1").arg(NPCpath2));

if((!m_scene->m_data->meta.untitled) && (QFileInfo(NPCpath2).exists()))
m_scene->m_mw->OpenFile(NPCpath2);
else if((!m_scene->m_data->meta.untitled) && (QFileInfo(NPCpath1).exists()))
Expand All @@ -379,8 +387,10 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->setFriendly(fri->isChecked());
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->setFriendly(fri->isChecked());
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_FRIENDLY, QVariant(fri->isChecked()));
Expand All @@ -393,8 +403,10 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->setNoMovable(stat->isChecked());
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->setNoMovable(stat->isChecked());
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_NOMOVEABLE, QVariant(stat->isChecked()));
Expand All @@ -413,11 +425,14 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->setMsg(msgBox.currentText);
((ItemNPC *) SelItem)->setFriendly(msgBox.isFriendlyChecked());
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->setMsg(msgBox.currentText);
n->setFriendly(msgBox.isFriendlyChecked());
}
}

m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_MESSAGE, QVariant(msgBox.currentText));
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_FRIENDLY, QVariant(msgBox.isFriendlyChecked()));
}
Expand All @@ -430,8 +445,10 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->setLegacyBoss(boss->isChecked());
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->setLegacyBoss(boss->isChecked());
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_BOSS, QVariant(boss->isChecked()));
Expand All @@ -443,34 +460,40 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->changeDirection(-1);
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->changeDirection(-1);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_DIRECTION, QVariant(-1));
}
if(selected == setRand)
else if(selected == setRand)
{
LevelData selData;
for(QGraphicsItem *SelItem : m_scene->selectedItems())
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->changeDirection(0);
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->changeDirection(0);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_DIRECTION, QVariant(0));
}
if(selected == setRight)
else if(selected == setRight)
{
LevelData selData;
for(QGraphicsItem *SelItem : m_scene->selectedItems())
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
selData.npc.push_back(((ItemNPC *) SelItem)->m_data);
((ItemNPC *) SelItem)->changeDirection(1);
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
Q_ASSERT(n);
selData.npc.push_back(n->m_data);
n->changeDirection(1);
}
}
m_scene->m_history->addChangeSettings(selData, HistorySettings::SETTING_DIRECTION, QVariant(1));
Expand Down Expand Up @@ -500,14 +523,17 @@ void ItemNPC::contextMenu(QGraphicsSceneMouseEvent *mouseEvent)
section.setBottom(s.size_bottom + mg);
our_items = m_scene->items(section, Qt::IntersectsItemShape);
}

for(QGraphicsItem *SelItem : our_items)
{
if(SelItem->data(ITEM_TYPE).toString() == "NPC")
{
if(((ItemNPC *) SelItem)->m_data.id == oldID)
ItemNPC *n = qgraphicsitem_cast<ItemNPC *>(SelItem);
if(n->m_data.id == oldID)
selectedList.push_back(SelItem);
}
}

if(!selectedList.isEmpty())
{
m_scene->removeLvlItems(selectedList);
Expand Down
Loading

0 comments on commit a75af69

Please sign in to comment.