diff options
-rw-r--r-- | src/include/tome/squelch/automatizer.hpp | 5 | ||||
-rw-r--r-- | src/include/tome/squelch/rule.hpp | 4 | ||||
-rw-r--r-- | src/squelch/automatizer.cc | 9 | ||||
-rw-r--r-- | src/squelch/condition_metadata.cc | 4 | ||||
-rw-r--r-- | src/squelch/rule.cc | 7 | ||||
-rw-r--r-- | src/squeltch.cc | 4 | ||||
-rw-r--r-- | src/util.cc | 13 | ||||
-rw-r--r-- | src/util.hpp | 2 |
8 files changed, 24 insertions, 24 deletions
diff --git a/src/include/tome/squelch/automatizer.hpp b/src/include/tome/squelch/automatizer.hpp index 4361941a..833b5648 100644 --- a/src/include/tome/squelch/automatizer.hpp +++ b/src/include/tome/squelch/automatizer.hpp @@ -114,10 +114,9 @@ public: void add_new_condition(std::function<std::shared_ptr<Condition> ()> factory); /** - * Get rule names. The names are not stable across multiple - * calls to methods on this class. + * Get rule names. */ - void get_rule_names(std::vector<const char *> *names) const; + std::vector<std::string> get_rule_names() const; /** * Get current number of rules. diff --git a/src/include/tome/squelch/rule.hpp b/src/include/tome/squelch/rule.hpp index 752a0c2e..af86dfc8 100644 --- a/src/include/tome/squelch/rule.hpp +++ b/src/include/tome/squelch/rule.hpp @@ -40,12 +40,12 @@ public: /** * Set the name of the rule */ - void set_name(const char *new_name); + void set_name(const std::string &new_name); /** * Get the name of the rule */ - const char *get_name() const; + std::string get_name() const; /** * Get condition diff --git a/src/squelch/automatizer.cc b/src/squelch/automatizer.cc index 2f177ef9..dbf8fa03 100644 --- a/src/squelch/automatizer.cc +++ b/src/squelch/automatizer.cc @@ -205,13 +205,14 @@ void Automatizer::add_new_condition(std::function<std::shared_ptr<Condition> ()> factory); } -void Automatizer::get_rule_names(std::vector<const char *> *names) const +std::vector<std::string> Automatizer::get_rule_names() const { - names->resize(m_rules.size()); - for (size_t i = 0; i < m_rules.size(); i++) + std::vector<std::string> names(m_rules.size()); + for (auto const &rule: m_rules) { - (*names)[i] = m_rules.at(i)->get_name(); + names.push_back(rule->get_name()); } + return names; } int Automatizer::rules_count() const diff --git a/src/squelch/condition_metadata.cc b/src/squelch/condition_metadata.cc index 5f91bbfb..f6d4370c 100644 --- a/src/squelch/condition_metadata.cc +++ b/src/squelch/condition_metadata.cc @@ -392,7 +392,7 @@ std::shared_ptr<Condition> new_condition_interactive() match_type::INVENTORY, match_type::EQUIPMENT }; - static std::vector<const char *> condition_type_names; + static std::vector<std::string> condition_type_names; // Fill in types names? if (condition_type_names.empty()) @@ -412,7 +412,7 @@ std::shared_ptr<Condition> new_condition_interactive() Term_clear(); Term_get_size(&wid, &hgt); - display_list(0, 0, hgt - 1, 15, "Rule types", condition_type_names.data(), condition_types.size(), begin, sel, TERM_L_GREEN); + display_list(0, 0, hgt - 1, 15, "Rule types", condition_type_names, begin, sel, TERM_L_GREEN); display_desc(condition_types[sel]); diff --git a/src/squelch/rule.cc b/src/squelch/rule.cc index 50a771ae..e35b3ce1 100644 --- a/src/squelch/rule.cc +++ b/src/squelch/rule.cc @@ -25,15 +25,14 @@ EnumStringMap<action_type> &action_mapping() return *m; } -void Rule::set_name(const char *new_name) +void Rule::set_name(std::string const &new_name) { - assert(new_name != nullptr); m_name = new_name; } -const char *Rule::get_name() const +std::string Rule::get_name() const { - return m_name.c_str(); + return m_name; } std::shared_ptr<Condition> Rule::get_condition() const diff --git a/src/squeltch.cc b/src/squeltch.cc index 293eab69..9c0de4be 100644 --- a/src/squeltch.cc +++ b/src/squeltch.cc @@ -277,9 +277,9 @@ void do_cmd_automatizer() int wid, hgt; Term_get_size(&wid, &hgt); - automatizer->get_rule_names(&rule_names); + auto rule_names = automatizer->get_rule_names(); - display_list(0, 0, hgt - 1, 15, "Rules", rule_names.data(), automatizer->rules_count(), automatizer->rules_begin(), automatizer->selected_rule(), (active == ACTIVE_LIST) ? TERM_L_GREEN : TERM_GREEN); + display_list(0, 0, hgt - 1, 15, "Rules", rule_names, automatizer->rules_begin(), automatizer->selected_rule(), (active == ACTIVE_LIST) ? TERM_L_GREEN : TERM_GREEN); draw_box(0, 15, hgt - 4, wid - 1 - 15); if (active == ACTIVE_RULE) diff --git a/src/util.cc b/src/util.cc index 1927d050..027c6c80 100644 --- a/src/util.cc +++ b/src/util.cc @@ -3580,21 +3580,22 @@ void draw_box(int y, int x, int h, int w) /* * Displays a scrollable boxed list with a selected item */ -void display_list(int y, int x, int h, int w, cptr title, cptr *list, int max, int begin, int sel, byte sel_color) +void display_list(int y, int x, int h, int w, cptr title, std::vector<std::string> const &list, std::size_t begin, std::size_t sel, byte sel_color) { - int i; - draw_box(y, x, h, w); c_put_str(TERM_L_BLUE, title, y, x + ((w - strlen(title)) / 2)); - for (i = 0; i < h - 1; i++) + for (int i = 0; i < h - 1; i++) { byte color = TERM_WHITE; - if (i + begin >= max) break; + if (i + begin >= list.size()) + { + break; + } if (i + begin == sel) color = sel_color; - c_put_str(color, list[i + begin], y + 1 + i, x + 1); + c_put_str(color, list[i + begin].c_str(), y + 1 + i, x + 1); } } diff --git a/src/util.hpp b/src/util.hpp index 90999567..4c74ad10 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -12,7 +12,7 @@ extern bool input_box(std::string const &text, int y, int x, std::string *buf, s extern std::string input_box_auto(std::string const &title, std::size_t max); extern bool input_box_auto(std::string const &prompt, std::string *buf, std::size_t max); extern void draw_box(int y, int x, int h, int w); -extern void display_list(int y, int x, int h, int w, cptr title, cptr *list, int max, int begin, int sel, byte sel_color); +extern void display_list(int y, int x, int h, int w, cptr title, std::vector<std::string> const &list, std::size_t begin, std::size_t sel, byte sel_color); extern std::string get_player_race_name(int pr, int ps); extern std::string get_day(s32b day); extern s32b bst(s32b what, s32b t); |