Skip to content
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ add_executable(Prune
src/prune/tooling/inspector.cpp
src/prune/tooling/command_history.cpp
src/prune/tooling/sprite_picker.cpp
src/prune/tooling/editor/tracked_property_table.cpp
src/prune/tooling/controls.cpp
src/prune/tooling/options.cpp
src/prune/tooling/stats.cpp
Expand Down
30 changes: 20 additions & 10 deletions src/prune/editor/editor_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,50 +110,60 @@ namespace prune {

EditorCommand make_object_command(
EditorCommandType type,
std::string label,
std::string_view label,
const GameObject& before,
const GameObject& after
const GameObject& after,
std::string_view detail
) {
EditorCommand command{};
command.type = type;
command.label = std::move(label);
command.label = std::string(label);
command.detail = std::string(detail);
command.object_id = after.identity.id;
command.before_object = before;
command.after_object = after;

return command;
}

EditorCommand make_create_object_command(const GameObject& created)
{
EditorCommand make_create_object_command(
const GameObject& created,
std::string_view detail
) {
EditorCommand command{};
command.type = EditorCommandType::CreateObject;
command.label = editor_command_type_label(EditorCommandType::CreateObject);
command.detail = std::string(detail);
command.object_id = created.identity.id;
command.after_object = created;

return command;
}

EditorCommand make_delete_object_command(const GameObject& deleted)
{
EditorCommand make_delete_object_command(
const GameObject& deleted,
std::string_view detail
) {
EditorCommand command{};
command.type = EditorCommandType::DeleteObject;
command.label = editor_command_type_label(EditorCommandType::DeleteObject);
command.detail = std::string(detail);
command.object_id = deleted.identity.id;
command.before_object = deleted;

return command;
}

EditorCommand make_viewport_command(
std::string label,
std::string_view label,
const Camera& before,
const Camera& after
const Camera& after,
std::string_view detail
) {
EditorCommand command{};
command.type = EditorCommandType::MoveViewport;
command.label = std::move(label);
command.label = std::string(label);
command.detail = std::string(detail);
command.before_camera = before;
command.after_camera = after;

Expand Down
23 changes: 17 additions & 6 deletions src/prune/editor/editor_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstddef>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "prune/scene/game_object.hpp"
Expand All @@ -27,6 +28,7 @@ namespace prune {
struct EditorCommand {
EditorCommandType type = EditorCommandType::MoveObject;
std::string label;
std::string detail;
GameObjectId object_id = k_invalid_game_object_id;

std::optional<GameObject> before_object;
Expand Down Expand Up @@ -62,18 +64,27 @@ namespace prune {

[[nodiscard]] EditorCommand make_object_command(
EditorCommandType type,
std::string label,
std::string_view label,
const GameObject& before,
const GameObject& after
const GameObject& after,
std::string_view detail = {}
);

[[nodiscard]] EditorCommand make_create_object_command(const GameObject& created);
[[nodiscard]] EditorCommand make_delete_object_command(const GameObject& deleted);
[[nodiscard]] EditorCommand make_create_object_command(
const GameObject& created,
std::string_view detail = {}
);

[[nodiscard]] EditorCommand make_delete_object_command(
const GameObject& deleted,
std::string_view detail = {}
);

[[nodiscard]] EditorCommand make_viewport_command(
std::string label,
std::string_view label,
const Camera& before,
const Camera& after
const Camera& after,
std::string_view detail = {}
);

}
9 changes: 6 additions & 3 deletions src/prune/scene/scene_interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace prune {
scene.record_editor_command(make_viewport_command(
editor_command_type_label(EditorCommandType::MoveViewport),
m_viewport_pan_start,
after
after,
"Mouse pan"
));
}

Expand Down Expand Up @@ -110,7 +111,8 @@ namespace prune {
EditorCommandType::MoveObject,
editor_command_type_label(EditorCommandType::MoveObject),
before,
*object
*object,
"Mouse drag"
));
}
}
Expand Down Expand Up @@ -233,7 +235,8 @@ namespace prune {
EditorCommandType::MoveObject,
editor_command_type_label(EditorCommandType::MoveObject),
before,
*selected
*selected,
"Keyboard nudge"
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/prune/scene/world_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace prune {
if (ImGui::Button(action.label.data())) {
const GameObjectId created_id = create_scene_object(action.id);
if (const GameObject* created = m_state.objects.get_by_id(created_id)) {
record_editor_command(make_create_object_command(*created));
record_editor_command(make_create_object_command(*created, action.label));
}
}
ImGui::PopID();
Expand Down
28 changes: 20 additions & 8 deletions src/prune/tooling/command_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ namespace prune {
ImGui::BeginDisabled();
}

ImGui::Text(
"%s%zu. %s",
applied ? "" : "redo: ",
command_index + 1,
command.label.empty()
? editor_command_type_label(command.type)
: command.label.c_str()
);
const char* label = command.label.empty()
? editor_command_type_label(command.type)
: command.label.c_str();

if (command.detail.empty()) {
ImGui::Text(
"%s%zu. %s",
applied ? "" : "redo: ",
command_index + 1,
label
);
} else {
ImGui::Text(
"%s%zu. %s: %s",
applied ? "" : "redo: ",
command_index + 1,
label,
command.detail.c_str()
);
}

if (command.object_id != k_invalid_game_object_id) {
ImGui::SameLine();
Expand Down
Loading
Loading