Skip to content

Commit 8834f0c

Browse files
VicSevenTscbroede
andauthored
Document Poketch Backlight Toggle (Overlay 37) (#803)
Co-authored-by: scbroede <[email protected]>
1 parent 557d2b4 commit 8834f0c

File tree

12 files changed

+420
-420
lines changed

12 files changed

+420
-420
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef POKEPLATINUM_POKETCH_BACKLIGHT_TOGGLE_GRAPHICS_H
2+
#define POKEPLATINUM_POKETCH_BACKLIGHT_TOGGLE_GRAPHICS_H
3+
4+
#include "applications/poketch/poketch_animation.h"
5+
#include "applications/poketch/poketch_task.h"
6+
7+
#include "bg_window.h"
8+
9+
#define BACKLIGHT_TOGGLE_TASK_SLOTS 4
10+
11+
typedef struct BacklightData {
12+
BOOL isOn;
13+
} BacklightData;
14+
15+
typedef struct BacklightToggleGraphics {
16+
const BacklightData *backlight;
17+
BgConfig *bgConfig;
18+
u32 activeTasks[POKETCH_TASK_SLOT_BASE + BACKLIGHT_TOGGLE_TASK_SLOTS];
19+
PoketchAnimation_AnimationManager *animMan;
20+
PoketchAnimation_AnimatedSpriteData *animation;
21+
PoketchAnimation_SpriteData sprite;
22+
} BacklightToggleGraphics;
23+
24+
enum BacklightToggleGraphicsTask {
25+
BACKLIGHT_TOGGLE_GRAPHICS_INIT = 0,
26+
BACKLIGHT_TOGGLE_GRAPHICS_FREE,
27+
BACKLIGHT_TOGGLE_GRAPHICS_UPDATE_SWITCH
28+
};
29+
30+
BOOL PoketchBacklightToggleGraphics_New(BacklightToggleGraphics **dest, const BacklightData *backlight, BgConfig *bgConfig);
31+
void PoketchBacklightToggleGraphics_Free(BacklightToggleGraphics *graphics);
32+
void PoketchBacklightToggleGraphics_StartTask(BacklightToggleGraphics *graphics, enum BacklightToggleGraphicsTask taskID);
33+
BOOL PoketchBacklighToggleGraphics_TaskIsNotActive(BacklightToggleGraphics *graphics, enum BacklightToggleGraphicsTask taskID);
34+
BOOL PoketchBacklightToggle_NoActiveTasks(BacklightToggleGraphics *graphics);
35+
36+
#endif // POKEPLATINUM_POKETCH_BACKLIGHT_TOGGLE_GRAPHICS_H

include/overlay037/ov37_022563D4.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

include/overlay037/struct_ov37_022563D4_1.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

include/overlay037/struct_ov37_022563D4_decl.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

platinum.us/main.lsf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,11 @@ Overlay poketch_pedometer
956956
Object main.nef.p/src_applications_poketch_pedometer_graphics.c.o
957957
}
958958

959-
Overlay overlay37
959+
Overlay poketch_backlight_toggle
960960
{
961961
After overlay25
962-
Object main.nef.p/src_overlay037_ov37_022561C0.c.o
963-
Object main.nef.p/src_overlay037_ov37_022563D4.c.o
962+
Object main.nef.p/src_applications_poketch_backlight_toggle_main.c.o
963+
Object main.nef.p/src_applications_poketch_backlight_toggle_graphics.c.o
964964
}
965965

966966
Overlay overlay38

platinum.us/sbins_shared.sha1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dfab77a2a03414852a047b45eabec7d3367fca58 *poketch_friendship_checker.sbin
3636
cd5d643c3bf17d863db96640d7bfc100bda30b37 *poketch_dowsing_machine.sbin
3737
4410caba494af7c853ef7f1a4a2ac4d8243f5a18 *poketch_counter.sbin
3838
09d6d7c195d109d31c8f890711f562ae2e219cfd *poketch_pedometer.sbin
39-
212e5bc9a6036f4c0be02d65bbba5feed12c5d53 *overlay37.sbin
39+
212e5bc9a6036f4c0be02d65bbba5feed12c5d53 *poketch_backlight_toggle.sbin
4040
3f15b19c0ca694b9942077a9c8eda0855c25450c *overlay38.sbin
4141
da2f09fdfc788b4a6e6ada88db5176fcdc23c924 *overlay39.sbin
4242
f8a583401a3a614cc88ee6dc7f3b3cdbf00f22cb *poketch_daycare_checker.sbin
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#include "applications/poketch/backlight_toggle/graphics.h"
2+
3+
#include <nitro.h>
4+
5+
#include "generated/sdat.h"
6+
7+
#include "applications/poketch/poketch_animation.h"
8+
#include "applications/poketch/poketch_graphics.h"
9+
#include "applications/poketch/poketch_system.h"
10+
#include "applications/poketch/poketch_task.h"
11+
12+
#include "bg_window.h"
13+
#include "graphics.h"
14+
#include "heap.h"
15+
#include "sys_task_manager.h"
16+
17+
static void SetupSprites(BacklightToggleGraphics *graphics, const BacklightData *backlight);
18+
static void UnloadSprites(BacklightToggleGraphics *graphics);
19+
static void EndTask(PoketchTaskManager *taskMan);
20+
static void Task_DrawBackground(SysTask *task, void *taskMan);
21+
static void Task_FreeBackground(SysTask *task, void *taskMan);
22+
static void Task_UpdateSwitch(SysTask *task, void *taskMan);
23+
24+
BOOL PoketchBacklightToggleGraphics_New(BacklightToggleGraphics **dest, const BacklightData *backlight, BgConfig *bgConfig)
25+
{
26+
BacklightToggleGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(BacklightToggleGraphics));
27+
28+
if (graphics != NULL) {
29+
PoketchTask_InitActiveTaskList(graphics->activeTasks, BACKLIGHT_TOGGLE_TASK_SLOTS);
30+
graphics->backlight = backlight;
31+
graphics->bgConfig = PoketchGraphics_GetBgConfig();
32+
graphics->animMan = PoketchGraphics_GetAnimationManager();
33+
34+
SetupSprites(graphics, backlight);
35+
*dest = graphics;
36+
37+
return TRUE;
38+
}
39+
40+
return FALSE;
41+
}
42+
43+
void PoketchBacklightToggleGraphics_Free(BacklightToggleGraphics *graphics)
44+
{
45+
if (graphics != NULL) {
46+
Heap_Free(graphics);
47+
}
48+
}
49+
50+
static void SetupSprites(BacklightToggleGraphics *graphics, const BacklightData *backlight)
51+
{
52+
static const PoketchAnimation_AnimationData animData = {
53+
.translation = { FX32_CONST(112), FX32_CONST(104) },
54+
.animIdx = 0,
55+
.flip = NNS_G2D_RENDERERFLIP_NONE,
56+
.oamPriority = 2,
57+
.priority = 0,
58+
.hasAffineTransform = FALSE,
59+
};
60+
61+
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 104, DS_SCREEN_SUB, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
62+
PoketchAnimation_LoadSpriteFromNARC(&graphics->sprite, NARC_INDEX_GRAPHIC__POKETCH, 102, 103, HEAP_ID_POKETCH_APP);
63+
64+
graphics->animation = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &animData, &graphics->sprite);
65+
66+
if (!backlight->isOn) {
67+
PoketchAnimation_UpdateAnimationIdx(graphics->animation, 1);
68+
}
69+
}
70+
71+
static void UnloadSprites(BacklightToggleGraphics *graphics)
72+
{
73+
PoketchAnimation_RemoveAnimatedSprite(graphics->animMan, graphics->animation);
74+
PoketchAnimation_FreeSpriteData(&graphics->sprite);
75+
}
76+
77+
static const PoketchTask sBacklightToggleGraphicsTasks[] = {
78+
{ BACKLIGHT_TOGGLE_GRAPHICS_INIT, Task_DrawBackground, 0 },
79+
{ BACKLIGHT_TOGGLE_GRAPHICS_FREE, Task_FreeBackground, 0 },
80+
{ BACKLIGHT_TOGGLE_GRAPHICS_UPDATE_SWITCH, Task_UpdateSwitch, 0 },
81+
{ 0 }
82+
};
83+
84+
void PoketchBacklightToggleGraphics_StartTask(BacklightToggleGraphics *graphics, enum BacklightToggleGraphicsTask taskID)
85+
{
86+
PoketchTask_Start(sBacklightToggleGraphicsTasks, taskID, graphics, graphics->backlight, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
87+
}
88+
89+
BOOL PoketchBacklighToggleGraphics_TaskIsNotActive(BacklightToggleGraphics *graphics, enum BacklightToggleGraphicsTask taskID)
90+
{
91+
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
92+
}
93+
94+
BOOL PoketchBacklightToggle_NoActiveTasks(BacklightToggleGraphics *graphics)
95+
{
96+
return PoketchTask_NoActiveTasks(graphics->activeTasks);
97+
}
98+
99+
static void EndTask(PoketchTaskManager *taskMan)
100+
{
101+
BacklightToggleGraphics *graphics = PoketchTask_GetTaskData(taskMan);
102+
103+
PoketchTask_EndTask(graphics->activeTasks, taskMan);
104+
}
105+
106+
static void Task_DrawBackground(SysTask *task, void *taskMan)
107+
{
108+
static const BgTemplate bgTemplate = {
109+
.x = 0,
110+
.y = 0,
111+
.bufferSize = 0x800,
112+
.baseTile = 0,
113+
.screenSize = BG_SCREEN_SIZE_256x256,
114+
.colorMode = GX_BG_COLORMODE_16,
115+
.screenBase = GX_BG_SCRBASE_0x7000,
116+
.charBase = GX_BG_CHARBASE_0x00000,
117+
.bgExtPltt = GX_BG_EXTPLTT_01,
118+
.priority = 2,
119+
.areaOver = 0,
120+
.mosaic = FALSE,
121+
};
122+
BacklightToggleGraphics *graphics = PoketchTask_GetTaskData(taskMan);
123+
124+
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &bgTemplate, BG_TYPE_STATIC);
125+
Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 101, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
126+
Graphics_LoadTilemapToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 100, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
127+
128+
PoketchGraphics_LoadActivePalette(0, 0);
129+
Bg_CopyTilemapBufferToVRAM(graphics->bgConfig, BG_LAYER_SUB_2);
130+
131+
GXSDispCnt dispCnt = GXS_GetDispCnt();
132+
GXS_SetVisiblePlane(dispCnt.visiblePlane | GX_PLANEMASK_BG2);
133+
134+
EndTask(taskMan);
135+
}
136+
137+
static void Task_FreeBackground(SysTask *task, void *taskMan)
138+
{
139+
BacklightToggleGraphics *graphics = PoketchTask_GetTaskData(taskMan);
140+
141+
UnloadSprites(graphics);
142+
Bg_FreeTilemapBuffer(graphics->bgConfig, BG_LAYER_SUB_2);
143+
EndTask(taskMan);
144+
}
145+
146+
static void Task_UpdateSwitch(SysTask *task, void *taskMan)
147+
{
148+
BacklightToggleGraphics *graphics = PoketchTask_GetTaskData(taskMan);
149+
const BacklightData *backlight = PoketchTask_GetConstTaskData(taskMan);
150+
151+
PoketchSystem_PlaySoundEffect(SEQ_SE_DP_POKETCH_003);
152+
153+
if (backlight->isOn) {
154+
PoketchAnimation_UpdateAnimationIdx(graphics->animation, 0);
155+
PM_SetBackLight(PM_LCD_BOTTOM, PM_BACKLIGHT_ON);
156+
} else {
157+
PoketchAnimation_UpdateAnimationIdx(graphics->animation, 1);
158+
PM_SetBackLight(PM_LCD_BOTTOM, PM_BACKLIGHT_OFF);
159+
}
160+
161+
EndTask(taskMan);
162+
}

0 commit comments

Comments
 (0)