Skip to content

Commit

Permalink
adding stories tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
DantSu committed Feb 23, 2024
1 parent 4f0430a commit 3cd090e
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###########################################################

TARGET=TelmiOS
VERSION=1.0.0
VERSION=1.0.1

###########################################################

Expand Down
9 changes: 9 additions & 0 deletions src/storyTeller/app_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ void app_menu(void) {
if(appOpened) {
switch (appIndex)
{
case APP_STORIES:
stories_menu();
break;
case APP_MUSIC:
musicplayer_menu();
break;
Expand Down Expand Up @@ -107,6 +110,9 @@ void app_up(void)
if(appOpened) {
switch (appIndex)
{
case APP_STORIES:
stories_up();
break;
case APP_MUSIC:
musicplayer_up();
break;
Expand All @@ -121,6 +127,9 @@ void app_down(void)
if(appOpened) {
switch (appIndex)
{
case APP_STORIES:
stories_down();
break;
case APP_MUSIC:
musicplayer_down();
break;
Expand Down
10 changes: 2 additions & 8 deletions src/storyTeller/music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,9 @@ void musicplayer_interfacealbum_drawAlbum(int baseIndex, int pos) {

void musicplayer_interfacealbum_draw() {
if(musicPlayerAlbumIndex >= musicPlayerAlbumsCount) {
musicPlayerAlbumIndex -= musicPlayerAlbumsCount;
if(musicPlayerAlbumIndex >= musicPlayerAlbumsCount) {
musicPlayerAlbumIndex = 0;
}
musicPlayerAlbumIndex = 0;
} else if(musicPlayerAlbumIndex < 0) {
musicPlayerAlbumIndex += musicPlayerAlbumsCount;
if(musicPlayerAlbumIndex < 0) {
musicPlayerAlbumIndex = musicPlayerAlbumsCount - 1;
}
musicPlayerAlbumIndex = musicPlayerAlbumsCount - 1;
}

int page = musicPlayerAlbumIndex / 9;
Expand Down
Binary file added src/storyTeller/res/storiesTiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 108 additions & 17 deletions src/storyTeller/stories_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
#include "./array_helper.h"
#include "./time_helper.h"

#define STR_DIRNAME 64
#define SYSTEM_RESOURCES "/mnt/SDCARD/.tmp_update/res/"
#define STORIES_RESOURCES "/mnt/SDCARD/Stories/"

#define STORIES_DISPLAY_MODE_SINGLE 0
#define STORIES_DISPLAY_MODE_TILES 1

#define STR_DIRNAME 128

static int storiesDiplayMode = STORIES_DISPLAY_MODE_SINGLE;
static char **storiesList = NULL;
static cJSON *storyJson = NULL;
static int storiesCount = 0;
static int storyIndex = 0;
static cJSON *storyJson = NULL;
static char storyStageKey[STR_MAX] = {'\0'};
static char storyActionKey[STR_MAX] = {'\0'};
static int storyActionOptionIndex = 0;
Expand All @@ -33,9 +40,6 @@ static bool storyOkAction = true;
static void (*callback_stories_autoplay)(void);
static void (*callback_stories_reset)(void);

#define SYSTEM_RESOURCES "/mnt/SDCARD/.tmp_update/res/"
#define STORIES_RESOURCES "/mnt/SDCARD/Stories/"

void stories_autosleep_unlock(void) {
autosleep_unlock(parameters_getScreenOnInactivityTime(), parameters_getScreenOffInactivityTime());
}
Expand Down Expand Up @@ -198,6 +202,51 @@ void stories_load(void)
stories_readAction();
}

void stories_title_single(void) {
char story_path[STR_MAX];
sprintf(story_path, "%s%s/", STORIES_RESOURCES, storiesList[storyIndex]);
video_displayImage(story_path, "title.png");
}

void stories_title_tile(int base, int pos) {
int sIndex = base + pos;

if(sIndex >= storiesCount) {
return;
}

int x = 33 + (pos % 3) * 201;
int y = 28 + (pos / 3) * 148;

if(storyIndex == sIndex) {
video_drawRectangle(x - 5, y - 5, 181, 138, 255, 186, 0);
}
char story_path[STR_MAX];
sprintf(story_path, "%s%s/", STORIES_RESOURCES, storiesList[sIndex]);
video_drawRectangle(x, y, 171, 128, 0, 0, 0);
video_screenAddImage(story_path, "title.png", x, y, 171);
}

void stories_title_tiles(void) {
int page = storyIndex / 9;
int baseIndex = page * 9;
char writePage[STR_MAX];
sprintf(writePage, "%i / %i", storyIndex + 1, storiesCount);

video_screenAddImage(SYSTEM_RESOURCES, "storiesTiles.png", 0, 0, 640);
stories_title_tile(baseIndex, 0);
stories_title_tile(baseIndex, 1);
stories_title_tile(baseIndex, 2);
stories_title_tile(baseIndex, 3);
stories_title_tile(baseIndex, 4);
stories_title_tile(baseIndex, 5);
stories_title_tile(baseIndex, 6);
stories_title_tile(baseIndex, 7);
stories_title_tile(baseIndex, 8);
video_screenWriteFont(writePage, fontRegular16, colorWhite60, 606, 456, SDL_ALIGN_RIGHT);
video_applyToVideo();
}

void stories_title(void)
{
if(storiesCount == 0) {
Expand All @@ -214,16 +263,21 @@ void stories_title(void)
} else if (storyIndex >= storiesCount) {
storyIndex = 0;
}

char story_path[STR_MAX];
sprintf(story_path, "%s%s/", STORIES_RESOURCES, storiesList[storyIndex]);

storyTime = 0;
video_displayImage(story_path, "title.png");
audio_play(story_path, "title.mp3", storyTime);

display_setScreen(true);
stories_autosleep_unlock();
storyStartTime = get_time();
storyTime = 0;

char story_path[STR_MAX];
sprintf(story_path, "%s%s/", STORIES_RESOURCES, storiesList[storyIndex]);
audio_play(story_path, "title.mp3", storyTime);

if(storiesDiplayMode == STORIES_DISPLAY_MODE_SINGLE) {
stories_title_single();
} else {
stories_title_tiles();
}
}

void stories_transition(char* transition) {
Expand Down Expand Up @@ -251,6 +305,37 @@ void stories_transition(char* transition) {
stories_readAction();
}


void stories_setMode(int dm) {
storiesDiplayMode = dm;
if(storiesDiplayMode == STORIES_DISPLAY_MODE_SINGLE) {
stories_title_single();
} else {
stories_title_tiles();
}
}

void stories_changeTitle(int direction) {
if(!storyAutoplay && storyActionKey[0] == '\0') {
storyIndex += direction;
stories_title();
}
}

void stories_up(void)
{
if(storiesDiplayMode == STORIES_DISPLAY_MODE_TILES) {
stories_changeTitle(-3);
}
}

void stories_down(void)
{
if(storiesDiplayMode == STORIES_DISPLAY_MODE_TILES) {
stories_changeTitle(3);
}
}

void stories_rewind(double time)
{
long int ts = get_time();
Expand All @@ -265,14 +350,12 @@ void stories_next(void)
stories_rewind(10);
} else {
if(storyActionKey[0] == '\0') {
storyIndex += 1;
stories_title();
stories_changeTitle(1);
} else {
storyActionOptionIndex += 1;
stories_readAction();
}
}

}

void stories_previous(void)
Expand All @@ -281,15 +364,23 @@ void stories_previous(void)
stories_rewind(-10);
} else {
if(storyActionKey[0] == '\0') {
storyIndex -= 1;
stories_title();
stories_changeTitle(-1);
} else {
storyActionOptionIndex -= 1;
stories_readAction();
}
}
}

void stories_menu(void)
{
if(storiesDiplayMode == STORIES_DISPLAY_MODE_SINGLE) {
stories_setMode(STORIES_DISPLAY_MODE_TILES);
} else {
stories_setMode(STORIES_DISPLAY_MODE_SINGLE);
}
}

void stories_ok(void)
{
if(!storyOkAction) {
Expand Down

0 comments on commit 3cd090e

Please sign in to comment.