Beispiel #1
0
void doDialogBox()
{
    if (dialogBox.thinkTime > 0)
    {
        dialogBox.thinkTime--;

        if (dialogBox.thinkTime == 0)
        {
            freeDialogBox();
        }
    }
}
Beispiel #2
0
void freeAllResources()
{
	int i;

	freeLevelResources();

	/* Free the hud */

	freeHud();

	/* Free the dialog box */

	freeDialogBox();

	/* Free the script */

	freeScript();

	/* Free the game surfaces */

	freeGame();

	/* Free the font */

	closeFont(game.font);

	closeFont(game.largeFont);

	/* Clear the collision grid */

	freeCollisionGrid();

	/* Free the menus */

	freeMenus();

	/* Free the pak file */

	freePakFile();

	/* Free the texture cache */

	freeTextureCache();

	if (key != NULL)
	{
		for (i=0;i<MAX_PROPS_FILES;i++)
		{
			free(key[i]);
		}
		
		free(key);

		key = NULL;
	}

	if (value != NULL)
	{
		for (i=0;i<MAX_PROPS_FILES;i++)
		{
			free(value[i]);
		}
		
		free(value);

		value = NULL;
	}
}
Beispiel #3
0
SDL_Surface *createDialogBox(char *title, char *msg)
{
    char *text, *token, word[MAX_VALUE_LENGTH], *savePtr, *titleText;
    int i, lines, w, h, maxWidth, lineBreak, *lineBreaks;
    SDL_Surface **surface, *tempSurface;
    SDL_Rect dest;

    savePtr = NULL;

    freeDialogBox();

    text = malloc(strlen(msg) + 1);

    if (text == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(msg) + 1);
    }

    STRNCPY(text, msg, strlen(msg) + 1);

    titleText = NULL;

    if (title != NULL)
    {
        titleText = malloc(strlen(title) + 1);

        if (titleText == NULL)
        {
            showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Text", (int)strlen(title) + 1);
        }

        STRNCPY(titleText, title, strlen(title) + 1);
    }

    token = strtok_r(text, " ", &savePtr);

    i = 0;

    while (token != NULL)
    {
        i++;

        token = strtok_r(NULL, " ", &savePtr);
    }

    lines = i;

    if (titleText != NULL)
    {
        token = titleText;

        while (*token != '\0')
        {
            if (*token == '_')
            {
                *token = ' ';
            }

            token++;
        }

        lines++;
    }

    surface = malloc(sizeof(SDL_Surface *) * lines);

    if (surface == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the Dialog Surfaces", (int)sizeof(SDL_Surface *) * lines);
    }

    lineBreaks = malloc(sizeof(int) * lines);

    if (lineBreaks == NULL)
    {
        showErrorAndExit("Failed to allocate a whole %d bytes for the line breaks", (int)sizeof(int) * lines);
    }

    STRNCPY(text, msg, strlen(msg) + 1);

    token = strtok_r(text, " ", &savePtr);

    i = 0;

    maxWidth = w = h = 0;

    if (titleText != NULL)
    {
        surface[i] = generateTextSurface(titleText, game.font, 255, 255, 0, 0, 0, 0);

        h = surface[i]->h + 5;

        maxWidth = surface[i]->w;

        i++;
    }

    while (token != NULL)
    {
        lineBreak = FALSE;

        snprintf(word, sizeof(word), "%d", game.kills);

        token = replaceString(token, "[GAME_KILLS]", word);

        token = replaceString(token, "[HOURS]", getPlayTimeHours());

        snprintf(word, sizeof(word), "%d", game.continues);

        token = replaceString(token, "[CONTINUE_COUNT]", word);

        token = replaceString(token, "[INPUT_LEFT]", getKeyValue(control.button[CONTROL_LEFT]));

        token = replaceString(token, "[INPUT_RIGHT]", getKeyValue(control.button[CONTROL_RIGHT]));

        token = replaceString(token, "[INPUT_JUMP]", getKeyValue(control.button[CONTROL_JUMP]));

        token = replaceString(token, "[INPUT_BLOCK]", getKeyValue(control.button[CONTROL_BLOCK]));

        token = replaceString(token, "[INPUT_ATTACK]", getKeyValue(control.button[CONTROL_ATTACK]));

        token = replaceString(token, "[INPUT_INTERACT]", getKeyValue(control.button[CONTROL_INTERACT]));

        token = replaceString(token, "[INPUT_ACTIVATE]", getKeyValue(control.button[CONTROL_ACTIVATE]));

        token = replaceString(token, "[INPUT_INVENTORY]", getKeyValue(control.button[CONTROL_INVENTORY]));

        token = replaceString(token, "[INPUT_PREVIOUS]", getKeyValue(control.button[CONTROL_PREVIOUS]));

        token = replaceString(token, "[INPUT_NEXT]", getKeyValue(control.button[CONTROL_NEXT]));

        snprintf(word, sizeof(word), "%s ", token);

        if (word[strlen(word) - 2] == '\n')
        {
            lineBreak = TRUE;

            word[strlen(word) - 2] = '\0';
        }

        token = strtok_r(NULL, " ", &savePtr);

        if (token == NULL)
        {
            word[strlen(word) - 1] = '\0';
        }

        surface[i] = generateTextSurface(word, game.font, 255, 255, 255, 0, 0, 0);

        lineBreaks[i] = lineBreak;

        if (h == 0 || (i == 1 && titleText != NULL))
        {
            h += surface[i]->h + 5;
        }

        if (w + surface[i]->w > MAX_DIALOG_WIDTH)
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        w += surface[i]->w;

        if (w > maxWidth)
        {
            maxWidth = w;
        }

        if (lineBreak == TRUE)
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        i++;
    }

    h -= 5;

    tempSurface = createSurface(maxWidth, h);

    w = h = 0;

    for (i=0; i<lines; i++)
    {
        if (w + surface[i]->w > MAX_DIALOG_WIDTH || (titleText != NULL && i == 1))
        {
            w = 0;

            h += surface[i]->h + 5;
        }

        dest.x = w;
        dest.y = h;
        dest.w = surface[i]->w;
        dest.h = surface[i]->h;

        SDL_BlitSurface(surface[i], NULL, tempSurface, &dest);

        w += surface[i]->w;

        SDL_FreeSurface(surface[i]);

        if (lineBreaks[i] == TRUE)
        {
            w = 0;

            h += surface[i]->h + 5;
        }
    }

    tempSurface = addBorder(tempSurface, 255, 255, 255, 0, 0, 0);

    free(surface);

    free(text);

    if (titleText != NULL)
    {
        free(titleText);
    }

    free(lineBreaks);

    return tempSurface;
}