Start of title screen.
This commit is contained in:
parent
25c3c499c5
commit
64c0a2bb74
|
@ -22,17 +22,91 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
static void logic(void);
|
static void logic(void);
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
|
static int getRecentSave(void);
|
||||||
|
|
||||||
|
static Texture *atlasTexture;
|
||||||
|
static Atlas *title;
|
||||||
|
static int recentSaveSlot;
|
||||||
|
static Widget *newGame;
|
||||||
|
static Widget *loadGame;
|
||||||
|
static Widget *continueGame;
|
||||||
|
static Widget *options;
|
||||||
|
static Widget *credits;
|
||||||
|
static Widget *quit;
|
||||||
|
|
||||||
void initTitle(void)
|
void initTitle(void)
|
||||||
{
|
{
|
||||||
|
startSectionTransition();
|
||||||
|
|
||||||
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
|
||||||
|
title = getImageFromAtlas("gfx/main/title.png");
|
||||||
|
|
||||||
|
newGame = getWidget("new", "title");
|
||||||
|
loadGame = getWidget("load", "title");
|
||||||
|
continueGame = getWidget("continue", "title");
|
||||||
|
options = getWidget("options", "title");
|
||||||
|
credits = getWidget("credits", "title");
|
||||||
|
quit = getWidget("exit", "title");
|
||||||
|
|
||||||
|
recentSaveSlot = getRecentSave();
|
||||||
|
|
||||||
|
showWidgetGroup("title");
|
||||||
|
|
||||||
|
if (recentSaveSlot != -1)
|
||||||
|
{
|
||||||
|
setSelectedWidget("continue", "title");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loadGame->disabled = 1;
|
||||||
|
continueGame->disabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
app.delegate.logic = &logic;
|
app.delegate.logic = &logic;
|
||||||
app.delegate.draw = &draw;
|
app.delegate.draw = &draw;
|
||||||
|
|
||||||
|
endSectionTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void logic(void)
|
static void logic(void)
|
||||||
{
|
{
|
||||||
|
doWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw(void)
|
static void draw(void)
|
||||||
{
|
{
|
||||||
|
blitRect(atlasTexture->texture, SCREEN_WIDTH / 2, 175, &title->rect, 1);
|
||||||
|
|
||||||
|
drawText(10, SCREEN_HEIGHT - 30, 18, TA_LEFT, colors.white, "Copyright 2014, 2018 Parallel Realities");
|
||||||
|
drawText(SCREEN_WIDTH - 10, SCREEN_HEIGHT - 30, 18, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION);
|
||||||
|
|
||||||
|
drawWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getRecentSave(void)
|
||||||
|
{
|
||||||
|
char filename[MAX_FILENAME_LENGTH];
|
||||||
|
int i, slot, curModTime, modTime;
|
||||||
|
|
||||||
|
slot = -1;
|
||||||
|
modTime = 0;
|
||||||
|
|
||||||
|
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
||||||
|
{
|
||||||
|
sprintf(filename, "%s/%d/game.json", app.saveDir, i);
|
||||||
|
|
||||||
|
if (fileExists(filename))
|
||||||
|
{
|
||||||
|
curModTime = getFileModTime(filename);
|
||||||
|
|
||||||
|
if (curModTime > modTime)
|
||||||
|
{
|
||||||
|
modTime = curModTime;
|
||||||
|
slot = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
extern App app;
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
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 App app;
|
||||||
|
extern Colors colors;
|
||||||
|
|
|
@ -184,5 +184,12 @@ static void handleCommandLine(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (worldId != NULL)
|
||||||
|
{
|
||||||
initWorldTest(worldId);
|
initWorldTest(worldId);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
initTitle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ extern void prepareScene(void);
|
||||||
extern void presentScene(void);
|
extern void presentScene(void);
|
||||||
extern void saveScreenshot(char *name);
|
extern void saveScreenshot(char *name);
|
||||||
extern void saveTrophyScreenshot(void);
|
extern void saveTrophyScreenshot(void);
|
||||||
|
extern void initTitle(void);
|
||||||
|
|
||||||
App app;
|
App app;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
|
|
|
@ -494,6 +494,7 @@ struct Widget {
|
||||||
int minValue;
|
int minValue;
|
||||||
int maxValue;
|
int maxValue;
|
||||||
int visible;
|
int visible;
|
||||||
|
int disabled;
|
||||||
int numOptions;
|
int numOptions;
|
||||||
char **options;
|
char **options;
|
||||||
void (*action)(void);
|
void (*action)(void);
|
||||||
|
|
|
@ -29,6 +29,15 @@ int fileExists(const char *filename)
|
||||||
return (stat(filename, &buffer) == 0);
|
return (stat(filename, &buffer) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long getFileModTime(const char *filename)
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
|
||||||
|
stat(filename, &buffer);
|
||||||
|
|
||||||
|
return buffer.st_mtime;
|
||||||
|
}
|
||||||
|
|
||||||
const char *getFileLocation(const char *filename)
|
const char *getFileLocation(const char *filename)
|
||||||
{
|
{
|
||||||
static char path[MAX_FILENAME_LENGTH];
|
static char path[MAX_FILENAME_LENGTH];
|
||||||
|
|
|
@ -208,6 +208,7 @@ void drawWidgets(void)
|
||||||
x = w->x + w->w + 25;
|
x = w->x + w->w + 25;
|
||||||
drawRect(x, w->y, 200, w->h, 0, 0, 0, 255);
|
drawRect(x, w->y, 200, w->h, 0, 0, 0, 255);
|
||||||
drawOutlineRect(x, w->y, 200, w->h, 0, outline, 0, 255);
|
drawOutlineRect(x, w->y, 200, w->h, 0, outline, 0, 255);
|
||||||
|
|
||||||
if (app.awaitingWidgetInput && w == selectedWidget)
|
if (app.awaitingWidgetInput && w == selectedWidget)
|
||||||
{
|
{
|
||||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "...");
|
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "...");
|
||||||
|
@ -226,6 +227,11 @@ void drawWidgets(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (w->disabled)
|
||||||
|
{
|
||||||
|
drawRect(w->x, w->y, w->w, w->h, 0, 0, 0, 160);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +245,10 @@ void drawWidgetFrame(void)
|
||||||
|
|
||||||
static void selectWidget(int dir)
|
static void selectWidget(int dir)
|
||||||
{
|
{
|
||||||
int oldWidgetIndex = widgetIndex;
|
int oldWidgetIndex, valid;
|
||||||
|
|
||||||
|
oldWidgetIndex = widgetIndex;
|
||||||
|
valid = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -257,7 +266,9 @@ static void selectWidget(int dir)
|
||||||
|
|
||||||
selectedWidget = &widgets[widgetIndex];
|
selectedWidget = &widgets[widgetIndex];
|
||||||
|
|
||||||
} while (!selectedWidget->visible);
|
valid = selectedWidget->visible && !selectedWidget->disabled;
|
||||||
|
|
||||||
|
} while (!valid);
|
||||||
|
|
||||||
if (oldWidgetIndex != widgetIndex)
|
if (oldWidgetIndex != widgetIndex)
|
||||||
{
|
{
|
||||||
|
@ -286,6 +297,11 @@ Widget *getWidget(char *name, char *group)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSelectedWidget(char *name, char *group)
|
||||||
|
{
|
||||||
|
selectedWidget = getWidget(name, group);
|
||||||
|
}
|
||||||
|
|
||||||
Widget *selectWidgetAt(int x, int y)
|
Widget *selectWidgetAt(int x, int y)
|
||||||
{
|
{
|
||||||
Widget *w;
|
Widget *w;
|
||||||
|
@ -396,7 +412,7 @@ static void loadWidgetGroup(char *filename)
|
||||||
|
|
||||||
for (node = root->child ; node != NULL ; node = node->next)
|
for (node = root->child ; node != NULL ; node = node->next)
|
||||||
{
|
{
|
||||||
if (++numWidgets >= MAX_WIDGETS)
|
if (numWidgets >= MAX_WIDGETS)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Out of widget space.");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Out of widget space.");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -435,6 +451,8 @@ static void loadWidgetGroup(char *filename)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numWidgets++;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
|
Loading…
Reference in New Issue