Skip to content

Commit

Permalink
feat: Preserve map's last edited layer in its metadata for ergonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
piiertho committed Mar 20, 2024
1 parent 4ed5275 commit 746b5c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/editor/commands/revert_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace editor {
public:
void redo() override;
void undo() override;
void set_context_node(TContextNode* p_context_node);
void set_context_node(TContextNode* p_context_node) override;

void set_reverse_command(Ref<Command<TContextNode>> p_reverse_command);

Expand Down
24 changes: 20 additions & 4 deletions src/editor/inspector/layers_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ LayersEditor::LayersEditor() : layer_line_edit(nullptr), layer_controls_containe
layer_controls_container->set_h_size_flags(SizeFlags::SIZE_EXPAND_FILL);
scroll_container->add_child(layer_controls_container);
add_child(scroll_container);

current_layer_button_group = Ref<ButtonGroup>();
current_layer_button_group.instantiate();

refresh();

scroll_container->set_h_size_flags(SizeFlags::SIZE_EXPAND_FILL);
scroll_container->set_v_size_flags(SizeFlags::SIZE_EXPAND_FILL);
set_h_size_flags(SizeFlags::SIZE_EXPAND_FILL);
set_v_size_flags(SizeFlags::SIZE_EXPAND_FILL);

current_layer_button_group = Ref<ButtonGroup>();
current_layer_button_group.instantiate();
}

void LayersEditor::refresh() {
Expand All @@ -61,6 +62,13 @@ void LayersEditor::refresh() {
layer_controls_container->add_child(is_visible_label);
layer_controls_container->add_child(remove_label);

uint32_t last_layer_edited {
current_map->get_meta(
node::IsometricMap::LAST_EDITED_LAYER_META_NAME,
node::IsometricMap::DEFAULT_LAYER_ID
)
};

const Dictionary& layers = current_map->get_layers();
Array ids = layers.keys();
Array layer_names = layers.values();
Expand All @@ -81,6 +89,8 @@ void LayersEditor::refresh() {
layer_remove_button->set_layer_informations(layer_id, layer_name);
layer_remove_button->connect(SNAME("pressed"), Callable(this, "refresh"));
layer_controls_container->add_child(layer_remove_button);

current_layer_check_box->set_pressed(layer_id == last_layer_edited);
}
}
}
Expand Down Expand Up @@ -229,8 +239,14 @@ void CurrentLayerCheckBox::set_layer_id(uint32_t p_layer_id) {
layer_id = p_layer_id;
}

CurrentLayerCheckBox::CurrentLayerCheckBox() : layer_id(node::IsometricMap::NO_LAYER_ID) {
void CurrentLayerCheckBox::on_pressed() {
if (node::IsometricMap* current_map{IsometricEditorPlugin::get_instance()->get_selected_map()}) {
current_map->set_meta(node::IsometricMap::LAST_EDITED_LAYER_META_NAME,layer_id);
}
}

CurrentLayerCheckBox::CurrentLayerCheckBox() : layer_id(node::IsometricMap::NO_LAYER_ID) {
connect(SNAME("pressed"), callable_mp(this, &CurrentLayerCheckBox::on_pressed));
}

void CurrentLayerCheckBox::_bind_methods() {
Expand Down
13 changes: 8 additions & 5 deletions src/editor/inspector/layers_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define ISOMETRIC_MAPS_LAYERS_EDITOR_H

#ifdef TOOLS_ENABLED
#include "scene/gui/box_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/grid_container.h"
#include "node/isometric_map.h"
#include <scene/gui/box_container.h>
#include <scene/gui/button.h>
#include <scene/gui/check_box.h>
#include <scene/gui/grid_container.h>
#include <scene/gui/line_edit.h>

namespace editor {
namespace inspector {
Expand Down Expand Up @@ -73,6 +74,8 @@ namespace editor {
uint32_t get_layer_id() const;
void set_layer_id(uint32_t p_layer_id);

void on_pressed();

CurrentLayerCheckBox();

private:
Expand Down
4 changes: 4 additions & 0 deletions src/node/isometric_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace node {
static constexpr uint32_t DEFAULT_LAYER_ID = 0;
static constexpr uint32_t NO_LAYER_ID = 0xffffffff;

#ifdef TOOLS_ENABLED
static constexpr const char* LAST_EDITED_LAYER_META_NAME = "_LAST_EDITED_LAYER";
#endif

private:
containers::Grid3D<int, resource::PositionableSet::NONE_POSITIONABLE_ID> grid_3d;
containers::Grid3D<uint32_t, DEFAULT_LAYER_ID> layers_grid_3d;
Expand Down

0 comments on commit 746b5c1

Please sign in to comment.