Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for custom playerlist formatting, show all users when authenticated #1046

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 47 additions & 37 deletions data/ui/options_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
<enum>Qt::ContextMenuPolicy::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>Settings</string>
Expand All @@ -20,7 +20,7 @@
<item>
<widget class="QTabWidget" name="settings_tabs">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
<property name="currentIndex">
<number>0</number>
Expand All @@ -39,9 +39,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-385</y>
<y>-585</y>
<width>394</width>
<height>878</height>
<height>902</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -131,10 +131,10 @@
<item row="6" column="1">
<widget class="QFrame" name="theme_log_divider">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -198,7 +198,7 @@
<string>Chat Rate Limit:</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
<enum>Qt::TextFormat::AutoText</enum>
</property>
</widget>
</item>
Expand All @@ -215,10 +215,10 @@
<item row="11" column="1">
<widget class="QFrame" name="log_names_divider">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -272,10 +272,10 @@
<item row="15" column="1">
<widget class="QFrame" name="net_divider">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -560,23 +560,6 @@
</property>
</widget>
</item>
<item row="35" column="1">
<widget class="QCheckBox" name="restoreposition_cb">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="35" column="0">
<widget class="QLabel" name="restoreposition_lbl">
<property name="toolTip">
<string>If ticked, some windows restore their last known position where they were closed.</string>
</property>
<property name="text">
<string>Restore Window Position</string>
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QLabel" name="resize_lbl">
<property name="toolTip">
Expand Down Expand Up @@ -609,6 +592,33 @@
</item>
</widget>
</item>
<item row="34" column="0">
<widget class="QLabel" name="restoreposition_lbl">
<property name="toolTip">
<string>If ticked, some windows restore their last known position where they were closed.</string>
</property>
<property name="text">
<string>Restore Window Position</string>
</property>
</widget>
</item>
<item row="34" column="1">
<widget class="QCheckBox" name="restoreposition_cb">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="35" column="0">
<widget class="QLabel" name="playerlist_format_lbl">
<property name="text">
<string>Playerlist Format:</string>
</property>
</widget>
</item>
<item row="35" column="1">
<widget class="QLineEdit" name="playerlist_format_edit"/>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -653,10 +663,10 @@
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="audio_volume_divider">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand All @@ -683,10 +693,10 @@
<item row="3" column="0" colspan="2">
<widget class="QFrame" name="volume_blip_divider">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -819,7 +829,7 @@
<item row="2" column="5">
<spacer name="mount_buttons_spacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -858,10 +868,10 @@
<item row="2" column="2">
<spacer name="mount_buttons_spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -1116,10 +1126,10 @@ Default: 0.</string>
<item>
<widget class="QFrame" name="privacy_separator">
<property name="frameShape">
<enum>QFrame::HLine</enum>
<enum>QFrame::Shape::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Shadow::Sunken</enum>
</property>
</widget>
</item>
Expand Down
6 changes: 6 additions & 0 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ void AOApplication::call_settings_menu()
if (is_lobby_constructed())
{}
l_dialog->exec();

if (is_courtroom_constructed())
{
w_courtroom->playerList()->reloadPlayers();
}

delete l_dialog;
}

Expand Down
10 changes: 10 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ void Options::setCallwords(QStringList value)
config.setValue("callwords", value);
}

QString Options::playerlistFormatString() const
{
return config.value("visuals/playerlist_format", "[{id}] {character} {displayname} {username}").toString();
}

void Options::setPlayerlistFormatString(QString value)
{
config.setValue("visuals/playerlist_format", value);
}

void Options::clearConfig()
{
config.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class Options
QStringList callwords() const;
void setCallwords(QStringList value);

QString playerlistFormatString() const;
void setPlayerlistFormatString(QString value);

// Clears the configuration file. Essentially restoring it to default.
void clearConfig();

Expand Down
3 changes: 2 additions & 1 deletion src/widgets/aooptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ void AOOptionsDialog::setupUI()
qWarning() << "Unable to open file " << l_uiFile.fileName();
return;
}

ui_settings_widget = l_loader.load(&l_uiFile, this);

auto l_layout = new QVBoxLayout(this);
Expand Down Expand Up @@ -372,6 +371,7 @@ void AOOptionsDialog::setupUI()
FROM_UI(QCheckBox, evidence_double_click_cb);
FROM_UI(QCheckBox, slides_cb);
FROM_UI(QCheckBox, restoreposition_cb);
FROM_UI(QLineEdit, playerlist_format_edit);

registerOption<QSpinBox, int>("theme_scaling_factor_sb", &Options::themeScalingFactor, &Options::setThemeScalingFactor);
registerOption<QCheckBox, bool>("animated_theme_cb", &Options::animatedThemeEnabled, &Options::setAnimatedThemeEnabled);
Expand Down Expand Up @@ -410,6 +410,7 @@ void AOOptionsDialog::setupUI()
registerOption<QCheckBox, bool>("evidence_double_click_cb", &Options::evidenceDoubleClickEdit, &Options::setEvidenceDoubleClickEdit);
registerOption<QCheckBox, bool>("slides_cb", &Options::slidesEnabled, &Options::setSlidesEnabled);
registerOption<QCheckBox, bool>("restoreposition_cb", &Options::restoreWindowPositionEnabled, &Options::setRestoreWindowPositionEnabled);
registerOption<QLineEdit, QString>("playerlist_format_edit", &Options::playerlistFormatString, &Options::setPlayerlistFormatString);

// Callwords tab. This could just be a QLineEdit, but no, we decided to allow
// people to put a billion entries in.
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/aooptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AOOptionsDialog : public QDialog
QPushButton *ui_theme_folder_button;
QCheckBox *ui_evidence_double_click_cb;
QCheckBox *ui_slides_cb;
QCheckBox *ui_restoreposition_cb;
QCheckBox *ui_animated_theme_cb;
QSpinBox *ui_stay_time_spinbox;
QCheckBox *ui_instant_objection_cb;
Expand Down Expand Up @@ -76,6 +75,8 @@ class AOOptionsDialog : public QDialog
QCheckBox *ui_continuous_cb;
QCheckBox *ui_category_stop_cb;
QCheckBox *ui_sfx_on_idle_cb;
QCheckBox *ui_restoreposition_cb;
QLineEdit *ui_playerlist_format_edit;

// The callwords tab
QPlainTextEdit *ui_callwords_textbox;
Expand Down
18 changes: 12 additions & 6 deletions src/widgets/playerlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ void PlayerListWidget::updatePlayer(const PlayerUpdate &update)
filterPlayerList();
}

void PlayerListWidget::reloadPlayers()
{
for (const PlayerData &player : qAsConst(m_player_map))
{
updatePlayer(player.id, false);
}
}

void PlayerListWidget::setAuthenticated(bool f_state)
{
m_is_authenticated = f_state;
for (const PlayerData &data : qAsConst(m_player_map))
{
updatePlayer(data.id, false);
filterPlayerList();
}
}

Expand Down Expand Up @@ -148,7 +157,7 @@ void PlayerListWidget::filterPlayerList()
qWarning() << "Trying to filter item that does not exist. This indicates either a broken server-implementation or a bad demo file.";
break;
}
item->setHidden(m_player_map[item->data(Qt::UserRole).toInt()].area_id != area_id);
item->setHidden(m_player_map[item->data(Qt::UserRole).toInt()].area_id != area_id && !m_is_authenticated);
}
}

Expand Down Expand Up @@ -186,9 +195,6 @@ void PlayerListWidget::updatePlayer(int playerId, bool updateIcon)

QString PlayerListWidget::formatLabel(const PlayerData &data)
{
if (m_is_authenticated)
{
return QString("%1 %2 %3").arg(data.character, data.character_name, data.name).simplified();
}
return QString("%1 %2").arg(data.character, data.character_name).simplified();
QString format = Options::getInstance().playerlistFormatString();
return format.replace("{id}", QString::number(data.id)).replace("{character}", data.character).replace("{displayname}", data.character_name.isEmpty() ? "No Data" : data.character_name).replace("{username}", m_is_authenticated ? data.name : "").simplified();
}
1 change: 1 addition & 0 deletions src/widgets/playerlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PlayerListWidget : public QListWidget

void registerPlayer(const PlayerRegister &update);
void updatePlayer(const PlayerUpdate &update);
void reloadPlayers();

void setAuthenticated(bool f_state);

Expand Down