aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2017-01-27 01:17:33 +0100
committerDavid Skoland <davidskoland@gmail.com>2017-01-27 01:17:33 +0100
commit9682087667e2de26e14406efde960b8c7f0c3c98 (patch)
treea2b2dbee3b1a3102499b3cb5c6529e6f01655f74
parent5e2ea2b24c2c0151ff8b0354632aa00148e0e6d6 (diff)
implemented ooc chat and cleaned up some old headers
-rw-r--r--Attorney_Online_remake.pro2
-rw-r--r--aoapplication.cpp17
-rw-r--r--aoapplication.h1
-rw-r--r--aobutton.cpp1
-rw-r--r--aocharbutton.cpp1
-rw-r--r--aoimage.cpp1
-rw-r--r--courtroom.cpp110
-rw-r--r--courtroom.h18
-rw-r--r--lobby.cpp15
-rw-r--r--lobby.h1
-rw-r--r--packet_distribution.cpp22
-rw-r--r--path_functions.cpp2
-rw-r--r--path_functions.h8
-rw-r--r--text_file_functions.cpp36
-rw-r--r--text_file_functions.h11
15 files changed, 202 insertions, 44 deletions
diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro
index 0ce693ab..c7845784 100644
--- a/Attorney_Online_remake.pro
+++ b/Attorney_Online_remake.pro
@@ -32,8 +32,6 @@ SOURCES += main.cpp\
hardware_functions.cpp
HEADERS += lobby.h \
- text_file_functions.h \
- path_functions.h \
aoimage.h \
file_functions.h \
aobutton.h \
diff --git a/aoapplication.cpp b/aoapplication.cpp
index 5388fc01..f0576eea 100644
--- a/aoapplication.cpp
+++ b/aoapplication.cpp
@@ -1,11 +1,12 @@
-#include <QDebug>
+#include "aoapplication.h"
#include "lobby.h"
#include "courtroom.h"
#include "networkmanager.h"
-#include "text_file_functions.h"
-#include "aoapplication.h"
+#include <QDebug>
+#include <QRect>
+#include <QDesktopWidget>
AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv)
{
@@ -29,6 +30,11 @@ 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;
+ w_lobby->move(x, y);
+
w_lobby->show();
}
@@ -54,6 +60,11 @@ 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;
+ w_courtroom->move(x, y);
}
void AOApplication::destruct_courtroom()
diff --git a/aoapplication.h b/aoapplication.h
index a63ec417..5cd255cc 100644
--- a/aoapplication.h
+++ b/aoapplication.h
@@ -86,6 +86,7 @@ public:
void write_to_serverlist_txt(QString p_line);
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);
private:
const int RELEASE = 2;
diff --git a/aobutton.cpp b/aobutton.cpp
index 0938f51b..370eca99 100644
--- a/aobutton.cpp
+++ b/aobutton.cpp
@@ -1,7 +1,6 @@
#include "aobutton.h"
#include "debug_functions.h"
-#include "path_functions.h"
#include "file_functions.h"
#include <QDebug>
diff --git a/aocharbutton.cpp b/aocharbutton.cpp
index 01b3c1c9..d6edf804 100644
--- a/aocharbutton.cpp
+++ b/aocharbutton.cpp
@@ -1,6 +1,5 @@
#include "aocharbutton.h"
-#include "path_functions.h"
#include "file_functions.h"
#include <QFile>
diff --git a/aoimage.cpp b/aoimage.cpp
index bfe11420..4b0e9738 100644
--- a/aoimage.cpp
+++ b/aoimage.cpp
@@ -1,5 +1,4 @@
#include "file_functions.h"
-#include "path_functions.h"
#include "aoimage.h"
diff --git a/courtroom.cpp b/courtroom.cpp
index 381d1595..f408b148 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -2,8 +2,8 @@
#include "aoapplication.h"
#include "lobby.h"
-#include "text_file_functions.h"
-#include "path_functions.h"
+#include "hardware_functions.h"
+#include "file_functions.h"
#include <QDebug>
@@ -18,22 +18,33 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
//viewport elements like background, desk, etc.
ui_ic_chatlog = new QPlainTextEdit(this);
+ ui_ic_chatlog->setReadOnly(true);
ui_ms_chatlog = new QPlainTextEdit(this);
- ui_server_chatlog = new QPlainTextEdit(this);
+ ui_ms_chatlog->setReadOnly(true);
+ ui_ms_chatlog->hide();
+ ui_server_chatlog = new QPlainTextEdit(this);
+ ui_server_chatlog->setReadOnly(true);
ui_mute_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_ooc_chat_message = new QLineEdit(this);
+ ui_ooc_chat_message->setFrame(false);
+
ui_ooc_chat_name = new QLineEdit(this);
+ ui_ooc_chat_name->setFrame(false);
+ ui_ooc_chat_name->setPlaceholderText("Name");
ui_area_password = new QLineEdit(this);
+ ui_area_password->setFrame(false);
ui_music_search = new QLineEdit(this);
+ ui_music_search->setFrame(false);
//emote buttons
@@ -138,6 +149,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_spectator = new AOButton(ui_char_select_background, ao_app);
+ connect(ui_ooc_chat_message, SIGNAL(returnPressed()), this, SLOT(on_ooc_return_pressed()));
+ connect(ui_ooc_toggle, SIGNAL(clicked()), this, SLOT(on_ooc_toggle_clicked()));
connect(ui_change_character, SIGNAL(clicked()), this, SLOT(on_change_character_clicked()));
connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked()));
@@ -390,6 +403,86 @@ void Courtroom::set_char_select_page()
}
+void Courtroom::enter_courtroom(int p_cid)
+{
+ m_cid = p_cid;
+ QString f_char = char_list.at(m_cid).name;
+
+ //T0D0: set emote buttons
+
+ QString side = ao_app->get_char_side(f_char);
+
+ if (side == "jud")
+ {
+ ui_witness_testimony->show();
+ ui_cross_examination->show();
+ ui_defense_minus->show();
+ ui_defense_plus->show();
+ ui_prosecution_minus->show();
+ ui_prosecution_plus->show();
+ }
+ else
+ {
+ ui_witness_testimony->hide();
+ ui_cross_examination->hide();
+ ui_defense_minus->hide();
+ ui_defense_plus->hide();
+ ui_prosecution_minus->hide();
+ ui_prosecution_plus->hide();
+ }
+
+ ui_char_select_background->hide();
+}
+
+void Courtroom::append_ms_chatmessage(QString f_message)
+{
+ ui_ms_chatlog->appendPlainText(f_message);
+}
+
+void Courtroom::append_server_chatmessage(QString f_message)
+{
+ ui_server_chatlog->appendPlainText(f_message);
+}
+
+void Courtroom::on_ooc_return_pressed()
+{
+ if (ui_ooc_chat_message->text() == "" || ui_ooc_chat_name->text() == "")
+ return;
+
+ QStringList packet_contents;
+ packet_contents.append(ui_ooc_chat_name->text());
+ packet_contents.append(ui_ooc_chat_message->text());
+
+ AOPacket *f_packet = new AOPacket("CT", packet_contents);
+
+ if (server_ooc)
+ ao_app->send_server_packet(f_packet);
+ else
+ ao_app->send_ms_packet(f_packet);
+
+ ui_ooc_chat_message->clear();
+}
+
+void Courtroom::on_ooc_toggle_clicked()
+{
+ if (server_ooc)
+ {
+ ui_ms_chatlog->show();
+ ui_server_chatlog->hide();
+ ui_ooc_toggle->setText("Master");
+
+ server_ooc = false;
+ }
+ else
+ {
+ ui_ms_chatlog->hide();
+ ui_server_chatlog->show();
+ ui_ooc_toggle->setText("Server");
+
+ server_ooc = true;
+ }
+}
+
void Courtroom::on_change_character_clicked()
{
ui_char_select_background->show();
@@ -428,7 +521,18 @@ void Courtroom::on_spectator_clicked()
void Courtroom::char_clicked(int n_char)
{
+ int n_real_char = n_char + current_char_page * 90;
+
+ QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini";
+
+ if (!file_exists(char_ini_path))
+ {
+ qDebug() << "did not find " << char_ini_path;
+ //T0D0: call error
+ return;
+ }
+ ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%"));
}
Courtroom::~Courtroom()
diff --git a/courtroom.h b/courtroom.h
index 5b2a1115..9f25387e 100644
--- a/courtroom.h
+++ b/courtroom.h
@@ -35,6 +35,11 @@ public:
void set_taken(int n_char, bool p_taken);
void set_char_select_page();
+ void enter_courtroom(int p_cid);
+
+ void append_ms_chatmessage(QString f_message);
+ void append_server_chatmessage(QString f_message);
+
~Courtroom();
private:
@@ -59,6 +64,12 @@ private:
//makes char arithmetic easier
int current_char_page = 0;
+ //character id, which index of the char_list the player is
+ int m_cid = 0;
+
+ //wether the ooc chat is server or master chat, true is server
+ bool server_ooc = true;
+
AOImage *ui_background;
//T0D0: add viewport elements like background, desk, etc.
@@ -143,16 +154,19 @@ private:
AOButton *ui_spectator;
private slots:
+ void on_ooc_return_pressed();
+ void on_ooc_toggle_clicked();
+
void on_change_character_clicked();
void on_reload_theme_clicked();
void on_back_to_lobby_clicked();
- void on_spectator_clicked();
-
void on_char_select_left_clicked();
void on_char_select_right_clicked();
+ void on_spectator_clicked();
+
void char_clicked(int n_char);
};
diff --git a/lobby.cpp b/lobby.cpp
index 37091146..8bc67bd4 100644
--- a/lobby.cpp
+++ b/lobby.cpp
@@ -1,7 +1,5 @@
#include "lobby.h"
-#include "path_functions.h"
-#include "text_file_functions.h"
#include "debug_functions.h"
#include "aoapplication.h"
#include "networkmanager.h"
@@ -27,6 +25,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
ui_description = new QPlainTextEdit(this);
ui_chatbox = new QPlainTextEdit(this);
ui_chatname = new QLineEdit(this);
+ ui_chatname->setPlaceholderText("Name");
ui_chatmessage = new QLineEdit(this);
ui_loading_background = new AOImage(this, ao_app);
ui_loading_text = new QTextEdit(ui_loading_background);
@@ -152,6 +151,13 @@ void Lobby::set_loading_text(QString p_text)
ui_loading_text->append(p_text);
}
+QString Lobby::get_chatlog()
+{
+ QString return_value = ui_chatbox->toPlainText();
+
+ return return_value;
+}
+
void Lobby::on_public_servers_clicked()
{
ui_public_servers->set_image("publicservers_selected.png");
@@ -260,6 +266,11 @@ void Lobby::on_server_list_clicked(QModelIndex p_model)
void Lobby::on_chatfield_return_pressed()
{
+ //no you can't send empty messages
+ if (ui_chatname->text() == "" || ui_chatmessage->text() == "")
+ return;
+
+
QString f_header = "CT";
QStringList f_contents{ui_chatname->text(), ui_chatmessage->text()};
diff --git a/lobby.h b/lobby.h
index 8f9b5ea6..ebdc05b2 100644
--- a/lobby.h
+++ b/lobby.h
@@ -29,6 +29,7 @@ public:
void set_loading_text(QString p_text);
void show_loading_overlay(){ui_loading_background->show();}
void hide_loading_overlay(){ui_loading_background->hide();}
+ QString get_chatlog();
~Lobby();
diff --git a/packet_distribution.cpp b/packet_distribution.cpp
index d53b5a6a..163c744d 100644
--- a/packet_distribution.cpp
+++ b/packet_distribution.cpp
@@ -63,8 +63,7 @@ void AOApplication::ms_packet_received(AOPacket *p_packet)
}
if (courtroom_constructed)
{
- //T0D0: uncomment this when it's implemented
- //w_courtroom->append_ms_chat_message(message_line);
+ w_courtroom->append_ms_chatmessage(message_line);
}
}
}
@@ -77,7 +76,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
QStringList f_contents = p_packet->get_contents();
QString f_packet = p_packet->to_string();
- qDebug() << "R: " << f_packet;
+ if (header != "checkconnection")
+ qDebug() << "R: " << f_packet;
if (header == "decryptor")
{
@@ -113,10 +113,9 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
return;
}
- //QString message_line = f_contents.at(0) + ": " + f_contents.at(1);
+ QString message_line = f_contents.at(0) + ": " + f_contents.at(1);
- //T0D0, uncomment when implemented
- //w_courtroom->append_ooc_chatmessage(message_line)
+ w_courtroom->append_server_chatmessage(message_line);
}
else if (header == "PN")
{
@@ -176,7 +175,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
w_lobby->set_loading_text("Loading chars:\n" + QString::number(loaded_chars) + "/" + QString::number(char_list_size));
w_courtroom->append_char(f_char);
- //qDebug() << "appended " << f_char.name << " to char_list";
}
if (loaded_chars < char_list_size)
@@ -281,10 +279,20 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
w_courtroom->set_char_select_page();
+ w_courtroom->append_ms_chatmessage(w_lobby->get_chatlog());
+
w_courtroom->show();
destruct_lobby();
}
+ //server accepting char request(CC) packet
+ if (header == "PV")
+ {
+ if (f_contents.size() < 3)
+ return;
+
+ w_courtroom->enter_courtroom(f_contents.at(2).toInt());
+ }
}
void AOApplication::send_ms_packet(AOPacket *p_packet)
diff --git a/path_functions.cpp b/path_functions.cpp
index 7afd923a..5b9e92ee 100644
--- a/path_functions.cpp
+++ b/path_functions.cpp
@@ -1,7 +1,5 @@
#include "aoapplication.h"
-#include "text_file_functions.h"
-
#include <QDir>
#include <QDebug>
diff --git a/path_functions.h b/path_functions.h
deleted file mode 100644
index 2f37a0ce..00000000
--- a/path_functions.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef PATH_FUNCTIONS_H
-#define PATH_FUNCTIONS_H
-
-#include <QString>
-
-
-
-#endif // PATH_FUNCTIONS_H
diff --git a/text_file_functions.cpp b/text_file_functions.cpp
index db1ecc74..dc97c607 100644
--- a/text_file_functions.cpp
+++ b/text_file_functions.cpp
@@ -1,6 +1,5 @@
#include "aoapplication.h"
-#include "path_functions.h"
#include "file_functions.h"
#include <QTextStream>
@@ -140,3 +139,38 @@ pos_size_type AOApplication::get_pos_and_size(QString p_identifier, QString p_de
return return_value;
}
+QString AOApplication::get_char_side(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 wit and don't make a big deal about it
+ return "wit";
+ }
+
+ QTextStream in(&char_ini);
+
+ while(!in.atEnd())
+ {
+ QString line = in.readLine();
+
+ if (!line.startsWith("side"))
+ continue;
+
+ QStringList line_elements = line.split("=");
+
+ if (line_elements.size() < 2)
+ continue;
+
+ //note that we do not validate if this is a valid side or not. that's up to the caller
+ return line_elements.at(1).trimmed().toLower();
+ }
+
+ return "wit";
+}
+
diff --git a/text_file_functions.h b/text_file_functions.h
deleted file mode 100644
index 54abd4d8..00000000
--- a/text_file_functions.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef TEXT_FILE_FUNCTIONS_H
-#define TEXT_FILE_FUNCTIONS_H
-
-#include "datatypes.h"
-
-#include <QString>
-#include <QFile>
-
-
-
-#endif // TEXT_FILE_FUNCTIONS_H