|
|
|
@@ -16,90 +16,27 @@ public:
|
|
|
|
|
float layer_entry_height = 30;
|
|
|
|
|
Event<std::string, bool> LayerVisibilityToggled;
|
|
|
|
|
Event<std::string> ActiveLayerSelected;
|
|
|
|
|
LayerView() : JUI::Window()
|
|
|
|
|
{
|
|
|
|
|
this->Title("Layers");
|
|
|
|
|
Name("LayerView");
|
|
|
|
|
Event<std::string> MoveLayerUp;
|
|
|
|
|
Event<std::string> MoveLayerDown;
|
|
|
|
|
|
|
|
|
|
scroller = new JUI::ScrollingRect(this->Content());
|
|
|
|
|
scroller->Size({100_percent, 100_percent});
|
|
|
|
|
/// Constructs a new LayerView by assigning it to a child of the given `parent` Widget.
|
|
|
|
|
explicit LayerView(Widget* parent);
|
|
|
|
|
|
|
|
|
|
layout = new JUI::VerticalListLayout(this->Content());
|
|
|
|
|
/// The base constructor initializes the core elements that are persistent in the layer view.
|
|
|
|
|
/// This constructor is to be called in a chain from the other constructors.
|
|
|
|
|
LayerView();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
explicit LayerView(Widget* parent) : LayerView()
|
|
|
|
|
{
|
|
|
|
|
Parent(parent);
|
|
|
|
|
}
|
|
|
|
|
void UpdateComponents(const Level* level)
|
|
|
|
|
{
|
|
|
|
|
for (auto entry : entry_elements) {
|
|
|
|
|
entry->Parent(nullptr);
|
|
|
|
|
delete entry;
|
|
|
|
|
}
|
|
|
|
|
///
|
|
|
|
|
void UpdateComponents(const Level* level);
|
|
|
|
|
|
|
|
|
|
entry_elements.clear();
|
|
|
|
|
void ClearComponents();
|
|
|
|
|
|
|
|
|
|
for (auto layer : level->layers)
|
|
|
|
|
{
|
|
|
|
|
auto* rect = new JUI::Rect(layout);
|
|
|
|
|
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});
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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--;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entry_elements.push_back(rect);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The transient components that will be re-generated when UpdateComponents is called.
|
|
|
|
|
std::vector<Widget*> entry_elements;
|
|
|
|
|
JUI::ScrollingRect* scroller = nullptr;
|
|
|
|
|
JUI::VerticalListLayout* layout = nullptr;
|
|
|
|
|
const Level* stored_level_data;
|
|
|
|
|
};
|