Skip to content

Commit

Permalink
render each collection of videos in its own ui
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSapps committed Jul 12, 2015
1 parent 812c063 commit fb13ae7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 69 deletions.
1 change: 1 addition & 0 deletions include/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Engine
void RenderVideoUi();
void ImGui_WindowResize();
private:
void DrawVideoSelectionUi(const std::string& name, const std::vector<std::string>& allFmvs);

bool mRunning = true;
FileSystem mFileSystem;
Expand Down
11 changes: 8 additions & 3 deletions include/gamedata.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <map>
#include <vector>

class GameData
Expand All @@ -9,10 +10,14 @@ class GameData
GameData();
~GameData();
bool Init(std::string basePath);
const std::vector<std::string>& Fmvs() const
const std::map<std::string, std::vector<std::string>>& Fmvs() const
{
return allFmvs;
return mFmvData;
}

private:
bool LoadFmvData(std::string basePath);

private:
std::vector<std::string> allFmvs;
std::map<std::string, std::vector<std::string>> mFmvData;
};
124 changes: 67 additions & 57 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,74 +342,83 @@ void Engine::Update()
UpdateImGui();
}

void Engine::RenderVideoUi()
void Engine::DrawVideoSelectionUi(const std::string& setName, const std::vector<std::string>& allFmvs)
{
if (!video)
{
ImGui::Begin("Video player", nullptr, ImVec2(550, 480), 1.0f, ImGuiWindowFlags_NoCollapse);
std::string name = "Video player (" + setName + ")";
ImGui::Begin(name.c_str(), nullptr, ImVec2(550, 580), 1.0f, ImGuiWindowFlags_NoCollapse);
#ifdef _WIN32
static char buf[4096] = "C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Oddworld Abes Exoddus\\";
static char buf[4096] = "C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Oddworld Abes Exoddus\\";
#else
static char buf[4096] = "/home/paul/ae_test/";
static char buf[4096] = "/home/paul/ae_test/";
#endif

ImGui::InputText("Video path", buf, sizeof(buf));
ImGui::InputText("Video path", buf, sizeof(buf));

static ImGuiTextFilter filter;
filter.Draw();
static ImGuiTextFilter filter;
filter.Draw();

auto allFmvs = mGameData.Fmvs();

static int listbox_item_current = 1;
static std::vector<const char*> listbox_items;
listbox_items.resize(allFmvs.size());
static int listbox_item_current = 1;
static std::vector<const char*> listbox_items;
listbox_items.resize(allFmvs.size());

int matchingFilter = 0;
for (size_t i = 0; i < allFmvs.size(); i++)
int matchingFilter = 0;
for (size_t i = 0; i < allFmvs.size(); i++)
{
if (filter.PassFilter(allFmvs[i].c_str()))
{
if (filter.PassFilter(allFmvs[i].c_str()))
{
listbox_items[matchingFilter] = allFmvs[i].c_str();
matchingFilter++;
}
listbox_items[matchingFilter] = allFmvs[i].c_str();
matchingFilter++;
}
ImGui::PushItemWidth(-1);
ImGui::ListBox("##", &listbox_item_current, listbox_items.data(), matchingFilter, 27);
}
ImGui::PushItemWidth(-1);
ImGui::ListBox("##", &listbox_item_current, listbox_items.data(), matchingFilter, 27);

if (ImGui::Button("Play", ImVec2(ImGui::GetWindowWidth(), 20)))
if (ImGui::Button("Play", ImVec2(ImGui::GetWindowWidth(), 20)))
{
std::string fullPath = std::string(buf) + listbox_items[listbox_item_current];
std::cout << "Play " << listbox_items[listbox_item_current] << std::endl;
try
{
std::string fullPath = std::string(buf) + listbox_items[listbox_item_current];
std::cout << "Play " << listbox_items[listbox_item_current] << std::endl;
try
{

video = std::make_unique<Oddlib::Masher>(fullPath);
if (videoFrame)
{
SDL_FreeSurface(videoFrame);
videoFrame = nullptr;
}

if (video->HasAudio())
{
AudioBuffer::ChangeAudioSpec(video->SingleAudioFrameSizeBytes(), video->AudioSampleRate());
}
video = std::make_unique<Oddlib::Masher>(fullPath);
if (videoFrame)
{
SDL_FreeSurface(videoFrame);
videoFrame = nullptr;
}

if (video->HasVideo())
{
videoFrame = SDL_CreateRGBSurface(0, video->Width(), video->Height(), 32, 0, 0, 0, 0);
// targetFps = video->FrameRate() * 2;
}
SDL_ShowCursor(0);
if (video->HasAudio())
{
AudioBuffer::ChangeAudioSpec(video->SingleAudioFrameSizeBytes(), video->AudioSampleRate());
}
catch (const Oddlib::Exception& ex)

if (video->HasVideo())
{
// ImGui::Text(ex.what());
videoFrame = SDL_CreateRGBSurface(0, video->Width(), video->Height(), 32, 0, 0, 0, 0);
// targetFps = video->FrameRate() * 2;
}
SDL_ShowCursor(0);
}
catch (const Oddlib::Exception& ex)
{
// ImGui::Text(ex.what());
}
}

ImGui::End();
ImGui::End();
}

void Engine::RenderVideoUi()
{

if (!video)
{
auto fmvs = mGameData.Fmvs();
for (auto fmvSet : fmvs)
{
DrawVideoSelectionUi(fmvSet.first, fmvSet.second);
}
}
else
{
Expand All @@ -436,7 +445,6 @@ void Engine::RenderVideoUi()

}
}

}

void Engine::Render()
Expand Down Expand Up @@ -542,6 +550,17 @@ void Engine::Render()

bool Engine::InitSDL()
{
SDL_Init(SDL_INIT_EVERYTHING);

window = SDL_CreateWindow(ALIVE_VERSION_NAME_STR,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

#if defined(_WIN32)
// I'd like my icon back thanks
setWindowsIcon(window);
#endif

return true;
}

Expand Down Expand Up @@ -604,16 +623,7 @@ void Engine::InitGL()
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_CORE);

SDL_Init(SDL_INIT_EVERYTHING);

window = SDL_CreateWindow(ALIVE_VERSION_NAME_STR,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

#if defined(_WIN32)
// I'd like my icon back thanks
setWindowsIcon(window);
#endif

context = SDL_GL_CreateContext(window);

Expand Down
23 changes: 14 additions & 9 deletions src/gamedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ GameData::~GameData()

}

bool GameData::Init(std::string basePath)
bool GameData::LoadFmvData(std::string basePath)
{

jsonxx::Object rootJsonObject;
std::ifstream tmpStream(basePath + "data/videos.json");
if (!tmpStream)
Expand All @@ -36,21 +35,27 @@ bool GameData::Init(std::string basePath)
jsonxx::Object& fmvObj = rootJsonObject.get<jsonxx::Object>("FMVS");
for (auto& v : fmvObj.kv_map())
{
std::string arrayName = v.first;

std::vector<std::string> fmvs;
jsonxx::Array& ar = fmvObj.get<jsonxx::Array>(v.first);
for (size_t i = 0; i < ar.size(); i++)
{
jsonxx::String s = ar.get<jsonxx::String>(i);
allFmvs.emplace_back(s);

fmvs.emplace_back(s);
}
mFmvData[v.first] = std::move(fmvs);
}
}

// for (auto& value : fmvsArray.values())
{
// jsonxx::Array& a = value->get<jsonxx::Array>();
return true;
}

}
bool GameData::Init(std::string basePath)
{
if (!LoadFmvData(basePath))
{
return false;
}

return true;
}

0 comments on commit fb13ae7

Please sign in to comment.