summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-07-24 19:47:52 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-07-24 19:47:52 +0200
commiteec83198b5dfdfe9a0db71b410383697eb58930c (patch)
treee2a1d890431c4c23f754236f33a909b521932afb /core
parent7546a80eccb64b6ac38b3f22ae83fa1c6af1f1c5 (diff)
downloadturns-eec83198b5dfdfe9a0db71b410383697eb58930c.tar.xz
turns-eec83198b5dfdfe9a0db71b410383697eb58930c.zip
app: add progress bar for turn order
Diffstat (limited to 'core')
-rw-r--r--core/include/turns/core/turn_order.hpp3
-rw-r--r--core/src/turn_order.cpp13
2 files changed, 16 insertions, 0 deletions
diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp
index 59cab84..59556bb 100644
--- a/core/include/turns/core/turn_order.hpp
+++ b/core/include/turns/core/turn_order.hpp
@@ -30,6 +30,7 @@ namespace turns::core
using has_next_type = bool;
using has_previous_type = bool;
using is_running_type = bool;
+ using progress_type = double;
using round_number_type = unsigned int;
auto static constexpr invalid_participant_index = std::numeric_limits<active_participant_type>::max();
@@ -45,6 +46,7 @@ namespace turns::core
auto has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>;
auto has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>;
auto is_running() const -> Glib::PropertyProxy_ReadOnly<is_running_type>;
+ auto progress() const -> Glib::PropertyProxy_ReadOnly<progress_type>;
auto round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>;
/** Element Modifications */
@@ -77,6 +79,7 @@ namespace turns::core
Glib::Property<has_previous_type> m_has_previous{*this, "has-previous", false};
Glib::Property<is_empty_type> m_is_empty{*this, "is-empty", true};
Glib::Property<is_running_type> m_is_running{*this, "is-running", false};
+ Glib::Property<progress_type> m_progress{*this, "progress", 0.0};
Glib::Property<round_number_type> m_round_number{*this, "round-number", invalid_round_number};
};
diff --git a/core/src/turn_order.cpp b/core/src/turn_order.cpp
index 234f394..835baab 100644
--- a/core/src/turn_order.cpp
+++ b/core/src/turn_order.cpp
@@ -56,6 +56,11 @@ namespace turns::core
return m_is_running.get_proxy();
}
+ auto turn_order::progress() const -> Glib::PropertyProxy_ReadOnly<progress_type>
+ {
+ return m_progress.get_proxy();
+ }
+
auto turn_order::round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>
{
return m_round_number.get_proxy();
@@ -85,6 +90,7 @@ namespace turns::core
m_has_previous = false;
m_active.reset();
m_round_number = invalid_round_number;
+ m_progress = 0;
auto old_size = get_n_items();
m_data.clear();
@@ -100,6 +106,8 @@ namespace turns::core
m_data[old_active]->is_active() = false;
m_data[*m_active]->is_active() = true;
+ m_progress = (static_cast<float>(*m_active) + 1) / get_n_items();
+
if (m_active == 0)
{
m_round_number = m_round_number + 1;
@@ -120,6 +128,8 @@ namespace turns::core
m_data[old_active]->is_active() = false;
m_data[*m_active]->is_active() = true;
+ m_progress = (static_cast<float>(*m_active) + 1) / get_n_items();
+
if (m_active == 0 && m_round_number > 0)
{
m_round_number = m_round_number - 1;
@@ -156,11 +166,14 @@ namespace turns::core
m_round_number = 0;
}
m_is_running = true;
+
+ m_progress = (static_cast<float>(*m_active) + 1) / get_n_items();
}
auto turn_order::stop() -> void
{
m_is_running = false;
+ m_progress = 0;
}
/** ListModel implementation */