From e0a7a3511e6d90068b5d3193c58c401add780282 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 20 Mar 2018 07:29:05 +0000 Subject: [PATCH] Updates to title screen. --- src/game/game.c | 7 +++++++ src/game/game.h | 10 +++++----- src/game/title.c | 45 ++++++++++++++++++++++++++++++++++++++------- src/game/title.h | 25 ++++++++++++++----------- src/hub/hub.c | 6 +++++- src/hub/hub.h | 1 + 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/game/game.c b/src/game/game.c index 1cd0911..d72a28a 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -42,6 +42,13 @@ void initGame(void) loadTrophyData(); } +void newGame(void) +{ + destroyGame(); + + initGame(); +} + int addItem(Item *item, int num) { int i; diff --git a/src/game/game.h b/src/game/game.h index 0571142..b179e3a 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -22,17 +22,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../json/cJSON.h" extern Entity *createEntity(char *name); +extern int deleteFile(char *path); extern int fileExists(const char *filename); +extern char **getFileList(const char *dir, int *count); extern char *getLookupName(const char *prefix, long num); +extern int getPercent(float current, float total); extern Trophy *getTrophy(char *id); +extern void loadTrophyData(void); extern int lookup(char *name); extern char *readFile(const char *filename); -extern int writeFile(const char *filename, const char *data); extern char *timeToString(int seconds, int showHours); -extern int getPercent(float current, float total); -extern char **getFileList(const char *dir, int *count); -extern int deleteFile(char *path); -extern void loadTrophyData(void); +extern int writeFile(const char *filename, const char *data); extern App app; extern Entity *self; diff --git a/src/game/title.c b/src/game/title.c index 3c895ac..8b03ea4 100644 --- a/src/game/title.c +++ b/src/game/title.c @@ -34,12 +34,13 @@ static void doSaveSlot(void); static void doLoadCancel(void); static void doOK(void); static void doCancel(void); +static void returnFromOptions(void); static Texture *atlasTexture; static Atlas *title; static int recentSaveSlot; static int saveAction; -static Widget *newGame; +static Widget *startNewGame; static Widget *load; static Widget *continueGame; static Widget *options; @@ -58,8 +59,8 @@ void initTitle(void) title = getImageFromAtlas("gfx/main/title.png"); - newGame = getWidget("new", "title"); - newGame->action = &doNewGame; + startNewGame = getWidget("new", "title"); + startNewGame->action = &doNewGame; load = getWidget("load", "title"); load->action = &doLoadGame; @@ -181,17 +182,35 @@ static void populateSaveSlotWidgets(void) static void doNewGame(void) { + int i; + saveAction = SA_DELETE; + showWidgetGroup("saveSlot"); + + for (i = 0 ; i < MAX_SAVE_SLOTS ; i++) + { + save[i]->disabled = 0; + } + + loadCancel->visible = 1; + destroyGame(); } static void doLoadGame(void) { + int i; + saveAction = SA_LOAD; showWidgetGroup("saveSlot"); + for (i = 0 ; i < MAX_SAVE_SLOTS ; i++) + { + save[i]->disabled = save[i]->value[0] == 0; + } + loadCancel->visible = 1; } @@ -206,12 +225,12 @@ static void doContinueGame(void) static void doOptions(void) { - + initOptions(returnFromOptions); } static void doCredits(void) { - + initCredits(); } static void doQuit(void) @@ -225,8 +244,6 @@ static void doSaveSlot(void) w = getSelectedWidget(); - game.saveSlot = w->value[1]; - if (saveAction == SA_LOAD) { loadGame(); @@ -235,8 +252,14 @@ static void doSaveSlot(void) } else if (saveAction == SA_DELETE) { + newGame(); + initHub(); } + + game.saveSlot = w->value[1]; + + saveGame(); } static void doLoadCancel(void) @@ -253,3 +276,11 @@ static void doCancel(void) { } + +static void returnFromOptions(void) +{ + app.delegate.logic = &logic; + app.delegate.draw = &draw; + + showWidgetGroup("title"); +} diff --git a/src/game/title.h b/src/game/title.h index 95fdb58..e47fa93 100644 --- a/src/game/title.h +++ b/src/game/title.h @@ -27,26 +27,29 @@ enum }; extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center); +extern void destroyGame(void); extern void doWidgets(void); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void drawWidgets(void); extern void endSectionTransition(void); -extern Atlas *getImageFromAtlas(char *filename); -extern Texture *getTexture(const char *filename); -extern Widget *getWidget(char *name, char *group); -extern void playSound(int snd, int ch); -extern void saveConfig(void); -extern void showWidgetGroup(char *group); -extern void startSectionTransition(void); -extern long getFileModTime(char *filename); extern int fileExists(const char *filename); -extern void setSelectedWidget(char *name, char *group); +extern long getFileModTime(char *filename); +extern Atlas *getImageFromAtlas(char *filename); extern char *getSaveWidgetLabel(char *filename); extern Widget *getSelectedWidget(void); -extern void loadGame(void); +extern Texture *getTexture(const char *filename); +extern Widget *getWidget(char *name, char *group); +extern void initCredits(void); extern void initHub(void); -extern void destroyGame(void); +extern void initOptions(void (*callback)(void)); +extern void loadGame(void); +extern void newGame(void); +extern void saveGame(void); +extern void setSelectedWidget(char *name, char *group); +extern void showWidgetGroup(char *group); +extern void startSectionTransition(void); extern App app; extern Colors colors; extern Game game; + diff --git a/src/hub/hub.c b/src/hub/hub.c index ff20170..44cc652 100644 --- a/src/hub/hub.c +++ b/src/hub/hub.c @@ -630,7 +630,11 @@ static void trophies(void) static void quit(void) { - + stopMusic(); + + destroyHub(); + + initTitle(); } static void returnFromTrophyStats(void) diff --git a/src/hub/hub.h b/src/hub/hub.h index c0f9ef4..a1fd688 100644 --- a/src/hub/hub.h +++ b/src/hub/hub.h @@ -58,6 +58,7 @@ extern Widget *getWidget(char *name, char *group); extern void hideAllWidgets(void); extern void initOptions(void (*callback)(void)); extern void initStatsDisplay(void); +extern void initTitle(void); extern void initWorld(void); extern int isControl(int type); extern void limitTextWidth(int width);