Implementing layer visibility, layer view controls.

This commit is contained in:
2025-06-18 02:26:09 -05:00
parent e4ef5c8f6a
commit 338429980f
8 changed files with 121 additions and 19 deletions

View File

@@ -280,6 +280,8 @@ JUI::Window* EditorApp::CreateTilesetViewerWindow(JUI::Widget* parent)
wind->Size(JUI::UDim2::FromPixels(loaded_tilesheet->GetDimensions().x, loaded_tilesheet->GetDimensions().y+20));
wind->SetResizable(false);
wind->Content()->BGColor(Colors::Black);
auto* img = new Image(wind->Content());
img->Content(loaded_tilesheet);
img->FitImageToParent(false);
@@ -392,6 +394,7 @@ void EditorApp::CreateWidgets()
layer_view = new LayerView(scene);
layer_view->Open();
topbar = new JUI::UtilityBar(scene);
topbar_stats = new JUI::Text(topbar);
@@ -457,6 +460,18 @@ void EditorApp::ToggleGrid()
grid_overlay_enabled = !grid_overlay_enabled;
}
int EditorApp::GetLayerIndexFromName(const std::string& name) {
for (int i = 0; i < loaded_level->layers.size(); ++i) {
if (loaded_level->layers[i]->name == name) {
return i;
}
}
return -1;
}
bool EditorApp::Open()
{
LoadPreferences();
@@ -485,7 +500,17 @@ bool EditorApp::Open()
CreateWidgets();
layer_view->UpdateComponents(loaded_level);
layer_view->ActiveLayerSelected += [this](const std::string& id) mutable {
int layer_index = GetLayerIndexFromName(id);
focus_layer_index = layer_index;
};
layer_view->LayerVisibilityToggled += [this](const std::string& id, bool value) mutable {
std::cout << id << ": " << value << std::endl;
int layer_index = GetLayerIndexFromName(id);
loaded_level->layers[layer_index]->visible = value;
};
for (auto tile : loaded_tileset->tiles) {
std::cout << tile.id << ", " << tile.name << std::endl;
@@ -772,6 +797,8 @@ void EditorApp::DrawTiles()
void EditorApp::DrawLayer(const Layer* layer) const
{
if (!layer->visible) return;
for (int gx = 0; gx < layer->rows; gx++) {
for (int gy = 0; gy < layer->cols; gy++) {
@@ -848,17 +875,7 @@ void EditorApp::Draw()
DrawCellPointerOutline();
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();
int hovered_tile_id = GetTile(cell);
if (hovered_tile_id > -1) {
Tile hovered_tile = loaded_tileset->tiles[hovered_tile_id];
J2D::DrawString(Colors::White, std::format("Hovered Tile: {}", hovered_tile.name), 16, 64, 16);
}
glPopMatrix();
@@ -868,6 +885,19 @@ 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);
Vector2i cell = GetGridCellFromMouse();
int hovered_tile_id = GetTile(cell);
if (hovered_tile_id > -1) {
Tile hovered_tile = loaded_tileset->tiles[hovered_tile_id];
J2D::DrawString(Colors::White, std::format("Hovered Tile: {}", hovered_tile.name), 16, 64, 16);
}
J2D::DrawPoint(Colors::White, bruhbruh, 4);
J2D::End();

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)
Layer::Layer(): rows(0), cols(0), cell_width(0), cell_height(0), parallax_x(0), parallax_y(0), cells(nullptr), visible(true)
{ }
Layer::Layer(int rows, int cols, int cell_width, int cell_height): cells(nullptr), parallax_x(0), parallax_y(0)
@@ -9,6 +9,7 @@ Layer::Layer(int rows, int cols, int cell_width, int cell_height): cells(nullptr
this->cols = cols;
this->cell_width = cell_width;
this->cell_height = cell_height;
this->visible = true;
}
@@ -162,8 +163,13 @@ bool Layer::WriteBinaryData(const std::filesystem::path& path) const
bool Layer::Save()
{ return WriteBinaryData(binary_path); }
bool Layer::Load()
{ return ReadBinaryData(binary_path); }
bool Layer::Load() {
if (!std::filesystem::exists(binary_path)) {
InitGrid();
return true;
}
return ReadBinaryData(binary_path);
}
bool Layer::ReadBinaryData(const std::filesystem::path& path)
{