From 5acfa254a71fec89703c3466d8c70e8dc7b536b7 Mon Sep 17 00:00:00 2001 From: Alice D Date: Sun, 6 Dec 2020 14:38:21 -0500 Subject: [PATCH] moving over from private branch --- src/dialog.c | 85 +++++++++++++++++++++++++++++++++----- src/dialog.h | 15 +++++++ src/dialog/dialog_macros.h | 2 +- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/dialog.c b/src/dialog.c index cf54a42908..72efbc1152 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -103,6 +103,24 @@ void dialog_update(Dialog *d) { fapproach_asymptotic_p(&a->focus, a->target_focus, 0.12, 1e-3); } + + if (d->title.active) { + if(d->title.timeout > 0) { + fapproach_asymptotic_p(&d->title.box.opacity, 1, 0.05, 1e-3); + if(d->title.box.opacity >= 0.9 ) { + fapproach_asymptotic_p(&d->title.box_text.opacity, 1, 0.05, 1e-3); + } + d->title.timeout--; + } + if(d->title.timeout == 0 || d->state == DIALOG_STATE_FADEOUT) { + fapproach_asymptotic_p(&d->title.box.opacity, 0, 0.1, 1e-3); + fapproach_asymptotic_p(&d->title.box_text.opacity, 0, 0.1, 1e-3); + d->title.box_text.opacity = 0; + d->title.timeout = 0; + } + } else if (d->title.timeout == 0) { + d->title.active = false; + } } void dialog_skippable_wait(Dialog *d, int timeout) { @@ -160,7 +178,6 @@ void dialog_message_ex(Dialog *d, const DialogMessageParams *params) { assume(params->actor != NULL); assume(params->text != NULL); - log_debug("%s: %s", params->actor->name, params->text); dialog_set_text(d, params->text, ¶ms->actor->speech_color); dialog_focus_actor(d, params->actor); @@ -245,8 +262,6 @@ void dialog_draw(Dialog *dialog) { return; } - float o = dialog->opacity; - for(DialogActor *a = dialog->actors.first; a; a = a->next) { dialog_actor_update_composite(a); } @@ -319,10 +334,11 @@ void dialog_draw(Dialog *dialog) { }; r_mat_mv_push(); - if(o < 1) { - r_mat_mv_translate(0, 100 * (1 - o), 0); + + if(dialog->opacity < 1) { + r_mat_mv_translate(0, 100 * (1 - dialog->opacity), 0); } - r_color4(0, 0, 0, 0.8 * o); + r_color4(0, 0, 0, 0.8 * dialog->opacity); r_mat_mv_push(); r_mat_mv_translate(dialog_bg_rect.x, dialog_bg_rect.y, 0); r_mat_mv_scale(dialog_bg_rect.w, dialog_bg_rect.h, 1); @@ -330,6 +346,7 @@ void dialog_draw(Dialog *dialog) { r_draw_quad(); r_mat_mv_pop(); + Font *font = res_font("standard"); r_mat_tex_push(); @@ -338,14 +355,15 @@ void dialog_draw(Dialog *dialog) { dialog_bg_rect.x -= dialog_bg_rect.w * 0.5; dialog_bg_rect.y -= dialog_bg_rect.h * 0.5; + if(dialog->text.fading_out->opacity > 0) { clr = dialog->text.fading_out->color; - color_mul_scalar(&clr, o); + color_mul_scalar(&clr, dialog->opacity); text_draw_wrapped(dialog->text.fading_out->text, dialog_bg_rect.w, &(TextParams) { .shader = "text_dialog", .aux_textures = { res_texture("cell_noise") }, - .shader_params = &(ShaderCustomParams) {{ o * (1.0 - (0.2 + 0.8 * (1 - dialog->text.fading_out->opacity))), 1 }}, + .shader_params = &(ShaderCustomParams) {{ dialog->opacity * (1.0 - (0.2 + 0.8 * (1 - dialog->text.fading_out->opacity))), 1 }}, .color = &clr, .pos = { VIEWPORT_W/2, VIEWPORT_H-110 + font_get_lineskip(font) }, .align = ALIGN_CENTER, @@ -356,12 +374,12 @@ void dialog_draw(Dialog *dialog) { if(dialog->text.current->opacity > 0) { clr = dialog->text.current->color; - color_mul_scalar(&clr, o); + color_mul_scalar(&clr, dialog->opacity); text_draw_wrapped(dialog->text.current->text, dialog_bg_rect.w, &(TextParams) { .shader = "text_dialog", .aux_textures = { res_texture("cell_noise") }, - .shader_params = &(ShaderCustomParams) {{ o * dialog->text.current->opacity, 0 }}, + .shader_params = &(ShaderCustomParams) {{ dialog->opacity * dialog->text.current->opacity, 0 }}, .color = &clr, .pos = { VIEWPORT_W/2, VIEWPORT_H-110 + font_get_lineskip(font) }, .align = ALIGN_CENTER, @@ -370,6 +388,44 @@ void dialog_draw(Dialog *dialog) { }); } + if(dialog->title.active) { + FloatRect title_bg_rect = { + .extent = { VIEWPORT_W-300, 60 }, + .offset = { VIEWPORT_W-125, VIEWPORT_H-170 }, + }; + + r_mat_mv_push(); + if(dialog->title.box.opacity < 1) { + r_mat_mv_translate(0, 100 * (1 - dialog->title.box.opacity), 0); + } + r_color4(0, 0, 0, 0.8 * dialog->title.box.opacity); + r_mat_mv_translate(title_bg_rect.x, title_bg_rect.y, 0); + r_mat_mv_scale(title_bg_rect.w, title_bg_rect.h, 1); + r_shader_standard_notex(); + r_draw_quad(); + r_mat_mv_pop(); + + title_bg_rect.w = VIEWPORT_W * 0.96; + title_bg_rect.x -= title_bg_rect.w * 0.6; + title_bg_rect.y -= title_bg_rect.h * 0.6; + + clr = dialog->text.current->color; + color_mul_scalar(&clr, dialog->title.box_text.opacity); + + text_draw(dialog->title.name, &(TextParams) { + .shader = "text_default", + .color = &clr, + .pos = { + title_bg_rect.y-10, + title_bg_rect.x+300 + }, + .align = ALIGN_CENTER, + .font_ptr = font, + }); + + } + + r_mat_tex_pop(); r_mat_mv_pop(); r_mat_mv_pop(); @@ -392,3 +448,12 @@ bool dialog_is_active(Dialog *d) { void dialog_preload(void) { preload_resource(RES_SHADER_PROGRAM, "text_dialog", RESF_DEFAULT); } + +void dialog_show_title(Dialog *dialog, DialogActor *actor, char *name, char *title) { + dialog->title.name = name; + dialog->title.text = title; + dialog->title.active = true; + dialog->title.timeout = 360; + + log_debug("%s - %s", name, title); +} diff --git a/src/dialog.h b/src/dialog.h index 32b3621c5b..60967cf286 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -64,6 +64,18 @@ typedef struct Dialog { DialogTextBuffer *fading_out; } text; + struct { + const char *name; + const char *text; + bool active; + int timeout; + struct { + float opacity; + } box, box_text; + } title; + + Color title_color; + COEVENTS_ARRAY( skip_requested, fadeout_began, @@ -130,6 +142,9 @@ void dialog_draw(Dialog *d); bool dialog_page(Dialog *d) attr_nonnull_all; +void dialog_show_title(Dialog *d, DialogActor *actor, char *name, char *title) + attr_nonnull_all; + bool dialog_is_active(Dialog *d); void dialog_preload(void); diff --git a/src/dialog/dialog_macros.h b/src/dialog/dialog_macros.h index 2f0c1ffc98..19a3381e4b 100644 --- a/src/dialog/dialog_macros.h +++ b/src/dialog/dialog_macros.h @@ -49,7 +49,7 @@ #define FOCUS(_actor) dialog_focus_actor(&dialog, &_actor) #define WAIT_SKIPPABLE(_delay) dialog_skippable_wait(&dialog, _delay) #define EVENT(_name) coevent_signal(&events._name) -#define TITLE(_actor, _name, _title) log_warn("TITLE(%s, %s, %s) not yet implemented", #_actor, #_name, #_title) +#define TITLE(_actor, _name, _title) dialog_show_title(&dialog, &_actor, _name, _title) #define DIALOG_TASK(_protag, _interface) \ TASK_WITH_INTERFACE(_protag##_##_interface##Dialog, _interface##Dialog)