Skip to content

Commit

Permalink
clean this up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWitch committed Jul 18, 2021
1 parent 5acfa25 commit 4ae1e18
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 44 deletions.
105 changes: 61 additions & 44 deletions src/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,66 @@ 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;
Expand Down Expand Up @@ -389,43 +449,9 @@ 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,
});

dialog_title_draw(dialog);
}


r_mat_tex_pop();
r_mat_mv_pop();
r_mat_mv_pop();
Expand All @@ -448,12 +474,3 @@ 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);
}
1 change: 1 addition & 0 deletions src/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct Dialog {
struct {
const char *name;
const char *text;
Color color;
bool active;
int timeout;
struct {
Expand Down

0 comments on commit 4ae1e18

Please sign in to comment.