#include "io/input-key-requester.h" //!< @todo 相互依存している、後で何とかする.
#include "main/sound-of-music.h"
#include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
#include "term/gameterm.h"
#include "term/screen-processor.h"
#include "term/term-color-types.h"
#include "util/int-char-converter.h"
#include "util/string-processor.h"
#include "view/display-messages.h"
-
#include <algorithm>
#include <charconv>
#include <climits>
#include <iostream>
#include <sstream>
+#include <stdexcept>
#include <string>
/*
}
const auto buf = ss.str();
+ auto &rfu = RedrawingFlagsUpdater::get_instance();
if (auto_more) {
- player_ptr->window_flags |= PW_MESSAGE;
+ rfu.set_flag(SubWindowRedrawingFlag::MESSAGE);
handle_stuff(player_ptr);
num_more = 0;
}
prt(buf, 0, 0);
if (!(mode & CHECK_NO_HISTORY) && player_ptr->playing) {
message_add(buf);
- player_ptr->window_flags |= (PW_MESSAGE);
+ rfu.set_flag(SubWindowRedrawingFlag::MESSAGE);
handle_stuff(player_ptr);
}
*/
QUANTITY get_quantity(std::optional<std::string_view> prompt_opt, QUANTITY max)
{
- // FIXME : QUANTITY、COMMAND_CODE、その他の型サイズがまちまちな変数とのやり取りが多数ある。この処理での数の入力を0からSHRT_MAXに制限することで不整合の発生を回避する。
+ /*!
+ * @todo QUANTITY、COMMAND_CODE、その他の型サイズがまちまちな変数とのやり取りが多数ある.
+ * この処理での数の入力を0からSHRT_MAXに制限することで不整合の発生を回避する.
+ */
max = std::clamp<QUANTITY>(max, 0, SHRT_MAX);
bool res;
prt("", row, 0);
}
-bool get_value(std::string_view prompt, int min, int max, int *value)
+std::optional<int> input_value_int(std::string_view prompt, int min, int max, int initial_value)
{
- std::stringstream st;
- int val;
+ std::stringstream ss;
char tmp_val[12] = "";
- /* std::to_chars() requires Mac OS X 10.15 or later. */
-#if !defined(MACH_O_COCOA) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15)
- std::to_chars(std::begin(tmp_val), std::end(tmp_val) - 1, *value);
-#else
- snprintf(tmp_val, sizeof(tmp_val), "%d", *value);
-#endif
- st << prompt << "(" << min << "-" << max << "): ";
- int digit = std::max(std::to_string(min).length(), std::to_string(max).length());
+ std::to_chars(std::begin(tmp_val), std::end(tmp_val) - 1, initial_value);
+ ss << prompt << "(" << min << "-" << max << "): ";
+ auto digit = std::max(std::to_string(min).length(), std::to_string(max).length());
while (true) {
- if (!get_string(st.str().data(), tmp_val, digit)) {
- return false;
+ if (!get_string(ss.str().data(), tmp_val, digit)) {
+ return std::nullopt;
}
- val = atoi(tmp_val);
+ try {
+ auto val = std::stoi(tmp_val);
+ if ((val < min) || (val > max)) {
+ msg_format(_("%dから%dの間で指定して下さい。", "It must be between %d to %d."), min, max);
+ continue;
+ }
- if (min <= val && max >= val) {
- break;
+ return val;
+ } catch (std::invalid_argument const &) {
+ msg_print(_("数値を入力して下さい。", "Please input numeric value."));
+ continue;
+ } catch (std::out_of_range const &) {
+ msg_print(_("入力可能な数値の範囲を超えています。", "Input value overflows the maximum number."));
+ continue;
}
- msg_format(_("%dから%dの間で指定して下さい。", "It must be between %d to %d."), min, max);
}
- *value = val;
- return true;
}