diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/aoapplication.cpp | 21 | ||||
| -rw-r--r-- | src/aoblipplayer.cpp | 80 | ||||
| -rw-r--r-- | src/aoevidencebutton.cpp | 2 | ||||
| -rw-r--r-- | src/aomusicplayer.cpp | 74 | ||||
| -rw-r--r-- | src/aooptionsdialog.cpp | 35 | ||||
| -rw-r--r-- | src/aosfxplayer.cpp | 97 | ||||
| -rw-r--r-- | src/charselect.cpp | 14 | ||||
| -rw-r--r-- | src/courtroom.cpp | 265 | ||||
| -rw-r--r-- | src/debug_functions.cpp | 9 | ||||
| -rw-r--r-- | src/discord_rich_presence.cpp | 36 | ||||
| -rw-r--r-- | src/evidence.cpp | 14 | ||||
| -rw-r--r-- | src/hardware_functions.cpp | 32 | ||||
| -rw-r--r-- | src/lobby.cpp | 33 | ||||
| -rw-r--r-- | src/main.cpp | 21 | ||||
| -rw-r--r-- | src/networkmanager.cpp | 19 | ||||
| -rw-r--r-- | src/packet_distribution.cpp | 127 | ||||
| -rw-r--r-- | src/path_functions.cpp | 2 | ||||
| -rw-r--r-- | src/text_file_functions.cpp | 19 |
18 files changed, 730 insertions, 170 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index d7c3e662..6213acd6 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -37,9 +37,9 @@ void AOApplication::construct_lobby() w_lobby = new Lobby(this); lobby_constructed = true; - QRect screenGeometry = QApplication::desktop()->screenGeometry(); - int x = (screenGeometry.width()-w_lobby->width()) / 2; - int y = (screenGeometry.height()-w_lobby->height()) / 2; + QRect geometry = QGuiApplication::primaryScreen()->geometry(); + int x = (geometry.width()-w_lobby->width()) / 2; + int y = (geometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); if (is_discord_enabled()) @@ -72,9 +72,9 @@ void AOApplication::construct_courtroom() w_courtroom = new Courtroom(this); courtroom_constructed = true; - QRect screenGeometry = QApplication::desktop()->screenGeometry(); - int x = (screenGeometry.width()-w_courtroom->width()) / 2; - int y = (screenGeometry.height()-w_courtroom->height()) / 2; + QRect geometry = QGuiApplication::primaryScreen()->geometry(); + int x = (geometry.width()-w_courtroom->width()) / 2; + int y = (geometry.height()-w_courtroom->height()) / 2; w_courtroom->move(x, y); } @@ -135,7 +135,7 @@ void AOApplication::server_disconnected() { if (courtroom_constructed) { - call_notice("Disconnected from server."); + call_notice(tr("Disconnected from server.")); construct_lobby(); destruct_courtroom(); } @@ -160,16 +160,15 @@ void AOApplication::ms_connect_finished(bool connected, bool will_retry) if (will_retry) { if (lobby_constructed) - w_lobby->append_error("Error connecting to master server. Will try again in " - + QString::number(net_manager->ms_reconnect_delay_ms / 1000.f) + " seconds."); + w_lobby->append_error(tr("Error connecting to master server. Will try again in %1 seconds.").arg(QString::number(net_manager->ms_reconnect_delay))); } else { - call_error("There was an error connecting to the master server.\n" + call_error(tr("There was an error connecting to the master server.\n" "We deploy multiple master servers to mitigate any possible downtime, " "but the client appears to have exhausted all possible methods of finding " "and connecting to one.\n" - "Please check your Internet connection and firewall, and please try again."); + "Please check your Internet connection and firewall, and please try again.")); } } } diff --git a/src/aoblipplayer.cpp b/src/aoblipplayer.cpp index 74757c50..1c668ab4 100644 --- a/src/aoblipplayer.cpp +++ b/src/aoblipplayer.cpp @@ -1,5 +1,6 @@ #include "aoblipplayer.h" +#if defined(BASSAUDIO) //Using bass.dll for the blips AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; @@ -17,7 +18,7 @@ void AOBlipPlayer::set_blips(QString p_sfx) m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); } - set_volume(m_volume); + set_volume_internal(m_volume); } void AOBlipPlayer::blip_tick() @@ -28,20 +29,89 @@ void AOBlipPlayer::blip_tick() m_cycle = 0; HSTREAM f_stream = m_stream_list[f_cycle]; - if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelPlay(f_stream, false); } -void AOBlipPlayer::set_volume(int p_value) +void AOBlipPlayer::set_volume(qreal p_value) { - m_volume = p_value; + m_volume = p_value / 100; + set_volume_internal(m_volume); +} - float volume = p_value / 100.0f; +void AOBlipPlayer::set_volume_internal(qreal p_value) +{ + float volume = p_value; for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) { BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); } } +#elif defined(QTAUDIO) //Using Qt's QSoundEffect class +AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOBlipPlayer::set_blips(QString p_sfx) +{ + QString f_path = ao_app->get_sounds_path(p_sfx); + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + m_blips.setSource(QUrl::fromLocalFile(f_path)); + } + + set_volume_internal(m_volume); +} + +void AOBlipPlayer::blip_tick() +{ + int f_cycle = m_cycle++; + + if (m_cycle == 5) + m_cycle = 0; + + m_blips.play(); +} + +void AOBlipPlayer::set_volume(qreal p_value) +{ + m_volume = p_value / 100; + set_volume_internal(m_volume); +} + +void AOBlipPlayer::set_volume_internal(qreal p_value) +{ + m_blips.setVolume(m_volume); +} +#else //No audio +AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOBlipPlayer::set_blips(QString p_sfx) +{ + +} + +void AOBlipPlayer::blip_tick() +{ + +} + +void AOBlipPlayer::set_volume(qreal p_value) +{ + +} + +void AOBlipPlayer::set_volume_internal(qreal p_value) +{ + +} +#endif diff --git a/src/aoevidencebutton.cpp b/src/aoevidencebutton.cpp index ab654bfe..4dc03959 100644 --- a/src/aoevidencebutton.cpp +++ b/src/aoevidencebutton.cpp @@ -86,6 +86,7 @@ void AOEvidenceButton::mouseDoubleClickEvent(QMouseEvent *e) evidence_double_clicked(m_id); } +/* void AOEvidenceButton::dragLeaveEvent(QMouseEvent *e) { //QWidget::dragLeaveEvent(e); @@ -95,6 +96,7 @@ void AOEvidenceButton::dragEnterEvent(QMouseEvent *e) { //QWidget::dragEnterEvent(e); } +*/ void AOEvidenceButton::enterEvent(QEvent * e) { diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index 7fcb277f..32848fb0 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -1,6 +1,6 @@ #include "aomusicplayer.h" - +#if defined(BASSAUDIO) AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() { m_parent = parent; @@ -55,3 +55,75 @@ void AOMusicPlayer::kill_loop() BASS_ChannelStop(m_stream); } +#elif defined(QTAUDIO) +AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() +{ + m_parent = parent; + ao_app = p_ao_app; +} + +AOMusicPlayer::~AOMusicPlayer() +{ + m_player.stop(); +} + +void AOMusicPlayer::play(QString p_song) +{ + m_player.stop(); + + QString f_path = ao_app->get_music_path(p_song); + + m_player.setMedia(QUrl::fromLocalFile(f_path)); + + this->set_volume(m_volume); + + m_player.play(); +} + +void AOMusicPlayer::set_volume(int p_value) +{ + m_volume = p_value; + m_player.setVolume(m_volume); +} + +QString AOMusicPlayer::get_path() +{ + return f_path; +} + +void AOMusicPlayer::kill_loop() +{ + // TODO QTAUDIO +} +#else +AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() +{ + m_parent = parent; + ao_app = p_ao_app; +} + +AOMusicPlayer::~AOMusicPlayer() +{ + +} + +void AOMusicPlayer::play(QString p_song) +{ + +} + +void AOMusicPlayer::set_volume(int p_value) +{ + +} + +QString AOMusicPlayer::get_path() +{ + return f_path; +} + +void AOMusicPlayer::kill_loop() +{ + +} +#endif
\ No newline at end of file diff --git a/src/aooptionsdialog.cpp b/src/aooptionsdialog.cpp index b0e1e996..30146c90 100644 --- a/src/aooptionsdialog.cpp +++ b/src/aooptionsdialog.cpp @@ -1,6 +1,5 @@ #include "aooptionsdialog.h" #include "aoapplication.h" -#include "bass.h" AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) { @@ -178,6 +177,21 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi ui_gameplay_form->setWidget(10, QFormLayout::FieldRole, ui_epilepsy_cb); + ui_language_label = new QLabel(ui_form_layout_widget); + ui_language_label->setText(tr("Language:")); + ui_language_label->setToolTip(tr("Sets the language if you don't want to use your system language.")); + ui_gameplay_form->setWidget(10, QFormLayout::LabelRole, ui_language_label); + + ui_language_combobox = new QComboBox(ui_form_layout_widget); + ui_language_combobox->addItem(configini->value("language", " ").value<QString>() + " - Keep current setting"); + ui_language_combobox->addItem(" - Default"); + ui_language_combobox->addItem("en - English"); + ui_language_combobox->addItem("de - Deutsch"); + ui_language_combobox->addItem("es - Español"); + ui_language_combobox->addItem("jp - 日本語"); + ui_language_combobox->addItem("ru - Русский"); + ui_gameplay_form->setWidget(10, QFormLayout::FieldRole, ui_language_combobox); + // Here we start the callwords tab. ui_callwords_tab = new QWidget(); ui_settings_tabs->addTab(ui_callwords_tab, tr("Callwords")); @@ -229,22 +243,30 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi ui_audio_device_combobox = new QComboBox(ui_audio_widget); - // Let's fill out the combobox with the available audio devices. + // Let's fill out the combobox with the available audio devices. Or don't if there is no audio int a = 0; - BASS_DEVICEINFO info; - if (needs_default_audiodev()) { + ui_audio_device_combobox->addItem("default"); - } + } + #ifdef BASSAUDIO + BASS_DEVICEINFO info; for (a = 0; BASS_GetDeviceInfo(a, &info); a++) { ui_audio_device_combobox->addItem(info.name); if (p_ao_app->get_audio_output_device() == info.name) ui_audio_device_combobox->setCurrentIndex(ui_audio_device_combobox->count()-1); } - + #elif defined QTAUDIO + foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) + { + ui_audio_device_combobox->addItem(deviceInfo.deviceName()); + if (p_ao_app->get_audio_output_device() == deviceInfo.deviceName()) + ui_audio_device_combobox->setCurrentIndex(ui_audio_device_combobox->count()-1); + } + #endif ui_audio_layout->setWidget(0, QFormLayout::FieldRole, ui_audio_device_combobox); ui_audio_volume_divider = new QFrame(ui_audio_widget); @@ -510,6 +532,7 @@ void AOOptionsDialog::save_pressed() configini->setValue("master", ui_ms_textbox->text()); configini->setValue("discord", ui_discord_cb->isChecked()); configini->setValue("shakeandflash", ui_epilepsy_cb->isChecked()); + configini->setValue("language", ui_language_combobox->currentText().left(2)); QFile* callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); diff --git a/src/aosfxplayer.cpp b/src/aosfxplayer.cpp index e39071e5..80b6ea3c 100644 --- a/src/aosfxplayer.cpp +++ b/src/aosfxplayer.cpp @@ -1,6 +1,7 @@ #include "aosfxplayer.h" #include "file_functions.h" +#if defined(BASSAUDIO) //Using bass.dll for sfx AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() { m_parent = parent; @@ -31,7 +32,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) BASS_ChannelStop(m_stream); m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); - set_volume(m_volume); + set_volume_internal(m_volume); if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); @@ -56,9 +57,95 @@ void AOSfxPlayer::stop() BASS_ChannelStop(m_stream); } -void AOSfxPlayer::set_volume(int p_value) +void AOSfxPlayer::set_volume(qreal p_value) { - m_volume = p_value; - float volume = p_value / 100.0f; - BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); + m_volume = p_value / 100; + set_volume_internal(m_volume); } + +void AOSfxPlayer::set_volume_internal(qreal p_value) +{ + float volume = p_value; + BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); +} +#elif defined(QTAUDIO) //Using Qt's QSoundEffect class +AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) +{ + m_sfx.stop(); + + QString misc_path = ""; + QString char_path = ""; + QString sound_path = ao_app->get_sounds_path(p_sfx); + + if (shout != "") + misc_path = ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx; + if (p_char != "") + char_path = ao_app->get_character_path(p_char, p_sfx); + + QString f_path; + + if (file_exists(char_path)) + f_path = char_path; + else if (file_exists(misc_path)) + f_path = misc_path; + else + f_path = sound_path; + + if (file_exists(f_path)) //if its missing, it will glitch out + { + m_sfx.setSource(QUrl::fromLocalFile(f_path)); + + set_volume_internal(m_volume); + + m_sfx.play(); + } +} + +void AOSfxPlayer::stop() +{ + m_sfx.stop(); +} + +void AOSfxPlayer::set_volume(qreal p_value) +{ + m_volume = p_value/100; + set_volume_internal(m_volume); +} + +void AOSfxPlayer::set_volume_internal(qreal p_value) +{ + m_sfx.setVolume(m_volume); +} +#else +AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app): QObject() +{ + m_parent = parent; + ao_app = p_ao_app; +} + +void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) +{ + +} + +void AOSfxPlayer::stop() +{ + +} + +void AOSfxPlayer::set_volume(qreal p_value) +{ + +} + +void AOSfxPlayer::set_volume_internal(qreal p_value) +{ + +} +#endif diff --git a/src/charselect.cpp b/src/charselect.cpp index 6edd87ef..875c8a51 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -97,7 +97,6 @@ void Courtroom::construct_char_select() set_size_and_pos(ui_char_buttons, "char_buttons"); - connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int))); connect(ui_back_to_lobby, SIGNAL(clicked()), this, SLOT(on_back_to_lobby_clicked())); connect(ui_char_select_left, SIGNAL(clicked()), this, SLOT(on_char_select_left_clicked())); @@ -105,9 +104,9 @@ void Courtroom::construct_char_select() connect(ui_spectator, SIGNAL(clicked()), this, SLOT(on_spectator_clicked())); - connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed(const QString&))); - connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked(int))); - connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked(int))); + connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed())); + connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked())); + connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked())); } void Courtroom::set_char_select() @@ -189,6 +188,7 @@ void Courtroom::char_clicked(int n_char) } else { + ao_app->send_server_packet(new AOPacket("PW#" + ui_char_password->text() + "#%")); ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_char) + "#" + get_hdid() + "#%")); } @@ -280,17 +280,17 @@ void Courtroom::filter_character_list() set_char_select_page(); } -void Courtroom::on_char_search_changed(const QString& newtext) +void Courtroom::on_char_search_changed() { filter_character_list(); } -void Courtroom::on_char_passworded_clicked(int newstate) +void Courtroom::on_char_passworded_clicked() { filter_character_list(); } -void Courtroom::on_char_taken_clicked(int newstate) +void Courtroom::on_char_taken_clicked() { filter_character_list(); } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 09055284..054603d3 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2,10 +2,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; - + #ifdef BASSAUDIO // Change the default audio output device to be the one the user has given // in his config.ini file for now. - int a = 0; + unsigned int a = 0; BASS_DEVICEINFO info; if (ao_app->get_audio_output_device() == "default") @@ -20,13 +20,29 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() if (ao_app->get_audio_output_device() == info.name) { BASS_SetDevice(a); - BASS_Init(a, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); + BASS_Init(static_cast<int>(a), 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); load_bass_opus_plugin(); qDebug() << info.name << "was set as the default audio output device."; break; } } } + #elif defined QTAUDIO + + if (ao_app->get_audio_output_device() != "default") + { + foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) + { + if (ao_app->get_audio_output_device() == deviceInfo.deviceName()) + { + ao_app->QtAudioDevice = deviceInfo; + qDebug() << deviceInfo.deviceName() << "was set as the default audio output device."; + break; + } + } + } + #endif + keepalive_timer = new QTimer(this); keepalive_timer->start(60000); @@ -47,20 +63,22 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() testimony_hide_timer = new QTimer(this); testimony_hide_timer->setSingleShot(true); - char_button_mapper = new QSignalMapper(this); - music_player = new AOMusicPlayer(this, ao_app); music_player->set_volume(0); + sfx_player = new AOSfxPlayer(this, ao_app); sfx_player->set_volume(0); + objection_player = new AOSfxPlayer(this, ao_app); objection_player->set_volume(0); + misc_sfx_player = new AOSfxPlayer(this, ao_app); misc_sfx_player->set_volume(0); frame_emote_sfx_player = new AOSfxPlayer(this, ao_app); frame_emote_sfx_player->set_volume(0); pair_frame_emote_sfx_player = new AOSfxPlayer(this, ao_app); // todo: recode pair // todo: recode fucking everything pair_frame_emote_sfx_player->set_volume(0); + blip_player = new AOBlipPlayer(this, ao_app); blip_player->set_volume(0); @@ -133,7 +151,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_chat_name = new QLineEdit(this); ui_ooc_chat_name->setFrame(false); - ui_ooc_chat_name->setPlaceholderText("Name"); + ui_ooc_chat_name->setPlaceholderText(tr("Name")); ui_ooc_chat_name->setMaxLength(30); ui_ooc_chat_name->setText(p_ao_app->get_default_username()); @@ -186,13 +204,18 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_switch_area_music = new AOButton(this, ao_app); ui_pre = new QCheckBox(this); - ui_pre->setText("Pre"); + ui_pre->setText(tr("Pre")); + ui_flip = new QCheckBox(this); - ui_flip->setText("Flip"); + ui_flip->setText(tr("Flip")); ui_flip->hide(); + ui_guard = new QCheckBox(this); - ui_guard->setText("Disable Modcalls"); + + ui_guard->setText(tr("Disable Modcalls")); + ui_guard->hide(); + ui_casing = new QCheckBox(this); ui_casing->setChecked(ao_app->get_casing_enabled()); ui_casing->setText(tr("Casing")); @@ -218,15 +241,15 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_prosecution_minus = new AOButton(this, ao_app); ui_text_color = new QComboBox(this); - ui_text_color->addItem("White"); - ui_text_color->addItem("Green"); - ui_text_color->addItem("Red"); - ui_text_color->addItem("Orange"); - ui_text_color->addItem("Blue"); - ui_text_color->addItem("Yellow"); - ui_text_color->addItem("Rainbow"); - ui_text_color->addItem("Pink"); - ui_text_color->addItem("Cyan"); + ui_text_color->addItem(tr("White")); + ui_text_color->addItem(tr("Green")); + ui_text_color->addItem(tr("Red")); + ui_text_color->addItem(tr("Orange")); + ui_text_color->addItem(tr("Blue")); + ui_text_color->addItem(tr("Yellow")); + ui_text_color->addItem(tr("Rainbow")); + ui_text_color->addItem(tr("Pink")); + ui_text_color->addItem(tr("Cyan")); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -245,10 +268,11 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_log_limit_spinbox->setValue(ao_app->get_max_log_size()); ui_mute_list = new QListWidget(this); + ui_pair_list = new QListWidget(this); ui_pair_offset_spinbox = new QSpinBox(this); ui_pair_offset_spinbox->setRange(-100,100); - ui_pair_offset_spinbox->setSuffix("% offset"); + ui_pair_offset_spinbox->setSuffix(tr("% offset")); ui_pair_button = new AOButton(this, ao_app); ui_evidence_button = new AOButton(this, ao_app); @@ -566,14 +590,14 @@ void Courtroom::set_widgets() ui_prosecution_bar->set_image("prosecutionbar" + QString::number(prosecution_bar_state) + ".png"); set_size_and_pos(ui_music_label, "music_label"); - ui_music_label->setText("Music"); + ui_music_label->setText(tr("Music")); set_size_and_pos(ui_sfx_label, "sfx_label"); - ui_sfx_label->setText("Sfx"); + ui_sfx_label->setText(tr("Sfx")); set_size_and_pos(ui_blip_label, "blip_label"); - ui_blip_label->setText("Blips"); + ui_blip_label->setText(tr("Blips")); set_size_and_pos(ui_log_limit_label, "log_limit_label"); - ui_log_limit_label->setText("Log limit"); + ui_log_limit_label->setText(tr("Log limit")); set_size_and_pos(ui_hold_it, "hold_it"); ui_hold_it->set_image("holdit.png"); @@ -583,7 +607,7 @@ void Courtroom::set_widgets() ui_take_that->set_image("takethat.png"); set_size_and_pos(ui_ooc_toggle, "ooc_toggle"); - ui_ooc_toggle->setText("Server"); + ui_ooc_toggle->setText(tr("Server")); set_size_and_pos(ui_witness_testimony, "witness_testimony"); ui_witness_testimony->set_image("witnesstestimony.png"); @@ -596,25 +620,25 @@ void Courtroom::set_widgets() ui_not_guilty->set_image("notguilty.png"); set_size_and_pos(ui_change_character, "change_character"); - ui_change_character->setText("Change character"); + ui_change_character->setText(tr("Change character")); set_size_and_pos(ui_reload_theme, "reload_theme"); - ui_reload_theme->setText("Reload theme"); + ui_reload_theme->setText(tr("Reload theme")); set_size_and_pos(ui_call_mod, "call_mod"); - ui_call_mod->setText("Call mod"); + ui_call_mod->setText(tr("Call mod")); set_size_and_pos(ui_settings, "settings"); - ui_settings->setText("Settings"); + ui_settings->setText(tr("Settings")); set_size_and_pos(ui_announce_casing, "casing_button"); - ui_announce_casing->setText("Casing"); + ui_announce_casing->setText(tr("Casing")); set_size_and_pos(ui_switch_area_music, "switch_area_music"); - ui_switch_area_music->setText("A/M"); + ui_switch_area_music->setText(tr("A/M")); set_size_and_pos(ui_pre, "pre"); - ui_pre->setText("Preanim"); + ui_pre->setText(tr("Preanim")); set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt"); set_size_and_pos(ui_flip, "flip"); @@ -695,7 +719,7 @@ void Courtroom::set_widgets() ui_selector->hide(); set_size_and_pos(ui_back_to_lobby, "back_to_lobby"); - ui_back_to_lobby->setText("Back to Lobby"); + ui_back_to_lobby->setText(tr("Back to Lobby")); set_size_and_pos(ui_char_password, "char_password"); @@ -738,7 +762,9 @@ void Courtroom::set_font(QWidget *widget, QString p_identifier) int f_weight = ao_app->get_font_size(p_identifier, design_file); QString class_name = widget->metaObject()->className(); - widget->setFont(QFont("Sans", f_weight)); + QString fontt = ao_app->get_font_name(p_identifier + "_font", design_file); + widget->setFont(QFont(fontt, f_weight)); + QColor f_color = ao_app->get_color(p_identifier + "_color", design_file); @@ -2333,6 +2359,7 @@ void Courtroom::chat_tick() //do not perform heavy operations here QString f_message = m_chatmessage[MESSAGE]; + f_message.remove(0, tick_pos); // Due to our new text speed system, we always need to stop the timer now. chat_tick_timer->stop(); @@ -2347,7 +2374,7 @@ void Courtroom::chat_tick() f_message.remove(0,2); } - if (tick_pos >= f_message.size()) + if (f_message.size() == 0) { text_state = 2; if (anim_state != 4) @@ -2359,9 +2386,21 @@ void Courtroom::chat_tick() else { - QString f_character = f_message.at(tick_pos); + QTextBoundaryFinder tbf(QTextBoundaryFinder::Grapheme, f_message); + QString f_character; + int f_char_length; + + tbf.toNextBoundary(); + + if (tbf.position() == -1) + f_character = f_message; + else + f_character = f_message.left(tbf.position()); + + f_char_length = f_character.length(); f_character = f_character.toHtmlEscaped(); + if (f_character == " ") ui_vp_message->insertPlainText(" "); @@ -2466,7 +2505,7 @@ void Courtroom::chat_tick() else { next_character_is_not_special = true; - tick_pos--; + tick_pos -= f_char_length; } } @@ -2487,7 +2526,7 @@ void Courtroom::chat_tick() else { next_character_is_not_special = true; - tick_pos--; + tick_pos -= f_char_length; } } @@ -2531,11 +2570,7 @@ void Courtroom::chat_tick() case INLINE_GREY: ui_vp_message->insertHtml("<font color=\""+ get_text_color("_inline_grey").name() +"\">" + f_character + "</font>"); break; - default: - ui_vp_message->insertHtml(f_character); - break; } - } else { @@ -2586,7 +2621,7 @@ void Courtroom::chat_tick() if(blank_blip) qDebug() << "blank_blip found true"; - if (f_message.at(tick_pos) != ' ' || blank_blip) + if (f_character != ' ' || blank_blip) { if (blip_pos % blip_rate == 0 && !formatting_char) @@ -2598,7 +2633,7 @@ void Courtroom::chat_tick() ++blip_pos; } - ++tick_pos; + tick_pos += f_char_length; // Restart the timer, but according to the newly set speeds, if there were any. // Keep the speed at bay. @@ -2625,6 +2660,7 @@ void Courtroom::chat_tick() } } + void Courtroom::show_testimony() { if (!testimony_in_progress || m_chatmessage[SIDE] != "wit") @@ -2997,19 +3033,24 @@ void Courtroom::on_ooc_return_pressed() toggle_judge_buttons(false); } } + else if (ooc_message.startsWith("/login")) + { + ui_guard->show(); + append_server_chatmessage("CLIENT", tr("You were granted the Guard button."), "1"); + } else if (ooc_message.startsWith("/rainbow") && ao_app->yellow_text_enabled && !rainbow_appended) { //ui_text_color->addItem("Rainbow"); ui_ooc_chat_message->clear(); //rainbow_appended = true; - append_server_chatmessage("CLIENT", "This does nohing, but there you go.", "1"); + append_server_chatmessage("CLIENT", tr("This does nothing, but there you go."), "1"); return; } else if (ooc_message.startsWith("/settings")) { ui_ooc_chat_message->clear(); ao_app->call_settings_menu(); - append_server_chatmessage("CLIENT", "You opened the settings menu.", "1"); + append_server_chatmessage("CLIENT", tr("You opened the settings menu."), "1"); return; } else if (ooc_message.startsWith("/pair")) @@ -3024,19 +3065,20 @@ void Courtroom::on_ooc_return_pressed() if (whom > -1) { other_charid = whom; - QString msg = "You will now pair up with "; + QString msg = tr("You will now pair up with "); msg.append(char_list.at(whom).name); - msg.append(" if they also choose your character in return."); + msg.append(tr(" if they also choose your character in return.")); append_server_chatmessage("CLIENT", msg, "1"); } else { - append_server_chatmessage("CLIENT", "You are no longer paired with anyone.", "1"); + other_charid = -1; + append_server_chatmessage("CLIENT", tr("You are no longer paired with anyone."), "1"); } } else { - append_server_chatmessage("CLIENT", "Are you sure you typed that well? The char ID could not be recognised.", "1"); + append_server_chatmessage("CLIENT", tr("Are you sure you typed that well? The char ID could not be recognised."), "1"); } return; } @@ -3052,32 +3094,32 @@ void Courtroom::on_ooc_return_pressed() if (off >= -100 && off <= 100) { offset_with_pair = off; - QString msg = "You have set your offset to "; + QString msg = tr("You have set your offset to "); msg.append(QString::number(off)); msg.append("%."); append_server_chatmessage("CLIENT", msg, "1"); } else { - append_server_chatmessage("CLIENT", "Your offset must be between -100% and 100%!", "1"); + append_server_chatmessage("CLIENT", tr("Your offset must be between -100% and 100%!"), "1"); } } else { - append_server_chatmessage("CLIENT", "That offset does not look like one.", "1"); + append_server_chatmessage("CLIENT", tr("That offset does not look like one."), "1"); } return; } else if (ooc_message.startsWith("/switch_am")) { - append_server_chatmessage("CLIENT", "You switched your music and area list.", "1"); + append_server_chatmessage("CLIENT", tr("You switched your music and area list."), "1"); on_switch_area_music_clicked(); ui_ooc_chat_message->clear(); return; } else if (ooc_message.startsWith("/enable_blocks")) { - append_server_chatmessage("CLIENT", "You have forcefully enabled features that the server may not support. You may not be able to talk IC, or worse, because of this.", "1"); + append_server_chatmessage("CLIENT", tr("You have forcefully enabled features that the server may not support. You may not be able to talk IC, or worse, because of this."), "1"); ao_app->cccc_ic_support_enabled = true; ao_app->arup_enabled = true; ao_app->modcall_reason_enabled = true; @@ -3088,9 +3130,9 @@ void Courtroom::on_ooc_return_pressed() else if (ooc_message.startsWith("/non_int_pre")) { if (ui_pre_non_interrupt->isChecked()) - append_server_chatmessage("CLIENT", "Your pre-animations interrupt again.", "1"); + append_server_chatmessage("CLIENT", tr("Your pre-animations interrupt again."), "1"); else - append_server_chatmessage("CLIENT", "Your pre-animations will not interrupt text.", "1"); + append_server_chatmessage("CLIENT", tr("Your pre-animations will not interrupt text."), "1"); ui_pre_non_interrupt->setChecked(!ui_pre_non_interrupt->isChecked()); ui_ooc_chat_message->clear(); return; @@ -3101,7 +3143,7 @@ void Courtroom::on_ooc_return_pressed() if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { - append_server_chatmessage("CLIENT", "Couldn't open chatlog.txt to write into.", "1"); + append_server_chatmessage("CLIENT", tr("Couldn't open chatlog.txt to write into."), "1"); ui_ooc_chat_message->clear(); return; } @@ -3114,7 +3156,7 @@ void Courtroom::on_ooc_return_pressed() file.close(); - append_server_chatmessage("CLIENT", "The IC chatlog has been saved.", "1"); + append_server_chatmessage("CLIENT", tr("The IC chatlog has been saved."), "1"); ui_ooc_chat_message->clear(); return; } @@ -3126,7 +3168,7 @@ void Courtroom::on_ooc_return_pressed() if (!casefolder.exists()) { QDir::current().mkdir("base/" + casefolder.dirName()); - append_server_chatmessage("CLIENT", "You don't have a `base/cases/` folder! It was just made for you, but seeing as it WAS just made for you, it's likely the case file you're looking for can't be found in there.", "1"); + append_server_chatmessage("CLIENT", tr("You don't have a `base/cases/` folder! It was just made for you, but seeing as it WAS just made for you, it's likely the case file you're looking for can't be found in there."), "1"); ui_ooc_chat_message->clear(); return; } @@ -3137,7 +3179,7 @@ void Courtroom::on_ooc_return_pressed() if (command.size() < 2) { - append_server_chatmessage("CLIENT", "You need to give a filename to load (extension not needed)! Make sure that it is in the `base/cases/` folder, and that it is a correctly formatted ini.\nCases you can load: " + caseslist.join(", "), "1"); + append_server_chatmessage("CLIENT", tr("You need to give a filename to load (extension not needed)! Make sure that it is in the `base/cases/` folder, and that it is a correctly formatted ini.\nCases you can load: %1").arg(caseslist.join(", ")), "1"); ui_ooc_chat_message->clear(); return; } @@ -3145,7 +3187,7 @@ void Courtroom::on_ooc_return_pressed() if (command.size() > 2) { - append_server_chatmessage("CLIENT", "Too many arguments to load a case! You only need one filename, without extension.", "1"); + append_server_chatmessage("CLIENT", tr("Too many arguments to load a case! You only need one filename, without extension."), "1"); ui_ooc_chat_message->clear(); return; } @@ -3158,13 +3200,13 @@ void Courtroom::on_ooc_return_pressed() QString casestatus = casefile.value("status", "").value<QString>(); if (!caseauth.isEmpty()) - append_server_chatmessage("CLIENT", "Case made by " + caseauth + ".", "1"); + append_server_chatmessage("CLIENT", tr("Case made by %1.").arg(caseauth), "1"); if (!casedoc.isEmpty()) ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/doc " + casedoc + "#%")); if (!casestatus.isEmpty()) ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/status " + casestatus + "#%")); if (!cmdoc.isEmpty()) - append_server_chatmessage("CLIENT", "Navigate to " + cmdoc + " for the CM doc.", "1"); + append_server_chatmessage("CLIENT", tr("Navigate to %1 for the CM doc.").arg(cmdoc), "1"); for (int i = local_evidence_list.size() - 1; i >= 0; i--) { ao_app->send_server_packet(new AOPacket("DE#" + QString::number(i) + "#%")); @@ -3183,10 +3225,64 @@ void Courtroom::on_ooc_return_pressed() ao_app->send_server_packet(new AOPacket("PE", f_contents)); } - append_server_chatmessage("CLIENT", "Your case \"" + command[1] + "\" was loaded!", "1"); + append_server_chatmessage("CLIENT", tr("Your case \"%1\" was loaded!").arg(command[1]), "1"); ui_ooc_chat_message->clear(); return; } + else if(ooc_message.startsWith("/save_case")) + { + QStringList command = ooc_message.split(" ", QString::SkipEmptyParts); + + QDir casefolder("base/cases"); + if (!casefolder.exists()) + { + QDir::current().mkdir("base/" + casefolder.dirName()); + append_server_chatmessage("CLIENT", tr("You don't have a `base/cases/` folder! It was just made for you, but seeing as it WAS just made for you, it's likely that you somehow deleted it."), "1"); + ui_ooc_chat_message->clear(); + return; + } + QStringList caseslist = casefolder.entryList(); + caseslist.removeOne("."); + caseslist.removeOne(".."); + caseslist.replaceInStrings(".ini",""); + + if (command.size() < 3) + { + append_server_chatmessage("CLIENT", tr("You need to give a filename to save (extension not needed) and the courtroom status!"), "1"); + ui_ooc_chat_message->clear(); + return; + } + + + if (command.size() > 3) + { + append_server_chatmessage("CLIENT", tr("Too many arguments to save a case! You only need a filename without extension and the courtroom status!"), "1"); + ui_ooc_chat_message->clear(); + return; + } + QSettings casefile("base/cases/" + command[1] + ".ini", QSettings::IniFormat); + casefile.setValue("author",ui_ooc_chat_name->text()); + casefile.setValue("cmdoc",""); + casefile.setValue("doc", ""); + casefile.setValue("status",command[2]); + casefile.sync(); + for(int i = local_evidence_list.size() - 1; i >= 0; i--) + { + QString clean_evidence_dsc = local_evidence_list[i].description.replace(QRegularExpression("<owner = ...>..."), ""); + clean_evidence_dsc = clean_evidence_dsc.replace(clean_evidence_dsc.lastIndexOf(">"), 1, ""); + casefile.beginGroup(QString::number(i)); + casefile.sync(); + casefile.setValue("name",local_evidence_list[i].name); + casefile.setValue("description",local_evidence_list[i].description); + casefile.setValue("image",local_evidence_list[i].image); + casefile.endGroup(); + } + casefile.sync(); + append_server_chatmessage("CLIENT", tr("Succesfully saved, edit doc and cmdoc link on the ini!"), "1"); + ui_ooc_chat_message->clear(); + return; + + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); @@ -3210,7 +3306,7 @@ void Courtroom::on_ooc_toggle_clicked() { ui_ms_chatlog->show(); ui_server_chatlog->hide(); - ui_ooc_toggle->setText("Master"); + ui_ooc_toggle->setText(tr("Master")); server_ooc = false; } @@ -3218,7 +3314,7 @@ void Courtroom::on_ooc_toggle_clicked() { ui_ms_chatlog->hide(); ui_server_chatlog->show(); - ui_ooc_toggle->setText("Server"); + ui_ooc_toggle->setText(tr("Server")); server_ooc = true; } @@ -3316,6 +3412,7 @@ void Courtroom::on_pair_list_clicked(QModelIndex p_index) QListWidgetItem *f_item = ui_pair_list->item(p_index.row()); QString f_char = f_item->text(); QString real_char; + int f_cid = -1; if (f_char.endsWith(" [x]")) { @@ -3323,17 +3420,19 @@ void Courtroom::on_pair_list_clicked(QModelIndex p_index) f_item->setText(real_char); } else - real_char = f_char; - - int f_cid = -1; - - for (int n_char = 0 ; n_char < char_list.size() ; n_char++) { + real_char = f_char; + for (int n_char = 0 ; n_char < char_list.size() ; n_char++) + { if (char_list.at(n_char).name == real_char) f_cid = n_char; + } } - if (f_cid < 0 || f_cid >= char_list.size()) + + + + if (f_cid < -2 || f_cid >= char_list.size()) { qDebug() << "W: " << real_char << " not present in char_list"; return; @@ -3352,8 +3451,10 @@ void Courtroom::on_pair_list_clicked(QModelIndex p_index) for (int i = 0; i < ui_pair_list->count(); i++) { ui_pair_list->item(i)->setText(sorted_pair_list.at(i)); } - - f_item->setText(real_char + " [x]"); + if(other_charid != -1) + { + f_item->setText(real_char + " [x]"); + } } void Courtroom::on_music_list_double_clicked(QModelIndex p_model) @@ -3695,8 +3796,8 @@ void Courtroom::on_call_mod_clicked() QInputDialog input; input.setWindowFlags(Qt::WindowSystemMenuHint); - input.setLabelText("Reason:"); - input.setWindowTitle("Call Moderator"); + input.setLabelText(tr("Reason:")); + input.setWindowTitle(tr("Call Moderator")); auto code = input.exec(); if (code != QDialog::Accepted) @@ -3704,10 +3805,10 @@ void Courtroom::on_call_mod_clicked() QString text = input.textValue(); if (text.isEmpty()) { - errorBox.critical(nullptr, "Error", "You must provide a reason."); + errorBox.critical(nullptr, tr("Error"), tr("You must provide a reason.")); return; } else if (text.length() > 256) { - errorBox.critical(nullptr, "Error", "The message is too long."); + errorBox.critical(nullptr, tr("Error"), tr("The message is too long.")); return; } @@ -3854,23 +3955,29 @@ Courtroom::~Courtroom() delete blip_player; } + #if (defined (_WIN32) || defined (_WIN64)) void Courtroom::load_bass_opus_plugin() { + #ifdef BASSAUDIO BASS_PluginLoad("bassopus.dll", 0); + #endif } #elif (defined (LINUX) || defined (__linux__)) void Courtroom::load_bass_opus_plugin() { + #ifdef BASSAUDIO BASS_PluginLoad("libbassopus.so", 0); + #endif } #elif defined __APPLE__ void Courtroom::load_bass_opus_plugin() { QString libpath = ao_app->get_base_path() + "../../Frameworks/libbassopus.dylib"; QByteArray ba = libpath.toLocal8Bit(); - + #ifdef BASSAUDIO BASS_PluginLoad(ba.data(), 0); + #endif } #else #error This operating system is unsupported for bass plugins. diff --git a/src/debug_functions.cpp b/src/debug_functions.cpp index 77f2f35a..a790610d 100644 --- a/src/debug_functions.cpp +++ b/src/debug_functions.cpp @@ -1,11 +1,14 @@ +#include <QMessageBox> +#include <QCoreApplication> + #include "debug_functions.h" void call_error(QString p_message) { QMessageBox *msgBox = new QMessageBox; - msgBox->setText("Error: " + p_message); - msgBox->setWindowTitle("Error"); + msgBox->setText(QCoreApplication::translate("debug_functions", "Error: %1").arg(p_message)); + msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Error")); //msgBox->setWindowModality(Qt::NonModal); @@ -17,7 +20,7 @@ void call_notice(QString p_message) QMessageBox *msgBox = new QMessageBox; msgBox->setText(p_message); - msgBox->setWindowTitle("Notice"); + msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Notice")); //msgBox->setWindowModality(Qt::NonModal); diff --git a/src/discord_rich_presence.cpp b/src/discord_rich_presence.cpp index 10f5833e..95a824a1 100644 --- a/src/discord_rich_presence.cpp +++ b/src/discord_rich_presence.cpp @@ -2,6 +2,7 @@ namespace AttorneyOnline { +#ifdef DISCORD Discord::Discord() { DiscordEventHandlers handlers; @@ -11,10 +12,10 @@ Discord::Discord() qInfo() << "Discord RPC ready"; }; handlers.disconnected = [](int errorCode, const char* message) { - qInfo() << "Discord RPC disconnected! " << message; + qInfo() << "Discord RPC disconnected! " << message << errorCode; }; handlers.errored = [](int errorCode, const char* message) { - qWarning() << "Discord RPC errored out! " << message; + qWarning() << "Discord RPC errored out! " << message << errorCode; }; qInfo() << "Initializing Discord RPC"; Discord_Initialize(APPLICATION_ID, &handlers, 1, nullptr); @@ -99,5 +100,36 @@ void Discord::state_spectate() presence.state = "Spectating"; Discord_UpdatePresence(&presence); } +#else +Discord::Discord() +{ + +} + +Discord::~Discord() +{ + +} + +void Discord::state_lobby() +{ + +} +void Discord::state_server(std::string name, std::string server_id) +{ + qDebug() << "Discord RPC: Setting server state"; +} + +void Discord::state_character(std::string name) +{ + qDebug() << "Discord RPC: Setting character state"; +} + +void Discord::state_spectate() +{ + qDebug() << "Discord RPC: Setting specator state"; + +} +#endif } diff --git a/src/evidence.cpp b/src/evidence.cpp index 4e796642..341bed0f 100644 --- a/src/evidence.cpp +++ b/src/evidence.cpp @@ -22,7 +22,7 @@ void Courtroom::construct_evidence() ui_evidence_delete = new AOButton(ui_evidence_overlay, ao_app); ui_evidence_image_name = new AOLineEdit(ui_evidence_overlay); ui_evidence_image_button = new AOButton(ui_evidence_overlay, ao_app); - ui_evidence_image_button->setText("Choose.."); + ui_evidence_image_button->setText(tr("Choose...")); ui_evidence_x = new AOButton(ui_evidence_overlay, ao_app); ui_evidence_description = new AOTextEdit(ui_evidence_overlay); @@ -188,11 +188,12 @@ void Courtroom::on_evidence_image_name_edited() void Courtroom::on_evidence_image_button_clicked() { + QDir dir(ao_app->get_base_path() + "evidence"); QFileDialog dialog(this); dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("Images (*.png)")); dialog.setViewMode(QFileDialog::List); - dialog.setDirectory(ao_app->get_base_path() + "evidence"); + dialog.setDirectory(dir); QStringList filenames; @@ -203,13 +204,8 @@ void Courtroom::on_evidence_image_button_clicked() return; QString filename = filenames.at(0); - - QStringList split_filename = filename.split("/"); - - filename = split_filename.at(split_filename.size() - 1); - + filename = dir.relativeFilePath(filename); ui_evidence_image_name->setText(filename); - on_evidence_image_name_edited(); } @@ -269,7 +265,7 @@ void Courtroom::on_evidence_hover(int p_id, bool p_state) if (p_state) { if (final_id == local_evidence_list.size()) - ui_evidence_name->setText("Add new evidence..."); + ui_evidence_name->setText(tr("Add new evidence...")); else if (final_id < local_evidence_list.size()) ui_evidence_name->setText(local_evidence_list.at(final_id).name); } diff --git a/src/hardware_functions.cpp b/src/hardware_functions.cpp index ebba6ab7..bd6a6c3c 100644 --- a/src/hardware_functions.cpp +++ b/src/hardware_functions.cpp @@ -5,12 +5,12 @@ #if (defined (_WIN32) || defined (_WIN64)) #include <windows.h> -DWORD dwVolSerial; -BOOL bIsRetrieved; +static DWORD dwVolSerial; +static BOOL bIsRetrieved; QString get_hdid() { - bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL); + bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), nullptr, 0, &dwVolSerial, nullptr, nullptr, nullptr, 0); if (bIsRetrieved) return QString::number(dwVolSerial, 16); @@ -18,7 +18,6 @@ QString get_hdid() //a totally random string //what could possibly go wrong return "gxsps32sa9fnwic92mfbs0"; - } #elif (defined (LINUX) || defined (__linux__)) @@ -51,10 +50,31 @@ QString get_hdid() } #elif defined __APPLE__ +#include <CoreFoundation/CoreFoundation.h> +#include <IOKit/IOKitLib.h> + QString get_hdid() { - //hdids are broken at this point anyways - return "just a mac passing by"; + CFStringRef serial; + char buffer[64] = {0}; + QString hdid; + io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, + IOServiceMatching("IOPlatformExpertDevice")); + if (platformExpert) + { + CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, + CFSTR(kIOPlatformSerialNumberKey), + kCFAllocatorDefault, 0); + if (serialNumberAsCFString) { + serial = (CFStringRef)serialNumberAsCFString; + } + if (CFStringGetCString(serial, buffer, 64, kCFStringEncodingUTF8)) { + hdid = buffer; + } + + IOObjectRelease(platformExpert); + } + return hdid; } #else diff --git a/src/lobby.cpp b/src/lobby.cpp index 6f8db065..17a07a7a 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -9,7 +9,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; - this->setWindowTitle("Attorney Online 2"); + this->setWindowTitle(tr("Attorney Online 2")); this->setWindowIcon(QIcon(":/logo.png")); ui_background = new AOImage(this, ao_app); @@ -26,7 +26,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() ui_chatbox = new AOTextArea(this); ui_chatbox->setOpenExternalLinks(true); ui_chatname = new QLineEdit(this); - ui_chatname->setPlaceholderText("Name"); + ui_chatname->setPlaceholderText(tr("Name")); ui_chatname->setText(ao_app->get_ooc_name()); ui_chatmessage = new QLineEdit(this); ui_loading_background = new AOImage(this, ao_app); @@ -47,6 +47,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() connect(ui_connect, SIGNAL(released()), this, SLOT(on_connect_released())); connect(ui_about, SIGNAL(clicked()), this, SLOT(on_about_clicked())); connect(ui_server_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_server_list_clicked(QModelIndex))); + connect(ui_server_list, SIGNAL(activated(QModelIndex)), this, SLOT(on_server_list_doubleclicked(QModelIndex))); connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed())); connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled())); @@ -71,9 +72,9 @@ void Lobby::set_widgets() qDebug() << "W: did not find lobby width or height in " << filename; // Most common symptom of bad config files and missing assets. - call_notice("It doesn't look like your client is set up correctly.\n" + call_notice(tr("It doesn't look like your client is set up correctly.\n" "Did you download all resources correctly from tiny.cc/getao, " - "including the large 'base' folder?"); + "including the large 'base' folder?")); this->resize(517, 666); } @@ -101,7 +102,7 @@ void Lobby::set_widgets() ui_connect->set_image("connect.png"); set_size_and_pos(ui_version, "version"); - ui_version->setText("Version: " + ao_app->get_version_string()); + ui_version->setText(tr("Version: %1").arg(ao_app->get_version_string())); set_size_and_pos(ui_about, "about"); ui_about->set_image("about.png"); @@ -111,7 +112,7 @@ void Lobby::set_widgets() "font: bold;"); set_size_and_pos(ui_player_count, "player_count"); - ui_player_count->setText("Offline"); + ui_player_count->setText(tr("Offline")); ui_player_count->setStyleSheet("font: bold;" "color: white;" "qproperty-alignment: AlignCenter;"); @@ -144,11 +145,11 @@ void Lobby::set_widgets() ui_loading_text->setFrameStyle(QFrame::NoFrame); ui_loading_text->setStyleSheet("background-color: rgba(0, 0, 0, 0);" "color: rgba(255, 128, 0, 255);"); - ui_loading_text->append("Loading"); + ui_loading_text->append(tr("Loading")); set_size_and_pos(ui_progress_bar, "progress_bar"); set_size_and_pos(ui_cancel, "cancel"); - ui_cancel->setText("Cancel"); + ui_cancel->setText(tr("Cancel")); ui_loading_background->hide(); @@ -286,9 +287,13 @@ void Lobby::on_about_clicked() QMessageBox::about(this, "About", msg); } +//clicked on an item in the serverlist void Lobby::on_server_list_clicked(QModelIndex p_model) { + if (p_model != last_model) + { server_type f_server; + last_model = p_model; int n_server = p_model.row(); if (n_server < 0) @@ -317,11 +322,19 @@ void Lobby::on_server_list_clicked(QModelIndex p_model) ui_description->moveCursor(QTextCursor::Start); ui_description->ensureCursorVisible(); - ui_player_count->setText("Offline"); + ui_player_count->setText(tr("Offline")); ui_connect->setEnabled(false); ao_app->net_manager->connect_to_server(f_server); + } +} + +//doubleclicked on an item in the serverlist so we'll connect right away +void Lobby::on_server_list_doubleclicked(QModelIndex p_model) +{ + on_server_list_clicked(p_model); + on_connect_released(); } void Lobby::on_chatfield_return_pressed() @@ -377,7 +390,7 @@ void Lobby::append_error(QString f_message) void Lobby::set_player_count(int players_online, int max_players) { - QString f_string = "Online: " + QString::number(players_online) + "/" + QString::number(max_players); + QString f_string = tr("Online: %1/%2").arg(QString::number(players_online)).arg(QString::number(max_players)); ui_player_count->setText(f_string); } diff --git a/src/main.cpp b/src/main.cpp index 5aae5c6e..778323fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ - #include "aoapplication.h" #include "datatypes.h" @@ -7,6 +6,9 @@ #include "courtroom.h" #include <QPluginLoader> #include <QDebug> +#include <QTranslator> +#include <QLibraryInfo> + int main(int argc, char *argv[]) { #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0) @@ -17,6 +19,23 @@ int main(int argc, char *argv[]) #endif AOApplication main_app(argc, argv); + + QSettings *configini = main_app.configini; + + QString p_language = configini->value("language", QLocale::system().name()).toString(); + if (p_language == " " || p_language == "") + p_language = QLocale::system().name(); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + p_language, + QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + main_app.installTranslator(&qtTranslator); + + QTranslator appTranslator; + qDebug() << ":/resource/translations/ao_" + p_language; + appTranslator.load("ao_" + p_language, ":/resource/translations/"); + main_app.installTranslator(&appTranslator); + main_app.construct_lobby(); main_app.w_lobby->show(); main_app.net_manager->connect_to_master(); diff --git a/src/networkmanager.cpp b/src/networkmanager.cpp index 288a9007..a9810d49 100644 --- a/src/networkmanager.cpp +++ b/src/networkmanager.cpp @@ -78,11 +78,8 @@ void NetworkManager::ship_server_packet(QString p_packet) void NetworkManager::handle_ms_packet() { - char buffer[buffer_max_size]; - std::memset(buffer, 0, buffer_max_size); - ms_socket->read(buffer, buffer_max_size); - - QString in_data = buffer; + QByteArray buffer = ms_socket->readAll(); + QString in_data = QString::fromUtf8(buffer, buffer.size()); if (!in_data.endsWith("%")) { @@ -137,7 +134,9 @@ void NetworkManager::on_srv_lookup() for (const QDnsServiceRecord &record : srv_records) { +#ifdef DEBUG_NETWORK qDebug() << "Connecting to " << record.target() << ":" << record.port(); +#endif ms_socket->connectToHost(record.target(), record.port()); QTime timer; timer.start(); @@ -206,7 +205,7 @@ void NetworkManager::on_ms_socket_error(QAbstractSocket::SocketError error) emit ms_connect_finished(false, true); - ms_reconnect_timer->start(ms_reconnect_delay_ms); + ms_reconnect_timer->start(ms_reconnect_delay * 1000); } void NetworkManager::retry_ms_connect() @@ -217,11 +216,8 @@ void NetworkManager::retry_ms_connect() void NetworkManager::handle_server_packet() { - char buffer[buffer_max_size]; - std::memset(buffer, 0, buffer_max_size); - server_socket->read(buffer, buffer_max_size); - - QString in_data = buffer; + QByteArray buffer = server_socket->readAll(); + QString in_data = QString::fromUtf8(buffer, buffer.size()); if (!in_data.endsWith("%")) { @@ -249,4 +245,3 @@ void NetworkManager::handle_server_packet() ao_app->server_packet_received(f_packet); } } - diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 7ad24739..fe26849f 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -43,8 +43,10 @@ void AOApplication::ms_packet_received(AOPacket *p_packet) QString header = p_packet->get_header(); QStringList f_contents = p_packet->get_contents(); +#ifdef DEBUG_NETWORK if (header != "CHECK") qDebug() << "R(ms):" << p_packet->to_string(); +#endif if (header == "ALL") { @@ -130,8 +132,16 @@ void AOApplication::ms_packet_received(AOPacket *p_packet) } } - call_notice("Outdated version! Your version: " + get_version_string() - + "\nPlease go to aceattorneyonline.com to update."); + call_notice(tr("Outdated version! Your version: %1\n" + "Please go to aceattorneyonline.com to update.") + .arg(get_version_string())); + destruct_courtroom(); + destruct_lobby(); + } + else if (header == "DOOM") + { + call_notice(tr("You have been exiled from AO.\n" + "Have a nice day.")); destruct_courtroom(); destruct_lobby(); } @@ -149,8 +159,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QStringList f_contents = p_packet->get_contents(); QString f_packet = p_packet->to_string(); +#ifdef DEBUG_NETWORK if (header != "checkconnection") qDebug() << "R:" << f_packet; +#endif if (header == "decryptor") { @@ -193,6 +205,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) s_pv = f_contents.at(0).toInt(); server_software = f_contents.at(1); + w_lobby->enable_connect_button(); + send_server_packet(new AOPacket("ID#AO2#" + get_version_string() + "#%")); } else if (header == "CT") @@ -266,7 +280,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) courtroom_loaded = false; - QString window_title = "Attorney Online 2"; + QString window_title = tr("Attorney Online 2"); int selected_server = w_lobby->get_selected_server(); QString server_address = "", server_name = ""; @@ -292,7 +306,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->set_window_title(window_title); w_lobby->show_loading_overlay(); - w_lobby->set_loading_text("Loading"); + w_lobby->set_loading_text(tr("Loading")); w_lobby->set_loading_value(0); AOPacket *f_packet; @@ -335,7 +349,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) ++loaded_evidence; - w_lobby->set_loading_text("Loading evidence:\n" + QString::number(loaded_evidence) + "/" + QString::number(evidence_list_size)); + w_lobby->set_loading_text(tr("Loading evidence:\n%1/%2").arg(QString::number(loaded_evidence)).arg(QString::number(evidence_list_size))); w_courtroom->append_evidence(f_evi); @@ -347,6 +361,65 @@ void AOApplication::server_packet_received(AOPacket *p_packet) send_server_packet(new AOPacket("AE#" + next_packet_number + "#%")); } + else if (header == "EM") + { + if (!courtroom_constructed) + goto end; + + bool musics_time = false; + int areas = 0; + + for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) + { + if (f_contents.at(n_element).toInt() != loaded_music) + break; + + if (n_element == f_contents.size() - 1) + break; + + QString f_music = f_contents.at(n_element + 1); + + ++loaded_music; + + w_lobby->set_loading_text(tr("Loading music:\n%1/%2").arg(QString::number(loaded_music)).arg(QString::number(music_list_size))); + + if (musics_time) + { + w_courtroom->append_music(f_music); + } + else + { + if (f_music.endsWith(".wav") || + f_music.endsWith(".mp3") || + f_music.endsWith(".mp4") || + f_music.endsWith(".ogg") || + f_music.endsWith(".opus")) + { + musics_time = true; + areas--; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_music); + } + else + { + w_courtroom->append_area(f_music); + areas++; + } + } + + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); + } + + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast<double>(total_loading_size)) * 100); + w_lobby->set_loading_value(loading_value); + } + + QString next_packet_number = QString::number(((loaded_music - 1) / 10) + 1); + send_server_packet(new AOPacket("AM#" + next_packet_number + "#%")); + } else if (header == "CharsCheck") { if (!courtroom_constructed) @@ -380,7 +453,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) ++loaded_chars; - w_lobby->set_loading_text("Loading chars:\n" + QString::number(loaded_chars) + "/" + QString::number(char_list_size)); + w_lobby->set_loading_text(tr("Loading chars:\n%1/%2").arg(QString::number(loaded_chars)).arg(QString::number(char_list_size))); w_courtroom->append_char(f_char); @@ -401,7 +474,35 @@ void AOApplication::server_packet_received(AOPacket *p_packet) for (int n_element = 0 ; n_element < f_contents.size() ; ++n_element) { - if (!musics_time && f_contents.at(n_element) == "===MUSIC START===.mp3") + ++loaded_music; + + w_lobby->set_loading_text(tr("Loading music:\n%1/%2").arg(QString::number(loaded_music)).arg(QString::number(music_list_size))); + + if (musics_time) + { + w_courtroom->append_music(f_contents.at(n_element)); + } + else + { + if (f_contents.at(n_element).endsWith(".wav") || + f_contents.at(n_element).endsWith(".mp3") || + f_contents.at(n_element).endsWith(".mp4") || + f_contents.at(n_element).endsWith(".ogg") || + f_contents.at(n_element).endsWith(".opus")) + { + musics_time = true; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_contents.at(n_element)); + areas--; + } + else + { + w_courtroom->append_area(f_contents.at(n_element)); + areas++; + } + } + + for (int area_n = 0; area_n < areas; area_n++) { musics_time = true; continue; @@ -566,7 +667,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) { if (courtroom_constructed && f_contents.size() >= 1) { - call_notice("You have been kicked from the server.\nReason: " + f_contents.at(0)); + call_notice(tr("You have been kicked from the server.\nReason: %1").arg(f_contents.at(0))); construct_lobby(); destruct_courtroom(); } @@ -575,7 +676,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) { if (courtroom_constructed && f_contents.size() >= 1) { - call_notice("You have been banned from the server.\nReason: " + f_contents.at(0)); + call_notice(tr("You have been banned from the server.\nReason: %1").arg(f_contents.at(0))); construct_lobby(); destruct_courtroom(); } @@ -583,7 +684,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) } else if (header == "BD") { - call_notice("You are banned on this server.\nReason: " + f_contents.at(0)); + call_notice(tr("You are banned on this server.\nReason: %1").arg(f_contents.at(0))); } else if (header == "ZZ") { @@ -609,7 +710,9 @@ void AOApplication::send_ms_packet(AOPacket *p_packet) net_manager->ship_ms_packet(f_packet); +#ifdef DEBUG_NETWORK qDebug() << "S(ms):" << f_packet; +#endif delete p_packet; } @@ -623,14 +726,18 @@ void AOApplication::send_server_packet(AOPacket *p_packet, bool encoded) if (encryption_needed) { +#ifdef DEBUG_NETWORK qDebug() << "S(e):" << f_packet; +#endif p_packet->encrypt_header(s_decryptor); f_packet = p_packet->to_string(); } else { +#ifdef DEBUG_NETWORK qDebug() << "S:" << f_packet; +#endif } net_manager->ship_server_packet(f_packet); diff --git a/src/path_functions.cpp b/src/path_functions.cpp index 92ff765b..c2c15a26 100644 --- a/src/path_functions.cpp +++ b/src/path_functions.cpp @@ -30,6 +30,8 @@ QString AOApplication::get_base_path() QString external_storage = getenv("EXTERNAL_STORAGE"); base_path = external_storage + "/AO2/"; } +#elif defined __APPLE__ + base_path = applicationDirPath() + "/../../../base/"; #else base_path = applicationDirPath() + "/base/"; #endif diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index a5eb2731..1e1c4744 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -224,7 +224,19 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QStrin return return_value; } - +QString AOApplication::get_font_name(QString p_identifier, QString p_file) +{ + QString design_ini_path = get_theme_path(p_file); + QString f_result = read_design_ini(p_identifier, design_ini_path); + QString default_path = get_default_theme_path(p_file); + if (f_result == "") + { + f_result = read_design_ini(p_identifier, default_path); + if (f_result == "") + return "Sans"; + } + return f_result; +} int AOApplication::get_font_size(QString p_identifier, QString p_file) { QString design_ini_path = get_theme_path(p_file); @@ -443,8 +455,9 @@ QString AOApplication::get_chat(QString p_char) QString AOApplication::get_char_shouts(QString p_char) { QString f_result = read_char_ini(p_char, "shouts", "Options"); - - return f_result; + if (f_result == "") + return "default"; + else return f_result; } int AOApplication::get_preanim_duration(QString p_char, QString p_emote) |
