New project generation working

Gui_Panel_Refactor
Joeyrp 4 years ago
parent 9e6a15d08f
commit fda2264251

@ -36,7 +36,7 @@ Core:
✔ Allow opening of listed directories @done (11/8/2021, 3:16:26 PM)
✔ Add indication that an item is directory @done (11/8/2021, 6:19:20 PM)
✔ Sort items by type (Directories should come first) @done (11/8/2021, 6:26:01 PM)
☐ Allow the user to type in a filename
✔ Allow the user to type in a filename @done (11/9/2021, 3:26:16 PM)
✔ Add a "New Directory" button @done (11/8/2021, 7:15:51 PM)
Input:

@ -14,6 +14,11 @@ Editor:
☐ Raw Sound importer class
☐ Raw font file importer class
Project (Class for loading and tracking project data):
✔ Generate new project at given location @done (11/9/2021, 3:26:03 PM)
☐ Save project data
☐ Open existing project
GUI Panels:
Project Overview (Tree view):

@ -8,14 +8,21 @@ Game:
Scene:
☐ Manage scene scripts
☐ Manage game objects in scene
☐ Manage the master list of game objects in scene
☐ Contains a World (World System)
Manage list of Regions:
☐ Track which regions should be loaded
World System:
☐ Track/manage loaded regions
☐ Render loaded Regions
Region:
☐ List of renderable images for each layer
Camera:
☐ Current Region
☐ Current Position within Region
Region:
☐ List of renderable images for each layer
☐ List of game objects (by reference) in this Region
Game Object:
☐ List of components
@ -30,4 +37,4 @@ Game:
☐ Audio Listener
Animations:
☐ Animated Sprite clas
☐ Animated Sprite class

@ -21,6 +21,10 @@ namespace lunarium
: mIsOpen(false), mSelectionMode(SelectionMode::FILES_ONLY), mWarnOnExisting(false), mpFolderIcon(nullptr), mResult(Result::CANCEL),
mpNewFolderIcon(nullptr), mpUpFolderIcon(nullptr)
{
mPrompt = "Select an item";
memset(mDirNameBuffer, 0, mBufferSize);
memset(mInputBuffer, 0, mBufferSize);
int x,y,n;
unsigned char* pData = stbi_load("dir_icon.png", &x, &y, &n, 0);
mpFolderIcon = new Image(pData, x, y, ImageFormat::RGBA);
@ -72,18 +76,21 @@ namespace lunarium
return false;
}
ImGui::TextUnformatted(mPrompt.c_str());
ImGui::Separator();
ImVec2 iconSize(mpNewFolderIcon->GetWidth(), mpNewFolderIcon->GetHeight());
if (ImGui::ImageButton((ImTextureID) mpNewFolderIcon->GetGLTextureID(), iconSize))
{
ImGui::OpenPopup("New Folder Name");
memset(mInputBuffer, 0, mBufferSize);
memset(mDirNameBuffer, 0, mBufferSize);
}
if (ImGui::BeginPopup("New Folder Name"))
{
if (ImGui::InputText("Folder Name", mInputBuffer, mBufferSize, ImGuiInputTextFlags_EnterReturnsTrue))
if (ImGui::InputText("Folder Name", mDirNameBuffer, mBufferSize, ImGuiInputTextFlags_EnterReturnsTrue))
{
std::filesystem::create_directory(mInputBuffer);
std::filesystem::create_directory(mDirNameBuffer);
ImGui::CloseCurrentPopup();
ReloadItems();
}
@ -104,13 +111,11 @@ namespace lunarium
DoListBox();
ImGui::Separator();
if (mpSelectedItem)
{
ImGui::Text("Selected: %s", mpSelectedItem->filename().string().c_str());
}
else
if (ImGui::InputText("selection", mInputBuffer, mBufferSize))
{
ImGui::Text("Selected: ");
mInputSelection = mCurrentDirectory / mInputBuffer;
mpSelectedItem = &mInputSelection;
}
ImGui::Separator();
@ -136,6 +141,11 @@ namespace lunarium
mWarnOnExisting = warn;
}
void FileBrowser::SetPrompt(std::string prompt)
{
mPrompt = prompt;
}
/// returns nullptr if the dialog has not been opened yet
const std::filesystem::path* FileBrowser::GetSelectedItem() const
@ -184,7 +194,7 @@ namespace lunarium
////////////////////////////////////////////////////////////
void FileBrowser::DoListBox()
{
if (ImGui::BeginListBox("", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowHeight() * .65f)))
if (ImGui::BeginListBox("", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowHeight() * .575f)))
{
for (int i = 0; i < mItemsInDir.size(); i++)
{

@ -45,6 +45,7 @@ namespace lunarium
bool DoFrame();
bool IsOpen() const;
void SetPrompt(std::string prompt);
void AddExtensionFilter(std::string ext);
void SetSelectionMode(SelectionMode mode);
void WarnOnExistingFileSelection(bool warn);
@ -59,15 +60,18 @@ namespace lunarium
SelectionMode mSelectionMode;
bool mWarnOnExisting;
Result mResult;
std::string mPrompt;
std::filesystem::path mCurrentDirectory;
std::vector<std::filesystem::path> mItemsInDir;
std::vector<std::string> mExtensionsFilter; // Show only these extensions. If empty show all files.
std::filesystem::path* mpSelectedItem;
std::filesystem::path mInputSelection;
Image* mpFolderIcon;
Image* mpNewFolderIcon;
Image* mpUpFolderIcon;
static const int mBufferSize = 256;
char mDirNameBuffer[mBufferSize];
char mInputBuffer[mBufferSize];
private:

@ -1,4 +1,4 @@
add_library(editor editor.cpp panels/iPanel.cpp panels/mainPanel.cpp panels/about.cpp)
add_library(editor editor.cpp project/project.cpp panels/iPanel.cpp panels/mainPanel.cpp panels/about.cpp)
target_include_directories(editor
PUBLIC "${PROJECT_BINARY_DIR}"
@ -8,4 +8,5 @@ target_include_directories(editor
PUBLIC ../../../external/glad/include
PUBLIC ../../../external/glfw/include
PUBLIC ../../../external/box2d/include
PUBLIC ../../../external/pugixml/src
)

@ -90,7 +90,8 @@ namespace lunarium
{
mpFileBrowser = new FileBrowser;
// mpFileBrowser->WarnOnExistingFileSelection(true);
mpFileBrowser->SetSelectionMode(FileBrowser::SelectionMode::DIRECTORIES_ONLY);
mpFileBrowser->SetSelectionMode(FileBrowser::SelectionMode::FILES_ONLY);
mpFileBrowser->SetPrompt("Pick a location and name for the project");
if (!mpFileBrowser->OpenInDirectory(""))
{
delete mpFileBrowser;
@ -106,7 +107,12 @@ namespace lunarium
{
Logger::Log(mLogCat, LogLevel::INFO, "Generating new project at %s", mpPath->string().c_str());
// TODO: Generate new project at mpPath
// Generate new project at mpPath
OpRes result = mProject.GenerateProject(mpPath->filename().string(), mpPath->parent_path());
if (Failed(result))
{
Logger::Log(mLogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description);
}
}
else
{

@ -13,6 +13,8 @@
#include <utils/opRes.h>
#include "panels/iPanel.h"
#include "project/project.h"
#include <filesystem>
#include <map>
@ -50,6 +52,8 @@ namespace lunarium
MainPanel* mpMainPanel;
std::map<PanelType, Panel*> mPanels;
Project mProject;
FileBrowser* mpFileBrowser;
const std::filesystem::path* mpPath;

@ -67,24 +67,6 @@ namespace lunarium
return false;
}
// const ImGuiViewport* vp = ImGui::GetWindowViewport();
// ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
// ImGui::DockSpace(dockspace_id, ImVec2(vp->WorkSize.x, vp->WorkSize.y - ImGui::GetFrameHeight() * 2));
// float status_bar_pos = (vp->WorkSize.y - ImGui::GetFrameHeight() * 2);
// ImGui::SetCursorPosY(status_bar_pos);
// ImGui::Separator();
// if (ImGui::BeginTable("status", 3))
// {
// ImGui::TableNextColumn();
// ImGui::Text("Lunarium");
// ImGui::TableNextColumn();
// ImGui::Text("Testing");
// ImGui::TableNextColumn();
// ImGui::Text("Status Bar");
// ImGui::EndTable();
// }
ImGui::PopStyleVar();
ImGui::End();

@ -0,0 +1,72 @@
/******************************************************************************
* File - project.cpp
* Author - Joey Pollack
* Date - 2021/11/09 (y/m/d)
* Mod Date - 2021/11/09 (y/m/d)
* Description - Manage data for a game project
******************************************************************************/
#include "project.h"
#include <pugixml.hpp>
namespace lunarium
{
Project::Project()
: mIsLoaded(false)
{
}
OpRes Project::GenerateProject(std::string name, std::filesystem::path location)
{
if (mIsLoaded)
{
return OpRes::Fail("A project is already loaded. Unload the current project to generate a new one.");
}
mName = name;
mLocation = location;
mLocation /= mName;
if (std::filesystem::exists(mLocation))
{
return OpRes::Fail("A project with that name (%s) already exists in this location: %s", mName.c_str(), mLocation.string().c_str());
}
std::filesystem::create_directory(mLocation);
std::filesystem::path proj_doc = mLocation;
proj_doc /= std::filesystem::path(mName + ".lproj");
pugi::xml_document doc;
pugi::xml_node proj_node = doc.append_child("Lunarium_Project");
proj_node.append_attribute("name").set_value(mName.c_str());
//pugi::xml_node name_node = proj_node.append_child("Name");
doc.save_file(proj_doc.string().c_str());
std::filesystem::create_directory(mLocation / std::filesystem::path("engine"));
std::filesystem::create_directory(mLocation / std::filesystem::path("contents"));
std::filesystem::create_directory(mLocation / std::filesystem::path("contents/assets"));
mIsLoaded = true;
return OpRes::OK();
}
bool Project::IsLoaded() const
{
return mIsLoaded;
}
OpRes Project::LoadProject(std::filesystem::path location)
{
return OpRes::Fail("Project::LoadProject not implemented yet");
}
void Project::UnloadCurrentProject()
{
mName = "";
mLocation = "";
mIsLoaded = false;
}
}

@ -0,0 +1,40 @@
/******************************************************************************
* File - project.h
* Author - Joey Pollack
* Date - 2021/11/09 (y/m/d)
* Mod Date - 2021/11/09 (y/m/d)
* Description - Manage data for a game project
******************************************************************************/
#ifndef PROJECT_H_
#define PROJECT_H_
#include <utils/opRes.h>
#include <string>
#include <vector>
#include <filesystem>
namespace lunarium
{
class Scene;
class Project
{
public:
Project();
OpRes GenerateProject(std::string name, std::filesystem::path location);
OpRes LoadProject(std::filesystem::path location);
void UnloadCurrentProject();
bool IsLoaded() const;
private:
bool mIsLoaded;
std::string mName;
std::filesystem::path mLocation;
std::vector<Scene*> mScenes;
};
}
#endif // PROJECT_H_
Loading…
Cancel
Save