Files
Aerofoil/GpApp/Banner.cpp

230 lines
6.2 KiB
C++
Raw Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// Banner.c
//----------------------------------------------------------------------------
//============================================================================
#include "PLNumberFormatting.h"
#include "PLPasStr.h"
2019-12-30 20:53:11 -05:00
#include "PLStandardColors.h"
2019-11-11 00:11:59 -05:00
#include "Externs.h"
#include "Environ.h"
2019-12-30 20:53:11 -05:00
#include "FontFamily.h"
#include "FontManager.h"
2019-11-11 00:11:59 -05:00
#include "MainWindow.h"
#include "RectUtils.h"
#include "Room.h"
#include "Utilities.h"
#define kBannerPageTopPICT 1993
#define kBannerPageBottomPICT 1992
#define kBannerPageBottomMask 1991
#define kStarsRemainingPICT 1017
#define kStarRemainingPICT 1018
void DrawBanner (Point *);
void DrawBannerMessage (Point);
short numStarsRemaining;
Boolean bannerStarCountOn;
extern Rect justRoomsRect;
extern Boolean quickerTransitions, demoGoing, isUseSecondScreen;
//============================================================== Functions
//-------------------------------------------------------------- DrawBanner
// Displays opening banner (when a new game is begun). The banner looks<6B>
// like a sheet of notebook paper. The text printed on it is specified<65>
// by the author of the house.
void DrawBanner (Point *topLeft)
{
Rect wholePage, partPage, mapBounds;
2019-12-30 20:53:11 -05:00
DrawSurface *tempMap;
DrawSurface *tempMask;
PLError_t theErr;
2019-11-11 00:11:59 -05:00
QSetRect(&wholePage, 0, 0, 330, 220);
mapBounds = thisMac.screen;
ZeroRectCorner(&mapBounds);
CenterRectInRect(&wholePage, &mapBounds);
topLeft->h = wholePage.left;
topLeft->v = wholePage.top;
partPage = wholePage;
partPage.bottom = partPage.top + 190;
2019-12-30 20:53:11 -05:00
LoadScaledGraphic(workSrcMap, kBannerPageTopPICT, &partPage);
2019-11-11 00:11:59 -05:00
partPage = wholePage;
partPage.top = partPage.bottom - 30;
mapBounds = partPage;
ZeroRectCorner(&mapBounds);
2019-12-29 06:38:18 -05:00
theErr = CreateOffScreenGWorld(&tempMap, &mapBounds, kPreferredPixelFormat);
2019-12-30 20:53:11 -05:00
LoadGraphic(tempMap, kBannerPageBottomPICT);
2019-11-11 00:11:59 -05:00
2019-12-29 06:38:18 -05:00
theErr = CreateOffScreenGWorld(&tempMask, &mapBounds, GpPixelFormats::kBW1);
2019-12-30 20:53:11 -05:00
LoadGraphic(tempMask, kBannerPageBottomMask);
2019-11-11 00:11:59 -05:00
CopyMask((BitMap *)*GetGWorldPixMap(tempMap),
(BitMap *)*GetGWorldPixMap(tempMask),
(BitMap *)*GetGWorldPixMap(workSrcMap),
&mapBounds, &mapBounds, &partPage);
2019-11-11 00:11:59 -05:00
DisposeGWorld(tempMap);
DisposeGWorld(tempMask);
}
//-------------------------------------------------------------- CountStarsInHouse
// Goes through the current house and counts the total number of stars within.
short CountStarsInHouse (void)
{
short i, h, numRooms, numStars;
numStars = 0;
numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++)
{
if ((*thisHouse)->rooms[i].suite != kRoomIsEmpty)
for (h = 0; h < kMaxRoomObs; h++)
{
if ((*thisHouse)->rooms[i].objects[h].what == kStar)
numStars++;
}
}
return (numStars);
}
//-------------------------------------------------------------- DrawBannerMessage
// This function prints the author's message acorss the notebook paper banner.
void DrawBannerMessage (Point topLeft)
{
Str255 bannerStr, subStr;
short count;
2019-12-27 14:16:42 -05:00
2019-12-30 20:53:11 -05:00
DrawSurface *wasGWorld = GetGraphicsPort();
2019-12-27 14:16:42 -05:00
2019-12-27 18:05:32 -05:00
SetGraphicsPort(workSrcMap);
2019-12-27 14:16:42 -05:00
2019-11-11 00:11:59 -05:00
PasStringCopy((*thisHouse)->banner, bannerStr);
2019-12-30 20:53:11 -05:00
workSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
workSrcMap->SetForeColor(StdColors::Black());
2019-11-11 00:11:59 -05:00
count = 0;
do
{
GetLineOfText(bannerStr, count, subStr);
2019-12-30 20:53:11 -05:00
workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 32 + (count * 20)), subStr);
2019-11-11 00:11:59 -05:00
count++;
}
while (subStr[0] > 0);
if (bannerStarCountOn)
{
if (numStarsRemaining != 1)
GetLocalizedString(1, bannerStr);
else
GetLocalizedString(2, bannerStr);
NumToString((long)numStarsRemaining, subStr);
PasStringConcat(bannerStr, subStr);
if (numStarsRemaining != 1)
GetLocalizedString(3, subStr);
else
GetLocalizedString(4, subStr);
PasStringConcat(bannerStr, subStr);
2019-12-30 20:53:11 -05:00
workSrcMap->SetForeColor(StdColors::Red());
workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 164), bannerStr);
2019-11-11 00:11:59 -05:00
GetLocalizedString(5, subStr);
2019-12-30 20:53:11 -05:00
workSrcMap->DrawString(Point::Create(topLeft.h + 16, topLeft.v + 180), subStr);
2019-11-11 00:11:59 -05:00
}
2019-12-30 20:53:11 -05:00
workSrcMap->SetForeColor(StdColors::Black());
2019-12-27 14:16:42 -05:00
2019-12-27 18:05:32 -05:00
SetGraphicsPort(wasGWorld);
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- BringUpBanner
// Handles bringing up displaying and disposing of the banner.
void BringUpBanner (void)
{
Rect wholePage;
Point topLeft;
DrawBanner(&topLeft);
DrawBannerMessage(topLeft);
DumpScreenOn(&justRoomsRect);
2019-11-11 00:11:59 -05:00
// if (quickerTransitions)
// DissBitsChunky(&justRoomsRect); // was workSrcRect
// else
// DissBits(&justRoomsRect);
QSetRect(&wholePage, 0, 0, 330, 220);
QOffsetRect(&wholePage, topLeft.h, topLeft.v);
CopyBits((BitMap *)*GetGWorldPixMap(backSrcMap),
(BitMap *)*GetGWorldPixMap(workSrcMap),
&wholePage, &wholePage, srcCopy);
2019-11-11 00:11:59 -05:00
if (demoGoing)
WaitForInputEvent(4);
else
WaitForInputEvent(15);
// if (quickerTransitions)
// DissBitsChunky(&justRoomsRect);
// else
// DissBits(&justRoomsRect);
}
//-------------------------------------------------------------- DisplayStarsRemaining
// This brings up a small message indicating the number of stars remaining<6E>
// in a house. It comes up when the player gets a star (the game is paused<65>
// and the user informed as to how many remain).
void DisplayStarsRemaining (void)
{
Rect src, bounds;
Str255 theStr;
2019-12-30 20:53:11 -05:00
DrawSurface *surface = mainWindow->GetDrawSurface();
2019-11-11 00:11:59 -05:00
QSetRect(&bounds, 0, 0, 256, 64);
CenterRectInRect(&bounds, &thisMac.screen);
QOffsetRect(&bounds, -thisMac.screen.left, -thisMac.screen.top);
src = bounds;
InsetRect(&src, 64, 32);
2019-12-30 20:53:11 -05:00
surface->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
2019-11-11 00:11:59 -05:00
NumToString((long)numStarsRemaining, theStr);
QOffsetRect(&bounds, 0, -20);
if (numStarsRemaining < 2)
2019-12-30 20:53:11 -05:00
LoadScaledGraphic(surface, kStarRemainingPICT, &bounds);
2019-11-11 00:11:59 -05:00
else
{
2019-12-30 20:53:11 -05:00
LoadScaledGraphic(surface, kStarsRemainingPICT, &bounds);
const Point textPoint = Point::Create(bounds.left + 102 - (surface->MeasureString(theStr) / 2), bounds.top + 23);
2019-12-30 20:53:11 -05:00
ColorText(surface, textPoint, theStr, 4L);
2019-11-11 00:11:59 -05:00
}
DelayTicks(60);
if (WaitForInputEvent(30))
RestoreEntireGameScreen();
CopyRectWorkToMain(&bounds);
}