Links (#615)
* add URL support to Label element and XML parsing * refactor Label URL handling to use getter method in setURL * implement URL opening confirmation dialog and platform-specific URL handling * fix: fixed build errors * remove: delete test link label from worlds.xml * refactor: remove URL handling from Label class and XML parsing * refactor: clean up Label class by removing unnecessary whitespace and improving code readability * refactor: remove unused URL member from Label class * refactor: remove unused URL attribute from XML UI documentation and related code * refactor: improve code readability by adding whitespace and formatting adjustments in Label class * refactor: improve whitespace consistency in Label class and add URL opening functionality in libcore
This commit is contained in:
parent
21725921e1
commit
240abb939f
@ -1,5 +1,4 @@
|
|||||||
<panel size='400' color='0' interval='1' context='menu'>
|
<panel size='400' color='0' interval='1' context='menu'>
|
||||||
|
|
||||||
<button onclick='menu.page="new_world"'>@New World</button>
|
<button onclick='menu.page="new_world"'>@New World</button>
|
||||||
|
|
||||||
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>
|
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>
|
||||||
|
|||||||
@ -25,6 +25,7 @@ Grant %{0} pack modification permission?=Выдаць дазвол на мады
|
|||||||
Error at line %{0}=Памылка ў радку %{0}
|
Error at line %{0}=Памылка ў радку %{0}
|
||||||
Run=Запусціць
|
Run=Запусціць
|
||||||
Filter=Фільтр
|
Filter=Фільтр
|
||||||
|
Are you sure you want to open the link: =Ці вы ўпэўненыя, што хочаце адкрыць спасылку:
|
||||||
|
|
||||||
editor.info.tooltip=CTRL+S - Захаваць\nCTRL+R - Запусціць\nCTRL+Z - Скасаваць\nCTRL+Y - Паўтарыць
|
editor.info.tooltip=CTRL+S - Захаваць\nCTRL+R - Запусціць\nCTRL+Z - Скасаваць\nCTRL+Y - Паўтарыць
|
||||||
devtools.traceback=Стэк выклікаў (ад апошняга)
|
devtools.traceback=Стэк выклікаў (ад апошняга)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Back=Zurück
|
|||||||
Continue=Weitermachen
|
Continue=Weitermachen
|
||||||
Add=Hinzufügen
|
Add=Hinzufügen
|
||||||
Converting world...=Weltkonvertierung im Gange...
|
Converting world...=Weltkonvertierung im Gange...
|
||||||
|
Are you sure you want to open the link: =Sind Sie sicher, dass Sie den Link öffnen möchten:
|
||||||
|
|
||||||
error.pack-not-found=Paket konnte nicht gefunden werden
|
error.pack-not-found=Paket konnte nicht gefunden werden
|
||||||
error.dependency-not-found=Die verwendete Abhängigkeit wurde nicht gefunden
|
error.dependency-not-found=Die verwendete Abhängigkeit wurde nicht gefunden
|
||||||
|
|||||||
@ -19,6 +19,7 @@ Problems=Ongelmia
|
|||||||
Monitor=Valvonta
|
Monitor=Valvonta
|
||||||
Debug=Virheenkorjaus
|
Debug=Virheenkorjaus
|
||||||
File=Tiedosto
|
File=Tiedosto
|
||||||
|
Are you sure you want to open the link: =Haluatko varmasti avata linkin:
|
||||||
|
|
||||||
devtools.traceback=Puhelupino (viimeisestä)
|
devtools.traceback=Puhelupino (viimeisestä)
|
||||||
error.pack-not-found=Pakettia ei löytynyt!
|
error.pack-not-found=Pakettia ei löytynyt!
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Back=Powrót
|
|||||||
Continue=Kontynuacja
|
Continue=Kontynuacja
|
||||||
Add=Dodać
|
Add=Dodać
|
||||||
Converting world...=Konwersja świata w toku...
|
Converting world...=Konwersja świata w toku...
|
||||||
|
Are you sure you want to open the link: =Czy na pewno chcesz otworzyć link:
|
||||||
|
|
||||||
error.pack-not-found=Nie udało się znaleźć pakietu
|
error.pack-not-found=Nie udało się znaleźć pakietu
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ Grant %{0} pack modification permission?=Выдать разрешение на
|
|||||||
Error at line %{0}=Ошибка на строке %{0}
|
Error at line %{0}=Ошибка на строке %{0}
|
||||||
Run=Запустить
|
Run=Запустить
|
||||||
Filter=Фильтр
|
Filter=Фильтр
|
||||||
|
Are you sure you want to open the link: =Вы уверены, что хотите открыть ссылку:
|
||||||
|
|
||||||
editor.info.tooltip=CTRL+S - Сохранить\nCTRL+R - Запустить\nCTRL+Z - Отменить\nCTRL+Y - Повторить
|
editor.info.tooltip=CTRL+S - Сохранить\nCTRL+R - Запустить\nCTRL+Z - Отменить\nCTRL+Y - Повторить
|
||||||
devtools.traceback=Стек вызовов (от последнего)
|
devtools.traceback=Стек вызовов (от последнего)
|
||||||
|
|||||||
@ -23,6 +23,7 @@ devtools.traceback=Стек викликів (від останнього)
|
|||||||
error.pack-not-found=Не вдалося знайти пакет
|
error.pack-not-found=Не вдалося знайти пакет
|
||||||
error.dependency-not-found=Використовувана залежність не знайдена
|
error.dependency-not-found=Використовувана залежність не знайдена
|
||||||
pack.remove-confirm=Видалити весь контент, що постачається паком/паками зі світу (безповоротно)?
|
pack.remove-confirm=Видалити весь контент, що постачається паком/паками зі світу (безповоротно)?
|
||||||
|
Are you sure you want to open the link: =Ви впевнені, що хочете відкрити посилання:
|
||||||
|
|
||||||
# Меню
|
# Меню
|
||||||
menu.Apply=Застосувати
|
menu.Apply=Застосувати
|
||||||
|
|||||||
@ -24,6 +24,7 @@ Save=Saqlash
|
|||||||
Grant %{0} pack modification permission?=%{0} to‘plamini o‘zgartirish ruxsatini berilsinmi?
|
Grant %{0} pack modification permission?=%{0} to‘plamini o‘zgartirish ruxsatini berilsinmi?
|
||||||
Error at line %{0}=%{0}-qatorida xatolik
|
Error at line %{0}=%{0}-qatorida xatolik
|
||||||
Run=Ishga tushirish
|
Run=Ishga tushirish
|
||||||
|
Are you sure you want to open the link: =Haqiqatan ham havolani ochmoqchimisiz:
|
||||||
|
|
||||||
editor.info.tooltip=CTRL+S - Saqlash\nCTRL+R - Ishga tushirish\nCTRL+Z - Bekor qilish\nCTRL+Y - Qayta bajarish
|
editor.info.tooltip=CTRL+S - Saqlash\nCTRL+R - Ishga tushirish\nCTRL+Z - Bekor qilish\nCTRL+Y - Qayta bajarish
|
||||||
devtools.traceback=Chaqiruvlar steki (so`nggisidan boshlab)
|
devtools.traceback=Chaqiruvlar steki (so`nggisidan boshlab)
|
||||||
|
|||||||
@ -103,9 +103,14 @@ void guiutil::confirm(
|
|||||||
|
|
||||||
panel->setGravity(Gravity::center_center);
|
panel->setGravity(Gravity::center_center);
|
||||||
container->add(panel);
|
container->add(panel);
|
||||||
|
|
||||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||||
panel->add(std::make_shared<Label>(gui, text));
|
|
||||||
|
auto label = std::make_shared<Label>(gui, text);
|
||||||
|
label->setSize(glm::vec2(600, 50));
|
||||||
|
label->setMultiline(true);
|
||||||
|
label->setTextWrapping(true);
|
||||||
|
|
||||||
|
panel->add(label);
|
||||||
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
auto subpanel = std::make_shared<Panel>(gui, glm::vec2(600, 53));
|
||||||
subpanel->setColor(glm::vec4(0));
|
subpanel->setColor(glm::vec4(0));
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,11 @@
|
|||||||
#include "util/platform.hpp"
|
#include "util/platform.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/generator/WorldGenerator.hpp"
|
#include "world/generator/WorldGenerator.hpp"
|
||||||
|
#include "util/platform.hpp"
|
||||||
|
#include "frontend/locale.hpp"
|
||||||
|
#include "graphics/ui/gui_util.hpp"
|
||||||
|
#include "graphics/ui/GUI.hpp"
|
||||||
|
#include "graphics/ui/elements/Menu.hpp"
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
@ -229,6 +234,24 @@ static int l_open_folder(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_open_url(lua::State* L) {
|
||||||
|
auto url = lua::require_string(L, 1);
|
||||||
|
|
||||||
|
std::wstring msg = langs::get(L"Are you sure you want to open the link:") +
|
||||||
|
L"\n" + util::str2wstr_utf8(url) +
|
||||||
|
std::wstring(L"?");
|
||||||
|
|
||||||
|
auto menu = engine->getGUI().getMenu();
|
||||||
|
|
||||||
|
guiutil::confirm(*engine, msg, [url, menu]() {
|
||||||
|
platform::openURL(url);
|
||||||
|
if (!menu->back()) {
|
||||||
|
menu->reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Quit the game
|
/// @brief Quit the game
|
||||||
static int l_quit(lua::State*) {
|
static int l_quit(lua::State*) {
|
||||||
engine->quit();
|
engine->quit();
|
||||||
@ -284,6 +307,7 @@ const luaL_Reg corelib[] = {
|
|||||||
{"str_setting", lua::wrap<l_str_setting>},
|
{"str_setting", lua::wrap<l_str_setting>},
|
||||||
{"get_setting_info", lua::wrap<l_get_setting_info>},
|
{"get_setting_info", lua::wrap<l_get_setting_info>},
|
||||||
{"open_folder", lua::wrap<l_open_folder>},
|
{"open_folder", lua::wrap<l_open_folder>},
|
||||||
|
{"open_url", lua::wrap<l_open_url>},
|
||||||
{"quit", lua::wrap<l_quit>},
|
{"quit", lua::wrap<l_quit>},
|
||||||
{"capture_output", lua::wrap<l_capture_output>},
|
{"capture_output", lua::wrap<l_capture_output>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
|||||||
@ -65,14 +65,31 @@ int platform::get_process_id() {
|
|||||||
return GetCurrentProcessId();
|
return GetCurrentProcessId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool platform::openURL(const std::string& url) {
|
||||||
|
if (url.empty()) return false;
|
||||||
|
// UTF-8 → UTF-16
|
||||||
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, nullptr, 0);
|
||||||
|
if (wlen <= 0) return false;
|
||||||
|
|
||||||
|
std::wstring wurl(wlen, L'\0');
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, &wurl[0], wlen);
|
||||||
|
|
||||||
|
HINSTANCE result = ShellExecuteW(
|
||||||
|
nullptr, L"open", wurl.c_str(), nullptr, nullptr, SW_SHOWNORMAL
|
||||||
|
);
|
||||||
|
|
||||||
|
return reinterpret_cast<intptr_t>(result) > 32;
|
||||||
|
}
|
||||||
|
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include "frontend/locale.hpp"
|
#include "frontend/locale.hpp"
|
||||||
|
|
||||||
void platform::configure_encoding() {
|
void platform::configure_encoding() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string platform::detect_locale() {
|
std::string platform::detect_locale() {
|
||||||
const char* const programLocaleName = setlocale(LC_ALL, nullptr);
|
const char* const programLocaleName = setlocale(LC_ALL, nullptr);
|
||||||
const char* const preferredLocaleName =
|
const char* const preferredLocaleName =
|
||||||
@ -92,6 +109,24 @@ void platform::sleep(size_t millis) {
|
|||||||
int platform::get_process_id() {
|
int platform::get_process_id() {
|
||||||
return getpid();
|
return getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool platform::openURL(const std::string& url) {
|
||||||
|
if (url.empty()) return false;
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
execlp("open", "open", url.c_str(), (char*)nullptr);
|
||||||
|
#else
|
||||||
|
execlp("xdg-open", "xdg-open", url.c_str(), (char*)nullptr);
|
||||||
|
#endif
|
||||||
|
_exit(127);
|
||||||
|
} else if (pid > 0) {
|
||||||
|
int status = 0;
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
void platform::open_folder(const std::filesystem::path& folder) {
|
void platform::open_folder(const std::filesystem::path& folder) {
|
||||||
|
|||||||
@ -13,4 +13,5 @@ namespace platform {
|
|||||||
/// Makes the current thread sleep for the specified amount of milliseconds.
|
/// Makes the current thread sleep for the specified amount of milliseconds.
|
||||||
void sleep(size_t millis);
|
void sleep(size_t millis);
|
||||||
int get_process_id();
|
int get_process_id();
|
||||||
|
bool openURL(const std::string& url);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user