1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Preperations for actual visuals

This commit is contained in:
Daniel Evans 2014-02-11 05:46:29 +00:00
parent 1741d7c295
commit a49bfd9d99
6 changed files with 88 additions and 12 deletions

View File

@ -62,7 +62,7 @@ public:
* ctor * ctor
* @param path Path to the root of the game data. * @param path Path to the root of the game data.
*/ */
GameData(const std::string& path); GameData(const std::string& path = "");
GameWorld* engine; GameWorld* engine;

View File

@ -18,7 +18,7 @@ public:
void setArchive(const LoaderIMG& archive); void setArchive(const LoaderIMG& archive);
signals: signals:
void selectedFileChanged(const std::string& file); void selectedFileChanged(const QString& file);
public slots: public slots:
void selectedIndexChanged(const QModelIndex& current); void selectedIndexChanged(const QModelIndex& current);

View File

@ -1,16 +1,27 @@
#include "ViewerWidget.hpp" #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() void ViewerWidget::initializeGL()
{ {
QGLWidget::initializeGL(); QGLWidget::initializeGL();
timer.setInterval(16); timer.setInterval(16);
connect(&timer, SIGNAL(timeout()), SLOT(updateGL())); connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
timer.start(); timer.start();
glewExperimental = 1;
glewInit();
gworld = new GameWorld("");
} }
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);
} }
void ViewerWidget::paintGL() void ViewerWidget::paintGL()
@ -18,15 +29,47 @@ 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); glClear(GL_COLOR_BUFFER_BIT);
if( !currentFile.empty() ) { if( !currentFile.isEmpty() ) {
QString dbg; QString dbg =
dbg.append("Viewing: "); QString("Viewing %1, %2")
dbg.append(currentFile.c_str()); .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); 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; currentFile = 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;
}

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#ifndef _VIEWERWIDGET_HPP_ #ifndef _VIEWERWIDGET_HPP_
#define _VIEWERWIDGET_HPP_ #define _VIEWERWIDGET_HPP_
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <QGLWidget> #include <QGLWidget>
#include <QTimer> #include <QTimer>
@ -8,20 +10,38 @@ class ViewerWidget : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
std::string currentFile; QString currentFile;
QTimer timer; QTimer timer;
GameWorld* gworld;
public: public:
enum FileMode {
TXD, DFF, UNK
};
ViewerWidget(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();
GameWorld* world();
public slots: 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 #endif

View File

@ -1,4 +1,5 @@
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
#include <engine/GameWorld.hpp>
#include "ViewerWidget.hpp" #include "ViewerWidget.hpp"
#include "ArchiveContentsWidget.hpp" #include "ArchiveContentsWidget.hpp"
#include <QMenuBar> #include <QMenuBar>
@ -23,7 +24,8 @@ ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags): QMainWindow(
file->addSeparator(); file->addSeparator();
file->addAction("E&xit", QApplication::instance(), SLOT(quit()), QKeySequence::Quit); 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"); QSettings settings("OpenRW", "rwviewer");
restoreGeometry(settings.value("geometry").toByteArray()); restoreGeometry(settings.value("geometry").toByteArray());
@ -41,6 +43,8 @@ void ViewerWindow::openArchive(const QString& name)
LoaderIMG ld; LoaderIMG ld;
ld.load(rname.toStdString()); ld.load(rname.toStdString());
viewer->world()->gameData.loadIMG(rname.toStdString());
archivewidget->setArchive(ld); archivewidget->setArchive(ld);
} }
@ -60,3 +64,9 @@ void ViewerWindow::openArchive()
openArchive(dialog.selectedFiles().at(0)); openArchive(dialog.selectedFiles().at(0));
} }
} }
void ViewerWindow::updateTitle(const QString& name)
{
setWindowTitle(name);
}

View File

@ -12,14 +12,17 @@ class ViewerWindow : public QMainWindow
ViewerWidget* viewer; ViewerWidget* viewer;
ArchiveContentsWidget* archivewidget; ArchiveContentsWidget* archivewidget;
public: public:
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
void openArchive(const QString& name); void openArchive(const QString& name);
virtual void closeEvent(QCloseEvent*); virtual void closeEvent(QCloseEvent*);
public slots: public slots:
void openArchive(); void openArchive();
void updateTitle(const QString& name);
}; };
#endif #endif