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

Clean up viewer widgets to make additional viewers easier to add.

This commit is contained in:
Daniel Evans 2016-05-15 20:25:20 +01:00
parent 238d788c0d
commit 5b76eb72f3
7 changed files with 114 additions and 99 deletions

View File

@ -10,9 +10,10 @@ add_executable(rwviewer
models/ObjectListModel.cpp models/ObjectListModel.cpp
models/DFFFramesTreeModel.cpp models/DFFFramesTreeModel.cpp
views/ViewerInterface.hpp
views/ObjectViewer.cpp views/ObjectViewer.cpp
views/ModelViewer.cpp views/ModelViewer.cpp
views/WorldViewer.cpp
ViewerWidget.cpp ViewerWidget.cpp
ItemListModel.cpp ItemListModel.cpp

View File

@ -1,22 +1,29 @@
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
#include "views/ObjectViewer.hpp" #include "views/ObjectViewer.hpp"
#include "views/ModelViewer.hpp" #include "views/ModelViewer.hpp"
#include "views/WorldViewer.hpp"
#include <ViewerWidget.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp> #include <render/GameRenderer.hpp>
#include <QMenuBar> #include <QMenuBar>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication> #include <QApplication>
#include <QSettings> #include <QSettings>
#include <QPushButton>
#include <QSignalMapper>
#include <QDebug> #include <QDebug>
#include <fstream> #include <fstream>
#include <QOffscreenSurface> #include <QOffscreenSurface>
#include <ViewerWidget.hpp>
static int MaxRecentGames = 5; static int MaxRecentGames = 5;
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags) ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags), gameData(nullptr), gameWorld(nullptr), renderer(nullptr) : QMainWindow(parent, flags)
, gameData(nullptr)
, gameWorld(nullptr)
, renderer(nullptr)
{ {
setMinimumSize(640, 480); setMinimumSize(640, 480);
@ -37,37 +44,55 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
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
viewerWidget = new ViewerWidget; viewerWidget = new ViewerWidget;
viewerWidget->context()->makeCurrent(); viewerWidget->context()->makeCurrent();
objectViewer = new ObjectViewer(viewerWidget);
connect(this, SIGNAL(loadedData(GameWorld*)), objectViewer, SLOT(showData(GameWorld*)));
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*)));
modelViewer = new ModelViewer(viewerWidget); //------------- Object Viewer
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
m_viewNames[ViewMode::Object] = "Objects";
connect(this, SIGNAL(loadedData(GameWorld*)), modelViewer, SLOT(showData(GameWorld*))); //------------- Model Viewer
m_views[ViewMode::Model] = new ModelViewer(viewerWidget);
m_viewNames[ViewMode::Model] = "Model";
#if 0
//------------- World Viewer
m_views[ViewMode::World] = new WorldViewer(viewerWidget);
m_viewNames[ViewMode::World] = "World";
#endif
//------------- display mode switching
viewSwitcher = new QStackedWidget; viewSwitcher = new QStackedWidget;
viewSwitcher->addWidget(objectViewer); auto signalMapper = new QSignalMapper(this);
viewSwitcher->addWidget(modelViewer); auto switchPanel = new QVBoxLayout();
int i = 0;
for(auto viewer : m_views) {
viewSwitcher->addWidget(viewer);
connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*)));
//connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*))); auto viewerButton = new QPushButton(m_viewNames[i].c_str());
connect(objectViewer, SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t))); signalMapper->setMapping(viewerButton, i++);
connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
switchPanel->addWidget(viewerButton);
}
objectViewer->setViewerWidget( viewerWidget ); switchView(ViewMode::Object);
QMenu* view = mb->addMenu("&View"); connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
QAction* objectAction = view->addAction("&Object"); connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
QAction* modelAction = view->addAction("&Model"); connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString)));
objectAction->setData(0); connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
modelAction->setData(1); connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int)));
connect(objectAction, SIGNAL(triggered()), this, SLOT(switchWidget())); switchPanel->addStretch();
connect(modelAction, SIGNAL(triggered()), this, SLOT(switchWidget())); auto mainlayout = new QHBoxLayout();
mainlayout->addLayout(switchPanel);
mainlayout->addWidget(viewSwitcher);
auto mainwidget = new QWidget();
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()));
@ -75,7 +100,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
QMenu* anim = mb->addMenu("&Animation"); QMenu* anim = mb->addMenu("&Animation");
anim->addAction("Load &Animations", this, SLOT(openAnimations())); anim->addAction("Load &Animations", this, SLOT(openAnimations()));
this->setCentralWidget(viewSwitcher); this->setCentralWidget(mainwidget);
updateRecentGames(); updateRecentGames();
} }
@ -103,7 +128,7 @@ void ViewerWindow::openAnimations()
{ {
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)"); QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)");
if(dialog.exec()) { if(dialog.exec()) {
modelViewer->loadAnimations(dialog.selectedFiles()[0]); loadAnimations(dialog.selectedFiles()[0]);
} }
} }
@ -156,31 +181,23 @@ void ViewerWindow::openRecent()
} }
} }
void ViewerWindow::switchWidget() void ViewerWindow::switchView(int mode)
{ {
QAction* r = qobject_cast< QAction* >(sender()); if( mode < int(m_views.size()) )
if(r) { {
int index = r->data().toInt(); m_views[mode]->setViewerWidget( viewerWidget );
}
if( index == 0 ) else
{ {
objectViewer->setViewerWidget( viewerWidget ); RW_ERROR("Unhandled view mode" << mode);
}
else if( index == 1 )
{
modelViewer->setViewerWidget( viewerWidget );
}
viewSwitcher->setCurrentIndex( index );
} }
} }
void ViewerWindow::showObjectModel(uint16_t object) void ViewerWindow::showObjectModel(uint16_t)
{ {
// Switch to the model viewer // Switch to the model viewer
modelViewer->setViewerWidget( viewerWidget ); switchView(ViewMode::Model);
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(modelViewer) ); viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) );
modelViewer->showObject(object);
} }
void ViewerWindow::updateRecentGames() void ViewerWindow::updateRecentGames()

View File

@ -1,16 +1,18 @@
#pragma once #pragma once
#ifndef _VIEWERWINDOW_HPP_ #ifndef _VIEWERWINDOW_HPP_
#define _VIEWERWINDOW_HPP_ #define _VIEWERWINDOW_HPP_
#include <QMainWindow>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <core/Logger.hpp> #include <core/Logger.hpp>
#include <QMainWindow>
#include <QStackedWidget> #include <QStackedWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
class ObjectViewer; #include <array>
class ModelViewer;
class ViewerWidget; class ViewerWidget;
class ViewerInterface;
class GameRenderer; class GameRenderer;
class QGLContext; class QGLContext;
@ -18,6 +20,15 @@ class ViewerWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
enum ViewMode {
Object = 0,
Model = 1,
#if 0
World = 2,
#endif
_Count
};
Logger engineLog; Logger engineLog;
WorkContext work; WorkContext work;
@ -28,8 +39,8 @@ class ViewerWindow : public QMainWindow
/** Contains the OGL context */ /** Contains the OGL context */
ViewerWidget* viewerWidget; ViewerWidget* viewerWidget;
ObjectViewer* objectViewer; std::array<ViewerInterface*, ViewMode::_Count> m_views;
ModelViewer* modelViewer; std::array<std::string, ViewMode::_Count> m_viewNames;
QStackedWidget* viewSwitcher; QStackedWidget* viewSwitcher;
@ -59,12 +70,13 @@ public slots:
signals: signals:
void loadedData(GameWorld* world); void loadedData(GameWorld* world);
void loadAnimations(const QString& file);
private slots: private slots:
void openRecent(); void openRecent();
void switchWidget(); void switchView(int mode);
void showObjectModel(uint16_t object); void showObjectModel(uint16_t object);

View File

@ -7,7 +7,7 @@
#include "ViewerWidget.hpp" #include "ViewerWidget.hpp"
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f) ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
: QWidget(parent, f), _world(nullptr), viewing(nullptr), skeleton(nullptr) : ViewerInterface(parent, f), viewing(nullptr), skeleton(nullptr)
{ {
mainSplit = new QSplitter; mainSplit = new QSplitter;
mainLayout = new QVBoxLayout; mainLayout = new QVBoxLayout;
@ -40,11 +40,6 @@ void ModelViewer::setViewerWidget(ViewerWidget* widget)
showModel(viewing); showModel(viewing);
} }
void ModelViewer::showData(GameWorld* world)
{
_world = world;
}
void ModelViewer::showModel(Model* model) void ModelViewer::showModel(Model* model)
{ {
viewing = model; viewing = model;

View File

@ -1,14 +1,17 @@
#pragma once #pragma once
#ifndef _MODELVIEWER_HPP_ #ifndef _MODELVIEWER_HPP_
#define _MODELVIEWER_HPP_ #define _MODELVIEWER_HPP_
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include "AnimationListWidget.hpp"
#include "ViewerInterface.hpp"
#include <QTreeView> #include <QTreeView>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QSplitter> #include <QSplitter>
#include <QLayout> #include <QLayout>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include "AnimationListWidget.hpp"
class ViewerWidget; class ViewerWidget;
class Model; class Model;
@ -16,11 +19,10 @@ class Skeleton;
class ModelFramesWidget; class ModelFramesWidget;
class Animation; class Animation;
class ModelViewer : public QWidget class ModelViewer : public ViewerInterface
{ {
Q_OBJECT Q_OBJECT
GameWorld* _world;
Model* viewing; Model* viewing;
Skeleton* skeleton; Skeleton* skeleton;
@ -36,12 +38,7 @@ public:
ModelViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0); ModelViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
GameWorld* world() void setViewerWidget( ViewerWidget* widget ) override;
{
return _world;
}
void setViewerWidget( ViewerWidget* widget );
public slots: public slots:
@ -55,8 +52,6 @@ public slots:
*/ */
void showObject(uint16_t object); void showObject(uint16_t object);
void showData(GameWorld* world);
void loadAnimations(const QString& file); void loadAnimations(const QString& file);
void playAnimation(Animation* anim); void playAnimation(Animation* anim);
}; };

View File

@ -5,7 +5,7 @@
#include <QMenu> #include <QMenu>
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f) ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
: QWidget(parent, f) : ViewerInterface(parent, f)
{ {
mainLayout = new QHBoxLayout; mainLayout = new QHBoxLayout;
@ -44,12 +44,29 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
void ObjectViewer::setViewerWidget(ViewerWidget* widget) void ObjectViewer::setViewerWidget(ViewerWidget* widget)
{ {
static size_t c = 0;
//widgetLayout->removeWidget(previewWidget); //widgetLayout->removeWidget(previewWidget);
previewWidget = widget; previewWidget = widget;
infoLayout->addWidget(previewWidget, 0, 0, 1, 2); infoLayout->addWidget(previewWidget, 0, 0, 1, 2);
} }
void ObjectViewer::worldChanged()
{
// Loade all of the IDEs.
for(std::map<std::string, std::string>::iterator it = world()->data->ideLocations.begin();
it != world()->data->ideLocations.end();
++it) {
world()->data->loadObjects(it->second);
}
if( objectList->model() )
{
delete objectList->model();
}
objectList->setModel(new ObjectListModel(world()->data, objectList));
connect(objectList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showItem(QModelIndex)));
}
static std::map<ObjectInformation::ObjectClass, QString> gDataType = static std::map<ObjectInformation::ObjectClass, QString> gDataType =
{ {
{ ObjectInformation::_class("OBJS"), "Object" }, { ObjectInformation::_class("OBJS"), "Object" },
@ -87,26 +104,6 @@ void ObjectViewer::showItem(qint16 item)
} }
} }
void ObjectViewer::showData(GameWorld *world)
{
_world = world;
// Loade all of the IDEs.
for(std::map<std::string, std::string>::iterator it = world->data->ideLocations.begin();
it != world->data->ideLocations.end();
++it) {
world->data->loadObjects(it->second);
}
if( objectList->model() )
{
delete objectList->model();
}
objectList->setModel(new ObjectListModel(world->data, objectList));
connect(objectList->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showItem(QModelIndex)));
}
void ObjectViewer::showItem(QModelIndex model) void ObjectViewer::showItem(QModelIndex model)
{ {
showItem(model.internalId()); showItem(model.internalId());

View File

@ -3,6 +3,9 @@
#define _OBJECTVIEWER_HPP_ #define _OBJECTVIEWER_HPP_
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include "ViewerInterface.hpp"
#include <QTableView> #include <QTableView>
#include <QLabel> #include <QLabel>
#include <QGridLayout> #include <QGridLayout>
@ -11,12 +14,11 @@
class ViewerWidget; class ViewerWidget;
class Model; class Model;
class ObjectViewer : public QWidget class ObjectViewer : public ViewerInterface
{ {
Q_OBJECT Q_OBJECT
QTableView* objectList; QTableView* objectList;
GameWorld* _world;
QHBoxLayout* mainLayout; QHBoxLayout* mainLayout;
QGridLayout* infoLayout; QGridLayout* infoLayout;
@ -31,13 +33,11 @@ public:
ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0); ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
GameWorld* world()
{
return _world;
}
void setViewerWidget( ViewerWidget* widget ); void setViewerWidget( ViewerWidget* widget );
protected:
void worldChanged() override;
signals: signals:
void modelChanged(Model* model); void modelChanged(Model* model);
@ -48,8 +48,6 @@ public slots:
void showItem(qint16 item); void showItem(qint16 item);
void showData(GameWorld* world);
private slots: private slots:
void showItem(QModelIndex model); void showItem(QModelIndex model);