More Organization

This commit is contained in:
2025-06-21 14:48:32 -05:00
parent abb1ba35c3
commit 80ce2c6160
11 changed files with 168 additions and 94 deletions

View File

@@ -236,7 +236,6 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
for (auto layer : loaded_level->layers)
layer->Load();
tileset_view = new TilesetView(loaded_tileset, loaded_tilesheet, scene);
tileset_view->TileSelected += [this](int id) mutable {
@@ -244,6 +243,7 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
};
layer_view->UpdateComponents(loaded_level);
layer_view->Open();
data_ready = true;
}
@@ -392,8 +392,6 @@ std::string tolower(const std::string& s) {
void EditorApp::BindConsoleCallbacks()
{
// TODO: This parsing pattern is duplicated between at least 2 other projects at this point.
// TODO: Move up into JUI or a separate package.
console->OnInput += [this] (const std::string& input)
@@ -451,6 +449,15 @@ void EditorApp::CreateWidgets()
{
scene = new JUI::Scene();
/*auto* blank_text = new JUI::TextRect(scene);
blank_text->Content("Open or create a new level file to get started!");
blank_text->Center();
blank_text->AutoFitSizeToText(true);
blank_text->Position({20_px, 20_px});*/
app_info_dialog = CreateAppInfoDialogWindow(scene);
fps_graph = new JUI::FpsGraph(scene);
@@ -467,10 +474,10 @@ void EditorApp::CreateWidgets()
BindConsoleCallbacks();
nmd = new NewMapDialog(scene);
nmd->Close();
nmd->Open();
layer_view = new LayerView(scene);
layer_view->Open();
layer_view->Close();
topbar = new JUI::UtilityBar(scene);
@@ -927,8 +934,11 @@ void EditorApp::Draw()
auto bruhbruh = camera.CameraToScreenSpace(camera.ScreenToCameraSpace(mouse_v2));
Tile selected_tile = loaded_tileset->tiles[selected_quad];
J2D::DrawString(Colors::White, std::format("Selected Tile: {}", selected_tile.name), 16, 48, 16);
if (selected_quad > -1){
Tile selected_tile = loaded_tileset->tiles[selected_quad];
J2D::DrawString(Colors::White, std::format("Selected Tile: {}", selected_tile.name), 16, 48, 16);
}
Vector2i cell = GetGridCellFromMouse();

104
src/App/LayerView.cpp Normal file
View File

@@ -0,0 +1,104 @@
#include <App/LayerView.hpp>
LayerView::LayerView(): JUI::Window() {
this->Title("Layers");
Name("LayerView");
scroller = new JUI::ScrollingRect(this->Content());
scroller->Size({100_percent, 100_percent});
layout = new JUI::VerticalListLayout(this->Content());
layout->LayoutOrder(JUI::LayoutOrder::V::TOP);
}
LayerView::LayerView(Widget *parent): LayerView() {
Parent(parent);
}
void LayerView::ClearComponents() {
for (auto entry : entry_elements) {
entry->Parent(nullptr);
delete entry;
}
entry_elements.clear();
}
void LayerView::UpdateComponents(const Level *level) {
stored_level_data = level;
ClearComponents();
for (auto layer : level->layers)
{
bool is_bottom_layer_in_stack = false;
bool is_top_layer_in_stack = false;
if (layer->order == 0) is_top_layer_in_stack = true;
if (layer->order == level->layers.size()-1) is_bottom_layer_in_stack = true;
auto* rect = new JUI::Rect(layout);
rect->LayoutOrder(layer->order);
rect->Size({100_percent, JUI::UDim(layer_entry_height, 0)});
auto* vis_chk = new JUI::Checkbox(rect);
vis_chk->Size({JUI::UDim(layer_entry_height, 0), JUI::UDim(layer_entry_height, 0)});
auto* label = new JUI::TextButton(rect);
label->Name("Label");
label->Position({JUI::UDim(layer_entry_height, 0), 0_px});
label->Size({100_percent-JUI::UDim(layer_entry_height*2, 0), JUI::UDim(layer_entry_height, 0)});
label->Content(layer->name);
label->TextColor(Colors::Black);
label->OnReleaseEvent += [this, label, layer] (auto a, auto b, auto c) mutable {
ActiveLayerSelected.Invoke(layer->name);
label->BaseBGColor(Colors::Gray);
};
vis_chk->OnReleaseEvent += [this, layer](auto a, auto b, auto c) mutable {
LayerVisibilityToggled.Invoke(layer->name, !layer->visible);
};
auto* layer_order_shift_box = new JUI::Rect(rect);
layer_order_shift_box->Size({JUI::UDim(layer_entry_height, 0), JUI::UDim(layer_entry_height, 0)});
layer_order_shift_box->Position({100_percent-JUI::UDim(layer_entry_height, 0), 0_px});
auto layer_up = new JUI::TextButton(layer_order_shift_box);
layer_up->Size({100_percent, 50_percent});
layer_up->TextColor(Colors::Black);
layer_up->Content("/\\");
layer_up->Center();
layer_up->OnReleaseEvent += [this, layer] (auto a, auto b, auto c) mutable {
if (layer->order > 0)
layer->order--;
};
if (is_top_layer_in_stack)
layer_up->Disable();
auto* layer_down = new JUI::TextButton(layer_order_shift_box);
layer_down->Size({100_percent, 50_percent});
layer_down->Content("\\/");
layer_down->TextColor(Colors::Black);
layer_down->Position({0_percent, 50_percent});
layer_down->Center();
layer_down->OnReleaseEvent += [this, level, layer] (auto a, auto b, auto c) mutable {
const int layer_count = level->layers.size();
if (layer->order <= layer_count)
layer->order++;
};
if (is_bottom_layer_in_stack)
layer_down->Disable();
entry_elements.push_back(rect);
}
}

View File

@@ -1,6 +1,6 @@
#include <Data/Layer.hpp>
Layer::Layer(): rows(0), cols(0), cell_width(0), cell_height(0), parallax_x(0), parallax_y(0), cells(nullptr), visible(true)
Layer::Layer(): rows(0), cols(0), cell_width(0), cell_height(0), parallax_x(0), parallax_y(0), cells(nullptr), visible(true), order(0)
{ }
Layer::Layer(int rows, int cols, int cell_width, int cell_height): cells(nullptr), parallax_x(0), parallax_y(0)
@@ -38,7 +38,7 @@ json::value Layer::Serialize() const
data["cols"] = (float)cols;
data["cell-width"] = (float)cell_width;
data["cell-height"] = (float)cell_height;
data["order"] = (float)order;
return data;
}
@@ -51,7 +51,7 @@ void Layer::Deserialize(const json::value& json)
cols = json["cols"].number.value();
cell_width = json["cell-width"].number.value();
cell_height = json["cell-height"].number.value();
order = json["order"].number.value_or(0);
}
void Layer::InitGrid()