From 49579cdb9cb162476b5402dced0b6af5844eb1ec Mon Sep 17 00:00:00 2001 From: David Skoland Date: Thu, 9 Feb 2017 02:01:25 +0100 Subject: [PATCH] added mod functions and optimized emotes --- aoimage.cpp | 2 + courtroom.cpp | 102 +++++++++++++++++++++++++++++++++++----- courtroom.h | 11 +++++ debug_functions.cpp | 12 +++++ debug_functions.h | 1 + emotes.cpp | 14 +++++- packet_distribution.cpp | 41 ++++++++++++++++ 7 files changed, 169 insertions(+), 14 deletions(-) diff --git a/aoimage.cpp b/aoimage.cpp index a8ad3a0..a623332 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -2,6 +2,8 @@ #include "aoimage.h" +#include + AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) { m_parent = parent; diff --git a/courtroom.cpp b/courtroom.cpp index fa56dad..5ba92bd 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -25,6 +25,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() sfx_delay_timer = new QTimer(this); sfx_delay_timer->setSingleShot(true); + realization_timer = new QTimer(this); + realization_timer->setSingleShot(true); + char_button_mapper = new QSignalMapper(this); sfx_player = new QSoundEffect(this); @@ -41,7 +44,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_vp_showname = new QLabel(ui_vp_chatbox); ui_vp_message = new QPlainTextEdit(ui_vp_chatbox); ui_vp_testimony = new AOImage(ui_viewport, ao_app); - ui_vp_realization = new AOImage(ui_viewport, ao_app); + ui_vp_realization = new AOImage(this, ao_app); ui_vp_wtce = new AOMovie(ui_viewport, ao_app); ui_vp_objection = new AOMovie(ui_viewport, ao_app); @@ -56,12 +59,15 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_server_chatlog->setReadOnly(true); ui_mute_list = new QListWidget(this); - ui_area_list = new QListWidget(this); + //ui_area_list = new QListWidget(this); ui_music_list = new QListWidget(this); ui_ic_chat_message = new QLineEdit(this); ui_ic_chat_message->setFrame(false); + ui_muted = new AOImage(ui_ic_chat_message, ao_app); + ui_muted->hide(); + ui_ooc_chat_message = new QLineEdit(this); ui_ooc_chat_message->setFrame(false); @@ -140,8 +146,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_blip_slider->setRange(0, 100); ui_blip_slider->setValue(50); - ui_muted = new AOImage(this, ao_app); - /////////////char select widgets under here/////////////// ui_char_select_background = new AOImage(this, ao_app); @@ -201,6 +205,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(chat_tick_timer, SIGNAL(timeout()), this, SLOT(chat_tick())); + connect(realization_timer, SIGNAL(timeout()), this, SLOT(realization_done())); + //emote signals are set in emotes.cpp connect(ui_ic_chat_message, SIGNAL(returnPressed()), this, SLOT(on_chat_return_pressed())); @@ -315,7 +321,9 @@ void Courtroom::set_widgets() ui_vp_testimony->resize(ui_viewport->width(), ui_viewport->height()); ui_vp_realization->move(0, 0); - ui_vp_realization->resize(ui_viewport->x(), ui_viewport->y()); + ui_vp_realization->resize(ui_viewport->width(), ui_viewport->height()); + ui_vp_realization->set_scaled_image("realizationflash.png"); + ui_vp_realization->hide(); ui_vp_wtce->move(0, 0); ui_vp_wtce->combo_resize(ui_viewport->width(), ui_viewport->height()); @@ -336,14 +344,17 @@ void Courtroom::set_widgets() set_size_and_pos(ui_mute_list, "mute_list"); ui_mute_list->hide(); - set_size_and_pos(ui_area_list, "area_list"); - ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); + //set_size_and_pos(ui_area_list, "area_list"); + //ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); set_size_and_pos(ui_music_list, "music_list"); - ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); + ui_music_list->setStyleSheet("QListWidget{background-color: rgba(0, 0, 0, 0);}"); + ui_music_list->setFont(f); set_size_and_pos(ui_ic_chat_message, "ic_chat_message"); ui_ic_chat_message->setStyleSheet("background-color: rgba(89, 89, 89, 255);"); + ui_muted->resize(ui_ic_chat_message->width(), ui_ic_chat_message->height()); + ui_muted->set_image("muted.png"); set_size_and_pos(ui_ooc_chat_message, "ooc_chat_message"); ui_ooc_chat_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); @@ -439,9 +450,6 @@ void Courtroom::set_widgets() set_size_and_pos(ui_sfx_slider, "sfx_slider"); set_size_and_pos(ui_blip_slider, "blip_slider"); - //T0D0: scale this according to ui_ic_chat_message - //set_size_and_pos(ui_muted, "muted"); - //char select stuff under here ui_char_select_background->set_image("charselect_background.png"); @@ -706,7 +714,7 @@ void Courtroom::append_server_chatmessage(QString f_message) void Courtroom::on_chat_return_pressed() { - if (ui_ic_chat_message->text() == "") + if (ui_ic_chat_message->text() == "" || is_muted) return; //MS#chat# @@ -817,6 +825,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) ui_objection->set_image("objection.png"); ui_take_that->set_image("takethat.png"); ui_custom_objection->set_image("custom.png"); + ui_realization->set_image("realization.png"); } append_ic_text(f_message); @@ -880,6 +889,8 @@ void Courtroom::handle_chatmessage_2() QString remote_name = m_chatmessage[CHAR_NAME]; QString local_showname = ao_app->get_showname(remote_name); + qDebug() << "local_showname: " << local_showname; + //empty string means we couldnt find showname in char ini if (local_showname == "") ui_vp_showname->setText(remote_name); @@ -971,6 +982,13 @@ void Courtroom::handle_chatmessage_3() anim_state = 3; } + if (m_chatmessage[REALIZATION] == "1") + { + realization_timer->start(60); + ui_vp_realization->show(); + //T0D0: add realization sfx + } + } void Courtroom::append_ic_text(QString p_text) @@ -1019,6 +1037,12 @@ void Courtroom::preanim_done() handle_chatmessage_3(); } +void Courtroom::realization_done() +{ + ui_vp_realization->hide(); + qDebug() << "realization_done called"; +} + void Courtroom::start_chat_ticking() { //we need to ensure that the text isn't already ticking because this function can be called by two logic paths @@ -1182,6 +1206,44 @@ void Courtroom::set_text_color() } } +void Courtroom::set_ip_list(QString p_list) +{ + QString f_list = p_list.replace("|", ":").replace("*", "\n"); + + ui_server_chatlog->appendPlainText(f_list); +} + +void Courtroom::set_mute(bool p_muted, int p_cid) +{ + if (p_cid != m_cid && p_cid != -1) + return; + + if (p_muted) + ui_muted->show(); + else + { + ui_muted->hide(); + ui_ic_chat_message->setFocus(); + } + + ui_muted->resize(ui_ic_chat_message->width(), ui_ic_chat_message->height()); + ui_muted->set_image("muted.png"); + + is_muted = p_muted; + ui_ic_chat_message->setEnabled(!p_muted); +} + +void Courtroom::set_ban(int p_cid) +{ + if (p_cid != m_cid && p_cid != -1) + return; + + call_notice("You have been banned."); + + ao_app->construct_lobby(); + ao_app->destruct_courtroom(); +} + void Courtroom::handle_song(QStringList *p_contents) { QStringList f_contents = *p_contents; @@ -1247,6 +1309,10 @@ void Courtroom::on_ooc_return_pressed() if (ui_ooc_chat_message->text() == "" || ui_ooc_chat_name->text() == "") return; + //cheap, but it works + if (ui_ooc_chat_message->text().startsWith("/login")) + ui_guard->show(); + QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); packet_contents.append(ui_ooc_chat_message->text()); @@ -1293,6 +1359,9 @@ void Courtroom::on_music_search_edited(QString p_text) void Courtroom::on_music_list_double_clicked(QModelIndex p_model) { + if (is_muted) + return; + QString p_song = ui_music_list->item(p_model.row())->text(); ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%")); @@ -1390,6 +1459,8 @@ void Courtroom::on_realization_clicked() realization_state = 0; ui_realization->set_image("realization.png"); } + + ui_ic_chat_message->setFocus(); } void Courtroom::on_defense_minus_clicked() @@ -1427,10 +1498,14 @@ void Courtroom::on_prosecution_plus_clicked() void Courtroom::on_text_color_changed(int p_color) { text_color = p_color; + ui_ic_chat_message->setFocus(); } void Courtroom::on_witness_testimony_clicked() { + if (is_muted) + return; + ao_app->send_server_packet(new AOPacket("RT#testimony1#%")); ui_ic_chat_message->setFocus(); @@ -1438,6 +1513,9 @@ void Courtroom::on_witness_testimony_clicked() void Courtroom::on_cross_examination_clicked() { + if (is_muted) + return; + ao_app->send_server_packet(new AOPacket("RT#testimony2#%")); ui_ic_chat_message->setFocus(); diff --git a/courtroom.h b/courtroom.h index e701f85..255f0a7 100644 --- a/courtroom.h +++ b/courtroom.h @@ -48,6 +48,11 @@ public: //sets text color based on text color in chatmessage void set_text_color(); + void set_ip_list(QString p_list); + + void set_mute(bool p_muted, int p_cid); + void set_ban(int p_cid); + //implementations in path_functions.cpp QString get_background_path(); QString get_default_background_path(); @@ -109,6 +114,8 @@ private: //delay before sfx plays QTimer *sfx_delay_timer; + QTimer *realization_timer; + //every time point in char.inis times this equals the final time const int time_mod = 35; @@ -118,6 +125,8 @@ private: QString previous_ic_message = ""; + bool is_muted = false; + //state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle int anim_state = 0; @@ -255,6 +264,8 @@ public slots: void objection_done(); void preanim_done(); + void realization_done(); + private slots: void start_chat_ticking(); void play_sfx(); diff --git a/debug_functions.cpp b/debug_functions.cpp index 7206885..347e620 100644 --- a/debug_functions.cpp +++ b/debug_functions.cpp @@ -10,6 +10,18 @@ void call_error(QString p_message) msgBox->setWindowTitle("Error"); + //msgBox->setWindowModality(Qt::NonModal); + msgBox->show(); +} + +void call_notice(QString p_message) +{ + QMessageBox *msgBox = new QMessageBox; + + msgBox->setText(p_message); + msgBox->setWindowTitle("Notice"); + + //msgBox->setWindowModality(Qt::NonModal); msgBox->show(); } diff --git a/debug_functions.h b/debug_functions.h index 38275b0..6feaf90 100644 --- a/debug_functions.h +++ b/debug_functions.h @@ -4,5 +4,6 @@ #include void call_error(QString message); +void call_notice(QString message); #endif // DEBUG_FUNCTIONS_H diff --git a/emotes.cpp b/emotes.cpp index c1598aa..5efc092 100644 --- a/emotes.cpp +++ b/emotes.cpp @@ -91,8 +91,17 @@ void Courtroom::set_emote_page() void Courtroom::on_emote_clicked(int p_id) { + int min = current_emote_page * max_emotes_on_page; + int max = 9 + current_emote_page * max_emotes_on_page; + + if (current_emote >= min && current_emote <= max) + ui_emote_list.at(current_emote % max_emotes_on_page)->set_off(current_char, current_emote); + current_emote = p_id + 10 * current_emote_page; + ui_emote_list.at(current_emote % max_emotes_on_page)->set_on(current_char, current_emote); + + /* for (int n_emote = 0 ; n_emote < 10 ; ++n_emote) { int n_real_emote = n_emote + current_emote_page * 10; @@ -100,9 +109,10 @@ void Courtroom::on_emote_clicked(int p_id) if (n_real_emote == current_emote) f_emote->set_on(current_char, n_real_emote); - else - f_emote->set_off(current_char, n_real_emote); + //else + // f_emote->set_off(current_char, n_real_emote); } + */ int emote_mod = ao_app->get_emote_mod(current_char, current_emote); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 70dd248..812c0a6 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -5,6 +5,7 @@ #include "networkmanager.h" #include "encryption_functions.h" #include "hardware_functions.h" +#include "debug_functions.h" #include @@ -326,6 +327,46 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (courtroom_constructed && f_contents.size() > 1) w_courtroom->set_hp_bar(f_contents.at(0).toInt(), f_contents.at(1).toInt()); } + else if (header == "IL") + { + if (courtroom_constructed && f_contents.size() > 0) + w_courtroom->set_ip_list(f_contents.at(0)); + } + else if (header == "MU") + { + if (courtroom_constructed && f_contents.size() > 0) + w_courtroom->set_mute(true, f_contents.at(0).toInt()); + } + else if (header == "UM") + { + if (courtroom_constructed && f_contents.size() > 0) + w_courtroom->set_mute(false, f_contents.at(0).toInt()); + } + else if (header == "KK") + { + if (courtroom_constructed && f_contents.size() > 0) + { + int f_cid = w_courtroom->get_cid(); + int remote_cid = f_contents.at(0).toInt(); + + if (f_cid != remote_cid && remote_cid != -1) + return; + + call_notice("You have been kicked."); + construct_lobby(); + destruct_courtroom(); + } + + } + else if (header == "KB") + { + if (courtroom_constructed && f_contents.size() > 0) + w_courtroom->set_ban(f_contents.at(0).toInt()); + } + else if (header == "BD") + { + call_notice("You are banned on this server."); + } else if (header == "checkconnection") { send_server_packet(new AOPacket("CH#" + QString::number(w_courtroom->get_cid()) + "#%"));