mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Now searching a test directory for files matching an extension and displaying them.
This commit is contained in:
parent
42a39c52e6
commit
3df40182b1
4
Makefile
4
Makefile
|
@ -1,7 +1,7 @@
|
|||
CC=g++
|
||||
CFLAGS=-c -Wall
|
||||
LDFLAGS=-lSDL -lSDL_ttf
|
||||
SRCSOURCES=main.cpp Renderer.cpp Renderer_draw.cpp GuiComponent.cpp InputManager.cpp components/GuiTitleScreen.cpp components/GuiList.cpp components/GuiGameList.cpp
|
||||
LDFLAGS=-lSDL -lSDL_ttf -lboost_system -lboost_filesystem
|
||||
SRCSOURCES=main.cpp Renderer.cpp Renderer_draw.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp components/GuiTitleScreen.cpp components/GuiList.cpp components/GuiGameList.cpp
|
||||
SOURCES=$(addprefix src/,$(SRCSOURCES))
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
EXECUTABLE=emulationstation
|
||||
|
|
13
src/GameData.cpp
Normal file
13
src/GameData.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "GameData.h"
|
||||
|
||||
GameData::GameData(SystemData* system, std::string path, std::string name)
|
||||
{
|
||||
mSystem = system;
|
||||
mPath = path;
|
||||
mName = name;
|
||||
}
|
||||
|
||||
std::string GameData::getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
19
src/GameData.h
Normal file
19
src/GameData.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef _GAMEDATA_H_
|
||||
#define _GAMEDATA_H_
|
||||
|
||||
#include <string>
|
||||
#include "SystemData.h"
|
||||
|
||||
class GameData
|
||||
{
|
||||
public:
|
||||
GameData(SystemData* system, std::string path, std::string name);
|
||||
|
||||
std::string getName();
|
||||
private:
|
||||
SystemData* mSystem;
|
||||
std::string mPath;
|
||||
std::string mName;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@ void Renderer::drawRect(int x, int y, int h, int w, int color)
|
|||
|
||||
void Renderer::loadFonts()
|
||||
{
|
||||
font = TTF_OpenFont("LinLibertine_R.ttf", 72);
|
||||
font = TTF_OpenFont("LinLibertine_R.ttf", 48);
|
||||
if(!font)
|
||||
{
|
||||
std::cerr << "Error - could not load font!\n";
|
||||
|
|
73
src/SystemData.cpp
Normal file
73
src/SystemData.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "SystemData.h"
|
||||
#include "GameData.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
SystemData::SystemData(std::string name, std::string startPath, std::string extension)
|
||||
{
|
||||
mName = name;
|
||||
mStartPath = startPath;
|
||||
mSearchExtension = extension;
|
||||
buildGameList();
|
||||
}
|
||||
|
||||
SystemData::~SystemData()
|
||||
{
|
||||
for(unsigned int i = 0; i < mGameVector.size(); i++)
|
||||
{
|
||||
delete mGameVector.at(i);
|
||||
}
|
||||
mGameVector.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SystemData::buildGameList()
|
||||
{
|
||||
std::cout << "System " << mName << " building game list...\n";
|
||||
|
||||
if(!fs::is_directory(mStartPath))
|
||||
{
|
||||
std::cout << "Error - system \"" << mName << "\"'s start path does not exist!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
for(fs::recursive_directory_iterator end, dir(mStartPath); dir != end; ++dir)
|
||||
{
|
||||
std::cout << "File found: " << *dir << "\n";
|
||||
|
||||
fs::path path = (*dir).path();
|
||||
|
||||
if(fs::is_directory(path))
|
||||
continue;
|
||||
|
||||
std::string name = path.stem().string();
|
||||
std::string extension = path.extension().string();
|
||||
|
||||
std::cout << "detected name as \"" << name <<"\", extension as \"" << extension << "\"\n";
|
||||
|
||||
if(extension == mSearchExtension)
|
||||
{
|
||||
mGameVector.push_back(new GameData(this, path.string(), name));
|
||||
std::cout << "Added game \"" << name << "\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "...done! Found " << mGameVector.size() << " games.\n";
|
||||
}
|
||||
|
||||
unsigned int SystemData::getGameCount()
|
||||
{
|
||||
return mGameVector.size();
|
||||
}
|
||||
|
||||
GameData* SystemData::getGame(unsigned int i)
|
||||
{
|
||||
return mGameVector.at(i);
|
||||
}
|
||||
|
||||
std::string SystemData::getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
26
src/SystemData.h
Normal file
26
src/SystemData.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef _SYSTEMDATA_H_
|
||||
#define _SYSTEMDATA_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class GameData;
|
||||
|
||||
class SystemData
|
||||
{
|
||||
public:
|
||||
SystemData(std::string name, std::string startPath, std::string extension);
|
||||
~SystemData();
|
||||
|
||||
unsigned int getGameCount();
|
||||
GameData* getGame(unsigned int i);
|
||||
std::string getName();
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mStartPath;
|
||||
std::string mSearchExtension;
|
||||
std::vector<GameData*> mGameVector;
|
||||
void buildGameList();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,16 +1,33 @@
|
|||
#include "GuiGameList.h"
|
||||
#include <iostream>
|
||||
|
||||
GuiGameList::GuiGameList(std::string systemName)
|
||||
GuiGameList::GuiGameList(SystemData* system)
|
||||
{
|
||||
mSystemName = systemName;
|
||||
mSystem = system;
|
||||
|
||||
mList = new GuiList();
|
||||
updateList();
|
||||
|
||||
addChild(mList);
|
||||
|
||||
Renderer::registerComponent(this);
|
||||
}
|
||||
|
||||
void GuiGameList::onRender()
|
||||
{
|
||||
SDL_Color color = {0, 0, 255};
|
||||
Renderer::drawCenteredText(mSystemName, 2, color);
|
||||
Renderer::drawRect(0, 0, 640, 480, 0xFFFFFF);
|
||||
|
||||
SDL_Color color = {0, 155, 100};
|
||||
Renderer::drawCenteredText(mSystem->getName(), 2, color);
|
||||
}
|
||||
|
||||
void GuiGameList::updateList()
|
||||
{
|
||||
mList->clear();
|
||||
|
||||
for(unsigned int i = 0; i < mSystem->getGameCount(); i++)
|
||||
{
|
||||
GameData* game = mSystem->getGame(i);
|
||||
mList->addObject(game->getName(), game);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,18 @@
|
|||
#include "../GuiComponent.h"
|
||||
#include "GuiList.h"
|
||||
#include <string>
|
||||
#include "../SystemData.h"
|
||||
#include "../GameData.h"
|
||||
|
||||
class GuiGameList : GuiComponent
|
||||
{
|
||||
public:
|
||||
GuiGameList(std::string systemName);
|
||||
GuiGameList(SystemData* system);
|
||||
void updateList();
|
||||
|
||||
void onRender();
|
||||
private:
|
||||
std::string mSystemName;
|
||||
SystemData* mSystem;
|
||||
GuiList* mList;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "GuiList.h"
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
GuiList::GuiList()
|
||||
{
|
||||
|
@ -7,7 +8,13 @@ GuiList::GuiList()
|
|||
|
||||
void GuiList::onRender()
|
||||
{
|
||||
|
||||
int y = 40;
|
||||
SDL_Color color = {0, 0, 255};
|
||||
for(unsigned int i = 0; i < mNameVector.size(); i++)
|
||||
{
|
||||
Renderer::drawCenteredText(mNameVector.at(i), y, color);
|
||||
y += 35;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiList::addObject(std::string name, void* obj)
|
||||
|
@ -16,7 +23,7 @@ void GuiList::addObject(std::string name, void* obj)
|
|||
mPointerVector.push_back(obj);
|
||||
}
|
||||
|
||||
void GuiList::clearObjects()
|
||||
void GuiList::clear()
|
||||
{
|
||||
mNameVector.clear();
|
||||
mPointerVector.clear();
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
void onRender();
|
||||
|
||||
void addObject(std::string name, void* obj);
|
||||
void clearObjects();
|
||||
void clear();
|
||||
|
||||
std::string getSelectedName();
|
||||
void* getSelectedObject();
|
||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -2,7 +2,8 @@
|
|||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
#include "Renderer.h"
|
||||
#include "components/GuiTitleScreen.h"
|
||||
#include "components/GuiGameList.h"
|
||||
#include "SystemData.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -26,7 +27,11 @@ int main()
|
|||
|
||||
SDL_ShowCursor(false);
|
||||
|
||||
GuiTitleScreen* testGui = new GuiTitleScreen();
|
||||
//GuiTitleScreen* testGui = new GuiTitleScreen();
|
||||
|
||||
//test systemData
|
||||
SystemData* testSystem = new SystemData("Test", "./testdir/", ".smc");
|
||||
GuiGameList* testGui = new GuiGameList(testSystem);
|
||||
|
||||
|
||||
bool running = true;
|
||||
|
@ -55,6 +60,7 @@ int main()
|
|||
}
|
||||
|
||||
delete testGui;
|
||||
delete testSystem;
|
||||
|
||||
std::cout << "EmulationStation cleanly shutting down...\n";
|
||||
|
||||
|
|
0
testdir/testgame.smc
Normal file
0
testdir/testgame.smc
Normal file
Loading…
Reference in a new issue