2021-10-15 16:43:09 +00:00
|
|
|
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
#include "GameWindow.h"
|
2021-10-31 22:13:51 +00:00
|
|
|
#include "TitleScene.h"
|
|
|
|
#include "PlayScene.h"
|
|
|
|
#include "LevelEndScene.h"
|
|
|
|
#include "GameEndScene.h"
|
2021-10-20 16:34:31 +00:00
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
void GameWindow_Init(GameWindow *pGameWindow)
|
2021-10-15 16:43:09 +00:00
|
|
|
{
|
2021-10-16 00:29:07 +00:00
|
|
|
if (pGameWindow->Window != nil)
|
2021-10-15 16:43:09 +00:00
|
|
|
{
|
|
|
|
ShowError("\pGameWindow already initialized!", false);
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
pGameWindow->Window = GetNewWindow(BaseResID, nil, MoveToFront);
|
2021-10-15 16:43:09 +00:00
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
if (pGameWindow->Window == nil)
|
2021-10-15 16:43:09 +00:00
|
|
|
{
|
2021-10-31 22:13:51 +00:00
|
|
|
ShowError("\pGameWindow WIND resource missing!", true);
|
2021-10-15 16:43:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
// Load PICT resources
|
|
|
|
Bitmaps_Init(&(pGameWindow->Bitmaps));
|
|
|
|
|
2021-10-31 22:13:51 +00:00
|
|
|
GameWindow_SetScene(pGameWindow, Title);
|
2021-10-16 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 18:32:19 +00:00
|
|
|
void GameWindow_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
2021-10-16 00:29:07 +00:00
|
|
|
{
|
2021-10-20 16:34:31 +00:00
|
|
|
const Rect *pContentRect = &(pGameWindow->Window->portRect);
|
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
SetPort(pGameWindow->Window);
|
2021-10-15 16:43:09 +00:00
|
|
|
|
2021-10-20 16:34:31 +00:00
|
|
|
if (fullRefresh)
|
|
|
|
{
|
|
|
|
// Fill background
|
2021-10-20 23:13:31 +00:00
|
|
|
FillRect(pContentRect, WindowPattern);
|
2021-10-20 16:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 22:13:51 +00:00
|
|
|
switch (pGameWindow->CurrentSceneId)
|
2021-10-22 18:32:19 +00:00
|
|
|
{
|
2021-10-29 00:44:36 +00:00
|
|
|
case Title:
|
2021-10-31 22:13:51 +00:00
|
|
|
TitleScene_Draw(pGameWindow, fullRefresh);
|
2021-10-29 00:44:36 +00:00
|
|
|
break;
|
2021-10-22 18:32:19 +00:00
|
|
|
case Play:
|
2021-10-31 22:13:51 +00:00
|
|
|
PlayScene_Draw(pGameWindow, fullRefresh);
|
2021-10-22 18:32:19 +00:00
|
|
|
break;
|
2021-10-31 22:13:51 +00:00
|
|
|
case LevelEnd:
|
|
|
|
LevelEndScene_Draw(pGameWindow, fullRefresh);
|
|
|
|
break;
|
|
|
|
case GameEnd:
|
|
|
|
GameEndScene_Draw(pGameWindow, fullRefresh);
|
2021-10-22 18:32:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-10-20 23:13:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 16:34:31 +00:00
|
|
|
void GameWindow_Click(GameWindow *pGameWindow, const Point *pPosition)
|
2021-10-22 18:32:19 +00:00
|
|
|
{
|
2021-10-31 22:13:51 +00:00
|
|
|
switch (pGameWindow->CurrentSceneId)
|
2021-10-22 18:32:19 +00:00
|
|
|
{
|
2021-10-29 00:44:36 +00:00
|
|
|
case Title:
|
2021-10-31 22:13:51 +00:00
|
|
|
TitleScene_Click(pGameWindow, pPosition);
|
2021-10-29 00:44:36 +00:00
|
|
|
break;
|
2021-10-22 18:32:19 +00:00
|
|
|
case Play:
|
2021-10-31 22:13:51 +00:00
|
|
|
PlayScene_Click(pGameWindow, pPosition);
|
2021-10-22 18:32:19 +00:00
|
|
|
break;
|
2021-10-31 22:13:51 +00:00
|
|
|
case LevelEnd:
|
|
|
|
LevelEndScene_Click(pGameWindow, pPosition);
|
|
|
|
break;
|
|
|
|
case GameEnd:
|
|
|
|
GameEndScene_Click(pGameWindow, pPosition);
|
2021-10-22 18:32:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-31 22:13:51 +00:00
|
|
|
void GameWindow_SetScene(GameWindow *pGameWindow, const SceneId sceneId)
|
2021-10-20 16:34:31 +00:00
|
|
|
{
|
2021-11-08 22:47:31 +00:00
|
|
|
switch (sceneId)
|
2021-10-20 16:34:31 +00:00
|
|
|
{
|
2021-11-08 22:47:31 +00:00
|
|
|
case Title:
|
|
|
|
TitleScene_Init(pGameWindow);
|
|
|
|
break;
|
|
|
|
case Play:
|
|
|
|
PlayScene_Init(pGameWindow);
|
|
|
|
break;
|
|
|
|
case LevelEnd:
|
|
|
|
LevelEndScene_Init(pGameWindow);
|
|
|
|
break;
|
|
|
|
case GameEnd:
|
|
|
|
GameEndScene_Init(pGameWindow);
|
|
|
|
break;
|
2021-10-20 16:34:31 +00:00
|
|
|
}
|
2021-10-31 22:13:51 +00:00
|
|
|
pGameWindow->CurrentSceneId = sceneId;
|
|
|
|
GameWindow_Draw(pGameWindow, true);
|
2021-10-20 16:34:31 +00:00
|
|
|
}
|
2021-10-22 18:32:19 +00:00
|
|
|
|
2021-10-31 22:13:51 +00:00
|
|
|
void GameWindow_Show(const GameWindow *pGameWindow)
|
2021-10-22 18:32:19 +00:00
|
|
|
{
|
2021-10-31 22:13:51 +00:00
|
|
|
ShowWindow(pGameWindow->Window);
|
2021-10-22 18:32:19 +00:00
|
|
|
}
|