diff options
Diffstat (limited to 'lib/src')
| -rw-r--r-- | lib/src/turns-turn-order.c | 27 | ||||
| -rw-r--r-- | lib/src/turnsmm/turn-order.cpp | 10 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/src/turns-turn-order.c b/lib/src/turns-turn-order.c index 1861888..b192d74 100644 --- a/lib/src/turns-turn-order.c +++ b/lib/src/turns-turn-order.c @@ -18,6 +18,7 @@ enum PROP_EMPTY = 1, PROP_PARTICIPANT_COUNT, PROP_RUNNING, + PROP_ROUND_PROGRESS, PROP_SORT_MODE, N_PROPERTIES, }; @@ -26,6 +27,7 @@ struct _TurnsTurnOrder { GObject parent_instance; + gsize active; GSList * participants; gboolean running; TurnsTurnOrderSortMode sort_mode; @@ -120,6 +122,9 @@ static void turns_turn_order_get_property(GObject * self, guint id, GValue * val case PROP_RUNNING: g_value_set_boolean(value, turns_turn_order_get_running(instance)); return; + case PROP_ROUND_PROGRESS: + g_value_set_float(value, turns_turn_order_get_round_progress(instance)); + return; case PROP_SORT_MODE: g_value_set_enum(value, turns_turn_order_get_sort_mode(instance)); return; @@ -144,6 +149,7 @@ static void turns_turn_order_set_property(GObject * self, guint id, GValue const static void turns_turn_order_init(TurnsTurnOrder * self) { + self->active = 0; self->participants = nullptr; self->running = false; self->sort_mode = TURNS_TURN_ORDER_SORT_MODE_DESCENDING; @@ -186,6 +192,14 @@ static void turns_turn_order_class_init(TurnsTurnOrderClass * klass) false, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY); + properties[PROP_ROUND_PROGRESS] = g_param_spec_float("round-progress", + "Round Progress", + "The current progress of the round.", + 0.0f, + 1.0f, + 0.0f, + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY); + properties[PROP_SORT_MODE] = g_param_spec_enum("sort-mode", "Sort Mode", "The sort mode applied to the turn order", @@ -304,6 +318,19 @@ gboolean turns_turn_order_get_running(TurnsTurnOrder const * self) return self->running; } +gfloat turns_turn_order_get_round_progress(TurnsTurnOrder const * self) +{ + g_return_val_if_fail(TURNS_IS_TURN_ORDER((TurnsTurnOrder *)self), 0.0f); + + auto participant_count = turns_turn_order_get_participant_count(self); + if (participant_count == 0) + { + return 0.0f; + } + + return ((gfloat)(self->active + 1)) / ((gfloat)participant_count); +} + TurnsTurnOrderSortMode turns_turn_order_get_sort_mode(TurnsTurnOrder const * self) { g_return_val_if_fail(TURNS_IS_TURN_ORDER((TurnsTurnOrder *)self), TURNS_TURN_ORDER_SORT_MODE_ASCENDING); diff --git a/lib/src/turnsmm/turn-order.cpp b/lib/src/turnsmm/turn-order.cpp index ae9bd43..58f4527 100644 --- a/lib/src/turnsmm/turn-order.cpp +++ b/lib/src/turnsmm/turn-order.cpp @@ -118,6 +118,11 @@ namespace Turns return turns_turn_order_get_running(unwrap(this)); } + auto TurnOrder::get_round_progress() const noexcept -> float + { + return turns_turn_order_get_round_progress(unwrap(this)); + } + auto TurnOrder::get_sort_mode() const noexcept -> SortMode { return static_cast<SortMode>(turns_turn_order_get_sort_mode(unwrap(this))); @@ -143,6 +148,11 @@ namespace Turns return {this, "running"}; } + auto TurnOrder::property_round_progress() const noexcept -> Glib::PropertyProxy_ReadOnly<float> + { + return {this, "round-progress"}; + } + auto TurnOrder::property_sort_mode() noexcept -> Glib::PropertyProxy<SortMode> { return {this, "sort-mode"}; |
