Update documented Poketch apps to consistent format (#790)

This commit is contained in:
VicSevenT 2025-10-03 21:38:01 -05:00 committed by GitHub
parent 42aba98f46
commit 75b153bf02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 821 additions and 791 deletions

View File

@ -2,10 +2,13 @@
#define POKEPLATINUM_POKETCH_ANALOG_WATCH_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "sys_task_manager.h"
#define ANALOG_WATCH_TASK_SLOTS 8
#define NUM_SPRITES 2
typedef struct AnalogWatchData {
@ -16,7 +19,7 @@ typedef struct AnalogWatchData {
typedef struct AnalogWatchGraphics {
const AnalogWatchData *watchData;
BgConfig *bgConfig;
u32 activeTasks[10];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + ANALOG_WATCH_TASK_SLOTS];
SysTask *emptyTask;
PoketchAnimation_SpriteData clockHandSprites;
PoketchAnimation_AnimationManager *animMan;

View File

@ -2,9 +2,12 @@
#define POKEPLATINUM_POKETCH_CALCULATOR_GRAPHICS_H
#include "applications/poketch/calculator/value.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define CALCULATOR_TASK_SLOTS 8
#define NUM_BUTTONS 17
#define CALC_BUTTON_DECIMAL 10
@ -30,7 +33,7 @@ typedef struct CalculatorData {
typedef struct CalculatorGraphics {
const CalculatorData *calcData;
BgConfig *bgConfig;
u32 activeTasks[10];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + CALCULATOR_TASK_SLOTS];
u16 outputRowTiles[14];
u16 releasedButtonTiles[NUM_BUTTONS][BUTTON_SIZE_TILES_LARGE];
} CalculatorGraphics;
@ -49,7 +52,7 @@ enum CalculatorGraphicsTask {
CALCULATOR_GRAPHICS_FREE,
};
BOOL PoketchCalculatorGraphics_New(CalculatorGraphics **graphics, const CalculatorData *calcState, BgConfig *bgConfig);
BOOL PoketchCalculatorGraphics_New(CalculatorGraphics **dest, const CalculatorData *calcState, BgConfig *bgConfig);
void PoketchCalculatorGraphics_Free(CalculatorGraphics *graphics);
void PoketchCalculatorGraphics_StartTask(CalculatorGraphics *graphics, enum CalculatorGraphicsTask taskID);
BOOL PoketchCalculatorGraphics_TaskIsNotActive(CalculatorGraphics *graphics, enum CalculatorGraphicsTask taskID);

View File

@ -2,9 +2,12 @@
#define POKEPLATINUM_POKETCH_COUNTER_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define COUNTER_TASK_SLOTS 4
#define NUM_DIGITS 4
enum CounterButtonPosition {
@ -20,7 +23,7 @@ typedef struct CounterData {
typedef struct CounterGraphics {
const CounterData *counterData;
BgConfig *bgConfig;
u32 activeTasks[6];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + COUNTER_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_AnimatedSpriteData *buttonAnimation;
PoketchAnimation_AnimatedSpriteData *digitsAnimation[NUM_DIGITS];
@ -29,7 +32,7 @@ typedef struct CounterGraphics {
} CounterGraphics;
enum CounterGraphicsTask {
COUNTER_GRAPHICS_INIT,
COUNTER_GRAPHICS_INIT = 0,
COUNTER_GRAPHICS_FREE,
COUNTER_GRAPHICS_UPDATE_BUTTON,
COUNTER_GRAPHICS_UPDATE_VALUE,

View File

@ -1,17 +1,18 @@
#ifndef POKEPLATINUM_OV40_0225645C_H
#define POKEPLATINUM_OV40_0225645C_H
#ifndef POKEPLATINUM_POKETCH_DAYCARE_CHECKER_GRAPHICS_H
#define POKEPLATINUM_POKETCH_DAYCARE_CHECKER_GRAPHICS_H
#include "constants/daycare.h"
#include "generated/genders.h"
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "sys_task_manager.h"
#define NUM_DAYCARE_SPRITES 11
#define DAYCARE_CHECKER_TASK_SLOTS 4
#define NUM_TASK_SLOTS 4
#define NUM_DAYCARE_SPRITES 11
typedef struct DaycareStatus {
u8 numMons;
@ -26,7 +27,7 @@ typedef struct DaycareStatus {
typedef struct DaycareCheckerGraphics {
const DaycareStatus *dayCareSummary;
BgConfig *bgConfig;
u32 activeTasks[2 + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + DAYCARE_CHECKER_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_AnimatedSpriteData *sprites[NUM_DAYCARE_SPRITES];
PoketchAnimation_SpriteData symbolAnimData;
@ -39,16 +40,16 @@ typedef struct DaycareCheckerGraphics {
SysTask *mosaicTask;
} DaycareCheckerGraphics;
enum DaycareGraphicsTasks {
TASK_DRAW_APP_BACKGROUND = 0,
TASK_FREE_BACKGROUND,
TASK_RELOAD_DAYCARE_STATE,
enum DaycareGraphicsTask {
DAYCARE_CHECKER_GRAPHICS_INIT = 0,
DAYCARE_CHECKER_GRAPHICS_FREE,
DAYCARE_CHECKER_GRAPHICS_RELOAD,
};
BOOL DaycareCheckerGraphics_New(DaycareCheckerGraphics **graphics, const DaycareStatus *daycareStatus, BgConfig *bgConfig);
void DaycareCheckerGraphics_Free(DaycareCheckerGraphics *graphics);
void PoketchDaycareCheckerGraphics_StartTask(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTasks taskID);
BOOL PoketchDaycareCheckerGraphics_TaskIsNotActive(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTasks taskID);
BOOL PoketchDaycareCheckerGraphics_New(DaycareCheckerGraphics **dest, const DaycareStatus *daycareStatus, BgConfig *bgConfig);
void PoketchDaycareCheckerGraphics_Free(DaycareCheckerGraphics *graphics);
void PoketchDaycareCheckerGraphics_StartTask(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTask taskID);
BOOL PoketchDaycareCheckerGraphics_TaskIsNotActive(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTask taskID);
BOOL PoketchDaycareCheckerGraphics_NoActiveTasks(DaycareCheckerGraphics *graphics);
#endif // POKEPLATINUM_OV40_0225645C_H
#endif // POKEPLATINUM_POKETCH_DAYCARE_CHECKER_GRAPHICS_H

View File

@ -1,9 +1,11 @@
#ifndef POKEPLATINUM_POKETCH_DIGITAL_WATCH_GRAPHICS_H
#define POKEPLATINUM_POKETCH_DIGITAL_WATCH_GRAPHICS_H
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define NUM_TASK_SLOTS 8
#define DIGITAL_WATCH_TASK_SLOTS 8
// Graphics
#define POKETCH_DIGITAL_WATCH_NARC_TILES_IDX 23
@ -26,26 +28,26 @@
typedef struct {
RTCTime time;
u32 backlightActive;
} WatchData;
} DigitalWatchData;
typedef struct PoketchDigitalWatchGraphics {
const WatchData *watchData;
const DigitalWatchData *watchData;
BgConfig *bgConfig;
u32 activeTasks[2 + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + DIGITAL_WATCH_TASK_SLOTS];
u16 digitsTilemap[POKETCH_DIGIT_TILEMAP_SIZE_BYTES];
} PoketchDigitalWatchGraphics;
enum DigitalWatchGraphicsTasks {
TASK_DRAW_APP_SCREEN = 0,
TASK_UPDATE_WATCH_DIGITS,
TASK_TOGGLE_BACKLIGHT,
TASK_FREE_GRAPHICS,
enum DigitalWatchGraphicsTask {
DIGITAL_WATCH_GRAPHICS_INIT = 0,
DIGITAL_WATCH_GRAPHICS_UPDATE_DIGITS,
DIGITAL_WATCH_GRAPHICS_TOGGLE_BACKLIGHT,
DIGITAL_WATCH_GRAPHICS_FREE,
};
BOOL PoketchDigitalWatchGraphics_New(PoketchDigitalWatchGraphics **graphics, const WatchData *watchData, BgConfig *bgConfig);
BOOL PoketchDigitalWatchGraphics_New(PoketchDigitalWatchGraphics **dest, const DigitalWatchData *watchData, BgConfig *bgConfig);
void PoketchDigitalWatchGraphics_Free(PoketchDigitalWatchGraphics *graphics);
void PoketchDigitalWatchGraphics_StartTask(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTasks taskID);
BOOL PoketchDigitalWatchGraphics_TaskIsNotActive(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTasks taskID);
void PoketchDigitalWatchGraphics_StartTask(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTask taskID);
BOOL PoketchDigitalWatchGraphics_TaskIsNotActive(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTask taskID);
BOOL PoketchDigitalWatchGraphics_NoActiveTasks(PoketchDigitalWatchGraphics *graphics);
#endif // POKEPLATINUM_POKETCH_DIGITAL_WATCH_GRAPHICS_H

View File

@ -1,9 +1,11 @@
#ifndef POKEPLATINUM_POKETCH_DOT_ARTIST_GRAPHICS_H
#define POKEPLATINUM_POKETCH_DOT_ARTIST_GRAPHICS_H
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define NUM_TASK_SLOTS 8
#define DOT_ARTIST_TASK_SLOTS 8
#define CANVAS_WIDTH 24
#define CANVAS_HEIGHT 20
@ -15,10 +17,10 @@ typedef struct DotArt {
typedef struct DotArtistGraphics {
const DotArt *dotArt;
BgConfig *bgConfig;
u32 activeTasks[2 + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + DOT_ARTIST_TASK_SLOTS];
} DotArtistGraphics;
enum DotArtistGraphicsTasks {
enum DotArtistGraphicsTask {
DOT_ARTIST_GRAPHICS_INIT = 0,
DOT_ARTIST_GRAPHICS_UPDATE,
DOT_ARTIST_GRAPHICS_FREE,
@ -26,8 +28,8 @@ enum DotArtistGraphicsTasks {
BOOL PoketchDotArtistGraphics_New(DotArtistGraphics **graphics, const DotArt *dotArt, BgConfig *bgConfig);
void PoketchDotArtistGraphics_Free(DotArtistGraphics *graphics);
void PoketchDotArtistGraphics_StartTask(DotArtistGraphics *graphics, enum DotArtistGraphicsTasks taskID);
BOOL PoketchDotArtistGraphics_TaskIsNotActive(DotArtistGraphics *graphics, enum DotArtistGraphicsTasks taskID);
void PoketchDotArtistGraphics_StartTask(DotArtistGraphics *graphics, enum DotArtistGraphicsTask taskID);
BOOL PoketchDotArtistGraphics_TaskIsNotActive(DotArtistGraphics *graphics, enum DotArtistGraphicsTask taskID);
BOOL PoketchDotArtistGraphics_NoActiveTasks(DotArtistGraphics *graphics);
#endif // POKEPLATINUM_POKETCH_DOT_ARTIST_GRAPHICS_H

View File

@ -2,9 +2,12 @@
#define POKEPLATINUM_POKETCH_DOWSING_MACHINE_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define DOWSING_MACHINE_TASK_SLOTS 8
#define MAX_DOWSING_ITEMS 8
typedef struct DowsingMachineItemPosition {
@ -25,7 +28,7 @@ typedef struct DowsingMachineData {
typedef struct DowsingMachingGraphics {
const DowsingMachineData *dowsingData;
BgConfig *bgConfig;
u32 activeTasks[10];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + DOWSING_MACHINE_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_AnimatedSpriteData *radarSprite;
PoketchAnimation_AnimatedSpriteData *itemSprites[MAX_DOWSING_ITEMS];

View File

@ -4,10 +4,13 @@
#include "constants/pokemon.h"
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "sys_task_manager.h"
#define FRIENDSHIP_CHECKER_TASK_SLOTS 8
#define FRIENDSHIP_LIKE 0
#define FRIENDSHIP_HATE 1
#define FRIENDSHIP_NEUTRAL 2
@ -20,17 +23,17 @@ enum TapState {
TAP_STATE_DOUBLE_TAP,
};
enum FriendshipCheckerGraphicTask {
enum FriendshipCheckerGraphicsTask {
FRIENDSHIP_CHECKER_GRAPHICS_INIT = 0,
FRIENDSHIP_CHECKER_GRAPHICS_FREE,
};
typedef struct FriendshipCheckerState {
typedef struct FriendshipCheckerData {
int monCount;
struct {
u32 spriteIdx;
u16 species;
u16 unk_06;
u16 unused;
u16 form;
u8 friendship;
u8 intensity;
@ -39,7 +42,7 @@ typedef struct FriendshipCheckerState {
u16 screenTapped;
u32 touchX;
u32 touchY;
} FriendshipCheckerState;
} FriendshipCheckerData;
typedef struct PokemonGraphic {
PoketchAnimation_AnimatedSpriteData *iconSprite;
@ -64,9 +67,9 @@ typedef struct PokemonGraphic {
} PokemonGraphic;
typedef struct FriendshipCheckerGraphics {
const FriendshipCheckerState *appState;
const FriendshipCheckerData *friendshipData;
BgConfig *bgConfig;
u32 activeTasks[10];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + FRIENDSHIP_CHECKER_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_SpriteData monAnimData;
PoketchAnimation_SpriteData heartAnimData;
@ -88,10 +91,10 @@ typedef struct FriendshipCheckerGraphics {
u32 touchY;
} FriendshipCheckerGraphics;
BOOL PoketchFriendshipCheckerGraphics_New(FriendshipCheckerGraphics **dest, const FriendshipCheckerState *appState, BgConfig *bgConfig);
BOOL PoketchFriendshipCheckerGraphics_New(FriendshipCheckerGraphics **dest, const FriendshipCheckerData *appState, BgConfig *bgConfig);
void PoketchFriendshipCheckerGraphics_Free(FriendshipCheckerGraphics *graphics);
void PoketchFriendshipCheckerGraphics_StartTask(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicTask taskID);
BOOL PoketchFriendshipCheckerGraphics_TaskIsNotActive(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicTask taskID);
void PoketchFriendshipCheckerGraphics_StartTask(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicsTask taskID);
BOOL PoketchFriendshipCheckerGraphics_TaskIsNotActive(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicsTask taskID);
BOOL PoketchFriendshipCheckerGraphics_NoActiveTasks(FriendshipCheckerGraphics *graphics);
#endif // POKEPLATINUM_POKETCH_FRIENDSHIP_CHECKER_GRAPHICS_H

View File

@ -2,47 +2,49 @@
#define POKEPLATINUM_POKETCH_MEMO_PAD_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define NUM_TASK_SLOTS 16
#define NUM_SPRITES 2
#define MEMO_PAD_TASK_SLOTS 16
#define NUM_SPRITES 2
#define MEMO_PAD_WIDTH 78
#define MEMO_PAD_HEIGHT 75
#define ERASER_SIZE 4
typedef struct MemoPadState {
typedef struct MemoPadData {
BOOL pencilActive;
u32 x;
u32 y;
u8 pixels[MEMO_PAD_WIDTH][MEMO_PAD_HEIGHT];
u32 appID;
} MemoPadState;
} MemoPadData;
typedef struct MemoPadGraphics {
const MemoPadState *padState;
const MemoPadData *padData;
BgConfig *bgConfig;
u32 activeTasks[NUM_TASK_SLOTS + 2];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + MEMO_PAD_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_SpriteData animData;
PoketchAnimation_AnimatedSpriteData *sprites[NUM_SPRITES];
Window *window;
} MemoPadGraphics;
enum MemoPadGraphicsTasks {
TASK_DRAW_APP_SCREEN = 0,
TASK_CHANGE_DRAW_TOOL,
TASK_PRINT_WINDOW,
TASK_UPDATE_MEMO_CONTENT,
TASK_PRINT_WINDOW_2,
TASK_FREE_BG,
enum MemoPadGraphicsTask {
MEMO_PAD_GRAPHICS_INIT = 0,
MEMO_PAD_GRAPHICS_CHANGE_TOOL,
MEMO_PAD_GRAPHICS_PRINT_WINDOW,
MEMO_PAD_GRAPHICS_UPDATE_CONTENT,
MEMO_PAD_GRAPHICS_PRINT_WINDOW_2,
MEMO_PAD_GRAPHICS_FREE,
};
BOOL MemoPadGraphics_New(MemoPadGraphics **graphics, const MemoPadState *padState, BgConfig *bgConfig);
BOOL MemoPadGraphics_New(MemoPadGraphics **graphics, const MemoPadData *padState, BgConfig *bgConfig);
void MemoPadGraphics_Free(MemoPadGraphics *graphics);
void PoketchMemoPadGraphics_StartTask(MemoPadGraphics *graphics, enum MemoPadGraphicsTasks taskID);
BOOL PoketchMemoPadGraphics_TaskIsNotActive(MemoPadGraphics *graphics, enum MemoPadGraphicsTasks taskID);
void PoketchMemoPadGraphics_StartTask(MemoPadGraphics *graphics, enum MemoPadGraphicsTask taskID);
BOOL PoketchMemoPadGraphics_TaskIsNotActive(MemoPadGraphics *graphics, enum MemoPadGraphicsTask taskID);
BOOL PoketchMemoPadGraphics_NoActiveTasks(MemoPadGraphics *graphics);
#endif // POKEPLATINUM_POKETCH_MEMO_PAD_GRAPHICS_H

View File

@ -2,13 +2,14 @@
#define POKEPLATINUM_POKETCH_MOVE_TESTER_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "message.h"
#define MOVE_TESTER_NONE_SELECTED NUM_POKEMON_TYPES
#define NUM_TASK_SLOTS 8
#define MOVE_TESTER_TASK_SLOTS 8
typedef struct MoveTesterData {
u32 lastButtonPressed;
@ -21,7 +22,7 @@ typedef struct MoveTesterData {
typedef struct PoketchMoveTesterGraphics {
const MoveTesterData *moveTesterData;
BgConfig *bgConfig;
u32 activeTasks[2 + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + MOVE_TESTER_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_AnimatedSpriteData *animSpriteData[6];
PoketchAnimation_AnimatedSpriteData *exclamSprites[5];
@ -35,18 +36,18 @@ typedef struct PoketchMoveTesterGraphics {
Strbuf *strBuf;
} PoketchMoveTesterGraphics;
enum MoveTesterGraphicsTasks {
TASK_DRAW_APP_SCREEN = 0,
TASK_FREE_WINDOWS_AND_BG,
TASK_BUTTON_PRESSED,
TASK_BUTTON_RELEASED,
TASK_UPDATE_GRAPHICS
enum MoveTesterGraphicsTask {
MOVE_TESTER_GRAPHICS_INIT = 0,
MOVE_TESTER_GRAPHICS_FREE,
MOVE_TESTER_GRAPHICS_BUTTON_PRESSED,
MOVE_TESTER_GRAPHICS_BUTTON_RELEASED,
MOVE_TESTER_GRAPHICS_UPDATE,
};
BOOL PoketchMoveTesterGraphics_New(PoketchMoveTesterGraphics **graphics, const MoveTesterData *moveTesterData, BgConfig *bgConfig);
BOOL PoketchMoveTesterGraphics_New(PoketchMoveTesterGraphics **dest, const MoveTesterData *moveTesterData, BgConfig *bgConfig);
void PoketchMoveTesterGraphics_Free(PoketchMoveTesterGraphics *graphics);
void PoketchMoveTesterGraphics_StartTask(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTasks taskID);
BOOL PoketchMoveTesterGraphics_TaskIsNotActive(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTasks taskID);
void PoketchMoveTesterGraphics_StartTask(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTask taskID);
BOOL PoketchMoveTesterGraphics_TaskIsNotActive(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTask taskID);
BOOL PoketchMoveTesterGraphics_NoActiveTasks(PoketchMoveTesterGraphics *graphics);
#endif // POKEPLATINUM_POKETCH_MOVE_TESTER_GRAPHICS_H

View File

@ -4,10 +4,13 @@
#include "constants/pokemon.h"
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "sys_task_manager.h"
#define PARTY_STATUS_TASK_SLOTS 8
typedef struct PartyStatus {
int partyCount;
struct {
@ -44,7 +47,7 @@ struct PartyStatusGraphics {
const PartyStatus *partyData;
BgConfig *bgConfig;
PoketchAnimation_AnimationManager *animMan;
u32 activeTaskIds[10];
u32 activeTaskIds[POKETCH_TASK_SLOT_BASE + PARTY_STATUS_TASK_SLOTS];
u32 hpBarBaseTile;
u32 partyCount;
Window hpBarWindows[MAX_PARTY_SIZE];

View File

@ -2,9 +2,12 @@
#define POKEPLATINUM_POKETCH_PEDOMETER_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#define PEDOMETER_TASK_SLOTS 4
#define NUM_DIGITS 5
enum PedometerButtonPosition {
@ -20,7 +23,7 @@ typedef struct PedometerData {
typedef struct PedometerGraphics {
const PedometerData *pedometerData;
BgConfig *bgConfig;
u32 activeTasks[6];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + PEDOMETER_TASK_SLOTS];
PoketchAnimation_AnimationManager *animMan;
PoketchAnimation_AnimatedSpriteData *buttonAnimation;
PoketchAnimation_AnimatedSpriteData *digitsAnimation[NUM_DIGITS];

View File

@ -14,6 +14,8 @@
#define POKETCH_SCREEN_TILE_OFFSET_X 2
#define POKETCH_SCREEN_TILE_OFFSET_Y 2
#define POKETCH_DIGITS_NCGR_NUM_TILES 80
enum PoketchGraphicsTask {
TASK_SETUP_BACKGROUND = 0,
TASK_REVEAL_SCREEN_1,

View File

@ -6,9 +6,9 @@
#define POKETCH_TASK_LIST_VALIDATOR 0x12345678 // If activeList[VALIDATOR_IDX] is not this value, tasks will not be added or removed.
#define POKETCH_EMPTY_TASK 0xFFFFFFFF
#define NUM_SLOTS_IDX 0
#define VALIDATOR_IDX 1
#define BASE_IDX 2
#define NUM_SLOTS_IDX 0
#define VALIDATOR_IDX 1
#define POKETCH_TASK_SLOT_BASE 2
typedef struct PoketchTask {
u32 taskId;

View File

@ -2,11 +2,12 @@
#define POKEPLATINUM_POKETCH_STOPWATCH_GRAPHICS_H
#include "applications/poketch/poketch_animation.h"
#include "applications/poketch/poketch_task.h"
#include "bg_window.h"
#include "sys_task_manager.h"
#define NUM_TASK_SLOTS 8
#define STOPWATCH_TASK_SLOTS 8
typedef struct TimerState {
BOOL isActive;
@ -21,7 +22,7 @@ typedef struct TimerState {
typedef struct PoketchStopwatchGraphics {
const TimerState *timerState;
BgConfig *bgConfig;
u32 activeTasks[2 + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + STOPWATCH_TASK_SLOTS];
u32 unused;
PoketchAnimation_SpriteData voltorbSprites;
PoketchAnimation_SpriteData digitSprites;
@ -31,12 +32,12 @@ typedef struct PoketchStopwatchGraphics {
} PoketchStopwatchGraphics;
enum StopwatchGraphicsTask {
TASK_DRAW_APP_SCREEN = 0,
TASK_UPDATE_GRAPHICS = 1,
TASK_FREE_GRAPHICS = 3,
STOPWATCH_GRAPHICS_INIT = 0,
STOPWATCH_GRAPHICS_UPDATE = 1,
STOPWATCH_GRAPHICS_FREE = 3,
};
BOOL PoketchStopwatchGraphics_New(PoketchStopwatchGraphics **graphics, const TimerState *timerState, BgConfig *bgConfig);
BOOL PoketchStopwatchGraphics_New(PoketchStopwatchGraphics **dest, const TimerState *timerState, BgConfig *bgConfig);
void PoketchStopwatchGraphics_Free(PoketchStopwatchGraphics *graphics);
void PoketchStopwatchGraphics_StartTask(PoketchStopwatchGraphics *graphics, enum StopwatchGraphicsTask taskID);
BOOL PoketchStopwatchGraphics_TaskIsNotActive(PoketchStopwatchGraphics *graphics, enum StopwatchGraphicsTask taskID);

View File

@ -28,13 +28,13 @@ BOOL PoketchAnalogWatch_New(AnalogWatchGraphics **dest, const AnalogWatchData *w
AnalogWatchGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(AnalogWatchGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, 8);
PoketchTask_InitActiveTaskList(graphics->activeTasks, ANALOG_WATCH_TASK_SLOTS);
graphics->watchData = watchData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
if (SetupSprites(graphics) == 0) {
if (SetupSprites(graphics) == FALSE) {
Heap_Free(graphics);
return FALSE;
}

View File

@ -46,17 +46,6 @@ static BOOL State_LoadApp(PoketchAnalogWatch *appData);
static BOOL State_UpdateApp(PoketchAnalogWatch *appData);
static BOOL State_UnloadApp(PoketchAnalogWatch *appData);
static const TouchScreenRect sScreenHitBox[] = {
{
.rect = {
.top = POKETCH_SCREEN_MIN_Y,
.bottom = POKETCH_SCREEN_MAX_Y,
.left = POKETCH_SCREEN_MIN_X,
.right = POKETCH_SCREEN_MAX_X,
},
},
};
static void NitroStaticInit(void)
{
PoketchSystem_SetAppFunctions(New, Exit);
@ -82,6 +71,10 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchAnalogWatch *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
static const TouchScreenRect sScreenHitBox[] = {
{ .rect = { .top = POKETCH_SCREEN_MIN_Y, .bottom = POKETCH_SCREEN_MAX_Y, .left = POKETCH_SCREEN_MIN_X, .right = POKETCH_SCREEN_MAX_X } }
};
if (PoketchAnalogWatch_New(&appData->graphics, &appData->watchData, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;

View File

@ -188,7 +188,7 @@ static const struct {
u8 y;
u8 width;
u8 height;
} buttonPositions[] = {
} sButtonPositions[] = {
{ 4, 18, 8, 4 }, // 0
{ 4, 14, 4, 4 }, // 1
{ 8, 14, 4, 4 }, // 2
@ -216,7 +216,7 @@ BOOL PoketchCalculatorGraphics_New(CalculatorGraphics **dest, const CalculatorDa
if (graphics != NULL) {
graphics->calcData = calcState;
graphics->bgConfig = bgConfig;
PoketchTask_InitActiveTaskList(graphics->activeTasks, 8);
PoketchTask_InitActiveTaskList(graphics->activeTasks, CALCULATOR_TASK_SLOTS);
*dest = graphics;
return TRUE;
@ -288,7 +288,7 @@ static void Task_DrawBackground(SysTask *task, void *taskMan)
const CalculatorData *calcState = PoketchTask_GetConstTaskData(taskMan);
CalculatorGraphics *graphics = PoketchTask_GetTaskData(taskMan);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &bgTemplate, 0);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &bgTemplate, BG_TYPE_STATIC);
Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 16, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadTilemapToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 17, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
@ -310,8 +310,8 @@ static void SaveReleasedButtonTiles(CalculatorGraphics *graphics)
for (u32 button = 0; button < NUM_BUTTONS; button++) {
u32 tile = 0;
for (u32 y = buttonPositions[button].y; y < buttonPositions[button].y + buttonPositions[button].height; y++) {
for (u32 x = buttonPositions[button].x; x < buttonPositions[button].x + buttonPositions[button].width; x++) {
for (u32 y = sButtonPositions[button].y; y < sButtonPositions[button].y + sButtonPositions[button].height; y++) {
for (u32 x = sButtonPositions[button].x; x < sButtonPositions[button].x + sButtonPositions[button].width; x++) {
graphics->releasedButtonTiles[button][tile++] = tilemapBuffer[y * POKETCH_WIDTH_TILES + x];
}
}
@ -326,7 +326,7 @@ static void Task_PressButton(SysTask *task, void *taskMan)
PoketchSystem_PlaySoundEffect(SEQ_SE_DP_POKETCH_003);
Bg_LoadToTilemapRect(graphics->bgConfig, BG_LAYER_SUB_2, sPressedButtonTiles[button], buttonPositions[button].x, buttonPositions[button].y, buttonPositions[button].width, buttonPositions[button].height);
Bg_LoadToTilemapRect(graphics->bgConfig, BG_LAYER_SUB_2, sPressedButtonTiles[button], sButtonPositions[button].x, sButtonPositions[button].y, sButtonPositions[button].width, sButtonPositions[button].height);
Bg_CopyTilemapBufferToVRAM(graphics->bgConfig, BG_LAYER_SUB_2);
EndTask(taskMan);
@ -339,7 +339,7 @@ static void Task_ReleaseButton(SysTask *task, void *taskMan)
CalculatorGraphics *graphics = PoketchTask_GetTaskData(taskMan);
Bg_LoadToTilemapRect(graphics->bgConfig, BG_LAYER_SUB_2, graphics->releasedButtonTiles[button], buttonPositions[button].x, buttonPositions[button].y, buttonPositions[button].width, buttonPositions[button].height);
Bg_LoadToTilemapRect(graphics->bgConfig, BG_LAYER_SUB_2, graphics->releasedButtonTiles[button], sButtonPositions[button].x, sButtonPositions[button].y, sButtonPositions[button].width, sButtonPositions[button].height);
Bg_CopyTilemapBufferToVRAM(graphics->bgConfig, BG_LAYER_SUB_2);
EndTask(taskMan);
@ -406,7 +406,6 @@ static void Task_DisplayOperatorAndResult(SysTask *task, void *taskMan)
static void Task_DisplayInvalidValue(SysTask *task, void *taskMan)
{
u32 i;
CalculatorGraphics *graphics = PoketchTask_GetTaskData(taskMan);
for (i = 0; i < CALCULATOR_MAX_DIGITS; i++) {

View File

@ -63,28 +63,6 @@ static void ResetCalculatorState(PoketchCalculator *appData);
static BOOL EvaluateResult(PoketchCalculator *appData, u32 operator);
static void PlayResultSpeciesCry(PoketchCalculator *appData, const CalculatorValue *result);
// clang-format off
static const TouchScreenRect buttonHitboxes[] = {
{ .rect = { .top = 144, .bottom = 175, .left = 32, .right = 95 } }, // 0
{ .rect = { .top = 112, .bottom = 143, .left = 32, .right = 63 } }, // 1
{ .rect = { .top = 112, .bottom = 143, .left = 64, .right = 95 } }, // 2
{ .rect = { .top = 112, .bottom = 143, .left = 96, .right = 127 } }, // 3
{ .rect = { .top = 80, .bottom = 111, .left = 32, .right = 63 } }, // 4
{ .rect = { .top = 80, .bottom = 111, .left = 64, .right = 95 } }, // 5
{ .rect = { .top = 80, .bottom = 111, .left = 96, .right = 127 } }, // 6
{ .rect = { .top = 48, .bottom = 79, .left = 32, .right = 63 } }, // 7
{ .rect = { .top = 48, .bottom = 79, .left = 64, .right = 95 } }, // 8
{ .rect = { .top = 48, .bottom = 79, .left = 96, .right = 127 } }, // 9
{ .rect = { .top = 144, .bottom = 175, .left = 96, .right = 127 } }, // decimal point
{ .rect = { .top = 80, .bottom = 111, .left = 160, .right = 191 } }, // minus
{ .rect = { .top = 80, .bottom = 111, .left = 128, .right = 159 } }, // plus
{ .rect = { .top = 112, .bottom = 143, .left = 128, .right = 159 } }, // times
{ .rect = { .top = 112, .bottom = 143, .left = 160, .right = 191 } }, // divide
{ .rect = { .top = 144, .bottom = 175, .left = 128, .right = 191 } }, // equals
{ .rect = { .top = 48, .bottom = 79, .left = 128, .right = 191 } }, // clear
};
// clang-format on
static void NitroStaticInit(void)
{
PoketchSystem_SetAppFunctions(New, Exit);
@ -108,6 +86,28 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchCalculator *appData, u32 appID, BgConfig *bgConfig)
{
// clang-format off
static const TouchScreenRect sButtonHitboxes[] = {
{ .rect = { .top = 144, .bottom = 175, .left = 32, .right = 95 } }, // 0
{ .rect = { .top = 112, .bottom = 143, .left = 32, .right = 63 } }, // 1
{ .rect = { .top = 112, .bottom = 143, .left = 64, .right = 95 } }, // 2
{ .rect = { .top = 112, .bottom = 143, .left = 96, .right = 127 } }, // 3
{ .rect = { .top = 80, .bottom = 111, .left = 32, .right = 63 } }, // 4
{ .rect = { .top = 80, .bottom = 111, .left = 64, .right = 95 } }, // 5
{ .rect = { .top = 80, .bottom = 111, .left = 96, .right = 127 } }, // 6
{ .rect = { .top = 48, .bottom = 79, .left = 32, .right = 63 } }, // 7
{ .rect = { .top = 48, .bottom = 79, .left = 64, .right = 95 } }, // 8
{ .rect = { .top = 48, .bottom = 79, .left = 96, .right = 127 } }, // 9
{ .rect = { .top = 144, .bottom = 175, .left = 96, .right = 127 } }, // decimal point
{ .rect = { .top = 80, .bottom = 111, .left = 160, .right = 191 } }, // minus
{ .rect = { .top = 80, .bottom = 111, .left = 128, .right = 159 } }, // plus
{ .rect = { .top = 112, .bottom = 143, .left = 128, .right = 159 } }, // times
{ .rect = { .top = 112, .bottom = 143, .left = 160, .right = 191 } }, // divide
{ .rect = { .top = 144, .bottom = 175, .left = 128, .right = 191 } }, // equals
{ .rect = { .top = 48, .bottom = 79, .left = 128, .right = 191 } }, // clear
};
// clang-format on
if (PoketchCalculatorGraphics_New(&appData->graphics, &appData->calcData, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;
@ -125,7 +125,7 @@ static BOOL Init(PoketchCalculator *appData, u32 appID, BgConfig *bgConfig)
return FALSE;
}
appData->buttonManager = PoketchButtonManager_New(buttonHitboxes, NUM_BUTTONS, ButtonCallback, appData, HEAP_ID_POKETCH_APP);
appData->buttonManager = PoketchButtonManager_New(sButtonHitboxes, NUM_BUTTONS, ButtonCallback, appData, HEAP_ID_POKETCH_APP);
if (appData->buttonManager == NULL) {
return FALSE;

View File

@ -30,7 +30,7 @@ BOOL PoketchCounterGraphics_New(CounterGraphics **dest, const CounterData *count
CounterGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(CounterGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, 4);
PoketchTask_InitActiveTaskList(graphics->activeTasks, COUNTER_TASK_SLOTS);
graphics->counterData = counterData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
@ -55,7 +55,7 @@ void PoketchCounterGraphics_Free(CounterGraphics *graphics)
static void SetupSprites(CounterGraphics *graphics, const CounterData *counterData)
{
static const PoketchAnimation_AnimationData buttonAnimData = {
static const PoketchAnimation_AnimationData sButtonAnimData = {
.translation = { FX32_CONST(114), FX32_CONST(128) },
.animIdx = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
@ -63,8 +63,8 @@ static void SetupSprites(CounterGraphics *graphics, const CounterData *counterDa
.priority = 0,
.hasAffineTransform = FALSE,
};
static const PoketchAnimation_AnimationData digitsAnimData = {
.translation = { 0, 0 },
static const PoketchAnimation_AnimationData sDigitsAnimData = {
.translation = { 0 },
.animIdx = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
@ -73,17 +73,17 @@ static void SetupSprites(CounterGraphics *graphics, const CounterData *counterDa
};
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 2, DS_SCREEN_SUB, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 47, DS_SCREEN_SUB, 80 * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 47, DS_SCREEN_SUB, POKETCH_DIGITS_NCGR_NUM_TILES * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
PoketchAnimation_LoadSpriteFromNARC(&graphics->buttonSprites, NARC_INDEX_GRAPHIC__POKETCH, 45, 46, HEAP_ID_POKETCH_APP);
PoketchAnimation_LoadSpriteFromNARC(&graphics->digitSprites, NARC_INDEX_GRAPHIC__POKETCH, 3, 4, HEAP_ID_POKETCH_APP);
graphics->buttonAnimation = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &buttonAnimData, &graphics->buttonSprites);
graphics->buttonAnimation = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &sButtonAnimData, &graphics->buttonSprites);
PoketchAnimation_SetSpriteCharNo(graphics->buttonAnimation, 80);
PoketchAnimation_SetSpriteCharNo(graphics->buttonAnimation, POKETCH_DIGITS_NCGR_NUM_TILES);
for (int i = 0; i < NUM_DIGITS; i++) {
graphics->digitsAnimation[i] = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &digitsAnimData, &graphics->digitSprites);
graphics->digitsAnimation[i] = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &sDigitsAnimData, &graphics->digitSprites);
PoketchAnimation_SetSpritePosition(graphics->digitsAnimation[i], FX32_CONST(88) + (FX32_CONST(16) * i), FX32_CONST(64));
}
@ -103,10 +103,10 @@ static void UnloadSprites(CounterGraphics *graphics)
}
static const PoketchTask sCounterGraphicsTasks[] = {
{ COUNTER_GRAPHICS_INIT, Task_DrawBackground, 0x0 },
{ COUNTER_GRAPHICS_FREE, Task_FreeBackground, 0x0 },
{ COUNTER_GRAPHICS_UPDATE_BUTTON, Task_UpdateButtonSprite, 0x0 },
{ COUNTER_GRAPHICS_UPDATE_VALUE, Task_UpdateValue, 0x0 },
{ COUNTER_GRAPHICS_INIT, Task_DrawBackground, 0 },
{ COUNTER_GRAPHICS_FREE, Task_FreeBackground, 0 },
{ COUNTER_GRAPHICS_UPDATE_BUTTON, Task_UpdateButtonSprite, 0 },
{ COUNTER_GRAPHICS_UPDATE_VALUE, Task_UpdateValue, 0 },
{ 0 }
};

View File

@ -67,7 +67,7 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchCounter *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
static const TouchScreenRect buttonHitBox[] = {
static const TouchScreenRect sButtonHitBox[] = {
{ .rect = { .top = 100, .bottom = 156, .left = 82, .right = 146 } },
};
@ -83,7 +83,7 @@ static BOOL Init(PoketchCounter *appData, PoketchSystem *poketchSys, BgConfig *b
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->buttonManager = PoketchButtonManager_New(buttonHitBox, NELEMS(buttonHitBox), ButtonCallback, appData, HEAP_ID_POKETCH_APP);
appData->buttonManager = PoketchButtonManager_New(sButtonHitBox, NELEMS(sButtonHitBox), ButtonCallback, appData, HEAP_ID_POKETCH_APP);
appData->buttonState = BUTTON_MANAGER_STATE_NULL;
appData->poketchSys = poketchSys;

View File

@ -1,7 +1,6 @@
#include "applications/poketch/daycare_checker/graphics.h"
#include <nitro.h>
#include <string.h>
#include "constants/graphics.h"
#include "generated/sdat.h"
@ -21,34 +20,36 @@
static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *daycareStatus);
static void UnloadSprites(DaycareCheckerGraphics *graphics);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppBackground(SysTask *task, void *taskMan);
static void Task_FreeBackground(SysTask *task, void *taskMan);
static void Task_ReloadDaycareState(SysTask *task, void *taskMan);
static void TriggerMosaicUpdate(DaycareCheckerGraphics *graphics);
static void Task_UpdateMosaicSize(SysTask *task, void *taskMan);
static void TriggerMosaicUpdate(DaycareCheckerGraphics *graphics);
static void LoadDaycareMonIcons(u32 offset, const DaycareStatus *daycareStatus);
static void DrawSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *daycareStatus);
static void SetLevelSprites(PoketchAnimation_AnimatedSpriteData **digitSprites, u32 level);
static void SetGenderSprites(PoketchAnimation_AnimatedSpriteData *genderSymbol, enum Gender gender);
BOOL DaycareCheckerGraphics_New(DaycareCheckerGraphics **graphics, const DaycareStatus *daycareStatus, BgConfig *bgConfig)
BOOL PoketchDaycareCheckerGraphics_New(DaycareCheckerGraphics **dest, const DaycareStatus *daycareStatus, BgConfig *bgConfig)
{
DaycareCheckerGraphics *daycareGraphics = (DaycareCheckerGraphics *)Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(DaycareCheckerGraphics));
DaycareCheckerGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(DaycareCheckerGraphics));
if (daycareGraphics != NULL) {
PoketchTask_InitActiveTaskList(daycareGraphics->activeTasks, NUM_TASK_SLOTS);
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, DAYCARE_CHECKER_TASK_SLOTS);
daycareGraphics->dayCareSummary = daycareStatus;
daycareGraphics->bgConfig = PoketchGraphics_GetBgConfig();
daycareGraphics->animMan = PoketchGraphics_GetAnimationManager();
daycareGraphics->updateMosaic = FALSE;
daycareGraphics->mosaicTask = SysTask_ExecuteAfterVBlank(Task_UpdateMosaicSize, daycareGraphics, 0);
graphics->dayCareSummary = daycareStatus;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
graphics->updateMosaic = FALSE;
graphics->mosaicTask = SysTask_ExecuteAfterVBlank(Task_UpdateMosaicSize, graphics, 0);
SetupSprites(daycareGraphics, daycareStatus);
SetupSprites(graphics, daycareStatus);
if (daycareGraphics->bgConfig != NULL) {
*graphics = daycareGraphics;
if (graphics->bgConfig != NULL) {
*dest = graphics;
return TRUE;
}
}
@ -56,7 +57,7 @@ BOOL DaycareCheckerGraphics_New(DaycareCheckerGraphics **graphics, const Daycare
return FALSE;
}
void DaycareCheckerGraphics_Free(DaycareCheckerGraphics *graphics)
void PoketchDaycareCheckerGraphics_Free(DaycareCheckerGraphics *graphics)
{
if (graphics != NULL) {
UnloadSprites(graphics);
@ -71,7 +72,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(56), FX32_CONST(128) },
.animIdx = 7,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = TRUE,
@ -79,7 +80,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(168), FX32_CONST(128) },
.animIdx = 6,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = TRUE,
@ -87,7 +88,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(112), FX32_CONST(136) },
.animIdx = 4,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = TRUE,
@ -95,7 +96,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(48), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -103,7 +104,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(64), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -111,7 +112,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(80), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -119,7 +120,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(152), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -127,7 +128,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(168), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -135,7 +136,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(184), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -143,7 +144,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(96), FX32_CONST(40) },
.animIdx = 10,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -151,7 +152,7 @@ static void SetupSprites(DaycareCheckerGraphics *graphics, const DaycareStatus *
{
.translation = { FX32_CONST(200), FX32_CONST(40) },
.animIdx = 10,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = FALSE,
@ -197,18 +198,18 @@ static void UnloadSprites(DaycareCheckerGraphics *graphics)
}
static const PoketchTask daycareTasks[] = {
{ TASK_DRAW_APP_BACKGROUND, Task_DrawAppBackground, 0x0 },
{ TASK_FREE_BACKGROUND, Task_FreeBackground, 0x0 },
{ TASK_RELOAD_DAYCARE_STATE, Task_ReloadDaycareState, 0x0 },
{ DAYCARE_CHECKER_GRAPHICS_INIT, Task_DrawAppBackground, 0 },
{ DAYCARE_CHECKER_GRAPHICS_FREE, Task_FreeBackground, 0 },
{ DAYCARE_CHECKER_GRAPHICS_RELOAD, Task_ReloadDaycareState, 0 },
{ 0 }
};
void PoketchDaycareCheckerGraphics_StartTask(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTasks taskID)
void PoketchDaycareCheckerGraphics_StartTask(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTask taskID)
{
PoketchTask_Start(daycareTasks, taskID, graphics, graphics->dayCareSummary, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchDaycareCheckerGraphics_TaskIsNotActive(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTasks taskID)
BOOL PoketchDaycareCheckerGraphics_TaskIsNotActive(DaycareCheckerGraphics *graphics, enum DaycareGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}
@ -243,7 +244,7 @@ static void Task_DrawAppBackground(SysTask *task, void *taskMan)
GXSDispCnt dispCnt;
DaycareCheckerGraphics *graphics = PoketchTask_GetTaskData(taskMan);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &bgTemplate, 0);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &bgTemplate, BG_TYPE_STATIC);
Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 81, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadTilemapToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 80, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
@ -269,7 +270,7 @@ static void Task_FreeBackground(SysTask *task, void *taskMan)
PoketchTask_IncrementState(taskMan);
break;
case 1:
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(graphics, TASK_RELOAD_DAYCARE_STATE)) {
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(graphics, DAYCARE_CHECKER_GRAPHICS_RELOAD)) {
G2S_SetBGMosaicSize(0, 0);
G2S_SetOBJMosaicSize(0, 0);
Bg_FreeTilemapBuffer(graphics->bgConfig, BG_LAYER_SUB_2);
@ -306,7 +307,7 @@ static void Task_ReloadDaycareState(SysTask *task, void *taskMan)
break;
}
if (++(graphics->mosaicProgress) >= 4) {
if (++graphics->mosaicProgress >= 4) {
graphics->mosaicProgress = 0;
graphics->mosaicSize--;

View File

@ -17,33 +17,33 @@
#include "touch_screen.h"
typedef struct PoketchDaycare {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
DaycareStatus daycareStatus;
DaycareCheckerGraphics *graphics;
PoketchSystem *poketchSys;
Daycare *daycareSaveData;
} PoketchDaycare;
} PoketchDaycareChecker;
enum DaycareTasks {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum DaycareCheckerState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
static void NitroStaticInit(void);
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static BOOL Init(PoketchDaycare *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static void Free(PoketchDaycare *appData);
static BOOL Init(PoketchDaycareChecker *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static void Free(PoketchDaycareChecker *appData);
static void Task_Main(SysTask *task, void *appData);
static void Exit(void *param0);
static void ChangeActiveTask(PoketchDaycare *appData, u32 taskID);
static BOOL Task_LoadApp(PoketchDaycare *appData);
static BOOL Task_UpdateApp(PoketchDaycare *appData);
static BOOL Task_UnloadApp(PoketchDaycare *appData);
static BOOL ScreenIsPressed(PoketchDaycare *appData);
static void Exit(void *appData);
static void ChangeState(PoketchDaycareChecker *appData, u32 newState);
static BOOL State_LoadApp(PoketchDaycareChecker *appData);
static BOOL State_UpdateApp(PoketchDaycareChecker *appData);
static BOOL State_UnloadApp(PoketchDaycareChecker *appData);
static BOOL ScreenIsPressed(PoketchDaycareChecker *appData);
static void LoadDaycareSummary(DaycareStatus *daycareStatus, Daycare *daycare);
static void NitroStaticInit(void)
@ -53,7 +53,7 @@ static void NitroStaticInit(void)
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
PoketchDaycare *daycareApp = (PoketchDaycare *)Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchDaycare));
PoketchDaycareChecker *daycareApp = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchDaycareChecker));
if (daycareApp != NULL) {
if (Init(daycareApp, poketchSys, bgConfig, appID)) {
@ -67,15 +67,15 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
return FALSE;
}
static BOOL Init(PoketchDaycare *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
static BOOL Init(PoketchDaycareChecker *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
appData->daycareSaveData = SaveData_GetDaycare(PoketchSystem_GetSaveData(poketchSys));
LoadDaycareSummary(&appData->daycareStatus, appData->daycareSaveData);
if (DaycareCheckerGraphics_New(&appData->graphics, &appData->daycareStatus, bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->taskFuncState = 0;
if (PoketchDaycareCheckerGraphics_New(&appData->graphics, &appData->daycareStatus, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->poketchSys = poketchSys;
@ -85,24 +85,24 @@ static BOOL Init(PoketchDaycare *appData, PoketchSystem *poketchSys, BgConfig *b
return FALSE;
}
static void Free(PoketchDaycare *appData)
static void Free(PoketchDaycareChecker *appData)
{
DaycareCheckerGraphics_Free(appData->graphics);
PoketchDaycareCheckerGraphics_Free(appData->graphics);
Heap_Free(appData);
}
static void Task_Main(SysTask *task, void *appData)
{
static BOOL (*const stateFuncs[])(PoketchDaycare *) = {
Task_LoadApp,
Task_UpdateApp,
Task_UnloadApp
static BOOL (*const stateFuncs[])(PoketchDaycareChecker *) = {
State_LoadApp,
State_UpdateApp,
State_UnloadApp
};
PoketchDaycare *daycareChecker = appData;
PoketchDaycareChecker *daycareChecker = appData;
if (daycareChecker->activeTask < NELEMS(stateFuncs)) {
if (stateFuncs[daycareChecker->activeTask](daycareChecker)) {
if (daycareChecker->state < NELEMS(stateFuncs)) {
if (stateFuncs[daycareChecker->state](daycareChecker)) {
Free(daycareChecker);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(daycareChecker->poketchSys);
@ -112,31 +112,31 @@ static void Task_Main(SysTask *task, void *appData)
static void Exit(void *appData)
{
((PoketchDaycare *)appData)->shouldExit = 1;
((PoketchDaycareChecker *)appData)->shouldExit = TRUE;
}
static void ChangeActiveTask(PoketchDaycare *appData, u32 taskID)
static void ChangeState(PoketchDaycareChecker *appData, u32 newState)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = newState;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL Task_LoadApp(PoketchDaycare *appData)
static BOOL State_LoadApp(PoketchDaycareChecker *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, TASK_DRAW_APP_BACKGROUND);
appData->taskFuncState++;
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, DAYCARE_CHECKER_GRAPHICS_INIT);
appData->subState++;
break;
case 1:
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(appData->graphics, TASK_DRAW_APP_BACKGROUND)) {
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(appData->graphics, DAYCARE_CHECKER_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeActiveTask(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -144,24 +144,24 @@ static BOOL Task_LoadApp(PoketchDaycare *appData)
return FALSE;
}
static BOOL Task_UpdateApp(PoketchDaycare *appData)
static BOOL State_UpdateApp(PoketchDaycareChecker *appData)
{
if (appData->shouldExit) {
ChangeActiveTask(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
return FALSE;
}
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
if (ScreenIsPressed(appData)) {
LoadDaycareSummary(&appData->daycareStatus, appData->daycareSaveData);
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, TASK_RELOAD_DAYCARE_STATE);
appData->taskFuncState++;
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, DAYCARE_CHECKER_GRAPHICS_RELOAD);
appData->subState++;
}
break;
case 1:
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(appData->graphics, TASK_RELOAD_DAYCARE_STATE)) {
appData->taskFuncState = 0;
if (PoketchDaycareCheckerGraphics_TaskIsNotActive(appData->graphics, DAYCARE_CHECKER_GRAPHICS_RELOAD)) {
appData->subState = 0;
}
break;
}
@ -169,12 +169,12 @@ static BOOL Task_UpdateApp(PoketchDaycare *appData)
return FALSE;
}
static BOOL Task_UnloadApp(PoketchDaycare *appData)
static BOOL State_UnloadApp(PoketchDaycareChecker *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, TASK_FREE_BACKGROUND);
appData->taskFuncState++;
PoketchDaycareCheckerGraphics_StartTask(appData->graphics, DAYCARE_CHECKER_GRAPHICS_FREE);
appData->subState++;
break;
case 1:
if (PoketchDaycareCheckerGraphics_NoActiveTasks(appData->graphics)) {
@ -186,7 +186,7 @@ static BOOL Task_UnloadApp(PoketchDaycare *appData)
return FALSE;
}
static BOOL ScreenIsPressed(PoketchDaycare *apData)
static BOOL ScreenIsPressed(PoketchDaycareChecker *apData)
{
if (PoketechSystem_IsRunningTask(apData->poketchSys) == FALSE) {
u32 x, y;

View File

@ -1,7 +1,6 @@
#include "applications/poketch/digital_watch/graphics.h"
#include <nitro.h>
#include <string.h>
#include "applications/poketch/poketch_graphics.h"
#include "applications/poketch/poketch_task.h"
@ -12,36 +11,38 @@
#include "sys_task_manager.h"
static void CopyDigitTilemap(const u16 *rawScreenData, u16 *dst);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppScreen(SysTask *sysTask, void *taskMan);
static void Task_UpdateClockDigits(SysTask *sysTask, void *taskMan);
static void Task_ToggleBacklightPalette(SysTask *sysTask, void *taskMan);
static void Task_FreeGraphics(SysTask *sysTask, void *taskMan);
static void DrawClockDigits(PoketchDigitalWatchGraphics *graphics);
BOOL PoketchDigitalWatchGraphics_New(PoketchDigitalWatchGraphics **graphics, const WatchData *watchData, BgConfig *bgConfig)
BOOL PoketchDigitalWatchGraphics_New(PoketchDigitalWatchGraphics **dest, const DigitalWatchData *watchData, BgConfig *bgConfig)
{
PoketchDigitalWatchGraphics *digitalWatchGraphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchDigitalWatchGraphics));
PoketchDigitalWatchGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchDigitalWatchGraphics));
if (digitalWatchGraphics != NULL) {
if (graphics != NULL) {
NNSG2dScreenData *screenData;
PoketchTask_InitActiveTaskList(digitalWatchGraphics->activeTasks, NUM_TASK_SLOTS);
PoketchTask_InitActiveTaskList(graphics->activeTasks, DIGITAL_WATCH_TASK_SLOTS);
digitalWatchGraphics->watchData = watchData;
digitalWatchGraphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->watchData = watchData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
void *nscrBuffer = Graphics_GetScrnData(NARC_INDEX_GRAPHIC__POKETCH, POKETCH_CLOCK_DIGITS_TILEMAP_IDX, TRUE, &screenData, HEAP_ID_POKETCH_APP);
if (nscrBuffer == NULL) {
Heap_Free(digitalWatchGraphics);
Heap_Free(graphics);
return FALSE;
}
CopyDigitTilemap((const u16 *)(screenData->rawData), digitalWatchGraphics->digitsTilemap);
CopyDigitTilemap((const u16 *)screenData->rawData, graphics->digitsTilemap);
Heap_Free(nscrBuffer);
*graphics = digitalWatchGraphics;
*dest = graphics;
return TRUE;
}
@ -71,19 +72,19 @@ void PoketchDigitalWatchGraphics_Free(PoketchDigitalWatchGraphics *graphics)
}
static const PoketchTask sDisplayTasks[] = {
{ TASK_DRAW_APP_SCREEN, Task_DrawAppScreen, 0x0 },
{ TASK_UPDATE_WATCH_DIGITS, Task_UpdateClockDigits, 0x0 },
{ TASK_TOGGLE_BACKLIGHT, Task_ToggleBacklightPalette, 0x0 },
{ TASK_FREE_GRAPHICS, Task_FreeGraphics, 0x0 },
{ DIGITAL_WATCH_GRAPHICS_INIT, Task_DrawAppScreen, 0 },
{ DIGITAL_WATCH_GRAPHICS_UPDATE_DIGITS, Task_UpdateClockDigits, 0 },
{ DIGITAL_WATCH_GRAPHICS_TOGGLE_BACKLIGHT, Task_ToggleBacklightPalette, 0 },
{ DIGITAL_WATCH_GRAPHICS_FREE, Task_FreeGraphics, 0 },
{ 0 }
};
void PoketchDigitalWatchGraphics_StartTask(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTasks taskID)
void PoketchDigitalWatchGraphics_StartTask(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTask taskID)
{
PoketchTask_Start(sDisplayTasks, taskID, graphics, graphics->watchData, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchDigitalWatchGraphics_TaskIsNotActive(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTasks taskID)
BOOL PoketchDigitalWatchGraphics_TaskIsNotActive(PoketchDigitalWatchGraphics *graphics, enum DigitalWatchGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}

View File

@ -1,6 +1,5 @@
#include <nitro.h>
#include <nitro/sinit.h>
#include <string.h>
#include "applications/poketch/digital_watch/graphics.h"
#include "applications/poketch/poketch_button.h"
@ -13,15 +12,9 @@
#include "sys_task_manager.h"
#include "touch_screen.h"
// Touch Screen Boundaries
#define BACKLIGHT_BUTTON_MIN_Y 0x10
#define BACKLIGHT_BUTTON_MAX_Y 0xAF
#define BACKLIGHT_BUTTON_MIN_X 0x10
#define BACKLIGHT_BUTTON_MAX_X 0xCF
typedef struct PoketchDigitalWatch {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
u8 unused_0;
u8 unused_1;
@ -30,15 +23,15 @@ typedef struct PoketchDigitalWatch {
u8 backlightChange;
u8 unused_2[8];
PoketchButtonManager *buttonManager;
WatchData watchData;
DigitalWatchData watchData;
PoketchDigitalWatchGraphics *graphics;
PoketchSystem *poketchSys;
} PoketchDigitalWatch;
enum DigitalWatchTasks {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum DigitalWatchState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
static void NitroStaticInit(void);
@ -48,7 +41,7 @@ static BOOL Init(PoketchDigitalWatch *appData, PoketchSystem *poketchSys, BgConf
static void Free(PoketchDigitalWatch *appData);
static void Exit(void *appData);
static void ChangeState(PoketchDigitalWatch *appData, enum DigitalWatchTasks taskID);
static void ChangeState(PoketchDigitalWatch *appData, enum DigitalWatchState newState);
static void Task_Main(SysTask *task, void *taskManager);
static BOOL State_LoadApp(PoketchDigitalWatch *appData);
static BOOL State_UpdateApp(PoketchDigitalWatch *appData);
@ -56,10 +49,6 @@ static BOOL State_UnloadApp(PoketchDigitalWatch *appData);
static void ToggleBacklight(u32 btnNumber, u32 buttonState, u32 touchState, void *appDataIn);
static const TouchScreenHitTable sButtonHitTable[] = {
{ BACKLIGHT_BUTTON_MIN_Y, BACKLIGHT_BUTTON_MAX_Y, BACKLIGHT_BUTTON_MIN_X, BACKLIGHT_BUTTON_MAX_X }
};
static void NitroStaticInit(void)
{
PoketchSystem_SetAppFunctions(New, Exit);
@ -84,15 +73,19 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchDigitalWatch *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
if (PoketchDigitalWatchGraphics_New(&(appData->graphics), &(appData->watchData), bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->taskFuncState = 0;
static const TouchScreenRect sButtonHitTable[] = {
{ .rect = { .top = POKETCH_SCREEN_MIN_Y, .bottom = POKETCH_SCREEN_MAX_Y, .left = POKETCH_SCREEN_MIN_X, .right = POKETCH_SCREEN_MAX_X } }
};
if (PoketchDigitalWatchGraphics_New(&appData->graphics, &appData->watchData, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->unused_0 = 1;
appData->backlightChange = FALSE;
appData->watchData.backlightActive = FALSE;
GetCurrentTime(&(appData->watchData.time));
GetCurrentTime(&appData->watchData.time);
if (appData->watchData.time.hour >= 24) {
appData->watchData.time.hour %= 24;
@ -127,7 +120,7 @@ static void Free(PoketchDigitalWatch *appData)
static void Task_Main(SysTask *task, void *callbackData)
{
static BOOL (*const funcArray[])(PoketchDigitalWatch *) = {
static BOOL (*const stateFuncs[])(PoketchDigitalWatch *) = {
State_LoadApp,
State_UpdateApp,
State_UnloadApp,
@ -135,10 +128,10 @@ static void Task_Main(SysTask *task, void *callbackData)
PoketchDigitalWatch *appData = callbackData;
if (appData->activeTask < NELEMS(funcArray)) {
if (appData->state < NELEMS(stateFuncs)) {
PoketechSystem_UpdateButtonManager(appData->poketchSys, appData->buttonManager);
if (funcArray[appData->activeTask](appData)) {
if (stateFuncs[appData->state](appData)) {
Free(appData);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(appData->poketchSys);
@ -156,39 +149,39 @@ static void ToggleBacklight(u32 btnNumber, u32 buttonState, u32 touchState, void
PoketchDigitalWatch *appData = appDataIn;
switch (touchState) {
case TRUE:
case BUTTON_TOUCH_PRESSED:
appData->watchData.backlightActive = TRUE;
appData->backlightChange = TRUE;
break;
case FALSE:
case BUTTON_TOUCH_RELEASED:
appData->watchData.backlightActive = FALSE;
appData->backlightChange = TRUE;
break;
}
}
static void ChangeState(PoketchDigitalWatch *appData, enum DigitalWatchTasks taskID)
static void ChangeState(PoketchDigitalWatch *appData, enum DigitalWatchState newState)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = newState;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL State_LoadApp(PoketchDigitalWatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDigitalWatchGraphics_StartTask(appData->graphics, TASK_DRAW_APP_SCREEN);
appData->taskFuncState++;
PoketchDigitalWatchGraphics_StartTask(appData->graphics, DIGITAL_WATCH_GRAPHICS_INIT);
appData->subState++;
break;
case 1:
if (PoketchDigitalWatchGraphics_TaskIsNotActive(appData->graphics, TASK_DRAW_APP_SCREEN)) {
if (PoketchDigitalWatchGraphics_TaskIsNotActive(appData->graphics, DIGITAL_WATCH_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeState(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -199,22 +192,22 @@ static BOOL State_LoadApp(PoketchDigitalWatch *appData)
static BOOL State_UpdateApp(PoketchDigitalWatch *appData)
{
if (appData->shouldExit) {
ChangeState(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
return FALSE;
}
if (appData->backlightChange) {
appData->backlightChange = FALSE;
PoketchDigitalWatchGraphics_StartTask(appData->graphics, TASK_TOGGLE_BACKLIGHT);
PoketchDigitalWatchGraphics_StartTask(appData->graphics, DIGITAL_WATCH_GRAPHICS_TOGGLE_BACKLIGHT);
}
if (PoketchDigitalWatchGraphics_TaskIsNotActive(appData->graphics, TASK_UPDATE_WATCH_DIGITS)) {
if (PoketchDigitalWatchGraphics_TaskIsNotActive(appData->graphics, DIGITAL_WATCH_GRAPHICS_UPDATE_DIGITS)) {
appData->minute = appData->watchData.time.minute;
appData->hour = appData->watchData.time.hour;
GetCurrentTime(&(appData->watchData.time));
GetCurrentTime(&appData->watchData.time);
if ((appData->minute != appData->watchData.time.minute) || (appData->hour != appData->watchData.time.hour)) {
PoketchDigitalWatchGraphics_StartTask(appData->graphics, TASK_UPDATE_WATCH_DIGITS);
PoketchDigitalWatchGraphics_StartTask(appData->graphics, DIGITAL_WATCH_GRAPHICS_UPDATE_DIGITS);
}
}
@ -223,10 +216,10 @@ static BOOL State_UpdateApp(PoketchDigitalWatch *appData)
static BOOL State_UnloadApp(PoketchDigitalWatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDigitalWatchGraphics_StartTask(appData->graphics, TASK_FREE_GRAPHICS);
appData->taskFuncState++;
PoketchDigitalWatchGraphics_StartTask(appData->graphics, DIGITAL_WATCH_GRAPHICS_FREE);
appData->subState++;
break;
case 1:

View File

@ -13,23 +13,24 @@
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawBackground(SysTask *task, void *taskMan);
static void GenerateDotTiles(BgConfig *bgConfig);
static void Task_UpdateCanvas(SysTask *task, void *taskMan);
static void Task_FreeBackground(SysTask *task, void *taskMan);
static void GenerateDotTiles(BgConfig *bgConfig);
static void UpdateTilemap(BgConfig *bgConfig, const DotArt *dotArt);
BOOL PoketchDotArtistGraphics_New(DotArtistGraphics **graphics, const DotArt *dotArt, BgConfig *bgConfig)
BOOL PoketchDotArtistGraphics_New(DotArtistGraphics **dest, const DotArt *dotArt, BgConfig *bgConfig)
{
DotArtistGraphics *dotArtistGraphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(DotArtistGraphics));
DotArtistGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(DotArtistGraphics));
if (dotArtistGraphics != NULL) {
PoketchTask_InitActiveTaskList(dotArtistGraphics->activeTasks, NUM_TASK_SLOTS);
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, DOT_ARTIST_TASK_SLOTS);
dotArtistGraphics->dotArt = dotArt;
dotArtistGraphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->dotArt = dotArt;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
if (dotArtistGraphics->bgConfig != NULL) {
*graphics = dotArtistGraphics;
if (graphics->bgConfig != NULL) {
*dest = graphics;
return TRUE;
}
}
@ -45,18 +46,18 @@ void PoketchDotArtistGraphics_Free(DotArtistGraphics *graphics)
}
static const PoketchTask sDotArtistGraphicsTasks[] = {
{ DOT_ARTIST_GRAPHICS_INIT, Task_DrawBackground, 0x0 },
{ DOT_ARTIST_GRAPHICS_UPDATE, Task_UpdateCanvas, 0x0 },
{ DOT_ARTIST_GRAPHICS_FREE, Task_FreeBackground, 0x0 },
{ DOT_ARTIST_GRAPHICS_INIT, Task_DrawBackground, 0 },
{ DOT_ARTIST_GRAPHICS_UPDATE, Task_UpdateCanvas, 0 },
{ DOT_ARTIST_GRAPHICS_FREE, Task_FreeBackground, 0 },
{ 0 }
};
void PoketchDotArtistGraphics_StartTask(DotArtistGraphics *graphics, enum DotArtistGraphicsTasks taskID)
void PoketchDotArtistGraphics_StartTask(DotArtistGraphics *graphics, enum DotArtistGraphicsTask taskID)
{
PoketchTask_Start(sDotArtistGraphicsTasks, taskID, graphics, graphics->dotArt, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchDotArtistGraphics_TaskIsNotActive(DotArtistGraphics *graphics, enum DotArtistGraphicsTasks taskID)
BOOL PoketchDotArtistGraphics_TaskIsNotActive(DotArtistGraphics *graphics, enum DotArtistGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}

View File

@ -14,41 +14,43 @@
#define PACKED_SIZE ((CANVAS_WIDTH * CANVAS_HEIGHT) / 4)
typedef struct PoketchDotArtist {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
u32 x;
u32 y;
DotArt state;
DotArt dotArt;
DotArtistGraphics *graphics;
PoketchSystem *poketchSys;
u8 packedData[PACKED_SIZE];
} PoketchDotArtist;
enum DotArtistTasks {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum DotArtistState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
static void NitroStaticInit(void);
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static BOOL Init(PoketchDotArtist *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static void Free(PoketchDotArtist *appData);
static void Exit(void *appData);
static void SetupDotArtGrid(PoketchDotArtist *appData, DotArt *dotArt);
static inline u8 LoadDot(const u8 *packedData, int index);
static inline void SaveDot(u8 *packedData, int index, int value);
static void LoadDotArtGrid(PoketchDotArtist *appData, DotArt *dotArt, Poketch *poketch);
static void SaveDotArtGrid(PoketchDotArtist *appData, DotArt *dotArt, Poketch *poketch);
static void InitDotArtGrid(DotArt *dotArt);
static void Free(PoketchDotArtist *appData);
static void SaveCallback(void *appData);
static void Task_Main(SysTask *task, void *appData);
static void Exit(void *appData);
static void ChangeActiveTask(PoketchDotArtist *appData, enum DotArtistTasks taskID);
static BOOL Task_LoadApp(PoketchDotArtist *appData);
static BOOL Task_UpdateApp(PoketchDotArtist *appData);
static BOOL Task_UnloadApp(PoketchDotArtist *appData);
static void ChangeState(PoketchDotArtist *appData, enum DotArtistState newState);
static BOOL State_LoadApp(PoketchDotArtist *appData);
static BOOL State_UpdateApp(PoketchDotArtist *appData);
static BOOL State_UnloadApp(PoketchDotArtist *appData);
static void NitroStaticInit(void)
{
@ -77,11 +79,11 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchDotArtist *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
appData->poketchSys = poketchSys;
SetupDotArtGrid(appData, &appData->state);
SetupDotArtGrid(appData, &appData->dotArt);
if (PoketchDotArtistGraphics_New(&appData->graphics, &appData->state, bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->taskFuncState = 0;
if (PoketchDotArtistGraphics_New(&appData->graphics, &appData->dotArt, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->x = CANVAS_WIDTH + 1;
appData->y = CANVAS_HEIGHT + 1;
@ -180,7 +182,7 @@ static void InitDotArtGrid(DotArt *dotArt)
static void Free(PoketchDotArtist *appData)
{
SaveDotArtGrid(appData, &appData->state, PoketchSystem_GetPoketchData(appData->poketchSys));
SaveDotArtGrid(appData, &appData->dotArt, PoketchSystem_GetPoketchData(appData->poketchSys));
PoketchDotArtistGraphics_Free(appData->graphics);
Heap_Free(appData);
@ -189,21 +191,21 @@ static void Free(PoketchDotArtist *appData)
static void SaveCallback(void *appData)
{
PoketchDotArtist *dotArtist = appData;
SaveDotArtGrid(dotArtist, &dotArtist->state, PoketchSystem_GetPoketchData(dotArtist->poketchSys));
SaveDotArtGrid(dotArtist, &dotArtist->dotArt, PoketchSystem_GetPoketchData(dotArtist->poketchSys));
}
static void Task_Main(SysTask *task, void *appData)
{
static BOOL (*const stateFuncs[])(PoketchDotArtist *) = {
Task_LoadApp,
Task_UpdateApp,
Task_UnloadApp
State_LoadApp,
State_UpdateApp,
State_UnloadApp
};
PoketchDotArtist *dotArtist = appData;
if (dotArtist->activeTask < NELEMS(stateFuncs)) {
if (stateFuncs[dotArtist->activeTask](dotArtist)) {
if (dotArtist->state < NELEMS(stateFuncs)) {
if (stateFuncs[dotArtist->state](dotArtist)) {
Free(dotArtist);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(dotArtist->poketchSys);
@ -216,28 +218,28 @@ static void Exit(void *appData)
((PoketchDotArtist *)appData)->shouldExit = TRUE;
}
static void ChangeActiveTask(PoketchDotArtist *appData, enum DotArtistTasks taskID)
static void ChangeState(PoketchDotArtist *appData, enum DotArtistState newState)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = newState;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL Task_LoadApp(PoketchDotArtist *appData)
static BOOL State_LoadApp(PoketchDotArtist *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDotArtistGraphics_StartTask(appData->graphics, DOT_ARTIST_GRAPHICS_INIT);
appData->taskFuncState++;
appData->subState++;
break;
case 1:
if (PoketchDotArtistGraphics_TaskIsNotActive(appData->graphics, DOT_ARTIST_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeActiveTask(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -245,10 +247,10 @@ static BOOL Task_LoadApp(PoketchDotArtist *appData)
return FALSE;
}
static BOOL Task_UpdateApp(PoketchDotArtist *appData)
static BOOL State_UpdateApp(PoketchDotArtist *appData)
{
if (appData->shouldExit) {
ChangeActiveTask(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
return FALSE;
}
@ -263,9 +265,9 @@ static BOOL Task_UpdateApp(PoketchDotArtist *appData)
if ((x < CANVAS_WIDTH) && (y < CANVAS_HEIGHT)) {
if (((appData->x != x) || (appData->y != y)) || (TouchScreen_Tapped() == TRUE)) {
appData->state.dots[y][x]++;
if (appData->state.dots[y][x] > 4) {
appData->state.dots[y][x] = 1;
appData->dotArt.dots[y][x]++;
if (appData->dotArt.dots[y][x] > 4) {
appData->dotArt.dots[y][x] = 1;
}
appData->x = x;
@ -281,12 +283,12 @@ static BOOL Task_UpdateApp(PoketchDotArtist *appData)
return FALSE;
}
static BOOL Task_UnloadApp(PoketchDotArtist *appData)
static BOOL State_UnloadApp(PoketchDotArtist *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchDotArtistGraphics_StartTask(appData->graphics, DOT_ARTIST_GRAPHICS_FREE);
appData->taskFuncState++;
appData->subState++;
break;
case 1:
if (PoketchDotArtistGraphics_NoActiveTasks(appData->graphics)) {

View File

@ -30,7 +30,7 @@ BOOL PoketchDowsingMachineGraphics_New(DowsingMachineGraphics **dest, const Dows
DowsingMachineGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(DowsingMachineGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, 8);
PoketchTask_InitActiveTaskList(graphics->activeTasks, DOWSING_MACHINE_TASK_SLOTS);
graphics->dowsingData = dowsingData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();

View File

@ -48,8 +48,8 @@ enum IconActions {
static void PrintDebugLog(const char *text, ...);
static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void SetupIconMovement(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void SetupIconMovement(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void SetupTapState(FriendshipCheckerGraphics *graphics);
static void SetRandomVelocity(VecFx32 *velocity);
@ -59,11 +59,11 @@ static void Task_UpdateGraphics(SysTask *task, void *taskMan);
static void Task_FreeBackground(SysTask *task, void *taskMan);
static void UpdateTapState(FriendshipCheckerGraphics *graphics, enum TapState newTapState);
static void TapStateIdle(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void TapStateFirstTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void TapStateHeldTooLong(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void TapStateReleasedFirst(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void TapStateDoubleTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void TapStateIdle(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void TapStateFirstTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void TapStateHeldTooLong(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void TapStateReleasedFirst(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void TapStateDoubleTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void TriggerJumpSequence(FriendshipCheckerGraphics *graphics);
static void ShowHeartSprite(FriendshipCheckerGraphics *graphics, int slot);
@ -72,7 +72,7 @@ static void HideActionSprite(FriendshipCheckerGraphics *graphics, int slot);
static BOOL NoJumpingMons(FriendshipCheckerGraphics *graphics);
static u32 CheckIfTouchingMon(FriendshipCheckerGraphics *graphics);
static void RunIconActions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void RunIconActions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
static void UpdateIconAction(FriendshipCheckerGraphics *graphics, int slot, enum IconActions newAction);
static inline void UpdateIconDirection(PokemonGraphic *pokemon);
@ -82,23 +82,23 @@ static BOOL VectorIsZero(const VecFx32 *vec);
static inline BOOL VectorIsZeroInline(const VecFx32 *vec);
static inline void InvertVector(VecFx32 *vec);
static void HandleWanderAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void HandleShowLikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void HandleShowDislikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void HandleJumpAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot);
static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState);
static void HandleWanderAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void HandleShowLikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void HandleShowDislikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void HandleJumpAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot);
static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData);
BOOL PoketchFriendshipCheckerGraphics_New(FriendshipCheckerGraphics **dest, const FriendshipCheckerState *appState, BgConfig *bgConfig)
BOOL PoketchFriendshipCheckerGraphics_New(FriendshipCheckerGraphics **dest, const FriendshipCheckerData *friendshipData, BgConfig *bgConfig)
{
FriendshipCheckerGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(FriendshipCheckerGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, HEAP_ID_POKETCH_APP);
PoketchTask_InitActiveTaskList(graphics->activeTasks, FRIENDSHIP_CHECKER_TASK_SLOTS);
graphics->appState = appState;
graphics->friendshipData = friendshipData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
graphics->updateTask = NULL;
@ -148,12 +148,12 @@ static const PoketchTask sFrienshipCheckerTasks[] = {
{ 0 }
};
void PoketchFriendshipCheckerGraphics_StartTask(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicTask taskID)
void PoketchFriendshipCheckerGraphics_StartTask(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicsTask taskID)
{
PoketchTask_Start(sFrienshipCheckerTasks, taskID, graphics, graphics->appState, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
PoketchTask_Start(sFrienshipCheckerTasks, taskID, graphics, graphics->friendshipData, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchFriendshipCheckerGraphics_TaskIsNotActive(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicTask taskID)
BOOL PoketchFriendshipCheckerGraphics_TaskIsNotActive(FriendshipCheckerGraphics *graphics, enum FriendshipCheckerGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}
@ -195,15 +195,15 @@ static void Task_InitGraphics(SysTask *task, void *taskMan)
PoketchGraphics_LoadActivePalette(0, 0);
Bg_CopyTilemapBufferToVRAM(graphics->bgConfig, BG_LAYER_SUB_2);
SetupSprites(graphics, graphics->appState);
SetupIconMovement(graphics, graphics->appState);
SetupSprites(graphics, graphics->friendshipData);
SetupIconMovement(graphics, graphics->friendshipData);
dispCnt = GXS_GetDispCnt();
GXS_SetVisiblePlane(dispCnt.visiblePlane | GX_PLANEMASK_BG2 | GX_PLANEMASK_OBJ);
EndTask(taskMan);
}
static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
static const struct {
u16 x;
@ -233,8 +233,8 @@ static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCh
animData.oamPriority = 2;
animData.hasAffineTransform = TRUE;
for (int slot = 0; slot < appState->monCount; slot++) {
ncgrFile = NARC_AllocAndReadWholeMember(pokeIconNarc, appState->party[slot].spriteIdx, HEAP_ID_POKETCH_APP);
for (int slot = 0; slot < friendshipData->monCount; slot++) {
ncgrFile = NARC_AllocAndReadWholeMember(pokeIconNarc, friendshipData->party[slot].spriteIdx, HEAP_ID_POKETCH_APP);
NNS_G2dGetUnpackedCharacterData(ncgrFile, &charData);
DC_FlushRange(charData->pRawData, POKE_ICON_SIZE * TILE_SIZE_4BPP);
GXS_LoadOBJ(charData->pRawData, POKE_ICON_SIZE * TILE_SIZE_4BPP * slot, POKE_ICON_SIZE * TILE_SIZE_4BPP);
@ -247,7 +247,7 @@ static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCh
graphics->pokemon[slot].iconSprite = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &animData, &graphics->monAnimData);
PoketchAnimation_SetSpriteCharNo(graphics->pokemon[slot].iconSprite, POKE_ICON_SIZE * slot);
PoketchAnimation_SetCParam(graphics->pokemon[slot].iconSprite, 1 + PokeIconPaletteIndex(appState->party[slot].species, appState->party[slot].form, FALSE));
PoketchAnimation_SetCParam(graphics->pokemon[slot].iconSprite, 1 + PokeIconPaletteIndex(friendshipData->party[slot].species, friendshipData->party[slot].form, FALSE));
animData.priority = 0;
graphics->pokemon[slot].actionSprite = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &animData, &graphics->heartAnimData);
@ -260,7 +260,7 @@ static void SetupSprites(FriendshipCheckerGraphics *graphics, const FriendshipCh
GF_ASSERT(0);
}
graphics->pokemon[slot].flipSprite = SpeciesData_GetFormValue(appState->party[slot].species, appState->party[slot].form, SPECIES_DATA_FLIP_SPRITE);
graphics->pokemon[slot].flipSprite = SpeciesData_GetFormValue(friendshipData->party[slot].species, friendshipData->party[slot].form, SPECIES_DATA_FLIP_SPRITE);
graphics->pokemon[slot].unused2 = 0;
graphics->pokemon[slot].bumpedFromRest = FALSE;
@ -295,9 +295,9 @@ static inline void UpdateIconDirection(PokemonGraphic *pokemon)
}
}
static void SetupIconMovement(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void SetupIconMovement(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
for (int slot = 0; slot < appState->monCount; slot++) {
for (int slot = 0; slot < friendshipData->monCount; slot++) {
SetRandomVelocity(&graphics->pokemon[slot].velocity);
UpdateIconDirection(&graphics->pokemon[slot]);
}
@ -318,12 +318,12 @@ static void SetupTapState(FriendshipCheckerGraphics *graphics)
{
graphics->tapState = TAP_STATE_IDLE;
for (int slot = 0; slot < graphics->appState->monCount; slot++) {
for (int slot = 0; slot < graphics->friendshipData->monCount; slot++) {
graphics->pokemon[slot].action = ACTION_WANDER;
graphics->pokemon[slot].collisionCooldown = 0;
}
graphics->touchedMonIdx = graphics->appState->monCount;
graphics->touchedMonIdx = graphics->friendshipData->monCount;
graphics->prevTouchedMonIdx = graphics->touchedMonIdx;
}
@ -335,7 +335,7 @@ static void UpdateTapState(FriendshipCheckerGraphics *graphics, enum TapState ne
static void Task_UpdateGraphics(SysTask *task, void *taskData)
{
static void (*const tapStateHandlers[])(FriendshipCheckerGraphics *, const FriendshipCheckerState *) = {
static void (*const tapStateHandlers[])(FriendshipCheckerGraphics *, const FriendshipCheckerData *) = {
TapStateIdle,
TapStateFirstTap,
TapStateHeldTooLong,
@ -344,30 +344,30 @@ static void Task_UpdateGraphics(SysTask *task, void *taskData)
};
FriendshipCheckerGraphics *graphics = taskData;
const FriendshipCheckerState *appState = graphics->appState;
const FriendshipCheckerData *friendshipData = graphics->friendshipData;
if (appState->screenHeld) {
graphics->touchX = appState->touchX;
graphics->touchY = appState->touchY - 8;
if (friendshipData->screenHeld) {
graphics->touchX = friendshipData->touchX;
graphics->touchY = friendshipData->touchY - 8;
graphics->touchedMonIdx = CheckIfTouchingMon(graphics);
graphics->touchingMonIcon = (graphics->touchedMonIdx < appState->monCount);
graphics->touchingMonIcon = (graphics->touchedMonIdx < friendshipData->monCount);
if (graphics->touchingMonIcon && (graphics->touchedMonIdx != graphics->prevTouchedMonIdx)) {
PoketchSystem_PlayCry(appState->party[graphics->touchedMonIdx].species, appState->party[graphics->touchedMonIdx].form);
PoketchSystem_PlayCry(friendshipData->party[graphics->touchedMonIdx].species, friendshipData->party[graphics->touchedMonIdx].form);
}
graphics->prevTouchedMonIdx = graphics->touchedMonIdx;
} else {
graphics->touchingMonIcon = FALSE;
graphics->prevTouchedMonIdx = appState->monCount;
graphics->prevTouchedMonIdx = friendshipData->monCount;
}
tapStateHandlers[graphics->tapState](graphics, appState);
tapStateHandlers[graphics->tapState](graphics, friendshipData);
RunIconActions(graphics, appState);
RunIconActions(graphics, friendshipData);
if (graphics->tapState != TAP_STATE_DOUBLE_TAP) {
UpdateIconPositions(graphics, appState);
UpdateIconPositions(graphics, friendshipData);
}
}
@ -375,7 +375,7 @@ static u32 CheckIfTouchingMon(FriendshipCheckerGraphics *graphics)
{
int x, y;
for (int slot = 0; slot < graphics->appState->monCount; slot++) {
for (int slot = 0; slot < graphics->friendshipData->monCount; slot++) {
x = graphics->pokemon[slot].position.x >> FX32_SHIFT;
y = graphics->pokemon[slot].position.y >> FX32_SHIFT;
x = (graphics->touchX - x) * (graphics->touchX - x);
@ -386,7 +386,7 @@ static u32 CheckIfTouchingMon(FriendshipCheckerGraphics *graphics)
}
}
return graphics->appState->monCount;
return graphics->friendshipData->monCount;
}
static BOOL PointWithinDistance(u32 x, u32 y, u32 distance, const VecFx32 *point)
@ -410,17 +410,17 @@ static BOOL PointWithinDistance(u32 x, u32 y, u32 distance, const VecFx32 *point
return FALSE;
}
static void TapStateIdle(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void TapStateIdle(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
if (appState->screenTapped) {
if (friendshipData->screenTapped) {
graphics->tappedOnMonIcon = graphics->touchingMonIcon;
UpdateTapState(graphics, TAP_STATE_FIRST_TAP);
}
}
static void TapStateFirstTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void TapStateFirstTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
if (appState->screenHeld) {
if (friendshipData->screenHeld) {
graphics->tapStateCounter++;
if (graphics->tapStateCounter > 6) {
@ -435,16 +435,16 @@ static void TapStateFirstTap(FriendshipCheckerGraphics *graphics, const Friendsh
}
}
static void TapStateHeldTooLong(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void TapStateHeldTooLong(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
if (appState->screenHeld == FALSE) {
if (friendshipData->screenHeld == FALSE) {
UpdateTapState(graphics, TAP_STATE_IDLE);
}
}
static void TapStateReleasedFirst(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void TapStateReleasedFirst(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
if (appState->screenTapped == FALSE) {
if (friendshipData->screenTapped == FALSE) {
graphics->tapStateCounter++;
if (graphics->tapStateCounter > 6) {
@ -460,7 +460,7 @@ static void TapStateReleasedFirst(FriendshipCheckerGraphics *graphics, const Fri
}
}
static void TapStateDoubleTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void TapStateDoubleTap(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
if (graphics->tapStateCounter == 0) {
TriggerJumpSequence(graphics);
@ -481,9 +481,9 @@ static void PrintDebugLog(const char *text, ...)
}
}
static void RunIconActions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void RunIconActions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
static void (*const actionHandlers[])(FriendshipCheckerGraphics *, const FriendshipCheckerState *, int) = {
static void (*const actionHandlers[])(FriendshipCheckerGraphics *, const FriendshipCheckerData *, int) = {
HandleWanderAction,
HandleGatherAction,
HandleRunAwayAction,
@ -492,12 +492,12 @@ static void RunIconActions(FriendshipCheckerGraphics *graphics, const Friendship
HandleJumpAction
};
for (int slot = 0; slot < appState->monCount; slot++) {
for (int slot = 0; slot < friendshipData->monCount; slot++) {
if (graphics->pokemon[slot].collisionCooldown) {
graphics->pokemon[slot].collisionCooldown--;
PrintDebugLog("icon[%d] REF[%d]\n", slot, graphics->pokemon[slot].collisionCooldown);
} else {
actionHandlers[graphics->pokemon[slot].action](graphics, appState, slot);
actionHandlers[graphics->pokemon[slot].action](graphics, friendshipData, slot);
}
}
@ -526,12 +526,12 @@ static void UpdateIconAction(FriendshipCheckerGraphics *graphics, int slot, enum
static void TriggerJumpSequence(FriendshipCheckerGraphics *graphics)
{
for (int slot = 0; slot < graphics->appState->monCount; slot++) {
for (int slot = 0; slot < graphics->friendshipData->monCount; slot++) {
UpdateIconAction(graphics, slot, ACTION_JUMP);
graphics->pokemon[slot].collisionCooldown = 0;
}
graphics->jumpingMons = graphics->appState->monCount;
graphics->jumpingMons = graphics->friendshipData->monCount;
}
static BOOL NoJumpingMons(FriendshipCheckerGraphics *graphics)
@ -541,9 +541,9 @@ static BOOL NoJumpingMons(FriendshipCheckerGraphics *graphics)
static void ShowHeartSprite(FriendshipCheckerGraphics *graphics, int slot)
{
if (graphics->appState->party[slot].friendship == FRIENDSHIP_LIKE) {
if (graphics->friendshipData->party[slot].friendship == FRIENDSHIP_LIKE) {
PoketchAnimation_SetSpritePrority(graphics->animMan, graphics->pokemon[slot].actionSprite, 0);
PoketchAnimation_UpdateAnimationIdx(graphics->pokemon[slot].actionSprite, graphics->appState->party[slot].intensity - 1);
PoketchAnimation_UpdateAnimationIdx(graphics->pokemon[slot].actionSprite, graphics->friendshipData->party[slot].intensity - 1);
PoketchAnimation_HideSprite(graphics->pokemon[slot].actionSprite, FALSE);
}
}
@ -580,26 +580,26 @@ static BOOL VectorIsZero(const VecFx32 *vec)
return (vec->x == 0) && (vec->y == 0);
}
static void HandleWanderAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleWanderAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PrintDebugLog(" icon[%d] Default\n", slot);
if (appState->screenHeld == FALSE) {
if (friendshipData->screenHeld == FALSE) {
LimitIconSpeed(768, 96, &graphics->pokemon[slot].velocity);
} else {
if (graphics->touchingMonIcon == FALSE) {
if (PointWithinDistance(graphics->touchX, graphics->touchY, 48, &graphics->pokemon[slot].position)) {
if (appState->party[slot].friendship != FRIENDSHIP_HATE) {
if (friendshipData->party[slot].friendship != FRIENDSHIP_HATE) {
UpdateIconAction(graphics, slot, ACTION_GATHER);
HandleGatherAction(graphics, appState, slot);
HandleGatherAction(graphics, friendshipData, slot);
} else {
UpdateIconAction(graphics, slot, ACTION_RUN_AWAY);
HandleRunAwayAction(graphics, appState, slot);
HandleRunAwayAction(graphics, friendshipData, slot);
}
}
} else if (graphics->touchedMonIdx == slot) {
if (PointWithinDistance(graphics->touchX, graphics->touchY, 8, &graphics->pokemon[slot].position)) {
if (appState->party[slot].friendship != FRIENDSHIP_HATE) {
if (friendshipData->party[slot].friendship != FRIENDSHIP_HATE) {
UpdateIconAction(graphics, slot, ACTION_SHOW_LIKE);
} else {
UpdateIconAction(graphics, slot, ACTION_SHOW_DISLIKE);
@ -609,11 +609,11 @@ static void HandleWanderAction(FriendshipCheckerGraphics *graphics, const Friend
}
}
static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PrintDebugLog(" icon[%d] ReaLike\n", slot);
if (appState->screenHeld && PointWithinDistance(graphics->touchX, graphics->touchY, 64, &graphics->pokemon[slot].position)) {
if (friendshipData->screenHeld && PointWithinDistance(graphics->touchX, graphics->touchY, 64, &graphics->pokemon[slot].position)) {
static const u8 speedFactor[] = {
100, 150, 175, 200
};
@ -628,8 +628,8 @@ static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const Friend
VEC_Subtract(&velocity, &graphics->pokemon[slot].position, &velocity);
VEC_Normalize(&velocity, &velocity);
velocity.x = (velocity.x * speedFactor[appState->party[slot].intensity]) / 100;
velocity.y = (velocity.y * speedFactor[appState->party[slot].intensity]) / 100;
velocity.x = (velocity.x * speedFactor[friendshipData->party[slot].intensity]) / 100;
velocity.y = (velocity.y * speedFactor[friendshipData->party[slot].intensity]) / 100;
velocity.x /= TIME_STEPS_PER_FRAME;
velocity.y /= TIME_STEPS_PER_FRAME;
@ -641,11 +641,11 @@ static void HandleGatherAction(FriendshipCheckerGraphics *graphics, const Friend
}
}
static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PrintDebugLog(" icon[%d] ReaHate\n", slot);
if (appState->screenHeld && PointWithinDistance(graphics->touchX, graphics->touchY, 64, &graphics->pokemon[slot].position)) {
if (friendshipData->screenHeld && PointWithinDistance(graphics->touchX, graphics->touchY, 64, &graphics->pokemon[slot].position)) {
static const u8 speedFactor[] = {
100, 150, 175, 200
};
@ -655,8 +655,8 @@ static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const Frien
VEC_Subtract(&graphics->pokemon[slot].position, &velocity, &velocity);
VEC_Normalize(&velocity, &velocity);
velocity.x = (velocity.x * speedFactor[appState->party[slot].intensity]) / 100;
velocity.y = (velocity.y * speedFactor[appState->party[slot].intensity]) / 100;
velocity.x = (velocity.x * speedFactor[friendshipData->party[slot].intensity]) / 100;
velocity.y = (velocity.y * speedFactor[friendshipData->party[slot].intensity]) / 100;
velocity.x /= TIME_STEPS_PER_FRAME;
velocity.y /= TIME_STEPS_PER_FRAME;
graphics->pokemon[slot].velocity = velocity;
@ -665,11 +665,11 @@ static void HandleRunAwayAction(FriendshipCheckerGraphics *graphics, const Frien
}
}
static void HandleShowLikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleShowLikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PrintDebugLog(" icon[%d] TcgLike\n", slot);
if (appState->screenHeld) {
if (friendshipData->screenHeld) {
VecFx32 velocity;
VEC_Set(&velocity, graphics->touchX << FX32_SHIFT, graphics->touchY << FX32_SHIFT, 0);
@ -696,11 +696,11 @@ static void HandleShowLikeAction(FriendshipCheckerGraphics *graphics, const Frie
UpdateIconAction(graphics, slot, ACTION_WANDER);
}
static void HandleShowDislikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleShowDislikeAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PrintDebugLog(" icon[%d] TchHate\n", slot);
if (appState->screenHeld) {
if (friendshipData->screenHeld) {
VecFx32 unused;
VEC_Set(&unused, graphics->touchX << FX32_SHIFT, graphics->touchY << FX32_SHIFT, 0);
@ -720,7 +720,7 @@ static void HandleShowDislikeAction(FriendshipCheckerGraphics *graphics, const F
UpdateIconAction(graphics, slot, ACTION_WANDER);
}
static void HandleJumpAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState, int slot)
static void HandleJumpAction(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData, int slot)
{
PokemonGraphic *monSprite = &graphics->pokemon[slot];
@ -762,7 +762,7 @@ static void HandleJumpAction(FriendshipCheckerGraphics *graphics, const Friendsh
}
}
static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerState *appState)
static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const FriendshipCheckerData *friendshipData)
{
VecFx32 iconDisplacement;
fx32 usedTimeSteps, remainingTimeSteps;
@ -777,11 +777,11 @@ static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const Frien
usedTimeSteps = remainingTimeSteps;
collisionCheckResult = NO_COLLISION;
for (slot = 0; slot < appState->monCount; slot++) {
for (slot = 0; slot < friendshipData->monCount; slot++) {
VEC_MultAdd(usedTimeSteps, &graphics->pokemon[slot].velocity, &graphics->pokemon[slot].position, &graphics->plannedPosition[slot]);
}
for (slot = 0; slot < appState->monCount; slot++) {
for (slot = 0; slot < friendshipData->monCount; slot++) {
if ((graphics->plannedPosition[slot].x < LEFT_EDGE) && (graphics->pokemon[slot].velocity.x != 0)) {
fx32 timeToContact = usedTimeSteps - ((graphics->plannedPosition[slot].x - LEFT_EDGE) / graphics->pokemon[slot].velocity.x);
@ -823,7 +823,7 @@ static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const Frien
}
}
for (slot2 = 0; slot2 < appState->monCount; slot2++) {
for (slot2 = 0; slot2 < friendshipData->monCount; slot2++) {
for (slot = 0; slot < slot2; slot++) {
VEC_Subtract(&graphics->plannedPosition[slot], &graphics->plannedPosition[slot2], &iconDisplacement);
@ -849,7 +849,7 @@ static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const Frien
break;
}
for (slot = 0; slot < appState->monCount; slot++) {
for (slot = 0; slot < friendshipData->monCount; slot++) {
VEC_MultAdd(usedTimeSteps, &graphics->pokemon[slot].velocity, &graphics->pokemon[slot].position, &graphics->pokemon[slot].position);
}
@ -940,7 +940,7 @@ static void UpdateIconPositions(FriendshipCheckerGraphics *graphics, const Frien
remainingTimeSteps -= usedTimeSteps;
} while (collisionCheckResult != NO_COLLISION);
for (slot = 0; slot < appState->monCount; slot++) {
for (slot = 0; slot < friendshipData->monCount; slot++) {
if (graphics->pokemon[slot].action < ACTION_SHOW_LIKE) {
UpdateIconDirection(&graphics->pokemon[slot]);
}

View File

@ -15,18 +15,18 @@
#include "touch_screen.h"
typedef struct PoketchFriendshipChecker {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
FriendshipCheckerState state;
FriendshipCheckerData friendshipCheckerData;
FriendshipCheckerGraphics *graphics;
PoketchSystem *poketchSys;
} PoketchFriendshipChecker;
enum FriendshipCheckerTask {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum FriendshipCheckerState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
static void NitroStaticInit(void);
@ -37,11 +37,11 @@ static void Free(PoketchFriendshipChecker *appData);
static void Exit(void *appData);
static u32 GetFriendshipLevel(u32 friendship);
static void ChangeActiveTask(PoketchFriendshipChecker *appData, enum FriendshipCheckerTask taskID);
static void ChangeState(PoketchFriendshipChecker *appData, enum FriendshipCheckerState newState);
static void Task_Main(SysTask *task, void *appData);
static BOOL Task_LoadApp(PoketchFriendshipChecker *appData);
static BOOL Task_UpdateApp(PoketchFriendshipChecker *appData);
static BOOL Task_UnloadApp(PoketchFriendshipChecker *appData);
static BOOL State_LoadApp(PoketchFriendshipChecker *appData);
static BOOL State_UpdateApp(PoketchFriendshipChecker *appData);
static BOOL State_UnloadApp(PoketchFriendshipChecker *appData);
static void NitroStaticInit(void)
{
@ -68,9 +68,9 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchFriendshipChecker *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
if (PoketchFriendshipCheckerGraphics_New(&appData->graphics, &appData->state, bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->taskFuncState = 0;
if (PoketchFriendshipCheckerGraphics_New(&appData->graphics, &appData->friendshipCheckerData, bgConfig)) {
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->poketchSys = poketchSys;
@ -80,34 +80,34 @@ static BOOL Init(PoketchFriendshipChecker *appData, PoketchSystem *poketchSys, B
int slot;
slot = 0;
appData->state.monCount = Party_GetCurrentCount(party);
appData->friendshipCheckerData.monCount = Party_GetCurrentCount(party);
for (int i = 0; i < appData->state.monCount; i++) {
for (int i = 0; i < appData->friendshipCheckerData.monCount; i++) {
pokemon = Party_GetPokemonBySlotIndex(party, i);
if (Pokemon_GetValue(pokemon, MON_DATA_IS_EGG, NULL) == 0) {
appData->state.party[slot].species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL);
appData->state.party[slot].form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL);
appData->state.party[slot].spriteIdx = BoxPokemon_IconSpriteIndex((const BoxPokemon *)pokemon);
appData->friendshipCheckerData.party[slot].species = Pokemon_GetValue(pokemon, MON_DATA_SPECIES, NULL);
appData->friendshipCheckerData.party[slot].form = Pokemon_GetValue(pokemon, MON_DATA_FORM, NULL);
appData->friendshipCheckerData.party[slot].spriteIdx = BoxPokemon_IconSpriteIndex((const BoxPokemon *)pokemon);
friendshipLevel = GetFriendshipLevel(Pokemon_GetValue(pokemon, MON_DATA_FRIENDSHIP, NULL));
switch (friendshipLevel) {
case 0:
case 1:
case 2:
appData->state.party[slot].friendship = FRIENDSHIP_HATE;
appData->state.party[slot].intensity = 3 - friendshipLevel;
appData->friendshipCheckerData.party[slot].friendship = FRIENDSHIP_HATE;
appData->friendshipCheckerData.party[slot].intensity = 3 - friendshipLevel;
break;
case 3:
default:
appData->state.party[slot].friendship = FRIENDSHIP_NEUTRAL;
appData->state.party[slot].intensity = 0;
appData->friendshipCheckerData.party[slot].friendship = FRIENDSHIP_NEUTRAL;
appData->friendshipCheckerData.party[slot].intensity = 0;
break;
case 4:
case 5:
case 6:
appData->state.party[slot].friendship = FRIENDSHIP_LIKE;
appData->state.party[slot].intensity = -(3 - friendshipLevel);
appData->friendshipCheckerData.party[slot].friendship = FRIENDSHIP_LIKE;
appData->friendshipCheckerData.party[slot].intensity = -(3 - friendshipLevel);
break;
}
@ -115,11 +115,11 @@ static BOOL Init(PoketchFriendshipChecker *appData, PoketchSystem *poketchSys, B
}
}
appData->state.monCount = slot;
appData->state.screenHeld = FALSE;
appData->state.screenTapped = FALSE;
appData->state.touchX = 0;
appData->state.touchY = 0;
appData->friendshipCheckerData.monCount = slot;
appData->friendshipCheckerData.screenHeld = FALSE;
appData->friendshipCheckerData.screenTapped = FALSE;
appData->friendshipCheckerData.touchX = 0;
appData->friendshipCheckerData.touchY = 0;
return TRUE;
}
@ -156,15 +156,15 @@ static void Free(PoketchFriendshipChecker *appData)
static void Task_Main(SysTask *task, void *appData)
{
static BOOL (*const stateFuncs[])(PoketchFriendshipChecker *) = {
Task_LoadApp,
Task_UpdateApp,
Task_UnloadApp,
State_LoadApp,
State_UpdateApp,
State_UnloadApp,
};
PoketchFriendshipChecker *friendshipChecker = appData;
if (friendshipChecker->activeTask < NELEMS(stateFuncs)) {
if (stateFuncs[friendshipChecker->activeTask](friendshipChecker)) {
if (friendshipChecker->state < NELEMS(stateFuncs)) {
if (stateFuncs[friendshipChecker->state](friendshipChecker)) {
Free(friendshipChecker);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(friendshipChecker->poketchSys);
@ -177,28 +177,28 @@ static void Exit(void *appData)
((PoketchFriendshipChecker *)appData)->shouldExit = TRUE;
}
static void ChangeActiveTask(PoketchFriendshipChecker *appData, enum FriendshipCheckerTask taskID)
static void ChangeState(PoketchFriendshipChecker *appData, enum FriendshipCheckerState newState)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = newState;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL Task_LoadApp(PoketchFriendshipChecker *appData)
static BOOL State_LoadApp(PoketchFriendshipChecker *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchFriendshipCheckerGraphics_StartTask(appData->graphics, FRIENDSHIP_CHECKER_GRAPHICS_INIT);
appData->taskFuncState++;
appData->subState++;
break;
case 1:
if (PoketchFriendshipCheckerGraphics_TaskIsNotActive(appData->graphics, FRIENDSHIP_CHECKER_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeActiveTask(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -206,37 +206,37 @@ static BOOL Task_LoadApp(PoketchFriendshipChecker *appData)
return FALSE;
}
static BOOL Task_UpdateApp(PoketchFriendshipChecker *appData)
static BOOL State_UpdateApp(PoketchFriendshipChecker *appData)
{
if (appData->shouldExit) {
ChangeActiveTask(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
return FALSE;
}
appData->state.screenHeld = PoketchSystem_GetDisplayHeldCoords(&appData->state.touchX, &appData->state.touchY);
appData->friendshipCheckerData.screenHeld = PoketchSystem_GetDisplayHeldCoords(&appData->friendshipCheckerData.touchX, &appData->friendshipCheckerData.touchY);
if (appData->state.screenHeld) {
if (INSIDE_POKETCH_SCREEN(appData->state.touchX, appData->state.touchY)) {
appData->state.screenTapped = TouchScreen_Tapped();
if (appData->friendshipCheckerData.screenHeld) {
if (INSIDE_POKETCH_SCREEN(appData->friendshipCheckerData.touchX, appData->friendshipCheckerData.touchY)) {
appData->friendshipCheckerData.screenTapped = TouchScreen_Tapped();
return FALSE;
}
appData->state.screenHeld = FALSE;
appData->friendshipCheckerData.screenHeld = FALSE;
}
appData->state.touchX = 0;
appData->state.touchY = 0;
appData->state.screenTapped = FALSE;
appData->friendshipCheckerData.touchX = 0;
appData->friendshipCheckerData.touchY = 0;
appData->friendshipCheckerData.screenTapped = FALSE;
return FALSE;
}
static BOOL Task_UnloadApp(PoketchFriendshipChecker *appData)
static BOOL State_UnloadApp(PoketchFriendshipChecker *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchFriendshipCheckerGraphics_StartTask(appData->graphics, FRIENDSHIP_CHECKER_GRAPHICS_FREE);
appData->taskFuncState++;
appData->subState++;
break;
case 1:

View File

@ -25,6 +25,7 @@
#define PENCIL_PRESSED 3
static BOOL SetupWindow(MemoPadGraphics *graphics);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppBackground(SysTask *task, void *taskMan);
static void Task_ChangeActiveDrawingTool(SysTask *task, void *taskMan);
@ -32,24 +33,25 @@ static void Task_PrintWindow(SysTask *task, void *taskMan);
static void Task_UpdateMemoContent(SysTask *task, void *taskMan);
static void Task_PrintWindow2(SysTask *task, void *taskMan);
static void Task_FreeBackground(SysTask *task, void *taskMan);
static void SetupSprites(MemoPadGraphics *graphics);
static void UnloadSprites(MemoPadGraphics *graphics);
BOOL MemoPadGraphics_New(MemoPadGraphics **graphics, const MemoPadState *padState, BgConfig *bgConfig)
BOOL MemoPadGraphics_New(MemoPadGraphics **dest, const MemoPadData *padState, BgConfig *bgConfig)
{
MemoPadGraphics *memoPadGraphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(MemoPadGraphics));
MemoPadGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(MemoPadGraphics));
if (memoPadGraphics != NULL) {
if (graphics != NULL) {
GF_ASSERT(GF_heap_c_dummy_return_true(HEAP_ID_POKETCH_MAIN));
PoketchTask_InitActiveTaskList(memoPadGraphics->activeTasks, NUM_TASK_SLOTS);
PoketchTask_InitActiveTaskList(graphics->activeTasks, MEMO_PAD_TASK_SLOTS);
GF_ASSERT(GF_heap_c_dummy_return_true(HEAP_ID_POKETCH_MAIN));
memoPadGraphics->padState = padState;
memoPadGraphics->bgConfig = PoketchGraphics_GetBgConfig();
memoPadGraphics->animMan = PoketchGraphics_GetAnimationManager();
graphics->padData = padState;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
GF_ASSERT(GF_heap_c_dummy_return_true(HEAP_ID_POKETCH_MAIN));
*graphics = memoPadGraphics;
*dest = graphics;
return TRUE;
}
@ -73,7 +75,7 @@ static BOOL SetupWindow(MemoPadGraphics *graphics)
if (graphics->window) {
Window_AddFromTemplate(graphics->bgConfig, graphics->window, &windowTemplate);
if (PoketchMemory_ReadFast(graphics->padState->appID, graphics->window->pixels, WINDOW_WIDTH_TILES * WINDOW_HEIGHT_TILES * TILE_SIZE_4BPP) == FALSE) {
if (PoketchMemory_ReadFast(graphics->padData->appID, graphics->window->pixels, WINDOW_WIDTH_TILES * WINDOW_HEIGHT_TILES * TILE_SIZE_4BPP) == FALSE) {
Window_FillTilemap(graphics->window, 0x4);
}
@ -89,7 +91,7 @@ void MemoPadGraphics_Free(MemoPadGraphics *graphics)
GF_ASSERT(GF_heap_c_dummy_return_true(HEAP_ID_POKETCH_MAIN));
if (graphics->window) {
PoketchMemory_WriteFast(graphics->padState->appID, graphics->window->pixels, WINDOW_WIDTH_TILES * WINDOW_HEIGHT_TILES * TILE_SIZE_4BPP);
PoketchMemory_WriteFast(graphics->padData->appID, graphics->window->pixels, WINDOW_WIDTH_TILES * WINDOW_HEIGHT_TILES * TILE_SIZE_4BPP);
Window_Remove(graphics->window);
Heap_Free(graphics->window);
}
@ -99,21 +101,21 @@ void MemoPadGraphics_Free(MemoPadGraphics *graphics)
}
static const PoketchTask memoPadTasks[] = {
{ TASK_DRAW_APP_SCREEN, Task_DrawAppBackground, 0x0 },
{ TASK_CHANGE_DRAW_TOOL, Task_ChangeActiveDrawingTool, 0x0 },
{ TASK_PRINT_WINDOW, Task_PrintWindow, 0x0 },
{ TASK_UPDATE_MEMO_CONTENT, Task_UpdateMemoContent, 0x0 },
{ TASK_PRINT_WINDOW_2, Task_PrintWindow2, 0x0 },
{ TASK_FREE_BG, Task_FreeBackground, 0x0 },
{ MEMO_PAD_GRAPHICS_INIT, Task_DrawAppBackground, 0 },
{ MEMO_PAD_GRAPHICS_CHANGE_TOOL, Task_ChangeActiveDrawingTool, 0 },
{ MEMO_PAD_GRAPHICS_PRINT_WINDOW, Task_PrintWindow, 0 },
{ MEMO_PAD_GRAPHICS_UPDATE_CONTENT, Task_UpdateMemoContent, 0 },
{ MEMO_PAD_GRAPHICS_PRINT_WINDOW_2, Task_PrintWindow2, 0 },
{ MEMO_PAD_GRAPHICS_FREE, Task_FreeBackground, 0 },
{ 0 }
};
void PoketchMemoPadGraphics_StartTask(MemoPadGraphics *graphics, enum MemoPadGraphicsTasks taskID)
void PoketchMemoPadGraphics_StartTask(MemoPadGraphics *graphics, enum MemoPadGraphicsTask taskID)
{
PoketchTask_Start(memoPadTasks, taskID, graphics, graphics->padState, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
PoketchTask_Start(memoPadTasks, taskID, graphics, graphics->padData, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchMemoPadGraphics_TaskIsNotActive(MemoPadGraphics *graphics, enum MemoPadGraphicsTasks taskID)
BOOL PoketchMemoPadGraphics_TaskIsNotActive(MemoPadGraphics *graphics, enum MemoPadGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}
@ -199,7 +201,7 @@ static void Task_ChangeActiveDrawingTool(SysTask *task, void *taskMan)
{
MemoPadGraphics *graphics = PoketchTask_GetTaskData(taskMan);
if (graphics->padState->pencilActive == TRUE) {
if (graphics->padData->pencilActive == TRUE) {
PoketchAnimation_UpdateAnimationIdx(graphics->sprites[0], ERASER_UNPRESSED);
PoketchAnimation_UpdateAnimationIdx(graphics->sprites[1], PENCIL_PRESSED);
} else {
@ -245,12 +247,12 @@ static void Task_UpdateMemoContent(SysTask *task, void *taskMan)
s32 x, y;
MemoPadGraphics *graphics = PoketchTask_GetTaskData(taskMan);
if (graphics->padState->pencilActive == FALSE) {
if (graphics->padData->pencilActive == FALSE) {
int width, height;
width = height = ERASER_SIZE * 2;
x = (graphics->padState->x * 2) - ERASER_SIZE;
y = (graphics->padState->y * 2) - ERASER_SIZE;
x = (graphics->padData->x * 2) - ERASER_SIZE;
y = (graphics->padData->y * 2) - ERASER_SIZE;
if (x < 0) {
width += x;
@ -265,8 +267,8 @@ static void Task_UpdateMemoContent(SysTask *task, void *taskMan)
Window_FillRectWithColor(graphics->window, 0x4, x, y, width, height);
RedrawWindowRegion(graphics->window->pixels, x, y, width, height);
} else {
x = graphics->padState->x * 2;
y = graphics->padState->y * 2;
x = graphics->padData->x * 2;
y = graphics->padData->y * 2;
Window_FillRectWithColor(graphics->window, 0x1, x, y, 2, 2);
RedrawWindowRegion(graphics->window->pixels, x, y, 2, 2);

View File

@ -18,16 +18,16 @@ typedef struct PoketchMemoPad {
u8 shouldExit;
u8 currentlyDrawing;
u32 unused;
MemoPadState padState;
MemoPadData padData;
MemoPadGraphics *graphics;
PoketchSystem *poketchSys;
PoketchButtonManager *buttonManager;
} PoketchMemoPad;
enum MemoPadTasks {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum MemoPadState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
static void NitroStaticInit(void);
@ -35,21 +35,18 @@ static void NitroStaticInit(void);
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static BOOL Init(PoketchMemoPad *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static void Free(PoketchMemoPad *appData);
static void Task_Main(SysTask *task, void *appData);
static void ButtonCallback(u32 buttonID, u32 buttonState, u32 touchState, void *appData);
static void Exit(void *appData);
static void ChangeActiveTask(PoketchMemoPad *appData, u32 taskID);
static BOOL Task_LoadApp(PoketchMemoPad *appData);
static BOOL Task_UpdateApp(PoketchMemoPad *appData);
static void ButtonCallback(u32 buttonID, u32 buttonState, u32 touchState, void *appData);
static void Task_Main(SysTask *task, void *appData);
static void ChangeState(PoketchMemoPad *appData, u32 newState);
static BOOL State_LoadApp(PoketchMemoPad *appData);
static BOOL State_UpdateApp(PoketchMemoPad *appData);
static BOOL State_UnloadApp(PoketchMemoPad *appData);
static BOOL GetTouchStartLocation(PoketchMemoPad *appData);
static BOOL GetTouchContinueLocation(PoketchMemoPad *appData);
static void UpdatePixelsOnPath(PoketchMemoPad *appData, u32 x, u32 y, u32 endX, u32 endY);
static BOOL Task_UnloadApp(PoketchMemoPad *appData);
static const TouchScreenHitTable sHitTableMemoPad[] = {
{ .rect = { .top = 0x18, .bottom = 0x58, .left = 0xB4, .right = 0xCC } },
{ .rect = { .top = 0x68, .bottom = 0xA8, .left = 0xB4, .right = 0xCC } }
};
static void NitroStaticInit(void)
{
@ -74,13 +71,18 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchMemoPad *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
memset(appData->padState.pixels, 0, sizeof(u8) * (MEMO_PAD_WIDTH * MEMO_PAD_HEIGHT));
static const TouchScreenRect sHitTableMemoPad[] = {
{ .rect = { .top = 24, .bottom = 88, .left = 180, .right = 204 } },
{ .rect = { .top = 104, .bottom = 168, .left = 180, .right = 204 } }
};
appData->padState.appID = appID;
appData->padState.pencilActive = TRUE;
memset(appData->padData.pixels, 0, sizeof(u8) * (MEMO_PAD_WIDTH * MEMO_PAD_HEIGHT));
if (MemoPadGraphics_New(&appData->graphics, &appData->padState, bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->padData.appID = appID;
appData->padData.pencilActive = TRUE;
if (MemoPadGraphics_New(&appData->graphics, &appData->padData, bgConfig)) {
appData->activeTask = STATE_LOAD_APP;
appData->taskFuncState = 0;
appData->shouldExit = FALSE;
appData->currentlyDrawing = FALSE;
@ -103,9 +105,9 @@ static void Free(PoketchMemoPad *appData)
static void Task_Main(SysTask *task, void *appData)
{
static BOOL (*const stateFuncs[])(PoketchMemoPad *) = {
Task_LoadApp,
Task_UpdateApp,
Task_UnloadApp
State_LoadApp,
State_UpdateApp,
State_UnloadApp
};
PoketchMemoPad *memoPad = appData;
@ -126,9 +128,9 @@ static void ButtonCallback(u32 buttonID, u32 buttonState, u32 touchState, void *
PoketchMemoPad *memoPad = appData;
if (touchState == 1) {
if (((memoPad->padState.pencilActive == TRUE) && (buttonID == 0)) || ((memoPad->padState.pencilActive == FALSE) && (buttonID == 1))) {
memoPad->padState.pencilActive ^= 1;
PoketchMemoPadGraphics_StartTask(memoPad->graphics, TASK_CHANGE_DRAW_TOOL);
if (((memoPad->padData.pencilActive == TRUE) && (buttonID == 0)) || ((memoPad->padData.pencilActive == FALSE) && (buttonID == 1))) {
memoPad->padData.pencilActive ^= 1;
PoketchMemoPadGraphics_StartTask(memoPad->graphics, MEMO_PAD_GRAPHICS_CHANGE_TOOL);
}
}
}
@ -138,28 +140,28 @@ static void Exit(void *appData)
((PoketchMemoPad *)appData)->shouldExit = TRUE;
}
static void ChangeActiveTask(PoketchMemoPad *appData, u32 taskID)
static void ChangeState(PoketchMemoPad *appData, u32 taskID)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->activeTask = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
}
static BOOL Task_LoadApp(PoketchMemoPad *appData)
static BOOL State_LoadApp(PoketchMemoPad *appData)
{
switch (appData->taskFuncState) {
case 0:
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_DRAW_APP_SCREEN);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_INIT);
appData->taskFuncState++;
break;
case 1:
if (PoketchMemoPadGraphics_TaskIsNotActive(appData->graphics, TASK_DRAW_APP_SCREEN)) {
if (PoketchMemoPadGraphics_TaskIsNotActive(appData->graphics, MEMO_PAD_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeActiveTask(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -167,10 +169,10 @@ static BOOL Task_LoadApp(PoketchMemoPad *appData)
return FALSE;
}
static BOOL Task_UpdateApp(PoketchMemoPad *appData)
static BOOL State_UpdateApp(PoketchMemoPad *appData)
{
if (appData->shouldExit) {
ChangeActiveTask(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
}
switch (appData->taskFuncState) {
@ -182,17 +184,17 @@ static BOOL Task_UpdateApp(PoketchMemoPad *appData)
if (appData->currentlyDrawing) {
u32 prevX, prevY;
prevX = appData->padState.x;
prevY = appData->padState.y;
prevX = appData->padData.x;
prevY = appData->padData.y;
if (GetTouchContinueLocation(appData)) {
UpdatePixelsOnPath(appData, prevX, prevY, appData->padState.x, appData->padState.y);
UpdatePixelsOnPath(appData, prevX, prevY, appData->padData.x, appData->padData.y);
} else {
appData->currentlyDrawing = FALSE;
}
} else {
if (GetTouchStartLocation(appData)) {
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_UPDATE_MEMO_CONTENT);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_UPDATE_CONTENT);
appData->currentlyDrawing = TRUE;
}
}
@ -211,9 +213,9 @@ static BOOL GetTouchStartLocation(PoketchMemoPad *appData)
x = (x - POKETCH_SCREEN_MIN_X) / 2;
y = (y - POKETCH_SCREEN_MIN_Y) / 2;
appData->padState.pixels[x][y] = appData->padState.pencilActive;
appData->padState.x = x;
appData->padState.y = y;
appData->padData.pixels[x][y] = appData->padData.pencilActive;
appData->padData.x = x;
appData->padData.y = y;
return TRUE;
}
@ -231,8 +233,8 @@ static BOOL GetTouchContinueLocation(PoketchMemoPad *appData)
x = (x - POKETCH_SCREEN_MIN_X) / 2;
y = (y - POKETCH_SCREEN_MIN_Y) / 2;
appData->padState.x = x;
appData->padState.y = y;
appData->padData.x = x;
appData->padData.y = y;
return TRUE;
}
@ -267,7 +269,7 @@ static void ErasePixelsAroundPoint(PoketchMemoPad *appData, u32 x, u32 y)
for (i = left; i < right; i++) {
for (j = top; j < bottom; j++) {
appData->padState.pixels[i][j] = 0;
appData->padData.pixels[i][j] = 0;
}
}
}
@ -301,16 +303,16 @@ static void UpdatePixelsOnPath(PoketchMemoPad *appData, u32 x, u32 y, u32 endX,
minorAxisRounded = minorAxis >> FX32_SHIFT;
if ((x < MEMO_PAD_WIDTH) && (minorAxisRounded < MEMO_PAD_HEIGHT)) {
if ((appData->padState.pencilActive == FALSE) || (appData->padState.pixels[x][minorAxisRounded] != appData->padState.pencilActive)) {
if (appData->padState.pencilActive == FALSE) {
if ((appData->padData.pencilActive == FALSE) || (appData->padData.pixels[x][minorAxisRounded] != appData->padData.pencilActive)) {
if (appData->padData.pencilActive == FALSE) {
ErasePixelsAroundPoint(appData, x, minorAxisRounded);
}
appData->padState.pixels[x][minorAxisRounded] = appData->padState.pencilActive;
appData->padState.x = x;
appData->padState.y = minorAxisRounded;
appData->padData.pixels[x][minorAxisRounded] = appData->padData.pencilActive;
appData->padData.x = x;
appData->padData.y = minorAxisRounded;
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_UPDATE_MEMO_CONTENT);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_UPDATE_CONTENT);
}
}
@ -334,16 +336,16 @@ static void UpdatePixelsOnPath(PoketchMemoPad *appData, u32 x, u32 y, u32 endX,
minorAxisRounded = minorAxis >> FX32_SHIFT;
if ((y < MEMO_PAD_HEIGHT) && (minorAxisRounded < MEMO_PAD_WIDTH)) {
if ((appData->padState.pencilActive == 0) || (appData->padState.pixels[minorAxisRounded][y] != appData->padState.pencilActive)) {
if (appData->padState.pencilActive == 0) {
if ((appData->padData.pencilActive == 0) || (appData->padData.pixels[minorAxisRounded][y] != appData->padData.pencilActive)) {
if (appData->padData.pencilActive == 0) {
ErasePixelsAroundPoint(appData, minorAxisRounded, y);
}
appData->padState.pixels[minorAxisRounded][y] = appData->padState.pencilActive;
appData->padState.x = minorAxisRounded;
appData->padState.y = y;
appData->padData.pixels[minorAxisRounded][y] = appData->padData.pencilActive;
appData->padData.x = minorAxisRounded;
appData->padData.y = y;
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_UPDATE_MEMO_CONTENT);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_UPDATE_CONTENT);
}
}
@ -353,22 +355,22 @@ static void UpdatePixelsOnPath(PoketchMemoPad *appData, u32 x, u32 y, u32 endX,
}
if ((endY < MEMO_PAD_HEIGHT) && (endX < MEMO_PAD_WIDTH)) {
if (appData->padState.pencilActive == FALSE) {
if (appData->padData.pencilActive == FALSE) {
ErasePixelsAroundPoint(appData, endX, endY);
}
appData->padState.x = endX;
appData->padState.y = endY;
appData->padData.x = endX;
appData->padData.y = endY;
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_UPDATE_MEMO_CONTENT);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_UPDATE_CONTENT);
}
}
static BOOL Task_UnloadApp(PoketchMemoPad *appData)
static BOOL State_UnloadApp(PoketchMemoPad *appData)
{
switch (appData->taskFuncState) {
case 0:
PoketchMemoPadGraphics_StartTask(appData->graphics, TASK_FREE_BG);
PoketchMemoPadGraphics_StartTask(appData->graphics, MEMO_PAD_GRAPHICS_FREE);
appData->taskFuncState++;
break;
case 1:

View File

@ -2,7 +2,6 @@
#include "nitro/fx/fx.h"
#include <nitro.h>
#include <string.h>
#include "constants/graphics.h"
#include "constants/heap.h"
@ -29,7 +28,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(28), FX32_CONST(128) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -37,7 +36,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(116), FX32_CONST(128) },
.animIdx = 2,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -45,7 +44,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(108), FX32_CONST(40) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -53,7 +52,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(196), FX32_CONST(40) },
.animIdx = 2,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -61,7 +60,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(108), FX32_CONST(72) },
.animIdx = 0,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -69,7 +68,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
{
.translation = { FX32_CONST(196), FX32_CONST(72) },
.animIdx = 2,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -79,7 +78,7 @@ static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataButtons[]
static const PoketchAnimation_AnimationData sPoketchMoveTester_AnimDataExclamation = {
.translation = { FX32_CONST(44), FX32_CONST(48) },
.animIdx = 5,
.flip = 0,
.flip = NNS_G2D_RENDERERFLIP_NONE,
.oamPriority = 2,
.priority = 0,
.hasAffineTransform = 0,
@ -97,38 +96,40 @@ static const BgTemplate sMoveTesterBgTemplate = {
.bgExtPltt = GX_BG_EXTPLTT_01,
.priority = 2,
.areaOver = 0,
.mosaic = FALSE
.mosaic = FALSE,
};
static void SetupSprites(PoketchMoveTesterGraphics *graphics);
static void UnloadSprites(PoketchMoveTesterGraphics *graphics);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppScreen(SysTask *task, void *param1);
static void AddWindows(PoketchMoveTesterGraphics *graphics, const MoveTesterData *moveTesterData, u32 baseTile);
static void RemoveWindows(PoketchMoveTesterGraphics *graphics);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppScreen(SysTask *task, void *taskMan);
static void Task_FreeWindowsAndBG(SysTask *task, void *taskMan);
static void Task_ButtonPressed(SysTask *task, void *taskMan);
static void Task_ButtonReleased(SysTask *task, void *taskMan);
static void Task_UpdateGraphics(SysTask *task, void *taskMan);
static void UpdateGraphics(PoketchMoveTesterGraphics *graphics, const MoveTesterData *moveTesterData);
static void AddTypeText(PoketchMoveTesterGraphics *graphics, Window *window, enum PokemonType type);
static void AddEffectivenessText(PoketchMoveTesterGraphics *graphics, Window *window, u32 exclamCount);
static void DisplayExclamation(PoketchMoveTesterGraphics *graphics, u32 exclamCount);
BOOL PoketchMoveTesterGraphics_New(PoketchMoveTesterGraphics **graphics, const MoveTesterData *moveTesterData, BgConfig *bgConfig)
BOOL PoketchMoveTesterGraphics_New(PoketchMoveTesterGraphics **dest, const MoveTesterData *moveTesterData, BgConfig *bgConfig)
{
PoketchMoveTesterGraphics *moveTesterGraphics = (PoketchMoveTesterGraphics *)Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchMoveTesterGraphics));
PoketchMoveTesterGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchMoveTesterGraphics));
if (moveTesterGraphics != NULL) {
PoketchTask_InitActiveTaskList(moveTesterGraphics->activeTasks, NUM_TASK_SLOTS);
moveTesterGraphics->moveTesterData = moveTesterData;
moveTesterGraphics->bgConfig = PoketchGraphics_GetBgConfig();
moveTesterGraphics->animMan = PoketchGraphics_GetAnimationManager();
moveTesterGraphics->msgLoaderTypes = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_POKEMON_TYPE_NAMES, HEAP_ID_POKETCH_APP);
moveTesterGraphics->msgLoaderEffectiveness = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_UNK_0456, HEAP_ID_POKETCH_APP);
moveTesterGraphics->strBuf = Strbuf_Init(128, HEAP_ID_POKETCH_APP); // Possibly TRAINER_NAME_LEN + 1
SetupSprites(moveTesterGraphics);
*graphics = moveTesterGraphics;
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, MOVE_TESTER_TASK_SLOTS);
graphics->moveTesterData = moveTesterData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
graphics->msgLoaderTypes = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_POKEMON_TYPE_NAMES, HEAP_ID_POKETCH_APP);
graphics->msgLoaderEffectiveness = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_UNK_0456, HEAP_ID_POKETCH_APP);
graphics->strBuf = Strbuf_Init(128, HEAP_ID_POKETCH_APP); // Possibly TRAINER_NAME_LEN + 1
SetupSprites(graphics);
*dest = graphics;
return TRUE;
}
@ -184,20 +185,20 @@ void PoketchMoveTesterGraphics_Free(PoketchMoveTesterGraphics *graphics)
}
static const PoketchTask sMoveTesterTasks[] = {
{ TASK_DRAW_APP_SCREEN, Task_DrawAppScreen, 0x0 },
{ TASK_FREE_WINDOWS_AND_BG, Task_FreeWindowsAndBG, 0x0 },
{ TASK_BUTTON_PRESSED, Task_ButtonPressed, 0x0 },
{ TASK_BUTTON_RELEASED, Task_ButtonReleased, 0x0 },
{ TASK_UPDATE_GRAPHICS, Task_UpdateGraphics, 0x0 },
{ MOVE_TESTER_GRAPHICS_INIT, Task_DrawAppScreen, 0 },
{ MOVE_TESTER_GRAPHICS_FREE, Task_FreeWindowsAndBG, 0 },
{ MOVE_TESTER_GRAPHICS_BUTTON_PRESSED, Task_ButtonPressed, 0 },
{ MOVE_TESTER_GRAPHICS_BUTTON_RELEASED, Task_ButtonReleased, 0 },
{ MOVE_TESTER_GRAPHICS_UPDATE, Task_UpdateGraphics, 0 },
{ 0 }
};
void PoketchMoveTesterGraphics_StartTask(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTasks taskID)
void PoketchMoveTesterGraphics_StartTask(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTask taskID)
{
PoketchTask_Start(sMoveTesterTasks, taskID, graphics, graphics->moveTesterData, graphics->activeTasks, 2, HEAP_ID_POKETCH_APP);
}
BOOL PoketchMoveTesterGraphics_TaskIsNotActive(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTasks taskID)
BOOL PoketchMoveTesterGraphics_TaskIsNotActive(PoketchMoveTesterGraphics *graphics, enum MoveTesterGraphicsTask taskID)
{
return PoketchTask_TaskIsNotActive(graphics->activeTasks, taskID);
}
@ -225,10 +226,10 @@ static void Task_DrawAppScreen(SysTask *task, void *taskMan)
graphics = PoketchTask_GetTaskData(taskMan);
moveTesterData = PoketchTask_GetConstTaskData(taskMan);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &sMoveTesterBgTemplate, 0);
Bg_InitFromTemplate(graphics->bgConfig, BG_LAYER_SUB_2, &sMoveTesterBgTemplate, BG_TYPE_STATIC);
tileSize = Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 61, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, 1, HEAP_ID_POKETCH_APP);
Graphics_LoadTilemapToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 60, graphics->bgConfig, 6, 0, 0, 1, HEAP_ID_POKETCH_APP);
tileSize = Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 61, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadTilemapToBgLayer(NARC_INDEX_GRAPHIC__POKETCH, 60, graphics->bgConfig, BG_LAYER_SUB_2, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
PoketchGraphics_LoadActivePalette(0, 0);
tileSize /= 0x20;
@ -254,20 +255,20 @@ static void AddWindows(PoketchMoveTesterGraphics *graphics, const MoveTesterData
Window_Add(graphics->bgConfig, &(graphics->windowExclamations), BG_LAYER_SUB_2, 3, 19, 22, 2, PLTT_0, baseTile);
Window_PutToTilemap(&(graphics->windowAttackType));
Window_PutToTilemap(&(graphics->windowDefenderType1));
Window_PutToTilemap(&(graphics->windowDefenderType2));
Window_PutToTilemap(&(graphics->windowExclamations));
Window_PutToTilemap(&graphics->windowAttackType);
Window_PutToTilemap(&graphics->windowDefenderType1);
Window_PutToTilemap(&graphics->windowDefenderType2);
Window_PutToTilemap(&graphics->windowExclamations);
UpdateGraphics(graphics, moveTesterData);
}
static void RemoveWindows(PoketchMoveTesterGraphics *graphics)
{
Window_Remove(&(graphics->windowAttackType));
Window_Remove(&(graphics->windowDefenderType1));
Window_Remove(&(graphics->windowDefenderType2));
Window_Remove(&(graphics->windowExclamations));
Window_Remove(&graphics->windowAttackType);
Window_Remove(&graphics->windowDefenderType1);
Window_Remove(&graphics->windowDefenderType2);
Window_Remove(&graphics->windowExclamations);
}
static void Task_FreeWindowsAndBG(SysTask *task, void *taskMan)
@ -311,10 +312,10 @@ static void Task_UpdateGraphics(SysTask *task, void *taskMan)
static void UpdateGraphics(PoketchMoveTesterGraphics *graphics, const MoveTesterData *moveTesterData)
{
AddTypeText(graphics, &(graphics->windowAttackType), moveTesterData->attackType);
AddTypeText(graphics, &(graphics->windowDefenderType1), moveTesterData->defenderType1);
AddTypeText(graphics, &(graphics->windowDefenderType2), moveTesterData->defenderType2);
AddEffectivenessText(graphics, &(graphics->windowExclamations), moveTesterData->exclamCount);
AddTypeText(graphics, &graphics->windowAttackType, moveTesterData->attackType);
AddTypeText(graphics, &graphics->windowDefenderType1, moveTesterData->defenderType1);
AddTypeText(graphics, &graphics->windowDefenderType2, moveTesterData->defenderType2);
AddEffectivenessText(graphics, &graphics->windowExclamations, moveTesterData->exclamCount);
DisplayExclamation(graphics, moveTesterData->exclamCount);
}

View File

@ -1,6 +1,5 @@
#include <nitro.h>
#include <nitro/sinit.h>
#include <string.h>
#include "constants/heap.h"
#include "generated/pokemon_types.h"
@ -17,8 +16,8 @@
#include "touch_screen.h"
typedef struct PoketchMoveTester {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
u32 appID;
MoveTesterData moveTesterData;
@ -28,10 +27,10 @@ typedef struct PoketchMoveTester {
u32 buttonState;
} PoketchMoveTester;
enum MoveTesterTasks {
TASK_LOAD_APP = 0,
TASK_UPDATE_LOOP,
TASK_SHUTDOWN,
enum MoveTesterState {
STATE_LOAD_APP = 0,
STATE_UPDATE_LOOP,
STATE_SHUTDOWN,
};
#define X(__d) MT_##__d##_X
@ -94,15 +93,6 @@ static const u8 sMoveTesterTypeOrder[] = {
TYPE_STEEL
};
static const TouchScreenHitTable sHitTableMoveTester[] = {
{ .rect = { .top = 112, .bottom = 144, .left = 16, .right = 40 } },
{ .rect = { .top = 112, .bottom = 144, .left = 104, .right = 128 } },
{ .rect = { .top = 24, .bottom = 56, .left = 96, .right = 120 } },
{ .rect = { .top = 24, .bottom = 56, .left = 184, .right = 208 } },
{ .rect = { .top = 56, .bottom = 88, .left = 96, .right = 120 } },
{ .rect = { .top = 56, .bottom = 88, .left = 184, .right = 208 } }
};
static void NitroStaticInit(void);
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
@ -111,7 +101,7 @@ static void InitData(MoveTesterData *moveTesterData);
static void Free(PoketchMoveTester *appData);
static void Exit(void *appData);
static void ChangeState(PoketchMoveTester *appData, enum MoveTesterTasks taskID);
static void ChangeState(PoketchMoveTester *appData, enum MoveTesterState newState);
static void Task_Main(SysTask *task, void *appData);
static BOOL State_LoadApp(PoketchMoveTester *appData);
static BOOL State_UpdateApp(PoketchMoveTester *appData);
@ -147,15 +137,24 @@ static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u
static BOOL Init(PoketchMoveTester *appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
static const TouchScreenRect sHitTableMoveTester[] = {
{ .rect = { .top = 112, .bottom = 144, .left = 16, .right = 40 } },
{ .rect = { .top = 112, .bottom = 144, .left = 104, .right = 128 } },
{ .rect = { .top = 24, .bottom = 56, .left = 96, .right = 120 } },
{ .rect = { .top = 24, .bottom = 56, .left = 184, .right = 208 } },
{ .rect = { .top = 56, .bottom = 88, .left = 96, .right = 120 } },
{ .rect = { .top = 56, .bottom = 88, .left = 184, .right = 208 } },
};
appData->appID = appID;
if (PoketchMemory_Read32(appID, &(appData->moveTesterData), sizeof(appData->moveTesterData)) == FALSE) {
InitData(&(appData->moveTesterData));
if (PoketchMemory_Read32(appID, &appData->moveTesterData, sizeof(appData->moveTesterData)) == FALSE) {
InitData(&appData->moveTesterData);
}
if (PoketchMoveTesterGraphics_New(&(appData->graphics), &(appData->moveTesterData), bgConfig)) {
appData->activeTask = TASK_LOAD_APP;
appData->taskFuncState = 0;
appData->state = STATE_LOAD_APP;
appData->subState = 0;
appData->shouldExit = FALSE;
appData->buttonManager = PoketchButtonManager_New(sHitTableMoveTester, NELEMS(sHitTableMoveTester), ButtonChanged, appData, HEAP_ID_POKETCH_APP);
appData->buttonState = BUTTON_MANAGER_STATE_NULL;
@ -178,7 +177,7 @@ static void InitData(MoveTesterData *moveTesterData)
static void Free(PoketchMoveTester *appData)
{
PoketchMemory_Write32(appData->appID, &(appData->moveTesterData), sizeof(appData->moveTesterData));
PoketchMemory_Write32(appData->appID, &appData->moveTesterData, sizeof(appData->moveTesterData));
PoketchButtonManager_Free(appData->buttonManager);
PoketchMoveTesterGraphics_Free(appData->graphics);
Heap_Free(appData);
@ -194,10 +193,10 @@ static void Task_Main(SysTask *task, void *appData)
PoketchMoveTester *moveTester = appData;
if (moveTester->activeTask < NELEMS(stateFuncs)) {
if (moveTester->state < NELEMS(stateFuncs)) {
PoketechSystem_UpdateButtonManager(moveTester->poketchSys, moveTester->buttonManager);
if (stateFuncs[moveTester->activeTask](moveTester)) {
if (stateFuncs[moveTester->state](moveTester)) {
Free(moveTester);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(moveTester->poketchSys);
@ -210,7 +209,7 @@ static void ButtonChanged(u32 buttonID, u32 buttonState, u32 touchState, void *a
PoketchMoveTester *moveTester = appData;
moveTester->moveTesterData.lastButtonPressed = buttonID;
moveTester->buttonState = (enum ButtonManagerState)buttonState;
moveTester->buttonState = buttonState;
}
static void Exit(void *appData)
@ -219,28 +218,28 @@ static void Exit(void *appData)
moveTester->shouldExit = TRUE;
}
static void ChangeState(PoketchMoveTester *appData, enum MoveTesterTasks taskID)
static void ChangeState(PoketchMoveTester *appData, enum MoveTesterState newState)
{
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = newState;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL State_LoadApp(PoketchMoveTester *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_DRAW_APP_SCREEN);
appData->taskFuncState++;
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_INIT);
appData->subState++;
break;
case 1:
if (PoketchMoveTesterGraphics_TaskIsNotActive(appData->graphics, TASK_DRAW_APP_SCREEN)) {
if (PoketchMoveTesterGraphics_TaskIsNotActive(appData->graphics, MOVE_TESTER_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
ChangeState(appData, TASK_UPDATE_LOOP);
ChangeState(appData, STATE_UPDATE_LOOP);
}
break;
}
@ -252,23 +251,23 @@ static BOOL State_UpdateApp(PoketchMoveTester *appData)
{
if (appData->shouldExit) {
if (PoketchMoveTesterGraphics_NoActiveTasks(appData->graphics)) {
ChangeState(appData, TASK_SHUTDOWN);
ChangeState(appData, STATE_SHUTDOWN);
}
return FALSE;
}
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
if (appData->buttonState == BUTTON_MANAGER_STATE_TOUCH) {
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_BUTTON_PRESSED);
appData->taskFuncState++;
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_BUTTON_PRESSED);
appData->subState++;
}
break;
case 1:
if (appData->buttonState == BUTTON_MANAGER_STATE_DRAGGING) {
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_BUTTON_RELEASED);
appData->taskFuncState = 0;
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_BUTTON_RELEASED);
appData->subState = 0;
break;
}
@ -295,15 +294,15 @@ static BOOL State_UpdateApp(PoketchMoveTester *appData)
}
appData->moveTesterData.exclamCount = GetExclamationCount(appData->moveTesterData.attackType, appData->moveTesterData.defenderType1, appData->moveTesterData.defenderType2);
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_BUTTON_RELEASED);
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
appData->taskFuncState++;
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_BUTTON_RELEASED);
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_UPDATE);
appData->subState++;
break;
}
break;
case 2:
if (PoketchMoveTesterGraphics_NoActiveTasks(appData->graphics)) {
appData->taskFuncState = 0;
appData->subState = 0;
}
break;
}
@ -313,10 +312,10 @@ static BOOL State_UpdateApp(PoketchMoveTester *appData)
static BOOL State_UnloadApp(PoketchMoveTester *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchMoveTesterGraphics_StartTask(appData->graphics, TASK_FREE_WINDOWS_AND_BG);
appData->taskFuncState++;
PoketchMoveTesterGraphics_StartTask(appData->graphics, MOVE_TESTER_GRAPHICS_FREE);
appData->subState++;
break;
case 1:
if (PoketchMoveTesterGraphics_NoActiveTasks(appData->graphics)) {

View File

@ -57,7 +57,7 @@ BOOL PartyStatusGraphics_New(PartyStatusGraphics **dest, const PartyStatus *part
PartyStatusGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PartyStatusGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTaskIds, 8);
PoketchTask_InitActiveTaskList(graphics->activeTaskIds, PARTY_STATUS_TASK_SLOTS);
graphics->partyData = partyData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();

View File

@ -30,7 +30,7 @@ BOOL PoketchPedometerGraphics_New(PedometerGraphics **dest, const PedometerData
PedometerGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PedometerGraphics));
if (graphics != NULL) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, 4);
PoketchTask_InitActiveTaskList(graphics->activeTasks, PEDOMETER_TASK_SLOTS);
graphics->pedometerData = pedometerData;
graphics->bgConfig = PoketchGraphics_GetBgConfig();
graphics->animMan = PoketchGraphics_GetAnimationManager();
@ -73,13 +73,13 @@ static void SetupSprites(PedometerGraphics *graphics, const PedometerData *pedom
};
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 2, DS_SCREEN_SUB, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 52, DS_SCREEN_SUB, 80 * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 52, DS_SCREEN_SUB, POKETCH_DIGITS_NCGR_NUM_TILES * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
PoketchAnimation_LoadSpriteFromNARC(&graphics->buttonSprites, NARC_INDEX_GRAPHIC__POKETCH, 50, 51, HEAP_ID_POKETCH_APP);
PoketchAnimation_LoadSpriteFromNARC(&graphics->digitSprites, NARC_INDEX_GRAPHIC__POKETCH, 3, 4, HEAP_ID_POKETCH_APP);
graphics->buttonAnimation = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &buttonAnimData, &graphics->buttonSprites);
PoketchAnimation_SetSpriteCharNo(graphics->buttonAnimation, 80);
PoketchAnimation_SetSpriteCharNo(graphics->buttonAnimation, POKETCH_DIGITS_NCGR_NUM_TILES);
for (int i = 0; i < NUM_DIGITS; i++) {
graphics->digitsAnimation[i] = PoketchAnimation_SetupNewAnimatedSprite(graphics->animMan, &digitsAnimData, &graphics->digitSprites);

View File

@ -20,7 +20,7 @@ typedef struct PoketchPedometer {
PedometerGraphics *graphics;
PoketchSystem *poketchSys;
PoketchButtonManager *buttonManager;
u32 buttonState;
enum ButtonManagerState buttonState;
Poketch *poketch;
} PoketchPedometer;

View File

@ -56,7 +56,7 @@ typedef struct PoketchGraphics_AppCounterAnimationData {
struct PoketchGraphics_TaskData {
const PoketchGraphics_ConstTaskData *constTaskData;
u32 activeTasks[BASE_IDX + NUM_TASK_SLOTS];
u32 activeTasks[POKETCH_TASK_SLOT_BASE + NUM_TASK_SLOTS];
u16 tilemapUpBtnPressed[BUTTON_TILEMAP_SIZE];
u16 tilemapUpBtnHalfPressed[BUTTON_TILEMAP_SIZE];
u16 tilemapUpBtn[BUTTON_TILEMAP_SIZE];

View File

@ -35,7 +35,7 @@ void PoketchTask_InitActiveTaskList(u32 *activeList, u32 numTaskSlots)
activeList[VALIDATOR_IDX] = POKETCH_TASK_LIST_VALIDATOR;
for (u32 slot = 0; slot < numTaskSlots; slot++) {
activeList[BASE_IDX + slot] = POKETCH_EMPTY_TASK;
activeList[POKETCH_TASK_SLOT_BASE + slot] = POKETCH_EMPTY_TASK;
}
}
@ -44,8 +44,8 @@ static BOOL AddTaskToActiveList(u32 *activeList, u32 taskId)
GF_ASSERT(activeList[VALIDATOR_IDX] == POKETCH_TASK_LIST_VALIDATOR);
for (u32 slot = 0; slot < activeList[NUM_SLOTS_IDX]; slot++) {
if (activeList[BASE_IDX + slot] == POKETCH_EMPTY_TASK) {
activeList[BASE_IDX + slot] = taskId;
if (activeList[POKETCH_TASK_SLOT_BASE + slot] == POKETCH_EMPTY_TASK) {
activeList[POKETCH_TASK_SLOT_BASE + slot] = taskId;
return TRUE;
}
}
@ -58,8 +58,8 @@ static void RemoveTaskFromActiveList(u32 *activeList, u32 taskId)
GF_ASSERT(activeList[VALIDATOR_IDX] == POKETCH_TASK_LIST_VALIDATOR);
for (u32 slot = 0; slot < activeList[NUM_SLOTS_IDX]; slot++) {
if (activeList[BASE_IDX + slot] == taskId) {
activeList[BASE_IDX + slot] = POKETCH_EMPTY_TASK;
if (activeList[POKETCH_TASK_SLOT_BASE + slot] == taskId) {
activeList[POKETCH_TASK_SLOT_BASE + slot] = POKETCH_EMPTY_TASK;
return;
}
}
@ -70,7 +70,7 @@ static void RemoveTaskFromActiveList(u32 *activeList, u32 taskId)
BOOL PoketchTask_TaskIsNotActive(u32 *activeList, u32 taskId)
{
for (u32 slot = 0; slot < activeList[NUM_SLOTS_IDX]; slot++) {
if (activeList[BASE_IDX + slot] == taskId) {
if (activeList[POKETCH_TASK_SLOT_BASE + slot] == taskId) {
return FALSE;
}
}
@ -81,7 +81,7 @@ BOOL PoketchTask_TaskIsNotActive(u32 *activeList, u32 taskId)
BOOL PoketchTask_NoActiveTasks(u32 *activeList)
{
for (u32 slot = 0; slot < activeList[NUM_SLOTS_IDX]; slot++) {
if (activeList[BASE_IDX + slot] != POKETCH_EMPTY_TASK) {
if (activeList[POKETCH_TASK_SLOT_BASE + slot] != POKETCH_EMPTY_TASK) {
return FALSE;
}
}

View File

@ -1,4 +1,4 @@
#include "graphics.h"
#include "applications/poketch/stopwatch/graphics.h"
#include <nitro.h>
@ -8,9 +8,9 @@
#include "applications/poketch/poketch_graphics.h"
#include "applications/poketch/poketch_system.h"
#include "applications/poketch/poketch_task.h"
#include "applications/poketch/stopwatch/graphics.h"
#include "bg_window.h"
#include "graphics.h"
#include "heap.h"
#include "sys_task.h"
#include "sys_task_manager.h"
@ -46,12 +46,14 @@ typedef struct ButtonBlinkManager {
u8 buttonTileGroup;
} ButtonBlinkManager;
static void Task_UpdateTimer(SysTask *task, void *graphics);
static void SetupSprites(PoketchStopwatchGraphics *graphics, const TimerState *timerState);
static void UnloadSprites(PoketchStopwatchGraphics *graphics);
static void UpdateTimerDigits(PoketchStopwatchGraphics *graphics);
static BOOL LoadObjectTiles(PoketchStopwatchGraphics *graphics);
static void EndTask(PoketchTaskManager *taskMan);
static void Task_DrawAppScreen(SysTask *task, void *taskMan);
static BOOL LoadObjectTiles(PoketchStopwatchGraphics *graphics);
static void SetupSprites(PoketchStopwatchGraphics *graphics, const TimerState *timerState);
static void Task_UpdateTimer(SysTask *task, void *graphics);
static void Task_UpdateGraphics(SysTask *task, void *taskMan);
static void Task_HandleInactiveTimerGraphics(SysTask *task, void *taskMan);
static void Task_HandleTimerTransition(SysTask *task, void *taskMan);
@ -60,33 +62,33 @@ static void Task_HandleBeginButtonBlinking(SysTask *task, void *taskMan);
static void Task_HandleSpeedUpButtonBlinking(SysTask *task, void *taskMan);
static void Task_BeginExplosion(SysTask *task, void *taskMan);
static void Task_PostResetBlinkingAnimation(SysTask *task, void *taskMan);
static void Task_FreeGraphics(SysTask *task, void *taskMan);
static BOOL UpdateBlinkState(ButtonBlinkManager *blinkManager, u32 framesPerBlinkState);
static void UpdateButtonTiles(BgConfig *bgConfig, enum ButtonTileGroup buttonTileGroup);
static void Task_FreeGraphics(SysTask *task, void *taskMan);
static void UnloadSprites(PoketchStopwatchGraphics *graphics);
struct PoketchSystem *FieldSystem_GetPoketchSystem(void);
BOOL PoketchStopwatchGraphics_New(PoketchStopwatchGraphics **graphics, const TimerState *timerState, BgConfig *bgConfig)
BOOL PoketchStopwatchGraphics_New(PoketchStopwatchGraphics **dest, const TimerState *timerState, BgConfig *bgConfig)
{
PoketchStopwatchGraphics *stopwatchGraphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchStopwatchGraphics));
PoketchStopwatchGraphics *graphics = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchStopwatchGraphics));
if (stopwatchGraphics != NULL) {
stopwatchGraphics->timerState = timerState;
stopwatchGraphics->animMan = PoketchGraphics_GetAnimationManager();
stopwatchGraphics->bgConfig = BgConfig_New(HEAP_ID_POKETCH_APP);
if (graphics != NULL) {
graphics->timerState = timerState;
graphics->animMan = PoketchGraphics_GetAnimationManager();
graphics->bgConfig = BgConfig_New(HEAP_ID_POKETCH_APP);
if (stopwatchGraphics->bgConfig == NULL) {
if (graphics->bgConfig == NULL) {
return FALSE;
}
if (PoketchAnimation_LoadSpriteFromNARC(&stopwatchGraphics->voltorbSprites, NARC_INDEX_GRAPHIC__POKETCH, 18, 19, HEAP_ID_POKETCH_APP)) {
if (PoketchAnimation_LoadSpriteFromNARC(&stopwatchGraphics->digitSprites, NARC_INDEX_GRAPHIC__POKETCH, 3, 4, HEAP_ID_POKETCH_APP)) {
PoketchTask_InitActiveTaskList(stopwatchGraphics->activeTasks, NUM_TASK_SLOTS);
stopwatchGraphics->timerUpdateTask = NULL;
*graphics = stopwatchGraphics;
if (PoketchAnimation_LoadSpriteFromNARC(&graphics->voltorbSprites, NARC_INDEX_GRAPHIC__POKETCH, 18, 19, HEAP_ID_POKETCH_APP)) {
if (PoketchAnimation_LoadSpriteFromNARC(&graphics->digitSprites, NARC_INDEX_GRAPHIC__POKETCH, 3, 4, HEAP_ID_POKETCH_APP)) {
PoketchTask_InitActiveTaskList(graphics->activeTasks, STOPWATCH_TASK_SLOTS);
graphics->timerUpdateTask = NULL;
*dest = graphics;
return TRUE;
} else {
PoketchAnimation_FreeSpriteData(&stopwatchGraphics->voltorbSprites);
PoketchAnimation_FreeSpriteData(&graphics->voltorbSprites);
}
}
}
@ -148,9 +150,9 @@ static void UpdateTimerDigits(PoketchStopwatchGraphics *graphics)
}
static const PoketchTask sStopwatchTasks[] = {
{ TASK_DRAW_APP_SCREEN, Task_DrawAppScreen, 0x0 },
{ TASK_UPDATE_GRAPHICS, Task_UpdateGraphics, sizeof(ButtonBlinkManager) },
{ TASK_FREE_GRAPHICS, Task_FreeGraphics, 0x0 },
{ STOPWATCH_GRAPHICS_INIT, Task_DrawAppScreen, 0 },
{ STOPWATCH_GRAPHICS_UPDATE, Task_UpdateGraphics, sizeof(ButtonBlinkManager) },
{ STOPWATCH_GRAPHICS_FREE, Task_FreeGraphics, 0 },
{ 0 }
};
@ -212,7 +214,7 @@ static void Task_DrawAppScreen(SysTask *task, void *taskMan)
UpdateTimerDigits(graphics);
if (timerState->isActive) {
PoketchStopwatchGraphics_StartTask(graphics, TASK_UPDATE_GRAPHICS);
PoketchStopwatchGraphics_StartTask(graphics, STOPWATCH_GRAPHICS_UPDATE);
}
dispCnt = GXS_GetDispCnt();
@ -224,7 +226,7 @@ static void Task_DrawAppScreen(SysTask *task, void *taskMan)
static BOOL LoadObjectTiles(PoketchStopwatchGraphics *graphics)
{
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 2, DS_SCREEN_SUB, 0, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 22, DS_SCREEN_SUB, 80 * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
Graphics_LoadObjectTiles(NARC_INDEX_GRAPHIC__POKETCH, 22, DS_SCREEN_SUB, POKETCH_DIGITS_NCGR_NUM_TILES * TILE_SIZE_4BPP, 0, TRUE, HEAP_ID_POKETCH_APP);
return TRUE;
}

View File

@ -24,8 +24,8 @@ typedef struct SavedTimerValue {
} SavedTimerValue;
typedef struct PoketchStopwatch {
u8 activeTask;
u8 taskFuncState;
u8 state;
u8 subState;
u8 shouldExit;
u8 previousTask;
u8 buttonState;
@ -40,13 +40,13 @@ typedef struct PoketchStopwatch {
PoketchSystem *poketchSys;
} PoketchStopwatch;
enum StopwatchTasks {
TASK_LOAD_APP = 0,
TASK_INACTIVE_TIMER,
TASK_ACTIVE_TIMER,
TASK_BUTTON_HELD,
TASK_RESET_TIMER,
TASK_SHUTDOWN
enum StopwatchTask {
STATE_LOAD_APP = 0,
STATE_INACTIVE_TIMER,
STATE_ACTIVE_TIMER,
STATE_BUTTON_HELD,
STATE_RESET_TIMER,
STATE_SHUTDOWN
};
static void NitroStaticInit(void);
@ -54,15 +54,17 @@ static void NitroStaticInit(void);
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID);
static BOOL Init(PoketchStopwatch *appData, BgConfig *bgConfig, u32 appID);
static void Free(PoketchStopwatch *appData);
static void Task_Main(SysTask *task, void *appData);
static void Exit(void *appData);
static void ChangeActiveTask(PoketchStopwatch *appData, enum StopwatchTasks taskID);
static BOOL Task_LoadApp(PoketchStopwatch *appData);
static BOOL Task_HandleInactiveTimer(PoketchStopwatch *appData);
static BOOL Task_HandleActiveTimer(PoketchStopwatch *appData);
static BOOL Task_HandleHeldButton(PoketchStopwatch *appData);
static BOOL Task_HandleResetSequence(PoketchStopwatch *appData);
static BOOL Task_UnloadApp(PoketchStopwatch *appData);
static void Task_Main(SysTask *task, void *appData);
static void ChangeState(PoketchStopwatch *appData, enum StopwatchTask newState);
static BOOL State_LoadApp(PoketchStopwatch *appData);
static BOOL State_InactiveTimer(PoketchStopwatch *appData);
static BOOL State_ActiveTimer(PoketchStopwatch *appData);
static BOOL State_HoldingButton(PoketchStopwatch *appData);
static BOOL State_ResetSequence(PoketchStopwatch *appData);
static BOOL State_UnloadApp(PoketchStopwatch *appData);
static BOOL RegisterButtonCallback(PoketchStopwatch *appData);
static void FreeButtonManager(PoketchStopwatch *appData);
static void ButtonChanged(u32 buttonID, u32 buttonState, u32 touchState, void *appData);
@ -78,7 +80,7 @@ static void NitroStaticInit(void)
static BOOL New(void **appData, PoketchSystem *poketchSys, BgConfig *bgConfig, u32 appID)
{
PoketchStopwatch *stopwatch = (PoketchStopwatch *)Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchStopwatch));
PoketchStopwatch *stopwatch = Heap_Alloc(HEAP_ID_POKETCH_APP, sizeof(PoketchStopwatch));
if (stopwatch != NULL) {
if (Init(stopwatch, bgConfig, appID)) {
@ -121,9 +123,9 @@ static BOOL Init(PoketchStopwatch *appData, BgConfig *bgConfig, u32 appID)
}
if (PoketchStopwatchGraphics_New(&appData->graphics, &appData->timerState, bgConfig)) {
appData->activeTask = TASK_DRAW_APP_SCREEN;
appData->taskFuncState = 0;
appData->previousTask = appData->activeTask;
appData->state = STOPWATCH_GRAPHICS_INIT;
appData->subState = 0;
appData->previousTask = appData->state;
appData->shouldExit = FALSE;
if (RegisterButtonCallback(appData)) {
@ -155,26 +157,26 @@ static void Free(PoketchStopwatch *appData)
static void Task_Main(SysTask *task, void *appData)
{
static BOOL (*const stateFuncs[])(PoketchStopwatch *) = {
Task_LoadApp,
Task_HandleInactiveTimer,
Task_HandleActiveTimer,
Task_HandleHeldButton,
Task_HandleResetSequence,
Task_UnloadApp
State_LoadApp,
State_InactiveTimer,
State_ActiveTimer,
State_HoldingButton,
State_ResetSequence,
State_UnloadApp
};
PoketchStopwatch *stopwatch = appData;
if (stopwatch->activeTask < NELEMS(stateFuncs)) {
if (stopwatch->shouldExit && (stopwatch->activeTask != TASK_SHUTDOWN)) {
ChangeActiveTask(stopwatch, TASK_SHUTDOWN);
if (stopwatch->state < NELEMS(stateFuncs)) {
if (stopwatch->shouldExit && (stopwatch->state != STATE_SHUTDOWN)) {
ChangeState(stopwatch, STATE_SHUTDOWN);
stopwatch->shouldExit = FALSE;
}
PoketechSystem_UpdateButtonManager(stopwatch->poketchSys, stopwatch->buttonManager);
CalcTimerValues(stopwatch, &stopwatch->timerState);
if (stateFuncs[stopwatch->activeTask](stopwatch)) {
if (stateFuncs[stopwatch->state](stopwatch)) {
Free(stopwatch);
SysTask_Done(task);
PoketchSystem_NotifyAppUnloaded(stopwatch->poketchSys);
@ -187,35 +189,35 @@ static void Exit(void *appData)
((PoketchStopwatch *)appData)->shouldExit = TRUE;
}
static void ChangeActiveTask(PoketchStopwatch *appData, enum StopwatchTasks taskID)
static void ChangeState(PoketchStopwatch *appData, enum StopwatchTask taskID)
{
appData->previousTask = appData->activeTask;
appData->previousTask = appData->state;
if (appData->shouldExit == FALSE) {
appData->activeTask = taskID;
appData->state = taskID;
} else {
appData->activeTask = TASK_SHUTDOWN;
appData->state = STATE_SHUTDOWN;
appData->shouldExit = FALSE;
}
appData->taskFuncState = 0;
appData->subState = 0;
}
static BOOL Task_LoadApp(PoketchStopwatch *appData)
static BOOL State_LoadApp(PoketchStopwatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_DRAW_APP_SCREEN);
appData->taskFuncState++;
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_INIT);
appData->subState++;
break;
case 1:
if (PoketchStopwatchGraphics_TaskIsNotActive(appData->graphics, TASK_DRAW_APP_SCREEN)) {
if (PoketchStopwatchGraphics_TaskIsNotActive(appData->graphics, STOPWATCH_GRAPHICS_INIT)) {
PoketchSystem_NotifyAppLoaded(appData->poketchSys);
if (appData->timerState.isActive) {
ChangeActiveTask(appData, TASK_ACTIVE_TIMER);
ChangeState(appData, STATE_ACTIVE_TIMER);
} else {
ChangeActiveTask(appData, TASK_INACTIVE_TIMER);
ChangeState(appData, STATE_INACTIVE_TIMER);
}
}
break;
@ -224,33 +226,33 @@ static BOOL Task_LoadApp(PoketchStopwatch *appData)
return FALSE;
}
static BOOL Task_HandleInactiveTimer(PoketchStopwatch *appData)
static BOOL State_InactiveTimer(PoketchStopwatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
if (appData->buttonState == BUTTON_MANAGER_STATE_TOUCH) {
appData->timerState.buttonSequence = 1;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
appData->taskFuncState++;
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
appData->subState++;
}
break;
case 1:
switch (appData->buttonState) {
case BUTTON_MANAGER_STATE_DRAGGING:
appData->timerState.buttonSequence = 0;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
appData->taskFuncState--;
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
appData->subState--;
break;
case BUTTON_MANAGER_STATE_TAP:
appData->timerState.buttonSequence = 2;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
StartTimer(appData);
ChangeActiveTask(appData, TASK_ACTIVE_TIMER);
ChangeState(appData, STATE_ACTIVE_TIMER);
break;
case BUTTON_MANAGER_STATE_TIMER0:
appData->timerState.buttonSequence = 3;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_BUTTON_HELD);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_BUTTON_HELD);
break;
}
break;
@ -259,33 +261,33 @@ static BOOL Task_HandleInactiveTimer(PoketchStopwatch *appData)
return FALSE;
}
static BOOL Task_HandleActiveTimer(PoketchStopwatch *appData)
static BOOL State_ActiveTimer(PoketchStopwatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
if (appData->buttonState == BUTTON_MANAGER_STATE_TOUCH) {
appData->timerState.buttonSequence = 1;
PauseTimer(appData);
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
appData->taskFuncState++;
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
appData->subState++;
}
break;
case 1:
switch (appData->buttonState) {
case BUTTON_MANAGER_STATE_DRAGGING:
appData->timerState.buttonSequence = 0;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_INACTIVE_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_INACTIVE_TIMER);
break;
case BUTTON_MANAGER_STATE_TAP:
appData->timerState.buttonSequence = 0;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_INACTIVE_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_INACTIVE_TIMER);
break;
case BUTTON_MANAGER_STATE_TIMER0:
appData->timerState.buttonSequence = 3;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_BUTTON_HELD);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_BUTTON_HELD);
break;
}
break;
@ -294,60 +296,60 @@ static BOOL Task_HandleActiveTimer(PoketchStopwatch *appData)
return FALSE;
}
static BOOL Task_HandleHeldButton(PoketchStopwatch *appData)
static BOOL State_HoldingButton(PoketchStopwatch *appData)
{
switch (appData->buttonState) {
case BUTTON_MANAGER_STATE_TAP:
if (appData->previousTask == TASK_INACTIVE_TIMER) {
if (appData->previousTask == STATE_INACTIVE_TIMER) {
StartTimer(appData);
appData->timerState.buttonSequence = 2;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_ACTIVE_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_ACTIVE_TIMER);
break;
}
case BUTTON_MANAGER_STATE_DRAGGING:
appData->timerState.buttonSequence = 0;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_INACTIVE_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_INACTIVE_TIMER);
break;
case BUTTON_MANAGER_STATE_TIMER1:
appData->timerState.buttonSequence = 4;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_RESET_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_RESET_TIMER);
break;
}
return FALSE;
}
static BOOL Task_HandleResetSequence(PoketchStopwatch *appData)
static BOOL State_ResetSequence(PoketchStopwatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
appData->resetSequenceTimer = 0;
appData->taskFuncState++;
appData->subState++;
case 1:
if (++appData->resetSequenceTimer >= 90) {
appData->timerState.buttonSequence = 5;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
appData->resetSequenceTimer = 0;
appData->taskFuncState++;
appData->subState++;
}
break;
case 2:
if (++appData->resetSequenceTimer >= 60) {
appData->timerState.buttonSequence = 6;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ResetTimer(appData);
appData->resetSequenceTimer = 0;
appData->taskFuncState++;
appData->subState++;
}
break;
case 3:
if (PoketchStopwatchGraphics_TaskIsNotActive(appData->graphics, TASK_UPDATE_GRAPHICS)) {
if (PoketchStopwatchGraphics_TaskIsNotActive(appData->graphics, STOPWATCH_GRAPHICS_UPDATE)) {
appData->timerState.buttonSequence = 0;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_UPDATE_GRAPHICS);
ChangeActiveTask(appData, TASK_INACTIVE_TIMER);
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_UPDATE);
ChangeState(appData, STATE_INACTIVE_TIMER);
}
break;
}
@ -355,13 +357,13 @@ static BOOL Task_HandleResetSequence(PoketchStopwatch *appData)
return FALSE;
}
static BOOL Task_UnloadApp(PoketchStopwatch *appData)
static BOOL State_UnloadApp(PoketchStopwatch *appData)
{
switch (appData->taskFuncState) {
switch (appData->subState) {
case 0:
appData->timerState.buttonSequence = 7;
PoketchStopwatchGraphics_StartTask(appData->graphics, TASK_FREE_GRAPHICS);
appData->taskFuncState++;
PoketchStopwatchGraphics_StartTask(appData->graphics, STOPWATCH_GRAPHICS_FREE);
appData->subState++;
break;
case 1:
if (PoketchStopwatchGraphics_NoActiveTasks(appData->graphics)) {
@ -376,7 +378,7 @@ static BOOL Task_UnloadApp(PoketchStopwatch *appData)
static BOOL RegisterButtonCallback(PoketchStopwatch *appData)
{
static const TouchScreenHitTable buttonHitBox[] = {
{ TOUCHSCREEN_USE_CIRCLE, 112, 112, 39 },
{ .circle = { .code = TOUCHSCREEN_USE_CIRCLE, .x = 112, .y = 112, .r = 39 } },
};
appData->buttonManager = PoketchButtonManager_New(buttonHitBox, NELEMS(buttonHitBox), ButtonChanged, appData, HEAP_ID_POKETCH_APP);