-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add layers to IsometricMap and basic features linked (set visib…
…ility, add/remove)
- Loading branch information
Showing
22 changed files
with
740 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifdef TOOLS_ENABLED | ||
|
||
#include "add_layer_command.h" | ||
#include "node/isometric_map.h" | ||
#include "editor/isometric_editor_plugin.h" | ||
|
||
using namespace editor::commands; | ||
|
||
void AddLayerCommand::redo() { | ||
IsometricEditorPlugin::get_instance()->get_selected_map()->add_layer(layer_name, layer_id); | ||
} | ||
|
||
void AddLayerCommand::undo() { | ||
if (layer_id == node::IsometricMap::NO_LAYER_ID) { | ||
IsometricEditorPlugin::get_instance()->get_selected_map()->remove_layer(layer_name); | ||
return; | ||
} | ||
IsometricEditorPlugin::get_instance()->get_selected_map()->remove_layer(layer_id); | ||
} | ||
|
||
void AddLayerCommand::set_layer_id(uint32_t p_layer_id) { | ||
layer_id = p_layer_id; | ||
} | ||
|
||
void AddLayerCommand::set_layer_name(const String& p_layer_name) { | ||
layer_name = p_layer_name; | ||
} | ||
|
||
AddLayerCommand::AddLayerCommand() : layer_id(node::IsometricMap::NO_LAYER_ID) { | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef ISOMETRIC_MAPS_ADD_LAYER_COMMAND_H | ||
#define ISOMETRIC_MAPS_ADD_LAYER_COMMAND_H | ||
|
||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include "command.h" | ||
|
||
namespace editor { | ||
namespace commands { | ||
class AddLayerCommand : public Command { | ||
public: | ||
void redo() override; | ||
void undo() override; | ||
|
||
void set_layer_id(uint32_t p_layer_id); | ||
void set_layer_name(const String& p_layer_name); | ||
|
||
AddLayerCommand(); | ||
~AddLayerCommand() override = default; | ||
|
||
private: | ||
uint32_t layer_id; | ||
String layer_name; | ||
}; | ||
} | ||
} | ||
#endif | ||
|
||
|
||
#endif //ISOMETRIC_MAPS_ADD_LAYER_COMMAND_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/editor/commands/emitters/command_to_action_transformer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef ISOMETRIC_MAPS_COMMAND_TO_ACTION_TRANSFORMER_H | ||
#define ISOMETRIC_MAPS_COMMAND_TO_ACTION_TRANSFORMER_H | ||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include <core/templates/vector.h> | ||
#include <core/object/ref_counted.h> | ||
#include <editor/commands/command.h> | ||
#include <scene/main/node.h> | ||
|
||
namespace editor { | ||
namespace commands { | ||
namespace emitters { | ||
class CommandToActionTransformer { | ||
public: | ||
template<const char* action_title, UndoRedo::MergeMode merge_mode = UndoRedo::MERGE_DISABLE> | ||
void transform(const Vector<Ref<Command>> commands, Node* p_context); | ||
|
||
CommandToActionTransformer() = default; | ||
~CommandToActionTransformer() = default; | ||
}; | ||
|
||
template<const char* action_title, UndoRedo::MergeMode merge_mode> | ||
void CommandToActionTransformer::transform(const Vector<Ref<Command>> commands, Node* p_context) { | ||
bool has_valid_command {false}; | ||
for (int i = 0; i < commands.size(); ++i) { | ||
Ref<Command> command {commands[i]}; | ||
if (command.is_null()) { continue; } | ||
if (!has_valid_command) { | ||
EditorUndoRedoManager::get_singleton()->create_action(action_title, merge_mode, p_context); | ||
has_valid_command = true; | ||
} | ||
command->append_to_undoredo(); | ||
} | ||
|
||
if (has_valid_command) { EditorUndoRedoManager::get_singleton()->commit_action(); } | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif | ||
|
||
|
||
#endif //ISOMETRIC_MAPS_COMMAND_TO_ACTION_TRANSFORMER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifdef TOOLS_ENABLED | ||
|
||
#include "set_layer_visibility_command.h" | ||
#include <editor/isometric_editor_plugin.h> | ||
|
||
using namespace editor::commands; | ||
|
||
void SetLayerVisibilityCommand::redo() { | ||
IsometricEditorPlugin::get_instance()->get_selected_map()->set_layer_visible(layer_id, is_visible); | ||
} | ||
|
||
void SetLayerVisibilityCommand::undo() { | ||
IsometricEditorPlugin::get_instance()->get_selected_map()->set_layer_visible(layer_id, !is_visible); | ||
} | ||
|
||
void SetLayerVisibilityCommand::set_layer_id(uint32_t p_layer_id) { | ||
layer_id = p_layer_id; | ||
} | ||
|
||
void SetLayerVisibilityCommand::set_visible(bool p_is_visible) { | ||
is_visible = p_is_visible; | ||
} | ||
|
||
SetLayerVisibilityCommand::SetLayerVisibilityCommand() : layer_id(node::IsometricMap::DEFAULT_LAYER_ID), is_visible() { | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ISOMETRIC_MAPS_SET_LAYER_VISIBILITY_COMMAND_H | ||
#define ISOMETRIC_MAPS_SET_LAYER_VISIBILITY_COMMAND_H | ||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include "command.h" | ||
|
||
namespace editor { | ||
namespace commands { | ||
class SetLayerVisibilityCommand : public Command { | ||
public: | ||
void redo() override; | ||
void undo() override; | ||
|
||
void set_layer_id(uint32_t p_layer_id); | ||
void set_visible(bool p_is_visible); | ||
|
||
SetLayerVisibilityCommand(); | ||
~SetLayerVisibilityCommand() override = default; | ||
|
||
private: | ||
uint32_t layer_id; | ||
bool is_visible; | ||
}; | ||
} | ||
} | ||
|
||
#endif | ||
|
||
#endif //ISOMETRIC_MAPS_SET_LAYER_VISIBILITY_COMMAND_H |
Oops, something went wrong.