From 5d8f799a1171f92054d4b45ba130cd7fdad0bd01 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 23 May 2025 14:04:27 +0200 Subject: app: prepare restructuring --- gui/CMakeLists.txt | 59 ++++++ gui/desktop.in | 10 + gui/lang/CMakeLists.txt | 77 ++++++++ gui/lang/include/turns/lang/messages.hpp | 49 +++++ gui/lang/po/de.po | 132 +++++++++++++ gui/lang/po/de_CH.po | 12 ++ gui/lang/po/en.po | 132 +++++++++++++ gui/lang/tests/intl_test_init.cpp | 26 +++ gui/lang/tests/messages.cpp | 72 +++++++ gui/metainfo.xml | 38 ++++ gui/mime.xml | 9 + gui/schemas/ch.arknet.Turns.gschema.xml | 25 +++ gui/settings.cpp | 28 +++ gui/settings.hpp | 21 ++ gui/src/main.cpp | 97 ++++++++++ gui/style/CMakeLists.txt | 18 ++ gui/style/style-dark.css | 32 ++++ gui/style/style.css | 31 +++ gui/ui/CMakeLists.txt | 59 ++++++ gui/ui/include/turns/ui/fwd.hpp | 14 ++ gui/ui/include/turns/ui/init.hpp | 15 ++ gui/ui/include/turns/ui/participant_editor.hpp | 82 ++++++++ gui/ui/include/turns/ui/participant_row.hpp | 50 +++++ gui/ui/include/turns/ui/preferences.hpp | 53 +++++ gui/ui/include/turns/ui/template_widget.hpp | 67 +++++++ gui/ui/include/turns/ui/tracker.hpp | 104 ++++++++++ gui/ui/include/turns/ui/turn_order_view.hpp | 40 ++++ gui/ui/src/init.cpp | 23 +++ gui/ui/src/participant_editor.cpp | 162 ++++++++++++++++ gui/ui/src/participant_editor.ui | 71 +++++++ gui/ui/src/participant_row.cpp | 149 +++++++++++++++ gui/ui/src/participant_row.ui | 89 +++++++++ gui/ui/src/preferences.cpp | 81 ++++++++ gui/ui/src/preferences.ui | 104 ++++++++++ gui/ui/src/tracker.cpp | 255 +++++++++++++++++++++++++ gui/ui/src/tracker.ui | 153 +++++++++++++++ gui/ui/src/tracker/actions.cpp | 125 ++++++++++++ gui/ui/src/tracker/event_handlers.cpp | 105 ++++++++++ gui/ui/src/turn_order_view.cpp | 64 +++++++ gui/ui/src/turn_order_view.ui | 38 ++++ gui/ui/tests/gtk_test_init.cpp | 41 ++++ gui/ui/tests/participant_editor.cpp | 150 +++++++++++++++ gui/ui/tests/participant_row.cpp | 30 +++ gui/ui/tests/resources.cpp | 21 ++ gui/ui/tests/tracker.cpp | 79 ++++++++ gui/ui/ui.cmb | 10 + 46 files changed, 3102 insertions(+) create mode 100644 gui/CMakeLists.txt create mode 100644 gui/desktop.in create mode 100644 gui/lang/CMakeLists.txt create mode 100644 gui/lang/include/turns/lang/messages.hpp create mode 100644 gui/lang/po/de.po create mode 100644 gui/lang/po/de_CH.po create mode 100644 gui/lang/po/en.po create mode 100644 gui/lang/tests/intl_test_init.cpp create mode 100644 gui/lang/tests/messages.cpp create mode 100644 gui/metainfo.xml create mode 100644 gui/mime.xml create mode 100644 gui/schemas/ch.arknet.Turns.gschema.xml create mode 100644 gui/settings.cpp create mode 100644 gui/settings.hpp create mode 100644 gui/src/main.cpp create mode 100644 gui/style/CMakeLists.txt create mode 100644 gui/style/style-dark.css create mode 100644 gui/style/style.css create mode 100644 gui/ui/CMakeLists.txt create mode 100644 gui/ui/include/turns/ui/fwd.hpp create mode 100644 gui/ui/include/turns/ui/init.hpp create mode 100644 gui/ui/include/turns/ui/participant_editor.hpp create mode 100644 gui/ui/include/turns/ui/participant_row.hpp create mode 100644 gui/ui/include/turns/ui/preferences.hpp create mode 100644 gui/ui/include/turns/ui/template_widget.hpp create mode 100644 gui/ui/include/turns/ui/tracker.hpp create mode 100644 gui/ui/include/turns/ui/turn_order_view.hpp create mode 100644 gui/ui/src/init.cpp create mode 100644 gui/ui/src/participant_editor.cpp create mode 100644 gui/ui/src/participant_editor.ui create mode 100644 gui/ui/src/participant_row.cpp create mode 100644 gui/ui/src/participant_row.ui create mode 100644 gui/ui/src/preferences.cpp create mode 100644 gui/ui/src/preferences.ui create mode 100644 gui/ui/src/tracker.cpp create mode 100644 gui/ui/src/tracker.ui create mode 100644 gui/ui/src/tracker/actions.cpp create mode 100644 gui/ui/src/tracker/event_handlers.cpp create mode 100644 gui/ui/src/turn_order_view.cpp create mode 100644 gui/ui/src/turn_order_view.ui create mode 100644 gui/ui/tests/gtk_test_init.cpp create mode 100644 gui/ui/tests/participant_editor.cpp create mode 100644 gui/ui/tests/participant_row.cpp create mode 100644 gui/ui/tests/resources.cpp create mode 100644 gui/ui/tests/tracker.cpp create mode 100644 gui/ui/ui.cmb (limited to 'gui') diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt new file mode 100644 index 0000000..1ae7a31 --- /dev/null +++ b/gui/CMakeLists.txt @@ -0,0 +1,59 @@ + + +# add_executable("app" +# "src/main.cpp" +# ) + +# target_link_libraries("app" PRIVATE +# "$<$,$>:gcov>" + +# "PkgConfig::gtkmm" +# "adwaitamm::adwaitamm" + +# "turns::core" +# "turns::lang" + +# "$<$:-Wl,--whole-archive>" +# "turns::ui" +# "turns::style" +# "$<$:-Wl,--no-whole-archive>" +# ) + +# target_add_glib_resources("app" +# PREFIX "/ch/arknet/Turns" +# UI_FILES "metainfo.xml" +# ) + +# set_target_properties("app" PROPERTIES +# OUTPUT_NAME "turns" +# ) + +# install(TARGETS "app" +# RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +# ) + +# install(FILES +# "${CMAKE_CURRENT_SOURCE_DIR}/metainfo.xml" +# DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" +# RENAME "ch.arknet.Turns.metainfo.xml" +# ) + +# configure_file("desktop.in" +# "turns.desktop" +# ) + +# install(FILES +# "${CMAKE_CURRENT_BINARY_DIR}/turns.desktop" +# DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" +# RENAME "ch.arknet.Turns.desktop" +# ) + +# configure_file("mime.xml" +# "turns.xml" +# ) + +# install(FILES +# "${CMAKE_CURRENT_BINARY_DIR}/turns.xml" +# DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages" +# RENAME "ch.arknet.Turns.xml" +# ) diff --git a/gui/desktop.in b/gui/desktop.in new file mode 100644 index 0000000..99c0307 --- /dev/null +++ b/gui/desktop.in @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Name=Turns +Name[de]=Züge +GenericName=Turn Tracker +Icon=ch.arknet.Turns +StartupNotify=true +Exec=@CMAKE_INSTALL_FULL_BINDIR@/turns %u +Categories=Utility; +MimeType=text/x-turn-order; \ No newline at end of file diff --git a/gui/lang/CMakeLists.txt b/gui/lang/CMakeLists.txt new file mode 100644 index 0000000..1842615 --- /dev/null +++ b/gui/lang/CMakeLists.txt @@ -0,0 +1,77 @@ +set(TRANSLATIONS + "de" + "de_CH" + "en" +) + +foreach(LANG IN LISTS TRANSLATIONS) + set(BINARY_FILE "${CMAKE_CURRENT_BINARY_DIR}/${LANG}/LC_MESSAGES/turns.mo") + set(SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/po/${LANG}.po") + + list(APPEND TRANSLATION_BINARIES "${BINARY_FILE}") + + add_custom_command(OUTPUT "${BINARY_FILE}" + COMMAND "${GETTEXT_MSGFMT_EXECUTABLE}" + ARGS + "-o" + "${BINARY_FILE}" + "${SOURCE_FILE}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DEPENDS + "${SOURCE_FILE}" + COMMENT "Processing translation ${LANG}" + ) + + install(FILES "${BINARY_FILE}" + DESTINATION "${CMAKE_INSTALL_FULL_LOCALEDIR}/${LANG}/LC_MESSAGES" + ) +endforeach() + +add_custom_target("mofiles" DEPENDS ${TRANSLATION_BINARIES}) + +add_library("lang" INTERFACE) + +add_library("turns::lang" ALIAS "lang") + +if(TURNS_USE_INSTALLED_TRANSLATIONS) + target_compile_definitions("lang" INTERFACE + "LOCALEDIR=\"${CMAKE_INSTALL_FULL_LOCALEDIR}\"" + ) +else() + target_compile_definitions("lang" INTERFACE + "LOCALEDIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" + ) +endif() + +target_include_directories("lang" INTERFACE + "include" +) + +add_dependencies("lang" "mofiles") + +# Tests + +add_executable("lang-tests" + "tests/intl_test_init.cpp" + + "tests/messages.cpp" +) + +target_link_libraries("lang-tests" PRIVATE + "Catch2::Catch2WithMain" + "Intl::Intl" + + "turns::lang" +) + +target_compile_definitions("lang-tests" PRIVATE + "TESTLOCALEDIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" +) + +enable_coverage("lang-tests") + +target_link_options("lang-tests" PRIVATE + "$<$,$>:--coverage>" +) + +catch_discover_tests("lang-tests") \ No newline at end of file diff --git a/gui/lang/include/turns/lang/messages.hpp b/gui/lang/include/turns/lang/messages.hpp new file mode 100644 index 0000000..e57fce4 --- /dev/null +++ b/gui/lang/include/turns/lang/messages.hpp @@ -0,0 +1,49 @@ +#ifndef TURNS_LANG_MESSAGES_HPP +#define TURNS_LANG_MESSAGES_HPP + +namespace turns::lang +{ + auto constexpr static add_participant = "Add participant"; + auto constexpr static cancel = "Cancel"; + auto constexpr static clear = "_Clear"; + auto constexpr static delete_participant = "Delete participant"; + auto constexpr static disposition = "Disposition"; + auto constexpr static disposition_colors = "Disposition Colors"; + auto constexpr static edit_participant = "Edit participant"; + auto constexpr static end_turn_order = "End turn order"; + auto constexpr static finish = "Finish"; + auto constexpr static flow = "Flow"; + auto constexpr static friendly = "Friendly"; + auto constexpr static hostile = "Hostile"; + auto constexpr static main_menu = "Main Menu"; + auto constexpr static mark_as_defeated = "Mark as defeated"; + auto constexpr static name = "Name"; + auto constexpr static new_turn_order_file_name = "New turn order.trns"; + auto constexpr static next_participant = "Next participant"; + auto constexpr static no_active_turn_order = "No active turn order"; + auto constexpr static open = "_Open..."; + auto constexpr static preferences = "Preferences"; + auto constexpr static preferences_mnemonic = "_Preferences"; + auto constexpr static previous_participant = "Previous participant"; + auto constexpr static priority = "Priority"; + auto constexpr static priority_number = "Priority {}"; + auto constexpr static question_clear_turn_order = "Do you want to clear the turn order?"; + auto constexpr static quit = "_Quit"; + auto constexpr static reset = "Reset"; + auto constexpr static round_number = "Round {}"; + auto constexpr static save = "_Save"; + auto constexpr static save_as = "Save as..."; + auto constexpr static saving_failed_format = "Saving failed: {}"; + auto constexpr static secret = "Secret"; + auto constexpr static skip_defeated = "Skip defeated"; + auto constexpr static start_turn_order = "Start turn order"; + auto constexpr static stop = "Stop"; + auto constexpr static stop_and_clear = "Stop and clear"; + auto constexpr static stop_turn_order = "Stop turn order"; + auto constexpr static successfully_opened_format = "Successfully opened '{}'"; + auto constexpr static successfully_saved_format = "Successfully saved '{}'"; + auto constexpr static turns = "Turns"; + auto constexpr static turns_files = "Turns Files"; +} // namespace turns::lang + +#endif \ No newline at end of file diff --git a/gui/lang/po/de.po b/gui/lang/po/de.po new file mode 100644 index 0000000..15c2d72 --- /dev/null +++ b/gui/lang/po/de.po @@ -0,0 +1,132 @@ +msgid "" +msgstr "" +"Project-Id-Version: turns 1.0.0\n" +"Last-Translator: Felix Morgner\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +msgid "Add participant" +msgstr "Teilnehmer hinzufügen" + +msgid "Cancel" +msgstr "Abbrechen" + +msgid "_Clear" +msgstr "_Leeren" + +msgid "Disposition" +msgstr "Gesinnung" + +msgid "Disposition Colors" +msgstr "Gesinnungsfarben" + +msgid "Delete participant" +msgstr "Teilnehmer entfernen" + +msgid "Do you want to clear the turn order?" +msgstr "Möchten Sie die Zugreihenfolge leeren?" + +msgid "Edit participant" +msgstr "Teilnehmer bearbeiten" + +msgid "End turn order" +msgstr "Zugreihenfolge beenden" + +msgid "Finish" +msgstr "Abschließen" + +msgid "Flow" +msgstr "Ablaufsteuerung" + +msgid "Friendly" +msgstr "Freundlich" + +msgid "Hostile" +msgstr "Feindseelig" + +msgid "Main Menu" +msgstr "Hauptmenü" + +msgid "Mark as defeated" +msgstr "Als besiegt markieren" + +msgid "Name" +msgstr "Name" + +msgid "New turn order.trns" +msgstr "Neue Zugreihenfolge.trns" + +msgid "Next participant" +msgstr "Nächster Teilnehmer" + +msgid "No active turn order" +msgstr "Keine aktive Zugreihenfolge" + +msgid "_Open..." +msgstr "_Öffnen..." + +msgid "Preferences" +msgstr "Einstellungen" + +msgid "_Preferences" +msgstr "_Einstellungen" + +msgid "Previous participant" +msgstr "Vorhergehender Teilnehmer" + +msgid "Priority" +msgstr "Priorität" + +msgid "Priority {}" +msgstr "Priorität {}" + +msgid "_Quit" +msgstr "_Beenden" + +msgid "Reset" +msgstr "Zurücksetzen" + +msgid "Round {}" +msgstr "Runde {}" + +msgid "_Save" +msgstr "_Speichern" + +msgid "Save as..." +msgstr "Speichern unter..." + +msgid "Saving failed: {}" +msgstr "Speichern fehlgeschlagen: {}" + +msgid "Secret" +msgstr "Geheim" + +msgid "Skip defeated" +msgstr "Besiegte Teilnehmer überspringen" + +msgid "Start turn order" +msgstr "Zugreihenfolge starten" + +msgid "Stop" +msgstr "Stoppen" + +msgid "Stop and clear" +msgstr "Stoppen und leeren" + +msgid "Stop turn order" +msgstr "Zugreihenfolge Stoppen" + +msgid "Successfully opened '{}'" +msgstr "'{}' wurde erfolgreich geöffnet." + +msgid "Successfully saved '{}'" +msgstr "'{}' wurde erfolgreich gespeichert." + +msgid "Turns" +msgstr "Züge" + +msgid "Turns Files" +msgstr "Züge Dateien" \ No newline at end of file diff --git a/gui/lang/po/de_CH.po b/gui/lang/po/de_CH.po new file mode 100644 index 0000000..e79f91e --- /dev/null +++ b/gui/lang/po/de_CH.po @@ -0,0 +1,12 @@ +msgid "" +msgstr "" +"Project-Id-Version: turns 1.0.0\n" +"Last-Translator: Felix Morgner\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +msgid "Finish" +msgstr "Abschliessen" diff --git a/gui/lang/po/en.po b/gui/lang/po/en.po new file mode 100644 index 0000000..54df09f --- /dev/null +++ b/gui/lang/po/en.po @@ -0,0 +1,132 @@ +msgid "" +msgstr "" +"Project-Id-Version: turns 1.0.0\n" +"Last-Translator: Felix Morgner\n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +msgid "Add participant" +msgstr "Add participant" + +msgid "Cancel" +msgstr "Cancel" + +msgid "_Clear" +msgstr "_Clear" + +msgid "Disposition" +msgstr "Disposition" + +msgid "Disposition Colors" +msgstr "Disposition Colors" + +msgid "Delete participant" +msgstr "Delete participant" + +msgid "Do you want to clear the turn order?" +msgstr "Do you want to clear the turn order?" + +msgid "Edit participant" +msgstr "Edit participant" + +msgid "End turn order" +msgstr "End turn order" + +msgid "Finish" +msgstr "Finish" + +msgid "Flow" +msgstr "Flow" + +msgid "Friendly" +msgstr "Friendly" + +msgid "Hostile" +msgstr "Hostile" + +msgid "Main Menu" +msgstr "Main Menu" + +msgid "Mark as defeated" +msgstr "Mark as defeated" + +msgid "Name" +msgstr "Name" + +msgid "New turn order.trns" +msgstr "New turn order.trns" + +msgid "Next participant" +msgstr "Next participant" + +msgid "No active turn order" +msgstr "No active turn order" + +msgid "_Open..." +msgstr "_Open..." + +msgid "Preferences" +msgstr "Preferences" + +msgid "_Preferences" +msgstr "_Preferences" + +msgid "Previous participant" +msgstr "Previous participant" + +msgid "Priority" +msgstr "Priority" + +msgid "Priority {}" +msgstr "Priority {}" + +msgid "_Quit" +msgstr "_Quit" + +msgid "Reset" +msgstr "Reset" + +msgid "Round {}" +msgstr "Round {}" + +msgid "_Save" +msgstr "_Save" + +msgid "Save as..." +msgstr "Save as..." + +msgid "Saving failed: {}" +msgstr "Saving failed: {}" + +msgid "Secret" +msgstr "Secret" + +msgid "Skip defeated" +msgstr "Skip defeated" + +msgid "Start turn order" +msgstr "Start turn order" + +msgid "Stop" +msgstr "Stop" + +msgid "Stop and clear" +msgstr "Stop and clear" + +msgid "Stop turn order" +msgstr "Stop turn order" + +msgid "Successfully opened '{}'" +msgstr "Successfully opened '{}'" + +msgid "Successfully saved '{}'" +msgstr "Successfully saved '{}'." + +msgid "Turns" +msgstr "Turns" + +msgid "Turns Files" +msgstr "Turns Files" diff --git a/gui/lang/tests/intl_test_init.cpp b/gui/lang/tests/intl_test_init.cpp new file mode 100644 index 0000000..5438179 --- /dev/null +++ b/gui/lang/tests/intl_test_init.cpp @@ -0,0 +1,26 @@ +#include +#include + +#include + +#include + +namespace turns::lang::tests +{ + + struct intl_test_init : Catch::EventListenerBase + { + using Catch::EventListenerBase::EventListenerBase; + + auto testRunStarting(Catch::TestRunInfo const &) -> void override + { + setlocale(LC_ALL, ""); + bindtextdomain("turns", TESTLOCALEDIR); + bind_textdomain_codeset("turns", "UTF-8"); + textdomain("turns"); + } + }; + + CATCH_REGISTER_LISTENER(intl_test_init); + +} // namespace turns::lang::tests \ No newline at end of file diff --git a/gui/lang/tests/messages.cpp b/gui/lang/tests/messages.cpp new file mode 100644 index 0000000..cecb038 --- /dev/null +++ b/gui/lang/tests/messages.cpp @@ -0,0 +1,72 @@ +#include "turns/lang/messages.hpp" + +#include +#include + +#include + +#include +#include +#include + +namespace turns::lang::tests +{ + + TEST_CASE("Translated messages") + { + auto locale = GENERATE("de_CH.UTF-8", "de_DE.UTF-8", "de_AT.UTF-8"); + setlocale(LC_ALL, locale); + + SECTION(std::format("Locale '{}'", locale)) + { + auto message = GENERATE(add_participant, + cancel, + clear, + delete_participant, + disposition, + disposition_colors, + edit_participant, + end_turn_order, + finish, + flow, + friendly, + hostile, + main_menu, + mark_as_defeated, + // a better solution is required to test the following entry: + // name, + new_turn_order_file_name, + next_participant, + no_active_turn_order, + open, + preferences, + preferences_mnemonic, + previous_participant, + priority, + priority_number, + question_clear_turn_order, + quit, + reset, + save, + save_as, + saving_failed_format, + secret, + skip_defeated, + start_turn_order, + stop, + stop_and_clear, + stop_turn_order, + successfully_opened_format, + successfully_saved_format, + round_number, + turns, + turns_files); + + SECTION(std::format("has a translation for '{}'", message)) + { + REQUIRE(std::string{gettext(message)} != message); + } + } + } + +} // namespace turns::lang::tests \ No newline at end of file diff --git a/gui/metainfo.xml b/gui/metainfo.xml new file mode 100644 index 0000000..621c1ee --- /dev/null +++ b/gui/metainfo.xml @@ -0,0 +1,38 @@ + + + ch.arknet.Turns + CC-BY-SA-4.0 + LGPL-2.1-or-later + Turns + Züge + A simple turn order tracker + +

+ Turns is an application to track turn order for TTRPGs like Dungeons and Dragons or Call of Cthulhu. +

+
+ + + +

This is the first public release

+
+
+
+ + keyboard + pointing + + + + Role-playing Games + Tabletop Games + + + Felix Morgner + + felix.morgner@gmail.com + ch.arknet.Turns.desktop + https://source.arknet.ch/fmorgner/turns + https://source.arknet.ch/fmorgner/turns/-/issues + https://source.arknet.ch/fmorgner/turns +
\ No newline at end of file diff --git a/gui/mime.xml b/gui/mime.xml new file mode 100644 index 0000000..92e0ff4 --- /dev/null +++ b/gui/mime.xml @@ -0,0 +1,9 @@ + + + + Turn order file + + + + + \ No newline at end of file diff --git a/gui/schemas/ch.arknet.Turns.gschema.xml b/gui/schemas/ch.arknet.Turns.gschema.xml new file mode 100644 index 0000000..d764608 --- /dev/null +++ b/gui/schemas/ch.arknet.Turns.gschema.xml @@ -0,0 +1,25 @@ + + + + + '#33d17a' + Friendly Disposition Color + The color used to shade friendly participants. + + + '#e01b24' + Hostile Disposition Color + The color used to shade hostile participants. + + + '#9141ac' + Secret Disposition Color + The color used to shade secret participants. + + + false + Skip Defeated Participants + Whether or not defeated participants shall be skipped while stepping through the turn order. + + + \ No newline at end of file diff --git a/gui/settings.cpp b/gui/settings.cpp new file mode 100644 index 0000000..13cf665 --- /dev/null +++ b/gui/settings.cpp @@ -0,0 +1,28 @@ +#include "turns/core/settings.hpp" + +#include +#include + +#include +#include + +#include + +namespace turns::core +{ + + auto get_settings() -> Glib::RefPtr + { + auto constexpr schema_id = "ch.arknet.Turns"; + +#ifdef TURNS_SETTINGS_SCHEMA_DIR + auto source = Gio::SettingsSchemaSource::create(TURNS_SETTINGS_SCHEMA_DIR "/glib-2.0/schemas", true); + auto schema = source->lookup(schema_id, true); + auto settings = g_settings_new_full(Glib::unwrap(schema), nullptr, nullptr); + return Glib::wrap(settings); +#else + return Gio::Settings::create(schema_id); +#endif + } + +} // namespace turns::core diff --git a/gui/settings.hpp b/gui/settings.hpp new file mode 100644 index 0000000..304394d --- /dev/null +++ b/gui/settings.hpp @@ -0,0 +1,21 @@ +#ifndef TURNS_CORE_SETTINGS_HPP +#define TURNS_CORE_SETTINGS_HPP + +#include + +#include + +namespace turns::core +{ + namespace settings::key + { + auto constexpr disposition_friendly_color = "disposition-color-friendly"; + auto constexpr disposition_hostile_color = "disposition-color-hostile"; + auto constexpr disposition_secret_color = "disposition-color-secret"; + auto constexpr skip_defeated = "skip-defeated"; + } // namespace settings::key + + auto get_settings() -> Glib::RefPtr; +} // namespace turns::core + +#endif \ No newline at end of file diff --git a/gui/src/main.cpp b/gui/src/main.cpp new file mode 100644 index 0000000..030aa0f --- /dev/null +++ b/gui/src/main.cpp @@ -0,0 +1,97 @@ +// #include "turns/core/init.hpp" +// #include "turns/core/settings.hpp" +// #include "turns/ui/init.hpp" +// #include "turns/ui/tracker.hpp" + +// #include +// #include + +// #include + +// #include +// #include + +// #include +// #include +// #include + +// #include +// #include +// #include +// #include + +// #include + +// #include +// #include + +// auto show_about(Glib::RefPtr app) +// { +// auto active_window = app->get_active_window(); +// auto dialog = Gtk::make_managed("/ch/arknet/Turns/metainfo.xml", ""); +// dialog->present(active_window); +// } + +// auto main(int argc, char * argv[]) -> int +// { +// setlocale(LC_ALL, ""); +// bindtextdomain("turns", LOCALEDIR); +// bind_textdomain_codeset("turns", "UTF-8"); +// textdomain("turns"); + +// auto app = Adwaita::Application::create("ch.arknet.Turns", Gio::Application::Flags::HANDLES_OPEN); +// auto settings = turns::core::get_settings(); + +// turns::core::register_types(); + +// app->signal_startup().connect([app] { +// turns::ui::register_types(); + +// auto style_manager = Adwaita::StyleManager::get_default(); +// style_manager->set_color_scheme(Adwaita::ColorScheme::PreferLight); + +// app->add_action("quit", sigc::mem_fun(*app, &Adwaita::Application::quit)); +// app->add_action("about", sigc::bind(&show_about, app)); +// app->set_accel_for_action("app.quit", "q"); +// app->set_accel_for_action("win.clear", "x"); +// app->set_accel_for_action("win.next", "space"); +// app->set_accel_for_action("win.previous", "BackSpace"); +// app->set_accel_for_action("win.add_participant", "a"); +// app->set_accel_for_action("win.open", "o"); +// app->set_accel_for_action("win.preferences", "comma"); +// app->set_accel_for_action("win.save", "s"); +// app->set_accel_for_action("win.save-as", "s"); +// }); + +// app->signal_activate().connect([app, settings] { +// auto window = new turns::ui::Tracker{app, settings}; +// window->present(); +// }); + +// app->signal_open().connect([app, settings](auto files, auto) { +// auto windows = app->get_windows(); +// auto window = static_cast(nullptr); + +// if (windows.empty()) +// { +// window = new turns::ui::Tracker{app, settings}; +// } +// else +// { +// window = dynamic_cast(windows[0]); +// } + +// window->present(); +// window->load(files[0]); +// }); + +// app->signal_window_removed().connect([](auto window) { +// auto tracker = dynamic_cast(window); +// if (tracker) +// { +// delete tracker; +// } +// }); + +// return app->run(argc, argv); +// } \ No newline at end of file diff --git a/gui/style/CMakeLists.txt b/gui/style/CMakeLists.txt new file mode 100644 index 0000000..8ddbae8 --- /dev/null +++ b/gui/style/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library("style") + +add_library("turns::style" ALIAS "style") + +target_add_glib_resources("style" + PREFIX "ch/arknet/Turns" + CSS_FILES + "style.css" + "style-dark.css" +) + +target_link_libraries("style" PUBLIC + "PkgConfig::giomm" + PRIVATE + "$<$,$>:gcov>" +) + +enable_coverage("style") diff --git a/gui/style/style-dark.css b/gui/style/style-dark.css new file mode 100644 index 0000000..928264a --- /dev/null +++ b/gui/style/style-dark.css @@ -0,0 +1,32 @@ +@define-color hostile #e01b24; +@define-color friendly #33d17a; +@define-color secret #9141ac; + + +.disposition-hostile { + background-color: mix(shade(@hostile, 0.8), @window_bg_color, 0.5); +} + +:checked.disposition-hostile { + background-color: mix(shade(@hostile, 0.5), @window_bg_color, 0.5); +} + +.disposition-friendly { + background-color: mix(shade(@friendly, 0.8), @window_bg_color, 0.5); +} + +:checked.disposition-friendly { + background-color: mix(shade(@friendly, 0.5), @window_bg_color, 0.5); +} + +.disposition-secret { + background-color: mix(shade(@secret, 0.8), @window_bg_color, 0.5); +} + +:checked.disposition-secret { + background-color: mix(shade(@secret, 0.5), @window_bg_color, 0.5); +} + +.active-participant { + background-color: mix(shade(@accent_bg_color, 0.5), @card_bg_color, 0.5); +} \ No newline at end of file diff --git a/gui/style/style.css b/gui/style/style.css new file mode 100644 index 0000000..a185c9b --- /dev/null +++ b/gui/style/style.css @@ -0,0 +1,31 @@ +@define-color hostile #e01b24; +@define-color friendly #33d17a; +@define-color secret #9141ac; + +.disposition-hostile { + background-color: mix(shade(@hostile, 1.6), @window_bg_color, 0.5); +} + +:checked.disposition-hostile { + background-color: mix(shade(@hostile, 1), @window_bg_color, 0.5); +} + +.disposition-friendly { + background-color: mix(shade(@friendly, 1.6), @window_bg_color, 0.5); +} + +:checked.disposition-friendly { + background-color: mix(shade(@friendly, 1), @window_bg_color, 0.5); +} + +.disposition-secret { + background-color: mix(shade(@secret, 1.6), @window_bg_color, 0.5); +} + +:checked.disposition-secret { + background-color: mix(shade(@secret, 1), @window_bg_color, 0.5); +} + +.active-participant { + background-color: mix(shade(@accent_bg_color, 1.5), @card_bg_color, 0.5); +} \ No newline at end of file diff --git a/gui/ui/CMakeLists.txt b/gui/ui/CMakeLists.txt new file mode 100644 index 0000000..1584479 --- /dev/null +++ b/gui/ui/CMakeLists.txt @@ -0,0 +1,59 @@ +# Library + +file(GLOB_RECURSE UI_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" CONFIGURE_DEPENDS "*.ui") +file(GLOB_RECURSE UI_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "src/*.cpp") +file(GLOB_RECURSE UI_TESTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "tests/*.cpp") + +add_library("ui" ${UI_SOURCES}) +add_library("turns::ui" ALIAS "ui") + +target_compile_options("ui" PUBLIC + "$<$:-Wall>" + "$<$:-Wextra>" + "$<$:-Werror>" + "$<$:-pedantic-errors>" +) + +target_include_directories("ui" PUBLIC + "include" +) + +target_link_libraries("ui" PUBLIC + "turns::core" + "turns::lang" + + "adwaitamm::adwaitamm" + "PkgConfig::gtkmm" +) + +target_add_glib_resources("ui" + PREFIX "/ch/arknet/Turns/" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" + UI_FILES ${UI_FILES} +) + +enable_coverage("ui") + +# Tests + +get_target_property(TRANSLATIONS_BINARY_DIR "lang" BINARY_DIR) + +add_executable("ui-tests" ${UI_TESTS}) + +target_compile_definitions("ui-tests" PUBLIC + "TESTLOCALEDIR=\"${TRANSLATIONS_BINARY_DIR}\"" +) + +target_link_libraries("ui-tests" PRIVATE + "Catch2::Catch2WithMain" + + "$<$:-Wl,--whole-archive>" + "turns::ui" + "$<$:-Wl,--no-whole-archive>" +) + +target_link_options("ui-tests" PRIVATE + "$<$,$>:--coverage>" +) + +catch_discover_tests("ui-tests") diff --git a/gui/ui/include/turns/ui/fwd.hpp b/gui/ui/include/turns/ui/fwd.hpp new file mode 100644 index 0000000..69dc0b5 --- /dev/null +++ b/gui/ui/include/turns/ui/fwd.hpp @@ -0,0 +1,14 @@ +#ifndef TURNS_UI_WIDGETS_FWD_HPP +#define TURNS_UI_WIDGETS_FWD_HPP + +namespace turns::ui::widgets +{ + struct participant_editor; + struct participant_row; + struct preferences; + struct tracker; + struct turn_order_view; + struct preferences; +} // namespace turns::ui::widgets + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/init.hpp b/gui/ui/include/turns/ui/init.hpp new file mode 100644 index 0000000..77bd009 --- /dev/null +++ b/gui/ui/include/turns/ui/init.hpp @@ -0,0 +1,15 @@ +#ifndef TURNS_UI_INIT_HPP +#define TURNS_UI_INIT_HPP + +#include + +#include + +namespace turns::ui +{ + + auto register_types() -> void; + +} // namespace turns::ui + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/participant_editor.hpp b/gui/ui/include/turns/ui/participant_editor.hpp new file mode 100644 index 0000000..0fbc504 --- /dev/null +++ b/gui/ui/include/turns/ui/participant_editor.hpp @@ -0,0 +1,82 @@ +#ifndef TURNS_UI_PARTICIPANT_EDITOR_HPP +#define TURNS_UI_PARTICIPANT_EDITOR_HPP + +#include "turns/core/disposition.hpp" +#include "turns/core/fwd.hpp" +#include "turns/core/participant.hpp" +#include "turns/ui/template_widget.hpp" + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +namespace turns::ui +{ + + struct ParticipantEditor : template_widget + { + using SignalFinishedType = sigc::signal; + + auto constexpr inline static children = std::array{ + "disposition", + "finish", + "name", + "priority", + }; + + explicit ParticipantEditor(Glib::RefPtr participant); + + [[nodiscard]] auto get_disposition() const -> core::Disposition; + [[nodiscard]] auto get_name() const -> Glib::ustring; + [[nodiscard]] auto get_participant() const -> Glib::RefPtr; + [[nodiscard]] auto get_priority() const -> double; + + auto set_disposition(core::Disposition value) -> void; + auto set_name(Glib::ustring const & value) -> void; + auto set_participant(Glib::RefPtr const & value) -> void; + auto set_priority(double value) -> void; + + [[nodiscard]] auto property_participant() -> Glib::PropertyProxy>; + [[nodiscard]] auto property_participant() const -> Glib::PropertyProxy_ReadOnly>; + + auto signal_finished() -> SignalFinishedType; + + private: + auto handle_finish_clicked() -> void; + auto handle_item_bind(Glib::RefPtr item) -> void; + auto handle_item_setup(Glib::RefPtr item) -> void; + auto handle_participant_changed() -> void; + + Adwaita::ComboRow * m_disposition; + Gtk::Button * m_finish; + Adwaita::EntryRow * m_name; + Adwaita::SpinRow * m_priority; + + Glib::RefPtr m_disposition_factory; + Glib::RefPtr m_disposition_model; + + Glib::Property> m_participant; + + SignalFinishedType m_signal_finished{}; + }; + +} // namespace turns::ui + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/participant_row.hpp b/gui/ui/include/turns/ui/participant_row.hpp new file mode 100644 index 0000000..561214b --- /dev/null +++ b/gui/ui/include/turns/ui/participant_row.hpp @@ -0,0 +1,50 @@ +#ifndef TURNS_UI_PARTICIPANT_ROW_HPP +#define TURNS_UI_PARTICIPANT_ROW_HPP + +#include "turns/core/fwd.hpp" +#include "turns/ui/template_widget.hpp" + +#include +#include +#include + +#include +#include +#include +#include + +#include + +namespace turns::ui +{ + struct ParticipantRow : template_widget + { + auto constexpr inline static children = std::array{ + "delete", + "edit", + "subtitle", + "title", + "toggle_defeated", + }; + + ParticipantRow(Glib::RefPtr participant); + + auto delete_enabled() -> Glib::PropertyProxy; + auto edit_enabled() -> Glib::PropertyProxy; + + private: + auto handle_delete() -> void; + auto handle_edit() -> void; + + Gtk::Button * m_delete; + Gtk::Button * m_edit; + Gtk::Label * m_subtitle; + Gtk::Label * m_title; + Gtk::ToggleButton * m_toggle_defeated; + + Glib::Property m_delete_enabled; + Glib::Property m_edit_enabled; + }; +} // namespace turns::ui::widgets + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/preferences.hpp b/gui/ui/include/turns/ui/preferences.hpp new file mode 100644 index 0000000..b68b91c --- /dev/null +++ b/gui/ui/include/turns/ui/preferences.hpp @@ -0,0 +1,53 @@ +#ifndef TURNS_UI_PREFERENCES_HPP +#define TURNS_UI_PREFERENCES_HPP + +#include "turns/ui/template_widget.hpp" + +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +namespace turns::ui +{ + struct Preferences : template_widget + { + + auto constexpr inline static children = std::array{ + "friendly_reset_button", + "hostile_reset_button", + "secret_reset_button", + "friendly_color_button", + "hostile_color_button", + "secret_color_button", + "skip_defeated", + }; + + explicit Preferences(Glib::RefPtr settings = {}); + + private: + auto bind_reset(Glib::ustring const & key, Gtk::Button * button) -> void; + auto bind_setting(Glib::ustring const & key, Gtk::ColorDialogButton * button) -> void; + auto update_sensitive(Glib::ustring const & key, Gtk::Button * button) -> void; + + Glib::RefPtr m_settings; + + Gtk::Button * m_friendly_reset_button{}; + Gtk::Button * m_hostile_reset_button{}; + Gtk::Button * m_secret_reset_button{}; + Gtk::ColorDialogButton * m_friendly_color_button{}; + Gtk::ColorDialogButton * m_hostile_color_button{}; + Gtk::ColorDialogButton * m_secret_color_button{}; + Adwaita::SwitchRow * m_skip_defeated{}; + }; +} // namespace turns::ui::widgets + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/template_widget.hpp b/gui/ui/include/turns/ui/template_widget.hpp new file mode 100644 index 0000000..7147560 --- /dev/null +++ b/gui/ui/include/turns/ui/template_widget.hpp @@ -0,0 +1,67 @@ +#ifndef TURNS_UI_TEMPLATE_WIDGET_HPP +#define TURNS_UI_TEMPLATE_WIDGET_HPP + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +namespace turns::ui +{ + + template + struct template_widget : Glib::ExtraClassInit, + BaseWidgetType + { + template + template_widget(Glib::ustring && resource_path, BaseWidgetCtorArgTypes &&... base_widget_ctor_args) + : Glib::ExtraClassInit{class_init, &resource_path, instance_init} + , BaseWidgetType{std::forward(base_widget_ctor_args)...} + { + } + + protected: + template + auto get_widget(char const * name) -> WidgetType * + { + auto self = static_cast(this); + auto widget = GTK_WIDGET(Glib::unwrap(self)); + auto type = G_OBJECT_TYPE(Glib::unwrap(self)); + auto child = GTK_WIDGET(gtk_widget_get_template_child(widget, type, name)); + g_assert_nonnull(child); + return dynamic_cast(Glib::wrap(child)); + } + + private: + auto static class_init(void * g_class, void * g_class_data) -> void + { + g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class)); + + auto resource_path = static_cast(g_class_data); + + gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(g_class), resource_path->c_str()); + + std::ranges::for_each(CustomWidgetType::children, [g_class](auto const & child) { + gtk_widget_class_bind_template_child_full(GTK_WIDGET_CLASS(g_class), child, false, 0); + }); + } + + auto static instance_init(GTypeInstance * instance, void * /* type_class */) -> void + { + g_return_if_fail(GTK_IS_WIDGET(instance)); + + gtk_widget_init_template(GTK_WIDGET(instance)); + } + }; + +} // namespace turns::ui::widgets + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/tracker.hpp b/gui/ui/include/turns/ui/tracker.hpp new file mode 100644 index 0000000..2e3adf5 --- /dev/null +++ b/gui/ui/include/turns/ui/tracker.hpp @@ -0,0 +1,104 @@ +#ifndef TURNS_UI_TRACKER_HPP +#define TURNS_UI_TRACKER_HPP + +#include "turns/core/turn_order_model.hpp" +#include "turns/ui/template_widget.hpp" +#include "turns/ui/turn_order_view.hpp" + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace turns::ui +{ + + struct Tracker : template_widget + { + auto constexpr inline static children = std::array{ + "controls", + "empty", + "overlay", + "stack", + "start", + "title", + }; + + Tracker(Glib::RefPtr const & app, Glib::RefPtr const & settings); + + auto load(Glib::RefPtr file) -> void; + + private: + friend auto register_types() -> void; + Tracker(); + + /** Setup */ + auto setup_actions() -> void; + auto setup_colors() -> void; + + /** Actions */ + auto add_participant() -> void; + auto delete_participant(Glib::VariantBase param) -> void; + auto edit_participant(Glib::VariantBase param) -> void; + auto open() -> void; + auto preferences() -> void; + auto save(bool force_ask) -> void; + auto stop() -> void; + + /** Event Handlers */ + auto on_open_response(Glib::RefPtr result, Glib::RefPtr dialog) -> void; + auto on_save_response(Glib::RefPtr result, Glib::RefPtr dialog) -> void; + auto on_load_content_done(Glib::RefPtr result) -> void; + auto on_replace_content_done(Glib::RefPtr result) -> void; + auto on_settings_changed(Glib::ustring key) -> void; + + /** Helpers */ + auto show_error(std::exception const & e) -> void; + auto show_toast(std::string const & message) -> void; + auto start_replace_content() -> void; + auto update_colors() -> void; + auto update_subtitle() -> void; + + Gtk::Revealer * m_controls; + Gtk::Widget * m_empty; + Adwaita::ToastOverlay * m_overlay; + Gtk::Stack * m_stack; + Gtk::Button * m_start; + Adwaita::WindowTitle * m_title; + Glib::RefPtr m_turn_order; + TurnOrderView * m_turn_order_view; + Glib::RefPtr m_settings{}; + Glib::PropertyProxy m_subtitle; + + Glib::RefPtr m_file{}; + std::string m_file_etag{}; + std::string m_file_buffer{}; + + Glib::RefPtr m_css{}; + }; + +} // namespace turns::ui + +#endif \ No newline at end of file diff --git a/gui/ui/include/turns/ui/turn_order_view.hpp b/gui/ui/include/turns/ui/turn_order_view.hpp new file mode 100644 index 0000000..8dae4e4 --- /dev/null +++ b/gui/ui/include/turns/ui/turn_order_view.hpp @@ -0,0 +1,40 @@ +#ifndef TURNS_UI_TURN_ORDER_VIEW_HPP +#define TURNS_UI_TURN_ORDER_VIEW_HPP + +#include "turns/core/fwd.hpp" +#include "turns/core/turn_order_model.hpp" +#include "turns/ui/template_widget.hpp" + +#include +#include + +#include +#include +#include +#include + +#include + +namespace turns::ui +{ + struct TurnOrderView : template_widget + { + using model_type = core::TurnOderModel; + + auto constexpr inline static children = std::array{ + "progress", + "view", + }; + + explicit TurnOrderView(Glib::RefPtr model = {}); + + private: + auto handle_create_row(Glib::RefPtr const item) -> Gtk::Widget *; + + Glib::RefPtr m_model; + Gtk::ProgressBar * m_progress; + Gtk::ListBox * m_view; + }; +} // namespace turns::ui::widgets + +#endif \ No newline at end of file diff --git a/gui/ui/src/init.cpp b/gui/ui/src/init.cpp new file mode 100644 index 0000000..1c0295a --- /dev/null +++ b/gui/ui/src/init.cpp @@ -0,0 +1,23 @@ +#include "turns/ui/init.hpp" + +#include "turns/ui/participant_editor.hpp" +#include "turns/ui/participant_row.hpp" +#include "turns/ui/preferences.hpp" +#include "turns/ui/tracker.hpp" +#include "turns/ui/turn_order_view.hpp" +#include +#include + +namespace turns::ui +{ + + auto register_types() -> void + { + static_cast(ParticipantEditor{{}}); + static_cast(ParticipantRow{{}}); + static_cast(Preferences{{}}); + static_cast(Tracker{}); + static_cast(TurnOrderView{{}}); + } + +} // namespace turns::ui \ No newline at end of file diff --git a/gui/ui/src/participant_editor.cpp b/gui/ui/src/participant_editor.cpp new file mode 100644 index 0000000..8c83559 --- /dev/null +++ b/gui/ui/src/participant_editor.cpp @@ -0,0 +1,162 @@ +#include "turns/ui/participant_editor.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" +#include "turns/lang/messages.hpp" +#include "turns/ui/template_widget.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace turns::ui +{ + namespace + { + auto constexpr static TYPE_NAME = "ParticipantEditor"; + auto constexpr static TEMPLATE = "/ch/arknet/Turns/participant_editor.ui"; + } // namespace + + ParticipantEditor::ParticipantEditor(Glib::RefPtr participant) + : Glib::ObjectBase{TYPE_NAME} + , template_widget{TEMPLATE} + , m_disposition{get_widget("disposition")} + , m_finish{get_widget("finish")} + , m_name{get_widget("name")} + , m_priority{get_widget("priority")} + , m_disposition_factory{Gtk::SignalListItemFactory::create()} + , m_disposition_model{Gtk::StringList::create()} + , m_participant{*this, "participant", nullptr} + { + m_finish->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantEditor::handle_finish_clicked)); + + for (auto n : std::views::iota(std::uint8_t{}, static_cast(core::Disposition::END))) + { + m_disposition_model->append(presentation_name_for(core::Disposition{n})); + } + + m_disposition_factory->signal_bind().connect(sigc::mem_fun(*this, &ParticipantEditor::handle_item_bind)); + m_disposition_factory->signal_setup().connect(sigc::mem_fun(*this, &ParticipantEditor::handle_item_setup)); + + m_disposition->set_factory(m_disposition_factory); + m_disposition->set_model(m_disposition_model); + + property_participant().signal_changed().connect(sigc::mem_fun(*this, &ParticipantEditor::handle_participant_changed)); + + set_participant(participant); + } + + auto ParticipantEditor::get_disposition() const -> core::Disposition + { + return static_cast(m_disposition->get_selected()); + } + + auto ParticipantEditor::get_name() const -> Glib::ustring + { + return m_name->get_text(); + } + + auto ParticipantEditor::get_participant() const -> Glib::RefPtr + { + return m_participant.get_value(); + } + + auto ParticipantEditor::get_priority() const -> double + { + return m_priority->get_value(); + } + + auto ParticipantEditor::set_disposition(core::Disposition value) -> void + { + m_disposition->set_selected(static_cast(value)); + } + + auto ParticipantEditor::set_name(Glib::ustring const & value) -> void + { + m_name->set_text(value); + } + + auto ParticipantEditor::set_participant(Glib::RefPtr const & value) -> void + { + m_participant.set_value(value); + } + + auto ParticipantEditor::set_priority(double value) -> void + { + m_priority->set_value(value); + } + + auto ParticipantEditor::property_participant() -> Glib::PropertyProxy> + { + return m_participant.get_proxy(); + } + + auto ParticipantEditor::property_participant() const -> Glib::PropertyProxy_ReadOnly> + { + return m_participant.get_proxy(); + } + + auto ParticipantEditor::signal_finished() -> SignalFinishedType + { + return m_signal_finished; + } + + auto ParticipantEditor::handle_finish_clicked() -> void + { + m_signal_finished.emit(m_name->get_text(), m_priority->get_value(), static_cast(m_disposition->get_selected())); + close(); + } + + auto ParticipantEditor::handle_item_bind(Glib::RefPtr item) -> void + { + auto value = std::dynamic_pointer_cast(item->get_item())->get_string(); + dynamic_cast(item->get_child())->set_label(value); + } + + auto ParticipantEditor::handle_item_setup(Glib::RefPtr item) -> void + { + item->set_child(*Gtk::make_managed()); + } + + auto ParticipantEditor::handle_participant_changed() -> void + { + auto value = m_participant.get_value(); + set_title(_(value ? lang::edit_participant : lang::add_participant)); + if (value) + { + Glib::Binding::bind_property(value->property_name(), + m_name->property_text(), + Glib::Binding::Flags::BIDIRECTIONAL | Glib::Binding::Flags::SYNC_CREATE); + Glib::Binding::bind_property(value->property_priority(), + m_priority->property_value(), + Glib::Binding::Flags::BIDIRECTIONAL | Glib::Binding::Flags::SYNC_CREATE); + Glib::Binding::bind_property(value->property_disposition(), + m_disposition->property_selected(), + Glib::Binding::Flags::BIDIRECTIONAL | Glib::Binding::Flags::SYNC_CREATE, + [](auto value) { return static_cast(value); }, + [](auto value) { return static_cast(value); }); + } + } + +} // namespace turns::ui \ No newline at end of file diff --git a/gui/ui/src/participant_editor.ui b/gui/ui/src/participant_editor.ui new file mode 100644 index 0000000..6bcf83e --- /dev/null +++ b/gui/ui/src/participant_editor.ui @@ -0,0 +1,71 @@ + + + + + + + + diff --git a/gui/ui/src/participant_row.cpp b/gui/ui/src/participant_row.cpp new file mode 100644 index 0000000..7ce8e53 --- /dev/null +++ b/gui/ui/src/participant_row.cpp @@ -0,0 +1,149 @@ +#include "turns/ui/participant_row.hpp" + +#include "turns/core/disposition.hpp" +#include "turns/core/participant.hpp" +#include "turns/lang/messages.hpp" +#include "turns/ui/template_widget.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace turns::ui +{ + namespace + { + auto constexpr static TYPE_NAME = "ParticipantRow"; + auto constexpr static TEMPLATE = "/ch/arknet/Turns/participant_row.ui"; + + auto css_class_for(core::Disposition value) -> Glib::ustring + { + switch (value) + { + case core::Disposition::Friendly: + return "disposition-friendly"; + case core::Disposition::Hostile: + return "disposition-hostile"; + case core::Disposition::Secret: + return "disposition-secret"; + default: + return ""; + } + } + } // namespace + + ParticipantRow::ParticipantRow(Glib::RefPtr participant) + : Glib::ObjectBase(TYPE_NAME) + , template_widget{TEMPLATE} + , m_delete{get_widget("delete")} + , m_edit{get_widget("edit")} + , m_subtitle{get_widget("subtitle")} + , m_title{get_widget("title")} + , m_toggle_defeated{get_widget("toggle_defeated")} + , m_delete_enabled{*this, "delete-enabled", true} + , m_edit_enabled{*this, "edit-enabled", true} + + { + m_delete->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantRow::handle_delete)); + m_edit->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantRow::handle_edit)); + + Glib::Binding::bind_property(m_subtitle->property_label(), + m_subtitle->property_visible(), + Glib::Binding::Flags::DEFAULT, + sigc::mem_fun(&Glib::ustring::size)); + Glib::Binding::bind_property(m_title->property_label(), + m_title->property_visible(), + Glib::Binding::Flags::INVERT_BOOLEAN, + sigc::mem_fun(&Glib::ustring::size)); + Glib::Binding::bind_property(m_toggle_defeated->property_active(), + m_toggle_defeated->property_icon_name(), + Glib::Binding::Flags::SYNC_CREATE, + [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); + + // clang-format off + Glib::Binding::bind_property(delete_enabled(), + m_delete->property_sensitive(), + Glib::Binding::Flags::SYNC_CREATE); + Glib::Binding::bind_property(edit_enabled(), + m_edit->property_sensitive(), + Glib::Binding::Flags::SYNC_CREATE); + // clang-format on + + if (participant) + { + Glib::Binding::bind_property(participant->property_name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE); + + Glib::Binding::bind_property(participant->property_priority(), + m_subtitle->property_label(), + Glib::Binding::Flags::SYNC_CREATE, + [](auto n) { return std::vformat(_(lang::priority_number), std::make_format_args(n)); }); + + Glib::Binding::bind_property(participant->property_disposition(), + m_toggle_defeated->property_css_classes(), + Glib::Binding::Flags::SYNC_CREATE, + [this](auto value) { + auto classes = m_toggle_defeated->get_css_classes(); + auto removed = std::ranges::remove_if(classes, [](auto cls) { + return (cls == "disposition-friendly") | (cls == "disposition-hostile") || (cls == "disposition-secret"); + }); + classes.erase(removed.begin(), removed.end()); + classes.push_back(css_class_for(value)); + return classes; + }); + + Glib::Binding::bind_property(participant->property_is_active(), + property_css_classes(), + Glib::Binding::Flags::SYNC_CREATE, + [this](auto value) { + auto classes = get_css_classes(); + if (!value) + { + std::erase(classes, "active-participant"); + } + else + { + classes.push_back("active-participant"); + } + return classes; + }); + } + } + + auto ParticipantRow::delete_enabled() -> Glib::PropertyProxy + { + return m_delete_enabled.get_proxy(); + } + + auto ParticipantRow::edit_enabled() -> Glib::PropertyProxy + { + return m_edit_enabled.get_proxy(); + } + + auto ParticipantRow::handle_delete() -> void + { + auto index = Glib::Variant::create(get_index()); + activate_action("win.delete", index); + } + + auto ParticipantRow::handle_edit() -> void + { + auto index = Glib::Variant::create(get_index()); + activate_action("win.edit", index); + } + +} // namespace turns::ui \ No newline at end of file diff --git a/gui/ui/src/participant_row.ui b/gui/ui/src/participant_row.ui new file mode 100644 index 0000000..b53cc53 --- /dev/null +++ b/gui/ui/src/participant_row.ui @@ -0,0 +1,89 @@ + + + + + +