Skip to content

Commit b9aa203

Browse files
CrystalwarriorstonedDiscordgithub-actions[bot]oldmud0
authored
Add "edit" and "open folder" actions for dropdowns (#776)
* Add "edit" and "open folder" actions for dropdowns: - CharSelect char button with "edit char.ini," "open this char folder" - pos dropdown with "open this background" - text color dropdown with "open chat_config.ini" - evidence button with "open evidence folder" - sound list with "open sounds folder" - music list with "open music folder" - theme list with "open themes folder" * Implement "Play <sfx_name>" for the Play action, and only show it if the sfx is not "0" or "1" or "-" Co-authored-by: stonedDiscord <Tukz@gmx.de> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
1 parent dd8eee7 commit b9aa203

5 files changed

Lines changed: 164 additions & 8 deletions

File tree

include/aooptionsdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AOOptionsDialog : public QDialog {
5151
QLabel *ui_subtheme_label;
5252
QComboBox *ui_subtheme_combobox;
5353
QPushButton *ui_theme_reload_button;
54+
QPushButton *ui_theme_folder_button;
5455
QLabel *ui_evidence_double_click_lbl;
5556
QCheckBox *ui_evidence_double_click_cb;
5657
QLabel *ui_animated_theme_lbl;

include/courtroom.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ class Courtroom : public QMainWindow {
824824
void set_char_select();
825825
void set_char_select_page();
826826
void char_clicked(int n_char);
827+
void on_char_button_context_menu_requested(const QPoint &pos);
827828
void put_button_in_place(int starting, int chars_on_this_page);
828829
void filter_character_list();
829830

@@ -893,6 +894,7 @@ private slots:
893894
void on_emote_dropdown_changed(int p_index);
894895
void on_pos_dropdown_changed(int p_index);
895896
void on_pos_dropdown_changed(QString p_text);
897+
void on_pos_dropdown_context_menu_requested(const QPoint &pos);
896898
void on_pos_remove_clicked();
897899

898900
void on_iniswap_dropdown_changed(int p_index);
@@ -952,6 +954,7 @@ private slots:
952954
void on_prosecution_plus_clicked();
953955

954956
void on_text_color_changed(int p_color);
957+
void on_text_color_context_menu_requested(const QPoint &pos);
955958
void set_text_color_dropdown();
956959

957960
void on_music_slider_moved(int p_value);
@@ -982,6 +985,7 @@ private slots:
982985
void on_showname_enable_clicked();
983986

984987
void on_evidence_button_clicked();
988+
void on_evidence_context_menu_requested(const QPoint &pos);
985989

986990
void on_evidence_delete_clicked();
987991
bool on_evidence_x_clicked();

src/aooptionsdialog.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
120120
ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_subtheme_combobox);
121121

122122
row += 1;
123-
124123
ui_theme_reload_button = new QPushButton(ui_form_layout_widget);
125124
ui_theme_reload_button->setText(tr("Reload Theme"));
126125
ui_theme_reload_button->setToolTip(
@@ -129,6 +128,22 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
129128
connect(ui_theme_reload_button, &QPushButton::clicked, this,
130129
&AOOptionsDialog::on_reload_theme_clicked);
131130

131+
row += 1;
132+
ui_theme_folder_button = new QPushButton(ui_form_layout_widget);
133+
ui_theme_folder_button->setText(tr("Open Theme Folder"));
134+
ui_theme_folder_button->setToolTip(
135+
tr("Open the theme folder of the currently selected theme."));
136+
ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_theme_folder_button);
137+
connect(ui_theme_folder_button, &QPushButton::clicked, this,
138+
[=] {
139+
QString p_path = ao_app->get_real_path(ao_app->get_theme_path("", ui_theme_combobox->itemText(ui_theme_combobox->currentIndex())));
140+
if (!dir_exists(p_path)) {
141+
return;
142+
}
143+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
144+
}
145+
);
146+
132147
row += 1;
133148
ui_animated_theme_lbl = new QLabel(ui_form_layout_widget);
134149
ui_animated_theme_lbl->setText(tr("Animated Theme:"));

src/charselect.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,41 @@ void Courtroom::char_clicked(int n_char)
190190
}
191191
}
192192

193+
void Courtroom::on_char_button_context_menu_requested(const QPoint &pos)
194+
{
195+
AOCharButton* button = qobject_cast<AOCharButton*>(sender());
196+
int n_char = ui_char_button_list.indexOf(button);
197+
if (n_char == -1)
198+
{
199+
return;
200+
}
201+
202+
QString char_name = char_list.at(n_char).name;
203+
QString char_ini_path = ao_app->get_real_path(
204+
ao_app->get_character_path(char_name, "char.ini"));
205+
206+
if (!file_exists(char_ini_path)) {
207+
call_error(tr("Could not find character (char.ini) for %1").arg(char_name));
208+
return;
209+
}
210+
211+
QMenu *menu = new QMenu(this);
212+
menu->addAction(QString("Edit " + char_name + "/char.ini"), this,
213+
[=] { QDesktopServices::openUrl(QUrl::fromLocalFile(char_ini_path)); }
214+
);
215+
menu->addSeparator();
216+
menu->addAction(QString("Open character folder " + char_name), this,
217+
[=] {
218+
QString p_path = ao_app->get_real_path(VPath("characters/" + char_name + "/"));
219+
if (!dir_exists(p_path)) {
220+
return;
221+
}
222+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
223+
}
224+
);
225+
menu->popup(button->mapToGlobal(pos));
226+
}
227+
193228
void Courtroom::put_button_in_place(int starting, int chars_on_this_page)
194229
{
195230
if (ui_char_button_list_filtered.size() == 0)
@@ -249,6 +284,7 @@ void Courtroom::character_loading_finished()
249284
for (int n = 0; n < char_list.size(); n++) {
250285
AOCharButton *char_button =
251286
new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken);
287+
char_button->setContextMenuPolicy(Qt::CustomContextMenu);
252288
char_button->reset();
253289
char_button->hide();
254290
char_button->set_image(char_list.at(n).name);
@@ -282,6 +318,7 @@ void Courtroom::character_loading_finished()
282318

283319
connect(char_button, &AOCharButton::clicked,
284320
[this, n]() { this->char_clicked(n); });
321+
connect(char_button, &AOCharButton::customContextMenuRequested, this, &Courtroom::on_char_button_context_menu_requested);
285322

286323
// This part here serves as a way of showing to the player that the game is
287324
// still running, it is just loading the pictures of the characters.

src/courtroom.cpp

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
211211
ui_music_search->setObjectName("ui_music_search");
212212

213213
ui_pos_dropdown = new QComboBox(this);
214+
ui_pos_dropdown->setContextMenuPolicy(Qt::CustomContextMenu);
214215
ui_pos_dropdown->view()->setTextElideMode(Qt::ElideLeft);
215216
ui_pos_dropdown->setObjectName("ui_pos_dropdown");
216217

@@ -359,6 +360,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
359360
ui_prosecution_minus->setObjectName("ui_prosecution_minus");
360361

361362
ui_text_color = new QComboBox(this);
363+
ui_text_color->setContextMenuPolicy(Qt::CustomContextMenu);
362364
ui_text_color->setObjectName("ui_text_color");
363365

364366
ui_music_slider = new QSlider(Qt::Horizontal, this);
@@ -401,6 +403,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
401403
ui_pair_button->setObjectName("ui_pair_button");
402404

403405
ui_evidence_button = new AOButton(this, ao_app);
406+
ui_evidence_button->setContextMenuPolicy(Qt::CustomContextMenu);
404407
ui_evidence_button->setObjectName("ui_evidence_button");
405408

406409
initialize_emotes();
@@ -431,6 +434,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
431434
QOverload<int>::of(&Courtroom::on_pos_dropdown_changed));
432435
connect(ui_pos_dropdown, &QComboBox::editTextChanged, this,
433436
QOverload<QString>::of(&Courtroom::on_pos_dropdown_changed));
437+
connect(ui_pos_dropdown, &QComboBox::customContextMenuRequested, this,
438+
&Courtroom::on_pos_dropdown_context_menu_requested);
434439
connect(ui_pos_remove, &AOButton::clicked, this, &Courtroom::on_pos_remove_clicked);
435440

436441
connect(ui_iniswap_dropdown, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
@@ -500,6 +505,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
500505

501506
connect(ui_text_color, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
502507
&Courtroom::on_text_color_changed);
508+
connect(ui_text_color, &QComboBox::customContextMenuRequested, this,
509+
&Courtroom::on_text_color_context_menu_requested);
503510

504511
connect(ui_music_slider, &QSlider::valueChanged, this,
505512
&Courtroom::on_music_slider_moved);
@@ -554,6 +561,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
554561

555562
connect(ui_evidence_button, &AOButton::clicked, this,
556563
&Courtroom::on_evidence_button_clicked);
564+
connect(ui_evidence_button, &QComboBox::customContextMenuRequested, this,
565+
&Courtroom::on_evidence_context_menu_requested);
557566

558567
connect(qApp, QOverload<Qt::ApplicationState>::of(&QApplication::applicationStateChanged), this,
559568
&Courtroom::on_application_state_changed);
@@ -4532,6 +4541,25 @@ void Courtroom::on_pos_dropdown_changed(QString p_text)
45324541
set_side(p_text);
45334542
}
45344543

4544+
void Courtroom::on_pos_dropdown_context_menu_requested(const QPoint &pos)
4545+
{
4546+
QMenu *menu = ui_iniswap_dropdown->lineEdit()->createStandardContextMenu();
4547+
4548+
menu->setAttribute(Qt::WA_DeleteOnClose);
4549+
menu->addSeparator();
4550+
4551+
menu->addAction(QString("Open background " + current_background), this,
4552+
[=] {
4553+
QString p_path = ao_app->get_real_path(VPath("background/" + current_background + "/"));
4554+
if (!dir_exists(p_path)) {
4555+
return;
4556+
}
4557+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
4558+
}
4559+
);
4560+
menu->popup(ui_iniswap_dropdown->mapToGlobal(pos));
4561+
}
4562+
45354563
void Courtroom::on_pos_remove_clicked()
45364564
{
45374565
ui_pos_dropdown->blockSignals(true);
@@ -4633,18 +4661,32 @@ void Courtroom::on_iniswap_context_menu_requested(const QPoint &pos)
46334661
if (file_exists(ao_app->get_real_path(
46344662
ao_app->get_character_path(current_char, "char.ini"))))
46354663
menu->addAction(QString("Edit " + current_char + "/char.ini"), this,
4636-
SLOT(on_iniswap_edit_requested()));
4664+
&Courtroom::on_iniswap_edit_requested);
46374665
if (ui_iniswap_dropdown->itemText(ui_iniswap_dropdown->currentIndex()) !=
46384666
char_list.at(m_cid).name)
46394667
menu->addAction(QString("Remove " + current_char), this,
4640-
SLOT(on_iniswap_remove_clicked()));
4668+
&Courtroom::on_iniswap_remove_clicked);
4669+
4670+
menu->addSeparator();
4671+
menu->addAction(QString("Open character folder " + current_char), this,
4672+
[=] {
4673+
QString p_path = ao_app->get_real_path(VPath("characters/" + current_char + "/"));
4674+
if (!dir_exists(p_path)) {
4675+
return;
4676+
}
4677+
4678+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
4679+
}
4680+
);
46414681
menu->popup(ui_iniswap_dropdown->mapToGlobal(pos));
46424682
}
4683+
46434684
void Courtroom::on_iniswap_edit_requested()
46444685
{
46454686
QString p_path = ao_app->get_real_path(ao_app->get_character_path(current_char, "char.ini"));
4646-
if (!file_exists(p_path))
4687+
if (!file_exists(p_path)) {
46474688
return;
4689+
}
46484690
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
46494691
}
46504692

@@ -4690,8 +4732,9 @@ void Courtroom::set_sfx_dropdown()
46904732
for (const QString &sound : qAsConst(sound_list)) {
46914733
QStringList unpacked = sound.split("=");
46924734
QString display = unpacked[0].trimmed();
4693-
if (unpacked.size() > 1)
4735+
if (unpacked.size() > 1) {
46944736
display = unpacked[1].trimmed();
4737+
}
46954738

46964739
display_sounds.append(display);
46974740
}
@@ -4726,7 +4769,11 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
47264769

47274770
menu->setAttribute(Qt::WA_DeleteOnClose);
47284771
menu->addSeparator();
4729-
menu->addAction(QString("Play"), this, &Courtroom::on_sfx_play_clicked);
4772+
// SFX is not "Nothing" or "Default"?
4773+
if (get_char_sfx() != "0" && get_char_sfx() != "1" && get_char_sfx() != "-") {
4774+
// Add an option to play the SFX
4775+
menu->addAction(QString("Play " + get_char_sfx()), this, &Courtroom::on_sfx_play_clicked);;
4776+
}
47304777
if (file_exists(ao_app->get_real_path(
47314778
ao_app->get_character_path(current_char, "soundlist.ini"))))
47324779
menu->addAction(QString("Edit " + current_char + "/soundlist.ini"), this,
@@ -4736,6 +4783,16 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
47364783
&Courtroom::on_sfx_edit_requested);
47374784
if (!custom_sfx.isEmpty())
47384785
menu->addAction(QString("Clear Edit Text"), this, &Courtroom::on_sfx_remove_clicked);
4786+
menu->addSeparator();
4787+
menu->addAction(QString("Open base sounds folder"), this,
4788+
[=] {
4789+
QString p_path = ao_app->get_base_path() + "sounds/general/";
4790+
if (!dir_exists(p_path)) {
4791+
return;
4792+
}
4793+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
4794+
}
4795+
);
47394796
menu->popup(ui_sfx_dropdown->mapToGlobal(pos));
47404797
}
47414798

@@ -4809,9 +4866,9 @@ void Courtroom::on_effects_context_menu_requested(const QPoint &pos)
48094866
QString("Open misc/" +
48104867
ao_app->read_char_ini(current_char, "effects", "Options") +
48114868
" folder"),
4812-
this, SLOT(on_character_effects_edit_requested()));
4869+
this, &Courtroom::on_character_effects_edit_requested);
48134870
menu->addAction(QString("Open theme's effects folder"), this,
4814-
SLOT(on_effects_edit_requested()));
4871+
&Courtroom::on_effects_edit_requested);
48154872
menu->popup(ui_effects_dropdown->mapToGlobal(pos));
48164873
}
48174874
void Courtroom::on_effects_edit_requested()
@@ -5001,6 +5058,17 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
50015058
connect(menu->actions().back(), &QAction::toggled, this,
50025059
&Courtroom::music_synchronize);
50035060

5061+
menu->addSeparator();
5062+
menu->addAction(QString("Open base music folder"), this,
5063+
[=] {
5064+
QString p_path = ao_app->get_base_path() + "sounds/music/";
5065+
if (!dir_exists(p_path)) {
5066+
return;
5067+
}
5068+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
5069+
}
5070+
);
5071+
50045072
menu->popup(ui_music_list->mapToGlobal(pos));
50055073
}
50065074

@@ -5313,6 +5381,22 @@ void Courtroom::on_prosecution_plus_clicked()
53135381
new AOPacket("HP", {"2", QString::number(f_state)}));
53145382
}
53155383

5384+
void Courtroom::on_text_color_context_menu_requested(const QPoint &pos)
5385+
{
5386+
QMenu *menu = new QMenu(this);
5387+
5388+
menu->addAction(QString("Open currently used chat_config.ini"), this,
5389+
[=] {
5390+
QString p_path = ao_app->get_asset("chat_config.ini", ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, ao_app->get_chat(current_char));
5391+
if (!file_exists(p_path)) {
5392+
return;
5393+
}
5394+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
5395+
}
5396+
);
5397+
menu->popup(ui_text_color->mapToGlobal(pos));
5398+
}
5399+
53165400
void Courtroom::set_text_color_dropdown()
53175401
{
53185402
// Clear the lists
@@ -5617,6 +5701,21 @@ void Courtroom::on_evidence_button_clicked()
56175701
}
56185702
}
56195703

5704+
void Courtroom::on_evidence_context_menu_requested(const QPoint &pos)
5705+
{
5706+
QMenu *menu = new QMenu(this);
5707+
menu->addAction(QString("Open base evidence folder"), this,
5708+
[=] {
5709+
QString p_path = ao_app->get_base_path() + "evidence/";
5710+
if (!dir_exists(p_path)) {
5711+
return;
5712+
}
5713+
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
5714+
}
5715+
);
5716+
menu->popup(ui_evidence_button->mapToGlobal(pos));
5717+
}
5718+
56205719
void Courtroom::on_switch_area_music_clicked()
56215720
{
56225721
if (ui_area_list->isHidden()) {

0 commit comments

Comments
 (0)