From a49bfd9d99169d3cd711a17c25627b8bb7588f36 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 11 Feb 2014 05:46:29 +0000 Subject: [PATCH] Preperations for actual visuals --- rwengine/include/engine/GameData.hpp | 2 +- rwviewer/ArchiveContentsWidget.hpp | 2 +- rwviewer/ViewerWidget.cpp | 55 +++++++++++++++++++++++++--- rwviewer/ViewerWidget.hpp | 26 +++++++++++-- rwviewer/ViewerWindow.cpp | 12 +++++- rwviewer/ViewerWindow.hpp | 3 ++ 6 files changed, 88 insertions(+), 12 deletions(-) diff --git a/rwengine/include/engine/GameData.hpp b/rwengine/include/engine/GameData.hpp index 69a569f3..fca7b7c4 100644 --- a/rwengine/include/engine/GameData.hpp +++ b/rwengine/include/engine/GameData.hpp @@ -62,7 +62,7 @@ public: * ctor * @param path Path to the root of the game data. */ - GameData(const std::string& path); + GameData(const std::string& path = ""); GameWorld* engine; diff --git a/rwviewer/ArchiveContentsWidget.hpp b/rwviewer/ArchiveContentsWidget.hpp index 4e7d0db5..13fdf551 100644 --- a/rwviewer/ArchiveContentsWidget.hpp +++ b/rwviewer/ArchiveContentsWidget.hpp @@ -18,7 +18,7 @@ public: void setArchive(const LoaderIMG& archive); signals: - void selectedFileChanged(const std::string& file); + void selectedFileChanged(const QString& file); public slots: void selectedIndexChanged(const QModelIndex& current); diff --git a/rwviewer/ViewerWidget.cpp b/rwviewer/ViewerWidget.cpp index 55f32dcf..4bdb94b6 100644 --- a/rwviewer/ViewerWidget.cpp +++ b/rwviewer/ViewerWidget.cpp @@ -1,16 +1,27 @@ #include "ViewerWidget.hpp" +ViewerWidget::ViewerWidget(QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f) +: QGLWidget(parent, shareWidget, f), gworld(nullptr), fm(ViewerWidget::UNK) +{ +} + void ViewerWidget::initializeGL() { QGLWidget::initializeGL(); timer.setInterval(16); connect(&timer, SIGNAL(timeout()), SLOT(updateGL())); timer.start(); + + glewExperimental = 1; + glewInit(); + + gworld = new GameWorld(""); } void ViewerWidget::resizeGL(int w, int h) { QGLWidget::resizeGL(w, h); + glViewport(0, 0, w, h); } void ViewerWidget::paintGL() @@ -18,15 +29,47 @@ void ViewerWidget::paintGL() glClearColor(0.3f, 0.3f, 0.3f, 1.f); glClear(GL_COLOR_BUFFER_BIT); - if( !currentFile.empty() ) { - QString dbg; - dbg.append("Viewing: "); - dbg.append(currentFile.c_str()); + if( !currentFile.isEmpty() ) { + QString dbg = + QString("Viewing %1, %2") + .arg(currentFile); + switch(fm) { + case DFF: dbg = dbg.arg("DFF"); + break; + case TXD: dbg = dbg.arg("TXD"); + break; + case UNK: dbg = dbg.arg("Unknown"); + break; + } renderText(5, height() - 5, dbg); } } -void ViewerWidget::showFile(const std::string& file) +GameWorld* ViewerWidget::world() +{ + return gworld; +} + +void ViewerWidget::showFile(const QString& file) { currentFile = file; -} \ No newline at end of file + QString low = file.toLower(); + if(low.endsWith("dff")) { + showDFF(file); + } + else if(low.endsWith("txd")) { + showTXD(file); + } + emit fileOpened(file); +} + +void ViewerWidget::showDFF(const QString& file) +{ + gworld->gameData.loadDFF(file.toStdString()); + fm = ViewerWidget::DFF; +} + +void ViewerWidget::showTXD(const QString& file) +{ + fm = ViewerWidget::TXD; +} diff --git a/rwviewer/ViewerWidget.hpp b/rwviewer/ViewerWidget.hpp index be14c4d6..7e29e62c 100644 --- a/rwviewer/ViewerWidget.hpp +++ b/rwviewer/ViewerWidget.hpp @@ -1,6 +1,8 @@ #pragma once #ifndef _VIEWERWIDGET_HPP_ #define _VIEWERWIDGET_HPP_ +#include +#include #include #include @@ -8,20 +10,38 @@ class ViewerWidget : public QGLWidget { Q_OBJECT - std::string currentFile; + QString currentFile; QTimer timer; - + GameWorld* gworld; public: + + enum FileMode { + TXD, DFF, UNK + }; + + ViewerWidget(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); + virtual void initializeGL(); virtual void resizeGL(int w, int h); virtual void paintGL(); + + GameWorld* world(); public slots: - void showFile(const std::string& file); + void showFile(const QString& file); + void showDFF(const QString& file); + void showTXD(const QString& file); + +signals: + + void fileOpened(const QString& file); + +private: + FileMode fm; }; #endif \ No newline at end of file diff --git a/rwviewer/ViewerWindow.cpp b/rwviewer/ViewerWindow.cpp index 9e4ce234..1d464f22 100644 --- a/rwviewer/ViewerWindow.cpp +++ b/rwviewer/ViewerWindow.cpp @@ -1,4 +1,5 @@ #include "ViewerWindow.hpp" +#include #include "ViewerWidget.hpp" #include "ArchiveContentsWidget.hpp" #include @@ -23,7 +24,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow( file->addSeparator(); file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit); - connect(archivewidget, SIGNAL(selectedFileChanged(std::string)), viewer, SLOT(showFile(std::string))); + connect(archivewidget, SIGNAL(selectedFileChanged(QString)), viewer, SLOT(showFile(QString))); + connect(viewer, SIGNAL(fileOpened(QString)), SLOT(updateTitle(QString))); QSettings settings("OpenRW", "rwviewer"); restoreGeometry(settings.value("geometry").toByteArray()); @@ -41,6 +43,8 @@ void ViewerWindow::openArchive(const QString& name) LoaderIMG ld; ld.load(rname.toStdString()); + viewer->world()->gameData.loadIMG(rname.toStdString()); + archivewidget->setArchive(ld); } @@ -60,3 +64,9 @@ void ViewerWindow::openArchive() openArchive(dialog.selectedFiles().at(0)); } } + +void ViewerWindow::updateTitle(const QString& name) +{ + setWindowTitle(name); +} + diff --git a/rwviewer/ViewerWindow.hpp b/rwviewer/ViewerWindow.hpp index 71621c5b..a129cd07 100644 --- a/rwviewer/ViewerWindow.hpp +++ b/rwviewer/ViewerWindow.hpp @@ -12,14 +12,17 @@ class ViewerWindow : public QMainWindow ViewerWidget* viewer; ArchiveContentsWidget* archivewidget; public: + ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); void openArchive(const QString& name); virtual void closeEvent(QCloseEvent*); + public slots: void openArchive(); + void updateTitle(const QString& name); }; #endif \ No newline at end of file