added objection handler and started on set_scene

This commit is contained in:
David Skoland 2017-02-01 18:20:48 +01:00
parent ab4de962e0
commit 6e7fd9c522
9 changed files with 204 additions and 32 deletions

View File

@ -89,6 +89,7 @@ public:
QVector<server_type> read_serverlist_txt();
pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path);
QString get_char_side(QString p_char);
QString get_showname(QString p_char);
private:
const int RELEASE = 2;

View File

@ -15,12 +15,18 @@ AOMovie::AOMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent)
connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int)));
}
void AOMovie::play(QString p_gif)
void AOMovie::play(QString p_gif, QString p_char)
{
m_movie->stop();
QString gif_path = ao_app->get_theme_path() + p_gif + ".gif";
QString default_path = ao_app->get_default_theme_path() + p_gif + ".gif";
QString gif_path;
if (p_gif == "custom")
gif_path = ao_app->get_character_path(p_char) + "custom.gif";
else
gif_path = ao_app->get_theme_path() + p_gif + ".gif";
if (file_exists(gif_path))
m_movie->setFileName(gif_path);

View File

@ -14,7 +14,7 @@ class AOMovie : public QLabel
public:
AOMovie(QWidget *p_parent, AOApplication *p_ao_app);
void play(QString p_gif);
void play(QString p_gif, QString p_char = "null");
void combo_resize(int w, int h);
void stop();

View File

@ -20,9 +20,13 @@ void AOScene::set_image(QString p_image)
int w = this->width();
int h = this->height();
if (file_exists(background_path))
this->setPixmap(background.scaled(w, h));
else
this->setPixmap(default_bg.scaled(w, h));
}
void AOScene::set_legacy_desk(QString p_image)
{
}

View File

@ -12,6 +12,7 @@ public:
explicit AOScene(Courtroom *parent);
void set_image(QString p_image);
void set_legacy_desk(QString p_image);
private:
Courtroom *m_courtroom;

View File

@ -14,6 +14,14 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
ao_app = p_ao_app;
chat_tick_timer = new QTimer(this);
text_delay = new QTimer(this);
text_delay->setSingleShot(true);
sfx_delay = new QTimer(this);
sfx_delay->setSingleShot(true);
char_button_mapper = new QSignalMapper(this);
sfx_player = new QSoundEffect(this);
@ -25,8 +33,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_vp_desk = new AOScene(this);
ui_vp_legacy_desk = new AOScene(this);
ui_vp_chatbox = new AOImage(this, ao_app);
ui_vp_showname = new QLabel(this);
ui_vp_message = new QPlainTextEdit(this);
ui_vp_showname = new QLabel(ui_vp_chatbox);
ui_vp_message = new QPlainTextEdit(ui_vp_chatbox);
ui_vp_testimony = new AOImage(this, ao_app);
ui_vp_realization = new AOImage(this, ao_app);
ui_vp_wtce = new AOMovie(this, ao_app);
@ -502,6 +510,16 @@ void Courtroom::set_char_select_page()
}
void Courtroom::set_background(QString p_background)
{
current_background = p_background;
QString bg_path = get_background_path();
is_ao2_bg = file_exists(bg_path + "defensedesk.png") &&
file_exists(bg_path + "prosecutiondesk.png") &&
file_exists(bg_path + "stand.png");
}
void Courtroom::enter_courtroom(int p_cid)
{
m_cid = p_cid;
@ -583,7 +601,14 @@ void Courtroom::append_server_chatmessage(QString f_message)
void Courtroom::handle_chatmessage(QStringList *p_contents)
{
QString f_message = p_contents->at(CHAR_NAME) + ": " + p_contents->at(MESSAGE) + '\n';
text_state = 0;
for (int n_string = 0 ; n_string < chatmessage_size ; ++n_string)
{
m_chatmessage[n_string] = p_contents->at(n_string);
}
QString f_message = m_chatmessage[CHAR_NAME] + ": " + m_chatmessage[MESSAGE] + '\n';
const QTextCursor old_cursor = ui_ic_chatlog->textCursor();
const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value();
@ -606,40 +631,102 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum());
}
int objection_mod = p_contents->at(OBJECTION_MOD);
int objection_mod = m_chatmessage[OBJECTION_MOD].toInt();
switch (objection_mod)
//if an objection is used
if (objection_mod <= 4 && objection_mod >= 1)
{
case 1:
ui_vp_objection->play("holdit");
break;
case 2:
ui_vp_objection->play("objection");
break;
case 3:
ui_vp_objection->play("takethat");
break;
//AO2 only
case 4:
//T0D0: add custom.gif here
default:
//T0D0: continue program flow
switch (objection_mod)
{
case 1:
ui_vp_objection->play("holdit");
break;
case 2:
ui_vp_objection->play("objection");
break;
case 3:
ui_vp_objection->play("takethat");
break;
//case 4 is AO2 only
case 4:
ui_vp_objection->play("custom", m_chatmessage[CHAR_NAME]);
break;
default:
qDebug() << "W: Logic error in objection switch statement!";
}
//means we are in a state of objecting
anim_state = 0;
int emote_mod = m_chatmessage[EMOTE_MOD].toInt();
switch (emote_mod)
{
//we change the chatmessage from no preanim to preanim, see documentation
case 0: case 2:
m_chatmessage[EMOTE_MOD] = QString::number(++emote_mod);
break;
case 5:
m_chatmessage[EMOTE_MOD] = QString::number(--emote_mod);
break;
}
}
//D3BUG START
ui_vp_background->set_image("defenseempty.png");
ui_vp_player_char->set(p_contents->at(CHAR_NAME), p_contents->at(EMOTE), p_contents->at(PRE_EMOTE));
ui_vp_player_char->play_talking();
//D3BUG END
else
handle_chatmessage_2();
}
void Courtroom::objection_done()
{
//T0D0: play preanim, advance to step 2 in chat message handling
handle_chatmessage_2();
}
void Courtroom::handle_chatmessage_2()
{
ui_vp_player_char->stop();
QString remote_name = m_chatmessage[CHAR_NAME];
QString local_showname = ao_app->get_showname(remote_name);
//empty string means we couldnt find showname in char ini
if (local_showname == "")
ui_vp_showname->remote_name;
else
ui_vp_showname->local_showname;
ui_vp_message->clear();
ui_vp_chatbox->hide();
set_scene();
set_text_color();
//ui_vp_player_char->set(m_chatmessage[CHAR_NAME], m_chatmessage[PRE_EMOTE], m_chatmessage[EMOTE]);
//ui_vp_player_char->play_pre();
}
void Courtroom::set_scene()
{
//witness is default if pos is invalid
QString f_image = "witnessempty.png";
QString f_side = m_chatmessage[SIDE];
if (f_side == "def")
f_image = "defenseempty.png";
else if (f_side == "pro")
f_image = "prosecutionempty.png";
else if (f_side == "jud")
f_image = "judgestand.png";
else if (f_side == "hld")
f_image = "helperstand.png";
else if (f_side == "hlp")
f_image = "prohelperstand.png";
ui_vp_background->set_image(f_image);
//now for the hard part: desks
}
void Courtroom::handle_wtce(QString p_wtce)

View File

@ -39,18 +39,28 @@ public:
void set_size_and_pos(QWidget *p_widget, QString p_identifier);
void set_taken(int n_char, bool p_taken);
void set_char_select_page();
void set_background(QString p_background){current_background = p_background;}
void set_background(QString p_background);
//sets desk and bg based on pos in chatmessage
void set_scene();
//sets text color based on text color in chatmessage
void set_text_color();
//implementations in path_functions.cpp
QString get_background_path();
QString get_default_background_path();
int get_cid() {return m_cid;}
void enter_courtroom(int p_cid);
void append_ms_chatmessage(QString f_message);
void append_server_chatmessage(QString f_message);
void handle_chatmessage(QStringList *p_contents);
void handle_chatmessage_2();
void handle_wtce(QString p_wtce);
~Courtroom();
@ -73,6 +83,28 @@ private:
QSignalMapper *char_button_mapper;
//determines how fast messages tick onto screen
QTimer *chat_tick_timer;
int chat_tick_interval = 60;
//which tick position(character in chat message) we are at
int tick_pos = 0;
//delay before chat messages starts ticking
QTimer *text_delay;
//delay before sfx plays
QTimer *sfx_delay;
static const int chatmessage_size = 15;
QString m_chatmessage[chatmessage_size];
bool chatmessage_is_empty = false;
//state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle
int anim_state = 0;
//state of text ticking, 0 = not yet ticking, 1 = ticking in progress, 2 = ticking done
int text_state = 0;
//0 is the first page, 1 second etc.
//makes char arithmetic easier
int current_char_page = 0;
@ -80,6 +112,9 @@ private:
//character id, which index of the char_list the player is
int m_cid = 0;
//is set to true if the bg folder contains defensedesk.png, prosecutiondesk.png and stand.png
bool is_ao2_bg = false;
//wether the ooc chat is server or master chat, true is server
bool server_ooc = true;

View File

@ -311,6 +311,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
w_courtroom->handle_wtce(f_contents.at(0));
}
else if (header == "checkconnection")
{
send_server_packet(new AOPacket("CH#" + QString::number(w_courtroom->get_cid()) + "#%"));
}
end:

View File

@ -174,3 +174,37 @@ QString AOApplication::get_char_side(QString p_char)
return "wit";
}
QString AOApplication::get_showname(QString p_char)
{
QString char_ini_path = get_character_path(p_char) + "char.ini";
QFile char_ini;
char_ini.setFileName(char_ini_path);
if (!char_ini.open(QIODevice::ReadOnly))
{
//default to empty string
return "";
}
QTextStream in(&char_ini);
while(!in.atEnd())
{
QString line = in.readLine();
if (!line.startsWith("showname"))
continue;
QStringList line_elements = line.split("=");
if (line_elements.size() < 2)
continue;
return line_elements.at(1).trimmed().toLower();
}
return "";
}