Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
trophy.c File Reference

Detailed Description

Trophies for swadge modes.

Author
Jerem.nosp@m.y.St.nosp@m.intzc.nosp@m.um@g.nosp@m.mail..nosp@m.com
Date
2025-05-22

Data Structures

struct  trophyDataWrapper_t
 
struct  trophyDisplayList_t
 
struct  trophySystem_t
 

Macros

#define DEFAULT_MILESTONE   25
 
#define BANNER_HEIGHT   48
 
#define BANNER_MAX_ICON_DIM   36
 
#define SCREEN_CORNER_CLEARANCE   19
 
#define IMAGE_BUFFER   8
 
#define NUMBER_TEXT_BUFFER   25
 
#define NUM_COLORS   6
 

Functions

int32_t _loadLatestWin (char *buffer)
 Loads ther index of the latest win.
 
void trophySystemInit (trophyDataList_t *data, const char *modeName)
 Initializes the Trophy system settings. The system is a global setting and every mode needs to set this when entered to avoid copying from other modes.
 
bool trophyUpdate (trophyData_t t, int newVal, bool drawUpdate)
 Updates specifed trophy if required.
 
bool trophyUpdateMilestone (trophyData_t t, int newVal, int threshold)
 Updates just like trophyUpdate(), but only draws when crossing percentage boundary.
 
int32_t trophyGetSavedValue (trophyData_t t)
 Returns the value saved to the NVS or 0 if the key isn't found.
 
bool trophySetChecklistTask (trophyData_t t, int32_t flag, bool set, bool drawUpdate)
 Sets or unsets a checklist item.
 
void trophyClear (trophyData_t t)
 Erases completion data from swadge. Only use in extreme circumstances.
 
bool checkBitFlag (int32_t flags, int8_t idx)
 Checks an individual bit flag out of a int32.
 
void setBitFlag (int32_t *flags, int8_t idx, bool setTrue)
 Set a bit flag.
 
int trophyGetPoints (bool total, const char *modeName)
 Get the point totals for the gamer score.
 
trophyData_t trophyGetLatest ()
 Get the Latest Trophy Idx object.
 
void trophySetSystemData (trophyDataList_t *dl, const char *modeName)
 Set the Trophy System to a specific mode's values.
 
bool isTrophyDrawing (void)
 Check if a trophy is currently being drawn.
 
void trophyDraw (font_t *fnt, int64_t elapsedUs)
 Draws the banner if one is queued.
 
void trophyDrawListInit (trophyListDisplayMode_t mode)
 Initialize the trophy Draw list.
 
void trophyDrawListColors (paletteColor_t background, paletteColor_t panel, paletteColor_t shadowBoxes, paletteColor_t dimText, paletteColor_t titleText, paletteColor_t checkmark)
 Set the colors of the panel to custom. Call after initialization of the list, or it'll be overwritten.
 
void trophyDrawListDeinit ()
 Tears down the WSGs and height list.
 
void trophyDrawList (font_t *fnt, int yOffset)
 Draws the list.
 

Data Structure Documentation

◆ trophyDataWrapper_t

struct trophyDataWrapper_t
Data Fields
trophyData_t trophyData Individual trophy data.
int32_t currentVal Saved value of the trophy.
wsg_t image Where the image is loaded.
bool active If this slot is loaded and ready to animate.

◆ trophyDisplayList_t

struct trophyDisplayList_t
Data Fields
int * heights Total height of the stack.
int platHeight Height of ther plat frame.
wsg_t * images Array of images to display.
trophyListDisplayMode_t mode Current display mode.
paletteColor_t colorList[NUM_COLORS]

◆ trophySystem_t

struct trophySystem_t
Data Fields
trophyDataList_t * data The settings of how the trophies behave.
list_t trophyQueue List of trophy updates to display. Holds type trophyDataWrapper_t*.
int numTrophiesScore Num of trophies adjusted for difficulty.
trophyData_t plat Platinum trophy data.
int32_t platVal Value of the platinum trophy.
wsg_t platImg Platinum's image.
bool active If the mode should be drawing a banner.
int32_t animTimer Timer used for sliding in and out.
wsgPalette_t grayPalette Grayscale palette for locked trophies.
wsgPalette_t normalPalette Normal colors.
trophyDisplayList_t tdl Display list data.

Macro Definition Documentation

◆ DEFAULT_MILESTONE

#define DEFAULT_MILESTONE   25

◆ BANNER_HEIGHT

#define BANNER_HEIGHT   48

◆ BANNER_MAX_ICON_DIM

#define BANNER_MAX_ICON_DIM   36

◆ SCREEN_CORNER_CLEARANCE

#define SCREEN_CORNER_CLEARANCE   19

◆ IMAGE_BUFFER

#define IMAGE_BUFFER   8

◆ NUMBER_TEXT_BUFFER

#define NUMBER_TEXT_BUFFER   25

◆ NUM_COLORS

#define NUM_COLORS   6

Function Documentation

◆ _loadLatestWin()

int32_t _loadLatestWin ( char * buffer)

Loads ther index of the latest win.

Parameters
bufferArray to shove modename into
Returns
int32_t index of the trophy

◆ trophySystemInit()

void trophySystemInit ( trophyDataList_t * settings,
const char * modeName )

Initializes the Trophy system settings. The system is a global setting and every mode needs to set this when entered to avoid copying from other modes.

Parameters
settingsThe settings data
modeNameName of the mode

◆ trophyUpdate()

bool trophyUpdate ( trophyData_t t,
int newVal,
bool drawUpdate )

Updates specifed trophy if required.

Parameters
tTrophy to update
newValNew value to try to set. Behavior is set by trophy type
drawUpdateIf this update should be drawn to the screen
Returns
true if a notification is being drawn, false otherwise

◆ trophyUpdateMilestone()

bool trophyUpdateMilestone ( trophyData_t t,
int newVal,
int threshold )

Updates just like trophyUpdate(), but only draws when crossing percentage boundary.

Parameters
tTrophy to update
newValValue to attempt to set
thresholdValue (0-100, representing a percent) to draw at
Returns
true if a notification is being drawn, false otherwise

◆ trophyGetSavedValue()

int32_t trophyGetSavedValue ( trophyData_t t)

Returns the value saved to the NVS or 0 if the key isn't found.

Parameters
tTrophy to grab value for
Returns
int32_t Stored value for the requested trophy

◆ trophySetChecklistTask()

bool trophySetChecklistTask ( trophyData_t t,
int32_t flag,
bool unset,
bool drawUpdate )

Sets or unsets a checklist item.

Parameters
tTrophy to set
flagTask that was just completed
unsetIf we're unsetting the bit
drawUpdateIf this update should be drawn
Returns
true if a notification is being drawn, false otherwise

◆ trophyClear()

void trophyClear ( trophyData_t t)

Erases completion data from swadge. Only use in extreme circumstances.

Parameters
tTrophy to set to 0

◆ checkBitFlag()

bool checkBitFlag ( int32_t flags,
int8_t idx )

Checks an individual bit flag out of a int32.

Parameters
flagsint32 containing the flag to check
idxIndex of the bit
Returns
true If bit is set
false If bit is not set

◆ setBitFlag()

void setBitFlag ( int32_t * flags,
int8_t idx,
bool setTrue )

Set a bit flag.

Parameters
flagspointer to variable to store flags
idxIndex of the bit to set
setTrueSet to false to unset the

◆ trophyGetPoints()

int trophyGetPoints ( bool total,
const char * modeName )

Get the point totals for the gamer score.

Parameters
totalIf loading the full score or for the current mode
modeNameMode name to load. Set to NULL to get currently loaded mode
Returns
int Value of the score

◆ trophyGetLatest()

trophyData_t trophyGetLatest ( void )

Get the Latest Trophy Idx object.

Returns
trophyData_t data for the latest win

◆ trophySetSystemData()

void trophySetSystemData ( trophyDataList_t * dl,
const char * modeName )

Set the Trophy System to a specific mode's values.

Parameters
dlData object from the mode
modeNameName of the mode

◆ isTrophyDrawing()

bool isTrophyDrawing ( void )

Check if a trophy is currently being drawn.

Returns
true if a trophy is being drawn, false otherwise

◆ trophyDraw()

void trophyDraw ( font_t * fnt,
int64_t elapsedUs )

Draws the banner if one is queued.

Parameters
fntFont to be used
elapsedUsTime since last frame

◆ trophyDrawListInit()

void trophyDrawListInit ( trophyListDisplayMode_t mode)

Initialize the trophy Draw list.

Parameters
modeWhat display mode to draw

◆ trophyDrawListColors()

void trophyDrawListColors ( paletteColor_t background,
paletteColor_t panel,
paletteColor_t shadowBoxes,
paletteColor_t dimText,
paletteColor_t titleText,
paletteColor_t checkmark )

Set the colors of the panel to custom. Call after initialization of the list, or it'll be overwritten.

Parameters
backgroundColor of the background behind the panels
panelThe main panel color
shadowBoxesThe check box and image shadowbox colors
dimTextDescription text and numbers
titleTextTitle of the trophy
checkmarkColor of the checkmark

◆ trophyDrawListDeinit()

void trophyDrawListDeinit ( void )

Tears down the WSGs and height list.

◆ trophyDrawList()

void trophyDrawList ( font_t * fnt,
int yOffset )

Draws the list.

Parameters
fntFont to use
yOffsetCurrent Y offset. Higher numbers effectively scroll down