diff options
| author | Tomas Chvatal <scarabeus@gentoo.org> | 2008-12-11 19:38:00 +0100 |
|---|---|---|
| committer | Tomas Chvatal <scarabeus@gentoo.org> | 2008-12-11 19:38:00 +0100 |
| commit | 3ba6105170ecac2fb124d9eb7e81ba72dd4700b8 (patch) | |
| tree | ec30e2b1dda198c9646ea3447308368bbe334500 /src/screen/credits.c | |
| parent | b2d2cf4f53748051ace835d27564cb2922c13db9 (diff) | |
First pass for renaming screen/widget.
Diffstat (limited to 'src/screen/credits.c')
| -rw-r--r-- | src/screen/credits.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/screen/credits.c b/src/screen/credits.c new file mode 100644 index 0000000..0f2541b --- /dev/null +++ b/src/screen/credits.c @@ -0,0 +1,163 @@ + +#include <stdio.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "textFile.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "credits.h" + +#include "widget.h" +#include "widget_image.h" +#include "widget_label.h" +#include "widget_button.h" + +static widget_t *image_backgorund; +static widget_t *button_back; +static list_t *listWidgetLabel; +static textFile_t *textFile; +static int offset; +static int creditExists; + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenCredits() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + offset = 0; + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenCredits() +{ + int i; + + drawWidgetImage(image_backgorund); + + drawWidgetButton(button_back); + + for (i = 0; i < listWidgetLabel->count; i++) { + int z; + + widget_t *this; + + this = (widget_t *) listWidgetLabel->list[i]; + + z = this->y; + this->y += offset; + + if (this->y > SCREEN_CREDITS_OFFSET_MIN && this->y < SCREEN_CREDITS_OFFSET_MAX) { + drawWidgetLabel(this); + } + + this->y = z; + } + +} + +void eventScreenCredits() +{ + eventWidgetButton(button_back); + + offset -= SCREEN_CREDITS_OFFSET_SPEED; + + if (offset < SCREEN_CREDITS_OFFSET_RESTART) { + offset = 0; + } + + //printf("offset = %d\n", offset); +} + +void stopScreenCredits() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } +} + +void initScreenCredits() +{ + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 80, eventWidget); + + listWidgetLabel = newList(); + + if (tryExistFile(PATH_DOC SCREEN_CREDITS_FILE) == 0) { + creditExists = 1; + textFile = loadTextFile(PATH_DOC SCREEN_CREDITS_FILE); + + for (i = 0; i < textFile->text->count; i++) { + widget_t *label; + char *line; + + line = (char *) textFile->text->list[i]; + + label = newWidgetLabel(line, WINDOW_SIZE_X / 2 - WINDOW_SIZE_X / 4, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_LEFT); + + addList(listWidgetLabel, label); + } + } else { + for (i = 0; i < 5; i++) { + creditExists = 0; + widget_t *label; + char line[STR_SIZE]; + + sprintf(line, _("Credit file not found... %s/%s"), PATH_DOC, + SCREEN_CREDITS_FILE); + + label = newWidgetLabel(line, WINDOW_SIZE_X / 2, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_CENTER); + + addList(listWidgetLabel, label); + } + } + + registerScreen(newScreen ("credits", startScreenCredits, eventScreenCredits, + drawScreenCredits, stopScreenCredits)); +} + +void quitScreenCredits() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_back); + destroyListItem(listWidgetLabel, destroyWidgetLabel); + + if (creditExists) { + destroyTextFile(textFile); + } +} |