mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-22 17:51:39 +00:00
Leave chat open on failed command execution
Also remove unused set_help_on_unknown function.
This commit is contained in:
parent
02f8110420
commit
403fc54790
@ -103,25 +103,25 @@ void chat_handler::send_command(const std::string& cmd, const std::string& args
|
|||||||
send_to_server(data);
|
send_to_server(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chat_handler::do_speak(const std::string& message, bool allies_only)
|
bool chat_handler::do_speak(const std::string& message, bool allies_only)
|
||||||
{
|
{
|
||||||
if (message.empty() || message == "/") {
|
if (message.empty() || message == "/") {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
bool is_command = (message[0] == '/');
|
bool is_command = (message[0] == '/');
|
||||||
bool quoted_command = (is_command && message[1] == ' ');
|
bool quoted_command = (is_command && message[1] == ' ');
|
||||||
|
|
||||||
if (!is_command) {
|
if (!is_command) {
|
||||||
send_chat_message(message, allies_only);
|
send_chat_message(message, allies_only);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
else if (quoted_command) {
|
else if (quoted_command) {
|
||||||
send_chat_message(std::string(message.begin() + 2, message.end()), allies_only);
|
send_chat_message(std::string(message.begin() + 2, message.end()), allies_only);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
std::string cmd(message.begin() + 1, message.end());
|
std::string cmd(message.begin() + 1, message.end());
|
||||||
chat_command_handler cch(*this, allies_only);
|
chat_command_handler cch(*this, allies_only);
|
||||||
cch.dispatch(cmd);
|
return cch.dispatch(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chat_handler::user_relation_changed(const std::string& /*name*/)
|
void chat_handler::user_relation_changed(const std::string& /*name*/)
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
virtual void send_to_server(const config& cfg) = 0;
|
virtual void send_to_server(const config& cfg) = 0;
|
||||||
protected:
|
protected:
|
||||||
void do_speak(const std::string& message, bool allies_only=false);
|
bool do_speak(const std::string& message, bool allies_only=false);
|
||||||
|
|
||||||
//called from do_speak
|
//called from do_speak
|
||||||
virtual void add_chat_message(const std::time_t& time,
|
virtual void add_chat_message(const std::time_t& time,
|
||||||
|
@ -158,7 +158,7 @@ public:
|
|||||||
return command_map_.empty();
|
return command_map_.empty();
|
||||||
}
|
}
|
||||||
//actual work function
|
//actual work function
|
||||||
void dispatch(std::string cmd)
|
bool dispatch(std::string cmd)
|
||||||
{
|
{
|
||||||
if (empty()) {
|
if (empty()) {
|
||||||
init_map_default();
|
init_map_default();
|
||||||
@ -177,18 +177,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (get_cmd().empty()) {
|
if (get_cmd().empty()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const command* c = get_command(get_cmd())) {
|
if (const command* c = get_command(get_cmd())) {
|
||||||
if (is_enabled(*c)) {
|
if (is_enabled(*c)) {
|
||||||
(static_cast<Worker*>(this)->*(c->handler))();
|
(static_cast<Worker*>(this)->*(c->handler))();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print(get_cmd(), _("This command is currently unavailable."));
|
print(get_cmd(), _("This command is currently unavailable."));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (help_on_unknown_) {
|
|
||||||
utils::string_map symbols;
|
utils::string_map symbols;
|
||||||
if(!cmd_flag_) {
|
if(!cmd_flag_) {
|
||||||
symbols["help_command"] = cmd_prefix_ + "help";
|
symbols["help_command"] = cmd_prefix_ + "help";
|
||||||
@ -229,7 +231,7 @@ public:
|
|||||||
print("help", VGETTEXT("Unknown command ‘$command’, try $help_command "
|
print("help", VGETTEXT("Unknown command ‘$command’, try $help_command "
|
||||||
"for a list of available commands.", symbols));
|
"for a list of available commands.", symbols));
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_commands_list() const
|
std::vector<std::string> get_commands_list() const
|
||||||
@ -399,11 +401,6 @@ protected:
|
|||||||
}
|
}
|
||||||
cmd_arg_parser cap_;
|
cmd_arg_parser cap_;
|
||||||
protected:
|
protected:
|
||||||
//show a "try help" message on unknown command?
|
|
||||||
static void set_help_on_unknown(bool value)
|
|
||||||
{
|
|
||||||
help_on_unknown_ = value;
|
|
||||||
}
|
|
||||||
//this is display-only
|
//this is display-only
|
||||||
static void set_cmd_prefix(const std::string& value)
|
static void set_cmd_prefix(const std::string& value)
|
||||||
{
|
{
|
||||||
@ -449,7 +446,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static inline command_map command_map_ {};
|
static inline command_map command_map_ {};
|
||||||
static inline command_alias_map command_alias_map_ {};
|
static inline command_alias_map command_alias_map_ {};
|
||||||
static inline bool help_on_unknown_ = true;
|
|
||||||
static inline bool show_unavailable_ = false;
|
static inline bool show_unavailable_ = false;
|
||||||
static inline std::string cmd_prefix_ {};
|
static inline std::string cmd_prefix_ {};
|
||||||
static inline bool cmd_flag_ = false;
|
static inline bool cmd_flag_ = false;
|
||||||
|
@ -1000,11 +1000,11 @@ void menu_handler::search()
|
|||||||
textbox_info_.show(gui::TEXTBOX_SEARCH, msg.str(), "", false, *gui_);
|
textbox_info_.show(gui::TEXTBOX_SEARCH, msg.str(), "", false, *gui_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_handler::do_speak()
|
bool menu_handler::do_speak()
|
||||||
{
|
{
|
||||||
// None of the two parameters really needs to be passed since the information belong to members of the class.
|
// None of the two parameters really needs to be passed since the information belong to members of the class.
|
||||||
// But since it makes the called method more generic, it is done anyway.
|
// But since it makes the called method more generic, it is done anyway.
|
||||||
chat_handler::do_speak(
|
return chat_handler::do_speak(
|
||||||
textbox_info_.box()->text(), textbox_info_.check() != nullptr ? textbox_info_.check()->checked() : false);
|
textbox_info_.box()->text(), textbox_info_.check() != nullptr ? textbox_info_.check()->checked() : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public:
|
|||||||
|
|
||||||
/** @return Whether or not the recruit was successful */
|
/** @return Whether or not the recruit was successful */
|
||||||
bool do_recruit(const std::string& name, int side_num, map_location& target_hex);
|
bool do_recruit(const std::string& name, int side_num, map_location& target_hex);
|
||||||
void do_speak();
|
bool do_speak();
|
||||||
void do_search(const std::string& new_search);
|
void do_search(const std::string& new_search);
|
||||||
void do_command(const std::string& str);
|
void do_command(const std::string& str);
|
||||||
void do_ai_formula(const std::string& str, int side_num, mouse_handler& mousehandler);
|
void do_ai_formula(const std::string& str, int side_num, mouse_handler& mousehandler);
|
||||||
|
@ -681,8 +681,9 @@ void play_controller::enter_textbox()
|
|||||||
menu_handler_.get_textbox().close();
|
menu_handler_.get_textbox().close();
|
||||||
break;
|
break;
|
||||||
case gui::TEXTBOX_MESSAGE:
|
case gui::TEXTBOX_MESSAGE:
|
||||||
menu_handler_.do_speak();
|
if (menu_handler_.do_speak()) {
|
||||||
menu_handler_.get_textbox().close(); // need to close that one after executing do_speak() !
|
menu_handler_.get_textbox().close();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case gui::TEXTBOX_COMMAND:
|
case gui::TEXTBOX_COMMAND:
|
||||||
menu_handler_.get_textbox().memorize_command(str);
|
menu_handler_.get_textbox().memorize_command(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user