mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
clang-format files in rwviewer
This commit is contained in:
parent
8a19f9b5d0
commit
d1c33af268
@ -1,35 +1,32 @@
|
||||
#include "AnimationListModel.hpp"
|
||||
|
||||
QVariant AnimationListModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole) {
|
||||
if(index.row() >= 0 && (unsigned) index.row() < animations.size()) {
|
||||
auto& f = animations.at(index.row());
|
||||
if(index.column() == 0) {
|
||||
return QString(f.first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant AnimationListModel::data(const QModelIndex& index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.row() >= 0 && (unsigned)index.row() < animations.size()) {
|
||||
auto& f = animations.at(index.row());
|
||||
if (index.column() == 0) {
|
||||
return QString(f.first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
QVariant AnimationListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if(section == 0) {
|
||||
return "Name";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant AnimationListModel::headerData(int section,
|
||||
Qt::Orientation orientation,
|
||||
int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if (section == 0) {
|
||||
return "Name";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
int AnimationListModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return animations.size();
|
||||
int AnimationListModel::rowCount(const QModelIndex& parent) const {
|
||||
return animations.size();
|
||||
}
|
||||
|
||||
int AnimationListModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return 1;
|
||||
int AnimationListModel::columnCount(const QModelIndex& parent) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -6,27 +6,29 @@
|
||||
|
||||
typedef std::vector<std::pair<std::string, Animation*>> AnimationList;
|
||||
|
||||
class AnimationListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
class AnimationListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
AnimationList animations;
|
||||
AnimationList animations;
|
||||
|
||||
public:
|
||||
|
||||
AnimationListModel(const AnimationList& anims, QObject* parent = 0)
|
||||
: QAbstractListModel(parent), animations(anims)
|
||||
{}
|
||||
AnimationListModel(const AnimationList& anims, QObject* parent = 0)
|
||||
: QAbstractListModel(parent), animations(anims) {
|
||||
}
|
||||
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant data(const QModelIndex& index,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
const AnimationList& getAnimations() const { return animations; }
|
||||
const AnimationList& getAnimations() const {
|
||||
return animations;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2,47 +2,45 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
|
||||
{
|
||||
setWindowTitle("Animations");
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QWidget* intermediate = new QWidget();
|
||||
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
|
||||
setWindowTitle("Animations");
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QWidget* intermediate = new QWidget();
|
||||
|
||||
searchbox = new QLineEdit();
|
||||
searchbox->setPlaceholderText("Search");
|
||||
searchbox = new QLineEdit();
|
||||
searchbox->setPlaceholderText("Search");
|
||||
|
||||
table = new QListView();
|
||||
layout->addWidget(searchbox);
|
||||
layout->addWidget(table);
|
||||
intermediate->setLayout(layout);
|
||||
setWidget(intermediate);
|
||||
table = new QListView();
|
||||
layout->addWidget(searchbox);
|
||||
layout->addWidget(table);
|
||||
intermediate->setLayout(layout);
|
||||
setWidget(intermediate);
|
||||
|
||||
filter = new QSortFilterProxyModel;
|
||||
table->setModel(filter);
|
||||
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
|
||||
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
|
||||
filter = new QSortFilterProxyModel;
|
||||
table->setModel(filter);
|
||||
connect(table->selectionModel(),
|
||||
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||
SLOT(selectedIndexChanged(QModelIndex)));
|
||||
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
|
||||
}
|
||||
|
||||
void AnimationListWidget::setAnimations(const AnimationList& archive)
|
||||
{
|
||||
auto m = new AnimationListModel(archive);
|
||||
filter->setSourceModel(m);
|
||||
if(model) {
|
||||
delete model;
|
||||
}
|
||||
model = m;
|
||||
void AnimationListWidget::setAnimations(const AnimationList& archive) {
|
||||
auto m = new AnimationListModel(archive);
|
||||
filter->setSourceModel(m);
|
||||
if (model) {
|
||||
delete model;
|
||||
}
|
||||
model = m;
|
||||
}
|
||||
|
||||
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current)
|
||||
{
|
||||
auto mts = filter->mapToSource(current);
|
||||
if(mts.row() >= 0 && (unsigned) mts.row() < model->getAnimations().size()) {
|
||||
auto& f = model->getAnimations().at(mts.row());
|
||||
emit selectedAnimationChanged(f.second);
|
||||
}
|
||||
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) {
|
||||
auto mts = filter->mapToSource(current);
|
||||
if (mts.row() >= 0 && (unsigned)mts.row() < model->getAnimations().size()) {
|
||||
auto& f = model->getAnimations().at(mts.row());
|
||||
emit selectedAnimationChanged(f.second);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationListWidget::setFilter(const QString &f)
|
||||
{
|
||||
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
|
||||
void AnimationListWidget::setFilter(const QString& f) {
|
||||
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
|
||||
}
|
||||
|
@ -2,34 +2,32 @@
|
||||
#ifndef _ANIMATIONLISTWIDGET_HPP_
|
||||
#define _ANIMATIONLISTWIDGET_HPP_
|
||||
#include <QDockWidget>
|
||||
#include <QListView>
|
||||
#include <QLineEdit>
|
||||
#include <QListView>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "AnimationListModel.hpp"
|
||||
|
||||
class AnimationListWidget : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class AnimationListWidget : public QDockWidget {
|
||||
Q_OBJECT
|
||||
|
||||
QSortFilterProxyModel* filter;
|
||||
AnimationListModel* model;
|
||||
QListView* table;
|
||||
QLineEdit* searchbox;
|
||||
QSortFilterProxyModel* filter;
|
||||
AnimationListModel* model;
|
||||
QListView* table;
|
||||
QLineEdit* searchbox;
|
||||
|
||||
public:
|
||||
AnimationListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
AnimationListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
void setAnimations(const AnimationList& anims);
|
||||
void setAnimations(const AnimationList& anims);
|
||||
|
||||
signals:
|
||||
|
||||
void selectedAnimationChanged(Animation* anim);
|
||||
void selectedAnimationChanged(Animation* anim);
|
||||
|
||||
public slots:
|
||||
void selectedIndexChanged(const QModelIndex& current);
|
||||
void selectedIndexChanged(const QModelIndex& current);
|
||||
|
||||
void setFilter(const QString& f);
|
||||
void setFilter(const QString& f);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,41 +1,38 @@
|
||||
#include "IMGArchiveModel.hpp"
|
||||
|
||||
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole) {
|
||||
if(index.row() >= 0 && (unsigned) index.row() < archive.getAssetCount()) {
|
||||
auto& f = archive.getAssetInfoByIndex(index.row());
|
||||
if(index.column() == 0) {
|
||||
return QString(f.name);
|
||||
}
|
||||
if(index.column() == 1) {
|
||||
return f.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.row() >= 0 &&
|
||||
(unsigned)index.row() < archive.getAssetCount()) {
|
||||
auto& f = archive.getAssetInfoByIndex(index.row());
|
||||
if (index.column() == 0) {
|
||||
return QString(f.name);
|
||||
}
|
||||
if (index.column() == 1) {
|
||||
return f.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if(section == 0) {
|
||||
return "Name";
|
||||
}
|
||||
if(section == 1) {
|
||||
return "Size";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if (section == 0) {
|
||||
return "Name";
|
||||
}
|
||||
if (section == 1) {
|
||||
return "Size";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
int IMGArchiveModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return archive.getAssetCount();
|
||||
int IMGArchiveModel::rowCount(const QModelIndex& parent) const {
|
||||
return archive.getAssetCount();
|
||||
}
|
||||
|
||||
int IMGArchiveModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return 2;
|
||||
int IMGArchiveModel::columnCount(const QModelIndex& parent) const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -4,27 +4,29 @@
|
||||
#include <QAbstractItemModel>
|
||||
#include <loaders/LoaderIMG.hpp>
|
||||
|
||||
class IMGArchiveModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
class IMGArchiveModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
LoaderIMG archive;
|
||||
LoaderIMG archive;
|
||||
|
||||
public:
|
||||
|
||||
IMGArchiveModel(const LoaderIMG& archive, QObject* parent = 0)
|
||||
: QAbstractListModel(parent), archive(archive)
|
||||
{}
|
||||
: QAbstractListModel(parent), archive(archive) {
|
||||
}
|
||||
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant data(const QModelIndex& index,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
const LoaderIMG& getArchive() const { return archive; }
|
||||
const LoaderIMG& getArchive() const {
|
||||
return archive;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,60 +1,55 @@
|
||||
#include "ItemListModel.hpp"
|
||||
#include <engine/GameData.hpp>
|
||||
|
||||
qint16 ItemListModel::getIDOf(unsigned int row) const
|
||||
{
|
||||
if( row < world()->data->objectTypes.size() )
|
||||
{
|
||||
return row;
|
||||
}
|
||||
qint16 ItemListModel::getIDOf(unsigned int row) const {
|
||||
if (row < world()->data->objectTypes.size()) {
|
||||
return row;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ItemListModel::ItemListModel(GameWorld *world, QObject *parent) :
|
||||
QAbstractTableModel(parent), _world( world )
|
||||
{
|
||||
ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
|
||||
: QAbstractTableModel(parent), _world(world) {
|
||||
}
|
||||
|
||||
int ItemListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return _world->data->objectTypes.size();
|
||||
int ItemListModel::rowCount(const QModelIndex &parent) const {
|
||||
return _world->data->objectTypes.size();
|
||||
}
|
||||
|
||||
int ItemListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 2;
|
||||
int ItemListModel::columnCount(const QModelIndex &parent) const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant ItemListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if ( role == Qt::DisplayRole ) {
|
||||
qint16 id = getIDOf(index.row());
|
||||
if( id == -1 ) return QVariant::Invalid;
|
||||
if( index.column() == 0 ) {
|
||||
return id;
|
||||
}
|
||||
else if ( index.column() == 1 ) {
|
||||
return QString::fromStdString("TODO");
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant ItemListModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
qint16 id = getIDOf(index.row());
|
||||
if (id == -1) return QVariant::Invalid;
|
||||
if (index.column() == 0) {
|
||||
return id;
|
||||
} else if (index.column() == 1) {
|
||||
return QString::fromStdString("TODO");
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if(section == 0) {
|
||||
return "ID";
|
||||
}
|
||||
if(section == 1) {
|
||||
return "Model";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
if (section == 0) {
|
||||
return "ID";
|
||||
}
|
||||
if (section == 1) {
|
||||
return "Model";
|
||||
}
|
||||
}
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
|
||||
QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex();
|
||||
QModelIndex ItemListModel::index(int row, int column,
|
||||
const QModelIndex &parent) const {
|
||||
return hasIndex(row, column, parent)
|
||||
? createIndex(row, column, getIDOf(row))
|
||||
: QModelIndex();
|
||||
}
|
||||
|
@ -5,28 +5,31 @@
|
||||
|
||||
#include <engine/GameWorld.hpp>
|
||||
|
||||
class ItemListModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
class ItemListModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
GameWorld* _world;
|
||||
GameWorld* _world;
|
||||
|
||||
public:
|
||||
explicit ItemListModel(GameWorld* _world, QObject *parent = 0);
|
||||
explicit ItemListModel(GameWorld* _world, QObject* parent = 0);
|
||||
|
||||
GameWorld* world() const { return _world; }
|
||||
GameWorld* world() const {
|
||||
return _world;
|
||||
}
|
||||
|
||||
qint16 getIDOf(unsigned int row ) const;
|
||||
qint16 getIDOf(unsigned int row) const;
|
||||
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
|
||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant data(const QModelIndex& index,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
||||
};
|
||||
|
||||
#endif // ITEMLISTMODEL_HPP
|
||||
#endif // ITEMLISTMODEL_HPP
|
||||
|
@ -1,47 +1,45 @@
|
||||
#include "ItemListWidget.hpp"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
|
||||
{
|
||||
setWindowTitle("Items");
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QWidget* intermediate = new QWidget();
|
||||
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
|
||||
setWindowTitle("Items");
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QWidget* intermediate = new QWidget();
|
||||
|
||||
searchbox = new QLineEdit();
|
||||
searchbox->setPlaceholderText("Search");
|
||||
searchbox = new QLineEdit();
|
||||
searchbox->setPlaceholderText("Search");
|
||||
|
||||
table = new QTableView();
|
||||
layout->addWidget(searchbox);
|
||||
layout->addWidget(table);
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
intermediate->setLayout(layout);
|
||||
setWidget(intermediate);
|
||||
table = new QTableView();
|
||||
layout->addWidget(searchbox);
|
||||
layout->addWidget(table);
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
intermediate->setLayout(layout);
|
||||
setWidget(intermediate);
|
||||
|
||||
filter = new QSortFilterProxyModel;
|
||||
table->setModel(filter);
|
||||
filter->setFilterKeyColumn(-1); // Search all columns
|
||||
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
|
||||
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
|
||||
filter = new QSortFilterProxyModel;
|
||||
table->setModel(filter);
|
||||
filter->setFilterKeyColumn(-1); // Search all columns
|
||||
connect(table->selectionModel(),
|
||||
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||
SLOT(selectedIndexChanged(QModelIndex)));
|
||||
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
|
||||
}
|
||||
|
||||
void ItemListWidget::worldLoaded(GameWorld *world)
|
||||
{
|
||||
if ( model ) delete model;
|
||||
model = new ItemListModel( world, this );
|
||||
filter->setSourceModel( model );
|
||||
void ItemListWidget::worldLoaded(GameWorld* world) {
|
||||
if (model) delete model;
|
||||
model = new ItemListModel(world, this);
|
||||
filter->setSourceModel(model);
|
||||
}
|
||||
|
||||
void ItemListWidget::selectedIndexChanged(const QModelIndex& current)
|
||||
{
|
||||
auto mts = filter->mapToSource(current);
|
||||
if( mts.isValid() ) {
|
||||
emit selectedItemChanged( model->getIDOf(mts.row()) );
|
||||
}
|
||||
void ItemListWidget::selectedIndexChanged(const QModelIndex& current) {
|
||||
auto mts = filter->mapToSource(current);
|
||||
if (mts.isValid()) {
|
||||
emit selectedItemChanged(model->getIDOf(mts.row()));
|
||||
}
|
||||
}
|
||||
|
||||
void ItemListWidget::setFilter(const QString &f)
|
||||
{
|
||||
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
|
||||
void ItemListWidget::setFilter(const QString& f) {
|
||||
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
|
||||
}
|
||||
|
@ -2,33 +2,32 @@
|
||||
#ifndef _ITEMLISTWIDGET_HPP_
|
||||
#define _ITEMLISTWIDGET_HPP_
|
||||
#include <QDockWidget>
|
||||
#include <QTableView>
|
||||
#include <QLineEdit>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTableView>
|
||||
#include "ItemListModel.hpp"
|
||||
|
||||
class ItemListWidget : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class ItemListWidget : public QDockWidget {
|
||||
Q_OBJECT
|
||||
|
||||
QSortFilterProxyModel* filter;
|
||||
ItemListModel* model;
|
||||
QTableView* table;
|
||||
QLineEdit* searchbox;
|
||||
QSortFilterProxyModel* filter;
|
||||
ItemListModel* model;
|
||||
QTableView* table;
|
||||
QLineEdit* searchbox;
|
||||
|
||||
public:
|
||||
ItemListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
ItemListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
signals:
|
||||
void selectedItemChanged(const qint16 id);
|
||||
void selectedItemChanged(const qint16 id);
|
||||
|
||||
public slots:
|
||||
|
||||
void worldLoaded(GameWorld* world);
|
||||
void worldLoaded(GameWorld* world);
|
||||
|
||||
void selectedIndexChanged(const QModelIndex& current);
|
||||
void selectedIndexChanged(const QModelIndex& current);
|
||||
|
||||
void setFilter(const QString& f);
|
||||
void setFilter(const QString& f);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,239 +1,214 @@
|
||||
#include "ViewerWidget.hpp"
|
||||
#include <QFileDialog>
|
||||
#include <QMouseEvent>
|
||||
#include <algorithm>
|
||||
#include <data/Model.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
#include <render/OpenGLRenderer.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <QMouseEvent>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <QFileDialog>
|
||||
#include <algorithm>
|
||||
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
|
||||
|
||||
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
|
||||
: QGLWidget(g, parent, shareWidget, f)
|
||||
, gworld(nullptr)
|
||||
, activeModel(nullptr)
|
||||
, selectedFrame(nullptr)
|
||||
, dummyObject(nullptr)
|
||||
, currentObjectID(0)
|
||||
, _lastModel(nullptr)
|
||||
, canimation(nullptr)
|
||||
, viewDistance(1.f)
|
||||
, dragging(false)
|
||||
, moveFast(false)
|
||||
, _frameWidgetDraw(nullptr)
|
||||
, _frameWidgetGeom(nullptr)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent,
|
||||
const QGLWidget* shareWidget, Qt::WindowFlags f)
|
||||
: QGLWidget(g, parent, shareWidget, f)
|
||||
, gworld(nullptr)
|
||||
, activeModel(nullptr)
|
||||
, selectedFrame(nullptr)
|
||||
, dummyObject(nullptr)
|
||||
, currentObjectID(0)
|
||||
, _lastModel(nullptr)
|
||||
, canimation(nullptr)
|
||||
, viewDistance(1.f)
|
||||
, dragging(false)
|
||||
, moveFast(false)
|
||||
, _frameWidgetDraw(nullptr)
|
||||
, _frameWidgetGeom(nullptr) {
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
struct WidgetVertex {
|
||||
float x, y, z;
|
||||
static const AttributeList vertex_attributes() {
|
||||
return {
|
||||
{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}
|
||||
};
|
||||
}
|
||||
float x, y, z;
|
||||
static const AttributeList vertex_attributes() {
|
||||
return {{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}};
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<WidgetVertex> widgetVerts = {
|
||||
{-.5f, 0.f, 0.f},
|
||||
{ .5f, 0.f, 0.f},
|
||||
{ 0.f,-.5f, 0.f},
|
||||
{ 0.f, .5f, 0.f},
|
||||
{ 0.f, 0.f,-.5f},
|
||||
{ 0.f, 0.f, .5f}
|
||||
};
|
||||
std::vector<WidgetVertex> widgetVerts = {{-.5f, 0.f, 0.f}, {.5f, 0.f, 0.f},
|
||||
{0.f, -.5f, 0.f}, {0.f, .5f, 0.f},
|
||||
{0.f, 0.f, -.5f}, {0.f, 0.f, .5f}};
|
||||
|
||||
void ViewerWidget::initializeGL()
|
||||
{
|
||||
QGLWidget::initializeGL();
|
||||
timer.setInterval(25);
|
||||
connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
|
||||
timer.start();
|
||||
void ViewerWidget::initializeGL() {
|
||||
QGLWidget::initializeGL();
|
||||
timer.setInterval(25);
|
||||
connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
|
||||
timer.start();
|
||||
|
||||
_frameWidgetDraw = new DrawBuffer;
|
||||
_frameWidgetDraw->setFaceType(GL_LINES);
|
||||
_frameWidgetGeom = new GeometryBuffer;
|
||||
_frameWidgetGeom->uploadVertices(widgetVerts);
|
||||
_frameWidgetDraw->addGeometry(_frameWidgetGeom);
|
||||
_frameWidgetDraw = new DrawBuffer;
|
||||
_frameWidgetDraw->setFaceType(GL_LINES);
|
||||
_frameWidgetGeom = new GeometryBuffer;
|
||||
_frameWidgetGeom->uploadVertices(widgetVerts);
|
||||
_frameWidgetDraw->addGeometry(_frameWidgetGeom);
|
||||
|
||||
glGenTextures(1, &whiteTex);
|
||||
glBindTexture(GL_TEXTURE_2D, whiteTex);
|
||||
GLuint tex = 0xFFFFFFFF;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glGenTextures(1, &whiteTex);
|
||||
glBindTexture(GL_TEXTURE_2D, whiteTex);
|
||||
GLuint tex = 0xFFFFFFFF;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE,
|
||||
&tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
void ViewerWidget::resizeGL(int w, int h)
|
||||
{
|
||||
QGLWidget::resizeGL(w, h);
|
||||
glViewport(0, 0, w, h);
|
||||
void ViewerWidget::resizeGL(int w, int h) {
|
||||
QGLWidget::resizeGL(w, h);
|
||||
glViewport(0, 0, w, h);
|
||||
}
|
||||
|
||||
void ViewerWidget::paintGL()
|
||||
{
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
void ViewerWidget::paintGL() {
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glViewport(0, 0, width(), height());
|
||||
glViewport(0, 0, width(), height());
|
||||
|
||||
if( world() == nullptr ) return;
|
||||
if (world() == nullptr) return;
|
||||
|
||||
auto& r = *renderer;
|
||||
auto& r = *renderer;
|
||||
|
||||
r.setViewport(width(), height());
|
||||
r.setViewport(width(), height());
|
||||
|
||||
if(dummyObject && dummyObject->animator && dummyObject->skeleton) {
|
||||
dummyObject->animator->tick(1.f/60.f);
|
||||
dummyObject->skeleton->interpolate(1.f);
|
||||
}
|
||||
if (dummyObject && dummyObject->animator && dummyObject->skeleton) {
|
||||
dummyObject->animator->tick(1.f / 60.f);
|
||||
dummyObject->skeleton->interpolate(1.f);
|
||||
}
|
||||
|
||||
gworld->_work->update();
|
||||
gworld->_work->update();
|
||||
|
||||
r.getRenderer()->invalidate();
|
||||
r.getRenderer()->invalidate();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glm::mat4 m(1.f);
|
||||
glm::mat4 m(1.f);
|
||||
|
||||
r.getRenderer()->useProgram(r.worldProg);
|
||||
r.getRenderer()->useProgram(r.worldProg);
|
||||
|
||||
ViewCamera vc;
|
||||
ViewCamera vc;
|
||||
|
||||
float viewFov = glm::radians(45.f);
|
||||
float viewFov = glm::radians(45.f);
|
||||
|
||||
vc.frustum.far = 500.f;
|
||||
vc.frustum.near = 0.1f;
|
||||
vc.frustum.fov = viewFov;
|
||||
vc.frustum.aspectRatio = width()/(height()*1.f);
|
||||
vc.frustum.far = 500.f;
|
||||
vc.frustum.near = 0.1f;
|
||||
vc.frustum.fov = viewFov;
|
||||
vc.frustum.aspectRatio = width() / (height() * 1.f);
|
||||
|
||||
Model* model = activeModel;
|
||||
if( model != _lastModel ) {
|
||||
_lastModel = model;
|
||||
emit modelChanged(_lastModel);
|
||||
}
|
||||
Model* model = activeModel;
|
||||
if (model != _lastModel) {
|
||||
_lastModel = model;
|
||||
emit modelChanged(_lastModel);
|
||||
}
|
||||
|
||||
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y), cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
|
||||
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y),
|
||||
cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
|
||||
|
||||
if( model )
|
||||
{
|
||||
glm::mat4 proj = vc.frustum.projection();
|
||||
glm::mat4 view = glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f));
|
||||
if (model) {
|
||||
glm::mat4 proj = vc.frustum.projection();
|
||||
glm::mat4 view =
|
||||
glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f),
|
||||
glm::vec3(0.f, 0.f, 1.f));
|
||||
|
||||
r.getRenderer()->setSceneParameters({ proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f), glm::vec4(0.f), 90.f, vc.frustum.far });
|
||||
r.getRenderer()->setSceneParameters(
|
||||
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
|
||||
glm::vec4(0.f), 90.f, vc.frustum.far});
|
||||
|
||||
r.getRenderer()->invalidate();
|
||||
r.getRenderer()->invalidate();
|
||||
|
||||
r.setupRender();
|
||||
r.setupRender();
|
||||
|
||||
r.renderModel(model, m, dummyObject);
|
||||
r.renderModel(model, m, dummyObject);
|
||||
|
||||
drawFrameWidget(model->frames[model->rootFrameIdx]);
|
||||
r.renderPostProcess();
|
||||
}
|
||||
else if (world()->allObjects.size() > 0)
|
||||
{
|
||||
vc.frustum.fov = glm::radians(90.f);
|
||||
vc.frustum.far = 1000.f;
|
||||
vc.position = viewPosition;
|
||||
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x, glm::vec3(0.f, 0.f, 1.f))
|
||||
* glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f));
|
||||
r.renderWorld(world(), vc, 0.f);
|
||||
}
|
||||
drawFrameWidget(model->frames[model->rootFrameIdx]);
|
||||
r.renderPostProcess();
|
||||
} else if (world()->allObjects.size() > 0) {
|
||||
vc.frustum.fov = glm::radians(90.f);
|
||||
vc.frustum.far = 1000.f;
|
||||
vc.position = viewPosition;
|
||||
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x,
|
||||
glm::vec3(0.f, 0.f, 1.f)) *
|
||||
glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f));
|
||||
r.renderWorld(world(), vc, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m)
|
||||
{
|
||||
auto thisM = m * f->getTransform();
|
||||
if(f->getGeometries().size() == 0)
|
||||
{
|
||||
Renderer::DrawParameters dp;
|
||||
dp.count = _frameWidgetGeom->getCount();
|
||||
dp.start = 0;
|
||||
dp.ambient = 1.f;
|
||||
dp.diffuse = 1.f;
|
||||
if( f == selectedFrame )
|
||||
{
|
||||
dp.colour = {255, 255, 0, 255};
|
||||
// Sorry!
|
||||
glLineWidth(10.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
dp.colour = {255, 255, 255, 255};
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
dp.textures = { whiteTex };
|
||||
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
|
||||
}
|
||||
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
|
||||
auto thisM = m * f->getTransform();
|
||||
if (f->getGeometries().size() == 0) {
|
||||
Renderer::DrawParameters dp;
|
||||
dp.count = _frameWidgetGeom->getCount();
|
||||
dp.start = 0;
|
||||
dp.ambient = 1.f;
|
||||
dp.diffuse = 1.f;
|
||||
if (f == selectedFrame) {
|
||||
dp.colour = {255, 255, 0, 255};
|
||||
// Sorry!
|
||||
glLineWidth(10.f);
|
||||
} else {
|
||||
dp.colour = {255, 255, 255, 255};
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
dp.textures = {whiteTex};
|
||||
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
|
||||
}
|
||||
|
||||
for(auto c : f->getChildren()) {
|
||||
drawFrameWidget(c, thisM);
|
||||
}
|
||||
for (auto c : f->getChildren()) {
|
||||
drawFrameWidget(c, thisM);
|
||||
}
|
||||
}
|
||||
|
||||
GameWorld* ViewerWidget::world()
|
||||
{
|
||||
return gworld;
|
||||
GameWorld* ViewerWidget::world() {
|
||||
return gworld;
|
||||
}
|
||||
|
||||
void ViewerWidget::showObject(qint16 item)
|
||||
{
|
||||
currentObjectID = item;
|
||||
void ViewerWidget::showObject(qint16 item) {
|
||||
currentObjectID = item;
|
||||
|
||||
if( dummyObject ) gworld->destroyObject( dummyObject );
|
||||
if (dummyObject) gworld->destroyObject(dummyObject);
|
||||
|
||||
auto def = world()->data->objectTypes[item];
|
||||
auto def = world()->data->objectTypes[item];
|
||||
|
||||
if( def )
|
||||
{
|
||||
if(def->class_type == ObjectData::class_id)
|
||||
{
|
||||
dummyObject = gworld->createInstance(item, {});
|
||||
}
|
||||
else if(def->class_type == CharacterData::class_id)
|
||||
{
|
||||
dummyObject = gworld->createPedestrian(item, {});
|
||||
}
|
||||
else if(def->class_type == VehicleData::class_id)
|
||||
{
|
||||
dummyObject = gworld->createVehicle(item, {});
|
||||
}
|
||||
RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
|
||||
if (dummyObject != nullptr) {
|
||||
activeModel = dummyObject->model->resource;
|
||||
}
|
||||
}
|
||||
if (def) {
|
||||
if (def->class_type == ObjectData::class_id) {
|
||||
dummyObject = gworld->createInstance(item, {});
|
||||
} else if (def->class_type == CharacterData::class_id) {
|
||||
dummyObject = gworld->createPedestrian(item, {});
|
||||
} else if (def->class_type == VehicleData::class_id) {
|
||||
dummyObject = gworld->createVehicle(item, {});
|
||||
}
|
||||
RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
|
||||
if (dummyObject != nullptr) {
|
||||
activeModel = dummyObject->model->resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::showModel(Model* model)
|
||||
{
|
||||
if( dummyObject ) gworld->destroyObject( dummyObject );
|
||||
dummyObject = nullptr;
|
||||
activeModel = model;
|
||||
void ViewerWidget::showModel(Model* model) {
|
||||
if (dummyObject) gworld->destroyObject(dummyObject);
|
||||
dummyObject = nullptr;
|
||||
activeModel = model;
|
||||
}
|
||||
|
||||
void ViewerWidget::selectFrame(ModelFrame* frame)
|
||||
{
|
||||
selectedFrame = frame;
|
||||
void ViewerWidget::selectFrame(ModelFrame* frame) {
|
||||
selectedFrame = frame;
|
||||
}
|
||||
|
||||
void ViewerWidget::exportModel()
|
||||
{
|
||||
QString toSv = QFileDialog::getSaveFileName(this,
|
||||
"Export Model",
|
||||
QDir::homePath(),
|
||||
"Model (*.DFF)");
|
||||
void ViewerWidget::exportModel() {
|
||||
QString toSv = QFileDialog::getSaveFileName(
|
||||
this, "Export Model", QDir::homePath(), "Model (*.DFF)");
|
||||
|
||||
if( toSv.size() == 0 ) return;
|
||||
if (toSv.size() == 0) return;
|
||||
|
||||
#if 0
|
||||
auto it = world()->objectTypes.find(currentObjectID);
|
||||
@ -252,77 +227,60 @@ void ViewerWidget::exportModel()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewerWidget::dataLoaded(GameWorld *world)
|
||||
{
|
||||
gworld = world;
|
||||
void ViewerWidget::dataLoaded(GameWorld* world) {
|
||||
gworld = world;
|
||||
}
|
||||
|
||||
void ViewerWidget::setRenderer(GameRenderer *render)
|
||||
{
|
||||
renderer = render;
|
||||
void ViewerWidget::setRenderer(GameRenderer* render) {
|
||||
renderer = render;
|
||||
}
|
||||
|
||||
void ViewerWidget::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Shift)
|
||||
moveFast = true;
|
||||
void ViewerWidget::keyPressEvent(QKeyEvent* e) {
|
||||
if (e->key() == Qt::Key_Shift) moveFast = true;
|
||||
|
||||
glm::vec3 movement;
|
||||
if (e->key() == Qt::Key_W)
|
||||
movement.y += moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_S)
|
||||
movement.y -= moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_A)
|
||||
movement.x -= moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_D)
|
||||
movement.x += moveFast? 10.f : 1.f;
|
||||
glm::vec3 movement;
|
||||
if (e->key() == Qt::Key_W) movement.y += moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_S) movement.y -= moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_A) movement.x -= moveFast ? 10.f : 1.f;
|
||||
if (e->key() == Qt::Key_D) movement.x += moveFast ? 10.f : 1.f;
|
||||
|
||||
if (movement.length() > 0.f)
|
||||
{
|
||||
movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f))
|
||||
* glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) * movement;
|
||||
viewPosition += movement;
|
||||
}
|
||||
if (movement.length() > 0.f) {
|
||||
movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) *
|
||||
glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) *
|
||||
movement;
|
||||
viewPosition += movement;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::keyReleaseEvent(QKeyEvent* e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Shift)
|
||||
moveFast = false;
|
||||
void ViewerWidget::keyReleaseEvent(QKeyEvent* e) {
|
||||
if (e->key() == Qt::Key_Shift) moveFast = false;
|
||||
}
|
||||
|
||||
Model* ViewerWidget::currentModel() const
|
||||
{
|
||||
return activeModel;
|
||||
Model* ViewerWidget::currentModel() const {
|
||||
return activeModel;
|
||||
}
|
||||
|
||||
GameObject* ViewerWidget::currentObject() const
|
||||
{
|
||||
return dummyObject;
|
||||
GameObject* ViewerWidget::currentObject() const {
|
||||
return dummyObject;
|
||||
}
|
||||
|
||||
void ViewerWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
dragging = true;
|
||||
dstart = e->localPos();
|
||||
dastart = viewAngles;
|
||||
void ViewerWidget::mousePressEvent(QMouseEvent* e) {
|
||||
dragging = true;
|
||||
dstart = e->localPos();
|
||||
dastart = viewAngles;
|
||||
}
|
||||
|
||||
void ViewerWidget::mouseReleaseEvent(QMouseEvent*)
|
||||
{
|
||||
dragging = false;
|
||||
void ViewerWidget::mouseReleaseEvent(QMouseEvent*) {
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
void ViewerWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if(dragging) {
|
||||
auto d = e->localPos() - dstart;
|
||||
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
|
||||
}
|
||||
void ViewerWidget::mouseMoveEvent(QMouseEvent* e) {
|
||||
if (dragging) {
|
||||
auto d = e->localPos() - dstart;
|
||||
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
|
||||
void ViewerWidget::wheelEvent(QWheelEvent* e) {
|
||||
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
#ifndef _VIEWERWIDGET_HPP_
|
||||
#define _VIEWERWIDGET_HPP_
|
||||
#include <QTimer>
|
||||
#include <data/Model.hpp>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <QTimer>
|
||||
#include <loaders/LoaderIFP.hpp>
|
||||
#include <gl/DrawBuffer.hpp>
|
||||
#include <gl/GeometryBuffer.hpp>
|
||||
#include <data/Model.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <loaders/LoaderIFP.hpp>
|
||||
|
||||
// Prevent Qt from conflicting with glLoadGen
|
||||
#define GL_ARB_debug_output
|
||||
@ -17,80 +17,79 @@
|
||||
|
||||
class GameRenderer;
|
||||
class Model;
|
||||
class ViewerWidget : public QGLWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class ViewerWidget : public QGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
GameRenderer* renderer;
|
||||
GameRenderer* renderer;
|
||||
|
||||
QString currentFile;
|
||||
QString currentFile;
|
||||
|
||||
QTimer timer;
|
||||
GameWorld* gworld;
|
||||
QTimer timer;
|
||||
GameWorld* gworld;
|
||||
|
||||
Model* activeModel;
|
||||
ModelFrame* selectedFrame;
|
||||
GameObject* dummyObject;
|
||||
quint16 currentObjectID;
|
||||
Model* activeModel;
|
||||
ModelFrame* selectedFrame;
|
||||
GameObject* dummyObject;
|
||||
quint16 currentObjectID;
|
||||
|
||||
Model* _lastModel;
|
||||
Animation* canimation;
|
||||
Model* _lastModel;
|
||||
Animation* canimation;
|
||||
|
||||
float viewDistance;
|
||||
glm::vec2 viewAngles;
|
||||
glm::vec3 viewPosition;
|
||||
float viewDistance;
|
||||
glm::vec2 viewAngles;
|
||||
glm::vec3 viewPosition;
|
||||
|
||||
bool dragging;
|
||||
QPointF dstart;
|
||||
glm::vec2 dastart;
|
||||
bool moveFast;
|
||||
bool dragging;
|
||||
QPointF dstart;
|
||||
glm::vec2 dastart;
|
||||
bool moveFast;
|
||||
|
||||
DrawBuffer* _frameWidgetDraw;
|
||||
GeometryBuffer* _frameWidgetGeom;
|
||||
GLuint whiteTex;
|
||||
DrawBuffer* _frameWidgetDraw;
|
||||
GeometryBuffer* _frameWidgetGeom;
|
||||
GLuint whiteTex;
|
||||
|
||||
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
|
||||
|
||||
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
|
||||
public:
|
||||
ViewerWidget(QGLFormat g, QWidget* parent = 0,
|
||||
const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
ViewerWidget(QGLFormat g, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
|
||||
virtual void initializeGL();
|
||||
|
||||
virtual void initializeGL();
|
||||
virtual void resizeGL(int w, int h);
|
||||
|
||||
virtual void resizeGL(int w, int h);
|
||||
virtual void paintGL();
|
||||
|
||||
virtual void paintGL();
|
||||
Model* currentModel() const;
|
||||
GameObject* currentObject() const;
|
||||
|
||||
Model *currentModel() const;
|
||||
GameObject* currentObject() const;
|
||||
|
||||
GameWorld* world();
|
||||
GameWorld* world();
|
||||
|
||||
public slots:
|
||||
|
||||
void showObject(qint16 item);
|
||||
void showModel(Model* model);
|
||||
void selectFrame(ModelFrame* frame);
|
||||
void showObject(qint16 item);
|
||||
void showModel(Model* model);
|
||||
void selectFrame(ModelFrame* frame);
|
||||
|
||||
void exportModel();
|
||||
void exportModel();
|
||||
|
||||
void dataLoaded(GameWorld* world);
|
||||
void dataLoaded(GameWorld* world);
|
||||
|
||||
void setRenderer(GameRenderer* renderer);
|
||||
void setRenderer(GameRenderer* renderer);
|
||||
|
||||
signals:
|
||||
|
||||
void fileOpened(const QString& file);
|
||||
void fileOpened(const QString& file);
|
||||
|
||||
void modelChanged(Model* model);
|
||||
void modelChanged(Model* model);
|
||||
|
||||
protected:
|
||||
|
||||
void keyPressEvent(QKeyEvent*) override;
|
||||
void keyReleaseEvent(QKeyEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
void wheelEvent(QWheelEvent*) override;
|
||||
void keyPressEvent(QKeyEvent*) override;
|
||||
void keyReleaseEvent(QKeyEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
void wheelEvent(QWheelEvent*) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,230 +1,224 @@
|
||||
#include "ViewerWindow.hpp"
|
||||
#include "views/ObjectViewer.hpp"
|
||||
#include "views/ModelViewer.hpp"
|
||||
#include "views/WorldViewer.hpp"
|
||||
#include <ViewerWidget.hpp>
|
||||
#include "views/ModelViewer.hpp"
|
||||
#include "views/ObjectViewer.hpp"
|
||||
#include "views/WorldViewer.hpp"
|
||||
|
||||
#include <engine/GameState.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <render/GameRenderer.hpp>
|
||||
|
||||
#include <QMenuBar>
|
||||
#include <QFileDialog>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
#include <QPushButton>
|
||||
#include <QSignalMapper>
|
||||
#include <QDebug>
|
||||
#include <fstream>
|
||||
#include <QFileDialog>
|
||||
#include <QMenuBar>
|
||||
#include <QOffscreenSurface>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QSignalMapper>
|
||||
#include <fstream>
|
||||
|
||||
static int MaxRecentGames = 5;
|
||||
|
||||
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
|
||||
: QMainWindow(parent, flags)
|
||||
, gameData(nullptr)
|
||||
, gameWorld(nullptr)
|
||||
, renderer(nullptr)
|
||||
{
|
||||
setMinimumSize(640, 480);
|
||||
: QMainWindow(parent, flags)
|
||||
, gameData(nullptr)
|
||||
, gameWorld(nullptr)
|
||||
, renderer(nullptr) {
|
||||
setMinimumSize(640, 480);
|
||||
|
||||
QMenuBar* mb = this->menuBar();
|
||||
QMenu* file = mb->addMenu("&File");
|
||||
QMenuBar* mb = this->menuBar();
|
||||
QMenu* file = mb->addMenu("&File");
|
||||
|
||||
file->addAction("Open &Game", this, SLOT(loadGame()));
|
||||
file->addAction("Open &Game", this, SLOT(loadGame()));
|
||||
|
||||
file->addSeparator();
|
||||
for(int i = 0; i < MaxRecentGames; ++i) {
|
||||
QAction* r = file->addAction("");
|
||||
recentGames.append(r);
|
||||
connect(r, SIGNAL(triggered()), SLOT(openRecent()));
|
||||
}
|
||||
file->addSeparator();
|
||||
for (int i = 0; i < MaxRecentGames; ++i) {
|
||||
QAction* r = file->addAction("");
|
||||
recentGames.append(r);
|
||||
connect(r, SIGNAL(triggered()), SLOT(openRecent()));
|
||||
}
|
||||
|
||||
recentSep = file->addSeparator();
|
||||
auto ex = file->addAction("E&xit");
|
||||
ex->setShortcut(QKeySequence::Quit);
|
||||
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));
|
||||
recentSep = file->addSeparator();
|
||||
auto ex = file->addAction("E&xit");
|
||||
ex->setShortcut(QKeySequence::Quit);
|
||||
connect(ex, SIGNAL(triggered()), QApplication::instance(),
|
||||
SLOT(closeAllWindows()));
|
||||
|
||||
//----------------------- View Mode setup
|
||||
//----------------------- View Mode setup
|
||||
|
||||
QGLFormat glFormat;
|
||||
glFormat.setVersion( 3, 3 );
|
||||
glFormat.setProfile( QGLFormat::CoreProfile );
|
||||
QGLFormat glFormat;
|
||||
glFormat.setVersion(3, 3);
|
||||
glFormat.setProfile(QGLFormat::CoreProfile);
|
||||
|
||||
viewerWidget = new ViewerWidget(glFormat);
|
||||
viewerWidget->context()->makeCurrent();
|
||||
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*)));
|
||||
viewerWidget = new ViewerWidget(glFormat);
|
||||
viewerWidget->context()->makeCurrent();
|
||||
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget,
|
||||
SLOT(dataLoaded(GameWorld*)));
|
||||
|
||||
//------------- Object Viewer
|
||||
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::Object] = "Objects";
|
||||
//------------- Object Viewer
|
||||
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::Object] = "Objects";
|
||||
|
||||
//------------- Model Viewer
|
||||
m_views[ViewMode::Model] = new ModelViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::Model] = "Model";
|
||||
//------------- Model Viewer
|
||||
m_views[ViewMode::Model] = new ModelViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::Model] = "Model";
|
||||
|
||||
//------------- World Viewer
|
||||
m_views[ViewMode::World] = new WorldViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::World] = "World";
|
||||
//------------- World Viewer
|
||||
m_views[ViewMode::World] = new WorldViewer(viewerWidget);
|
||||
m_viewNames[ViewMode::World] = "World";
|
||||
|
||||
//------------- display mode switching
|
||||
viewSwitcher = new QStackedWidget;
|
||||
auto signalMapper = new QSignalMapper(this);
|
||||
auto switchPanel = new QVBoxLayout();
|
||||
int i = 0;
|
||||
for(auto viewer : m_views) {
|
||||
viewSwitcher->addWidget(viewer);
|
||||
connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*)));
|
||||
//------------- display mode switching
|
||||
viewSwitcher = new QStackedWidget;
|
||||
auto signalMapper = new QSignalMapper(this);
|
||||
auto switchPanel = new QVBoxLayout();
|
||||
int i = 0;
|
||||
for (auto viewer : m_views) {
|
||||
viewSwitcher->addWidget(viewer);
|
||||
connect(this, SIGNAL(loadedData(GameWorld*)), viewer,
|
||||
SLOT(showData(GameWorld*)));
|
||||
|
||||
auto viewerButton = new QPushButton(m_viewNames[i].c_str());
|
||||
signalMapper->setMapping(m_views[i], i);
|
||||
signalMapper->setMapping(viewerButton, i);
|
||||
connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
|
||||
switchPanel->addWidget(viewerButton);
|
||||
i++;
|
||||
}
|
||||
// Map world viewer loading placements to switch to the world viewer
|
||||
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map()));
|
||||
auto viewerButton = new QPushButton(m_viewNames[i].c_str());
|
||||
signalMapper->setMapping(m_views[i], i);
|
||||
signalMapper->setMapping(viewerButton, i);
|
||||
connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
|
||||
switchPanel->addWidget(viewerButton);
|
||||
i++;
|
||||
}
|
||||
// Map world viewer loading placements to switch to the world viewer
|
||||
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)),
|
||||
signalMapper, SLOT(map()));
|
||||
|
||||
switchView(ViewMode::Object);
|
||||
switchView(ViewMode::Object);
|
||||
|
||||
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
|
||||
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
|
||||
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString)));
|
||||
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this,
|
||||
SLOT(showObjectModel(uint16_t)));
|
||||
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)),
|
||||
m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
|
||||
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model],
|
||||
SLOT(loadAnimations(QString)));
|
||||
|
||||
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
|
||||
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int)));
|
||||
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
|
||||
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher,
|
||||
SLOT(setCurrentIndex(int)));
|
||||
|
||||
switchPanel->addStretch();
|
||||
auto mainlayout = new QHBoxLayout();
|
||||
mainlayout->addLayout(switchPanel);
|
||||
mainlayout->addWidget(viewSwitcher);
|
||||
auto mainwidget = new QWidget();
|
||||
mainwidget->setLayout(mainlayout);
|
||||
switchPanel->addStretch();
|
||||
auto mainlayout = new QHBoxLayout();
|
||||
mainlayout->addLayout(switchPanel);
|
||||
mainlayout->addWidget(viewSwitcher);
|
||||
auto mainwidget = new QWidget();
|
||||
mainwidget->setLayout(mainlayout);
|
||||
|
||||
QMenu* data = mb->addMenu("&Data");
|
||||
//data->addAction("Export &Model", objectViewer, SLOT(exportModel()));
|
||||
QMenu* data = mb->addMenu("&Data");
|
||||
// data->addAction("Export &Model", objectViewer, SLOT(exportModel()));
|
||||
|
||||
QMenu* anim = mb->addMenu("&Animation");
|
||||
anim->addAction("Load &Animations", this, SLOT(openAnimations()));
|
||||
QMenu* anim = mb->addMenu("&Animation");
|
||||
anim->addAction("Load &Animations", this, SLOT(openAnimations()));
|
||||
|
||||
QMenu* map = mb->addMenu("&Map");
|
||||
map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements()));
|
||||
QMenu* map = mb->addMenu("&Map");
|
||||
map->addAction("Load IPL", m_views[ViewMode::World],
|
||||
SLOT(loadPlacements()));
|
||||
|
||||
this->setCentralWidget(mainwidget);
|
||||
this->setCentralWidget(mainwidget);
|
||||
|
||||
updateRecentGames();
|
||||
updateRecentGames();
|
||||
}
|
||||
|
||||
void ViewerWindow::showEvent(QShowEvent*)
|
||||
{
|
||||
static bool first = true;
|
||||
if(first) {
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||
restoreState(settings.value("window/windowState").toByteArray());
|
||||
first = false;
|
||||
}
|
||||
void ViewerWindow::showEvent(QShowEvent*) {
|
||||
static bool first = true;
|
||||
if (first) {
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||
restoreState(settings.value("window/windowState").toByteArray());
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
settings.setValue("window/geometry", saveGeometry());
|
||||
settings.setValue("window/windowState", saveState());
|
||||
QMainWindow::closeEvent(event);
|
||||
void ViewerWindow::closeEvent(QCloseEvent* event) {
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
settings.setValue("window/geometry", saveGeometry());
|
||||
settings.setValue("window/windowState", saveState());
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
void ViewerWindow::openAnimations()
|
||||
{
|
||||
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)");
|
||||
if(dialog.exec()) {
|
||||
loadAnimations(dialog.selectedFiles()[0]);
|
||||
}
|
||||
void ViewerWindow::openAnimations() {
|
||||
QFileDialog dialog(this, "Open Animations", QDir::homePath(),
|
||||
"IFP Animations (*.ifp)");
|
||||
if (dialog.exec()) {
|
||||
loadAnimations(dialog.selectedFiles()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::loadGame()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(
|
||||
this, tr("Open Directory"),
|
||||
QDir::homePath(),
|
||||
QFileDialog::ShowDirsOnly
|
||||
| QFileDialog::DontResolveSymlinks);
|
||||
void ViewerWindow::loadGame() {
|
||||
QString dir = QFileDialog::getExistingDirectory(
|
||||
this, tr("Open Directory"), QDir::homePath(),
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if( dir.size() > 0 ) loadGame( dir );
|
||||
if (dir.size() > 0) loadGame(dir);
|
||||
}
|
||||
|
||||
void ViewerWindow::loadGame(const QString &path)
|
||||
{
|
||||
QDir gameDir( path );
|
||||
void ViewerWindow::loadGame(const QString& path) {
|
||||
QDir gameDir(path);
|
||||
|
||||
if( gameDir.exists() && path.size() > 0 ) {
|
||||
gameData = new GameData( &engineLog, &work, gameDir.absolutePath().toStdString() );
|
||||
gameWorld = new GameWorld( &engineLog, &work, gameData );
|
||||
renderer = new GameRenderer(&engineLog, gameData );
|
||||
gameWorld->state = new GameState;
|
||||
viewerWidget->setRenderer(renderer);
|
||||
if (gameDir.exists() && path.size() > 0) {
|
||||
gameData = new GameData(&engineLog, &work,
|
||||
gameDir.absolutePath().toStdString());
|
||||
gameWorld = new GameWorld(&engineLog, &work, gameData);
|
||||
renderer = new GameRenderer(&engineLog, gameData);
|
||||
gameWorld->state = new GameState;
|
||||
viewerWidget->setRenderer(renderer);
|
||||
|
||||
gameWorld->data->load();
|
||||
gameWorld->data->load();
|
||||
|
||||
loadedData(gameWorld);
|
||||
}
|
||||
loadedData(gameWorld);
|
||||
}
|
||||
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentGames").toStringList();
|
||||
recent.removeAll( path );
|
||||
recent.prepend( path );
|
||||
while(recent.size() > MaxRecentGames) recent.removeLast();
|
||||
settings.setValue("recentGames", recent);
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentGames").toStringList();
|
||||
recent.removeAll(path);
|
||||
recent.prepend(path);
|
||||
while (recent.size() > MaxRecentGames) recent.removeLast();
|
||||
settings.setValue("recentGames", recent);
|
||||
|
||||
updateRecentGames();
|
||||
updateRecentGames();
|
||||
}
|
||||
|
||||
void ViewerWindow::openRecent()
|
||||
{
|
||||
QAction* r = qobject_cast< QAction* >(sender());
|
||||
if(r) {
|
||||
loadGame( r->data().toString() );
|
||||
}
|
||||
void ViewerWindow::openRecent() {
|
||||
QAction* r = qobject_cast<QAction*>(sender());
|
||||
if (r) {
|
||||
loadGame(r->data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::switchView(int mode)
|
||||
{
|
||||
if( mode < int(m_views.size()) )
|
||||
{
|
||||
m_views[mode]->setViewerWidget( viewerWidget );
|
||||
}
|
||||
else
|
||||
{
|
||||
RW_ERROR("Unhandled view mode" << mode);
|
||||
}
|
||||
void ViewerWindow::switchView(int mode) {
|
||||
if (mode < int(m_views.size())) {
|
||||
m_views[mode]->setViewerWidget(viewerWidget);
|
||||
} else {
|
||||
RW_ERROR("Unhandled view mode" << mode);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::showObjectModel(uint16_t)
|
||||
{
|
||||
// Switch to the model viewer
|
||||
switchView(ViewMode::Model);
|
||||
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) );
|
||||
void ViewerWindow::showObjectModel(uint16_t) {
|
||||
// Switch to the model viewer
|
||||
switchView(ViewMode::Model);
|
||||
viewSwitcher->setCurrentIndex(
|
||||
viewSwitcher->indexOf(m_views[ViewMode::Model]));
|
||||
}
|
||||
|
||||
void ViewerWindow::updateRecentGames()
|
||||
{
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentGames").toStringList();
|
||||
void ViewerWindow::updateRecentGames() {
|
||||
QSettings settings("OpenRW", "rwviewer");
|
||||
QStringList recent = settings.value("recentGames").toStringList();
|
||||
|
||||
for(int i = 0; i < MaxRecentGames; ++i) {
|
||||
if(i < recent.size()) {
|
||||
QString fnm(QFileInfo(recent[i]).fileName());
|
||||
recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
|
||||
recentGames[i]->setData(recent[i]);
|
||||
recentGames[i]->setVisible(true);
|
||||
}
|
||||
else {
|
||||
recentGames[i]->setVisible(false);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MaxRecentGames; ++i) {
|
||||
if (i < recent.size()) {
|
||||
QString fnm(QFileInfo(recent[i]).fileName());
|
||||
recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
|
||||
recentGames[i]->setData(recent[i]);
|
||||
recentGames[i]->setVisible(true);
|
||||
} else {
|
||||
recentGames[i]->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
recentSep->setVisible(recent.size() > 0);
|
||||
recentSep->setVisible(recent.size() > 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef _VIEWERWINDOW_HPP_
|
||||
#define _VIEWERWINDOW_HPP_
|
||||
#include <core/Logger.hpp>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <core/Logger.hpp>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QStackedWidget>
|
||||
@ -16,74 +16,67 @@ class ViewerInterface;
|
||||
class GameRenderer;
|
||||
class QGLContext;
|
||||
|
||||
class ViewerWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
class ViewerWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
enum ViewMode {
|
||||
Object = 0,
|
||||
Model = 1,
|
||||
World = 2,
|
||||
_Count
|
||||
};
|
||||
enum ViewMode { Object = 0, Model = 1, World = 2, _Count };
|
||||
|
||||
Logger engineLog;
|
||||
WorkContext work;
|
||||
Logger engineLog;
|
||||
WorkContext work;
|
||||
|
||||
GameData* gameData;
|
||||
GameWorld* gameWorld;
|
||||
GameRenderer* renderer;
|
||||
GameState* state;
|
||||
GameData* gameData;
|
||||
GameWorld* gameWorld;
|
||||
GameRenderer* renderer;
|
||||
GameState* state;
|
||||
|
||||
/** Contains the OGL context */
|
||||
ViewerWidget* viewerWidget;
|
||||
/** Contains the OGL context */
|
||||
ViewerWidget* viewerWidget;
|
||||
|
||||
std::array<ViewerInterface*, ViewMode::_Count> m_views;
|
||||
std::array<std::string, ViewMode::_Count> m_viewNames;
|
||||
std::array<ViewerInterface*, ViewMode::_Count> m_views;
|
||||
std::array<std::string, ViewMode::_Count> m_viewNames;
|
||||
|
||||
QStackedWidget* viewSwitcher;
|
||||
QStackedWidget* viewSwitcher;
|
||||
|
||||
QGLContext* context;
|
||||
|
||||
QGLContext* context;
|
||||
public:
|
||||
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
/**
|
||||
* @brief openGame Loads a game's dat file.
|
||||
* @param datFile
|
||||
*/
|
||||
void openGame(const QString& datFile);
|
||||
|
||||
/**
|
||||
* @brief openGame Loads a game's dat file.
|
||||
* @param datFile
|
||||
*/
|
||||
void openGame(const QString& datFile);
|
||||
virtual void showEvent(QShowEvent*);
|
||||
|
||||
virtual void showEvent(QShowEvent*);
|
||||
|
||||
virtual void closeEvent(QCloseEvent*);
|
||||
virtual void closeEvent(QCloseEvent*);
|
||||
|
||||
public slots:
|
||||
|
||||
void openAnimations();
|
||||
void openAnimations();
|
||||
|
||||
void loadGame();
|
||||
void loadGame();
|
||||
|
||||
void loadGame( const QString& path );
|
||||
void loadGame(const QString& path);
|
||||
|
||||
signals:
|
||||
|
||||
void loadedData(GameWorld* world);
|
||||
void loadAnimations(const QString& file);
|
||||
void loadedData(GameWorld* world);
|
||||
void loadAnimations(const QString& file);
|
||||
|
||||
private slots:
|
||||
|
||||
void openRecent();
|
||||
void openRecent();
|
||||
|
||||
void switchView(int mode);
|
||||
void switchView(int mode);
|
||||
|
||||
void showObjectModel(uint16_t object);
|
||||
void showObjectModel(uint16_t object);
|
||||
|
||||
private:
|
||||
|
||||
QList<QAction*> recentGames;
|
||||
QAction* recentSep;
|
||||
void updateRecentGames();
|
||||
QList<QAction*> recentGames;
|
||||
QAction* recentSep;
|
||||
void updateRecentGames();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2,12 +2,11 @@
|
||||
#include <QStyleFactory>
|
||||
#include "ViewerWindow.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
ViewerWindow viewer;
|
||||
viewer.show();
|
||||
ViewerWindow viewer;
|
||||
viewer.show();
|
||||
|
||||
return app.exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user