Fix backwards compatibility with the stopmusic
Hide ~stop.mp3 and the stop category Add an option to make it so when you double-click a category, it expands/collapses it without sending the stop-music command Make right click stop music backwards compatible
This commit is contained in:
		
							parent
							
								
									ce77e50f75
								
							
						
					
					
						commit
						aea0e2ef80
					
				@ -226,6 +226,10 @@ public:
 | 
			
		||||
  // from the config.ini.
 | 
			
		||||
  bool is_continuous_enabled();
 | 
			
		||||
 | 
			
		||||
  // Returns the value of whether stopping music by double clicking category should be used
 | 
			
		||||
  // from the config.ini.
 | 
			
		||||
  bool is_category_stop_enabled();
 | 
			
		||||
 | 
			
		||||
  // Returns the value of the maximum amount of lines the IC chatlog
 | 
			
		||||
  // may contain, from config.ini.
 | 
			
		||||
  int get_max_log_size();
 | 
			
		||||
 | 
			
		||||
@ -102,6 +102,9 @@ private:
 | 
			
		||||
  QLabel *ui_continuous_lbl;
 | 
			
		||||
  QCheckBox *ui_continuous_cb;
 | 
			
		||||
 | 
			
		||||
  QLabel *ui_category_stop_lbl;
 | 
			
		||||
  QCheckBox *ui_category_stop_cb;
 | 
			
		||||
 | 
			
		||||
  QWidget *ui_callwords_tab;
 | 
			
		||||
  QWidget *ui_callwords_widget;
 | 
			
		||||
  QVBoxLayout *ui_callwords_layout;
 | 
			
		||||
 | 
			
		||||
@ -472,6 +472,19 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
 | 
			
		||||
 | 
			
		||||
  ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_continuous_cb);
 | 
			
		||||
 | 
			
		||||
  row += 1;
 | 
			
		||||
  ui_category_stop_lbl = new QLabel(ui_form_layout_widget);
 | 
			
		||||
  ui_category_stop_lbl->setText(tr("Stop Music w/ Category:"));
 | 
			
		||||
  ui_category_stop_lbl->setToolTip(
 | 
			
		||||
      tr("Stop music when double-clicking a category. If this is disabled, use the right-click context menu to stop music."));
 | 
			
		||||
 | 
			
		||||
  ui_gameplay_form->setWidget(row, QFormLayout::LabelRole, ui_category_stop_lbl);
 | 
			
		||||
 | 
			
		||||
  ui_category_stop_cb = new QCheckBox(ui_form_layout_widget);
 | 
			
		||||
  ui_category_stop_cb->setChecked(ao_app->is_category_stop_enabled());
 | 
			
		||||
 | 
			
		||||
  ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_category_stop_cb);
 | 
			
		||||
 | 
			
		||||
  QScrollArea *scroll = new QScrollArea(this);
 | 
			
		||||
  scroll->setWidget(ui_form_layout_widget);
 | 
			
		||||
  ui_gameplay_tab->setLayout(new QVBoxLayout);
 | 
			
		||||
@ -886,6 +899,7 @@ void AOOptionsDialog::save_pressed()
 | 
			
		||||
  configini->setValue("customchat", ui_customchat_cb->isChecked());
 | 
			
		||||
  configini->setValue("automatic_logging_enabled", ui_log_cb->isChecked());
 | 
			
		||||
  configini->setValue("continuous_playback", ui_continuous_cb->isChecked());
 | 
			
		||||
  configini->setValue("category_stop", ui_category_stop_cb->isChecked());
 | 
			
		||||
  QFile *callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini");
 | 
			
		||||
 | 
			
		||||
  if (callwordsini->open(QIODevice::WriteOnly | QIODevice::Truncate |
 | 
			
		||||
 | 
			
		||||
@ -1551,10 +1551,18 @@ void Courtroom::list_music()
 | 
			
		||||
  QTreeWidgetItem *parent = nullptr;
 | 
			
		||||
  for (int n_song = 0; n_song < music_list.size(); ++n_song) {
 | 
			
		||||
    QString i_song = music_list.at(n_song);
 | 
			
		||||
    // It's a stop song or a stop category
 | 
			
		||||
    // yes we cannot properly parse a stop song without a stop category cuz otherwise areas break
 | 
			
		||||
    // I hate this program
 | 
			
		||||
    // I hate qt5 for making .remove and .replace return a reference to the string (modify original var)
 | 
			
		||||
    // instead of returning a new string
 | 
			
		||||
    // please end my suffering
 | 
			
		||||
    QString temp = i_song;
 | 
			
		||||
    if (i_song == "~stop.mp3" || (temp.remove('=').toLower() == "stop"))
 | 
			
		||||
        continue;
 | 
			
		||||
    QString i_song_listname = i_song.left(i_song.lastIndexOf("."));
 | 
			
		||||
    i_song_listname = i_song_listname.right(
 | 
			
		||||
        i_song_listname.length() - (i_song_listname.lastIndexOf("/") + 1));
 | 
			
		||||
 | 
			
		||||
    QTreeWidgetItem *treeItem;
 | 
			
		||||
    if (i_song_listname != i_song &&
 | 
			
		||||
        parent != nullptr) // not a category, parent exists
 | 
			
		||||
@ -3749,9 +3757,9 @@ void Courtroom::handle_song(QStringList *p_contents)
 | 
			
		||||
    {
 | 
			
		||||
      effect_flags = p_contents->at(5).toInt();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool is_stop = f_song == "~stop.mp3";
 | 
			
		||||
    if (!mute_map.value(n_char)) {
 | 
			
		||||
      if (f_song == "~stop.mp3") {
 | 
			
		||||
      if (is_stop) {
 | 
			
		||||
        log_ic_text(str_char, str_show, "", tr("has stopped the music"));
 | 
			
		||||
        append_ic_text("", str_show, tr("has stopped the music"));
 | 
			
		||||
      }
 | 
			
		||||
@ -3760,7 +3768,7 @@ void Courtroom::handle_song(QStringList *p_contents)
 | 
			
		||||
        append_ic_text(f_song_clear, str_show, tr("has played a song"));
 | 
			
		||||
      }
 | 
			
		||||
      music_player->play(f_song, channel, looping, effect_flags);
 | 
			
		||||
      if (f_song == "~stop.mp3")
 | 
			
		||||
      if (is_stop)
 | 
			
		||||
        ui_music_name->setText(tr("None"));
 | 
			
		||||
      else if (channel == 0) {
 | 
			
		||||
        if (file_exists(ao_app->get_sfx_suffix(ao_app->get_music_path(f_song))) & !f_song.startsWith("http"))
 | 
			
		||||
@ -4701,7 +4709,7 @@ void Courtroom::on_music_list_double_clicked(QTreeWidgetItem *p_item,
 | 
			
		||||
{
 | 
			
		||||
  if (is_muted)
 | 
			
		||||
    return;
 | 
			
		||||
  if (p_item->parent() == nullptr) // i.e. we've clicked a category
 | 
			
		||||
  if (!ao_app->is_category_stop_enabled() && p_item->parent() == nullptr)
 | 
			
		||||
    return;
 | 
			
		||||
  column = 1; // Column 1 is always the metadata (which we want)
 | 
			
		||||
  QString p_song = p_item->text(column);
 | 
			
		||||
@ -4802,12 +4810,26 @@ void Courtroom::music_list_collapse_all()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Courtroom::music_stop()
 | 
			
		||||
{               // send a fake music packet with a nonexistent song
 | 
			
		||||
  if (is_muted) // this requires a special exception for "~stop.mp3" in
 | 
			
		||||
    return;     // tsuserver3, as it will otherwise reject songs not on
 | 
			
		||||
{
 | 
			
		||||
  if (is_muted)
 | 
			
		||||
    return;
 | 
			
		||||
  // Default fake song is a song present in Vanilla content, the ~stop.mp3
 | 
			
		||||
  QString fake_song = "~stop.mp3";
 | 
			
		||||
  // If the fake song is not present in the music list
 | 
			
		||||
  if (!music_list.contains(fake_song)) {
 | 
			
		||||
      // Loop through our music list
 | 
			
		||||
      for (QString song : music_list) {
 | 
			
		||||
          // Pick first song that does not contain a file extension
 | 
			
		||||
          if (!song.contains('.')) {
 | 
			
		||||
              // Use it as a fake song as the server we're working with must recognize song categories
 | 
			
		||||
              fake_song = song;
 | 
			
		||||
              break;
 | 
			
		||||
          }
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
  QStringList packet_contents; // its music list
 | 
			
		||||
  packet_contents.append(
 | 
			
		||||
      "~stop.mp3"); // this is our fake song, playing it triggers special code
 | 
			
		||||
      fake_song); // this is our fake song, playing it triggers special code
 | 
			
		||||
  packet_contents.append(QString::number(m_cid));
 | 
			
		||||
  if ((!ui_ic_chat_name->text().isEmpty() && ao_app->cccc_ic_support_enabled) ||
 | 
			
		||||
      ao_app->effects_enabled)
 | 
			
		||||
 | 
			
		||||
@ -1101,6 +1101,12 @@ bool AOApplication::is_continuous_enabled()
 | 
			
		||||
  return result.startsWith("true");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool AOApplication::is_category_stop_enabled()
 | 
			
		||||
{
 | 
			
		||||
  QString result = configini->value("category_stop", "true").value<QString>();
 | 
			
		||||
  return result.startsWith("true");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool AOApplication::get_casing_enabled()
 | 
			
		||||
{
 | 
			
		||||
  QString result = configini->value("casing_enabled", "false").value<QString>();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user