summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-20 10:26:22 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-20 10:51:24 +0100
commitdb9b9f316d7bdcb9504092908bb18e82fc21de2f (patch)
tree3f7bb1577c5210a9523fd240556cf840665f3efb /src/localplayer.cpp
parent0d1024b64155a05f45f247ad57d0f444db01c1e2 (diff)
downloadmana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.gz
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.bz2
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.xz
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.zip
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.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 7dec601a..7e66632b 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -29,7 +29,6 @@
#include "map.h"
#include "particle.h"
#include "playerinfo.h"
-#include "sound.h"
#include "gui/gui.h"
#include "gui/okdialog.h"
@@ -63,7 +62,7 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mAwayListener = new AwayListener();
- setShowName(config.getValue("showownname", 1));
+ setShowName(config.showOwnName);
listen(Event::ConfigChannel);
listen(Event::ActorSpriteChannel);
@@ -870,11 +869,11 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
msg = N_("Item belongs to someone else."); break;
default: msg = N_("Unknown problem picking up item."); break;
}
- if (config.getValue("showpickupchat", 1))
+ if (config.showPickupChat)
{
serverNotice(_(msg));
}
- if (mMap && config.getBoolValue("showpickupparticle"))
+ if (mMap && config.showPickupParticle)
{
// Show pickup notification
addMessageToQueue(_(msg), UserPalette::PICKUP_INFO);
@@ -882,7 +881,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
}
else
{
- if (config.getBoolValue("showpickupchat"))
+ if (config.showPickupChat)
{
// TRANSLATORS: This sentence may be translated differently
// for different grammatical numbers (singular, plural, ...)
@@ -892,7 +891,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
amount, itemInfo.id, itemInfo.name.c_str()));
}
- if (mMap && config.getBoolValue("showpickupparticle"))
+ if (mMap && config.showPickupParticle)
{
// Show pickup notification
std::string msg;
@@ -1006,7 +1005,7 @@ void LocalPlayer::event(Event::Channel channel, const Event &event)
if (event.getType() == Event::ConfigOptionChanged &&
event.getString("option") == "showownname")
{
- setShowName(config.getValue("showownname", 1));
+ setShowName(config.showOwnName);
}
}
@@ -1020,8 +1019,9 @@ void LocalPlayer::changeAwayMode()
if (mAwayMode)
{
- mAwayDialog = new OkDialog(_("Away"),
- config.getValue("afkMessage", "I am away from keyboard"));
+ auto msg = config.afkMessage.empty() ? _("I am away from keyboard")
+ : config.afkMessage;
+ mAwayDialog = new OkDialog(_("Away"), msg);
mAwayDialog->addActionListener(mAwayListener);
}
@@ -1031,33 +1031,31 @@ void LocalPlayer::changeAwayMode()
void LocalPlayer::setAway(const std::string &message)
{
if (!message.empty())
- config.setValue("afkMessage", message);
+ config.afkMessage = message;
changeAwayMode();
}
void LocalPlayer::afkRespond(ChatTab *tab, const std::string &nick)
{
- if (mAwayMode)
- {
- if (mAfkTimer.passed())
- {
- std::string msg = "*AFK*: "
- + config.getValue("afkMessage", "I am away from keyboard");
+ if (!mAwayMode || !mAfkTimer.passed())
+ return;
- Net::getChatHandler()->privateMessage(nick, msg);
- if (!tab)
- {
- localChatTab->chatLog(getName() + " : " + msg,
- ACT_WHISPER, false);
- }
- else
- {
- tab->chatLog(getName(), msg);
- }
+ auto msg = config.afkMessage.empty() ? _("I am away from keyboard")
+ : config.afkMessage;
+ msg = strprintf(_("*AFK*: %s"), msg.c_str());
- mAfkTimer.set(AWAY_MESSAGE_TIMEOUT);
- }
+ Net::getChatHandler()->privateMessage(nick, msg);
+ if (!tab)
+ {
+ localChatTab->chatLog(getName() + " : " + msg,
+ ACT_WHISPER, false);
}
+ else
+ {
+ tab->chatLog(getName(), msg);
+ }
+
+ mAfkTimer.set(AWAY_MESSAGE_TIMEOUT);
}
void AwayListener::action(const gcn::ActionEvent &event)