summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-21 09:55:52 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-21 09:55:52 +0100
commit80a77b6563e64119748e59af3d2ea2fdef6488c6 (patch)
tree79ff1bf0d1456617e2b1c368ef3f83280270442f
parente224a015dbb69db35a9403f40ede7fc397d549fc (diff)
downloadmana-80a77b6563e64119748e59af3d2ea2fdef6488c6.tar.gz
mana-80a77b6563e64119748e59af3d2ea2fdef6488c6.tar.bz2
mana-80a77b6563e64119748e59af3d2ea2fdef6488c6.tar.xz
mana-80a77b6563e64119748e59af3d2ea2fdef6488c6.zip
Update names as soon as the "Show gender" option is changed
No need to wait for Apply for this option. Using `ConfigOptionChanged` event rather than direct call into `ActorSpriteManager::updatePlayerNames`.
-rw-r--r--src/actorspritemanager.cpp15
-rw-r--r--src/actorspritemanager.h5
-rw-r--r--src/gui/setup_players.cpp20
-rw-r--r--src/gui/setup_players.h1
4 files changed, 31 insertions, 10 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index a5f1a4b9..f7da58ec 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -21,6 +21,7 @@
#include "actorspritemanager.h"
+#include "configuration.h"
#include "game.h"
#include "localplayer.h"
@@ -66,6 +67,8 @@ ActorSpriteManager::ActorSpriteManager()
{
mPlayerNames = new PlayerNamesLister;
mPlayerNPCNames = new PlayerNPCNamesLister;
+
+ listen(Event::ConfigChannel);
}
ActorSpriteManager::~ActorSpriteManager()
@@ -359,3 +362,15 @@ void ActorSpriteManager::updatePlayerNames()
being->updateName();
}
}
+
+void ActorSpriteManager::event(Event::Channel channel, const Event &event)
+{
+ if (channel == Event::ConfigChannel)
+ {
+ if (event.getType() == Event::ConfigOptionChanged &&
+ event.hasValue(&Config::showGender))
+ {
+ updatePlayerNames();
+ }
+ }
+}
diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h
index 7a5f8907..edbe51eb 100644
--- a/src/actorspritemanager.h
+++ b/src/actorspritemanager.h
@@ -24,6 +24,7 @@
#include "actorsprite.h"
#include "being.h"
+#include "eventlistener.h"
#include "flooritem.h"
#include "gui/widgets/textfield.h"
@@ -33,7 +34,7 @@ class Map;
using ActorSprites = std::set<ActorSprite *>;
-class ActorSpriteManager
+class ActorSpriteManager : public EventListener
{
public:
ActorSpriteManager();
@@ -162,6 +163,8 @@ class ActorSpriteManager
void updatePlayerNames();
+ void event(Event::Channel channel, const Event &event) override;
+
protected:
friend class PlayerNamesLister;
friend class PlayerNPCNamesLister;
diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp
index 501fc83a..67fe79da 100644
--- a/src/gui/setup_players.cpp
+++ b/src/gui/setup_players.cpp
@@ -21,7 +21,6 @@
#include "gui/setup_players.h"
-#include "actorspritemanager.h"
#include "configuration.h"
#include "gui/widgets/button.h"
@@ -203,6 +202,7 @@ public:
#define ACTION_STRATEGY "strategy"
Setup_Players::Setup_Players():
+ mShowGender(config.showGender),
mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)),
mPlayerTableModel(new PlayerTableModel),
mPlayerTable(new GuiTable(mPlayerTableModel)),
@@ -244,6 +244,8 @@ Setup_Players::Setup_Players():
gcn::Label *ignore_action_label = new Label(_("When ignoring:"));
+ mShowGenderCheckBox->setActionEventId("showgender");
+ mShowGenderCheckBox->addActionListener(this);
mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY);
mIgnoreActionChoicesBox->addActionListener(this);
@@ -309,21 +311,19 @@ void Setup_Players::apply()
| (mDefaultWhisper->isSelected() ?
PlayerPermissions::WHISPER : 0));
- const bool showGenderChanged = config.showGender != mShowGenderCheckBox->isSelected();
-
config.whisperTab = mWhisperTabCheckBox->isSelected();
- config.showGender = mShowGenderCheckBox->isSelected();
config.enableChatLog = mEnableChatLogCheckBox->isSelected();
- if (actorSpriteManager && showGenderChanged)
- actorSpriteManager->updatePlayerNames();
+ mShowGender = config.showGender;
}
void Setup_Players::cancel()
{
mWhisperTabCheckBox->setSelected(config.whisperTab);
- mShowGenderCheckBox->setSelected(config.showGender);
+ mShowGenderCheckBox->setSelected(mShowGender);
mEnableChatLogCheckBox->setSelected(config.enableChatLog);
+
+ setConfigValue(&Config::showGender, mShowGender);
}
void Setup_Players::action(const gcn::ActionEvent &event)
@@ -341,7 +341,6 @@ void Setup_Players::action(const gcn::ActionEvent &event)
mPlayerTableModel->updateModelInRow(row);
player_relations.addListener(this);
-
}
else if (event.getId() == ACTION_DELETE)
{
@@ -351,7 +350,6 @@ void Setup_Players::action(const gcn::ActionEvent &event)
const std::string &name = mPlayerTableModel->getPlayerAt(player_index);
player_relations.removePlayer(name);
-
}
else if (event.getId() == ACTION_STRATEGY)
{
@@ -361,6 +359,10 @@ void Setup_Players::action(const gcn::ActionEvent &event)
player_relations.setPlayerIgnoreStrategy(s);
}
+ else if (event.getId() == "showgender")
+ {
+ setConfigValue(&Config::showGender, mShowGenderCheckBox->isSelected());
+ }
}
void Setup_Players::playerRelationsUpdated()
diff --git a/src/gui/setup_players.h b/src/gui/setup_players.h
index 48a08e83..126d621b 100644
--- a/src/gui/setup_players.h
+++ b/src/gui/setup_players.h
@@ -51,6 +51,7 @@ public:
void playerRelationsUpdated() override;
private:
+ bool mShowGender;
StaticTableModel *mPlayerTableTitleModel;
PlayerTableModel *mPlayerTableModel;
GuiTable *mPlayerTable;