1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

clang-format files in rwviewer

This commit is contained in:
Daniel Evans 2016-09-09 21:13:21 +01:00
parent 8a19f9b5d0
commit d1c33af268
15 changed files with 692 additions and 760 deletions

View File

@ -1,11 +1,10 @@
#include "AnimationListModel.hpp" #include "AnimationListModel.hpp"
QVariant AnimationListModel::data(const QModelIndex& index, int role) const QVariant AnimationListModel::data(const QModelIndex& index, int role) const {
{ if (role == Qt::DisplayRole) {
if(role == Qt::DisplayRole) { if (index.row() >= 0 && (unsigned)index.row() < animations.size()) {
if(index.row() >= 0 && (unsigned) index.row() < animations.size()) {
auto& f = animations.at(index.row()); auto& f = animations.at(index.row());
if(index.column() == 0) { if (index.column() == 0) {
return QString(f.first.c_str()); return QString(f.first.c_str());
} }
} }
@ -13,23 +12,21 @@ QVariant AnimationListModel::data(const QModelIndex& index, int role) const
return QVariant::Invalid; return QVariant::Invalid;
} }
QVariant AnimationListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant AnimationListModel::headerData(int section,
{ Qt::Orientation orientation,
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { int role) const {
if(section == 0) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if (section == 0) {
return "Name"; return "Name";
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
int AnimationListModel::rowCount(const QModelIndex& parent) const int AnimationListModel::rowCount(const QModelIndex& parent) const {
{
return animations.size(); return animations.size();
} }
int AnimationListModel::columnCount(const QModelIndex& parent) const int AnimationListModel::columnCount(const QModelIndex& parent) const {
{
return 1; return 1;
} }

View File

@ -6,27 +6,29 @@
typedef std::vector<std::pair<std::string, Animation*>> AnimationList; typedef std::vector<std::pair<std::string, Animation*>> AnimationList;
class AnimationListModel : public QAbstractListModel class AnimationListModel : public QAbstractListModel {
{
Q_OBJECT Q_OBJECT
AnimationList animations; AnimationList animations;
public: public:
AnimationListModel(const AnimationList& anims, QObject* parent = 0) AnimationListModel(const AnimationList& anims, QObject* parent = 0)
: QAbstractListModel(parent), animations(anims) : QAbstractListModel(parent), animations(anims) {
{} }
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;
const AnimationList& getAnimations() const { return animations; } const AnimationList& getAnimations() const {
return animations;
}
}; };
#endif #endif

View File

@ -2,8 +2,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags) AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) : QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
{
setWindowTitle("Animations"); setWindowTitle("Animations");
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget(); QWidget* intermediate = new QWidget();
@ -19,30 +18,29 @@ AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
filter = new QSortFilterProxyModel; filter = new QSortFilterProxyModel;
table->setModel(filter); table->setModel(filter);
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex))); connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString))); connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
} }
void AnimationListWidget::setAnimations(const AnimationList& archive) void AnimationListWidget::setAnimations(const AnimationList& archive) {
{
auto m = new AnimationListModel(archive); auto m = new AnimationListModel(archive);
filter->setSourceModel(m); filter->setSourceModel(m);
if(model) { if (model) {
delete model; delete model;
} }
model = m; model = m;
} }
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) {
{
auto mts = filter->mapToSource(current); auto mts = filter->mapToSource(current);
if(mts.row() >= 0 && (unsigned) mts.row() < model->getAnimations().size()) { if (mts.row() >= 0 && (unsigned)mts.row() < model->getAnimations().size()) {
auto& f = model->getAnimations().at(mts.row()); auto& f = model->getAnimations().at(mts.row());
emit selectedAnimationChanged(f.second); emit selectedAnimationChanged(f.second);
} }
} }
void AnimationListWidget::setFilter(const QString &f) void AnimationListWidget::setFilter(const QString& f) {
{
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive)); filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
} }

View File

@ -2,13 +2,12 @@
#ifndef _ANIMATIONLISTWIDGET_HPP_ #ifndef _ANIMATIONLISTWIDGET_HPP_
#define _ANIMATIONLISTWIDGET_HPP_ #define _ANIMATIONLISTWIDGET_HPP_
#include <QDockWidget> #include <QDockWidget>
#include <QListView>
#include <QLineEdit> #include <QLineEdit>
#include <QListView>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "AnimationListModel.hpp" #include "AnimationListModel.hpp"
class AnimationListWidget : public QDockWidget class AnimationListWidget : public QDockWidget {
{
Q_OBJECT Q_OBJECT
QSortFilterProxyModel* filter; QSortFilterProxyModel* filter;
@ -17,7 +16,6 @@ class AnimationListWidget : public QDockWidget
QLineEdit* searchbox; QLineEdit* searchbox;
public: 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);

View File

@ -1,14 +1,14 @@
#include "IMGArchiveModel.hpp" #include "IMGArchiveModel.hpp"
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const {
{ if (role == Qt::DisplayRole) {
if(role == Qt::DisplayRole) { if (index.row() >= 0 &&
if(index.row() >= 0 && (unsigned) index.row() < archive.getAssetCount()) { (unsigned)index.row() < archive.getAssetCount()) {
auto& f = archive.getAssetInfoByIndex(index.row()); auto& f = archive.getAssetInfoByIndex(index.row());
if(index.column() == 0) { if (index.column() == 0) {
return QString(f.name); return QString(f.name);
} }
if(index.column() == 1) { if (index.column() == 1) {
return f.size; return f.size;
} }
} }
@ -16,26 +16,23 @@ QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const
return QVariant::Invalid; return QVariant::Invalid;
} }
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if(section == 0) { if (section == 0) {
return "Name"; return "Name";
} }
if(section == 1) { if (section == 1) {
return "Size"; return "Size";
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
int IMGArchiveModel::rowCount(const QModelIndex& parent) const int IMGArchiveModel::rowCount(const QModelIndex& parent) const {
{
return archive.getAssetCount(); return archive.getAssetCount();
} }
int IMGArchiveModel::columnCount(const QModelIndex& parent) const int IMGArchiveModel::columnCount(const QModelIndex& parent) const {
{
return 2; return 2;
} }

View File

@ -4,27 +4,29 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <loaders/LoaderIMG.hpp> #include <loaders/LoaderIMG.hpp>
class IMGArchiveModel : public QAbstractListModel class IMGArchiveModel : public QAbstractListModel {
{
Q_OBJECT Q_OBJECT
LoaderIMG archive; LoaderIMG archive;
public: public:
IMGArchiveModel(const LoaderIMG& archive, QObject* parent = 0) 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 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;
const LoaderIMG& getArchive() const { return archive; } const LoaderIMG& getArchive() const {
return archive;
}
}; };
#endif #endif

View File

@ -1,60 +1,55 @@
#include "ItemListModel.hpp" #include "ItemListModel.hpp"
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
qint16 ItemListModel::getIDOf(unsigned int row) const qint16 ItemListModel::getIDOf(unsigned int row) const {
{ if (row < world()->data->objectTypes.size()) {
if( row < world()->data->objectTypes.size() )
{
return row; return row;
} }
return -1; return -1;
} }
ItemListModel::ItemListModel(GameWorld *world, QObject *parent) : ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
QAbstractTableModel(parent), _world( world ) : QAbstractTableModel(parent), _world(world) {
{
} }
int ItemListModel::rowCount(const QModelIndex &parent) const int ItemListModel::rowCount(const QModelIndex &parent) const {
{
return _world->data->objectTypes.size(); return _world->data->objectTypes.size();
} }
int ItemListModel::columnCount(const QModelIndex &parent) const int ItemListModel::columnCount(const QModelIndex &parent) const {
{
return 2; return 2;
} }
QVariant ItemListModel::data(const QModelIndex &index, int role) const QVariant ItemListModel::data(const QModelIndex &index, int role) const {
{ if (role == Qt::DisplayRole) {
if ( role == Qt::DisplayRole ) {
qint16 id = getIDOf(index.row()); qint16 id = getIDOf(index.row());
if( id == -1 ) return QVariant::Invalid; if (id == -1) return QVariant::Invalid;
if( index.column() == 0 ) { if (index.column() == 0) {
return id; return id;
} } else if (index.column() == 1) {
else if ( index.column() == 1 ) {
return QString::fromStdString("TODO"); return QString::fromStdString("TODO");
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ItemListModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if(section == 0) { if (section == 0) {
return "ID"; return "ID";
} }
if(section == 1) { if (section == 1) {
return "Model"; return "Model";
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const QModelIndex ItemListModel::index(int row, int column,
{ const QModelIndex &parent) const {
return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex(); return hasIndex(row, column, parent)
? createIndex(row, column, getIDOf(row))
: QModelIndex();
} }

View File

@ -5,28 +5,31 @@
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
class ItemListModel : public QAbstractTableModel class ItemListModel : public QAbstractTableModel {
{
Q_OBJECT Q_OBJECT
GameWorld* _world; GameWorld* _world;
public: 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

View File

@ -1,10 +1,9 @@
#include "ItemListWidget.hpp" #include "ItemListWidget.hpp"
#include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QVBoxLayout>
ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags) ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) : QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
{
setWindowTitle("Items"); setWindowTitle("Items");
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget(); QWidget* intermediate = new QWidget();
@ -22,26 +21,25 @@ ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
filter = new QSortFilterProxyModel; filter = new QSortFilterProxyModel;
table->setModel(filter); table->setModel(filter);
filter->setFilterKeyColumn(-1); // Search all columns filter->setFilterKeyColumn(-1); // Search all columns
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex))); connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString))); connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
} }
void ItemListWidget::worldLoaded(GameWorld *world) void ItemListWidget::worldLoaded(GameWorld* world) {
{ if (model) delete model;
if ( model ) delete model; model = new ItemListModel(world, this);
model = new ItemListModel( world, this ); filter->setSourceModel(model);
filter->setSourceModel( model );
} }
void ItemListWidget::selectedIndexChanged(const QModelIndex& current) void ItemListWidget::selectedIndexChanged(const QModelIndex& current) {
{
auto mts = filter->mapToSource(current); auto mts = filter->mapToSource(current);
if( mts.isValid() ) { if (mts.isValid()) {
emit selectedItemChanged( model->getIDOf(mts.row()) ); emit selectedItemChanged(model->getIDOf(mts.row()));
} }
} }
void ItemListWidget::setFilter(const QString &f) void ItemListWidget::setFilter(const QString& f) {
{
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive)); filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
} }

View File

@ -2,13 +2,12 @@
#ifndef _ITEMLISTWIDGET_HPP_ #ifndef _ITEMLISTWIDGET_HPP_
#define _ITEMLISTWIDGET_HPP_ #define _ITEMLISTWIDGET_HPP_
#include <QDockWidget> #include <QDockWidget>
#include <QTableView>
#include <QLineEdit> #include <QLineEdit>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QTableView>
#include "ItemListModel.hpp" #include "ItemListModel.hpp"
class ItemListWidget : public QDockWidget class ItemListWidget : public QDockWidget {
{
Q_OBJECT Q_OBJECT
QSortFilterProxyModel* filter; QSortFilterProxyModel* filter;

View File

@ -1,21 +1,21 @@
#include "ViewerWidget.hpp" #include "ViewerWidget.hpp"
#include <QFileDialog>
#include <QMouseEvent>
#include <algorithm>
#include <data/Model.hpp> #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/GameRenderer.hpp>
#include <render/OpenGLRenderer.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/CharacterObject.hpp>
#include <objects/InstanceObject.hpp>
#include <objects/VehicleObject.hpp> #include <objects/VehicleObject.hpp>
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent,
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f) const QGLWidget* shareWidget, Qt::WindowFlags f)
: QGLWidget(g, parent, shareWidget, f) : QGLWidget(g, parent, shareWidget, f)
, gworld(nullptr) , gworld(nullptr)
, activeModel(nullptr) , activeModel(nullptr)
@ -28,31 +28,22 @@ ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareW
, dragging(false) , dragging(false)
, moveFast(false) , moveFast(false)
, _frameWidgetDraw(nullptr) , _frameWidgetDraw(nullptr)
, _frameWidgetGeom(nullptr) , _frameWidgetGeom(nullptr) {
{
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
} }
struct WidgetVertex { struct WidgetVertex {
float x, y, z; float x, y, z;
static const AttributeList vertex_attributes() { static const AttributeList vertex_attributes() {
return { return {{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}};
{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}
};
} }
}; };
std::vector<WidgetVertex> widgetVerts = { std::vector<WidgetVertex> widgetVerts = {{-.5f, 0.f, 0.f}, {.5f, 0.f, 0.f},
{-.5f, 0.f, 0.f}, {0.f, -.5f, 0.f}, {0.f, .5f, 0.f},
{ .5f, 0.f, 0.f}, {0.f, 0.f, -.5f}, {0.f, 0.f, .5f}};
{ 0.f,-.5f, 0.f},
{ 0.f, .5f, 0.f},
{ 0.f, 0.f,-.5f},
{ 0.f, 0.f, .5f}
};
void ViewerWidget::initializeGL() void ViewerWidget::initializeGL() {
{
QGLWidget::initializeGL(); QGLWidget::initializeGL();
timer.setInterval(25); timer.setInterval(25);
connect(&timer, SIGNAL(timeout()), SLOT(updateGL())); connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
@ -67,32 +58,31 @@ void ViewerWidget::initializeGL()
glGenTextures(1, &whiteTex); glGenTextures(1, &whiteTex);
glBindTexture(GL_TEXTURE_2D, whiteTex); glBindTexture(GL_TEXTURE_2D, whiteTex);
GLuint tex = 0xFFFFFFFF; GLuint tex = 0xFFFFFFFF;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &tex); 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_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} }
void ViewerWidget::resizeGL(int w, int h) void ViewerWidget::resizeGL(int w, int h) {
{
QGLWidget::resizeGL(w, h); QGLWidget::resizeGL(w, h);
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
} }
void ViewerWidget::paintGL() void ViewerWidget::paintGL() {
{
glClearColor(0.3f, 0.3f, 0.3f, 1.f); glClearColor(0.3f, 0.3f, 0.3f, 1.f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 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) { if (dummyObject && dummyObject->animator && dummyObject->skeleton) {
dummyObject->animator->tick(1.f/60.f); dummyObject->animator->tick(1.f / 60.f);
dummyObject->skeleton->interpolate(1.f); dummyObject->skeleton->interpolate(1.f);
} }
@ -113,22 +103,26 @@ void ViewerWidget::paintGL()
vc.frustum.far = 500.f; vc.frustum.far = 500.f;
vc.frustum.near = 0.1f; vc.frustum.near = 0.1f;
vc.frustum.fov = viewFov; vc.frustum.fov = viewFov;
vc.frustum.aspectRatio = width()/(height()*1.f); vc.frustum.aspectRatio = width() / (height() * 1.f);
Model* model = activeModel; Model* model = activeModel;
if( model != _lastModel ) { if (model != _lastModel) {
_lastModel = model; _lastModel = model;
emit modelChanged(_lastModel); 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 ) if (model) {
{
glm::mat4 proj = vc.frustum.projection(); 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)); 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();
@ -138,73 +132,59 @@ void ViewerWidget::paintGL()
drawFrameWidget(model->frames[model->rootFrameIdx]); drawFrameWidget(model->frames[model->rootFrameIdx]);
r.renderPostProcess(); r.renderPostProcess();
} } else if (world()->allObjects.size() > 0) {
else if (world()->allObjects.size() > 0)
{
vc.frustum.fov = glm::radians(90.f); vc.frustum.fov = glm::radians(90.f);
vc.frustum.far = 1000.f; vc.frustum.far = 1000.f;
vc.position = viewPosition; vc.position = viewPosition;
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x,
* glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f)); 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); r.renderWorld(world(), vc, 0.f);
} }
} }
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
{
auto thisM = m * f->getTransform(); auto thisM = m * f->getTransform();
if(f->getGeometries().size() == 0) if (f->getGeometries().size() == 0) {
{
Renderer::DrawParameters dp; Renderer::DrawParameters dp;
dp.count = _frameWidgetGeom->getCount(); dp.count = _frameWidgetGeom->getCount();
dp.start = 0; dp.start = 0;
dp.ambient = 1.f; dp.ambient = 1.f;
dp.diffuse = 1.f; dp.diffuse = 1.f;
if( f == selectedFrame ) if (f == selectedFrame) {
{
dp.colour = {255, 255, 0, 255}; dp.colour = {255, 255, 0, 255};
// Sorry! // Sorry!
glLineWidth(10.f); glLineWidth(10.f);
} } else {
else
{
dp.colour = {255, 255, 255, 255}; dp.colour = {255, 255, 255, 255};
glLineWidth(1.f); glLineWidth(1.f);
} }
dp.textures = { whiteTex }; dp.textures = {whiteTex};
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp); renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
} }
for(auto c : f->getChildren()) { for (auto c : f->getChildren()) {
drawFrameWidget(c, thisM); drawFrameWidget(c, thisM);
} }
} }
GameWorld* ViewerWidget::world() GameWorld* ViewerWidget::world() {
{
return gworld; return gworld;
} }
void ViewerWidget::showObject(qint16 item) void ViewerWidget::showObject(qint16 item) {
{
currentObjectID = 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) {
{ if (def->class_type == ObjectData::class_id) {
if(def->class_type == ObjectData::class_id)
{
dummyObject = gworld->createInstance(item, {}); dummyObject = gworld->createInstance(item, {});
} } else if (def->class_type == CharacterData::class_id) {
else if(def->class_type == CharacterData::class_id)
{
dummyObject = gworld->createPedestrian(item, {}); dummyObject = gworld->createPedestrian(item, {});
} } else if (def->class_type == VehicleData::class_id) {
else if(def->class_type == VehicleData::class_id)
{
dummyObject = gworld->createVehicle(item, {}); dummyObject = gworld->createVehicle(item, {});
} }
RW_CHECK(dummyObject != nullptr, "Dummy Object is null"); RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
@ -214,26 +194,21 @@ void ViewerWidget::showObject(qint16 item)
} }
} }
void ViewerWidget::showModel(Model* model) void ViewerWidget::showModel(Model* model) {
{ if (dummyObject) gworld->destroyObject(dummyObject);
if( dummyObject ) gworld->destroyObject( dummyObject );
dummyObject = nullptr; dummyObject = nullptr;
activeModel = model; activeModel = model;
} }
void ViewerWidget::selectFrame(ModelFrame* frame) void ViewerWidget::selectFrame(ModelFrame* frame) {
{
selectedFrame = frame; selectedFrame = frame;
} }
void ViewerWidget::exportModel() void ViewerWidget::exportModel() {
{ QString toSv = QFileDialog::getSaveFileName(
QString toSv = QFileDialog::getSaveFileName(this, this, "Export Model", QDir::homePath(), "Model (*.DFF)");
"Export Model",
QDir::homePath(),
"Model (*.DFF)");
if( toSv.size() == 0 ) return; if (toSv.size() == 0) return;
#if 0 #if 0
auto it = world()->objectTypes.find(currentObjectID); auto it = world()->objectTypes.find(currentObjectID);
@ -252,77 +227,60 @@ void ViewerWidget::exportModel()
#endif #endif
} }
void ViewerWidget::dataLoaded(GameWorld *world) void ViewerWidget::dataLoaded(GameWorld* world) {
{
gworld = world; gworld = world;
} }
void ViewerWidget::setRenderer(GameRenderer *render) void ViewerWidget::setRenderer(GameRenderer* render) {
{
renderer = render; renderer = render;
} }
void ViewerWidget::keyPressEvent(QKeyEvent* e) void ViewerWidget::keyPressEvent(QKeyEvent* e) {
{ if (e->key() == Qt::Key_Shift) moveFast = true;
if (e->key() == Qt::Key_Shift)
moveFast = true;
glm::vec3 movement; glm::vec3 movement;
if (e->key() == Qt::Key_W) if (e->key() == Qt::Key_W) movement.y += moveFast ? 10.f : 1.f;
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_S) if (e->key() == Qt::Key_A) movement.x -= moveFast ? 10.f : 1.f;
movement.y -= moveFast ? 10.f : 1.f; if (e->key() == Qt::Key_D) movement.x += 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) if (movement.length() > 0.f) {
{ movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.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))) *
* glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) * movement; movement;
viewPosition += movement; viewPosition += movement;
} }
} }
void ViewerWidget::keyReleaseEvent(QKeyEvent* e) void ViewerWidget::keyReleaseEvent(QKeyEvent* e) {
{ if (e->key() == Qt::Key_Shift) moveFast = false;
if (e->key() == Qt::Key_Shift)
moveFast = false;
} }
Model* ViewerWidget::currentModel() const Model* ViewerWidget::currentModel() const {
{
return activeModel; return activeModel;
} }
GameObject* ViewerWidget::currentObject() const GameObject* ViewerWidget::currentObject() const {
{
return dummyObject; return dummyObject;
} }
void ViewerWidget::mousePressEvent(QMouseEvent* e) void ViewerWidget::mousePressEvent(QMouseEvent* e) {
{
dragging = true; dragging = true;
dstart = e->localPos(); dstart = e->localPos();
dastart = viewAngles; dastart = viewAngles;
} }
void ViewerWidget::mouseReleaseEvent(QMouseEvent*) void ViewerWidget::mouseReleaseEvent(QMouseEvent*) {
{
dragging = false; dragging = false;
} }
void ViewerWidget::mouseMoveEvent(QMouseEvent* e) void ViewerWidget::mouseMoveEvent(QMouseEvent* e) {
{ if (dragging) {
if(dragging) {
auto d = e->localPos() - dstart; auto d = e->localPos() - dstart;
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f; viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
} }
} }
void ViewerWidget::wheelEvent(QWheelEvent* e) void ViewerWidget::wheelEvent(QWheelEvent* e) {
{
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f); viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
} }

View File

@ -1,14 +1,14 @@
#pragma once #pragma once
#ifndef _VIEWERWIDGET_HPP_ #ifndef _VIEWERWIDGET_HPP_
#define _VIEWERWIDGET_HPP_ #define _VIEWERWIDGET_HPP_
#include <QTimer>
#include <data/Model.hpp>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <QTimer>
#include <loaders/LoaderIFP.hpp>
#include <gl/DrawBuffer.hpp> #include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp> #include <gl/GeometryBuffer.hpp>
#include <data/Model.hpp>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <loaders/LoaderIFP.hpp>
// Prevent Qt from conflicting with glLoadGen // Prevent Qt from conflicting with glLoadGen
#define GL_ARB_debug_output #define GL_ARB_debug_output
@ -17,8 +17,7 @@
class GameRenderer; class GameRenderer;
class Model; class Model;
class ViewerWidget : public QGLWidget class ViewerWidget : public QGLWidget {
{
Q_OBJECT Q_OBJECT
GameRenderer* renderer; GameRenderer* renderer;
@ -50,9 +49,10 @@ class ViewerWidget : public QGLWidget
GLuint whiteTex; 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); public:
ViewerWidget(QGLFormat g, QWidget* parent = 0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual void initializeGL(); virtual void initializeGL();
@ -60,7 +60,7 @@ public:
virtual void paintGL(); virtual void paintGL();
Model *currentModel() const; Model* currentModel() const;
GameObject* currentObject() const; GameObject* currentObject() const;
GameWorld* world(); GameWorld* world();
@ -84,7 +84,6 @@ signals:
void modelChanged(Model* model); void modelChanged(Model* model);
protected: protected:
void keyPressEvent(QKeyEvent*) override; void keyPressEvent(QKeyEvent*) override;
void keyReleaseEvent(QKeyEvent*) override; void keyReleaseEvent(QKeyEvent*) override;
void mousePressEvent(QMouseEvent*) override; void mousePressEvent(QMouseEvent*) override;

View File

@ -1,22 +1,22 @@
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
#include "views/ObjectViewer.hpp"
#include "views/ModelViewer.hpp"
#include "views/WorldViewer.hpp"
#include <ViewerWidget.hpp> #include <ViewerWidget.hpp>
#include "views/ModelViewer.hpp"
#include "views/ObjectViewer.hpp"
#include "views/WorldViewer.hpp"
#include <engine/GameState.hpp> #include <engine/GameState.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp> #include <render/GameRenderer.hpp>
#include <QMenuBar>
#include <QFileDialog>
#include <QApplication> #include <QApplication>
#include <QSettings>
#include <QPushButton>
#include <QSignalMapper>
#include <QDebug> #include <QDebug>
#include <fstream> #include <QFileDialog>
#include <QMenuBar>
#include <QOffscreenSurface> #include <QOffscreenSurface>
#include <QPushButton>
#include <QSettings>
#include <QSignalMapper>
#include <fstream>
static int MaxRecentGames = 5; static int MaxRecentGames = 5;
@ -24,8 +24,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags) : QMainWindow(parent, flags)
, gameData(nullptr) , gameData(nullptr)
, gameWorld(nullptr) , gameWorld(nullptr)
, renderer(nullptr) , renderer(nullptr) {
{
setMinimumSize(640, 480); setMinimumSize(640, 480);
QMenuBar* mb = this->menuBar(); QMenuBar* mb = this->menuBar();
@ -34,7 +33,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
file->addAction("Open &Game", this, SLOT(loadGame())); file->addAction("Open &Game", this, SLOT(loadGame()));
file->addSeparator(); file->addSeparator();
for(int i = 0; i < MaxRecentGames; ++i) { for (int i = 0; i < MaxRecentGames; ++i) {
QAction* r = file->addAction(""); QAction* r = file->addAction("");
recentGames.append(r); recentGames.append(r);
connect(r, SIGNAL(triggered()), SLOT(openRecent())); connect(r, SIGNAL(triggered()), SLOT(openRecent()));
@ -43,17 +42,19 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
recentSep = file->addSeparator(); recentSep = file->addSeparator();
auto ex = file->addAction("E&xit"); auto ex = file->addAction("E&xit");
ex->setShortcut(QKeySequence::Quit); ex->setShortcut(QKeySequence::Quit);
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows())); connect(ex, SIGNAL(triggered()), QApplication::instance(),
SLOT(closeAllWindows()));
//----------------------- View Mode setup //----------------------- View Mode setup
QGLFormat glFormat; QGLFormat glFormat;
glFormat.setVersion( 3, 3 ); glFormat.setVersion(3, 3);
glFormat.setProfile( QGLFormat::CoreProfile ); glFormat.setProfile(QGLFormat::CoreProfile);
viewerWidget = new ViewerWidget(glFormat); viewerWidget = new ViewerWidget(glFormat);
viewerWidget->context()->makeCurrent(); viewerWidget->context()->makeCurrent();
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget,
SLOT(dataLoaded(GameWorld*)));
//------------- Object Viewer //------------- Object Viewer
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget); m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
@ -72,9 +73,10 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
auto signalMapper = new QSignalMapper(this); auto signalMapper = new QSignalMapper(this);
auto switchPanel = new QVBoxLayout(); auto switchPanel = new QVBoxLayout();
int i = 0; int i = 0;
for(auto viewer : m_views) { for (auto viewer : m_views) {
viewSwitcher->addWidget(viewer); viewSwitcher->addWidget(viewer);
connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewer,
SLOT(showData(GameWorld*)));
auto viewerButton = new QPushButton(m_viewNames[i].c_str()); auto viewerButton = new QPushButton(m_viewNames[i].c_str());
signalMapper->setMapping(m_views[i], i); signalMapper->setMapping(m_views[i], i);
@ -84,16 +86,21 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
i++; i++;
} }
// Map world viewer loading placements to switch to the world viewer // Map world viewer loading placements to switch to the world viewer
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map())); 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)), this,
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t))); SLOT(showObjectModel(uint16_t)));
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString))); 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)), this, SLOT(switchView(int)));
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int))); connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher,
SLOT(setCurrentIndex(int)));
switchPanel->addStretch(); switchPanel->addStretch();
auto mainlayout = new QHBoxLayout(); auto mainlayout = new QHBoxLayout();
@ -103,23 +110,23 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
mainwidget->setLayout(mainlayout); mainwidget->setLayout(mainlayout);
QMenu* data = mb->addMenu("&Data"); QMenu* data = mb->addMenu("&Data");
//data->addAction("Export &Model", objectViewer, SLOT(exportModel())); // data->addAction("Export &Model", objectViewer, SLOT(exportModel()));
QMenu* anim = mb->addMenu("&Animation"); QMenu* anim = mb->addMenu("&Animation");
anim->addAction("Load &Animations", this, SLOT(openAnimations())); anim->addAction("Load &Animations", this, SLOT(openAnimations()));
QMenu* map = mb->addMenu("&Map"); QMenu* map = mb->addMenu("&Map");
map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements())); map->addAction("Load IPL", m_views[ViewMode::World],
SLOT(loadPlacements()));
this->setCentralWidget(mainwidget); this->setCentralWidget(mainwidget);
updateRecentGames(); updateRecentGames();
} }
void ViewerWindow::showEvent(QShowEvent*) void ViewerWindow::showEvent(QShowEvent*) {
{
static bool first = true; static bool first = true;
if(first) { if (first) {
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
restoreGeometry(settings.value("window/geometry").toByteArray()); restoreGeometry(settings.value("window/geometry").toByteArray());
restoreState(settings.value("window/windowState").toByteArray()); restoreState(settings.value("window/windowState").toByteArray());
@ -127,41 +134,37 @@ void ViewerWindow::showEvent(QShowEvent*)
} }
} }
void ViewerWindow::closeEvent(QCloseEvent* event) void ViewerWindow::closeEvent(QCloseEvent* event) {
{
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
settings.setValue("window/geometry", saveGeometry()); settings.setValue("window/geometry", saveGeometry());
settings.setValue("window/windowState", saveState()); settings.setValue("window/windowState", saveState());
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
void ViewerWindow::openAnimations() void ViewerWindow::openAnimations() {
{ QFileDialog dialog(this, "Open Animations", QDir::homePath(),
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)"); "IFP Animations (*.ifp)");
if(dialog.exec()) { if (dialog.exec()) {
loadAnimations(dialog.selectedFiles()[0]); loadAnimations(dialog.selectedFiles()[0]);
} }
} }
void ViewerWindow::loadGame() void ViewerWindow::loadGame() {
{
QString dir = QFileDialog::getExistingDirectory( QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), this, tr("Open Directory"), QDir::homePath(),
QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if( dir.size() > 0 ) loadGame( dir ); if (dir.size() > 0) loadGame(dir);
} }
void ViewerWindow::loadGame(const QString &path) void ViewerWindow::loadGame(const QString& path) {
{ QDir gameDir(path);
QDir gameDir( path );
if( gameDir.exists() && path.size() > 0 ) { if (gameDir.exists() && path.size() > 0) {
gameData = new GameData( &engineLog, &work, gameDir.absolutePath().toStdString() ); gameData = new GameData(&engineLog, &work,
gameWorld = new GameWorld( &engineLog, &work, gameData ); gameDir.absolutePath().toStdString());
renderer = new GameRenderer(&engineLog, gameData ); gameWorld = new GameWorld(&engineLog, &work, gameData);
renderer = new GameRenderer(&engineLog, gameData);
gameWorld->state = new GameState; gameWorld->state = new GameState;
viewerWidget->setRenderer(renderer); viewerWidget->setRenderer(renderer);
@ -172,59 +175,50 @@ void ViewerWindow::loadGame(const QString &path)
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
QStringList recent = settings.value("recentGames").toStringList(); QStringList recent = settings.value("recentGames").toStringList();
recent.removeAll( path ); recent.removeAll(path);
recent.prepend( path ); recent.prepend(path);
while(recent.size() > MaxRecentGames) recent.removeLast(); while (recent.size() > MaxRecentGames) recent.removeLast();
settings.setValue("recentGames", recent); settings.setValue("recentGames", recent);
updateRecentGames(); updateRecentGames();
} }
void ViewerWindow::openRecent() void ViewerWindow::openRecent() {
{ QAction* r = qobject_cast<QAction*>(sender());
QAction* r = qobject_cast< QAction* >(sender()); if (r) {
if(r) { loadGame(r->data().toString());
loadGame( r->data().toString() );
} }
} }
void ViewerWindow::switchView(int mode) void ViewerWindow::switchView(int mode) {
{ if (mode < int(m_views.size())) {
if( mode < int(m_views.size()) ) m_views[mode]->setViewerWidget(viewerWidget);
{ } else {
m_views[mode]->setViewerWidget( viewerWidget );
}
else
{
RW_ERROR("Unhandled view mode" << mode); RW_ERROR("Unhandled view mode" << mode);
} }
} }
void ViewerWindow::showObjectModel(uint16_t) void ViewerWindow::showObjectModel(uint16_t) {
{
// Switch to the model viewer // Switch to the model viewer
switchView(ViewMode::Model); switchView(ViewMode::Model);
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) ); viewSwitcher->setCurrentIndex(
viewSwitcher->indexOf(m_views[ViewMode::Model]));
} }
void ViewerWindow::updateRecentGames() void ViewerWindow::updateRecentGames() {
{
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
QStringList recent = settings.value("recentGames").toStringList(); QStringList recent = settings.value("recentGames").toStringList();
for(int i = 0; i < MaxRecentGames; ++i) { for (int i = 0; i < MaxRecentGames; ++i) {
if(i < recent.size()) { if (i < recent.size()) {
QString fnm(QFileInfo(recent[i]).fileName()); QString fnm(QFileInfo(recent[i]).fileName());
recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm)); recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
recentGames[i]->setData(recent[i]); recentGames[i]->setData(recent[i]);
recentGames[i]->setVisible(true); recentGames[i]->setVisible(true);
} } else {
else {
recentGames[i]->setVisible(false); recentGames[i]->setVisible(false);
} }
} }
recentSep->setVisible(recent.size() > 0); recentSep->setVisible(recent.size() > 0);
} }

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#ifndef _VIEWERWINDOW_HPP_ #ifndef _VIEWERWINDOW_HPP_
#define _VIEWERWINDOW_HPP_ #define _VIEWERWINDOW_HPP_
#include <core/Logger.hpp>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <core/Logger.hpp>
#include <QMainWindow> #include <QMainWindow>
#include <QStackedWidget> #include <QStackedWidget>
@ -16,16 +16,10 @@ class ViewerInterface;
class GameRenderer; class GameRenderer;
class QGLContext; class QGLContext;
class ViewerWindow : public QMainWindow class ViewerWindow : public QMainWindow {
{
Q_OBJECT Q_OBJECT
enum ViewMode { enum ViewMode { Object = 0, Model = 1, World = 2, _Count };
Object = 0,
Model = 1,
World = 2,
_Count
};
Logger engineLog; Logger engineLog;
WorkContext work; WorkContext work;
@ -44,8 +38,8 @@ class ViewerWindow : public QMainWindow
QStackedWidget* viewSwitcher; QStackedWidget* viewSwitcher;
QGLContext* context; QGLContext* context;
public:
public:
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
/** /**
@ -64,7 +58,7 @@ public slots:
void loadGame(); void loadGame();
void loadGame( const QString& path ); void loadGame(const QString& path);
signals: signals:
@ -80,7 +74,6 @@ private slots:
void showObjectModel(uint16_t object); void showObjectModel(uint16_t object);
private: private:
QList<QAction*> recentGames; QList<QAction*> recentGames;
QAction* recentSep; QAction* recentSep;
void updateRecentGames(); void updateRecentGames();

View File

@ -2,8 +2,7 @@
#include <QStyleFactory> #include <QStyleFactory>
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
QApplication app(argc, argv); QApplication app(argc, argv);
ViewerWindow viewer; ViewerWindow viewer;