aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2018-02-08 18:55:46 -0600
committerGitHub <noreply@github.com>2018-02-08 18:55:46 -0600
commit34a4519d1e2df8e9b5bbf7b5bb0e670cf99b266f (patch)
treee46e0b024ecd64884b3f94ae1347fba9d12a15c4
parent28decf8dbf2ae1b9fef71821aa0384bab72d404e (diff)
parent0d82ce72fa2747878d32bcb0702b247395716807 (diff)
Merge pull request #10 from OmniTroid/master
fixed that performance issue related to big IC logs
-rw-r--r--aoapplication.cpp8
-rw-r--r--aoapplication.h14
-rw-r--r--aotextarea.cpp14
-rw-r--r--aotextarea.h1
-rw-r--r--courtroom.cpp20
-rw-r--r--courtroom.h44
-rw-r--r--lobby.cpp20
-rw-r--r--lobby.h1
-rw-r--r--path_functions.cpp2
-rw-r--r--text_file_functions.cpp11
10 files changed, 98 insertions, 37 deletions
diff --git a/aoapplication.cpp b/aoapplication.cpp
index e170c990..12e540cd 100644
--- a/aoapplication.cpp
+++ b/aoapplication.cpp
@@ -86,15 +86,17 @@ void AOApplication::destruct_courtroom()
courtroom_constructed = false;
}
-QString AOApplication::get_version_string(){
+QString AOApplication::get_version_string()
+{
return
QString::number(RELEASE) + "." +
QString::number(MAJOR_VERSION) + "." +
QString::number(MINOR_VERSION);
}
-void AOApplication::set_user_theme(){
- user_theme = read_user_theme();
+void AOApplication::reload_theme()
+{
+ current_theme = read_theme();
}
void AOApplication::set_favorite_list()
diff --git a/aoapplication.h b/aoapplication.h
index 3d1936c9..e1245607 100644
--- a/aoapplication.h
+++ b/aoapplication.h
@@ -77,6 +77,8 @@ public:
int get_minor_version() {return MINOR_VERSION;}
QString get_version_string();
+ ///////////////////////////////////////////
+
void set_favorite_list();
QVector<server_type>& get_favorite_list() {return favorite_list;}
void add_favorite_server(int p_server);
@@ -84,8 +86,10 @@ public:
void set_server_list();
QVector<server_type>& get_server_list() {return server_list;}
- void set_user_theme();
- QString get_user_theme() {return user_theme;}
+ //reads the theme from config.ini and sets it accordingly
+ void reload_theme();
+
+ //QString get_theme() {return current_theme;}
QString get_current_char();
@@ -103,8 +107,10 @@ public:
QString get_evidence_path();
//implementation in text_file_functions.cpp
+
+ QString read_file(QString p_path);
QString read_config(QString searchline);
- QString read_user_theme();
+ QString read_theme();
int read_blip_rate();
bool get_blank_blip();
int get_default_music();
@@ -143,7 +149,7 @@ private:
const int MAJOR_VERSION = 4;
const int MINOR_VERSION = 8;
- QString user_theme = "default";
+ QString current_theme = "default";
QVector<server_type> server_list;
QVector<server_type> favorite_list;
diff --git a/aotextarea.cpp b/aotextarea.cpp
index d49f03e8..40cc3148 100644
--- a/aotextarea.cpp
+++ b/aotextarea.cpp
@@ -28,7 +28,6 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
this->insertHtml(result);
this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
- this->auto_truncate();
}
void AOTextArea::append_error(QString p_message)
@@ -47,7 +46,6 @@ void AOTextArea::append_error(QString p_message)
this->insertHtml("<font color='red'>" + result + "</font>");
this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
- this->auto_truncate();
}
void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value, bool is_scrolled_down)
@@ -65,15 +63,3 @@ void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value, bo
this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum());
}
}
-
-void AOTextArea::auto_truncate()
-{
- QTextCursor temp_cursor = this->textCursor();
-
- if (this->document()->characterCount() > 500000)
- {
- temp_cursor.movePosition(QTextCursor::Start);
- temp_cursor.select(QTextCursor::LineUnderCursor);
- temp_cursor.removeSelectedText();
- }
-}
diff --git a/aotextarea.h b/aotextarea.h
index 46b9bcc7..32635fdb 100644
--- a/aotextarea.h
+++ b/aotextarea.h
@@ -15,7 +15,6 @@ private:
const QRegExp omnis_dank_url_regex = QRegExp("\\b(https?://\\S+\\.\\S+)\\b");
void auto_scroll(QTextCursor old_cursor, int scrollbar_value, bool is_scrolled_down);
- void auto_truncate();
};
#endif // AOTEXTAREA_H
diff --git a/courtroom.cpp b/courtroom.cpp
index 97d1f714..ca94f434 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -12,6 +12,7 @@
#include <QRegExp>
#include <QBrush>
#include <QTextCharFormat>
+#include <QFont>
Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
@@ -80,7 +81,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_vp_wtce = new AOMovie(this, ao_app);
ui_vp_objection = new AOMovie(this, ao_app);
- ui_ic_chatlog = new QPlainTextEdit(this);
+ ui_ic_chatlog = new QTextEdit(this);
ui_ic_chatlog->setReadOnly(true);
ui_ms_chatlog = new AOTextArea(this);
@@ -963,7 +964,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
ui_evidence_present->set_image("present_disabled.png");
}
- append_ic_text("<b>" + f_showname.toHtmlEscaped() + "</b>:&nbsp;" + m_chatmessage[MESSAGE].toHtmlEscaped());
+ append_ic_text(": " + m_chatmessage[MESSAGE], f_showname);
previous_ic_message = f_message;
@@ -1147,17 +1148,20 @@ void Courtroom::handle_chatmessage_3()
}
-void Courtroom::append_ic_text(QString p_text)
+void Courtroom::append_ic_text(QString p_text, QString p_name)
{
+ QTextCharFormat bold;
+ QTextCharFormat normal;
+ bold.setFontWeight(QFont::Bold);
+ normal.setFontWeight(QFont::Normal);
const QTextCursor old_cursor = ui_ic_chatlog->textCursor();
const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value();
const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum();
ui_ic_chatlog->moveCursor(QTextCursor::Start);
- ui_ic_chatlog->textCursor().insertHtml(p_text);
- ui_ic_chatlog->textCursor().insertHtml("<br>");
-
+ ui_ic_chatlog->textCursor().insertText(p_name, bold);
+ ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal);
if (old_cursor.hasSelection() || !is_scrolled_up)
{
@@ -1527,7 +1531,7 @@ void Courtroom::handle_song(QStringList *p_contents)
if (!mute_map.value(n_char))
{
- append_ic_text("<b>" + str_char + "</b> has played a song: " + f_song);
+ append_ic_text(" has played a song: " + f_song, str_char);
music_player->play(f_song);
}
}
@@ -1969,7 +1973,7 @@ void Courtroom::on_change_character_clicked()
void Courtroom::on_reload_theme_clicked()
{
- ao_app->set_user_theme();
+ ao_app->reload_theme();
//to update status on the background
set_background(current_background);
diff --git a/courtroom.h b/courtroom.h
index 4e7e1910..85554a0e 100644
--- a/courtroom.h
+++ b/courtroom.h
@@ -44,17 +44,31 @@ public:
void append_evidence(evi_type p_evi){evidence_list.append(p_evi);}
void append_music(QString f_music){music_list.append(f_music);}
+ //sets position of widgets based on theme ini files
void set_widgets();
+ //sets font size based on theme ini files
void set_font(QWidget *widget, QString p_identifier);
+ //helper function that calls above function on the relevant widgets
void set_fonts();
+
void set_window_title(QString p_title);
+
+ //reads theme inis and sets size and pos based on the identifier
void set_size_and_pos(QWidget *p_widget, QString p_identifier);
+
+ //sets status as taken on character with cid n_char and places proper shading on charselect
void set_taken(int n_char, bool p_taken);
+
+ //sets the current background to argument. also does some checks to see if it's a legacy bg
void set_background(QString p_background);
+
+ //sets the evidence list member variable to argument
void set_evidence_list(QVector<evi_type> &p_evi_list);
+ //called when a DONE#% from the server was received
void done_received();
+ //sets the local mute list based on characters available on the server
void set_mute_list();
//sets desk and bg based on pos in chatmessage
@@ -63,35 +77,58 @@ public:
//sets text color based on text color in chatmessage
void set_text_color();
+ //takes in serverD-formatted IP list as prints a converted version to server OOC
+ //admittedly poorly named
void set_ip_list(QString p_list);
+ //disables chat if current cid matches second argument
+ //enables if p_muted is false
void set_mute(bool p_muted, int p_cid);
+
+ //send a message that the player is banned and quits the server
void set_ban(int p_cid);
//implementations in path_functions.cpp
QString get_background_path();
QString get_default_background_path();
+ //cid = character id, returns the cid of the currently selected character
int get_cid() {return m_cid;}
QString get_current_char() {return current_char;}
+ //properly sets up some varibles: resets user state
void enter_courtroom(int p_cid);
+
+ //helper function that populates ui_music_list with the contents of music_list
void list_music();
+ //these are for OOC chat
void append_ms_chatmessage(QString f_name, QString f_message);
void append_server_chatmessage(QString p_name, QString p_message);
+ //these functions handle chatmessages sequentially.
+ //The process itself is very convoluted and merits separate documentation
+ //But the general idea is objection animation->pre animation->talking->idle
void handle_chatmessage(QStringList *p_contents);
void handle_chatmessage_2();
void handle_chatmessage_3();
- void append_ic_text(QString p_text);
+ //adds text to the IC chatlog. p_name first as bold then p_text then a newlin
+ //this function keeps the chatlog scrolled to the top unless there's text selected
+ // or the user isn't already scrolled to the top
+ void append_ic_text(QString p_text, QString p_name = "");
+ //prints who played the song to IC chat and plays said song(if found on local filesystem)
+ //takes in a list where the first element is the song name and the second is the char id of who played it
void handle_song(QStringList *p_contents);
void play_preanim();
+ //plays the witness testimony or cross examination animation based on argument
void handle_wtce(QString p_wtce);
+
+ //sets the hp bar of defense(p_bar 1) or pro(p_bar 2)
+ //state is an number between 0 and 10 inclusive
void set_hp_bar(int p_bar, int p_state);
void check_connection_received();
@@ -137,9 +174,12 @@ private:
//delay before sfx plays
QTimer *sfx_delay_timer;
+ //keeps track of how long realization is visible(it's just a white square and should be visible less than a second)
QTimer *realization_timer;
+ //times how long the blinking testimony should be shown(green one in the corner)
QTimer *testimony_show_timer;
+ //times how long the blinking testimony should be hidden
QTimer *testimony_hide_timer;
//every time point in char.inis times this equals the final time
@@ -236,7 +276,7 @@ private:
AOMovie *ui_vp_wtce;
AOMovie *ui_vp_objection;
- QPlainTextEdit *ui_ic_chatlog;
+ QTextEdit *ui_ic_chatlog;
AOTextArea *ui_ms_chatlog;
AOTextArea *ui_server_chatlog;
diff --git a/lobby.cpp b/lobby.cpp
index 1df765fd..3a10439d 100644
--- a/lobby.cpp
+++ b/lobby.cpp
@@ -4,6 +4,7 @@
#include "aoapplication.h"
#include "networkmanager.h"
#include "aosfxplayer.h"
+#include "file_functions.h"
#include <QDebug>
#include <QScrollBar>
@@ -51,14 +52,27 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed()));
connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled()));
- set_widgets();
+ //set_widgets();
+ set_theme();
+}
+
+void Lobby::set_theme()
+{
+ ao_app->reload_theme();
+
+ //check if our current theme is a valid qss theme
+ if (!file_exists(ao_app->get_theme_path() + "lobby.qss"))
+ {
+ set_widgets();
+ return;
+ }
+
+ this->setStyleSheet(ao_app->read_file(ao_app->get_theme_path() + "lobby.qss"));
}
//sets images, position and size
void Lobby::set_widgets()
{
- ao_app->set_user_theme();
-
QString filename = "lobby_design.ini";
pos_size_type f_lobby = ao_app->get_element_dimensions("lobby", filename);
diff --git a/lobby.h b/lobby.h
index 2d3aee5f..20b37340 100644
--- a/lobby.h
+++ b/lobby.h
@@ -23,6 +23,7 @@ class Lobby : public QMainWindow
public:
Lobby(AOApplication *p_ao_app);
+ void set_theme();
void set_widgets();
void list_servers();
void list_favorites();
diff --git a/path_functions.cpp b/path_functions.cpp
index 754ce9e3..6e772dbb 100644
--- a/path_functions.cpp
+++ b/path_functions.cpp
@@ -53,7 +53,7 @@ QString AOApplication::get_data_path()
QString AOApplication::get_theme_path()
{
- return get_base_path() + "themes/" + user_theme.toLower() + "/";
+ return get_base_path() + "themes/" + current_theme.toLower() + "/";
}
QString AOApplication::get_default_theme_path()
diff --git a/text_file_functions.cpp b/text_file_functions.cpp
index 47a9df36..2bc89034 100644
--- a/text_file_functions.cpp
+++ b/text_file_functions.cpp
@@ -8,6 +8,15 @@
#include <QDebug>
#include <QColor>
+QString AOApplication::read_file(QString p_path)
+{
+ QFile file(p_path);
+ if (!file.open(QFile::ReadOnly))
+ return "";
+
+ return file.readAll();
+}
+
QString AOApplication::read_config(QString searchline)
{
QString return_value = "";
@@ -42,7 +51,7 @@ QString AOApplication::read_config(QString searchline)
return return_value;
}
-QString AOApplication::read_user_theme()
+QString AOApplication::read_theme()
{
QString result = read_config("theme");