Skip to content

Commit

Permalink
Fix music_display not stretching properly, reconsolidate ForegroundLa…
Browse files Browse the repository at this point in the history
…yer into InterjectionLayer, rename InterjectionLayer to SplashLayer (AttorneyOnline#436)

* more intelligent separation

* separation 2 electric boogaloo

* rename InterjectionLayer to SplashLayer

* remove redundant layer type

* comments and cleanup

* fix incorrect use of continuous

* remove nonfunctional check

* fix additive not coloring correctly

Co-authored-by: Crystalwarrior <[email protected]>
  • Loading branch information
in1tiate and Crystalwarrior authored Jan 29, 2021
1 parent 4a9480a commit 5cafb01
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 77 deletions.
2 changes: 1 addition & 1 deletion base/themes
Submodule themes updated 2411 files
46 changes: 29 additions & 17 deletions include/aolayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@

class AOApplication;

// "Brief" explanation of what the hell this is:
//
// AOLayer handles all animations both inside and outside
// the viewport. It was originally devised as a layering
// system, but turned into a full refactor of the existing
// animation code.
//
// AOLayer has six subclasses, all of which differ mainly in
// how they handle path resolution.
//
// - BackgroundLayer: self-explanatory, handles files found in base/background
// - CharLayer: handles all the "wonderful" quirks of character path resolution
// - SplashLayer: handles elements that can either be provided by a misc/ directory
// or by the theme - speedlines, shouts, WT/CE, et cetera
// - EffectLayer: this is basically a dummy layer since effects do their own wonky
// path resolution in a different file
// - InterfaceLayer: handles UI elements like the chat arrow and the music display
// - StickerLayer: Crystalwarrior really wanted this. Handles "stickers," whatever those are.
//
// For questions comments or concerns, bother someone else

class AOLayer : public QLabel {
Q_OBJECT

Expand All @@ -24,6 +45,11 @@ class AOLayer : public QLabel {
bool play_once = false; // Whether to loop this animation or not
bool cull_image = true; // if we're done playing this animation, should we
// hide it? also controls durational culling
// Are we loading this from the same frame we left off on?
bool continuous = false;
// Whether or not to forcibly bypass the simple check done by start_playback
// and use the existent value of continuous instead
bool force_continuous = false;
Qt::TransformationMode transform_mode = Qt::FastTransformation; // transformation mode to use for this image
bool stretch = false; // Should we stretch/squash this image to fill the screen?

Expand Down Expand Up @@ -72,7 +98,7 @@ class AOLayer : public QLabel {
QElapsedTimer actual_time;

// Usually used to turn seconds into milliseconds such as for [Time] tag in
// char.ini
// char.ini (which is no longer used)
const int tick_ms = 60;

// These are the X and Y values before they are fixed based on the sprite's
Expand All @@ -91,12 +117,6 @@ class AOLayer : public QLabel {
int speed = 100;

bool m_flipped = false;
// Are we loading this from the same frame we left off on? TODO: actually make
// this work
bool continuous = false;
// Whether or not to forcibly bypass the simple check done by start_playback
// and use the existent value of continuous instead
bool force_continuous = false;

int duration = 0;

Expand Down Expand Up @@ -129,14 +149,6 @@ class BackgroundLayer : public AOLayer {
void load_image(QString p_filename);
};

class ForegroundLayer : public AOLayer {
Q_OBJECT
public:
ForegroundLayer(QWidget *p_parent, AOApplication *p_ao_app);
QString miscname; //'misc' folder to search. we fetch this based on p_charname below
void load_image(QString p_filename, QString p_charname);
};

class CharLayer : public AOLayer {
Q_OBJECT
public:
Expand Down Expand Up @@ -191,10 +203,10 @@ private slots:
void play_sfx(QString sfx);
};

class InterjectionLayer : public AOLayer {
class SplashLayer : public AOLayer {
Q_OBJECT
public:
InterjectionLayer(QWidget *p_parent, AOApplication *p_ao_app);
SplashLayer(QWidget *p_parent, AOApplication *p_ao_app);
void load_image(QString p_filename, QString p_charname, QString p_miscname);
};

Expand Down
8 changes: 4 additions & 4 deletions include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ class Courtroom : public QMainWindow {

QWidget *ui_viewport;
BackgroundLayer *ui_vp_background;
ForegroundLayer *ui_vp_speedlines;
SplashLayer *ui_vp_speedlines;
CharLayer *ui_vp_player_char;
CharLayer *ui_vp_sideplayer_char;
BackgroundLayer *ui_vp_desk;
Expand All @@ -614,10 +614,10 @@ class Courtroom : public QMainWindow {
QLabel *ui_vp_showname;
InterfaceLayer *ui_vp_chat_arrow;
QTextEdit *ui_vp_message;
InterfaceLayer *ui_vp_testimony;
InterjectionLayer *ui_vp_wtce;
SplashLayer *ui_vp_testimony;
SplashLayer *ui_vp_wtce;
EffectLayer *ui_vp_effect;
InterjectionLayer *ui_vp_objection;
SplashLayer *ui_vp_objection;

QTextEdit *ui_ic_chatlog;

Expand Down
38 changes: 3 additions & 35 deletions src/aolayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ BackgroundLayer::BackgroundLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
}
ForegroundLayer::ForegroundLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
}
CharLayer::CharLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
Expand All @@ -40,15 +36,14 @@ EffectLayer::EffectLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
}
InterjectionLayer::InterjectionLayer(QWidget *p_parent, AOApplication *p_ao_app)
SplashLayer::SplashLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
}
InterfaceLayer::InterfaceLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
}

StickerLayer::StickerLayer(QWidget *p_parent, AOApplication *p_ao_app)
: AOLayer(p_parent, p_ao_app)
{
Expand Down Expand Up @@ -135,27 +130,6 @@ void BackgroundLayer::load_image(QString p_filename)
start_playback(ao_app->get_image_suffix(ao_app->get_background_path(p_filename)));
}

void ForegroundLayer::load_image(QString p_filename, QString p_charname)
{
play_once = false;
cull_image = false;
miscname = ao_app->get_char_shouts(p_charname);
qDebug() << "[ForegroundLayer] FG loaded: " << p_filename;
QList<QString> pathlist = {
ao_app->get_image_suffix(ao_app->get_character_path(
p_charname, p_filename)), // first check the character folder
ao_app->get_image_suffix(ao_app->get_theme_path(
"misc/" + miscname + "/" +
p_filename)), // then check our theme's misc directory
ao_app->get_image_suffix(ao_app->get_misc_path(
miscname, p_filename)), // then check our global misc folder
ao_app->get_image_suffix(
ao_app->get_theme_path(p_filename)), // then check the user's theme
ao_app->get_image_suffix(ao_app->get_default_theme_path(
p_filename))}; // and finally check the default theme
start_playback(find_image(pathlist));
}

void CharLayer::load_image(QString p_filename, QString p_charname,
int p_duration, bool p_is_preanim)
{
Expand Down Expand Up @@ -219,12 +193,9 @@ void CharLayer::load_image(QString p_filename, QString p_charname,
this->start_playback(find_image(pathlist));
}

void InterjectionLayer::load_image(QString p_filename, QString p_charname,
void SplashLayer::load_image(QString p_filename, QString p_charname,
QString p_miscname)
{
continuous = false;
force_continuous = true;
play_once = true;
transform_mode = ao_app->get_misc_scaling(p_miscname);
QList<QString> pathlist = {
ao_app->get_image_suffix(ao_app->get_character_path(
Expand Down Expand Up @@ -269,7 +240,7 @@ void EffectLayer::load_image(QString p_filename, bool p_looping)

void InterfaceLayer::load_image(QString p_filename, QString p_miscname)
{
transform_mode = ao_app->get_misc_scaling(p_miscname);
stretch = true;
QList<QString> pathlist = {
ao_app->get_image_suffix(ao_app->get_theme_path(
"misc/" + p_miscname + "/" +
Expand Down Expand Up @@ -371,12 +342,9 @@ void AOLayer::start_playback(QString p_image)
int l_delay = m_reader.nextImageDelay();
movie_frames.append(l_pixmap);
movie_delays.append(l_delay);
// qDebug() << "appending delay of " << l_delay;
}
}
last_path = p_image;
// qDebug() << "CONT: " << continuous << " MAX: " << max_frames
// << " LAST MAX: " << last_max_frames << " FRAME: " << frame;
QPixmap f_pixmap = this->get_pixmap(m_reader.read());
int f_delay = m_reader.nextImageDelay();

Expand Down
48 changes: 28 additions & 20 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()

ui_viewport = new QWidget(this);
ui_vp_background = new BackgroundLayer(ui_viewport, ao_app);
ui_vp_speedlines = new ForegroundLayer(ui_viewport, ao_app);
ui_vp_speedlines = new SplashLayer(ui_viewport, ao_app);
ui_vp_player_char = new CharLayer(ui_viewport, ao_app);
ui_vp_sideplayer_char = new CharLayer(ui_viewport, ao_app);
ui_vp_sideplayer_char->hide();
Expand All @@ -67,13 +67,18 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_vp_message->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui_vp_message->setReadOnly(true);

ui_vp_testimony = new InterfaceLayer(this, ao_app);
ui_vp_testimony = new SplashLayer(this, ao_app);
ui_vp_testimony->set_play_once(false);
ui_vp_testimony->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_vp_wtce = new InterjectionLayer(this, ao_app);
ui_vp_wtce = new SplashLayer(this, ao_app);
ui_vp_wtce->set_play_once(true);
ui_vp_wtce->continuous = false;
ui_vp_wtce->force_continuous = true;
ui_vp_wtce->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_vp_objection = new InterjectionLayer(this, ao_app);
ui_vp_objection = new SplashLayer(this, ao_app);
ui_vp_objection->set_play_once(true);
ui_vp_objection->continuous = false;
ui_vp_objection->force_continuous = true;
ui_vp_objection->setAttribute(Qt::WA_TransparentForMouseEvents);

ui_ic_chatlog = new QTextEdit(this);
Expand Down Expand Up @@ -115,6 +120,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()

ui_music_display = new InterfaceLayer(this, ao_app);
ui_music_display->set_play_once(false);
ui_music_display->transform_mode = Qt::SmoothTransformation;
ui_music_display->setAttribute(Qt::WA_TransparentForMouseEvents);

ui_music_name = new ScrollText(ui_music_display);
Expand Down Expand Up @@ -1998,6 +2004,7 @@ void Courtroom::chatmessage_dequeue()
QString f_char = m_chatmessage[CHAR_NAME];
f_custom_theme = ao_app->get_chat(f_char);
}
ui_vp_chat_arrow->transform_mode = ao_app->get_misc_scaling(f_custom_theme);
ui_vp_chat_arrow->load_image("chat_arrow", f_custom_theme);

// Nothing to parse in the queue
Expand Down Expand Up @@ -2592,18 +2599,16 @@ void Courtroom::initialize_chatbox()

// This should probably be called only if any change from the last chat
// arrow was actually detected.
if (current_misc != last_misc) {
pos_size_type design_ini_result = ao_app->get_element_dimensions(
"chat_arrow", "courtroom_design.ini", customchar);
if (design_ini_result.width < 0 || design_ini_result.height < 0) {
qDebug() << "W: could not find \"chat_arrow\" in courtroom_design.ini";
ui_vp_chat_arrow->hide();
}
else {
ui_vp_chat_arrow->move(design_ini_result.x + ui_vp_chatbox->x(), design_ini_result.y + ui_vp_chatbox->y());
ui_vp_chat_arrow->combo_resize(design_ini_result.width,
design_ini_result.height);
}
pos_size_type design_ini_result = ao_app->get_element_dimensions(
"chat_arrow", "courtroom_design.ini", customchar);
if (design_ini_result.width < 0 || design_ini_result.height < 0) {
qDebug() << "W: could not find \"chat_arrow\" in courtroom_design.ini";
ui_vp_chat_arrow->hide();
}
else {
ui_vp_chat_arrow->move(design_ini_result.x + ui_vp_chatbox->x(), design_ini_result.y + ui_vp_chatbox->y());
ui_vp_chat_arrow->combo_resize(design_ini_result.width,
design_ini_result.height);
}

pos_size_type default_width = ao_app->get_element_dimensions(
Expand Down Expand Up @@ -2719,7 +2724,7 @@ void Courtroom::handle_ic_speaking()
filename = "prosecution_speedlines";
else
filename = "defense_speedlines";
ui_vp_speedlines->load_image(filename, m_chatmessage[CHAR_NAME]);
ui_vp_speedlines->load_image(filename, m_chatmessage[CHAR_NAME], ao_app->get_char_shouts(m_chatmessage[CHAR_NAME]));
}

// Check if this is a talking color (white text, etc.)
Expand Down Expand Up @@ -3308,12 +3313,14 @@ void Courtroom::chat_tick()
f_char = m_chatmessage[CHAR_NAME];
f_custom_theme = ao_app->get_chat(f_char);
}
ui_vp_chat_arrow->load_image("chat_arrow",f_custom_theme); // Chat stopped being processed, indicate that.
ui_vp_chat_arrow->transform_mode = ao_app->get_misc_scaling(f_custom_theme);
ui_vp_chat_arrow->load_image("chat_arrow", f_custom_theme); // Chat stopped being processed, indicate that.
additive_previous =
additive_previous +
filter_ic_text(f_message, true, -1, m_chatmessage[TEXT_COLOR].toInt());
QString f_message_filtered = filter_ic_text(f_message, true, -1, m_chatmessage[TEXT_COLOR].toInt());
for (int c = 0; c < max_colors; ++c) {
additive_previous = additive_previous.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
f_message_filtered = f_message_filtered.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
}
additive_previous = additive_previous + f_message_filtered;
Expand Down Expand Up @@ -3448,6 +3455,7 @@ void Courtroom::chat_tick()
// Do the colors, gradual showing, etc. in here
QString f_message_filtered = filter_ic_text(f_message, true, tick_pos, m_chatmessage[TEXT_COLOR].toInt());
for (int c = 0; c < max_colors; ++c) {
additive_previous = additive_previous.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
f_message_filtered = f_message_filtered.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
}
ui_vp_message->setHtml(additive_previous + f_message_filtered);
Expand Down Expand Up @@ -3772,6 +3780,7 @@ void Courtroom::handle_song(QStringList *p_contents)
void Courtroom::handle_wtce(QString p_wtce, int variant)
{
QString sfx_file = "courtroom_sounds.ini";
QString bg_misc = ao_app->read_design_ini("misc", ao_app->get_background_path("design.ini"));
QString sfx_name;
QString filename;
ui_vp_wtce->set_static_duration(wtce_static_time);
Expand All @@ -3780,7 +3789,7 @@ void Courtroom::handle_wtce(QString p_wtce, int variant)
if (p_wtce == "testimony1") {
sfx_name = "witness_testimony";
filename = "witnesstestimony";
ui_vp_testimony->load_image("testimony", "");
ui_vp_testimony->load_image("testimony", "", bg_misc);
}
// cross examination
else if (p_wtce == "testimony2") {
Expand All @@ -3802,7 +3811,6 @@ void Courtroom::handle_wtce(QString p_wtce, int variant)
ui_vp_testimony->stop();
}
}
QString bg_misc = ao_app->read_design_ini("misc", ao_app->get_background_path("design.ini"));
sfx_player->play(ao_app->get_sfx(sfx_name, bg_misc));
ui_vp_wtce->load_image(filename, "", bg_misc);
ui_vp_wtce->set_play_once(true);
Expand Down

0 comments on commit 5cafb01

Please sign in to comment.