From 2543d469acd4eff604156570ebe7a54dbd195d72 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 6 Feb 2018 08:16:30 +0000 Subject: [PATCH] Show info point messages. --- src/entities/misc/infoPoint.c | 35 +---------------------------------- src/structs.h | 2 -- src/world/hud.c | 29 ++++++++++++++++++++--------- src/world/hud.h | 2 ++ src/world/world.c | 3 --- 5 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/entities/misc/infoPoint.c b/src/entities/misc/infoPoint.c index 35770fc..0e0ecca 100644 --- a/src/entities/misc/infoPoint.c +++ b/src/entities/misc/infoPoint.c @@ -39,8 +39,6 @@ Entity *initInfoPoint(void) s->flags |= EF_WEIGHTLESS | EF_IGNORE_BULLETS | EF_NO_CLIP | EF_NO_ENVIRONMENT; s->ty = s->y; - - s->firstTouch = 1; s->init = init; s->tick = tick; @@ -69,38 +67,12 @@ static void tick(void) static void touch(Entity *other) { Structure *s; - int showMessage; s = (Structure*)self; if (other == (Entity*)world.bob) { - showMessage = 0; - - if (s->firstTouch) - { - s->firstTouch = 0; - showMessage = 1; - s->messageTimer = FPS; - } - else if (world.bob->dx == 0 && world.bob->dy == 0 && world.bob->isOnGround) - { - s->messageTimer++; - - if (s->messageTimer == FPS) - { - showMessage = 1; - } - } - else - { - s->messageTimer = 0; - } - - if (showMessage) - { - showInfoMessage(s->message); - } + showInfoMessage(s->message); } } @@ -111,10 +83,6 @@ static void load(cJSON *root) s = (Structure*)self; STRNCPY(s->message, cJSON_GetObjectItem(root, "message")->valuestring, MAX_DESCRIPTION_LENGTH); - if (cJSON_GetObjectItem(root, "firstTouch")) - { - s->firstTouch = cJSON_GetObjectItem(root, "firstTouch")->valueint; - } } static void save(cJSON *root) @@ -125,5 +93,4 @@ static void save(cJSON *root) cJSON_AddStringToObject(root, "type", "InfoPoint"); cJSON_AddStringToObject(root, "message", s->name); - cJSON_AddNumberToObject(root, "firstTouch", s->firstTouch); } diff --git a/src/structs.h b/src/structs.h index f072598..c046875 100644 --- a/src/structs.h +++ b/src/structs.h @@ -229,8 +229,6 @@ struct Structure { int closedX, closedY; int isLocked; int speed; - int messageTimer; - int firstTouch; int requiredPower; int isWeighted; int weightApplied; diff --git a/src/world/hud.c b/src/world/hud.c index 685d4cc..9015b46 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -24,10 +24,10 @@ static void drawHealth(void); static void drawPower(void); static int messageTime; +static int infoMessageTime; static char message[MAX_DESCRIPTION_LENGTH]; static int messageType; static SDL_Color messageColor; - static char infoMessage[MAX_DESCRIPTION_LENGTH]; void initHud(void) @@ -40,19 +40,21 @@ void initHud(void) void doHud(void) { - messageTime--; - - if (messageTime <= 0) + if (--messageTime <= 0) { - messageType = MSG_STANDARD; - + messageType = MSG_STANDARD; messageTime = 0; } + + if (--infoMessageTime <= 0) + { + infoMessageTime = 0; + } } void drawHud(void) { - int x, y; + int x, y, h; drawRect(0, 0, SCREEN_WIDTH, 32, 0, 0, 0, 200); @@ -69,6 +71,16 @@ void drawHud(void) drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 26, 16, TA_CENTER, messageColor, message); } + if (infoMessageTime > 0) + { + limitTextWidth(500); + h = getWrappedTextHeight(infoMessage, 20) + 20; + drawRect((SCREEN_WIDTH / 2) - 300, 40, 600, h, 0, 0, 0, 168); + drawOutlineRect((SCREEN_WIDTH / 2) - 300, 40, 600, h, 192, 192, 192, 255); + drawText(SCREEN_WIDTH / 2, 50, 20, TA_CENTER, colors.white, infoMessage); + limitTextWidth(0); + } + if (dev.debug) { x = -camera.x + world.bob->x + (world.bob->w / 2); @@ -150,6 +162,5 @@ void setGameplayMessage(int newMessageType, const char *format, ...) void showInfoMessage(char *newInfoMessage) { STRNCPY(infoMessage, newInfoMessage, MAX_DESCRIPTION_LENGTH); - - showWidgetGroup("ok"); + infoMessageTime = FPS / 4; } diff --git a/src/world/hud.h b/src/world/hud.h index e8e59ff..656a466 100644 --- a/src/world/hud.h +++ b/src/world/hud.h @@ -25,6 +25,8 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a); const char *getWeaponName(int i); extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a); +extern void limitTextWidth(int width); +extern int getWrappedTextHeight(const char *text, int size); extern Dev dev; extern Camera camera; diff --git a/src/world/world.c b/src/world/world.c index b3e4eef..35eb9c9 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -79,9 +79,6 @@ void initWorld(void) app.delegate.draw = draw; startMission(); - - world.bob->x = 90 * MAP_TILE_SIZE; - world.bob->y = 98 * MAP_TILE_SIZE; } static void logic(void)