Skip to content

Commit

Permalink
moving over from private branch
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWitch committed Dec 6, 2020
1 parent 48f0a21 commit 098c1a2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
85 changes: 75 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 @@ -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);
}
Expand Down Expand Up @@ -319,17 +334,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 +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,
Expand All @@ -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,
Expand All @@ -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();
Expand All @@ -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);
}
15 changes: 15 additions & 0 deletions src/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
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 @@ -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)
Expand Down

0 comments on commit 098c1a2

Please sign in to comment.