Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all flags with one value when holding Ctrl/Cmd in the layers editor #39364

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ EditorPropertyFlags::EditorPropertyFlags() {

void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
// Show rename popup for active layer.
if (renamed_layer_index == -1) {
if (renamed_layer_index == INT32_MAX) {
return;
}
String name = names[renamed_layer_index];
Expand Down Expand Up @@ -902,8 +902,8 @@ void EditorPropertyLayersGrid::_update_hovered(const Vector2 &p_position) {
}

// Remove highlight when no square is hovered.
if (hovered_index != -1) {
hovered_index = -1;
if (hovered_index != INT32_MAX) {
hovered_index = INT32_MAX;
queue_redraw();
}
}
Expand All @@ -913,20 +913,32 @@ void EditorPropertyLayersGrid::_on_hover_exit() {
expand_hovered = false;
queue_redraw();
}
if (hovered_index != -1) {
hovered_index = -1;
if (hovered_index != INT32_MAX) {
hovered_index = INT32_MAX;
queue_redraw();
}
}

void EditorPropertyLayersGrid::_update_flag() {
if (hovered_index >= 0) {
void EditorPropertyLayersGrid::_update_flag(bool p_replace) {
if (hovered_index != INT32_MAX) {
// Toggle the flag.
// We base our choice on the hovered flag, so that it always matches the hovered flag.
if (value & (1 << hovered_index)) {
value &= ~(1 << hovered_index);
if (p_replace) {
// Replace all flags with the hovered flag ("solo mode"),
// instead of toggling the hovered flags while preserving other flags' state.
if (value == uint32_t(1 << hovered_index)) {
// If the flag is already enabled, enable all other items and disable the current flag.
// This allows for quicker toggling.
value = INT32_MAX - (1 << hovered_index);
} else {
value = 1 << hovered_index;
}
} else {
value |= (1 << hovered_index);
if (value & (1 << hovered_index)) {
value &= ~(1 << hovered_index);
} else {
value |= (1 << hovered_index);
}
}

emit_signal(SNAME("flag_changed"), value);
Expand All @@ -951,10 +963,10 @@ void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
const Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
_update_hovered(mb->get_position());
_update_flag();
_update_flag(mb->is_command_or_control_pressed());
}
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
if (hovered_index >= 0) {
if (hovered_index != INT32_MAX) {
renamed_layer_index = hovered_index;
layer_rename->set_position(get_screen_position() + mb->get_position());
layer_rename->reset_size();
Expand Down Expand Up @@ -987,7 +999,7 @@ void EditorPropertyLayersGrid::_notification(int p_what) {

const int vofs = (grid_size.height - h) / 2;

int layer_index = 0;
uint32_t layer_index = 0;

Point2 arrow_pos;

Expand Down Expand Up @@ -1242,7 +1254,7 @@ void EditorPropertyLayers::_button_pressed() {
}

void EditorPropertyLayers::_menu_pressed(int p_menu) {
if (p_menu == grid->layer_count) {
if (uint32_t(p_menu) == grid->layer_count) {
ProjectSettingsEditor::get_singleton()->popup_project_settings(true);
ProjectSettingsEditor::get_singleton()->set_general_page(basename);
} else {
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class EditorPropertyLayersGrid : public Control {
bool expand_hovered = false;
bool expanded = false;
int expansion_rows = 0;
int hovered_index = -1;
uint32_t hovered_index = INT32_MAX; // Nothing is hovered.
bool read_only = false;
int renamed_layer_index = -1;
PopupMenu *layer_rename = nullptr;
Expand All @@ -275,7 +275,7 @@ class EditorPropertyLayersGrid : public Control {
void _rename_operation_confirm();
void _update_hovered(const Vector2 &p_position);
void _on_hover_exit();
void _update_flag();
void _update_flag(bool p_replace);
Size2 get_grid_size() const;

protected:
Expand All @@ -285,7 +285,7 @@ class EditorPropertyLayersGrid : public Control {
public:
uint32_t value = 0;
int layer_group_size = 0;
int layer_count = 0;
uint32_t layer_count = 0;
Vector<String> names;
Vector<String> tooltips;

Expand Down