Mercurial > molko
changeset 293:5abf2ebb1621
rpg: add battle-message
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 05 Mar 2021 10:08:29 +0100 |
parents | 08ab73b32832 |
children | 1606b061e4ce |
files | libmlk-rpg/rpg/battle-message.c libmlk-rpg/rpg/battle-message.h |
diffstat | 2 files changed, 113 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmlk-rpg/rpg/battle-message.c Fri Mar 05 10:08:29 2021 +0100 @@ -0,0 +1,69 @@ +/* + * battle-message.c -- automatic top center message in battle + * + * Copyright (c) 2020 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <assert.h> + +#include <core/window.h> + +#include <ui/align.h> +#include <ui/frame.h> +#include <ui/label.h> + +#include "battle-message.h" + +#define DELAY 1500 + +bool +battle_message_update(struct battle_message *msg, unsigned int ticks) +{ + assert(msg); + + msg->elapsed += ticks; + + return msg->elapsed >= DELAY; +} + +void +battle_message_draw(const struct battle_message *msg) +{ + assert(msg); + + struct frame f = {0}; + struct label l = {0}; + unsigned int lw = 0, lh = 0; + + /* Prepare message frame. */ + f.w = window.w / 3; + f.h = window.h / 15; + f.theme = msg->theme; + + /* Center on top. */ + align(ALIGN_TOP, &f.x, &f.y, f.w, f.h, 0, 20, window.w, window.h); + + /* Prepare message label box. */ + l.text = msg->text; + l.flags = LABEL_FLAGS_SHADOW; + l.theme = msg->theme; + label_query(&l, &lw, &lh); + + /* Align the text in the box. */ + align(ALIGN_CENTER, &l.x, &l.y, lw, lh, f.x, f.y, f.w, f.h); + + frame_draw(&f); + label_draw(&l); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmlk-rpg/rpg/battle-message.h Fri Mar 05 10:08:29 2021 +0100 @@ -0,0 +1,44 @@ +/* + * battle-message.h -- automatic top center message in battle + * + * Copyright (c) 2020 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef MOLKO_ADVENTURE_BATTLE_MESSAGE_H +#define MOLKO_ADVENTURE_BATTLE_MESSAGE_H + +#include <stdbool.h> + +#include <core/core.h> + +struct theme; + +struct battle_message { + const char *text; + struct theme *theme; + unsigned int elapsed; +}; + +CORE_BEGIN_DECLS + +bool +battle_message_update(struct battle_message *, unsigned int); + +void +battle_message_draw(const struct battle_message *); + +CORE_END_DECLS + +#endif /* !MOLKO_ADVENTURE_BATTLE_MESSAGE_H */