Start of widget loading.
This commit is contained in:
parent
343c534159
commit
c87b9a6986
|
@ -335,6 +335,8 @@ enum
|
||||||
STAT_KEYS_FOUND,
|
STAT_KEYS_FOUND,
|
||||||
STAT_CELLS_FOUND,
|
STAT_CELLS_FOUND,
|
||||||
STAT_HEARTS_FOUND,
|
STAT_HEARTS_FOUND,
|
||||||
|
STAT_TARGETS_DEFEATED,
|
||||||
|
STAT_MIAS_RESCUED,
|
||||||
STAT_DEATHS,
|
STAT_DEATHS,
|
||||||
STAT_SHOTS_FIRED,
|
STAT_SHOTS_FIRED,
|
||||||
STAT_SHOTS_HIT,
|
STAT_SHOTS_HIT,
|
||||||
|
@ -345,8 +347,6 @@ enum
|
||||||
STAT_BATTERIES_PICKED_UP,
|
STAT_BATTERIES_PICKED_UP,
|
||||||
STAT_WEAPONS_PICKED_UP,
|
STAT_WEAPONS_PICKED_UP,
|
||||||
STAT_ENEMIES_KILLED,
|
STAT_ENEMIES_KILLED,
|
||||||
STAT_TARGETS_DEFEATED,
|
|
||||||
STAT_MIAS_RESCUED,
|
|
||||||
STAT_MISSIONS_PLAYED,
|
STAT_MISSIONS_PLAYED,
|
||||||
STAT_TIME_PLAYED,
|
STAT_TIME_PLAYED,
|
||||||
STAT_MAX
|
STAT_MAX
|
||||||
|
|
|
@ -134,6 +134,7 @@ void initGameSystem(void)
|
||||||
initGraphics,
|
initGraphics,
|
||||||
initFonts,
|
initFonts,
|
||||||
initAtlas,
|
initAtlas,
|
||||||
|
initWidgets,
|
||||||
initSounds,
|
initSounds,
|
||||||
initSprites,
|
initSprites,
|
||||||
initEntityFactory
|
initEntityFactory
|
||||||
|
|
|
@ -29,12 +29,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
extern void createSaveFolder(void);
|
extern void createSaveFolder(void);
|
||||||
extern void setLanguage(char *applicationName, char *languageCode);
|
extern void setLanguage(char *applicationName, char *languageCode);
|
||||||
extern void initLookups(void);
|
|
||||||
extern void initGraphics(void);
|
extern void initGraphics(void);
|
||||||
extern void initFonts(void);
|
extern void initFonts(void);
|
||||||
extern void initAtlas(void);
|
extern void initAtlas(void);
|
||||||
extern void initSounds(void);
|
extern void initSounds(void);
|
||||||
extern void initSprites(void);
|
extern void initSprites(void);
|
||||||
|
extern void initWidgets(void);
|
||||||
extern void initEntityFactory(void);
|
extern void initEntityFactory(void);
|
||||||
extern void destroyLookups(void);
|
extern void destroyLookups(void);
|
||||||
extern void destroyFonts(void);
|
extern void destroyFonts(void);
|
||||||
|
|
|
@ -48,6 +48,10 @@ void initLookups(void)
|
||||||
addLookup("CONTROL_JETPACK", CONTROL_JETPACK);
|
addLookup("CONTROL_JETPACK", CONTROL_JETPACK);
|
||||||
addLookup("CONTROL_PAUSE", CONTROL_PAUSE);
|
addLookup("CONTROL_PAUSE", CONTROL_PAUSE);
|
||||||
addLookup("CONTROL_MAP", CONTROL_MAP);
|
addLookup("CONTROL_MAP", CONTROL_MAP);
|
||||||
|
|
||||||
|
addLookup("WT_BUTTON", WT_BUTTON);
|
||||||
|
addLookup("WT_SPINNER", WT_SPINNER);
|
||||||
|
addLookup("WT_PLAIN_BUTTON", WT_PLAIN_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addLookup(const char *name, long value)
|
static void addLookup(const char *name, long value)
|
||||||
|
|
|
@ -23,5 +23,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
extern float wrap(float value, float low, float high);
|
extern float wrap(float value, float low, float high);
|
||||||
extern char *readFile(const char *filename);
|
extern char *readFile(const char *filename);
|
||||||
char **getFileList(const char *dir, int *count);
|
extern char **getFileList(const char *dir, int *count);
|
||||||
extern Atlas *getImageFromAtlas(char *filename);
|
extern Atlas *getImageFromAtlas(char *filename);
|
||||||
|
|
|
@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "widgets.h"
|
#include "widgets.h"
|
||||||
|
|
||||||
Widget *getWidgetAt(int x, int y);
|
Widget *getWidgetAt(int x, int y);
|
||||||
|
static void loadWidgetGroup(char *filename);
|
||||||
|
static void loadWidgets(void);
|
||||||
|
|
||||||
static Widget widgetHead;
|
static Widget widgetHead;
|
||||||
static Widget *widgetTail;
|
static Widget *widgetTail;
|
||||||
|
@ -30,6 +32,8 @@ void initWidgets(void)
|
||||||
{
|
{
|
||||||
memset(&widgetHead, 0, sizeof(Widget));
|
memset(&widgetHead, 0, sizeof(Widget));
|
||||||
widgetTail = &widgetHead;
|
widgetTail = &widgetHead;
|
||||||
|
|
||||||
|
loadWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *getWidget(char *name, char *group)
|
Widget *getWidget(char *name, char *group)
|
||||||
|
@ -139,9 +143,69 @@ int wasWidgetClicked(Widget *w)
|
||||||
return wasClicked;
|
return wasClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadWidgets(char *filename)
|
static void loadWidgets(void)
|
||||||
{
|
{
|
||||||
|
char **filenames;
|
||||||
|
char path[MAX_FILENAME_LENGTH];
|
||||||
|
int count, i;
|
||||||
|
|
||||||
|
filenames = getFileList("data/widgets", &count);
|
||||||
|
|
||||||
|
for (i = 0 ; i < count ; i++)
|
||||||
|
{
|
||||||
|
sprintf(path, "data/widgets/%s", filenames[i]);
|
||||||
|
|
||||||
|
loadWidgetGroup(path);
|
||||||
|
|
||||||
|
free(filenames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(filenames);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void loadWidgetGroup(char *filename)
|
||||||
|
{
|
||||||
|
cJSON *root, *node;
|
||||||
|
char *text;
|
||||||
|
Widget *w;
|
||||||
|
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
||||||
|
|
||||||
|
text = readFile(filename);
|
||||||
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
for (node = root->child ; node != NULL ; node = node->next)
|
||||||
|
{
|
||||||
|
w = malloc(sizeof(Widget));
|
||||||
|
memset(w, 0, sizeof(Widget));
|
||||||
|
widgetTail->next = w;
|
||||||
|
widgetTail = w;
|
||||||
|
|
||||||
|
STRNCPY(w->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
STRNCPY(w->group, cJSON_GetObjectItem(node, "group")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
STRNCPY(w->label, cJSON_GetObjectItem(node, "label")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
w->x = cJSON_GetObjectItem(node, "x")->valueint;
|
||||||
|
w->y = cJSON_GetObjectItem(node, "y")->valueint;
|
||||||
|
w->w = cJSON_GetObjectItem(node, "w")->valueint;
|
||||||
|
w->h = cJSON_GetObjectItem(node, "h")->valueint;
|
||||||
|
w->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||||
|
|
||||||
|
switch (w->type)
|
||||||
|
{
|
||||||
|
case WT_BUTTON:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WT_SPINNER:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WT_PLAIN_BUTTON:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(root);
|
||||||
|
|
||||||
|
free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy(void)
|
void destroy(void)
|
||||||
|
|
|
@ -19,5 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "../json/cJSON.h"
|
||||||
|
|
||||||
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
||||||
|
extern char *readFile(const char *filename);
|
||||||
|
extern char **getFileList(const char *dir, int *count);
|
||||||
|
extern long lookup(const char *name);
|
||||||
|
|
|
@ -33,7 +33,7 @@ void initAtlasTest(void)
|
||||||
|
|
||||||
initHub();
|
initHub();
|
||||||
|
|
||||||
loadWorld("greenlands4");
|
loadWorld("greenlands5");
|
||||||
|
|
||||||
initWorld();
|
initWorld();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue