Files
Dreierpack-Manager/src/ui/analytics.hpp
T
ClaudeandClaude Sonnet 5.5 287b5a9251 Add header comments to the source files
Every source file in ui, app, game, formats, cli, audio and launch that had none
now starts with a short English comment: what it implements, what state it owns
and how it relates to its neighbours (request/acknowledge flow, pairs of files,
random generator use). Comment lines only; the full build and the runnable
tests are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 09:15:23 +01:00

84 lines
2.9 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// Analytics statistics page: six data series with per-metric toggles and an absolute/relative scale switch.
// Owns AnalyticsState (values copied from the game, never simulated, plus the parent underlay) and
// AnalyticsScreen. Toggles raise AnalyticsRequest values carrying expected and target flag bytes;
// the owner persists the flags and calls acknowledge(), or reject() to drop the request.
// Implementation: analytics.cpp.
#pragma once
#include <array>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <vector>
#include "formats/le.hpp"
#include "formats/textd.hpp"
#include "formats/vga.hpp"
#include "game/state.hpp"
#include "ui/sprite_font.hpp"
#include "ui/desktop.hpp"
namespace bmh::ui {
// Case 2 of StatisticsMenuScreen opens CopyOpaqueSlice(board, 0): the German
// “Analytics” page, with six Source series. Values are copied, never simulated.
struct AnalyticsSeries {
std::string label;
uint8_t color = 0;
int32_t absolute_min = 0;
int32_t absolute_max = 0;
std::vector<int32_t> values;
bool operator==(const AnalyticsSeries&) const = default;
};
struct AnalyticsState {
DeskRequest owner;
int manager_slot = -1;
uint8_t source_flags = 0; // Flags[manager*3], param2=0.
std::array<AnalyticsSeries, 6> series;
Image underlay; // supplied by the accepted statistics-parent render.
};
enum class AnalyticsRequestKind : uint8_t { toggle_metric, toggle_absolute_scale, close };
struct AnalyticsRequest {
DeskRequest owner;
AnalyticsRequestKind kind = AnalyticsRequestKind::toggle_metric;
int manager_slot = -1;
int metric = -1;
uint8_t expected_flags = 0;
uint8_t target_flags = 0;
bool operator==(const AnalyticsRequest&) const = default;
};
AnalyticsState analytics_from_game(const GameState&, const LeImage&, int manager_slot,
const Image& accepted_parent_underlay);
class AnalyticsScreen {
public:
AnalyticsScreen(const std::filesystem::path& data, AnalyticsState);
Image render() const;
bool click(int x, int y);
bool pointer_down(int x, int y, bool right = false);
const std::optional<AnalyticsRequest>& pending() const { return pending_; }
void acknowledge(uint8_t accepted_flags, DeskRequest accepted_owner);
void reject() { pending_.reset(); }
// Local display preference only. The containing owner must persist/ack
// source_flags through its normal statistics-session contract.
bool toggle_metric(int index);
bool toggle_absolute_scale();
const AnalyticsState& state() const { return state_; }
private:
AnalyticsState state_;
LeImage exe_;
Image buttons_;
SpriteFont sprite_;
TextDb texts_;
std::optional<AnalyticsRequest> pending_;
int pressed_metric_ = -1;
bool pressed_absolute_ = false;
};
} // namespace bmh::ui