aboutsummaryrefslogtreecommitdiff
path: root/src/game/status_manager.cpp
blob: 1a709d3e36d7a236b04f37edb78ceb6f72bf4c7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "status_manager.hpp"

#include <fmt/core.h>

#include <utility>

StatusManager::StatusManager(std::shared_ptr<IStatusLine> statusline) noexcept
	: _statusline(std::move(statusline))

{
}

void StatusManager::initialize() noexcept
{
	_statusline->set_section_length(StatusLineSection::A, 5U);
	_statusline->set_section_length(StatusLineSection::B, 15U);
	_statusline->set_section_length(StatusLineSection::C, 15U);
	_statusline->set_section_length(StatusLineSection::D, 20U);
	_statusline->set_section_length(StatusLineSection::E, 15U);
	_statusline->set_section_length(StatusLineSection::F, 15U);

	_statusline->initialize_background();
}

void StatusManager::set_section_title(
	const StatusLineSection &section,
	const std::string_view &title) noexcept
{
	if (_title_lengths.count(section) != 0)
	{
		fmt::print(stderr, "Error: can't set statusbar section title more than once");
		return;
	}

	_statusline->set_status(section, title);

	_title_lengths[section] = title.length();
}

void StatusManager::set_section_body(
	const StatusLineSection &section,
	const std::string_view &body) noexcept
{
	auto section_title_length = _title_lengths[section];

	_statusline->set_status(section, body, section_title_length + 1);
}