OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / core / asking-player.h
1 #pragma once
2
3 #include "util/flag-group.h"
4 #include <optional>
5 #include <string_view>
6 #include <type_traits>
7
8 enum class UserCheck {
9     NONE = 0,
10     OKAY_CANCEL = 1,
11     NO_ESCAPE = 2,
12     NO_HISTORY = 3,
13     DEFAULT_Y = 4,
14     MAX = 5,
15 };
16
17 class PlayerType;
18 std::optional<std::string> askfor(int len, std::string_view initial_value = "", bool numpad_cursor = true);
19 std::optional<std::string> input_string(std::string_view prompt, int len, std::string_view initial_value = "", bool numpad_cursor = true);
20 bool input_check(std::string_view prompt);
21 bool input_check_strict(PlayerType *player_ptr, std::string_view prompt, UserCheck one_mode);
22 bool input_check_strict(PlayerType *player_ptr, std::string_view prompt, EnumClassFlagGroup<UserCheck> mode);
23 std::optional<char> input_command(std::string_view prompt, bool z_escape = false);
24 int input_quantity(int max, std::string_view initial_prompt = "");
25 void pause_line(int row);
26 std::optional<int> input_integer(std::string_view prompt, int min, int max, int initial_value = 0);
27
28 template <typename T>
29 std::optional<T> input_numerics(std::string_view prompt, int min, int max, T initial_value = static_cast<T>(0))
30     requires std::is_integral_v<T> || std::is_enum_v<T>
31 {
32     auto result = input_integer(prompt, min, max, static_cast<int>(initial_value));
33     if (!result.has_value()) {
34         return std::nullopt;
35     }
36
37     return std::make_optional(static_cast<T>(result.value()));
38 }