Files
Aerofoil/GpApp/InterfaceInit.cpp

260 lines
7.6 KiB
C++
Raw Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// InterfaceInit.c
//----------------------------------------------------------------------------
//============================================================================
#include "Externs.h"
#include "Environ.h"
2020-02-23 20:21:04 -05:00
#include "IGpDisplayDriver.h"
2021-05-11 00:41:35 -04:00
#include "IGpSystemServices.h"
#include "GpApplicationName.h"
2019-11-11 00:11:59 -05:00
#include "Map.h"
#include "MenuManager.h"
2019-11-11 00:11:59 -05:00
#include "RectUtils.h"
2020-09-26 21:15:43 -04:00
#include "ResourceManager.h"
2019-11-11 00:11:59 -05:00
#include "Tools.h"
#include "PLDrivers.h"
#include "PLKeyEncoding.h"
#include "PLPasStr.h"
2019-11-11 00:11:59 -05:00
#define kHandCursorID 128
#define kVertCursorID 129
#define kHoriCursorID 130
#define kDiagCursorID 131
2020-02-23 20:21:04 -05:00
struct IGpCursor;
2019-11-11 00:11:59 -05:00
2019-12-29 23:14:37 -05:00
extern THandle<Rect> mirrorRects;
2019-11-11 00:11:59 -05:00
extern WindowPtr mapWindow, toolsWindow, linkWindow;
2020-04-01 14:53:44 -04:00
extern Rect boardSrcRect, localRoomsDest[];
2020-02-23 20:21:04 -05:00
extern IGpCursor *handCursor, *vertCursor, *horiCursor;
extern IGpCursor *diagCursor;
2021-05-07 02:16:25 -04:00
extern MenuHandle appleMenu, gameMenu, optionsMenu, houseMenu, exportMenu;
2019-11-11 00:11:59 -05:00
extern long incrementModeTime;
extern UInt32 doubleTime;
extern short fadeInSequence[], idleMode;
extern short toolSelected, lastBackground, wasFlower, numExtraHouses;
extern short lastHighScore, maxFiles, willMaxFiles;
2019-11-11 00:11:59 -05:00
extern Boolean quitting, playing, fadeGraysOut;
extern Boolean houseOpen, newRoomNow, evenFrame, menusUp, demoGoing;
extern Boolean twoPlayerGame, paused, hasMirror, splashDrawn;
//============================================================== Functions
//-------------------------------------------------------------- InitializeMenus
// The menus are loaded from disk and the menu bar set up and drawn.
void InitializeMenus (void)
{
2021-05-07 02:16:25 -04:00
PortabilityLayer::MenuManager *mm = PortabilityLayer::MenuManager::GetInstance();
2019-11-11 00:11:59 -05:00
appleMenu = GetMenu(kAppleMenuID);
if (appleMenu == nil)
RedAlert(kErrFailedResourceLoad);
2019-12-21 18:40:17 -05:00
//AppendResMenu(appleMenu, 'DRVR'); // GP: We don't support this
AppendMenuItem(appleMenu, 0, 0, 0, 0, true, false, PSTR("About " GP_APPLICATION_NAME "\xc9"));
2019-11-11 00:11:59 -05:00
InsertMenu(appleMenu, 0);
gameMenu = GetMenu(kGameMenuID);
if (gameMenu == nil)
RedAlert(kErrFailedResourceLoad);
InsertMenu(gameMenu, 0);
optionsMenu = GetMenu(kOptionsMenuID);
if (optionsMenu == nil)
RedAlert(kErrFailedResourceLoad);
InsertMenu(optionsMenu, 0);
if (!thisMac.isTouchscreen)
{
menusUp = true;
2021-05-07 02:16:25 -04:00
mm->SetMenuVisible(true);
}
2019-11-11 00:11:59 -05:00
houseMenu = GetMenu(kHouseMenuID);
if (houseMenu == nil)
RedAlert(kErrFailedResourceLoad);
2021-05-07 02:16:25 -04:00
2021-05-11 00:41:35 -04:00
exportMenu = mm->CreateMenu(PSTR("Import/Export"), kExportMenuID, true, 100, 16, 0);
2021-05-07 02:16:25 -04:00
mm->AppendMenuItem(exportMenu, 0, 0, 0, 0, true, false, PSTR("Export Glider PRO\xaa House..."));
2021-05-11 00:41:35 -04:00
mm->AppendMenuItem(exportMenu, 0, 0, 0, 0, false, false, PSTR("Download House..."));
2019-11-11 00:11:59 -05:00
UpdateMenus(false);
}
//-------------------------------------------------------------- GetExtraCursors
// Extra cursors (custom cursors) like the "hand" and various room<6F>
// editing cursors are loaded up.
2020-09-26 21:15:43 -04:00
IGpCursor *LoadBWCursor(int resID)
{
const THandle<void> resHdl = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('CURS', resID);
if (!resHdl)
return nullptr;
struct BWCursor
{
uint8_t m_pixels[32];
uint8_t m_mask[32];
BEUInt16_t m_hotSpotX;
BEUInt16_t m_hotSpotY;
};
const BWCursor *cursorData = static_cast<const BWCursor *>(*resHdl);
IGpCursor *cursor = PLDrivers::GetDisplayDriver()->CreateBWCursor(16, 16, cursorData->m_pixels, cursorData->m_mask, cursorData->m_hotSpotX, cursorData->m_hotSpotY);
2020-09-26 21:15:43 -04:00
resHdl.Dispose();
return cursor;
}
2019-11-11 00:11:59 -05:00
void GetExtraCursors (void)
{
2020-09-26 21:15:43 -04:00
struct BWCursor
{
uint8_t m_pixels[32];
uint8_t m_mask[32];
BEUInt16_t m_hotSpotX;
BEUInt16_t m_hotSpotY;
};
handCursor = LoadBWCursor(kHandCursorID);
2020-02-23 20:21:04 -05:00
if (handCursor == nil)
2019-11-11 00:11:59 -05:00
RedAlert(kErrFailedResourceLoad);
2020-09-26 21:15:43 -04:00
vertCursor = LoadBWCursor(kVertCursorID);
2020-02-23 20:21:04 -05:00
if (vertCursor == nil)
2019-11-11 00:11:59 -05:00
RedAlert(kErrFailedResourceLoad);
2020-09-26 21:15:43 -04:00
horiCursor = LoadBWCursor(kHoriCursorID);
2020-02-23 20:21:04 -05:00
if (horiCursor == nil)
2019-11-11 00:11:59 -05:00
RedAlert(kErrFailedResourceLoad);
2020-09-26 21:15:43 -04:00
diagCursor = LoadBWCursor(kDiagCursorID);
2020-02-23 20:21:04 -05:00
if (diagCursor == nil)
2019-11-11 00:11:59 -05:00
RedAlert(kErrFailedResourceLoad);
}
2020-04-01 14:53:44 -04:00
//-------------------------------------------------------------- RecomputeScreenRects
void RecomputeInterfaceRects (void)
{
houseRect = thisMac.constrainedScreen;
2020-04-01 14:53:44 -04:00
houseRect.bottom -= kScoreboardTall;
if (houseRect.right > kMaxViewWidth)
houseRect.right = kMaxViewWidth;
if (houseRect.bottom > kMaxViewHeight)
houseRect.bottom = kMaxViewHeight;
// NOTE: This is actually buggy, since the visible area is houseRect, not screen.
// We preserve the buggy behavior for authenticity unless the window is very tall.
short poHeight = RectTall(&thisMac.constrainedScreen);
if (poHeight > kMaxViewHeight - kScoreboardTall)
poHeight = kMaxViewHeight - kScoreboardTall;
playOriginH = (RectWide(&thisMac.constrainedScreen) - kRoomWide) / 2;
playOriginV = (poHeight - kTileHigh) / 2;
2020-04-01 14:53:44 -04:00
for (int i = 0; i < 9; i++)
{
QSetRect(&localRoomsDest[i], 0, 0, kRoomWide, kTileHigh);
QOffsetRect(&localRoomsDest[i], playOriginH, playOriginV);
}
QOffsetRect(&localRoomsDest[kNorthRoom], 0, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kNorthEastRoom], kRoomWide, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kEastRoom], kRoomWide, 0);
QOffsetRect(&localRoomsDest[kSouthEastRoom], kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthRoom], 0, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthWestRoom], -kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kWestRoom], -kRoomWide, 0);
QOffsetRect(&localRoomsDest[kNorthWestRoom], -kRoomWide, -kVertLocalOffset);
}
2019-11-11 00:11:59 -05:00
//-------------------------------------------------------------- VariableInit
// All the simple interface variables are intialized here - Booleans,<2C>
// shorts, a few Rects, etc.
void VariableInit (void)
{
menusUp = false;
quitting = false;
houseOpen = false;
newRoomNow = false;
playing = false;
evenFrame = false;
if (thisMac.isDepth == 8)
fadeGraysOut = true;
else
fadeGraysOut = false;
twoPlayerGame = false;
paused = false;
hasMirror = false;
demoGoing = false;
2020-07-03 04:59:40 -04:00
scrapIsARoom = true;
2019-11-11 00:11:59 -05:00
splashDrawn = false;
#ifndef COMPILEDEMO
// SeeIfValidScrapAvailable(false);
#endif
theGlider.which = kPlayer1;
2019-12-25 22:20:10 -05:00
theGlider2.leftKey = PL_KEY_ASCII('A');
theGlider2.rightKey = PL_KEY_ASCII('D');
theGlider2.battKey = PL_KEY_ASCII('S');
theGlider2.bandKey = PL_KEY_ASCII('W');
2019-12-29 17:39:19 -05:00
theGlider2.gamepadLeftKey = PL_KEY_GAMEPAD_BUTTON(kDPadLeft, 1);
theGlider2.gamepadRightKey = PL_KEY_GAMEPAD_BUTTON(kDPadRight, 1);
theGlider2.gamepadBandKey = PL_KEY_GAMEPAD_BUTTON(kFaceDown, 1);
theGlider2.gamepadBattKey = PL_KEY_GAMEPAD_BUTTON(kFaceLeft, 1);
2019-11-11 00:11:59 -05:00
theGlider2.which = kPlayer2;
theMode = kSplashMode;
thisRoomNumber = 0;
previousRoom = -1;
toolSelected = kSelectTool;
lastBackground = kBaseBackgroundID;
wasFlower = RandomInt(kNumFlowers);
lastHighScore = -1;
idleMode = kIdleSplashMode;
incrementModeTime = TickCount() + kIdleSplashTicks;
willMaxFiles = maxFiles;
numExtraHouses = 0;
fadeInSequence[0] = 4; // 4
fadeInSequence[1] = 5;
fadeInSequence[2] = 6;
fadeInSequence[3] = 7;
fadeInSequence[4] = 5; // 5
fadeInSequence[5] = 6;
fadeInSequence[6] = 7;
fadeInSequence[7] = 8;
fadeInSequence[8] = 6; // 6
fadeInSequence[9] = 7;
fadeInSequence[10] = 8;
fadeInSequence[11] = 9;
fadeInSequence[12] = 7; // 7
fadeInSequence[13] = 8;
fadeInSequence[14] = 9;
fadeInSequence[15] = 10;
doubleTime = 30; // PL_NotYetImplemented_TODO: Get this from the system settings
2019-11-11 00:11:59 -05:00
mirrorRects = nil;
2019-11-11 00:11:59 -05:00
mainWindow = nil;
2019-12-27 00:30:31 -05:00
boardWindow = nil;
2019-11-11 00:11:59 -05:00
mapWindow = nil;
toolsWindow = nil;
linkWindow = nil;
coordWindow = nil;
toolSrcMap = nil;
nailSrcMap = nil;
2020-04-01 14:53:44 -04:00
RecomputeInterfaceRects();
2019-11-11 00:11:59 -05:00
}