Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow displaying age/page and object IDs in Object Browser tree #78

Closed
wants to merge 9 commits into from
114 changes: 91 additions & 23 deletions src/PrpShop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ PrpShopMain::PrpShopMain()
fActions[kFileSaveAs] = new QAction(tr("Sa&ve As..."), this);
fActions[kFileExit] = new QAction(tr("E&xit"), this);
fActions[kToolsProperties] = new QAction(tr("Show &Properties Pane"), this);
fActions[kToolsShowAgePageIDs] = new QAction(tr("Show &Age/Page IDs"), this);
fActions[kToolsShowTypeIDs] = new QAction(tr("Show Type &IDs"), this);
fActions[kToolsShowObjectIDs] = new QAction(tr("Show &Object IDs"), this);
fActions[kToolsNewObject] = new QAction(tr("&New Object..."), this);
fActions[kWindowPrev] = new QAction(tr("&Previous"), this);
fActions[kWindowNext] = new QAction(tr("&Next"), this);
Expand Down Expand Up @@ -96,8 +98,12 @@ PrpShopMain::PrpShopMain()
fActions[kWindowClose]->setShortcutContext(Qt::WidgetWithChildrenShortcut);
fActions[kToolsProperties]->setCheckable(true);
fActions[kToolsProperties]->setChecked(true);
fActions[kToolsShowAgePageIDs]->setCheckable(true);
fActions[kToolsShowAgePageIDs]->setChecked(false);
fActions[kToolsShowTypeIDs]->setCheckable(true);
fActions[kToolsShowTypeIDs]->setChecked(false);
fActions[kToolsShowObjectIDs]->setCheckable(true);
fActions[kToolsShowObjectIDs]->setChecked(false);

// Main Menus
QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
Expand All @@ -111,7 +117,9 @@ PrpShopMain::PrpShopMain()

QMenu* viewMenu = menuBar()->addMenu(tr("&Tools"));
viewMenu->addAction(fActions[kToolsProperties]);
viewMenu->addAction(fActions[kToolsShowAgePageIDs]);
viewMenu->addAction(fActions[kToolsShowTypeIDs]);
viewMenu->addAction(fActions[kToolsShowObjectIDs]);
viewMenu->addSeparator();
viewMenu->addAction(fActions[kToolsNewObject]);

Expand Down Expand Up @@ -180,8 +188,12 @@ PrpShopMain::PrpShopMain()
fPropertyDock, &QWidget::setVisible);
connect(fPropertyDock, &QDockWidget::visibilityChanged,
fActions[kToolsProperties], &QAction::setChecked);
connect(fActions[kToolsShowAgePageIDs], &QAction::toggled,
this, &PrpShopMain::showAgePageIDs);
connect(fActions[kToolsShowTypeIDs], &QAction::toggled,
this, &PrpShopMain::showTypeIDs);
connect(fActions[kToolsShowObjectIDs], &QAction::toggled,
this, &PrpShopMain::showObjectIDs);
connect(fActions[kToolsNewObject], &QAction::triggered,
this, &PrpShopMain::createNewObject);

Expand Down Expand Up @@ -231,8 +243,12 @@ PrpShopMain::PrpShopMain()
if (settings.contains("DialogDir"))
fDialogDir = settings.value("DialogDir").toString();

fActions[kToolsShowAgePageIDs]->setChecked(
settings.value("ShowAgePageIDs", false).toBool());
fActions[kToolsShowTypeIDs]->setChecked(
settings.value("ShowTypeIDs", false).toBool());
fActions[kToolsShowObjectIDs]->setChecked(
settings.value("ShowObjectIDs", false).toBool());
}

void PrpShopMain::closeEvent(QCloseEvent*)
Expand All @@ -248,7 +264,9 @@ void PrpShopMain::closeEvent(QCloseEvent*)
settings.setValue("WinState", saveState());

settings.setValue("DialogDir", fDialogDir);
settings.setValue("ShowAgePageIDs", s_showAgePageIDs);
settings.setValue("ShowTypeIDs", s_showTypeIDs);
settings.setValue("ShowObjectIDs", s_showObjectIDs);
}

void PrpShopMain::dragEnterEvent(QDragEnterEvent* evt)
Expand Down Expand Up @@ -344,6 +362,7 @@ void PrpShopMain::setPropertyPage(PropWhich which)
fLoadMaskQ[1] = new QSpinBox(group);
fLoadMaskQ[0]->setRange(0, 255);
fLoadMaskQ[1]->setRange(0, 255);
fObjId = new QLabel(group);

fCloneIdBox = new QGroupBox(tr("Clone IDs"), group);
fCloneIdBox->setCheckable(true);
Expand All @@ -364,7 +383,9 @@ void PrpShopMain::setPropertyPage(PropWhich which)
layout->addWidget(new QLabel(tr("Load Mask:"), group), 2, 0);
layout->addWidget(fLoadMaskQ[0], 2, 1);
layout->addWidget(fLoadMaskQ[1], 2, 2);
layout->addWidget(fCloneIdBox, 3, 0, 1, 3);
layout->addWidget(new QLabel(tr("Object ID:"), group), 3, 0);
layout->addWidget(fObjId, 3, 1, 1, 2);
layout->addWidget(fCloneIdBox, 4, 0, 1, 3);
}
break;
default:
Expand Down Expand Up @@ -408,6 +429,7 @@ void PrpShopMain::treeItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* pre
fObjType->setText(item->obj()->ClassName());
fLoadMaskQ[0]->setValue(item->obj()->getKey()->getLoadMask().getQuality(0));
fLoadMaskQ[1]->setValue(item->obj()->getKey()->getLoadMask().getQuality(1));
fObjId->setText(QString("%1").arg(item->obj()->getKey()->getID()));
fCloneId->setValue(item->obj()->getKey()->getCloneID());
fClonePlayerId->setValue(item->obj()->getKey()->getClonePlayerID());
fCloneIdBox->setChecked(fCloneId->value() != 0 || fClonePlayerId->value() != 0);
Expand Down Expand Up @@ -558,6 +580,12 @@ void PrpShopMain::treeDelete()
QPlasmaTreeItem* folder = (QPlasmaTreeItem*)item->parent();
delete item;

// Deleting an object may change the object IDs of other objects of the same type,
// so reinit all objects in the type folder to update their displayed IDs.
for (int i = 0; i < folder->childCount(); i++) {
static_cast<QPlasmaTreeItem*>(folder->child(i))->reinit();
}

if (folder->childCount() == 0)
delete folder;
}
Expand All @@ -567,10 +595,10 @@ QPlasmaTreeItem* PrpShopMain::ensurePath(const plLocation& loc, short objType)
plPageInfo* page = fResMgr.FindPage(loc);
QPlasmaTreeItem* ageItem = NULL;
QString ageName = st2qstr(page->getAge());
QString pageName = st2qstr(page->getPage());
for (int i=0; i<fBrowserTree->topLevelItemCount(); i++) {
if (fBrowserTree->topLevelItem(i)->text(0) == ageName) {
ageItem = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i);
auto topLevelItem = static_cast<QPlasmaTreeItem*>(fBrowserTree->topLevelItem(i));
if (topLevelItem->age() == ageName) {
ageItem = topLevelItem;
break;
}
}
Expand All @@ -579,27 +607,27 @@ QPlasmaTreeItem* PrpShopMain::ensurePath(const plLocation& loc, short objType)

QPlasmaTreeItem* pageItem = NULL;
for (int i=0; i<ageItem->childCount(); i++) {
if (ageItem->child(i)->text(0) == pageName) {
pageItem = (QPlasmaTreeItem*)ageItem->child(i);
auto child = static_cast<QPlasmaTreeItem*>(ageItem->child(i));
if (child->page()->getLocation() == loc) {
pageItem = child;
break;
}
}
if (pageItem == NULL)
throw hsBadParamException(__FILE__, __LINE__, "Invalid Page");

QPlasmaTreeItem* folderItem = NULL;
QString typeName = pqGetFriendlyClassName(objType);
QPlasmaTreeItem* typeItem = nullptr;
for (int i=0; i<pageItem->childCount(); i++) {
if (pageItem->child(i)->text(0) == typeName) {
folderItem = (QPlasmaTreeItem*)pageItem->child(i);
auto child = static_cast<QPlasmaTreeItem*>(pageItem->child(i));
if (child->classType() == objType) {
typeItem = child;
break;
}
}
if (folderItem == NULL) {
folderItem = new QPlasmaTreeItem(pageItem);
folderItem->setText(0, typeName);
if (typeItem == nullptr) {
typeItem = new QPlasmaTreeItem(pageItem, objType);
}
return folderItem;
return typeItem;
}

void PrpShopMain::closeWindows(const plLocation& loc)
Expand Down Expand Up @@ -1014,6 +1042,7 @@ void PrpShopMain::saveFile(plPageInfo* page, QString filename)
void PrpShopMain::saveProps(QPlasmaTreeItem* item)
{
if (item != NULL) {
bool reinit = false;
bool refreshTree = false;
if (item->type() == QPlasmaTreeItem::kTypePage) {
if (fAgeName->text() != st2qstr(item->page()->getAge())) {
Expand All @@ -1026,7 +1055,7 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item)
}
if (fPageName->text() != st2qstr(item->page()->getPage())) {
item->page()->setPage(qstr2st(fPageName->text()));
item->setText(0, fPageName->text());
reinit = true;
refreshTree = true;
}
if (fReleaseVersion->value() != (int)item->page()->getReleaseVersion())
Expand All @@ -1043,12 +1072,13 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item)
fLoadedLocations[loc] = fLoadedLocations[item->page()->getLocation()];
fLoadedLocations.erase(fLoadedLocations.find(item->page()->getLocation()));
fResMgr.ChangeLocation(item->page()->getLocation(), loc);
reinit = true;
}
} else if (item->type() == QPlasmaTreeItem::kTypeKO) {
if (item->obj() != NULL) {
if (fObjName->text() != st2qstr(item->obj()->getKey()->getName())) {
item->obj()->getKey()->setName(qstr2st(fObjName->text()));
item->setText(0, fObjName->text());
reinit = true;
refreshTree = true;
}
plLoadMask mask = item->obj()->getKey()->getLoadMask();
Expand All @@ -1058,6 +1088,9 @@ void PrpShopMain::saveProps(QPlasmaTreeItem* item)
item->obj()->getKey()->setCloneIDs(fCloneId->value(), fClonePlayerId->value());
}
}
if (reinit) {
item->reinit();
}
if (refreshTree)
fBrowserTree->sortItems(0, Qt::AscendingOrder);
}
Expand All @@ -1074,8 +1107,9 @@ QPlasmaTreeItem* PrpShopMain::loadPage(plPageInfo* page, QString filename)
// Find or create the Age folder
QString ageName = st2qstr(page->getAge());
for (int i=0; i<fBrowserTree->topLevelItemCount(); i++) {
if (fBrowserTree->topLevelItem(i)->text(0) == ageName) {
parent = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i);
auto topLevelItem = static_cast<QPlasmaTreeItem*>(fBrowserTree->topLevelItem(i));
if (topLevelItem->age() == ageName) {
parent = topLevelItem;
break;
}
}
Expand All @@ -1096,12 +1130,11 @@ QPlasmaTreeItem* PrpShopMain::loadPage(plPageInfo* page, QString filename)
// Populate the type folders and actual objects
std::vector<short> types = fResMgr.getTypes(page->getLocation(), true);
for (size_t i=0; i<types.size(); i++) {
QPlasmaTreeItem* folder = new QPlasmaTreeItem(item);
folder->setText(0, pqGetFriendlyClassName(types[i]));
QPlasmaTreeItem* typeItem = new QPlasmaTreeItem(item, types[i]);

std::vector<plKey> keys = fResMgr.getKeys(page->getLocation(), types[i], true);
for (size_t j=0; j<keys.size(); j++)
new QPlasmaTreeItem(folder, keys[j]);
new QPlasmaTreeItem(typeItem, keys[j]);
}

item->setFilename(filename);
Expand Down Expand Up @@ -1173,6 +1206,21 @@ void PrpShopMain::createNewObject()
}
}

void PrpShopMain::showAgePageIDs(bool show)
{
s_showAgePageIDs = show;

// Refresh the folder display for currently loaded pages
for (int i=0; i<fBrowserTree->topLevelItemCount(); i++) {
QPlasmaTreeItem* ageNode = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i);
for (int j=0; j<ageNode->childCount(); j++) {
QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j);
pageNode->reinit();
}
ageNode->sortChildren(0, Qt::AscendingOrder);
}
}

void PrpShopMain::showTypeIDs(bool show)
{
s_showTypeIDs = show;
Expand All @@ -1184,14 +1232,34 @@ void PrpShopMain::showTypeIDs(bool show)
QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j);
for (int t=0; t<pageNode->childCount(); t++) {
QPlasmaTreeItem* typeNode = (QPlasmaTreeItem*)pageNode->child(t);
short type = ((QPlasmaTreeItem*)typeNode->child(0))->obj()->ClassIndex();
typeNode->setText(0, pqGetFriendlyClassName(type));
typeNode->reinit();
}
pageNode->sortChildren(0, Qt::AscendingOrder);
}
}
}

void PrpShopMain::showObjectIDs(bool show)
{
s_showObjectIDs = show;

// Refresh the folder display for currently loaded pages
for (int i=0; i<fBrowserTree->topLevelItemCount(); i++) {
QPlasmaTreeItem* ageNode = (QPlasmaTreeItem*)fBrowserTree->topLevelItem(i);
for (int j=0; j<ageNode->childCount(); j++) {
QPlasmaTreeItem* pageNode = (QPlasmaTreeItem*)ageNode->child(j);
for (int t=0; t<pageNode->childCount(); t++) {
QPlasmaTreeItem* typeNode = (QPlasmaTreeItem*)pageNode->child(t);
for (int o=0; o<typeNode->childCount(); o++) {
QPlasmaTreeItem* objectNode = (QPlasmaTreeItem*)typeNode->child(o);
objectNode->reinit();
}
typeNode->sortChildren(0, Qt::AscendingOrder);
}
}
}
}

int main(int argc, char* argv[])
{
// Redirect libPlasma's debug stuff to PrpShop.log
Expand Down
7 changes: 5 additions & 2 deletions src/PrpShop/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PrpShopMain : public QMainWindow
QLineEdit* fObjName;
QLabel* fObjType;
QSpinBox* fLoadMaskQ[2];
QLabel* fObjId;
QGroupBox* fCloneIdBox;
QSpinBox* fCloneId;
QSpinBox* fClonePlayerId;
Expand All @@ -73,8 +74,8 @@ class PrpShopMain : public QMainWindow
{
// Main Menu
kFileNewPage, kFileOpen, kFileSave, kFileSaveAs, kFileExit,
kToolsProperties, kToolsShowTypeIDs, kToolsNewObject, kWindowPrev,
kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll,
kToolsProperties, kToolsShowAgePageIDs, kToolsShowTypeIDs, kToolsShowObjectIDs, kToolsNewObject,
kWindowPrev, kWindowNext, kWindowTile, kWindowCascade, kWindowClose, kWindowCloseAll,

// Tree Context Menu
kTreeClose, kTreeEdit, kTreeEditPRC, kTreeEditHex, kTreePreview,
Expand Down Expand Up @@ -119,7 +120,9 @@ public slots:
void treeItemActivated(QTreeWidgetItem* item, int column);
void treeContextMenu(const QPoint& pos);
void createNewObject();
void showAgePageIDs(bool show);
void showTypeIDs(bool show);
void showObjectIDs(bool show);
void closeWindows(const plLocation& loc);

void treeClose();
Expand Down
2 changes: 1 addition & 1 deletion src/PrpShop/PRP/Audio/QWinSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void QWinSound::editEaxSettings()
{
QEaxSourceSettings* eaxDlg = new QEaxSourceSettings(&(plSound::Convert(fCreatable))->getEAXSettings());
eaxDlg->setWindowTitle(tr("EAX Settings: %1")
.arg(st2qstr(plSound::Convert(fCreatable)->getKey()->getName())));
.arg(pqFormatKeyName(plSound::Convert(fCreatable)->getKey())));
eaxDlg->show();
}

Expand Down
4 changes: 2 additions & 2 deletions src/PrpShop/PRP/GUI/QGUIPopUpMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void QPopUpMenuItemDialog::init(pfGUIPopUpMenu::pfMenuItem* item, int idx)
fItemIdx = idx;
fName->setText(st2qstr(fItem->fName));
fProcType->setCurrentIndex(fItem->fHandler == NULL ? 0 : fItem->fHandler->getType());
fSubMenuKey->setText(fItem->fSubMenu.Exists() ? st2qstr(fItem->fSubMenu->getName()) : tr("(Null)"));
fSubMenuKey->setText(fItem->fSubMenu.Exists() ? pqFormatKeyName(fItem->fSubMenu) : tr("(Null)"));
fYOffsetToNext->setValue(fItem->fYOffsetToNext);
}

Expand Down Expand Up @@ -365,7 +365,7 @@ void QPopUpMenuItemDialog::selectKey()
dlg.init(PrpShopMain::ResManager(), fItem->fSubMenu);
if (dlg.exec() == QDialog::Accepted) {
fItem->fSubMenu = dlg.selection();
fSubMenuKey->setText(st2qstr(fItem->fSubMenu->getName()));
fSubMenuKey->setText(pqFormatKeyName(fItem->fSubMenu));
} else {
fItem->fSubMenu = plKey();
fSubMenuKey->setText(tr("(Null)"));
Expand Down
4 changes: 2 additions & 2 deletions src/PrpShop/PRP/GUI/QGUIRadioGroupCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QGUIRadioGroupCtrl::QGUIRadioGroupCtrl(plCreatable* pCre, QWidget* parent)
for (size_t i=0; i<ctrl->getControls().size(); i++) {
fControls->addKey(ctrl->getControls()[i]);
fDefaultValue->addItem(pqGetTypeIcon(ctrl->getControls()[i]->getType()),
st2qstr(ctrl->getControls()[i]->getName()));
pqFormatKeyName(ctrl->getControls()[i]));
}
fDefaultValue->setCurrentIndex(ctrl->getDefaultValue());

Expand Down Expand Up @@ -81,7 +81,7 @@ void QGUIRadioGroupCtrl::saveDamage()

void QGUIRadioGroupCtrl::controlAdded(plKey ctrl)
{
fDefaultValue->addItem(pqGetTypeIcon(ctrl->getType()), st2qstr(ctrl->getName()));
fDefaultValue->addItem(pqGetTypeIcon(ctrl->getType()), pqFormatKeyName(ctrl));
}

void QGUIRadioGroupCtrl::controlRemoved(int which)
Expand Down
6 changes: 3 additions & 3 deletions src/PrpShop/PRP/Modifier/QPythonFileMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static QStringList makeParamItem(const plPythonParameter& param)
else if (param.fValueType == plPythonParameter::kNone)
row << "(None)";
else if (param.fObjKey.Exists())
row << st2qstr(param.fObjKey->getName());
row << pqFormatKeyName(param.fObjKey);
else
row << "(None)";
return row;
Expand Down Expand Up @@ -261,7 +261,7 @@ void QPythonParamDialog::init(const plPythonParameter& param)
} else {
fKey = param.fObjKey;
if (fKey.Exists())
fKeyValue->setText(st2qstr(fKey->getName()));
fKeyValue->setText(pqFormatKeyName(fKey));
else
fKeyValue->setText("(None)");
}
Expand Down Expand Up @@ -298,7 +298,7 @@ void QPythonParamDialog::selectKey()
dlg.init(PrpShopMain::ResManager(), fKey);
if (dlg.exec() == QDialog::Accepted) {
fKey = dlg.selection();
fKeyValue->setText(st2qstr(fKey->getName()));
fKeyValue->setText(pqFormatKeyName(fKey));
}
}

Expand Down
Loading