Show info point messages.

This commit is contained in:
Steve 2018-02-06 08:16:30 +00:00
parent fb5723d96e
commit 2543d469ac
5 changed files with 23 additions and 48 deletions

View File

@ -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);
}

View File

@ -229,8 +229,6 @@ struct Structure {
int closedX, closedY;
int isLocked;
int speed;
int messageTimer;
int firstTouch;
int requiredPower;
int isWeighted;
int weightApplied;

View File

@ -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;
}

View File

@ -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;

View File

@ -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)