Files
Aerofoil/GpApp/RoomInfo.cpp

886 lines
24 KiB
C++
Raw Permalink Normal View History

2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// RoomInfo.c
//----------------------------------------------------------------------------
//============================================================================
2019-12-30 20:53:11 -05:00
#include "DialogManager.h"
2019-11-11 00:11:59 -05:00
#include "DialogUtils.h"
#include "Externs.h"
2020-02-23 20:21:04 -05:00
#include "IGpDisplayDriver.h"
2019-11-11 00:11:59 -05:00
#include "RectUtils.h"
2020-03-01 17:01:35 -05:00
#include "PLPopupMenuWidget.h"
2020-02-23 20:21:04 -05:00
#include "PLTimeTaggedVOSEvent.h"
#include "QDPixMap.h"
2020-05-21 03:30:11 -04:00
#include "ResolveCachingColor.h"
2019-12-29 22:12:11 -05:00
#include "ResourceCompiledRef.h"
#include "ResourceManager.h"
2019-11-11 00:11:59 -05:00
#include "Utilities.h"
#include "PLDrivers.h"
#include "PLKeyEncoding.h"
#include "PLNumberFormatting.h"
#include "PLResources.h"
#include "PLSound.h"
#include "PLPasStr.h"
#include "PLStandardColors.h"
2019-11-11 00:11:59 -05:00
#define kRoomInfoDialogID 1003
#define kOriginalArtDialogID 1016
#define kNoPICTFoundAlert 1036
#define kRoomNameItem 3
#define kRoomLocationBox 6
#define kRoomTilesBox 10
#define kRoomPopupItem 11
#define kRoomDividerLine 12
#define kRoomTilesBox2 15
#define kRoomFirstCheck 17
#define kLitUnlitText 18
#define kMiniTileWide 16
#define kBoundsButton 19
#define kOriginalArtworkItem 19
#define kPICTIDItem 5
#define kFloorSupportCheck 12
2019-12-31 02:42:20 -05:00
void UpdateRoomInfoDialog (Dialog *);
void DragMiniTile (Window *, DrawSurface *, Point, short *);
2019-12-30 20:53:11 -05:00
void HiliteTileOver (DrawSurface *, Point);
2020-09-12 22:29:57 -04:00
int16_t RoomFilter (void *context, Dialog *dialog, const TimeTaggedVOSEvent *evt);
2020-02-23 20:21:04 -05:00
2019-11-11 00:11:59 -05:00
short ChooseOriginalArt (short);
2019-12-31 02:42:20 -05:00
void UpdateOriginalArt (Dialog *);
2020-09-12 22:29:57 -04:00
int16_t OriginalArtFilter (void *context, Dialog *dialog, const TimeTaggedVOSEvent *evt);
2019-11-11 00:11:59 -05:00
Boolean PictIDExists (short);
short GetFirstPICT (void);
void ComplainAboutPICTNotFound (void);
2019-11-11 00:11:59 -05:00
Rect tileSrc, tileDest, tileSrcRect, editTETextBox;
Rect leftBound, topBound, rightBound, bottomBound;
2019-12-30 20:53:11 -05:00
DrawSurface *tileSrcMap;
2019-11-11 00:11:59 -05:00
short tempTiles[kNumTiles];
short tileOver, tempBack, cursorIs;
Boolean originalLeftOpen, originalTopOpen, originalRightOpen, originalBottomOpen;
Boolean originalFloor;
2020-02-23 20:21:04 -05:00
extern IGpCursor *handCursor;
extern short lastBackground;
2019-11-11 00:11:59 -05:00
extern PortabilityLayer::IResourceArchive *houseResFork;
2020-03-01 17:01:35 -05:00
2019-11-11 00:11:59 -05:00
//============================================================== Functions
//-------------------------------------------------------------- UpdateRoomInfoDialog
#ifndef COMPILEDEMO
2019-12-31 02:42:20 -05:00
void UpdateRoomInfoDialog (Dialog *theDialog)
2019-11-11 00:11:59 -05:00
{
Rect src, dest;
short i;
if (tempBack >= kUserBackground)
SetPopUpMenuValue(theDialog, kRoomPopupItem, kOriginalArtworkItem);
else
SetPopUpMenuValue(theDialog, kRoomPopupItem,
(tempBack - kBaseBackgroundID) + 1);
CopyBits(GetPortBitMapForCopyBits(tileSrcMap),
2020-02-23 20:21:04 -05:00
GetPortBitMapForCopyBits(theDialog->GetWindow()->GetDrawSurface()),
&tileSrcRect, &tileSrc, srcCopy);
2019-11-11 00:11:59 -05:00
/*
CopyBits(&((GrafPtr)tileSrcMap)->portBits,
&(((GrafPtr)theDialog)->portBits),
&tileSrcRect, &tileSrc, srcCopy, nil);
*/
dest = tileDest;
dest.right = dest.left + kMiniTileWide;
for (i = 0; i < kNumTiles; i++)
{
QSetRect(&src, 0, 0, kMiniTileWide, 80);
QOffsetRect(&src, tempTiles[i] * kMiniTileWide, 0);
CopyBits(GetPortBitMapForCopyBits(tileSrcMap),
2020-02-23 20:21:04 -05:00
GetPortBitMapForCopyBits(theDialog->GetWindow()->GetDrawSurface()),
&src, &dest, srcCopy);
2019-11-11 00:11:59 -05:00
/*
CopyBits(&((GrafPtr)tileSrcMap)->portBits,
&(((GrafPtr)theDialog)->portBits),
&src, &dest, srcCopy, nil);
*/
QOffsetRect(&dest, kMiniTileWide, 0);
}
if (GetNumberOfLights(thisRoomNumber) == 0)
SetDialogString(theDialog, kLitUnlitText, PSTR("(Room Is Dark)"));
else
SetDialogString(theDialog, kLitUnlitText, PSTR("(Room Is Lit)"));
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor blackColor = StdColors::Black();
2019-11-11 00:11:59 -05:00
FrameDialogItemC(theDialog, kRoomLocationBox, kRedOrangeColor8);
2020-05-21 03:30:11 -04:00
FrameDialogItem(theDialog, kRoomTilesBox, blackColor);
2019-11-11 00:11:59 -05:00
FrameDialogItemC(theDialog, kRoomDividerLine, kRedOrangeColor8);
2020-05-21 03:30:11 -04:00
FrameDialogItem(theDialog, kRoomTilesBox2, blackColor);
2019-11-11 00:11:59 -05:00
}
#endif
//-------------------------------------------------------------- DragMiniTile
#ifndef COMPILEDEMO
void DragMiniTile (Window *window, DrawSurface *surface, Point mouseIs, short *newTileOver)
2019-11-11 00:11:59 -05:00
{
Rect dragRect;
Point mouseWas;
short wasTileOver;
Pattern dummyPattern;
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
PortabilityLayer::ResolveCachingColor blueColor = StdColors::Blue();
2019-11-11 00:11:59 -05:00
tileOver = (mouseIs.h - tileSrc.left) / kMiniTileWide;
wasTileOver = -1;
QSetRect(&dragRect, 0, 0, kMiniTileWide, 80);
QOffsetRect(&dragRect,
tileSrc.left + (tileOver * kMiniTileWide),
tileSrc.top);
2019-12-30 20:53:11 -05:00
const uint8_t *pattern = *GetQDGlobalsGray(&dummyPattern);
surface->InvertFrameRect(dragRect, pattern);
2019-11-11 00:11:59 -05:00
mouseWas = mouseIs;
2021-04-19 01:02:10 -04:00
while (WaitMouseUp_DisarmAsyncify()) // loop until mouse button let up
2019-11-11 00:11:59 -05:00
{
2021-04-19 01:02:10 -04:00
GetMouse(window, &mouseIs); // get mouse coords
if (mouseWas != mouseIs) // the mouse has moved
2019-11-11 00:11:59 -05:00
{
2019-12-30 20:53:11 -05:00
surface->InvertFrameRect(dragRect, pattern);
2019-11-11 00:11:59 -05:00
QOffsetRect(&dragRect, mouseIs.h - mouseWas.h, 0);
2019-12-30 20:53:11 -05:00
surface->InvertFrameRect(dragRect, pattern);
2020-02-18 20:53:54 -05:00
if (tileDest.Contains(mouseIs)) // is cursor in the drop rect
2019-11-11 00:11:59 -05:00
{
*newTileOver = (mouseIs.h - tileDest.left) / kMiniTileWide;
if (*newTileOver != wasTileOver)
{
2019-12-30 20:53:11 -05:00
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (*newTileOver * kMiniTileWide), tileDest.top - 3 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, blueColor);
2019-12-30 20:53:11 -05:00
}
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (*newTileOver * kMiniTileWide), tileDest.bottom + 1 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, blueColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
if (wasTileOver != -1)
{
2019-12-30 20:53:11 -05:00
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
}
2019-12-30 20:53:11 -05:00
2019-11-11 00:11:59 -05:00
wasTileOver = *newTileOver;
}
}
else
{
*newTileOver = -1; // we're not in the drop zone
if (wasTileOver != -1)
{
2019-12-30 20:53:11 -05:00
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
wasTileOver = -1;
}
}
mouseWas = mouseIs;
}
}
if (wasTileOver != -1)
{
2019-12-30 20:53:11 -05:00
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.top - 3 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
for (int offset = 0; offset < 2; offset++)
{
Point pointA = Point::Create(tileDest.left + (wasTileOver * kMiniTileWide), tileDest.bottom + 1 + offset);
Point pointB = Point::Create(pointA.h + kMiniTileWide, pointA.v);
2020-05-21 03:30:11 -04:00
surface->DrawLine(pointA, pointB, whiteColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
wasTileOver = -1;
}
2019-12-30 20:53:11 -05:00
surface->InvertFrameRect(dragRect, pattern);
2019-11-11 00:11:59 -05:00
}
#endif
//-------------------------------------------------------------- HiliteTileOver
#ifndef COMPILEDEMO
2019-12-30 20:53:11 -05:00
void HiliteTileOver (DrawSurface *surface, Point mouseIs)
2019-11-11 00:11:59 -05:00
{
short newTileOver;
2020-05-21 03:30:11 -04:00
PortabilityLayer::ResolveCachingColor whiteColor = StdColors::White();
PortabilityLayer::ResolveCachingColor redColor = StdColors::Red();
2019-11-11 00:11:59 -05:00
2020-02-18 20:53:54 -05:00
if (tileSrc.Contains(mouseIs))
2019-11-11 00:11:59 -05:00
{
if (cursorIs != kHandCursor)
{
PLDrivers::GetDisplayDriver()->SetCursor(handCursor);
2019-11-11 00:11:59 -05:00
cursorIs = kHandCursor;
}
newTileOver = (mouseIs.h - tileSrc.left) / kMiniTileWide;
if (newTileOver != tileOver)
{
2019-12-30 20:53:11 -05:00
{
const Point tileLineTopLeft = Point::Create(tileSrc.left + (newTileOver * kMiniTileWide), tileSrc.top - 3);
const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2);
2020-05-21 03:30:11 -04:00
surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), redColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
if (tileOver != -1)
{
2019-12-30 20:53:11 -05:00
{
const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.top - 3);
const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2);
2020-05-21 03:30:11 -04:00
surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor);
2019-12-30 20:53:11 -05:00
}
{
const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.bottom + 1);
const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2);
2020-05-21 03:30:11 -04:00
surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
}
2019-12-30 20:53:11 -05:00
2019-11-11 00:11:59 -05:00
tileOver = newTileOver;
}
}
else
{
if (tileOver != -1)
{
2019-12-30 20:53:11 -05:00
{
const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.top - 3);
const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2);
2020-05-21 03:30:11 -04:00
surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor);
2019-12-30 20:53:11 -05:00
}
{
const Point tileLineTopLeft = Point::Create(tileSrc.left + (tileOver * kMiniTileWide), tileSrc.bottom + 1);
const Point tileLineBottomRight = Point::Create(tileLineTopLeft.h + kMiniTileWide + 1, tileLineTopLeft.v + 2);
2020-05-21 03:30:11 -04:00
surface->FillRect(Rect::Create(tileLineTopLeft.v, tileLineTopLeft.h, tileLineBottomRight.v, tileLineBottomRight.h), whiteColor);
2019-12-30 20:53:11 -05:00
}
2019-11-11 00:11:59 -05:00
tileOver = -1;
}
2020-02-18 20:53:54 -05:00
if (editTETextBox.Contains(mouseIs))
2019-11-11 00:11:59 -05:00
{
if (cursorIs != kBeamCursor)
{
PLDrivers::GetDisplayDriver()->SetStandardCursor(EGpStandardCursors::kIBeam);
2019-11-11 00:11:59 -05:00
cursorIs = kBeamCursor;
}
}
else
{
if (cursorIs != kArrowCursor)
{
InitCursor();
cursorIs = kArrowCursor;
}
}
}
}
#endif
//-------------------------------------------------------------- RoomFilter
#ifndef COMPILEDEMO
2020-09-12 22:29:57 -04:00
int16_t RoomFilter(void *context, Dialog *dial, const TimeTaggedVOSEvent *evt)
2019-11-11 00:11:59 -05:00
{
Point mouseIs;
short newTileOver;
2019-12-30 20:53:11 -05:00
2020-02-23 20:21:04 -05:00
if (!evt)
return -1;
Window *window = dial->GetWindow();
2019-12-30 20:53:11 -05:00
DrawSurface *surface = dial->GetWindow()->GetDrawSurface();
2020-02-23 20:21:04 -05:00
if (evt->IsKeyDownEvent())
2019-11-11 00:11:59 -05:00
{
2020-02-23 20:21:04 -05:00
switch (PackVOSKeyCode(evt->m_vosEvent.m_event.m_keyboardInputEvent))
2019-11-11 00:11:59 -05:00
{
2020-02-23 20:21:04 -05:00
case PL_KEY_SPECIAL(kEnter):
case PL_KEY_NUMPAD_SPECIAL(kEnter):
2019-11-11 00:11:59 -05:00
FlashDialogButton(dial, kOkayButton);
2020-02-23 20:21:04 -05:00
return kOkayButton;
2019-12-25 22:20:10 -05:00
2020-02-23 20:21:04 -05:00
case PL_KEY_SPECIAL(kEscape):
2019-11-11 00:11:59 -05:00
FlashDialogButton(dial, kCancelButton);
2020-02-23 20:21:04 -05:00
return kCancelButton;
2019-12-25 22:20:10 -05:00
2020-02-23 20:21:04 -05:00
case PL_KEY_SPECIAL(kTab):
2019-11-11 00:11:59 -05:00
SelectDialogItemText(dial, kRoomNameItem, 0, 1024);
2020-02-23 20:21:04 -05:00
return 0;
default:
return -1;
2019-11-11 00:11:59 -05:00
}
2020-02-23 20:21:04 -05:00
}
else if (evt->m_vosEvent.m_eventType == GpVOSEventTypes::kMouseInput)
{
const GpMouseInputEvent &mouseEvent = evt->m_vosEvent.m_event.m_mouseInputEvent;
if (evt->IsLMouseDownEvent())
2019-11-11 00:11:59 -05:00
{
2020-02-23 20:21:04 -05:00
mouseIs = Point::Create(mouseEvent.m_x, mouseEvent.m_y);
2020-05-20 17:20:50 -04:00
mouseIs -= dial->GetWindow()->GetTopLeftCoord();
2020-02-23 20:21:04 -05:00
if (tileSrc.Contains(mouseIs))
2019-11-11 00:11:59 -05:00
{
2020-02-23 20:21:04 -05:00
if (StillDown())
2019-11-11 00:11:59 -05:00
{
DragMiniTile(window, surface, mouseIs, &newTileOver);
2020-02-23 20:21:04 -05:00
if ((newTileOver >= 0) && (newTileOver < kNumTiles))
{
tempTiles[newTileOver] = tileOver;
UpdateRoomInfoDialog(dial);
}
2019-11-11 00:11:59 -05:00
}
2020-02-23 20:21:04 -05:00
return 0;
2019-11-11 00:11:59 -05:00
}
2020-02-23 20:21:04 -05:00
else
return -1;
}
else if (mouseEvent.m_eventType == GpMouseEventTypes::kMove)
{
mouseIs = dial->GetWindow()->MouseToLocal(mouseEvent);
HiliteTileOver(surface, mouseIs);
2020-03-09 01:40:34 -04:00
return -1;
2019-11-11 00:11:59 -05:00
}
}
2020-03-09 01:40:34 -04:00
return -1;
2019-11-11 00:11:59 -05:00
}
#endif
//-------------------------------------------------------------- DoRoomInfo
2020-03-01 17:01:35 -05:00
void DoRoomInfo(void)
2019-11-11 00:11:59 -05:00
{
#ifndef COMPILEDEMO
2020-03-01 17:01:35 -05:00
#define kBackgroundsMenuID 140
2019-12-31 02:42:20 -05:00
Dialog *roomInfoDialog;
2019-11-11 00:11:59 -05:00
Str255 floorStr, suiteStr, objectsStr, tempStr;
short item, i, newBack;
char wasState;
Boolean leaving, wasFirstRoom, forceDraw;
2019-12-29 06:38:18 -05:00
PLError_t theErr;
2020-03-01 17:01:35 -05:00
2019-11-11 00:11:59 -05:00
tileOver = -1;
cursorIs = kArrowCursor;
tempBack = thisRoom->background;
2020-03-01 17:01:35 -05:00
// SetMenuItemTextStyle(backgroundsMenu, kOriginalArtworkItem, italic);
2019-11-11 00:11:59 -05:00
NumToString(thisRoom->floor, floorStr);
NumToString(thisRoom->suite, suiteStr);
NumToString(thisRoom->numObjects, objectsStr);
DialogTextSubstitutions substitutions(floorStr, suiteStr, objectsStr);
2020-03-01 17:01:35 -05:00
2020-06-13 04:33:41 -04:00
theErr = CreateOffScreenGWorld(&tileSrcMap, &tileSrcRect);
2020-03-01 17:01:35 -05:00
// CreateOffScreenPixMap(&tileSrcRect, &tileSrcMap);
// SetPort((GrafPtr)tileSrcMap);
2019-11-11 00:11:59 -05:00
if ((tempBack > kStars) && (!PictIDExists(tempBack)))
{
ComplainAboutPICTNotFound();
2019-11-11 00:11:59 -05:00
tempBack = kSimpleRoom;
}
2020-03-01 17:01:35 -05:00
if ((tempBack == 2002) || (tempBack == 2011) ||
(tempBack == 2016) || (tempBack == 2017))
LoadScaledGraphicCustom(tileSrcMap, tempBack - 800, &tileSrcRect);
2019-11-11 00:11:59 -05:00
else
LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect);
2020-03-01 17:01:35 -05:00
2019-11-11 00:11:59 -05:00
for (i = 0; i < kNumTiles; i++)
tempTiles[i] = thisRoom->tiles[i];
2020-03-01 17:01:35 -05:00
// CenterDialog(kRoomInfoDialogID);
roomInfoDialog = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kRoomInfoDialogID, kPutInFront, &substitutions);
2019-11-11 00:11:59 -05:00
if (roomInfoDialog == nil)
RedAlert(kErrDialogDidntLoad);
2020-03-01 17:01:35 -05:00
{
PortabilityLayer::WidgetBasicState state;
GetDialogItemRect(roomInfoDialog, kRoomPopupItem, &state.m_rect);
state.m_resID = kBackgroundsMenuID;
state.m_enabled = true;
2020-05-18 02:03:17 -04:00
PortabilityLayer::PopupMenuWidget *roomPopupWidget = PortabilityLayer::PopupMenuWidget::Create(state, nullptr);
2020-03-01 17:01:35 -05:00
roomInfoDialog->ReplaceWidget(kRoomPopupItem - 1, roomPopupWidget);
if (HouseHasOriginalPicts())
EnableMenuItem(roomPopupWidget->GetMenu(), kOriginalArtworkItem);
}
2019-11-11 00:11:59 -05:00
if (tempBack >= kUserBackground)
SetPopUpMenuValue(roomInfoDialog, kRoomPopupItem, kOriginalArtworkItem);
else
SetPopUpMenuValue(roomInfoDialog, kRoomPopupItem,
(tempBack - kBaseBackgroundID) + 1);
SetDialogString(roomInfoDialog, kRoomNameItem, thisRoom->name);
GetDialogItemRect(roomInfoDialog, kRoomTilesBox, &tileSrc);
GetDialogItemRect(roomInfoDialog, kRoomTilesBox2, &tileDest);
GetDialogItemRect(roomInfoDialog, kRoomNameItem, &editTETextBox);
SelectDialogItemText(roomInfoDialog, kRoomNameItem, 0, 1024);
2019-12-30 20:53:11 -05:00
ShowWindow(roomInfoDialog->GetWindow());
2019-11-11 00:11:59 -05:00
DrawDefaultButton(roomInfoDialog);
wasFirstRoom = ((*thisHouse)->firstRoom == thisRoomNumber);
SetDialogItemValue(roomInfoDialog, kRoomFirstCheck, (short)wasFirstRoom);
if (tempBack >= kUserBackground)
MyEnableControl(roomInfoDialog, kBoundsButton);
else
MyDisableControl(roomInfoDialog, kBoundsButton);
leaving = false;
2020-02-23 20:21:04 -05:00
UpdateRoomInfoDialog(roomInfoDialog);
2019-11-11 00:11:59 -05:00
while (!leaving)
{
2020-03-01 17:01:35 -05:00
bool needRedraw = false;
2021-03-29 21:41:11 -04:00
item = roomInfoDialog->ExecuteModal(nullptr, PL_FILTER_FUNC(RoomFilter));
2019-11-11 00:11:59 -05:00
if (item == kOkayButton)
{
for (i = 0; i < kNumTiles; i++)
thisRoom->tiles[i] = tempTiles[i];
GetDialogString(roomInfoDialog, kRoomNameItem, tempStr);
PasStringCopyNum(tempStr, thisRoom->name, 27);
if (wasFirstRoom)
{
(*thisHouse)->firstRoom = thisRoomNumber;
}
thisRoom->background = tempBack;
if (tempBack < kUserBackground)
lastBackground = tempBack;
CopyThisRoomToRoom();
ReflectCurrentRoom(false);
fileDirty = true;
UpdateMenus(false);
leaving = true;
}
else if (item == kCancelButton)
{
leaving = true;
}
else if (item == kRoomFirstCheck)
{
wasFirstRoom = !wasFirstRoom;
SetDialogItemValue(roomInfoDialog, kRoomFirstCheck, (short)wasFirstRoom);
}
else if (item == kRoomPopupItem)
{
GetPopUpMenuValue(roomInfoDialog, kRoomPopupItem, &newBack);
if (newBack == kOriginalArtworkItem) // original art item selected?
{
if (tempBack < kUserBackground) // was previous bg built-in?
{
tempBack = GetFirstPICT(); // then assign 1st PICT
forceDraw = true;
}
else
forceDraw = false;
newBack = ChooseOriginalArt(tempBack); // bring up dialog
if ((tempBack != newBack) || (forceDraw))
{
tempBack = newBack;
LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect);
2020-03-01 17:01:35 -05:00
needRedraw = true;
2019-11-11 00:11:59 -05:00
}
}
else
{
newBack += (kBaseBackgroundID - 1); // adjust to get real PICT ID
if (newBack != tempBack) // if background has changed
SetInitialTiles(newBack, false);
}
if (newBack >= kUserBackground)
{
MyEnableControl(roomInfoDialog, kBoundsButton);
if (newBack != tempBack) // if background has changed
SetInitialTiles(newBack, false);
}
else
MyDisableControl(roomInfoDialog, kBoundsButton);
if (newBack != tempBack)
{
tempBack = newBack;
if ((tempBack == 2002) || (tempBack == 2011) ||
(tempBack == 2016) || (tempBack == 2017))
LoadScaledGraphicCustom(tileSrcMap, tempBack - 800, &tileSrcRect);
2019-11-11 00:11:59 -05:00
else
LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect);
2020-03-01 17:01:35 -05:00
needRedraw = true;
2019-11-11 00:11:59 -05:00
}
}
else if (item == kBoundsButton)
{
newBack = ChooseOriginalArt(tempBack);
if (tempBack != newBack)
{
tempBack = newBack;
LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect);
2020-03-01 17:01:35 -05:00
needRedraw = true;
2019-11-11 00:11:59 -05:00
}
}
2020-03-01 17:01:35 -05:00
if (needRedraw)
UpdateRoomInfoDialog(roomInfoDialog);
2019-11-11 00:11:59 -05:00
}
InitCursor();
roomInfoDialog->Destroy();
2019-11-11 00:11:59 -05:00
// KillOffScreenPixMap(tileSrcMap);
DisposeGWorld(tileSrcMap);
tileSrcMap = nil;
#endif
}
//-------------------------------------------------------------- UpdateOriginalArt
#ifndef COMPILEDEMO
2019-12-31 02:42:20 -05:00
void UpdateOriginalArt (Dialog *theDialog)
2019-11-11 00:11:59 -05:00
{
2020-03-01 17:01:35 -05:00
Pattern grayPattern;
GetQDGlobalsGray(&grayPattern);
2019-11-11 00:11:59 -05:00
DrawDefaultButton(theDialog);
if (!originalLeftOpen)
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 7, 8, 2, nullptr);
2019-11-11 00:11:59 -05:00
else
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 7, 8, 2, grayPattern);
2019-11-11 00:11:59 -05:00
if (!originalTopOpen)
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 8, 4, 2, nullptr);
2019-11-11 00:11:59 -05:00
else
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 8, 4, 2, grayPattern);
2019-11-11 00:11:59 -05:00
if (!originalRightOpen)
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 9, 1, 2, nullptr);
2019-11-11 00:11:59 -05:00
else
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 9, 1, 2, grayPattern);
2019-11-11 00:11:59 -05:00
if (!originalBottomOpen)
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 10, 2, 2, nullptr);
2019-11-11 00:11:59 -05:00
else
2020-03-01 17:01:35 -05:00
BorderDialogItem(theDialog, 10, 2, 2, grayPattern);
2019-11-11 00:11:59 -05:00
}
#endif
//-------------------------------------------------------------- OriginalArtFilter
#ifndef COMPILEDEMO
2020-09-12 22:29:57 -04:00
int16_t OriginalArtFilter(void *context, Dialog *dial, const TimeTaggedVOSEvent *evt)
2019-11-11 00:11:59 -05:00
{
Point mouseIs;
2020-03-01 17:01:35 -05:00
if (!evt)
return -1;
if (evt->IsKeyDownEvent())
2019-11-11 00:11:59 -05:00
{
2020-03-01 17:01:35 -05:00
switch (PackVOSKeyCode(evt->m_vosEvent.m_event.m_keyboardInputEvent))
2019-11-11 00:11:59 -05:00
{
2020-03-01 17:01:35 -05:00
case PL_KEY_SPECIAL(kEnter):
case PL_KEY_NUMPAD_SPECIAL(kEnter):
2019-11-11 00:11:59 -05:00
FlashDialogButton(dial, kOkayButton);
2020-03-01 17:01:35 -05:00
return kOkayButton;
2019-12-25 22:20:10 -05:00
2020-03-01 17:01:35 -05:00
case PL_KEY_SPECIAL(kEscape):
2019-11-11 00:11:59 -05:00
FlashDialogButton(dial, kCancelButton);
2020-03-01 17:01:35 -05:00
return kCancelButton;
2019-12-25 22:20:10 -05:00
2020-03-01 17:01:35 -05:00
case PL_KEY_SPECIAL(kTab):
2019-11-11 00:11:59 -05:00
SelectDialogItemText(dial, kPICTIDItem, 0, 1024);
2020-03-01 17:01:35 -05:00
return 0;
default:
return -1;
2019-11-11 00:11:59 -05:00
}
2020-03-01 17:01:35 -05:00
}
else if (evt->IsLMouseDownEvent())
{
const GpMouseInputEvent &mouseEvt = evt->m_vosEvent.m_event.m_mouseInputEvent;
mouseIs = Point::Create(mouseEvt.m_x, mouseEvt.m_y);
2020-05-20 17:20:50 -04:00
mouseIs -= dial->GetWindow()->GetTopLeftCoord();
2020-02-18 20:53:54 -05:00
if (leftBound.Contains(mouseIs))
2020-03-01 17:01:35 -05:00
return 7;
2020-02-18 20:53:54 -05:00
else if (topBound.Contains(mouseIs))
2020-03-01 17:01:35 -05:00
return 8;
2020-02-18 20:53:54 -05:00
else if (rightBound.Contains(mouseIs))
2020-03-01 17:01:35 -05:00
return 9;
2020-02-18 20:53:54 -05:00
else if (bottomBound.Contains(mouseIs))
2020-03-01 17:01:35 -05:00
return 10;
2019-11-11 00:11:59 -05:00
else
2020-03-01 17:01:35 -05:00
return -1;
2019-11-11 00:11:59 -05:00
}
2020-03-01 17:01:35 -05:00
return -1;
2019-11-11 00:11:59 -05:00
}
#endif
//-------------------------------------------------------------- ChooseOriginalArt
#ifndef COMPILEDEMO
short ChooseOriginalArt (short was)
{
2019-12-31 02:42:20 -05:00
Dialog *theDialog;
2019-11-11 00:11:59 -05:00
long longID;
short item, newPictID, tempShort, wasPictID;
Boolean leaving;
if (was < kUserBackground)
was = kUserBackground;
InitCursor();
BringUpDialog(&theDialog, kOriginalArtDialogID, nullptr);
2019-11-11 00:11:59 -05:00
if (was >= kOriginalArtworkItem)
{
newPictID = was;
wasPictID = was;
}
else
{
newPictID = kUserBackground;
wasPictID = 0;
}
SetDialogNumToStr(theDialog, kPICTIDItem, (long)newPictID);
SelectDialogItemText(theDialog, kPICTIDItem, 0, 16);
GetDialogItemRect(theDialog, 7, &leftBound);
GetDialogItemRect(theDialog, 8, &topBound);
GetDialogItemRect(theDialog, 9, &rightBound);
GetDialogItemRect(theDialog, 10, &bottomBound);
tempShort = thisRoom->bounds >> 1; // version 2.0 house
originalLeftOpen = ((tempShort & 1) == 1);
originalTopOpen = ((tempShort & 2) == 2);
originalRightOpen = ((tempShort & 4) == 4);
originalBottomOpen = ((tempShort & 8) == 8);
originalFloor = ((tempShort & 16) == 16);
SetDialogItemValue(theDialog, kFloorSupportCheck, (short)originalFloor);
leaving = false;
2020-03-01 17:01:35 -05:00
UpdateOriginalArt(theDialog);
2019-11-11 00:11:59 -05:00
while (!leaving)
{
2021-03-29 21:41:11 -04:00
item = theDialog->ExecuteModal(nullptr, PL_FILTER_FUNC(OriginalArtFilter));
2019-11-11 00:11:59 -05:00
if (item == kOkayButton)
{
GetDialogNumFromStr(theDialog, kPICTIDItem, &longID);
if ((longID >= 3000) && (longID < 3800) && (PictIDExists((short)longID)))
{
newPictID = (short)longID;
if (newPictID != wasPictID)
SetInitialTiles(tempBack, false);
tempShort = 0;
if (originalLeftOpen)
tempShort += 1;
if (originalTopOpen)
tempShort += 2;
if (originalRightOpen)
tempShort += 4;
if (originalBottomOpen)
tempShort += 8;
if (originalFloor)
tempShort += 16;
tempShort = tempShort << 1; // shift left 1 bit
tempShort += 1; // flag that says orginal bounds used
thisRoom->bounds = tempShort;
leaving = true;
}
else
{
SysBeep(1);
SetDialogNumToStr(theDialog, kPICTIDItem, (long)newPictID);
}
}
else if (item == kCancelButton)
{
newPictID = was;
leaving = true;
}
else if (item == 7)
{
originalLeftOpen = !originalLeftOpen;
UpdateOriginalArt(theDialog);
}
else if (item == 8)
{
originalTopOpen = !originalTopOpen;
UpdateOriginalArt(theDialog);
}
else if (item == 9)
{
originalRightOpen = !originalRightOpen;
UpdateOriginalArt(theDialog);
}
else if (item == 10)
{
originalBottomOpen = !originalBottomOpen;
UpdateOriginalArt(theDialog);
}
else if (item == kFloorSupportCheck)
{
originalFloor = !originalFloor;
ToggleDialogItemValue(theDialog, kFloorSupportCheck);
}
}
theDialog->Destroy();
2019-11-11 00:11:59 -05:00
return (newPictID);
}
#endif
//-------------------------------------------------------------- PictIDExists
Boolean PictIDExists (short theID)
{
THandle<void> thePicture;
2019-11-11 00:11:59 -05:00
// Handle resHandle;
// Str255 resName;
// ResType resType;
// short numPicts, i;
// short resID;
Boolean foundIt;
foundIt = true;
thePicture = LoadHouseResource('PICT', theID);
2019-11-11 00:11:59 -05:00
if (thePicture == nil)
{
thePicture = LoadHouseResource('Date', theID);
2019-11-11 00:11:59 -05:00
if (thePicture == nil)
{
foundIt = false;
}
else
2019-12-29 23:14:37 -05:00
thePicture.Dispose();
2019-11-11 00:11:59 -05:00
}
else
2019-12-29 23:14:37 -05:00
thePicture.Dispose();
2019-11-11 00:11:59 -05:00
// foundIt = false;
// numPicts = Count1Resources('PICT');
// for (i = 1; i <= numPicts; i++)
// {
// resHandle = Get1IndResource('PICT', i);
// if (resHandle != nil)
// {
// GetResInfo(resHandle, &resID, &resType, resName);
// ReleaseResource(resHandle);
// if (resID == theID)
// {
// foundIt = true;
// break;
// }
// }
// }
return (foundIt);
}
//-------------------------------------------------------------- GetFirstPICT
short GetFirstPICT (void)
{
Handle resHandle;
Str255 resName;
2020-03-01 17:01:35 -05:00
int16_t resID = 0;
if (!houseResFork->FindFirstResourceOfType('PICT', resID))
return -1;
2020-03-01 17:01:35 -05:00
return resID;
2019-11-11 00:11:59 -05:00
}
//-------------------------------------------------------------- ComplainAboutPICTNotFound
2019-11-11 00:11:59 -05:00
#ifndef COMPILEDEMO
void ComplainAboutPICTNotFound (void)
2019-11-11 00:11:59 -05:00
{
short hitWhat;
// CenterAlert(kNoPICTFoundAlert);
hitWhat = PortabilityLayer::DialogManager::GetInstance()->DisplayAlert(kNoPICTFoundAlert, nullptr);
2019-11-11 00:11:59 -05:00
}
#endif
2021-03-29 21:41:11 -04:00
PL_IMPLEMENT_FILTER_FUNCTION(RoomFilter)
PL_IMPLEMENT_FILTER_FUNCTION(OriginalArtFilter)