feat(wip): implementing edit history and un-re-do
This commit is contained in:
parent
b875c2089b
commit
e2926f7c3f
6 changed files with 90 additions and 3 deletions
33
modules/terrain_editor/edit_history.cpp
Normal file
33
modules/terrain_editor/edit_history.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "edit_history.h"
|
||||
#include "macros.h"
|
||||
|
||||
EditHistory *EditHistory::singleton_instance{ nullptr };
|
||||
|
||||
void EditHistory::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("push_action", "do_action", "undo_action"), &self_type::push_action);
|
||||
ClassDB::bind_method(D_METHOD("undo_last"), &self_type::undo);
|
||||
ClassDB::bind_method(D_METHOD("redo_last"), &self_type::redo);
|
||||
}
|
||||
|
||||
void EditHistory::push_action(Callable do_action, Callable undo_action) {
|
||||
if (this->undo_count != 0) {
|
||||
this->history.resize(this->history.size() - this->undo_count);
|
||||
this->undo_count = 0;
|
||||
}
|
||||
do_action.call();
|
||||
this->history.push_back({ do_action, undo_action });
|
||||
}
|
||||
|
||||
void EditHistory::undo() {
|
||||
if (this->undo_count + 1 < this->history.size()) {
|
||||
this->undo_count++;
|
||||
this->history[this->history.size() - this->undo_count].undo_action.call();
|
||||
}
|
||||
}
|
||||
|
||||
void EditHistory::redo() {
|
||||
if (this->undo_count > 1) {
|
||||
this->undo_count--;
|
||||
this->history[this->history.size() - this->undo_count].do_action.call();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue