diff options
| author | Tomas Chvatal <scarabeus@gentoo.org> | 2009-02-07 17:52:36 +0100 |
|---|---|---|
| committer | Tomas Chvatal <scarabeus@gentoo.org> | 2009-02-07 17:52:36 +0100 |
| commit | dc1bd4d1dcf8713bc5be0e9a154d44b43f71ddf8 (patch) | |
| tree | b0372c2abc47ac869f654acc786131740ee146a9 /src/screen/table.c | |
| parent | eecde9b1f70397367f3f0dea4c47f27064f13fc0 (diff) | |
Revert "Revert "Revert "First pass renaming sreen and widgets."""
This reverts commit 87821f04c9565450d8e724be76993ae5ea2c20c4.
Diffstat (limited to 'src/screen/table.c')
| -rw-r--r-- | src/screen/table.c | 229 |
1 files changed, 0 insertions, 229 deletions
diff --git a/src/screen/table.c b/src/screen/table.c deleted file mode 100644 index c9c005f..0000000 --- a/src/screen/table.c +++ /dev/null @@ -1,229 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "list.h" -#include "textFile.h" -#include "homeDirector.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "table.h" - -#include "image.h" -#include "label.h" -#include "button.h" - -static widget_t *image_backgorund; -static widget_t *button_back; - -static list_t *listWidgetLabelNumer; -static list_t *listWidgetLabelName; -static list_t *listWidgetLabelScore; - -static textFile_t *textFile; - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenTable() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -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); - } -} - -void eventScreenTable() -{ - eventWidgetButton(button_back); -} - -void stopScreenTable() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } -} - -static void setWidgetLabel() -{ - 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); - } -} - -static void loadHighscoreFile() -{ - 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 addPlayerInHighScore(char *name, int score) -{ - 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; -} - -void initScreenTable() -{ - image_t *image; - - image = addImageData("table.png", IMAGE_NO_ALPHA, "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); - } -} |