summaryrefslogtreecommitdiff
path: root/src/screen/screen_table.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen/screen_table.c')
-rw-r--r--src/screen/screen_table.c346
1 files changed, 175 insertions, 171 deletions
diff --git a/src/screen/screen_table.c b/src/screen/screen_table.c
index f4c981c..5eea4d2 100644
--- a/src/screen/screen_table.c
+++ b/src/screen/screen_table.c
@@ -31,208 +31,212 @@ static list_t *listWidgetLabelScore;
static textFile_t *textFile;
-void startScreenTable()
+void
+startScreenTable()
{
#ifndef NO_SOUND
- playMusic("menu", MUSIC_GROUP_BASE);
+ playMusic("menu", MUSIC_GROUP_BASE);
#endif
}
-void drawScreenTable()
+void
+drawScreenTable()
{
- int i;
-
- drawWidgetImage(image_backgorund);
-
- drawWidgetButton(button_back);
-
- for( i = 0 ; i < listWidgetLabelNumer->count ; i++ )
- {
- widget_t *this;
- this = (widget_t *)listWidgetLabelNumer->list[i];
- drawWidgetLabel(this);
- }
-
- for( i = 0 ; i < listWidgetLabelName->count ; i++ )
- {
- widget_t *this;
- this = (widget_t *)listWidgetLabelName->list[i];
- drawWidgetLabel(this);
- }
-
- for( i = 0 ; i < listWidgetLabelScore->count ; i++ )
- {
- widget_t *this;
- this = (widget_t *)listWidgetLabelScore->list[i];
- drawWidgetLabel(this);
- }
-}
+ int i;
-void eventScreenTable()
-{
- eventWidgetButton(button_back);
+ drawWidgetImage(image_backgorund);
+
+ drawWidgetButton(button_back);
+
+ for (i = 0; i < listWidgetLabelNumer->count; i++) {
+ widget_t *this;
+ this = (widget_t *) listWidgetLabelNumer->list[i];
+ drawWidgetLabel(this);
+ }
+
+ for (i = 0; i < listWidgetLabelName->count; i++) {
+ widget_t *this;
+ this = (widget_t *) listWidgetLabelName->list[i];
+ drawWidgetLabel(this);
+ }
+
+ for (i = 0; i < listWidgetLabelScore->count; i++) {
+ widget_t *this;
+ this = (widget_t *) listWidgetLabelScore->list[i];
+ drawWidgetLabel(this);
+ }
}
-void stopScreenTable()
+void
+eventScreenTable()
{
+ eventWidgetButton(button_back);
}
-static void eventWidget(void *p)
+void
+stopScreenTable()
{
- widget_t *button;
-
- button = (widget_t *)(p);
-
- if( button == button_back )
- {
- setScreen("mainMenu");
- }
}
-static void setWidgetLabel()
+static void
+eventWidget(void *p)
{
- int i;
-
- if( textFile == NULL )
- {
- fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"),
- SCREEN_TABLE_FILE_HIGHSCORE_NAME);
-
- return;
- }
-
- if( listWidgetLabelNumer != NULL ||
- listWidgetLabelName != NULL ||
- listWidgetLabelScore != NULL )
- {
- destroyListItem(listWidgetLabelNumer, destroyWidgetLabel);
- destroyListItem(listWidgetLabelName, destroyWidgetLabel);
- destroyListItem(listWidgetLabelScore, destroyWidgetLabel);
- }
-
- listWidgetLabelNumer = newList();
- listWidgetLabelName = newList();
- listWidgetLabelScore = newList();
-
- for( i = 0 ; i < SCREEN_TABLE_MAX_PLAYERS ; i++ )
- {
- widget_t *label;
- char name[STR_NAME_SIZE];
- char score[STR_NUM_SIZE];
- char num[STR_NUM_SIZE];
- char *line;
-
- line = (char *) textFile->text->list[i];
-
- sscanf(line, "%s %s", name, score);
- sprintf(num, "%2d)", i+1);
-
- label = newWidgetLabel(num, WINDOW_SIZE_X/2 - 100, 200 + i * 20, WIDGET_LABEL_LEFT);
- addList(listWidgetLabelNumer, label);
-
- label = newWidgetLabel(name, WINDOW_SIZE_X/2, 200 + i * 20, WIDGET_LABEL_CENTER);
- addList(listWidgetLabelName, label);
-
- label = newWidgetLabel(score, WINDOW_SIZE_X/2 + 80, 200 + i * 20, WIDGET_LABEL_LEFT);
- addList(listWidgetLabelScore, label);
- }
+ widget_t *button;
+
+ button = (widget_t *) (p);
+
+ if (button == button_back) {
+ setScreen("mainMenu");
+ }
}
-static void loadHighscoreFile()
+static void
+setWidgetLabel()
{
- char path[STR_PATH_SIZE];
- int i;
-
- sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME , getHomeDirector());
- textFile = loadTextFile(path);
-
- if( textFile == NULL )
- {
- fprintf(stderr, _("I am unable to load: \"%s\" !\n"), path);
- fprintf(stderr, _("Creating: \"%s\"\n"), path);
- textFile = newTextFile(path);
- }
- else
- {
- return;
- }
-
- if( textFile == NULL )
- {
- fprintf(stderr, _("I was unable to create: \"%s\" !\n"), path);
- return;
- }
-
- for( i = 0 ; i < SCREEN_TABLE_MAX_PLAYERS ; i++ )
- {
- addList(textFile->text, strdup("no_name 0") );
- }
-
- saveTextFile(textFile);
+ int i;
+
+ if (textFile == NULL) {
+ fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"),
+ SCREEN_TABLE_FILE_HIGHSCORE_NAME);
+
+ return;
+ }
+
+ if (listWidgetLabelNumer != NULL ||
+ listWidgetLabelName != NULL || listWidgetLabelScore != NULL) {
+ destroyListItem(listWidgetLabelNumer, destroyWidgetLabel);
+ destroyListItem(listWidgetLabelName, destroyWidgetLabel);
+ destroyListItem(listWidgetLabelScore, destroyWidgetLabel);
+ }
+
+ listWidgetLabelNumer = newList();
+ listWidgetLabelName = newList();
+ listWidgetLabelScore = newList();
+
+ for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) {
+ widget_t *label;
+ char name[STR_NAME_SIZE];
+ char score[STR_NUM_SIZE];
+ char num[STR_NUM_SIZE];
+ char *line;
+
+ line = (char *) textFile->text->list[i];
+
+ sscanf(line, "%s %s", name, score);
+ sprintf(num, "%2d)", i + 1);
+
+ label =
+ newWidgetLabel(num, WINDOW_SIZE_X / 2 - 100, 200 + i * 20,
+ WIDGET_LABEL_LEFT);
+ addList(listWidgetLabelNumer, label);
+
+ label =
+ newWidgetLabel(name, WINDOW_SIZE_X / 2, 200 + i * 20,
+ WIDGET_LABEL_CENTER);
+ addList(listWidgetLabelName, label);
+
+ label =
+ newWidgetLabel(score, WINDOW_SIZE_X / 2 + 80, 200 + i * 20,
+ WIDGET_LABEL_LEFT);
+ addList(listWidgetLabelScore, label);
+ }
}
-int addPlayerInHighScore(char *name, int score)
+static void
+loadHighscoreFile()
{
- int i;
-
- for( i = 0 ; i < SCREEN_TABLE_MAX_PLAYERS ; i++ )
- {
- char *line;
- char thisName[STR_NAME_SIZE];
- int thisCore;
-
- line = (char *) textFile->text->list[i];
- sscanf(line, "%s %d", thisName, &thisCore);
-
- if( score >= thisCore )
- {
- char new[STR_SIZE];
-
- sprintf(new, "%s %d", name, score);
- insList(textFile->text, i, strdup(new) );
- delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free);
- setWidgetLabel();
-
- return 0;
- }
- }
-
- return -1;
+ char path[STR_PATH_SIZE];
+ int i;
+
+ sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME, getHomeDirector());
+ textFile = loadTextFile(path);
+
+ if (textFile == NULL) {
+ fprintf(stderr, _("I am unable to load: \"%s\" !\n"), path);
+ fprintf(stderr, _("Creating: \"%s\"\n"), path);
+ textFile = newTextFile(path);
+ }
+ else {
+ return;
+ }
+
+ if (textFile == NULL) {
+ fprintf(stderr, _("I was unable to create: \"%s\" !\n"), path);
+ return;
+ }
+
+ for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) {
+ addList(textFile->text, strdup("no_name 0"));
+ }
+
+ saveTextFile(textFile);
}
-void initScreenTable()
+int
+addPlayerInHighScore(char *name, int score)
{
- image_t *image;
+ int i;
+
+ for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) {
+ char *line;
+ char thisName[STR_NAME_SIZE];
+ int thisCore;
- image = addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", IMAGE_GROUP_BASE);
- image_backgorund = newWidgetImage(0, 0, image);
+ line = (char *) textFile->text->list[i];
+ sscanf(line, "%s %d", thisName, &thisCore);
- button_back = newWidgetButton(_("back"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2,
- WINDOW_SIZE_Y-100, eventWidget);
+ if (score >= thisCore) {
+ char new[STR_SIZE];
- loadHighscoreFile();
- listWidgetLabelNumer = NULL;
- listWidgetLabelName = NULL;
- listWidgetLabelScore = NULL;
- setWidgetLabel();
+ sprintf(new, "%s %d", name, score);
+ insList(textFile->text, i, strdup(new));
+ delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free);
+ setWidgetLabel();
- registerScreen( newScreen("table", startScreenTable, eventScreenTable,
- drawScreenTable, stopScreenTable) );
+ return 0;
+ }
+ }
+
+ return -1;
}
-void quitScreenTable()
+void
+initScreenTable()
{
- destroyWidgetImage(image_backgorund);
-
- destroyWidgetButton(button_back);
- destroyListItem(listWidgetLabelNumer, destroyWidgetLabel);
- destroyListItem(listWidgetLabelName, destroyWidgetLabel);
- destroyListItem(listWidgetLabelScore, destroyWidgetLabel);
-
- if( textFile != NULL )
- {
- saveTextFile(textFile);
- destroyTextFile(textFile);
- }
+ image_t *image;
+
+ image =
+ addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table",
+ IMAGE_GROUP_BASE);
+ image_backgorund = newWidgetImage(0, 0, image);
+
+ button_back =
+ newWidgetButton(_("back"),
+ WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2,
+ WINDOW_SIZE_Y - 100, eventWidget);
+
+ loadHighscoreFile();
+ listWidgetLabelNumer = NULL;
+ listWidgetLabelName = NULL;
+ listWidgetLabelScore = NULL;
+ setWidgetLabel();
+
+ registerScreen(newScreen("table", startScreenTable, eventScreenTable,
+ drawScreenTable, stopScreenTable));
}
+void
+quitScreenTable()
+{
+ destroyWidgetImage(image_backgorund);
+
+ destroyWidgetButton(button_back);
+ destroyListItem(listWidgetLabelNumer, destroyWidgetLabel);
+ destroyListItem(listWidgetLabelName, destroyWidgetLabel);
+ destroyListItem(listWidgetLabelScore, destroyWidgetLabel);
+
+ if (textFile != NULL) {
+ saveTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+}