feat: UI elements for key combinations
This commit is contained in:
parent
ab300878cf
commit
c668771696
15 changed files with 415 additions and 33 deletions
|
|
@ -30,3 +30,8 @@ void EditHistory::redo() {
|
|||
this->undo_count--;
|
||||
}
|
||||
}
|
||||
|
||||
void EditHistory::clear_history() {
|
||||
this->history.clear();
|
||||
this->undo_count = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
void push_action(Callable do_action, Callable undo_action);
|
||||
void undo();
|
||||
void redo();
|
||||
void clear_history();
|
||||
|
||||
private:
|
||||
size_t undo_count{ 0 };
|
||||
|
|
|
|||
|
|
@ -40,13 +40,15 @@ String const TerrainMeshEditor::sig_selection_changed{ "selection_changed" };
|
|||
void TerrainMeshEditor::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::OBJECT, point_primitive_object, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
|
||||
ClassDB::bind_method(D_METHOD("save_data"), &self_type::save_data);
|
||||
ClassDB::bind_method(D_METHOD("save_data_as"), &self_type::save_data_as);
|
||||
BIND_HPROPERTY(Variant::OBJECT, current_selected, PROPERTY_HINT_RESOURCE_TYPE, "TerrainPrimitive");
|
||||
BIND_HPROPERTY(Variant::OBJECT, new_file_data, PROPERTY_HINT_RESOURCE_TYPE, "SaveData");
|
||||
ADD_SIGNAL(MethodInfo(sig_selection_changed, PropertyInfo(Variant::OBJECT, "new_selection", PROPERTY_HINT_RESOURCE_TYPE, "TerrainPrimitive")));
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::ready() {
|
||||
connect(sig_primitive_list_changed, callable_mp(this, &self_type::on_primitive_list_changed));
|
||||
on_primitive_list_changed(get_primitives());
|
||||
load_new();
|
||||
if (FileDialog * dialog{ memnew(FileDialog) }) {
|
||||
this->file_dialog = dialog;
|
||||
add_child(dialog);
|
||||
|
|
@ -96,6 +98,13 @@ void TerrainMeshEditor::on_save_file_selected(String path) {
|
|||
}
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::load_new() {
|
||||
this->data = this->new_file_data->duplicate(true);
|
||||
this->set_primitives(this->data->get_primitives().duplicate(true));
|
||||
this->data->set_save_path("");
|
||||
EditHistory::get_singleton()->clear_history();
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
|
|
@ -121,9 +130,7 @@ void TerrainMeshEditor::unhandled_input(Ref<InputEvent> const &event) {
|
|||
case Key::S:
|
||||
if (key->is_shift_pressed() && key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
this->file_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
|
||||
this->file_dialog->set_ok_button_text("Save");
|
||||
this->file_dialog->popup_file_dialog();
|
||||
save_data_as();
|
||||
} else if (key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
save_data();
|
||||
|
|
@ -146,6 +153,12 @@ void TerrainMeshEditor::unhandled_input(Ref<InputEvent> const &event) {
|
|||
EditHistory::get_singleton()->undo();
|
||||
}
|
||||
break;
|
||||
case Key::N:
|
||||
if (key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
load_new();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,15 +168,27 @@ void TerrainMeshEditor::save_data() {
|
|||
return;
|
||||
}
|
||||
if (this->data->get_save_path().is_empty()) {
|
||||
this->file_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
|
||||
this->file_dialog->set_ok_button_text("Save");
|
||||
this->file_dialog->popup_file_dialog();
|
||||
save_data_as();
|
||||
} else {
|
||||
this->data->set_primitives(get_primitives());
|
||||
this->data->write_to_file();
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::save_data_as() {
|
||||
this->file_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
|
||||
this->file_dialog->set_ok_button_text("Save");
|
||||
this->file_dialog->popup_file_dialog();
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::set_new_file_data(Ref<SaveData> data) {
|
||||
this->new_file_data = data;
|
||||
}
|
||||
|
||||
Ref<SaveData> TerrainMeshEditor::get_new_file_data() const {
|
||||
return this->new_file_data;
|
||||
}
|
||||
|
||||
void TerrainMeshEditor::set_current_selected(Ref<TerrainPrimitive> primitive) {
|
||||
this->current_selected = primitive;
|
||||
emit_signal(sig_selection_changed, primitive);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class TerrainMeshEditor : public TerrainMeshGenerator {
|
|||
void on_primitive_list_changed(Array primitives);
|
||||
void on_primitive_node_removed();
|
||||
void on_save_file_selected(String path);
|
||||
void load_new();
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
|
@ -35,12 +36,16 @@ protected:
|
|||
|
||||
public:
|
||||
void save_data();
|
||||
void save_data_as();
|
||||
void set_new_file_data(Ref<SaveData> data);
|
||||
Ref<SaveData> get_new_file_data() const;
|
||||
void set_current_selected(Ref<TerrainPrimitive>);
|
||||
Ref<TerrainPrimitive> get_current_selected() const;
|
||||
void set_point_primitive_object(Ref<PackedScene> scene);
|
||||
Ref<PackedScene> get_point_primitive_object() const;
|
||||
|
||||
private:
|
||||
Ref<SaveData> new_file_data{};
|
||||
Ref<SaveData> data{ memnew(SaveData) };
|
||||
Ref<TerrainPrimitive> current_selected{};
|
||||
FileDialog *file_dialog{};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue