Developing file operation dialogs.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.18..3.27)
|
||||
|
||||
project(Redacted2DLevelLibrary
|
||||
VERSION 1.2
|
||||
project(Redacted2D
|
||||
DESCRIPTION "A C++ Project for "
|
||||
HOMEPAGE_URL https://git.redacted.cc/josh/Editor2D
|
||||
VERSION 1.2.0
|
||||
LANGUAGES CXX)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
@@ -12,16 +14,18 @@ set(CMAKE_BUILD_PARALLEL_LEVEL 8)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
# Enable package managers
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
file(GLOB_RECURSE FORMAT_HEADERS "include/Format/*.hpp")
|
||||
file(GLOB_RECURSE FORMAT_SRC "src/Format/*.cpp" "src/Re2DLevelAPI.cpp")
|
||||
file(GLOB_RECURSE EDITOR_SRC "src/Editor/*.cpp")
|
||||
file(GLOB_RECURSE MISC_SRC "src/SimpleAABBSolver.cpp" "src/Re2DLevelAPI.cpp")
|
||||
|
||||
file(GLOB_RECURSE FORMAT_HEADERS "include/Format/*.hpp" ${MISC_SRC})
|
||||
file(GLOB_RECURSE FORMAT_SRC "src/Format/*.cpp" ${MISC_SRC})
|
||||
file(GLOB_RECURSE EDITOR_SRC "src/Editor/*.cpp" ${MISC_SRC})
|
||||
|
||||
|
||||
file(GLOB_RECURSE DEMOGAME_HEADERS "include/DemoGame/*.hpp")
|
||||
file(GLOB_RECURSE DEMOGAME_SRC "src/DemoGame/*.cpp")
|
||||
@@ -50,7 +54,7 @@ CPMAddPackage(NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-58.zip)
|
||||
|
||||
CPMAddPackage(NAME JUI
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.4.zip)
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.6.zip)
|
||||
|
||||
|
||||
if (UNIX)
|
||||
@@ -104,9 +108,15 @@ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/assets/"
|
||||
add_executable(EditorApp apps/editor.cpp app.rc)
|
||||
target_link_libraries(EditorApp PUBLIC Editor)
|
||||
|
||||
|
||||
add_executable(DemoGame apps/game.cpp)
|
||||
target_link_libraries(DemoGame PUBLIC LevelFormat)
|
||||
add_executable(DemoGame apps/game.cpp ${DEMOGAME_SRC})
|
||||
target_link_libraries(DemoGame PUBLIC LevelFormat jlog ReWindow JGL JUI mcolor)
|
||||
target_include_directories(DemoGame PUBLIC
|
||||
${jlog_SOURCE_DIR}/include
|
||||
${ReWindow_SOURCE_DIR}/include
|
||||
${JGL_SOURCE_DIR}/include
|
||||
${JUI_SOURCE_DIR}/include
|
||||
${mcolor_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_executable(level_format_tests apps/tests.cpp)
|
||||
target_link_libraries(level_format_tests PUBLIC LevelFormat)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <ReWindow/types/Window.h>
|
||||
|
||||
#include "ReWindow/Logger.h"
|
||||
#include <ReWindow/Logger.h>
|
||||
#include <Format/Level.hpp>
|
||||
#include <JGL/JGL.h>
|
||||
#include <JUI/Widgets/FpsGraph.hpp>
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <Editor/LayerView.hpp>
|
||||
#include <Editor/TilesetView.hpp>
|
||||
|
||||
#include "JUI/Widgets/FileDialog.hpp"
|
||||
#include "JUI/Widgets/FpsGraph.hpp"
|
||||
|
||||
#define GL_VER_MAJOR 2
|
||||
@@ -79,6 +80,7 @@ public:
|
||||
//JUI::Window* tileset_viewer = nullptr;
|
||||
JUI::Rect* cell_indicator = nullptr;
|
||||
NewMapDialog* nmd = nullptr;
|
||||
JUI::FileDialogWindow* file_dialog = nullptr;
|
||||
LayerView* layer_view = nullptr;
|
||||
JUI::Window* bg_color_tool_window = nullptr;
|
||||
JUI::ColorPicker* bg_color_tool = nullptr;
|
||||
@@ -105,10 +107,8 @@ public:
|
||||
|
||||
JUI::Window * CreateAppInfoDialogWindow(JUI::Widget *parent);
|
||||
|
||||
Layer* GetLayer(int index)
|
||||
{
|
||||
return loaded_level->layers[index];
|
||||
}
|
||||
Layer* GetLayer(int index) const;
|
||||
|
||||
Layer* GetFocusLayer()
|
||||
{
|
||||
return loaded_level->layers[focus_layer_index];
|
||||
@@ -181,6 +181,8 @@ public:
|
||||
|
||||
void BindConsoleCallbacks();
|
||||
|
||||
void CreateTopbarWidgets();
|
||||
|
||||
/// Create all JUI elements required for this program.
|
||||
void CreateWidgets();
|
||||
|
||||
|
@@ -8,13 +8,35 @@ public:
|
||||
Event<> OnSubmit;
|
||||
|
||||
NewMapDialog() : JUI::Window() {
|
||||
using namespace JUI::UDimLiterals;
|
||||
|
||||
Name("NewMapDialog");
|
||||
|
||||
level_name_field = new JUI::TextInputForm(this->Content());
|
||||
level_name_field->Size({200_px, 20_px});
|
||||
|
||||
description_field = new JUI::TextInputForm(this->Content());
|
||||
description_field->Size({200_px, 20_px});
|
||||
description_field->Position({0_px, 20_px});
|
||||
|
||||
author_field = new JUI::TextInputForm(this->Content());
|
||||
author_field->Size({200_px, 20_px});
|
||||
author_field->Position({0_px, 40_px});
|
||||
}
|
||||
|
||||
explicit NewMapDialog(Widget* parent) : NewMapDialog()
|
||||
{
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void ClearFields() {
|
||||
|
||||
}
|
||||
protected:
|
||||
|
||||
JUI::TextInputForm* level_name_field;
|
||||
JUI::TextInputForm* description_field;
|
||||
JUI::TextInputForm* author_field;
|
||||
|
||||
private:
|
||||
};
|
@@ -22,6 +22,10 @@ public:
|
||||
/// The human-readable name of the level.
|
||||
/// This is typically displayed in level selection menus or editors.
|
||||
std::string name;
|
||||
|
||||
/// A UTC-timestamp of the last time the level file was modified.
|
||||
std::string last_edit_timestamp;
|
||||
|
||||
/// A brief description of the level's content or purpose.
|
||||
/// Useful for level browsers or internal documentation.
|
||||
std::string description;
|
||||
|
@@ -79,6 +79,10 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
return window;
|
||||
}
|
||||
|
||||
Layer * EditorApp::GetLayer(int index) const {
|
||||
return loaded_level->layers[index];
|
||||
}
|
||||
|
||||
Vector2i EditorApp::IndexToCell(int index, int width)
|
||||
{
|
||||
int x = index % width;
|
||||
@@ -208,6 +212,9 @@ void EditorApp::SaveCurrentLevel() const
|
||||
layer->Save();
|
||||
}
|
||||
|
||||
// save current timestamp to level file.
|
||||
loaded_level->last_edit_timestamp = std::format("{:%d-%m-%Y %H:%M:%OS}", std::chrono::system_clock::now());
|
||||
|
||||
auto data = loaded_level->Serialize();
|
||||
|
||||
write_file_contents("level.json", json::deparse(data));
|
||||
@@ -317,7 +324,6 @@ void EditorApp::CreateTestLevel() {
|
||||
data_ready = true;
|
||||
|
||||
SaveCurrentLevel();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +358,6 @@ JUI::Window* EditorApp::CreateTilesetViewerWindow(JUI::Widget* parent)
|
||||
|
||||
auto* grid_overlay_tex = new JGL::Texture(*grid_overlay->GetTexture());
|
||||
|
||||
|
||||
auto* overlay = new JUI::Image(wind->Content());
|
||||
overlay->Content(grid_overlay_tex);
|
||||
overlay->ZIndex(2);
|
||||
@@ -476,6 +481,67 @@ void EditorApp::BindConsoleCallbacks()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void EditorApp::CreateTopbarWidgets() {
|
||||
// Topbar Creation
|
||||
topbar = new JUI::UtilityBar(scene);
|
||||
|
||||
topbar_stats = new JUI::Text(topbar);
|
||||
topbar_stats->HorizontalTextAlign(JUI::TextAlign::H::Right);
|
||||
topbar_stats->TextColor(Colors::Black);
|
||||
|
||||
auto* file = topbar->AddSubmenu("File");
|
||||
file->Font(JGL::Fonts::Jupiteroid);
|
||||
|
||||
auto* new_map = file->AddButton("New Map", [this] () mutable {
|
||||
nmd->Open();
|
||||
});
|
||||
|
||||
file->AddButton("Open", [this]() mutable {
|
||||
|
||||
if (file_dialog) {
|
||||
//file_dialog->Close();
|
||||
//file_dialog->Parent(nullptr);
|
||||
//delete file_dialog;
|
||||
}
|
||||
|
||||
|
||||
file_dialog = new JUI::FileDialogWindow(scene, ".");
|
||||
});
|
||||
file->AddButton("Save", [this]{SaveCurrentLevel();});
|
||||
file->AddButton("Save As");
|
||||
file->AddSeparator(2_px);
|
||||
file->AddButton("About", [this]{app_info_dialog->Toggle(); });
|
||||
file->AddButton("Preferences");
|
||||
|
||||
auto* edit = topbar->AddSubmenu("Edit");
|
||||
edit->AddButton("Undo");
|
||||
edit->AddButton("Redo");
|
||||
edit->AddButton("Copy");
|
||||
edit->AddSeparator(2_px);
|
||||
edit->AddButton("Paste");
|
||||
edit->AddButton("Cut Selection");
|
||||
|
||||
auto* view = topbar->AddSubmenu("View");
|
||||
view->AddButton("Zoom In");
|
||||
view->AddButton("Zoom Out");
|
||||
view->AddSeparator(2_px);
|
||||
view->AddButton("Toggle Grid", [this]{ToggleGrid();});
|
||||
view->AddButton("Set Background Color", [this]{bg_color_tool_window->Toggle();});
|
||||
view->AddSeparator(2_px);
|
||||
view->AddButton("Console", [this]()mutable { console->Toggle();});
|
||||
view->AddButton("Tileset Viewer", [this]()mutable { tileset_view->Toggle();});
|
||||
|
||||
auto* level = topbar->AddSubmenu("Level");
|
||||
auto* layer = topbar->AddSubmenu("Layer");
|
||||
layer->AddButton("New");
|
||||
layer->AddButton("Open from File");
|
||||
layer->AddButton("Duplicate Selected");
|
||||
layer->AddButton("Delete Selected");
|
||||
layer->AddButton("Edit Selected");
|
||||
layer->AddButton("Export Layer");
|
||||
}
|
||||
|
||||
void EditorApp::CreateWidgets()
|
||||
{
|
||||
scene = new JUI::Scene();
|
||||
@@ -510,55 +576,7 @@ void EditorApp::CreateWidgets()
|
||||
layer_view = new LayerView(scene);
|
||||
layer_view->Close();
|
||||
|
||||
|
||||
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->Font(JGL::Fonts::Jupiteroid);
|
||||
|
||||
|
||||
auto* new_map = file->AddButton("New Map", [this] () mutable {
|
||||
nmd->Open();
|
||||
});
|
||||
|
||||
file->AddButton("Open");
|
||||
file->AddButton("Save", [this]{SaveCurrentLevel();});
|
||||
file->AddButton("Save As");
|
||||
file->AddSeparator(2_px);
|
||||
file->AddButton("About", [this]{app_info_dialog->Toggle(); });
|
||||
file->AddButton("Preferences");
|
||||
|
||||
auto* edit = topbar->AddSubmenu("Edit");
|
||||
edit->AddButton("Undo");
|
||||
edit->AddButton("Redo");
|
||||
edit->AddButton("Copy");
|
||||
edit->AddSeparator(2_px);
|
||||
edit->AddButton("Paste");
|
||||
edit->AddButton("Cut Selection");
|
||||
|
||||
auto* view = topbar->AddSubmenu("View");
|
||||
view->AddButton("Zoom In");
|
||||
view->AddButton("Zoom Out");
|
||||
view->AddSeparator(2_px);
|
||||
view->AddButton("Toggle Grid", [this]{ToggleGrid();});
|
||||
view->AddButton("Set Background Color", [this]{bg_color_tool_window->Toggle();});
|
||||
view->AddSeparator(2_px);
|
||||
view->AddButton("Console", [this]()mutable { console->Toggle();});
|
||||
view->AddButton("Tileset Viewer", [this]()mutable { tileset_view->Toggle();});
|
||||
|
||||
auto* level = topbar->AddSubmenu("Level");
|
||||
auto* layer = topbar->AddSubmenu("Layer");
|
||||
layer->AddButton("New");
|
||||
layer->AddButton("Open from File");
|
||||
layer->AddButton("Duplicate Selected");
|
||||
layer->AddButton("Delete Selected");
|
||||
layer->AddButton("Edit Selected");
|
||||
layer->AddButton("Export Layer");
|
||||
CreateTopbarWidgets();
|
||||
|
||||
|
||||
bg_color_tool_window = new JUI::Window(scene);
|
||||
@@ -1057,8 +1075,12 @@ void EditorApp::OnKeyDown(const KeyDownEvent& e)
|
||||
|
||||
void EditorApp::OnKeyUp(const KeyUpEvent& e)
|
||||
{
|
||||
|
||||
|
||||
if (scene->ObserveKeyInput(e.key, false)) return;
|
||||
|
||||
if (e.key == Keys::T)
|
||||
if (e.key == Keys::T && tileset_view) {
|
||||
tileset_view->Toggle();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ Layer::Layer(int rows, int cols, int cell_width, int cell_height): cells(nullptr
|
||||
this->cell_width = cell_width;
|
||||
this->cell_height = cell_height;
|
||||
this->visible = true;
|
||||
|
||||
}
|
||||
|
||||
Layer::Layer(const json::value& json)
|
||||
|
Reference in New Issue
Block a user