Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title Cards #263

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 92 additions & 10 deletions src/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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, &params->actor->speech_color);
dialog_focus_actor(d, params->actor);
Expand Down Expand Up @@ -240,13 +257,71 @@ static void dialog_actor_update_composite(DialogActor *a) {
a->composite_dirty = false;
}

void dialog_show_title(Dialog *dialog, DialogActor *actor, char *name, char *title) {
dialog->title.name = name;
dialog->title.text = title;
dialog->title.color = actor->speech_color;
dialog->title.active = true;
dialog->title.timeout = 720;

log_debug("[title] %s - %s (timeout: %i)", name, title, dialog->title.timeout);
}

static void dialog_title_draw(Dialog *dialog) {
if (dialog == NULL) {
return;
}

FloatRect title_bg_rect = {
.extent = { VIEWPORT_W / 3, VIEWPORT_H / 8 },
.offset = { VIEWPORT_W / 2 + 100, VIEWPORT_H / 2 + 100 },
};

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.x -= title_bg_rect.w * 0.5;
title_bg_rect.y -= title_bg_rect.h * 0.5;

Color clr = dialog->title.color;
color_mul_scalar(&clr, dialog->title.box_text.opacity);

text_draw_wrapped(dialog->title.name, title_bg_rect.w, &(TextParams) {
.shader = "text_default",
.shader_params = &(ShaderCustomParams) {{ dialog->opacity * dialog->text.current->opacity, 0 }},
.aux_textures = { res_texture("cell_noise") },
.color = &clr,
.pos = { title_bg_rect.x + title_bg_rect.w * 0.5, title_bg_rect.y + title_bg_rect.h * 0.3 },
.align = ALIGN_CENTER,
.font_ptr = res_font("standard"),
.overlay_projection = &title_bg_rect,
});

text_draw_wrapped(dialog->title.text, title_bg_rect.w, &(TextParams) {
.shader = "text_default",
.shader_params = &(ShaderCustomParams) {{ dialog->opacity * dialog->text.current->opacity, 0 }},
.aux_textures = { res_texture("cell_noise") },
.color = &clr,
.pos = { title_bg_rect.x + title_bg_rect.w * 0.5, title_bg_rect.y + title_bg_rect.h * 0.60 },
.align = ALIGN_CENTER,
.font_ptr = res_font("small"),
.overlay_projection = &title_bg_rect,
});
}

void dialog_draw(Dialog *dialog) {
if(dialog == NULL) {
return;
}

float o = dialog->opacity;

for(DialogActor *a = dialog->actors.first; a; a = a->next) {
dialog_actor_update_composite(a);
}
Expand Down Expand Up @@ -319,17 +394,19 @@ 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);
r_shader_standard_notex();
r_draw_quad();
r_mat_mv_pop();


Font *font = res_font("standard");

r_mat_tex_push();
Expand All @@ -338,14 +415,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,
Expand All @@ -356,12 +434,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,
Expand All @@ -370,6 +448,10 @@ void dialog_draw(Dialog *dialog) {
});
}

if(dialog->title.active) {
dialog_title_draw(dialog);
}

r_mat_tex_pop();
r_mat_mv_pop();
r_mat_mv_pop();
Expand Down
16 changes: 16 additions & 0 deletions src/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ typedef struct Dialog {
DialogTextBuffer *fading_out;
} text;

struct {
const char *name;
const char *text;
Color color;
bool active;
int timeout;
struct {
float opacity;
} box, box_text;
} title;

Color title_color;

COEVENTS_ARRAY(
skip_requested,
fadeout_began,
Expand Down Expand Up @@ -128,6 +141,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);
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/dialog_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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)
Expand Down