2015-11-28 11:11:20 +01:00
|
|
|
/*
|
2016-02-21 16:50:27 +01:00
|
|
|
Copyright (C) 2015-2016 Parallel Realities
|
2015-11-28 11:11:20 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "messageBox.h"
|
|
|
|
|
2015-12-06 16:03:44 +01:00
|
|
|
static void calculateMessageBoxHeight(MessageBox *msg);
|
2016-05-15 09:19:26 +02:00
|
|
|
static void nextMessage(void);
|
2015-12-06 16:03:44 +01:00
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
static MessageBox head;
|
|
|
|
static MessageBox *tail;
|
2016-05-15 09:19:26 +02:00
|
|
|
static Entity *lastWingmate;
|
2015-11-28 11:11:20 +01:00
|
|
|
|
|
|
|
void initMessageBox(void)
|
|
|
|
{
|
|
|
|
memset(&head, 0, sizeof(MessageBox));
|
|
|
|
tail = &head;
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
lastWingmate = NULL;
|
2015-11-28 11:11:20 +01:00
|
|
|
}
|
|
|
|
|
2016-05-15 11:00:06 +02:00
|
|
|
void addMessageBox(char *title, char *body, int type)
|
2015-11-28 11:11:20 +01:00
|
|
|
{
|
2015-11-28 18:00:54 +01:00
|
|
|
MessageBox *msg;
|
2016-05-15 09:19:26 +02:00
|
|
|
int isFirst;
|
2015-11-28 18:00:54 +01:00
|
|
|
float time;
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
isFirst = (tail == &head);
|
2015-11-29 13:55:36 +01:00
|
|
|
|
2015-11-28 18:00:54 +01:00
|
|
|
msg = malloc(sizeof(MessageBox));
|
2015-11-28 11:11:20 +01:00
|
|
|
memset(msg, 0, sizeof(MessageBox));
|
|
|
|
tail->next = msg;
|
|
|
|
tail = msg;
|
|
|
|
|
2015-11-28 18:00:54 +01:00
|
|
|
time = 0.075 * strlen(body);
|
|
|
|
time = MIN(MAX(time, 3), 7);
|
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
STRNCPY(msg->title, title, MAX_NAME_LENGTH);
|
|
|
|
STRNCPY(msg->body, body, MAX_DESCRIPTION_LENGTH);
|
|
|
|
msg->time = time * FPS;
|
2016-05-15 11:00:06 +02:00
|
|
|
msg->type = type;
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
if (isFirst)
|
|
|
|
{
|
|
|
|
nextMessage();
|
|
|
|
}
|
2015-11-28 11:11:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void doMessageBox(void)
|
|
|
|
{
|
2015-11-29 13:55:36 +01:00
|
|
|
MessageBox *msg;
|
2015-11-28 11:11:20 +01:00
|
|
|
|
|
|
|
msg = head.next;
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
{
|
2015-12-30 19:43:20 +01:00
|
|
|
if (--msg->time <= -(FPS / 4))
|
2015-11-28 11:11:20 +01:00
|
|
|
{
|
2015-11-28 15:34:19 +01:00
|
|
|
if (msg == tail)
|
|
|
|
{
|
2015-11-29 13:55:36 +01:00
|
|
|
tail = &head;
|
2015-11-28 15:34:19 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 13:55:36 +01:00
|
|
|
head.next = msg->next;
|
2015-11-28 11:11:20 +01:00
|
|
|
free(msg);
|
2015-11-29 13:55:36 +01:00
|
|
|
msg = &head;
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
battle.messageSpeaker = NULL;
|
|
|
|
|
2015-11-29 13:55:36 +01:00
|
|
|
if (head.next)
|
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
nextMessage();
|
2015-11-29 13:55:36 +01:00
|
|
|
}
|
2015-11-28 11:11:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 16:03:44 +01:00
|
|
|
static void calculateMessageBoxHeight(MessageBox *msg)
|
|
|
|
{
|
|
|
|
limitTextWidth(575);
|
|
|
|
|
|
|
|
msg->height = getWrappedTextHeight(msg->body, 18);
|
|
|
|
|
|
|
|
limitTextWidth(0);
|
|
|
|
}
|
|
|
|
|
2015-11-28 18:00:54 +01:00
|
|
|
int showingMessageBoxes(void)
|
|
|
|
{
|
|
|
|
return head.next != NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
void drawMessageBox(void)
|
|
|
|
{
|
|
|
|
MessageBox *msg = head.next;
|
|
|
|
SDL_Rect r;
|
|
|
|
|
|
|
|
if (msg && msg->time > 0)
|
|
|
|
{
|
2015-12-06 16:03:44 +01:00
|
|
|
if (!msg->height)
|
|
|
|
{
|
|
|
|
calculateMessageBoxHeight(msg);
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
r.y = 50;
|
|
|
|
r.w = 650;
|
2015-12-06 16:03:44 +01:00
|
|
|
r.h = msg->height + 40;
|
2015-11-28 11:11:20 +01:00
|
|
|
r.x = (SCREEN_WIDTH - r.w) / 2;
|
|
|
|
|
|
|
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
2016-04-16 12:00:19 +02:00
|
|
|
|
2016-05-15 11:00:06 +02:00
|
|
|
if (msg->type == MB_IMPORTANT)
|
2016-04-16 12:00:19 +02:00
|
|
|
{
|
2016-05-15 11:00:06 +02:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 64);
|
2016-04-16 12:00:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-15 11:00:06 +02:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
|
2016-04-16 12:00:19 +02:00
|
|
|
}
|
2015-11-28 11:11:20 +01:00
|
|
|
SDL_RenderFillRect(app.renderer, &r);
|
2016-04-16 12:00:19 +02:00
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 128);
|
|
|
|
SDL_RenderDrawRect(app.renderer, &r);
|
|
|
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
|
|
|
|
|
|
|
drawText(r.x + 10, r.y + 5, 18, TA_LEFT, colors.cyan, msg->title);
|
|
|
|
|
2015-12-06 16:03:44 +01:00
|
|
|
limitTextWidth(575);
|
2015-11-28 11:11:20 +01:00
|
|
|
|
2016-05-15 11:00:06 +02:00
|
|
|
drawText(r.x + 10, r.y + 30, (msg->type == MB_PANDORAN) ? 0 : 18, TA_LEFT, (msg->type != MB_IMPORTANT) ? colors.white : colors.red, msg->body);
|
2015-11-28 11:11:20 +01:00
|
|
|
|
|
|
|
limitTextWidth(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
static void nextMessage(void)
|
|
|
|
{
|
|
|
|
Entity *e, *wingmate;
|
|
|
|
int isWingmate;
|
|
|
|
|
|
|
|
wingmate = NULL;
|
|
|
|
|
|
|
|
isWingmate = strcmp(head.next->title, "Wingmate") == 0;
|
|
|
|
|
|
|
|
playSound(SND_RADIO);
|
|
|
|
|
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->active && e != player)
|
|
|
|
{
|
|
|
|
if (strcmp(e->name, head.next->title) == 0)
|
|
|
|
{
|
|
|
|
battle.messageSpeaker = e;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isWingmate && e->type == ET_FIGHTER && e->speed > 0)
|
|
|
|
{
|
|
|
|
wingmate = e;
|
|
|
|
|
|
|
|
if (rand() % 2 && e != lastWingmate)
|
|
|
|
{
|
|
|
|
battle.messageSpeaker = lastWingmate = e;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
battle.messageSpeaker = wingmate;
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
void resetMessageBox(void)
|
|
|
|
{
|
|
|
|
MessageBox *messageBox;
|
|
|
|
|
|
|
|
while (head.next)
|
|
|
|
{
|
|
|
|
messageBox = head.next;
|
|
|
|
head.next = messageBox->next;
|
|
|
|
free(messageBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
tail = &head;
|
|
|
|
}
|