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

@@ -31,6 +31,48 @@
"collides": false,
"name":"Gate_Right",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":777,
"collides": false,
"name":"Traffic_Cone",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":838,
"collides": false,
"name":"SecurityCamera_South",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":838,
"collides": false,
"name":"SecurityCamera_SouthWest",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":710,
"collides": false,
"name":"Truss1",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":714,
"collides": false,
"name":"Truss2",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":798,
"collides": false,
"name":"GrassA",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
},
{
"id":799,
"collides": false,
"name":"GrassB",
"quad":[0.000000, 0.000000, 16.000000, 16.000000]
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

View File

@@ -176,6 +176,8 @@ public:
/// Toggles the level grid.
void ToggleGrid();
int GetLayerIndexFromName(const std::string &name);
bool Open() override;
Vector2i GetTilesetCellFromMouse();

View File

@@ -8,17 +8,22 @@
#include <Data/Level.hpp>
using namespace JUI::UDimLiterals;
class LayerView : public JUI::Window
{
public:
Event<std::string, bool> LayerVisibilityToggled;
Event<std::string> ActiveLayerSelected;
LayerView() : JUI::Window()
{
this->Title("Layers");
Name("LayerView");
scroller = new JUI::ScrollingRect(this->Content());
scroller->Size({100_percent, 100_percent});
layout = new JUI::VerticalListLayout(scroller);
layout = new JUI::VerticalListLayout(this->Content());
}
explicit LayerView(Widget* parent) : LayerView()
@@ -37,12 +42,30 @@ public:
for (auto layer : level->layers)
{
auto* rect = new JUI::Rect(layout);
auto* label = new JUI::Text(rect);
label->Content(layer->name);
rect->Size({100_percent, 20_px});
auto* vis_chk = new JUI::Checkbox(rect);
vis_chk->Size({20_px, 20_px});
auto* label = new JUI::TextButton(rect);
label->Name("Label");
label->Position({20_px, 0_px});
label->Size({100_percent-20_px, 20_px});
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);
};
entry_elements.push_back(rect);
}
}

View File

@@ -47,7 +47,8 @@ public:
/// The vertical parallax scrolling factor for this layer.
float parallax_y;
bool visible;
bool visible = true;
int order;
float opacity;
@@ -125,5 +126,4 @@ public:
protected:
bool grid_allocated = false;
};

View File

@@ -60,7 +60,6 @@ namespace TestGame
JUI::Scene* scene = nullptr;
Player* player = nullptr;
bool data_ready = false;

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,6 +875,16 @@ void EditorApp::Draw()
DrawCellPointerOutline();
glPopMatrix();
auto maus = GetMouseCoordinates();
Vector2 mouse_v2(maus.x, maus.y);
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);
@@ -860,13 +897,6 @@ void EditorApp::Draw()
J2D::DrawString(Colors::White, std::format("Hovered Tile: {}", hovered_tile.name), 16, 64, 16);
}
glPopMatrix();
auto maus = GetMouseCoordinates();
Vector2 mouse_v2(maus.x, maus.y);
auto bruhbruh = camera.CameraToScreenSpace(camera.ScreenToCameraSpace(mouse_v2));
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)
{