Skip to content

Commit

Permalink
Apply Godot's community's feedback
Browse files Browse the repository at this point in the history
By using the comments of this PR:
godotengine/godot#60603
  • Loading branch information
98teg committed Dec 9, 2022
1 parent d144770 commit fc8d1ef
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/native_accept_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void NativeAcceptDialog::_bind_methods() {
}

NativeAcceptDialog::NativeAcceptDialog() {
title = TranslationServer::get_singleton()->translate("Alert!");
title = "Alert!";
text = "";
icon = ICON_WARNING;
}
Expand Down Expand Up @@ -82,8 +82,8 @@ void NativeAcceptDialog::show() {
}

message = new pfd::message(
title.utf8().get_data(),
text.utf8().get_data(),
String(TranslationServer::get_singleton()->translate(title)).utf8().get_data(),
String(TranslationServer::get_singleton()->translate(text)).utf8().get_data(),
choice,
pfd_icon);
}
Expand Down
2 changes: 0 additions & 2 deletions src/native_accept_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class NativeAcceptDialog : public Node {
protected:
static void _bind_methods();

void process_button(pfd::button button);

void set_choice(pfd::choice p_choice);
pfd::choice get_choice();

Expand Down
4 changes: 1 addition & 3 deletions src/native_confirmation_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <godot_cpp/classes/translation_server.hpp>

#include "native_confirmation_dialog.h"

using namespace godot;
Expand All @@ -14,7 +12,7 @@ void NativeConfirmationDialog::_bind_methods() {
}

NativeConfirmationDialog::NativeConfirmationDialog() {
set_title(TranslationServer::get_singleton()->translate("Please Confirm..."));
set_title("Please Confirm...");
set_icon(ICON_QUESTION);
set_buttons_texts(BUTTONS_TEXTS_OK_CANCEL);
}
Expand Down
2 changes: 0 additions & 2 deletions src/native_confirmation_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class NativeConfirmationDialog : public NativeAcceptDialog {
protected:
static void _bind_methods();

void process_button(pfd::button button);

public:
enum ButtonsTexts {
BUTTONS_TEXTS_OK_CANCEL,
Expand Down
38 changes: 18 additions & 20 deletions src/native_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ NativeFileDialog::NativeFileDialog() {
access = ACCESS_RESOURCES;
root_subfolder = "";
filters = PackedStringArray();
title = TranslationServer::get_singleton()->translate("Save a File");
title = "Save a File";
}

NativeFileDialog::~NativeFileDialog() {
Expand All @@ -67,27 +67,25 @@ NativeFileDialog::~NativeFileDialog() {
void NativeFileDialog::_process(float delta) {
if (open_file && open_file->ready(0)) {
PackedStringArray result = PackedStringArray();
for (int i = 0; i < open_file->result().size(); i++) {
for (int i = 0; i < open_file->result().size(); i++)
result.append(get_godot_path(open_file->result()[i]));
}

if (result.size() == 1) {
emit_signal("file_selected", result[0]);
} else {
if (!result.is_empty())
emit_signal("files_selected", result);
}

hide();
}
} else if (save_file && save_file->ready(0)) {
String result = get_godot_path(save_file->result());

if (save_file && save_file->ready(0)) {
emit_signal("file_selected", get_godot_path(save_file->result()));
if (!result.is_empty())
emit_signal("file_selected", result);

hide();
}
} else if (select_folder && select_folder->ready(0)) {
String result = get_godot_path(select_folder->result());

if (select_folder && select_folder->ready(0)) {
emit_signal("dir_selected", get_godot_path(select_folder->result()));
if (!result.is_empty())
emit_signal("dir_selected", get_godot_path(select_folder->result()));

hide();
}
Expand All @@ -103,7 +101,7 @@ void NativeFileDialog::show() {

hide();

const char *title = get_title().utf8().get_data();
const char *title = String(TranslationServer::get_singleton()->translate(get_title())).utf8().get_data();

if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) {
pfd::opt option = mode == FILE_MODE_OPEN_FILES ? pfd::opt::multiselect : pfd::opt::none;
Expand Down Expand Up @@ -238,7 +236,7 @@ std::vector<std::string> NativeFileDialog::get_pfd_filters() const {
for (int i = 0; i < filters.size(); i++) {
PackedStringArray filter = filters[i].split(" ; ");

String name = filter.size() == 2 ? filter[1] : "";
String name = TranslationServer::get_singleton()->translate(filter.size() == 2 ? filter[1] : "");
String extensions = filter[0].replace(", ", " ");

pfd_filters.push_back(name.utf8().get_data());
Expand All @@ -265,7 +263,7 @@ std::string NativeFileDialog::get_pfd_path() const {
}

String NativeFileDialog::get_godot_path(const std::string &pfd_path) const {
String godot_path = pfd_path.c_str();
String godot_path = String::utf8(pfd_path.c_str());

#if _WIN32
godot_path = godot_path.replace("\\", "/");
Expand All @@ -281,16 +279,16 @@ void NativeFileDialog::override_title() {

switch (mode) {
case FILE_MODE_OPEN_FILE:
set_title(TranslationServer::get_singleton()->translate("Open a File"));
set_title("Open a File");
break;
case FILE_MODE_OPEN_FILES:
set_title(TranslationServer::get_singleton()->translate("Open File(s)"));
set_title("Open File(s)");
break;
case FILE_MODE_OPEN_DIR:
set_title(TranslationServer::get_singleton()->translate("Open a Directory"));
set_title("Open a Directory");
break;
case FILE_MODE_SAVE_FILE:
set_title(TranslationServer::get_singleton()->translate("Save a File"));
set_title("Save a File");
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/native_notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void NativeNotification::_bind_methods() {
}

NativeNotification::NativeNotification() {
title = TranslationServer::get_singleton()->translate("Alert!");
title = "Alert!";
text = "";
icon = ICON_WARNING;
}
Expand All @@ -46,7 +46,10 @@ void NativeNotification::send() {
break;
}

pfd::notify(title.utf8().get_data(), text.utf8().get_data(), pfd_icon);
pfd::notify(
String(TranslationServer::get_singleton()->translate(title)).utf8().get_data(),
String(TranslationServer::get_singleton()->translate(text)).utf8().get_data(),
pfd_icon);
}

void NativeNotification::set_title(const String &p_title) {
Expand Down

0 comments on commit fc8d1ef

Please sign in to comment.