Example #1
0
void ViewerWindow::loadGame(const QString &path)
{
	QDir gameDir( path );

	if( gameDir.exists() && path.size() > 0 ) {
		gameData = new GameData( &engineLog, &work, gameDir.absolutePath().toStdString() );
		gameWorld = new GameWorld( &engineLog, &work, gameData );
		renderer = new GameRenderer(&engineLog, gameData );
		viewerWidget->setRenderer(renderer);

		gameWorld->data->load();

		// Initalize all the archives.
		gameWorld->data->loadIMG("/models/gta3");
		gameWorld->data->loadIMG("/models/txd");
		gameWorld->data->loadIMG("/anim/cuts");

		loadedData(gameWorld);
	}

	QSettings settings("OpenRW", "rwviewer");
	QStringList recent = settings.value("recentGames").toStringList();
	recent.removeAll( path );
	recent.prepend( path );
	while(recent.size() > MaxRecentGames) recent.removeLast();
	settings.setValue("recentGames", recent);

	updateRecentGames();
}
Example #2
0
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
	: QMainWindow(parent, flags), gameData(nullptr), gameWorld(nullptr), renderer(nullptr)
{
	setMinimumSize(640, 480);

	QMenuBar* mb = this->menuBar();
	QMenu* file = mb->addMenu("&File");

	file->addAction("Open &Game", this, SLOT(loadGame()));

	file->addSeparator();
	for(int i = 0; i < MaxRecentGames; ++i) {
		QAction* r = file->addAction("");
		recentGames.append(r);
		connect(r, SIGNAL(triggered()), SLOT(openRecent()));
	}

	recentSep = file->addSeparator();
	auto ex = file->addAction("E&xit");
	ex->setShortcut(QKeySequence::Quit);
	connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));

	viewerWidget = new ViewerWidget;

	viewerWidget->context()->makeCurrent();

	glewExperimental = 1;
	glewInit();

	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);

	connect(this, SIGNAL(loadedData(GameWorld*)), modelViewer, SLOT(showData(GameWorld*)));

	viewSwitcher = new QStackedWidget;
	viewSwitcher->addWidget(objectViewer);
	viewSwitcher->addWidget(modelViewer);

	//connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*)));
	connect(objectViewer, SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));

	objectViewer->setViewerWidget( viewerWidget );

	QMenu* view = mb->addMenu("&View");
	QAction* objectAction = view->addAction("&Object");
	QAction* modelAction = view->addAction("&Model");

	objectAction->setData(0);
	modelAction->setData(1);

	connect(objectAction, SIGNAL(triggered()), this, SLOT(switchWidget()));
	connect(modelAction, SIGNAL(triggered()), this, SLOT(switchWidget()));

	QMenu* data = mb->addMenu("&Data");
	//data->addAction("Export &Model", objectViewer, SLOT(exportModel()));

	QMenu* anim = mb->addMenu("&Animation");
	anim->addAction("Load &Animations", this, SLOT(openAnimations()));

	this->setCentralWidget(viewSwitcher);

	updateRecentGames();
}
Example #3
0
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
	: QMainWindow(parent, flags)
	, gameData(nullptr)
	, gameWorld(nullptr)
	, renderer(nullptr)
{
	setMinimumSize(640, 480);

	QMenuBar* mb = this->menuBar();
	QMenu* file = mb->addMenu("&File");

	file->addAction("Open &Game", this, SLOT(loadGame()));

	file->addSeparator();
	for(int i = 0; i < MaxRecentGames; ++i) {
		QAction* r = file->addAction("");
		recentGames.append(r);
		connect(r, SIGNAL(triggered()), SLOT(openRecent()));
	}

	recentSep = file->addSeparator();
	auto ex = file->addAction("E&xit");
	ex->setShortcut(QKeySequence::Quit);
	connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));

	//----------------------- View Mode setup
	viewerWidget = new ViewerWidget;
	viewerWidget->context()->makeCurrent();
	connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*)));

	//------------- Object Viewer
	m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
	m_viewNames[ViewMode::Object] = "Objects";

	//------------- Model Viewer
	m_views[ViewMode::Model]  = new ModelViewer(viewerWidget);
	m_viewNames[ViewMode::Model] = "Model";

	//------------- World Viewer
	m_views[ViewMode::World] = new WorldViewer(viewerWidget);
	m_viewNames[ViewMode::World] = "World";

	//------------- display mode switching
	viewSwitcher = new QStackedWidget;
	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*)));

		auto viewerButton = new QPushButton(m_viewNames[i].c_str());
		signalMapper->setMapping(m_views[i], i);
		signalMapper->setMapping(viewerButton, i);
		connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
		switchPanel->addWidget(viewerButton);
		i++;
	}
	// Map world viewer loading placements to switch to the world viewer
	connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map()));

	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)), 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)), viewSwitcher, SLOT(setCurrentIndex(int)));

	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()));

	QMenu* anim = mb->addMenu("&Animation");
	anim->addAction("Load &Animations", this, SLOT(openAnimations()));

	QMenu* map = mb->addMenu("&Map");
	map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements()));

	this->setCentralWidget(mainwidget);

	updateRecentGames();
}