From 72ab1fb4c1bf363f46470816d8b914a78ac493c4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 24 May 2025 11:58:39 +0200 Subject: gui: restructure file layout and apply licenses --- .clang-format | 5 +- .clangd | 3 - .gitlab-ci.yml | 3 - .gitmodules | 3 - REUSE.toml | 28 +++ gui/CMakeLists.txt | 3 +- gui/desktop.in | 3 + gui/gschema.xml | 27 +++ gui/include/messages.hpp | 54 +++++ gui/include/participant_editor.hpp | 87 +++++++++ gui/include/participant_row.hpp | 55 ++++++ gui/include/preferences.hpp | 58 ++++++ gui/include/settings.hpp | 26 +++ gui/include/template_widget.hpp | 72 +++++++ gui/include/tracker.hpp | 109 +++++++++++ gui/include/turn_order_view.hpp | 45 +++++ gui/lang/CMakeLists.txt | 77 -------- gui/lang/de.po | 132 +++++++++++++ gui/lang/de_CH.po | 12 ++ gui/lang/en.po | 132 +++++++++++++ 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 | 2 + gui/mime.xml | 2 + gui/schemas/ch.arknet.Turns.gschema.xml | 25 --- gui/settings.cpp | 28 --- gui/settings.hpp | 21 -- gui/src/main.cpp | 5 + gui/src/participant_editor.cpp | 167 ++++++++++++++++ gui/src/participant_row.cpp | 154 +++++++++++++++ gui/src/preferences.cpp | 86 ++++++++ gui/src/settings.cpp | 33 ++++ gui/src/tracker.cpp | 260 +++++++++++++++++++++++++ gui/src/tracker_actions.cpp | 130 +++++++++++++ gui/src/tracker_event_handlers.cpp | 110 +++++++++++ gui/src/turn_order_view.cpp | 69 +++++++ gui/style/CMakeLists.txt | 18 -- gui/style/style-dark.css | 32 --- gui/style/style.css | 31 --- gui/tests/gtk_test_init.cpp | 46 +++++ gui/tests/intl_test_init.cpp | 31 +++ gui/tests/messages.cpp | 77 ++++++++ gui/tests/participant_editor.cpp | 155 +++++++++++++++ gui/tests/participant_row.cpp | 35 ++++ gui/tests/resources.cpp | 26 +++ gui/tests/tracker.cpp | 84 ++++++++ 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/participant_editor.ui | 71 +++++++ gui/ui/participant_row.ui | 89 +++++++++ gui/ui/preferences.ui | 104 ++++++++++ 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/style-dark.css | 32 +++ gui/ui/style.css | 31 +++ 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/tracker.ui | 153 +++++++++++++++ gui/ui/turn_order_view.ui | 38 ++++ gui/ui/turns.cmb | 10 + gui/ui/ui.cmb | 10 - 86 files changed, 2843 insertions(+), 2903 deletions(-) create mode 100644 REUSE.toml create mode 100644 gui/gschema.xml create mode 100644 gui/include/messages.hpp create mode 100644 gui/include/participant_editor.hpp create mode 100644 gui/include/participant_row.hpp create mode 100644 gui/include/preferences.hpp create mode 100644 gui/include/settings.hpp create mode 100644 gui/include/template_widget.hpp create mode 100644 gui/include/tracker.hpp create mode 100644 gui/include/turn_order_view.hpp delete mode 100644 gui/lang/CMakeLists.txt create mode 100644 gui/lang/de.po create mode 100644 gui/lang/de_CH.po create mode 100644 gui/lang/en.po delete mode 100644 gui/lang/include/turns/lang/messages.hpp delete mode 100644 gui/lang/po/de.po delete mode 100644 gui/lang/po/de_CH.po delete mode 100644 gui/lang/po/en.po delete mode 100644 gui/lang/tests/intl_test_init.cpp delete mode 100644 gui/lang/tests/messages.cpp delete mode 100644 gui/schemas/ch.arknet.Turns.gschema.xml delete mode 100644 gui/settings.cpp delete mode 100644 gui/settings.hpp create mode 100644 gui/src/participant_editor.cpp create mode 100644 gui/src/participant_row.cpp create mode 100644 gui/src/preferences.cpp create mode 100644 gui/src/settings.cpp create mode 100644 gui/src/tracker.cpp create mode 100644 gui/src/tracker_actions.cpp create mode 100644 gui/src/tracker_event_handlers.cpp create mode 100644 gui/src/turn_order_view.cpp delete mode 100644 gui/style/CMakeLists.txt delete mode 100644 gui/style/style-dark.css delete mode 100644 gui/style/style.css create mode 100644 gui/tests/gtk_test_init.cpp create mode 100644 gui/tests/intl_test_init.cpp create mode 100644 gui/tests/messages.cpp create mode 100644 gui/tests/participant_editor.cpp create mode 100644 gui/tests/participant_row.cpp create mode 100644 gui/tests/resources.cpp create mode 100644 gui/tests/tracker.cpp delete mode 100644 gui/ui/CMakeLists.txt delete mode 100644 gui/ui/include/turns/ui/fwd.hpp delete mode 100644 gui/ui/include/turns/ui/init.hpp delete mode 100644 gui/ui/include/turns/ui/participant_editor.hpp delete mode 100644 gui/ui/include/turns/ui/participant_row.hpp delete mode 100644 gui/ui/include/turns/ui/preferences.hpp delete mode 100644 gui/ui/include/turns/ui/template_widget.hpp delete mode 100644 gui/ui/include/turns/ui/tracker.hpp delete mode 100644 gui/ui/include/turns/ui/turn_order_view.hpp create mode 100644 gui/ui/participant_editor.ui create mode 100644 gui/ui/participant_row.ui create mode 100644 gui/ui/preferences.ui delete mode 100644 gui/ui/src/init.cpp delete mode 100644 gui/ui/src/participant_editor.cpp delete mode 100644 gui/ui/src/participant_editor.ui delete mode 100644 gui/ui/src/participant_row.cpp delete mode 100644 gui/ui/src/participant_row.ui delete mode 100644 gui/ui/src/preferences.cpp delete mode 100644 gui/ui/src/preferences.ui delete mode 100644 gui/ui/src/tracker.cpp delete mode 100644 gui/ui/src/tracker.ui delete mode 100644 gui/ui/src/tracker/actions.cpp delete mode 100644 gui/ui/src/tracker/event_handlers.cpp delete mode 100644 gui/ui/src/turn_order_view.cpp delete mode 100644 gui/ui/src/turn_order_view.ui create mode 100644 gui/ui/style-dark.css create mode 100644 gui/ui/style.css delete mode 100644 gui/ui/tests/gtk_test_init.cpp delete mode 100644 gui/ui/tests/participant_editor.cpp delete mode 100644 gui/ui/tests/participant_row.cpp delete mode 100644 gui/ui/tests/resources.cpp delete mode 100644 gui/ui/tests/tracker.cpp create mode 100644 gui/ui/tracker.ui create mode 100644 gui/ui/turn_order_view.ui create mode 100644 gui/ui/turns.cmb delete mode 100644 gui/ui/ui.cmb diff --git a/.clang-format b/.clang-format index 98b4862..187d49c 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,4 @@ -# SPDX-FileCopyrightText: 2025 Felix Morgner -# SPDX-License-Identifier: CC0-1.0 - ---- +--- Language: Cpp AccessModifierOffset: -2 diff --git a/.clangd b/.clangd index 08ec78d..2c38de5 100644 --- a/.clangd +++ b/.clangd @@ -1,6 +1,3 @@ -# SPDX-FileCopyrightText: 2025 Felix Morgner -# SPDX-License-Identifier: CC0-1.0 - CompileFlags: Remove: [-fmodules-ts, -fdeps-format=*, -fmodule-mapper=*, -fcondition-coverage] Diagnostics: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8df6d7b..faea96e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,3 @@ -# SPDX-FileCopyrightText: 2025 Felix Morgner -# SPDX-License-Identifier: CC0-1.0 - stages: - build - coverage diff --git a/.gitmodules b/.gitmodules index 92078e8..a29ece2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -# SPDX-FileCopyrightText: 2025 Felix Morgner -# SPDX-License-Identifier: CC0-1.0 - [submodule "deps/libadwaitamm"] path = deps/libadwaitamm url = ../libadwaitamm.git diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..5a94cb2 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,28 @@ +version = 1 + +[[annotations]] +path = [ + "gui/**.cmb", + "gui/**.css", + "gui/**.po", + "gui/**.ui", + "cmake/Modules/GlibCompileResources.in" +] +precedence = "aggregate" +SPDX-FileCopyrightText = "2025 Felix Morgner " +SPDX-License-Identifier = "LGPL-2.1-only" + +[[annotations]] +path = [ + ".vscode/**.json", + ".clang-format", + ".clangd", + ".gitmodules", + ".gitlab-ci.yml", + ".lcovrc", + "CMakePresets.json", + "README.md", +] +precedence = "aggregate" +SPDX-FileCopyrightText = "2025 Felix Morgner " +SPDX-License-Identifier = "CC0-1.0" \ No newline at end of file diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 1ae7a31..ebdb1be 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -1,4 +1,5 @@ - +# SPDX-FileCopyrightText: 2025 Felix Morgner +# SPDX-License-Identifier: LGPL-2.1-only # add_executable("app" # "src/main.cpp" diff --git a/gui/desktop.in b/gui/desktop.in index 99c0307..7e767ba 100644 --- a/gui/desktop.in +++ b/gui/desktop.in @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2025 Felix Morgner +# SPDX-License-Identifier: LGPL-2.1-only + [Desktop Entry] Type=Application Name=Turns diff --git a/gui/gschema.xml b/gui/gschema.xml new file mode 100644 index 0000000..bea1f8b --- /dev/null +++ b/gui/gschema.xml @@ -0,0 +1,27 @@ + + + + + + + '#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/include/messages.hpp b/gui/include/messages.hpp new file mode 100644 index 0000000..e29580b --- /dev/null +++ b/gui/include/messages.hpp @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/participant_editor.hpp b/gui/include/participant_editor.hpp new file mode 100644 index 0000000..39b721c --- /dev/null +++ b/gui/include/participant_editor.hpp @@ -0,0 +1,87 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/participant_row.hpp b/gui/include/participant_row.hpp new file mode 100644 index 0000000..81b3610 --- /dev/null +++ b/gui/include/participant_row.hpp @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/preferences.hpp b/gui/include/preferences.hpp new file mode 100644 index 0000000..c5bace3 --- /dev/null +++ b/gui/include/preferences.hpp @@ -0,0 +1,58 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/settings.hpp b/gui/include/settings.hpp new file mode 100644 index 0000000..70e429a --- /dev/null +++ b/gui/include/settings.hpp @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/template_widget.hpp b/gui/include/template_widget.hpp new file mode 100644 index 0000000..f90b473 --- /dev/null +++ b/gui/include/template_widget.hpp @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/tracker.hpp b/gui/include/tracker.hpp new file mode 100644 index 0000000..d639aee --- /dev/null +++ b/gui/include/tracker.hpp @@ -0,0 +1,109 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/include/turn_order_view.hpp b/gui/include/turn_order_view.hpp new file mode 100644 index 0000000..9a7ede6 --- /dev/null +++ b/gui/include/turn_order_view.hpp @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/lang/CMakeLists.txt b/gui/lang/CMakeLists.txt deleted file mode 100644 index 1842615..0000000 --- a/gui/lang/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -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/de.po b/gui/lang/de.po new file mode 100644 index 0000000..15c2d72 --- /dev/null +++ b/gui/lang/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/de_CH.po b/gui/lang/de_CH.po new file mode 100644 index 0000000..e79f91e --- /dev/null +++ b/gui/lang/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/en.po b/gui/lang/en.po new file mode 100644 index 0000000..54df09f --- /dev/null +++ b/gui/lang/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/include/turns/lang/messages.hpp b/gui/lang/include/turns/lang/messages.hpp deleted file mode 100644 index e57fce4..0000000 --- a/gui/lang/include/turns/lang/messages.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#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 deleted file mode 100644 index 15c2d72..0000000 --- a/gui/lang/po/de.po +++ /dev/null @@ -1,132 +0,0 @@ -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 deleted file mode 100644 index e79f91e..0000000 --- a/gui/lang/po/de_CH.po +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 54df09f..0000000 --- a/gui/lang/po/en.po +++ /dev/null @@ -1,132 +0,0 @@ -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 deleted file mode 100644 index 5438179..0000000 --- a/gui/lang/tests/intl_test_init.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#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 deleted file mode 100644 index cecb038..0000000 --- a/gui/lang/tests/messages.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#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 index 621c1ee..f8beb6b 100644 --- a/gui/metainfo.xml +++ b/gui/metainfo.xml @@ -1,4 +1,6 @@ + + ch.arknet.Turns CC-BY-SA-4.0 diff --git a/gui/mime.xml b/gui/mime.xml index 92e0ff4..ffa6d31 100644 --- a/gui/mime.xml +++ b/gui/mime.xml @@ -1,4 +1,6 @@ + + Turn order file diff --git a/gui/schemas/ch.arknet.Turns.gschema.xml b/gui/schemas/ch.arknet.Turns.gschema.xml deleted file mode 100644 index d764608..0000000 --- a/gui/schemas/ch.arknet.Turns.gschema.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - '#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 deleted file mode 100644 index 13cf665..0000000 --- a/gui/settings.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#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 deleted file mode 100644 index 304394d..0000000 --- a/gui/settings.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#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 index 030aa0f..a1f9843 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + // #include "turns/core/init.hpp" // #include "turns/core/settings.hpp" // #include "turns/ui/init.hpp" diff --git a/gui/src/participant_editor.cpp b/gui/src/participant_editor.cpp new file mode 100644 index 0000000..998d566 --- /dev/null +++ b/gui/src/participant_editor.cpp @@ -0,0 +1,167 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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/src/participant_row.cpp b/gui/src/participant_row.cpp new file mode 100644 index 0000000..c0f53df --- /dev/null +++ b/gui/src/participant_row.cpp @@ -0,0 +1,154 @@ +/* + * SPDX-FileCopyrightText: 2025 Felix Morgner + * SPDX-License-Identifier: LGPL-2.1-only + */ + +#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"); + } + r