Esempio n. 1
0
void tutShutdown(void)
{
    sdword count;

	if(tutorial == 3)
	{
		tutUnInitialize();
		return;
	}

    for(count = 0; count < NUM_BUTTON_TEXTURES; count++)
    {
        if (tutButtonImage[count] != NULL)
        {
            memFree(tutButtonImage[count]);
            tutButtonImage[count] = NULL;
        }
        if (tutButtonTexture[count] != TR_InvalidInternalHandle)
        {
            trRGBTextureDelete(tutButtonTexture[count]);
            tutButtonTexture[count] = TR_InvalidInternalHandle;
        }
    }

    if(tutRegion != NULL)
    {
        regLinkRemove(tutRegion);
    }
}
Esempio n. 2
0
void spBackPicking(char *name, featom *atom)
{
    spDescriptionDefaultsAndFreeText();

    if (scenarioTexture != TR_InvalidInternalHandle)
    {                                                       //delete the preview image, if there was one
        trRGBTextureDelete(scenarioTexture);
        scenarioTexture = TR_InvalidInternalHandle;
        if (spTextureData != NULL)
        {
            memFree(spTextureData);
            spTextureData = NULL;
        }
    }

    feScreenDisappear(NULL, NULL);
    spPickerStarted = FALSE;
}
Esempio n. 3
0
/*-----------------------------------------------------------------------------
    Name        : spDonePicking/spBackPicking
    // if the region is the scenario picker
    Description : Close the color picker and optionally specify the file path
                    of the chosen file.
    Inputs      : standard FE callback
    Outputs     : DonePicking stores chosen file name in parameter to spScenarioPick
    Return      : void
----------------------------------------------------------------------------*/
void spDonePicking(char *name, featom *atom)
{
    sdword index;
    sdword spCurrentSelectedCandidate = spCurrentSelected;

    if (spScenarioListWindow->CurLineSelected!=NULL)
    {
        for (index = 0; index < spNumberScenarios; index++)
        {
            if (spScenarioListWindow->CurLineSelected->data == (ubyte *)&spScenarios[index])
            {
                spCurrentSelectedCandidate = index;
                break;
            }
        }
    }

    if (gameTypeFromDescription != NULL)
    {                                                       //if there is a game type from description file
        mgSetGameTypeByStruct(gameTypeFromDescription);     //set that game type
        feAllCallOnCreate(feStack[feStackIndex - 1].screen);//update buttons to reflect changes
        mgGameTypesOtherButtonPressed();
    }
    spDescriptionDefaultsAndFreeText();

    if (scenarioTexture != TR_InvalidInternalHandle)
    {                                                       //delete the preview image, if there was one
        trRGBTextureDelete(scenarioTexture);
        scenarioTexture = TR_InvalidInternalHandle;
        if (spTextureData != NULL)
        {
            memFree(spTextureData);
            spTextureData = NULL;
        }
    }

    if (spSelectionValid(spCurrentSelectedCandidate))
    {
        spCurrentSelected = spCurrentSelectedCandidate;
    }

    feScreenDisappear(NULL, NULL);
    spPickerStarted = FALSE;
}
Esempio n. 4
0
/*-----------------------------------------------------------------------------
    Name        : spNewItem
    Description : Called when a new item in the color picker list is selected.
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void spNewItem(void)
{
    char bitmapFile[_MAX_PATH];
    char descriptionFile[_MAX_PATH];
    char *chopBuffer;
    sdword scen;
    rectangle textureRect;
//    rectangle rect = spScenarioBitmapWindow->rect;
    color *bmpBuffer;
    filehandle handle;
    bmpheader header;
    featom *atom;

    scen = spScenarioListWindow->CurLineSelected->position;
    atom = feAtomFindInScreen(feStack[feStackIndex].screen, "CS_ScenarioBitmap");
    dbgAssert(atom != NULL);

    if (scenarioTexture != TR_InvalidInternalHandle)
    {                                                       //delete the old texture before creating a new one
        trRGBTextureDelete(scenarioTexture);
        scenarioTexture = TR_InvalidInternalHandle;
        if (spTextureData != NULL)
        {
            memFree(spTextureData);
            spTextureData = NULL;
        }
    }

    //free the previous text and set defaults
    spDescriptionDefaultsAndFreeText();

    spFindImage(bitmapFile, descriptionFile, spScenarios[scen].bitmapfileSpec);
    if (strlen(bitmapFile) > 0)
    {
        handle = bmpFileOpen(&header, bitmapFile);         //open the file
        if (handle != 0)
        {                                                   //if opened properly
            if (header.biWidth < SCP_PreviewWidthMin || header.biHeight > SCP_PreviewWidthMax)
            {
#if SCP_VERBOSE_LEVEL >= 1
                dbgMessagef("\n'%s': width of %d bad.", bitmapFile, header.biWidth);
#endif
                bmpClose(handle);
                return;
            }
            else if (header.biHeight < SCP_PreviewHeightMin || header.biHeight > SCP_PreviewHeightMax)
            {
#if SCP_VERBOSE_LEVEL >= 1
                dbgMessagef("\n'%s': height of %d bad.", bitmapFile, header.biHeight);
#endif
                bmpClose(handle);
                return;
            }
            //allocate the image buffer
            bmpBuffer = memAlloc(header.biWidth * header.biHeight * sizeof(color), "TempBMPbuffer", Pyrophoric);
            bmpBodyRead(bmpBuffer, handle, &header);        //read in the body of the file
            if (header.biWidth != SCP_PreviewWidth || header.biHeight != SCP_PreviewHeight)
            {                                               //if the image is the wrong size
                //rescale the image to the proper size
                bmpBuffer = trImageScale(bmpBuffer, header.biWidth, header.biHeight, SCP_PreviewWidth, SCP_PreviewHeight, TRUE);
                header.biWidth = SCP_PreviewWidth;           //make it think we're the right size
                header.biHeight = SCP_PreviewHeight;
            }
            scenarioTexture = trRGBTextureCreate(bmpBuffer, header.biWidth, header.biHeight, FALSE);
            spTextureWidth  = header.biWidth;
            spTextureHeight = header.biHeight;
            if (spTextureData != NULL)
            {
                memFree(spTextureData);
            }
            spTextureData = (ubyte*)memAlloc(4*spTextureWidth*spTextureHeight, "scenpick data", NonVolatile);
            memcpy(spTextureData, bmpBuffer, 4*spTextureWidth*spTextureHeight);
            memFree(bmpBuffer);                             //free the image
        }
        else
        {
            return;
        }
    }
    else
    {
#if SCP_VERBOSE_LEVEL >= 1
        dbgMessage("\nNo preview image found!");
#endif
        textureRect.x0 = atom->x + SCP_TEXTURE_INSET;
        textureRect.y0 = atom->y + SCP_TEXTURE_INSET;
        textureRect.x1 = atom->x + atom->width - SCP_TEXTURE_INSET;
        textureRect.y1 = atom->y + atom->height - SCP_TEXTURE_INSET;
        primRectSolid2(&textureRect, colBlack);
    }

    if (strlen(descriptionFile) > 0)
    {                                                       //if there is a description file
        // load in the proper description based on the language
        if (strCurLanguage==languageEnglish)
        {
            scriptSet(NULL, descriptionFile, spDescriptionTweaks);//load in the description text
        }
        else if (strCurLanguage==languageFrench)
        {
            scriptSet(NULL, descriptionFile, spDescriptionTweaksFrench);//load in the description text
            if (spDescription==NULL)
            {
                // if french isn't found load in english
                scriptSet(NULL, descriptionFile, spDescriptionTweaks);//load in the description text
            }
        }
        else if (strCurLanguage==languageGerman)
        {
            scriptSet(NULL, descriptionFile, spDescriptionTweaksGerman);//load in the description text
            if (spDescription==NULL)
            {
                // if german isn't found load in english
                scriptSet(NULL, descriptionFile, spDescriptionTweaks);//load in the description text
            }
        }
        else if (strCurLanguage==languageSpanish)
        {
            scriptSet(NULL, descriptionFile, spDescriptionTweaksSpanish);//load in the description text
            if (spDescription==NULL)
            {
                // if german isn't found load in english
                scriptSet(NULL, descriptionFile, spDescriptionTweaks);//load in the description text
            }
        }
        else if (strCurLanguage==languageItalian)
        {
            scriptSet(NULL, descriptionFile, spDescriptionTweaksItalian);//load in the description text
            if (spDescription==NULL)
            {
                // if german isn't found load in english
                scriptSet(NULL, descriptionFile, spDescriptionTweaks);//load in the description text
            }
        }

        if (spDescription != NULL)
        {                                                   //if there was real text in that file
            if (spDescriptionFont == FONT_InvalidFontHandle)
            {                                               //make sure we have a font
                spDescriptionFont = frFontRegister("default.hff");
            }
            textureRect.x0 = atom->x + SCP_TEXTURE_INSET;   //and a region to print into
            textureRect.y0 = atom->y + SCP_TEXTURE_INSET;
            textureRect.x1 = atom->x + atom->width - SCP_TEXTURE_INSET;
            textureRect.y1 = atom->y + atom->height - SCP_TEXTURE_INSET;

            spDescriptionLines = memAlloc(sizeof(char *) * (textureRect.y1 - textureRect.y0), "DescLines", NonVolatile);//allocate the chopping pointers
            chopBuffer = memAlloc(strlen(spDescription) + textureRect.y1 - textureRect.y0, "DescChopped", NonVolatile);//allocate chop buffer
            spNDescriptionLines = subStringsChop(&textureRect, spDescriptionFont, strlen(spDescription), spDescription, chopBuffer, spDescriptionLines);
            memFree(spDescription);                         //free unchopped description
            spDescription = chopBuffer;                     //keep pointer to chopped description
        }
        gameTypeFromDescription = memAlloc(sizeof(GameType), "DescGameType", 0);
        memset(gameTypeFromDescription, 0xff, sizeof(GameType));       //flag all members as unused
        gameTypeFromDescription->flag = gameTypeFromDescription->flagNeeded = 0;    //flag none of the flags needed

        scriptSetStruct(NULL, descriptionFile, StaticMGInfoScriptTable, (ubyte *)gameTypeFromDescription);
    }

    if (strlen(descriptionFile) > 0 || strlen(bitmapFile) > 0)
    {                                                       //if there is a description file or a bitmap
        if (spPickerStarted)
        {
            spScenarioBitmap(atom, (regionhandle)atom->region);//draw it/them
        }
    }
}
Esempio n. 5
0
/*-----------------------------------------------------------------------------
    Name        : tmTechImageDraw
    Description : Loads in, decompresses and draws the tech picture.
    Inputs      : none
    Outputs     : loads in tmTechImage and creates tmTechTexture
    Return      : void
----------------------------------------------------------------------------*/
void tmTechImageDraw(featom *atom, regionhandle region)
{
    char      filename[128];
    sdword    index, lru = 0;
    real32    time=(real32)1.0e22;
    rectangle textureRect;

    tmTechImageRegion = region;

    feStaticRectangleDraw(region); //draw standard rectangle

    if (tmtechinfo != -1)
    {
        if (tmtechinfo != tmCurTechTexture)
        {
            for (index=0;index<TM_TOTALPICS;index++) // RM_TOTALPICS is the size of the cache
            {
                // Find least recently used texture
                if (pictures[index].timestamp < time)
                {
                    time = pictures[index].timestamp;
                    lru  = index;
                }
                // If already cached, use it and exit this routine
                if ( (pictures[index].tech==tmtechinfo) &&
                     (pictures[index].race==universe.curPlayerPtr->race) )
                {
                    tmTechTexturePrepare(index);
                    tmCurTechTexture = tmtechinfo;
                    tmCurTechImage = pictures[lru].techImage;
                    tmCurIndex = index;
                    pictures[index].timestamp = universe.totaltimeelapsed;

                    textureRect.x0=region->rect.x0+TM_TEXTURE_INSET;
                    textureRect.y0=region->rect.y0+TM_TEXTURE_INSET;
                    textureRect.x1=region->rect.x1-TM_TEXTURE_INSET;
                    textureRect.y1=region->rect.y1-TM_TEXTURE_INSET;

                    rndPerspectiveCorrection(FALSE);
                    primRectSolidTextured2(&textureRect);

                    //if(tmExtendedInfoActive)
                    //{
                    //    primRectTranslucent2(&textureRect, colRGBA(0, 0, 0, 128));
                    //    tmTechInfoDraw(region);
                    //}
                    return;
                }
            }

            // Build filename for loading texture from file
            strcpy(filename, TechImagePaths[universe.curPlayerPtr->race]);
            strcat(filename, TechTypeToString(tmtechinfo));
            strcat(filename,".lif");

            // Remove oldest (least recently used) texture from memory
            if (pictures[lru].techImage != NULL)
            {
                memFree(pictures[lru].techImage);
                pictures[lru].techImage = NULL;
            }
            if (pictures[lru].techTexture != TR_InvalidInternalHandle)
            {
                trRGBTextureDelete(pictures[lru].techTexture);
                pictures[lru].techTexture = TR_InvalidInternalHandle;
            }

            // Load the image into LRU cache
            pictures[lru].techImage = trLIFFileLoad(filename, NonVolatile);
            dbgAssertOrIgnore(pictures[lru].techImage->flags & TRF_Paletted);

            tmTechTexturePrepare(lru);
            tmCurTechTexture = tmtechinfo;
            tmCurTechImage = pictures[lru].techImage;
            pictures[lru].tech = tmtechinfo;
            pictures[lru].race = universe.curPlayerPtr->race;
            pictures[lru].timestamp = universe.totaltimeelapsed;
        }
        else
        {
            trPalettedTextureMakeCurrent(pictures[tmCurIndex].techTexture,
                                         pictures[tmCurIndex].techImage->palette);
        }

        textureRect.x0=region->rect.x0+TM_TEXTURE_INSET;
        textureRect.y0=region->rect.y0+TM_TEXTURE_INSET;
        textureRect.x1=region->rect.x1-TM_TEXTURE_INSET;
        textureRect.y1=region->rect.y1-TM_TEXTURE_INSET;

        rndPerspectiveCorrection(FALSE);
        primRectSolidTextured2(&textureRect);
    }
}