2014-09-19 01:10:05 +02:00
|
|
|
#include "ObjectViewer.hpp"
|
|
|
|
#include <models/ObjectListModel.hpp>
|
|
|
|
#include "ViewerWidget.hpp"
|
2014-09-21 17:13:01 +02:00
|
|
|
#include <QDebug>
|
2015-04-14 02:06:50 +02:00
|
|
|
#include <QMenu>
|
2014-09-19 01:10:05 +02:00
|
|
|
|
|
|
|
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
|
|
|
: QWidget(parent, f)
|
|
|
|
{
|
2014-09-21 17:13:01 +02:00
|
|
|
mainLayout = new QHBoxLayout;
|
2014-09-19 01:10:05 +02:00
|
|
|
|
2014-09-21 17:13:01 +02:00
|
|
|
objectList = new QTableView;
|
2014-09-19 01:10:05 +02:00
|
|
|
|
2015-04-14 02:06:50 +02:00
|
|
|
objectMenu = new QMenu(objectList);
|
|
|
|
objectList->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
auto viewModelAction = new QAction("View Model", objectMenu);
|
|
|
|
objectMenu->addAction(viewModelAction);
|
|
|
|
connect(viewModelAction, SIGNAL(triggered()), this, SLOT(menuViewModel()));
|
|
|
|
connect(objectList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint)));
|
|
|
|
|
2014-09-21 17:13:01 +02:00
|
|
|
mainLayout->addWidget(objectList);
|
2014-09-19 01:10:05 +02:00
|
|
|
|
|
|
|
previewWidget = viewer;
|
|
|
|
previewWidget->setMinimumSize(250,250);
|
|
|
|
|
2014-09-21 17:13:01 +02:00
|
|
|
infoLayout = new QGridLayout;
|
2014-09-19 01:10:05 +02:00
|
|
|
|
|
|
|
previewID = new QLabel;
|
|
|
|
previewModel = new QLabel;
|
|
|
|
previewClass = new QLabel;
|
2014-09-21 17:13:01 +02:00
|
|
|
infoLayout->addWidget(new QLabel("ID"), 1, 0);
|
|
|
|
infoLayout->addWidget(previewID, 1, 1);
|
|
|
|
infoLayout->addWidget(new QLabel("Type"), 2, 0);
|
|
|
|
infoLayout->addWidget(previewClass, 2, 1);
|
|
|
|
infoLayout->addWidget(new QLabel("Model"), 3, 0);
|
|
|
|
infoLayout->addWidget(previewModel, 3, 1);
|
|
|
|
|
|
|
|
mainLayout->addLayout(infoLayout);
|
2014-09-19 01:10:05 +02:00
|
|
|
|
2014-09-21 17:13:01 +02:00
|
|
|
this->setLayout(mainLayout);
|
2014-09-19 01:10:05 +02:00
|
|
|
|
2014-09-21 17:13:01 +02:00
|
|
|
setViewerWidget(previewWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectViewer::setViewerWidget(ViewerWidget* widget)
|
|
|
|
{
|
|
|
|
static size_t c = 0;
|
|
|
|
//widgetLayout->removeWidget(previewWidget);
|
|
|
|
previewWidget = widget;
|
|
|
|
infoLayout->addWidget(previewWidget, 0, 0, 1, 2);
|
2014-09-19 01:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::map<ObjectInformation::ObjectClass, QString> gDataType =
|
|
|
|
{
|
|
|
|
{ ObjectInformation::_class("OBJS"), "Object" },
|
|
|
|
{ ObjectInformation::_class("CARS"), "Vehicle" },
|
|
|
|
{ ObjectInformation::_class("PEDS"), "Pedestrian" },
|
|
|
|
{ ObjectInformation::_class("HIER"), "Cutscene" }
|
|
|
|
};
|
|
|
|
|
|
|
|
void ObjectViewer::showItem(qint16 item)
|
|
|
|
{
|
2015-04-24 19:09:21 +02:00
|
|
|
auto def = world()->data->objectTypes[item];
|
2014-09-19 01:10:05 +02:00
|
|
|
|
|
|
|
if( def )
|
|
|
|
{
|
|
|
|
previewID->setText(QString::number(def->ID));
|
|
|
|
previewClass->setText(gDataType[def->class_type]);
|
|
|
|
|
|
|
|
if(def->class_type == ObjectData::class_id)
|
|
|
|
{
|
|
|
|
auto v = std::static_pointer_cast<ObjectData>(def);
|
|
|
|
previewModel->setText(QString::fromStdString(v->modelName));
|
|
|
|
}
|
|
|
|
else if(def->class_type == VehicleData::class_id)
|
|
|
|
{
|
|
|
|
auto v = std::static_pointer_cast<VehicleData>(def);
|
|
|
|
previewModel->setText(QString::fromStdString(v->modelName));
|
|
|
|
}
|
|
|
|
else if(def->class_type == CharacterData::class_id)
|
|
|
|
{
|
|
|
|
auto v = std::static_pointer_cast<CharacterData>(def);
|
|
|
|
previewModel->setText(QString::fromStdString(v->modelName));
|
|
|
|
}
|
|
|
|
|
2015-04-14 02:06:50 +02:00
|
|
|
previewWidget->showObject(item);
|
2014-09-19 01:10:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectViewer::showData(GameWorld *world)
|
|
|
|
{
|
|
|
|
_world = world;
|
|
|
|
|
|
|
|
// Loade all of the IDEs.
|
2015-04-18 02:11:17 +02:00
|
|
|
for(std::map<std::string, std::string>::iterator it = world->data->ideLocations.begin();
|
|
|
|
it != world->data->ideLocations.end();
|
2014-09-19 01:10:05 +02:00
|
|
|
++it) {
|
2015-04-24 19:09:21 +02:00
|
|
|
world->data->loadObjects(it->second);
|
2014-09-19 01:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( objectList->model() )
|
|
|
|
{
|
|
|
|
delete objectList->model();
|
|
|
|
}
|
|
|
|
|
2015-04-24 19:09:21 +02:00
|
|
|
objectList->setModel(new ObjectListModel(world->data, objectList));
|
2014-09-19 01:10:05 +02:00
|
|
|
connect(objectList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showItem(QModelIndex)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectViewer::showItem(QModelIndex model)
|
|
|
|
{
|
|
|
|
showItem(model.internalId());
|
|
|
|
}
|
|
|
|
|
2015-04-14 02:06:50 +02:00
|
|
|
void ObjectViewer::onCustomContextMenu(const QPoint& p)
|
|
|
|
{
|
|
|
|
contextMenuIndex = objectList->indexAt(p);
|
|
|
|
if ( contextMenuIndex.isValid() )
|
|
|
|
{
|
|
|
|
objectMenu->exec(objectList->mapToGlobal(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectViewer::menuViewModel()
|
|
|
|
{
|
|
|
|
if( contextMenuIndex.isValid() )
|
|
|
|
{
|
|
|
|
auto id = contextMenuIndex.internalId();
|
|
|
|
showObjectModel(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|