Test integration of FPSGraph
This commit is contained in:
@@ -23,7 +23,7 @@ file(GLOB_RECURSE EDITOR_SRC "src/*.cpp")
|
||||
include_directories("include")
|
||||
|
||||
CPMAddPackage(NAME mcolor
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-7.3.zip)
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Prerelease-7.4.zip)
|
||||
|
||||
CPMAddPackage(NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-18.zip)
|
||||
@@ -45,7 +45,7 @@ CPMAddPackage(NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-55.zip)
|
||||
|
||||
CPMAddPackage(NAME JUI
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.zip)
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.1.zip)
|
||||
|
||||
|
||||
if (UNIX)
|
||||
|
@@ -82,6 +82,7 @@ public:
|
||||
JUI::UtilityBar* topbar = nullptr;
|
||||
|
||||
JUI::Window* app_info_dialog = nullptr;
|
||||
JUI::Text* topbar_stats = nullptr;
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Map Data
|
||||
@@ -157,8 +158,48 @@ public:
|
||||
|
||||
/// Saves the current editor's data to test.lvl.
|
||||
/// @note Placeholder until FileDialogs are added.
|
||||
void SaveTestFile();
|
||||
void SaveCurrentLevel() const;
|
||||
void LoadLevel(const std::filesystem::path& level_meta_path);
|
||||
void CreateTestLevel() {
|
||||
loaded_level = new Level();
|
||||
loaded_level->name = "TestLevel";
|
||||
loaded_level->author = "dawsh";
|
||||
loaded_level->cols = 64;
|
||||
loaded_level->rows = 64;
|
||||
loaded_level->tileset_path = "tileset.json";
|
||||
auto layer = new Layer();
|
||||
layer->name = "Layer 1";
|
||||
layer->cols = 64;
|
||||
layer->rows = 64;
|
||||
layer->cell_height = 16;
|
||||
layer->cell_width = 16;
|
||||
layer->binary_path = "layers/1.bin";
|
||||
layer->InitGrid();
|
||||
layer->Save();
|
||||
loaded_level->layers.push_back(layer);
|
||||
loaded_tileset = new Tileset();
|
||||
loaded_tileset->name = "MegaCommando";
|
||||
loaded_tileset->author = "dawsh";
|
||||
loaded_tileset->tex_height = 1280;
|
||||
loaded_tileset->tex_width = 1024;
|
||||
loaded_tileset->tile_width = 16;
|
||||
loaded_tileset->tile_height = 16;
|
||||
loaded_tileset->tile_spacing = 0;
|
||||
loaded_tileset->cols = 80;
|
||||
loaded_tileset->rows = 60;
|
||||
loaded_tileset->file_path = "tileset.json";
|
||||
loaded_tileset->texture_path = "../megacommando.png";
|
||||
loaded_tilesheet = new JGL::Texture("../megacommando.png");
|
||||
|
||||
write_file_contents("tileset.json", json::deparse(loaded_tileset->Serialize()));
|
||||
|
||||
//layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
data_ready = true;
|
||||
|
||||
SaveCurrentLevel();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SizeCellIndicatorToTilesetSize();
|
||||
|
@@ -13,7 +13,7 @@ class LayerView : public JUI::Window
|
||||
public:
|
||||
LayerView() : JUI::Window()
|
||||
{
|
||||
this->SetTitle("Layers");
|
||||
this->Title("Layers");
|
||||
Name("LayerView");
|
||||
|
||||
scroller = new JUI::ScrollingRect(this->Content());
|
||||
@@ -25,15 +25,28 @@ public:
|
||||
{
|
||||
Parent(parent);
|
||||
}
|
||||
void UpdateComponents(Level* level)
|
||||
void UpdateComponents(const Level* level)
|
||||
{
|
||||
|
||||
for (auto entry : entry_elements) {
|
||||
entry->Parent(nullptr);
|
||||
delete entry;
|
||||
}
|
||||
entry_elements.clear();
|
||||
|
||||
for (auto layer : level->layers)
|
||||
{
|
||||
//auto* rect = new JUI::Rect(layout);
|
||||
//auto* vis_chk = new JUI::Checkbox(rect);
|
||||
auto* rect = new JUI::Rect(layout);
|
||||
auto* label = new JUI::Text(rect);
|
||||
label->Content(layer->name);
|
||||
auto* vis_chk = new JUI::Checkbox(rect);
|
||||
|
||||
|
||||
entry_elements.push_back(rect);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Widget*> entry_elements;
|
||||
JUI::ScrollingRect* scroller = nullptr;
|
||||
JUI::VerticalListLayout* layout = nullptr;
|
||||
};
|
@@ -5,12 +5,14 @@
|
||||
|
||||
#include <Data/Format.hpp>
|
||||
|
||||
#include "JUI/Widgets/FpsGraph.hpp"
|
||||
|
||||
|
||||
JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
{
|
||||
// TODO: Implement JUI structure that makes blocks of text easy to impelement.
|
||||
auto window = new JUI::Window(parent);
|
||||
window->SetTitle("About Editor2D");
|
||||
window->Title("About Editor2D");
|
||||
window->Size({350_px, 375_px});
|
||||
window->MinSize({350, 375});
|
||||
|
||||
@@ -21,9 +23,9 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
auto line_item = [&] (const std::string& text, int size = 20, const Color4& color = Colors::White) {
|
||||
auto* content = new JUI::TextRect(layout);
|
||||
content->Size({100_percent, JUI::UDim(size+5, 0)});
|
||||
content->SetContent(text);
|
||||
content->SetTextSize(size);
|
||||
content->SetTextColor(color);
|
||||
content->Content(text);
|
||||
content->TextSize(size);
|
||||
content->TextColor(color);
|
||||
content->BGColor(Colors::Transparent);
|
||||
content->AlignCenterHorizontally();
|
||||
content->BorderWidth(0);
|
||||
@@ -59,10 +61,10 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
btn_layout->Padding(8_px);
|
||||
|
||||
auto btn_item = [&] (const std::string& text) -> JUI::TextButton* {
|
||||
JUI::TextButton* btn = new JUI::TextButton(btn_layout);
|
||||
btn->SetContent(text);
|
||||
auto* btn = new JUI::TextButton(btn_layout);
|
||||
btn->Content(text);
|
||||
btn->Size({32_percent, 100_percent});
|
||||
btn->SetTextColor(Colors::Black);
|
||||
btn->TextColor(Colors::Black);
|
||||
btn->Center();
|
||||
return btn;
|
||||
};
|
||||
@@ -188,10 +190,13 @@ void EditorApp::SavePreferences()
|
||||
|
||||
void EditorApp::LoadTestFile()
|
||||
{
|
||||
LoadLevel("level.json");
|
||||
if (std::filesystem::exists("level.json"))
|
||||
LoadLevel("level.json");
|
||||
else
|
||||
CreateTestLevel();
|
||||
}
|
||||
|
||||
void EditorApp::SaveTestFile()
|
||||
void EditorApp::SaveCurrentLevel() const
|
||||
{
|
||||
|
||||
for (auto layer : loaded_level->layers)
|
||||
@@ -207,6 +212,7 @@ void EditorApp::SaveTestFile()
|
||||
|
||||
void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
|
||||
{
|
||||
|
||||
loaded_level = new Level(level_meta_path);
|
||||
|
||||
loaded_tileset = new Tileset(std::filesystem::path(loaded_level->tileset_path));
|
||||
@@ -216,7 +222,7 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
|
||||
for (auto layer : loaded_level->layers)
|
||||
layer->Load();
|
||||
|
||||
layer_view->UpdateComponents(loaded_level);
|
||||
//layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
data_ready = true;
|
||||
}
|
||||
@@ -233,7 +239,7 @@ JUI::Window* EditorApp::CreateTilesetViewerWindow(JUI::Widget* parent)
|
||||
using namespace JUI;
|
||||
|
||||
auto* wind = new Window(parent);
|
||||
wind->SetTitle("Tileset Viewer");
|
||||
wind->Title("Tileset Viewer");
|
||||
wind->Size(JUI::UDim2::FromPixels(loaded_tilesheet->GetDimensions().x, loaded_tilesheet->GetDimensions().y+20));
|
||||
wind->SetResizable(false);
|
||||
|
||||
@@ -330,6 +336,10 @@ void EditorApp::CreateWidgets()
|
||||
|
||||
app_info_dialog = CreateAppInfoDialogWindow(scene);
|
||||
|
||||
auto* fpsgraphwindow = new JUI::Window(scene);
|
||||
auto* fpsgraph = new JUI::FpsGraph(scene);
|
||||
|
||||
|
||||
console = new JUI::CommandLine(scene);
|
||||
console->Close();
|
||||
BindConsoleCallbacks();
|
||||
@@ -342,8 +352,13 @@ void EditorApp::CreateWidgets()
|
||||
|
||||
topbar = new JUI::UtilityBar(scene);
|
||||
|
||||
topbar_stats = new JUI::Text(topbar);
|
||||
topbar_stats->HorizontalTextAlign(JUI::TextAlign::H::Left);
|
||||
topbar_stats->TextColor(Colors::Black);
|
||||
|
||||
|
||||
auto* file = topbar->AddSubmenu("File");
|
||||
file->SetFont(JGL::Fonts::Jupiteroid);
|
||||
file->Font(JGL::Fonts::Jupiteroid);
|
||||
|
||||
|
||||
auto* new_map = file->AddButton("New Map", [this] () mutable {
|
||||
@@ -351,7 +366,7 @@ void EditorApp::CreateWidgets()
|
||||
});
|
||||
|
||||
file->AddButton("Open");
|
||||
file->AddButton("Save", [this]{SaveTestFile();});
|
||||
file->AddButton("Save", [this]{SaveCurrentLevel();});
|
||||
file->AddButton("Save As");
|
||||
file->AddSeparator(2_px);
|
||||
file->AddButton("About", [this]{app_info_dialog->Toggle(); });
|
||||
@@ -427,7 +442,7 @@ bool EditorApp::Open()
|
||||
LoadTestFile();
|
||||
CreateWidgets();
|
||||
|
||||
|
||||
layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -793,7 +808,7 @@ void EditorApp::Draw()
|
||||
void EditorApp::OnClosing()
|
||||
{
|
||||
SavePreferences();
|
||||
SaveTestFile();
|
||||
SaveCurrentLevel();
|
||||
}
|
||||
|
||||
void EditorApp::OnRefresh(float elapsed)
|
||||
|
@@ -7,7 +7,21 @@ Level::Level(): rows(0), cols(0)
|
||||
|
||||
Level::Level(const std::filesystem::path& path)
|
||||
{
|
||||
if (path.empty())
|
||||
throw std::runtime_error(std::format("Level::Level({}: blank file path provided!", path.string()));;
|
||||
if (!std::filesystem::exists(path))
|
||||
throw std::runtime_error(std::format("Level::Level({}): file does not exist!", path.string()));
|
||||
|
||||
std::string file_contents = read_file_contents(path);
|
||||
|
||||
if (file_contents.empty())
|
||||
throw std::runtime_error(std::format("Level::Level({}): file contents are empty!", path.string()));
|
||||
|
||||
auto [json, err] = json::parse(read_file_contents(path));
|
||||
|
||||
if (err != "")
|
||||
throw std::runtime_error(std::format("Level::Level({}): file contains invalid JSON: {}", path.string(), err));
|
||||
|
||||
Deserialize(json);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user