Skip to content

Commit e6ced65

Browse files
in1tiateoldmud0
andauthored
Fix expanded_desk_mods (2-5) being nonfunctional (#451)
Also fix backgrounds appearing off to the left if they are less wide than the viewport. i am in agony Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
1 parent 8162783 commit e6ced65

3 files changed

Lines changed: 65 additions & 36 deletions

File tree

include/aolayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class AOLayer : public QLabel {
7373
// Move the label itself around
7474
void move(int ax, int ay);
7575

76+
// Move the label and center it
77+
void move_and_center(int ax, int ay);
78+
7679
// This is somewhat pointless now as there's no "QMovie" object to resize, aka
7780
// no "combo" to speak of
7881
void combo_resize(int w, int h);
@@ -132,6 +135,8 @@ class AOLayer : public QLabel {
132135

133136
// Set the movie's frame to provided pixmap
134137
void set_frame(QPixmap f_pixmap);
138+
// Center the QLabel in the viewport based on the dimensions of f_pixmap
139+
void center_pixmap(QPixmap f_pixmap);
135140

136141
signals:
137142
void done();

src/aolayer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ QPixmap AOLayer::get_pixmap(QImage image)
8989
void AOLayer::set_frame(QPixmap f_pixmap)
9090
{
9191
this->setPixmap(f_pixmap);
92+
this->center_pixmap(f_pixmap);
93+
}
94+
95+
void AOLayer::center_pixmap(QPixmap f_pixmap) {
9296
QLabel::move(
9397
x + (f_w - f_pixmap.width()) / 2,
9498
y + (f_h - f_pixmap.height())); // Always center horizontally, always put
@@ -118,6 +122,16 @@ void AOLayer::move(int ax, int ay)
118122
QLabel::move(x, y);
119123
}
120124

125+
void AOLayer::move_and_center(int ax, int ay)
126+
{
127+
x = ax;
128+
y = ay;
129+
if (movie_frames.isEmpty()) // safeguard
130+
QLabel::move(x,y);
131+
else
132+
center_pixmap(movie_frames[0]); // just use the first frame since dimensions are all that matter
133+
}
134+
121135
void BackgroundLayer::load_image(QString p_filename)
122136
{
123137
play_once = false;

src/courtroom.cpp

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -532,21 +532,21 @@ void Courtroom::set_widgets()
532532
// them.
533533
ui_settings->show();
534534

535-
ui_vp_background->move(0, 0);
535+
ui_vp_background->move_and_center(0, 0);
536536
ui_vp_background->combo_resize(ui_viewport->width(), ui_viewport->height());
537537

538-
ui_vp_speedlines->move(0, 0);
538+
ui_vp_speedlines->move_and_center(0, 0);
539539
ui_vp_speedlines->combo_resize(ui_viewport->width(), ui_viewport->height());
540540

541-
ui_vp_player_char->move(0, 0);
541+
ui_vp_player_char->move_and_center(0, 0);
542542
ui_vp_player_char->combo_resize(ui_viewport->width(), ui_viewport->height());
543543

544-
ui_vp_sideplayer_char->move(0, 0);
544+
ui_vp_sideplayer_char->move_and_center(0, 0);
545545
ui_vp_sideplayer_char->combo_resize(ui_viewport->width(),
546546
ui_viewport->height());
547547

548548
// the AO2 desk element
549-
ui_vp_desk->move(0, 0);
549+
ui_vp_desk->move_and_center(0, 0);
550550
ui_vp_desk->combo_resize(ui_viewport->width(), ui_viewport->height());
551551

552552
ui_vp_evidence_display->move(0, 0);
@@ -570,16 +570,16 @@ void Courtroom::set_widgets()
570570
// thing, which is to parent these to ui_viewport. instead, AOLayer handles
571571
// masking so we don't overlap parts of the UI, and they become free floating
572572
// widgets.
573-
ui_vp_testimony->move(ui_viewport->x(), ui_viewport->y());
573+
ui_vp_testimony->move_and_center(ui_viewport->x(), ui_viewport->y());
574574
ui_vp_testimony->combo_resize(ui_viewport->width(), ui_viewport->height());
575575

576-
ui_vp_effect->move(ui_viewport->x(), ui_viewport->y());
576+
ui_vp_effect->move_and_center(ui_viewport->x(), ui_viewport->y());
577577
ui_vp_effect->combo_resize(ui_viewport->width(), ui_viewport->height());
578578

579-
ui_vp_wtce->move(ui_viewport->x(), ui_viewport->y());
579+
ui_vp_wtce->move_and_center(ui_viewport->x(), ui_viewport->y());
580580
ui_vp_wtce->combo_resize(ui_viewport->width(), ui_viewport->height());
581581

582-
ui_vp_objection->move(ui_viewport->x(), ui_viewport->y());
582+
ui_vp_objection->move_and_center(ui_viewport->x(), ui_viewport->y());
583583
ui_vp_objection->combo_resize(ui_viewport->width(), ui_viewport->height());
584584

585585
log_maximum_blocks = ao_app->get_max_log_size();
@@ -2277,24 +2277,7 @@ void Courtroom::display_character()
22772277
// Hide the face sticker
22782278
ui_vp_sticker->stop();
22792279
// Initialize the correct pos (called SIDE here for some reason) with DESK_MOD to determine if we should hide the desk or not.
2280-
switch(m_chatmessage[DESK_MOD].toInt()) {
2281-
case 4:
2282-
set_self_offset(m_chatmessage[SELF_OFFSET]);
2283-
[[fallthrough]];
2284-
case 2:
2285-
set_scene("1", m_chatmessage[SIDE]);
2286-
break;
2287-
case 5:
2288-
ui_vp_sideplayer_char->hide();
2289-
ui_vp_player_char->move(0, 0);
2290-
[[fallthrough]];
2291-
case 3:
2292-
set_scene("0", m_chatmessage[SIDE]);
2293-
break;
2294-
default:
2295-
set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
2296-
break;
2297-
}
2280+
set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
22982281

22992282
// Arrange the netstrings of the frame SFX for the character to know about
23002283
if (!m_chatmessage[FRAME_SFX].isEmpty() &&
@@ -2313,16 +2296,8 @@ void Courtroom::display_character()
23132296
ui_vp_player_char->set_flipped(true);
23142297
else
23152298
ui_vp_player_char->set_flipped(false);
2316-
2317-
// Parse the character X offset
2318-
QStringList offsets = m_chatmessage[SELF_OFFSET].split("&");
2319-
int offset_x = offsets[0].toInt();
2320-
// Y offset is 0 by default unless we find that the server sent us the Y position as well
2321-
int offset_y = 0;
2322-
if (offsets.length() > 1)
2323-
offset_y = offsets[1].toInt();
23242299
// Move the character on the viewport according to the offsets
2325-
ui_vp_player_char->move(ui_viewport->width() * offset_x / 100, ui_viewport->height() * offset_y / 100);
2300+
set_self_offset(m_chatmessage[SELF_OFFSET]);
23262301
}
23272302

23282303
void Courtroom::display_pair_character(QString other_charid, QString other_offset)
@@ -3189,6 +3164,23 @@ void Courtroom::play_preanim(bool immediate)
31893164
ui_vp_player_char->set_play_once(true);
31903165
ui_vp_player_char->load_image(f_preanim, f_char, preanim_duration, true);
31913166

3167+
switch(m_chatmessage[DESK_MOD].toInt()) {
3168+
case 4:
3169+
ui_vp_sideplayer_char->hide();
3170+
ui_vp_player_char->move_and_center(0, 0);
3171+
[[fallthrough]];
3172+
case 2:
3173+
set_scene("0", m_chatmessage[SIDE]);
3174+
break;
3175+
case 5:
3176+
case 3:
3177+
set_scene("1", m_chatmessage[SIDE]);
3178+
break;
3179+
default:
3180+
set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
3181+
break;
3182+
}
3183+
31923184
if (immediate)
31933185
anim_state = 4;
31943186
else
@@ -3204,6 +3196,24 @@ void Courtroom::play_preanim(bool immediate)
32043196
void Courtroom::preanim_done()
32053197
{
32063198
anim_state = 1;
3199+
switch(m_chatmessage[DESK_MOD].toInt()) {
3200+
case 4:
3201+
set_self_offset(m_chatmessage[SELF_OFFSET]);
3202+
[[fallthrough]];
3203+
case 2:
3204+
set_scene("1", m_chatmessage[SIDE]);
3205+
break;
3206+
case 5:
3207+
ui_vp_sideplayer_char->hide();
3208+
ui_vp_player_char->move_and_center(0, 0);
3209+
[[fallthrough]];
3210+
case 3:
3211+
set_scene("0", m_chatmessage[SIDE]);
3212+
break;
3213+
default:
3214+
set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
3215+
break;
3216+
}
32073217
qDebug() << "preanim over, anim_state set to 1";
32083218
handle_ic_speaking();
32093219
}

0 commit comments

Comments
 (0)