From db9b9f316d7bdcb9504092908bb18e82fc21de2f Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 20 Jan 2025 10:26:22 +0100 Subject: Made client config statically typed This makes accessing the config values much faster, since it no longer needs to do a lookup nor string conversion, which means we could remove some needless copying of the values. Overall it makes it easier to find out where settings are used and it puts the defaults along with the declaration. Options with default values are no longer saved to the config file. This does not include unrecognized options, which are kept around to provide some compatibility with older clients. While most basic options have kept the same name, more complicated settings like window geometry, shortcuts, outfits, etc. now have their own XML elements. Older clients will ignore these and erase them when saving the configuration. --- src/commandhandler.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/commandhandler.cpp') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 9100c9e3..75cca1ab 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -23,6 +23,7 @@ #include "actorspritemanager.h" #include "channelmanager.h" +#include "configuration.h" #include "game.h" #include "localplayer.h" #include "playerrelations.h" @@ -36,6 +37,12 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +std::string booleanOptionInstructions(const char *command) +{ + return strprintf(_("Options to /%s are \"yes\", \"no\", \"true\", \"false\", \"1\", \"0\"."), + command); +} + CommandHandler::CommandHandler() {} @@ -452,8 +459,8 @@ void CommandHandler::handleToggle(const std::string &args, ChatTab *tab) { if (args.empty()) { - tab->chatLog(chatWindow->getReturnTogglesChat() ? - _("Return toggles chat.") : _("Message closes chat.")); + tab->chatLog(config.returnTogglesChat ? _("Return toggles chat.") + : _("Message closes chat.")); return; } @@ -463,14 +470,14 @@ void CommandHandler::handleToggle(const std::string &args, ChatTab *tab) { case 1: tab->chatLog(_("Return now toggles chat.")); - chatWindow->setReturnTogglesChat(true); + config.returnTogglesChat = true; return; case 0: tab->chatLog(_("Message now closes chat.")); - chatWindow->setReturnTogglesChat(false); + config.returnTogglesChat = false; return; case -1: - tab->chatLog(strprintf(BOOLEAN_OPTIONS, "toggle")); + tab->chatLog(booleanOptionInstructions("toggle")); } } @@ -496,7 +503,7 @@ void CommandHandler::handleShowIp(const std::string &args, ChatTab *tab) local_player->setShowIp(true); break; case -1: - tab->chatLog(strprintf(BOOLEAN_OPTIONS, "showip")); + tab->chatLog(booleanOptionInstructions("showip")); return; } -- cgit v1.2.3-70-g09d2