mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-07 01:15:14 +01:00
Simpler way to create new project, project path in title bar
This commit is contained in:
parent
f95495ef6b
commit
caa0e73935
5 changed files with 61 additions and 9 deletions
|
|
@ -69,6 +69,7 @@ struct StoryProject
|
||||||
{
|
{
|
||||||
m_uuid = "";
|
m_uuid = "";
|
||||||
m_working_dir = "";
|
m_working_dir = "";
|
||||||
|
m_story_file_path = "";
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,11 @@ void Gui::Destroy()
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Gui::SetWindowTitle(const std::string &title)
|
||||||
|
{
|
||||||
|
SDL_SetWindowTitle(window, title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
bool Gui::LoadRawImage(const std::string &filename, Image &image)
|
bool Gui::LoadRawImage(const std::string &filename, Image &image)
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public:
|
||||||
void StartFrame();
|
void StartFrame();
|
||||||
void EndFrame();
|
void EndFrame();
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
void SetWindowTitle(const std::string &title);
|
||||||
|
|
||||||
static bool LoadRawImage(const std::string &filename, Image &image);
|
static bool LoadRawImage(const std::string &filename, Image &image);
|
||||||
static Size GetWindowSize();
|
static Size GetWindowSize();
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ void MainWindow::DrawMainMenuBar()
|
||||||
|
|
||||||
if (showNewProject)
|
if (showNewProject)
|
||||||
{
|
{
|
||||||
ImGui::OpenPopup("NewProjectPopup");
|
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDialog", "Choose a parent directory for your project", nullptr, ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showOpenProject)
|
if (showOpenProject)
|
||||||
|
|
@ -363,7 +363,7 @@ void MainWindow::DrawMainMenuBar()
|
||||||
void MainWindow::Initialize()
|
void MainWindow::Initialize()
|
||||||
{
|
{
|
||||||
// GUI Init
|
// GUI Init
|
||||||
gui.Initialize();
|
m_gui.Initialize();
|
||||||
// gui.ApplyTheme();
|
// gui.ApplyTheme();
|
||||||
|
|
||||||
m_editorWindow.Initialize();
|
m_editorWindow.Initialize();
|
||||||
|
|
@ -420,7 +420,6 @@ void MainWindow::OpenProjectDialog()
|
||||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||||
|
|
||||||
OpenProject(filePathName);
|
OpenProject(filePathName);
|
||||||
// RefreshProjectInformation(); // FIXME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// close
|
// close
|
||||||
|
|
@ -430,6 +429,39 @@ void MainWindow::OpenProjectDialog()
|
||||||
|
|
||||||
void MainWindow::NewProjectPopup()
|
void MainWindow::NewProjectPopup()
|
||||||
{
|
{
|
||||||
|
// Always center this window when appearing
|
||||||
|
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||||
|
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||||
|
|
||||||
|
if (ImGuiFileDialog::Instance()->Display("ChooseDirDialog"))
|
||||||
|
{
|
||||||
|
// action if OK
|
||||||
|
if (ImGuiFileDialog::Instance()->IsOk())
|
||||||
|
{
|
||||||
|
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||||
|
std::string projdir = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||||
|
|
||||||
|
std::string uuid = UUID().String();
|
||||||
|
auto p = std::filesystem::path(projdir) / uuid / std::filesystem::path("project.json");
|
||||||
|
m_story.Initialize(p.generic_string());
|
||||||
|
|
||||||
|
m_story.SetDisplayFormat(320, 240);
|
||||||
|
m_story.SetImageFormat(StoryProject::IMG_FORMAT_QOIF);
|
||||||
|
m_story.SetSoundFormat(StoryProject::SND_FORMAT_WAV);
|
||||||
|
m_story.SetName("New project");
|
||||||
|
m_story.SetUuid(uuid);
|
||||||
|
|
||||||
|
SaveProject();
|
||||||
|
OpenProject(p.generic_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// close
|
||||||
|
ImGuiFileDialog::Instance()->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
static std::string projdir;
|
static std::string projdir;
|
||||||
// Always center this window when appearing
|
// Always center this window when appearing
|
||||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||||
|
|
@ -443,11 +475,13 @@ void MainWindow::NewProjectPopup()
|
||||||
ImGui::Text("Directory: "); ImGui::SameLine();
|
ImGui::Text("Directory: "); ImGui::SameLine();
|
||||||
static char project_dir[256] = "";
|
static char project_dir[256] = "";
|
||||||
ImGui::InputTextWithHint("##project_path", "Project path", project_dir, IM_ARRAYSIZE(project_dir));
|
ImGui::InputTextWithHint("##project_path", "Project path", project_dir, IM_ARRAYSIZE(project_dir));
|
||||||
|
ImGui::SameLine();
|
||||||
if (ImGui::Button( ICON_MDI_FOLDER " ..."))
|
if (ImGui::Button( ICON_MDI_FOLDER " ..."))
|
||||||
{
|
{
|
||||||
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDialog", "Choose File", nullptr, ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
|
ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDialog", "Choose File", nullptr, ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// display
|
// display
|
||||||
if (ImGuiFileDialog::Instance()->Display("ChooseDirDialog"))
|
if (ImGuiFileDialog::Instance()->Display("ChooseDirDialog"))
|
||||||
{
|
{
|
||||||
|
|
@ -616,6 +650,7 @@ void MainWindow::NewProjectPopup()
|
||||||
{
|
{
|
||||||
projdir = "";
|
projdir = "";
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SaveProject()
|
void MainWindow::SaveProject()
|
||||||
|
|
@ -627,7 +662,6 @@ void MainWindow::SaveProject()
|
||||||
|
|
||||||
void MainWindow::OpenProject(const std::string &filename)
|
void MainWindow::OpenProject(const std::string &filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_story.Initialize(filename);
|
m_story.Initialize(filename);
|
||||||
|
|
||||||
nlohmann::json model;
|
nlohmann::json model;
|
||||||
|
|
@ -662,7 +696,15 @@ void MainWindow::OpenProject(const std::string &filename)
|
||||||
Log("Open project error");
|
Log("Open project error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefreshProjectInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::RefreshProjectInformation()
|
||||||
|
{
|
||||||
|
m_gui.SetWindowTitle("Story Editor - " + m_story.GetProjectFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::CloseProject()
|
void MainWindow::CloseProject()
|
||||||
{
|
{
|
||||||
m_story.Clear();
|
m_story.Clear();
|
||||||
|
|
@ -680,6 +722,8 @@ void MainWindow::CloseProject()
|
||||||
m_editorWindow.Disable();
|
m_editorWindow.Disable();
|
||||||
m_resourcesWindow.Disable();
|
m_resourcesWindow.Disable();
|
||||||
m_PropertiesWindow.Disable();
|
m_PropertiesWindow.Disable();
|
||||||
|
|
||||||
|
RefreshProjectInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -691,9 +735,9 @@ void MainWindow::Loop()
|
||||||
|
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
bool aboutToClose = gui.PollEvent();
|
bool aboutToClose = m_gui.PollEvent();
|
||||||
|
|
||||||
gui.StartFrame();
|
m_gui.StartFrame();
|
||||||
|
|
||||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||||
DrawMainMenuBar();
|
DrawMainMenuBar();
|
||||||
|
|
@ -725,12 +769,12 @@ void MainWindow::Loop()
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.EndFrame();
|
m_gui.EndFrame();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.Destroy();
|
m_gui.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::Log(const std::string &txt, bool critical)
|
void MainWindow::Log(const std::string &txt, bool critical)
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ private:
|
||||||
|
|
||||||
ResourceManager m_resources;
|
ResourceManager m_resources;
|
||||||
|
|
||||||
Gui gui;
|
Gui m_gui;
|
||||||
EmulatorWindow m_emulatorWindow;
|
EmulatorWindow m_emulatorWindow;
|
||||||
ConsoleWindow m_consoleWindow;
|
ConsoleWindow m_consoleWindow;
|
||||||
CodeEditor m_editorWindow;
|
CodeEditor m_editorWindow;
|
||||||
|
|
@ -173,6 +173,7 @@ private:
|
||||||
std::string GetFileNameFromMemory(uint32_t addr);
|
std::string GetFileNameFromMemory(uint32_t addr);
|
||||||
void ProcessStory();
|
void ProcessStory();
|
||||||
void StepInstruction();
|
void StepInstruction();
|
||||||
|
void RefreshProjectInformation();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue