mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-03 00:59:47 +02:00
Clean up viewer widgets to make additional viewers easier to add.
This commit is contained in:
parent
238d788c0d
commit
5b76eb72f3
@ -10,9 +10,10 @@ add_executable(rwviewer
|
||||
models/ObjectListModel.cpp
|
||||
models/DFFFramesTreeModel.cpp
|
||||
|
||||
|
||||
views/ViewerInterface.hpp
|
||||
views/ObjectViewer.cpp
|
||||
views/ModelViewer.cpp
|
||||
views/WorldViewer.cpp
|
||||
|
||||
ViewerWidget.cpp
|
||||
ItemListModel.cpp
|
||||
|
@ -1,22 +1,29 @@
|
||||
#include "ViewerWindow.hpp"
|
||||
#include "views/ObjectViewer.hpp"
|
||||
#include "views/ModelViewer.hpp"
|
||||
#include "views/WorldViewer.hpp"
|
||||
#include <ViewerWidget.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 <QOffscreenSurface>
|
||||
#include <ViewerWidget.hpp>
|
||||
|
||||
static int MaxRecentGames = 5;
|
||||
|
||||
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);
|
||||
|
||||
@ -37,37 +44,55 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
|
||||
ex->setShortcut(QKeySequence::Quit);
|
||||
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));
|
||||
|
||||
//----------------------- View Mode setup
|
||||
viewerWidget = new ViewerWidget;
|
||||
|
||||
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*)));
|
||||
|
||||
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->addWidget(objectViewer);
|
||||
viewSwitcher->addWidget(modelViewer);
|
||||
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*)));
|
||||
|
||||
//connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*)));
|
||||
connect(objectViewer, SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
|
||||
auto viewerButton = new QPushButton(m_viewNames[i].c_str());
|
||||
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");
|
||||
QAction* objectAction = view->addAction("&Object");
|
||||
QAction* modelAction = view->addAction("&Model");
|
||||
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)));
|
||||
|
||||
objectAction->setData(0);
|
||||
modelAction->setData(1);
|
||||
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
|
||||
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int)));
|
||||
|
||||
connect(objectAction, SIGNAL(triggered()), this, SLOT(switchWidget()));
|
||||
connect(modelAction, SIGNAL(triggered()), this, SLOT(switchWidget()));
|
||||
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()));
|
||||
@ -75,7 +100,7 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
|
||||
QMenu* anim = mb->addMenu("&Animation");
|
||||
anim->addAction("Load &Animations", this, SLOT(openAnimations()));
|
||||
|
||||
this->setCentralWidget(viewSwitcher);
|
||||
this->setCentralWidget(mainwidget);
|
||||
|
||||
updateRecentGames();
|
||||
}
|
||||
@ -103,7 +128,7 @@ void ViewerWindow::openAnimations()
|
||||
{
|
||||
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)");
|
||||
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(r) {
|
||||
int index = r->data().toInt();
|
||||
|
||||
if( index == 0 )
|
||||
{
|
||||
objectViewer->setViewerWidget( viewerWidget );
|
||||
}
|
||||
else if( index == 1 )
|
||||
{
|
||||
modelViewer->setViewerWidget( viewerWidget );
|
||||
}
|
||||
|
||||
viewSwitcher->setCurrentIndex( index );
|
||||
if( mode < int(m_views.size()) )
|
||||
{
|
||||
m_views[mode]->setViewerWidget( viewerWidget );
|
||||
}
|
||||
else
|
||||
{
|
||||
RW_ERROR("Unhandled view mode" << mode);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWindow::showObjectModel(uint16_t object)
|
||||
void ViewerWindow::showObjectModel(uint16_t)
|
||||
{
|
||||
// Switch to the model viewer
|
||||
modelViewer->setViewerWidget( viewerWidget );
|
||||
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(modelViewer) );
|
||||
modelViewer->showObject(object);
|
||||
switchView(ViewMode::Model);
|
||||
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) );
|
||||
}
|
||||
|
||||
void ViewerWindow::updateRecentGames()
|
||||
|
@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
#ifndef _VIEWERWINDOW_HPP_
|
||||
#define _VIEWERWINDOW_HPP_
|
||||
#include <QMainWindow>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <core/Logger.hpp>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class ObjectViewer;
|
||||
class ModelViewer;
|
||||
#include <array>
|
||||
|
||||
class ViewerWidget;
|
||||
class ViewerInterface;
|
||||
class GameRenderer;
|
||||
class QGLContext;
|
||||
|
||||
@ -18,6 +20,15 @@ class ViewerWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum ViewMode {
|
||||
Object = 0,
|
||||
Model = 1,
|
||||
#if 0
|
||||
World = 2,
|
||||
#endif
|
||||
_Count
|
||||
};
|
||||
|
||||
Logger engineLog;
|
||||
WorkContext work;
|
||||
|
||||
@ -28,8 +39,8 @@ class ViewerWindow : public QMainWindow
|
||||
/** Contains the OGL context */
|
||||
ViewerWidget* viewerWidget;
|
||||
|
||||
ObjectViewer* objectViewer;
|
||||
ModelViewer* modelViewer;
|
||||
std::array<ViewerInterface*, ViewMode::_Count> m_views;
|
||||
std::array<std::string, ViewMode::_Count> m_viewNames;
|
||||
|
||||
QStackedWidget* viewSwitcher;
|
||||
|
||||
@ -59,12 +70,13 @@ public slots:
|
||||
signals:
|
||||
|
||||
void loadedData(GameWorld* world);
|
||||
void loadAnimations(const QString& file);
|
||||
|
||||
private slots:
|
||||
|
||||
void openRecent();
|
||||
|
||||
void switchWidget();
|
||||
void switchView(int mode);
|
||||
|
||||
void showObjectModel(uint16_t object);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "ViewerWidget.hpp"
|
||||
|
||||
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;
|
||||
mainLayout = new QVBoxLayout;
|
||||
@ -40,11 +40,6 @@ void ModelViewer::setViewerWidget(ViewerWidget* widget)
|
||||
showModel(viewing);
|
||||
}
|
||||
|
||||
void ModelViewer::showData(GameWorld* world)
|
||||
{
|
||||
_world = world;
|
||||
}
|
||||
|
||||
void ModelViewer::showModel(Model* model)
|
||||
{
|
||||
viewing = model;
|
||||
|
@ -1,14 +1,17 @@
|
||||
#pragma once
|
||||
#ifndef _MODELVIEWER_HPP_
|
||||
#define _MODELVIEWER_HPP_
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include "AnimationListWidget.hpp"
|
||||
|
||||
#include "ViewerInterface.hpp"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSplitter>
|
||||
#include <QLayout>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include "AnimationListWidget.hpp"
|
||||
|
||||
class ViewerWidget;
|
||||
class Model;
|
||||
@ -16,11 +19,10 @@ class Skeleton;
|
||||
class ModelFramesWidget;
|
||||
class Animation;
|
||||
|
||||
class ModelViewer : public QWidget
|
||||
class ModelViewer : public ViewerInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
GameWorld* _world;
|
||||
Model* viewing;
|
||||
Skeleton* skeleton;
|
||||
|
||||
@ -36,12 +38,7 @@ public:
|
||||
|
||||
ModelViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
GameWorld* world()
|
||||
{
|
||||
return _world;
|
||||
}
|
||||
|
||||
void setViewerWidget( ViewerWidget* widget );
|
||||
void setViewerWidget( ViewerWidget* widget ) override;
|
||||
|
||||
public slots:
|
||||
|
||||
@ -55,8 +52,6 @@ public slots:
|
||||
*/
|
||||
void showObject(uint16_t object);
|
||||
|
||||
void showData(GameWorld* world);
|
||||
|
||||
void loadAnimations(const QString& file);
|
||||
void playAnimation(Animation* anim);
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <QMenu>
|
||||
|
||||
ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
: ViewerInterface(parent, f)
|
||||
{
|
||||
mainLayout = new QHBoxLayout;
|
||||
|
||||
@ -44,12 +44,29 @@ ObjectViewer::ObjectViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlag
|
||||
|
||||
void ObjectViewer::setViewerWidget(ViewerWidget* widget)
|
||||
{
|
||||
static size_t c = 0;
|
||||
//widgetLayout->removeWidget(previewWidget);
|
||||
previewWidget = widget;
|
||||
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 =
|
||||
{
|
||||
{ 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)
|
||||
{
|
||||
showItem(model.internalId());
|
||||
|
@ -3,6 +3,9 @@
|
||||
#define _OBJECTVIEWER_HPP_
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
|
||||
#include "ViewerInterface.hpp"
|
||||
|
||||
#include <QTableView>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
@ -11,12 +14,11 @@
|
||||
class ViewerWidget;
|
||||
class Model;
|
||||
|
||||
class ObjectViewer : public QWidget
|
||||
class ObjectViewer : public ViewerInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QTableView* objectList;
|
||||
GameWorld* _world;
|
||||
|
||||
QHBoxLayout* mainLayout;
|
||||
QGridLayout* infoLayout;
|
||||
@ -31,13 +33,11 @@ public:
|
||||
|
||||
ObjectViewer(ViewerWidget *viewer = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
GameWorld* world()
|
||||
{
|
||||
return _world;
|
||||
}
|
||||
|
||||
void setViewerWidget( ViewerWidget* widget );
|
||||
|
||||
protected:
|
||||
void worldChanged() override;
|
||||
|
||||
signals:
|
||||
|
||||
void modelChanged(Model* model);
|
||||
@ -48,8 +48,6 @@ public slots:
|
||||
|
||||
void showItem(qint16 item);
|
||||
|
||||
void showData(GameWorld* world);
|
||||
|
||||
private slots:
|
||||
|
||||
void showItem(QModelIndex model);
|
||||
|
Loading…
Reference in New Issue
Block a user