Beispiel #1
0
//****************************************************************************************
// Challenge menu
//*****************************************************************************************
bool addChallenges()
{
    char			sPath[PATH_MAX];
    const char *sSearchPath	= "challenges";
    UDWORD			slotCount;
    static char		sSlotCaps[totalslots][totalslotspace];
    static char		sSlotTips[totalslots][totalslotspace];
    static char		sSlotFile[totalslots][totalslotspace];
    char **i, **files;

    (void) PHYSFS_mkdir(sSearchPath); // just in case

    psRequestScreen = widgCreateScreen(); // init the screen
    widgSetTipFont(psRequestScreen, font_regular);

    /* add a form to place the tabbed form on */
    W_FORMINIT sFormInit;
    sFormInit.formID = 0;				//this adds the blue background, and the "box" behind the buttons -Q
    sFormInit.id = CHALLENGE_FORM;
    sFormInit.style = WFORM_PLAIN;
    sFormInit.x = (SWORD) CHALLENGE_X;
    sFormInit.y = (SWORD) CHALLENGE_Y;
    sFormInit.width = CHALLENGE_W;
    // we need the form to be long enough for all resolutions, so we take the total number of items * height
    // and * the gaps, add the banner, and finally, the fudge factor ;)
    sFormInit.height = (slotsInColumn * CHALLENGE_ENTRY_H + CHALLENGE_HGAP * slotsInColumn) + CHALLENGE_BANNER_DEPTH + 20;
    sFormInit.disableChildren = true;
    sFormInit.pDisplay = intOpenPlainForm;
    widgAddForm(psRequestScreen, &sFormInit);

    // Add Banner
    sFormInit.formID = CHALLENGE_FORM;
    sFormInit.id = CHALLENGE_BANNER;
    sFormInit.x = CHALLENGE_HGAP;
    sFormInit.y = CHALLENGE_VGAP;
    sFormInit.width = CHALLENGE_W - (2 * CHALLENGE_HGAP);
    sFormInit.height = CHALLENGE_BANNER_DEPTH;
    sFormInit.disableChildren = false;
    sFormInit.pDisplay = displayLoadBanner;
    sFormInit.UserData = 0;
    widgAddForm(psRequestScreen, &sFormInit);

    // Add Banner Label
    W_LABINIT sLabInit;
    sLabInit.formID		= CHALLENGE_BANNER;
    sLabInit.id		= CHALLENGE_LABEL;
    sLabInit.style		= WLAB_ALIGNCENTRE;
    sLabInit.x		= 0;
    sLabInit.y		= 3;
    sLabInit.width		= CHALLENGE_W - (2 * CHALLENGE_HGAP);	//CHALLENGE_W;
    sLabInit.height		= CHALLENGE_BANNER_DEPTH;		//This looks right -Q
    sLabInit.pText		= "Challenge";
    widgAddLabel(psRequestScreen, &sLabInit);

    // add cancel.
    W_BUTINIT sButInit;
    sButInit.formID = CHALLENGE_BANNER;
    sButInit.x = 8;
    sButInit.y = 8;
    sButInit.width		= iV_GetImageWidth(IntImages, IMAGE_NRUTER);
    sButInit.height		= iV_GetImageHeight(IntImages, IMAGE_NRUTER);
    sButInit.UserData	= PACKDWORD_TRI(0, IMAGE_NRUTER , IMAGE_NRUTER);

    sButInit.id = CHALLENGE_CANCEL;
    sButInit.pTip = _("Close");
    sButInit.pDisplay = intDisplayImageHilight;
    widgAddButton(psRequestScreen, &sButInit);

    // add slots
    sButInit = W_BUTINIT();
    sButInit.formID		= CHALLENGE_FORM;
    sButInit.width		= CHALLENGE_ENTRY_W;
    sButInit.height		= CHALLENGE_ENTRY_H;
    sButInit.pDisplay	= displayLoadSlot;

    for (slotCount = 0; slotCount < totalslots; slotCount++)
    {
        sButInit.id		= slotCount + CHALLENGE_ENTRY_START;

        if (slotCount < slotsInColumn)
        {
            sButInit.x	= 22 + CHALLENGE_HGAP;
            sButInit.y	= (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + (
                                      slotCount * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H)));
        }
        else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2)))
        {
            sButInit.x	= 22 + (2 * CHALLENGE_HGAP + CHALLENGE_ENTRY_W);
            sButInit.y	= (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + (
                                      (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H)));
        }
        else
        {
            sButInit.x	= 22 + (3 * CHALLENGE_HGAP + (2 * CHALLENGE_ENTRY_W));
            sButInit.y	= (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + (
                                      (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H)));
        }
        widgAddButton(psRequestScreen, &sButInit);
    }

    // fill slots.
    slotCount = 0;

    sstrcpy(sPath, sSearchPath);
    sstrcat(sPath, "/*.ini");

    debug(LOG_SAVE, "Searching \"%s\" for challenges", sPath);

    // add challenges to buttons
    files = PHYSFS_enumerateFiles(sSearchPath);
    for (i = files; *i != NULL; ++i)
    {
        W_BUTTON *button;
        char description[totalslotspace];
        char highscore[totalslotspace];
        const char *name, *difficulty, *map, *givendescription;
        inifile *inif;

        // See if this filename contains the extension we're looking for
        if (!strstr(*i, ".ini"))
        {
            // If it doesn't, move on to the next filename
            continue;
        }

        /* First grab any high score associated with this challenge */
        inif = inifile_load(CHALLENGE_SCORES);
        sstrcpy(sPath, *i);
        sPath[strlen(sPath) - 4] = '\0';	// remove .ini
        sstrcpy(highscore, "no score");
        if (inif)
        {
            char key[64];
            bool victory;
            int seconds;

            ssprintf(key, "%s:Player", sPath);
            name = inifile_get(inif, key, "NO NAME");
            ssprintf(key, "%s:Victory", sPath);
            victory = inifile_get_as_bool(inif, key, false);
            ssprintf(key, "%s:Seconds", sPath);
            seconds = inifile_get_as_int(inif, key, -1);
            if (seconds > 0)
            {
                getAsciiTime(key, seconds * GAME_TICKS_PER_SEC);
                ssprintf(highscore, "%s by %s (%s)", key, name, victory ? "Victory" : "Survived");
            }
            inifile_delete(inif);
        }

        ssprintf(sPath, "%s/%s", sSearchPath, *i);
        inif = inifile_load(sPath);
        inifile_set_current_section(inif, "challenge");
        if (!inif)
        {
            debug(LOG_ERROR, "Could not open \"%s\"", sPath);
            continue;
        }
        name = inifile_get(inif, "Name", "BAD NAME");
        map = inifile_get(inif, "Map", "BAD MAP");
        difficulty = inifile_get(inif, "difficulty", "BAD DIFFICULTY");
        givendescription = inifile_get(inif, "description", "");
        ssprintf(description, "%s, %s, %s. %s", map, difficulty, highscore, givendescription);

        button = (W_BUTTON*)widgGetFromID(psRequestScreen, CHALLENGE_ENTRY_START + slotCount);

        debug(LOG_SAVE, "We found [%s]", *i);

        /* Set the button-text */
        sstrcpy(sSlotCaps[slotCount], name);		// store it!
        sstrcpy(sSlotTips[slotCount], description);	// store it, too!
        sstrcpy(sSlotFile[slotCount], sPath);		// store filename
        inifile_delete(inif);

        /* Add button */
        button->pTip = sSlotTips[slotCount];
        button->pText = sSlotCaps[slotCount];
        button->pUserData = (void *)sSlotFile[slotCount];
        slotCount++;		// go to next button...
        if (slotCount == totalslots)
        {
            break;
        }
    }
    PHYSFS_freeList(files);

    challengesUp = true;

    return true;
}
Beispiel #2
0
void
inifile_delete_cb(void *self)
{
  inifile_delete(self);
}