+static void HandleInfoScreen_Version(int);
+
+static void MapScreenMenuGadgets(int);
+static void MapScreenTreeGadgets(TreeInfo *);
+
+static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
+
+static int info_mode = INFO_MODE_MAIN;
+static int setup_mode = SETUP_MODE_MAIN;
+
+static TreeInfo *screen_modes = NULL;
+static TreeInfo *screen_mode_current = NULL;
+
+static TreeInfo *scroll_delays = NULL;
+static TreeInfo *scroll_delay_current = NULL;
+
+static TreeInfo *game_speeds = NULL;
+static TreeInfo *game_speed_current = NULL;
+
+static struct
+{
+ int value;
+ char *text;
+} game_speeds_list[] =
+{
+#if 1
+ { 30, "Very Slow" },
+ { 25, "Slow" },
+ { 20, "Normal" },
+ { 15, "Fast" },
+ { 10, "Very Fast" },
+#else
+ { 1000, "1/1s (Extremely Slow)" },
+ { 500, "1/2s" },
+ { 200, "1/5s" },
+ { 100, "1/10s" },
+ { 50, "1/20s" },
+ { 29, "1/35s (Original Supaplex)" },
+ { 25, "1/40s" },
+ { 20, "1/50s (Normal Speed)" },
+ { 14, "1/70s (Maximum Supaplex)" },
+ { 10, "1/100s" },
+ { 5, "1/200s" },
+ { 2, "1/500s" },
+ { 1, "1/1000s (Extremely Fast)" },
+#endif
+
+ { -1, NULL },
+};
+
+static struct
+{
+ int value;
+ char *text;
+} scroll_delays_list[] =
+{
+ { 0, "0 Tiles (No Scroll Delay)" },
+ { 1, "1 Tile" },
+ { 2, "2 Tiles" },
+ { 3, "3 Tiles (Default)" },
+ { 4, "4 Tiles" },
+ { 5, "5 Tiles" },
+ { 6, "6 Tiles" },
+ { 7, "7 Tiles" },
+ { 8, "8 Tiles (Maximum Scroll Delay)"},
+
+ { -1, NULL },
+};
+
+#define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \
+ (s) <= GAME_MODE_SETUP ? (s) : \
+ (s) == GAME_MODE_PSEUDO_TYPENAME ? \
+ GAME_MODE_MAIN : GAME_MODE_DEFAULT)
+
+/* (there are no draw offset definitions needed for INFO_MODE_TITLE) */
+#define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_ELEMENTS && \
+ (i) <= INFO_MODE_LEVELSET ? (i) : \
+ INFO_MODE_MAIN)
+
+#define DRAW_MODE_SETUP(i) ((i) >= SETUP_MODE_MAIN && \
+ (i) <= SETUP_MODE_SHORTCUTS_4 ? (i) : \
+ (i) >= SETUP_MODE_CHOOSE_GRAPHICS && \
+ (i) <= SETUP_MODE_CHOOSE_MUSIC ? \
+ SETUP_MODE_CHOOSE_ARTWORK : \
+ SETUP_MODE_CHOOSE_OTHER)
+
+#define DRAW_XOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
+ menu.draw_xoffset[GAME_MODE_INFO] : \
+ menu.draw_xoffset_info[DRAW_MODE_INFO(i)])
+#define DRAW_YOFFSET_INFO(i) (DRAW_MODE_INFO(i) == INFO_MODE_MAIN ? \
+ menu.draw_yoffset[GAME_MODE_INFO] : \
+ menu.draw_yoffset_info[DRAW_MODE_INFO(i)])
+
+#define DRAW_XOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
+ menu.draw_xoffset[GAME_MODE_SETUP] : \
+ menu.draw_xoffset_setup[DRAW_MODE_SETUP(i)])
+#define DRAW_YOFFSET_SETUP(i) (DRAW_MODE_SETUP(i) == SETUP_MODE_MAIN ? \
+ menu.draw_yoffset[GAME_MODE_SETUP] : \
+ menu.draw_yoffset_setup[DRAW_MODE_SETUP(i)])
+
+#define DRAW_XOFFSET(s) ((s) == GAME_MODE_INFO ? \
+ DRAW_XOFFSET_INFO(info_mode) : \
+ (s) == GAME_MODE_SETUP ? \
+ DRAW_XOFFSET_SETUP(setup_mode) : \
+ menu.draw_xoffset[DRAW_MODE(s)])
+#define DRAW_YOFFSET(s) ((s) == GAME_MODE_INFO ? \
+ DRAW_YOFFSET_INFO(info_mode) : \
+ (s) == GAME_MODE_SETUP ? \
+ DRAW_YOFFSET_SETUP(setup_mode) : \
+ menu.draw_yoffset[DRAW_MODE(s)])
+
+#define mSX (SX + DRAW_XOFFSET(game_status))
+#define mSY (SY + DRAW_YOFFSET(game_status))
+
+#define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \
+ menu.list_size[game_status] : \
+ MAX_MENU_ENTRIES_ON_SCREEN)
+
+#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
+#define NUM_SCROLLBAR_BITMAPS 2
+static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS];
+#endif
+
+
+/* title display and control definitions */
+
+#define MAX_NUM_TITLE_SCREENS (2 * MAX_NUM_TITLE_IMAGES + \
+ 2 * MAX_NUM_TITLE_MESSAGES)
+
+static int num_title_screens = 0;
+
+struct TitleControlInfo
+{
+ boolean is_image;
+ boolean initial;
+ int local_nr;
+ int sort_priority;
+};
+
+struct TitleControlInfo title_controls[MAX_NUM_TITLE_SCREENS];
+
+/* main menu display and control definitions */
+
+#define MAIN_CONTROL_NAME 0
+#define MAIN_CONTROL_LEVELS 1
+#define MAIN_CONTROL_SCORES 2
+#define MAIN_CONTROL_EDITOR 3
+#define MAIN_CONTROL_INFO 4
+#define MAIN_CONTROL_GAME 5
+#define MAIN_CONTROL_SETUP 6
+#define MAIN_CONTROL_QUIT 7
+#define MAIN_CONTROL_PREV_LEVEL 8
+#define MAIN_CONTROL_NEXT_LEVEL 9
+#define MAIN_CONTROL_FIRST_LEVEL 10
+#define MAIN_CONTROL_LAST_LEVEL 11
+#define MAIN_CONTROL_LEVEL_NUMBER 12
+#define MAIN_CONTROL_LEVEL_INFO_1 13
+#define MAIN_CONTROL_LEVEL_INFO_2 14
+#define MAIN_CONTROL_LEVEL_NAME 15
+#define MAIN_CONTROL_LEVEL_AUTHOR 16
+#define MAIN_CONTROL_LEVEL_YEAR 17
+#define MAIN_CONTROL_LEVEL_IMPORTED_FROM 18
+#define MAIN_CONTROL_LEVEL_IMPORTED_BY 19
+#define MAIN_CONTROL_LEVEL_TESTED_BY 20
+#define MAIN_CONTROL_TITLE_1 21
+#define MAIN_CONTROL_TITLE_2 22
+#define MAIN_CONTROL_TITLE_3 23
+
+static char str_main_text_name[10];
+static char str_main_text_first_level[10];
+static char str_main_text_last_level[10];
+static char str_main_text_level_number[10];
+
+static char *main_text_name = str_main_text_name;
+static char *main_text_first_level = str_main_text_first_level;
+static char *main_text_last_level = str_main_text_last_level;
+static char *main_text_level_number = str_main_text_level_number;
+static char *main_text_levels = "Levelset";
+static char *main_text_scores = "Hall Of Fame";
+static char *main_text_editor = "Level Creator";
+static char *main_text_info = "Info Screen";
+static char *main_text_game = "Start Game";
+static char *main_text_setup = "Setup";
+static char *main_text_quit = "Quit";
+static char *main_text_level_name = level.name;
+static char *main_text_level_author = level.author;
+static char *main_text_level_year = NULL;
+static char *main_text_level_imported_from = NULL;
+static char *main_text_level_imported_by = NULL;
+static char *main_text_level_tested_by = NULL;
+static char *main_text_title_1 = PROGRAM_TITLE_STRING;
+static char *main_text_title_2 = PROGRAM_COPYRIGHT_STRING;
+static char *main_text_title_3 = PROGRAM_GAME_BY_STRING;
+
+struct MainControlInfo
+{
+ int nr;
+
+ struct MenuPosInfo *pos_button;
+ int button_graphic;
+
+ struct TextPosInfo *pos_text;
+ char **text;
+
+ struct TextPosInfo *pos_input;
+ char **input;
+};
+
+static struct MainControlInfo main_controls[] =
+{
+ {
+ MAIN_CONTROL_NAME,
+ &menu.main.button.name, IMG_MENU_BUTTON_NAME,
+ &menu.main.text.name, &main_text_name,
+ &menu.main.input.name, &setup.player_name,
+ },
+ {
+ MAIN_CONTROL_LEVELS,
+ &menu.main.button.levels, IMG_MENU_BUTTON_LEVELS,
+ &menu.main.text.levels, &main_text_levels,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_SCORES,
+ &menu.main.button.scores, IMG_MENU_BUTTON_SCORES,
+ &menu.main.text.scores, &main_text_scores,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_EDITOR,
+ &menu.main.button.editor, IMG_MENU_BUTTON_EDITOR,
+ &menu.main.text.editor, &main_text_editor,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_INFO,
+ &menu.main.button.info, IMG_MENU_BUTTON_INFO,
+ &menu.main.text.info, &main_text_info,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_GAME,
+ &menu.main.button.game, IMG_MENU_BUTTON_GAME,
+ &menu.main.text.game, &main_text_game,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_SETUP,
+ &menu.main.button.setup, IMG_MENU_BUTTON_SETUP,
+ &menu.main.text.setup, &main_text_setup,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_QUIT,
+ &menu.main.button.quit, IMG_MENU_BUTTON_QUIT,
+ &menu.main.text.quit, &main_text_quit,
+ NULL, NULL,
+ },
+#if 0
+ /* (these two buttons are real gadgets) */
+ {
+ MAIN_CONTROL_PREV_LEVEL,
+ &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
+ NULL, NULL,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_NEXT_LEVEL,
+ &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
+ NULL, NULL,
+ NULL, NULL,
+ },
+#endif
+ {
+ MAIN_CONTROL_FIRST_LEVEL,
+ NULL, -1,
+ &menu.main.text.first_level, &main_text_first_level,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LAST_LEVEL,
+ NULL, -1,
+ &menu.main.text.last_level, &main_text_last_level,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_NUMBER,
+ NULL, -1,
+ &menu.main.text.level_number, &main_text_level_number,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_INFO_1,
+ NULL, -1,
+ &menu.main.text.level_info_1, NULL,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_INFO_2,
+ NULL, -1,
+ &menu.main.text.level_info_2, NULL,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_NAME,
+ NULL, -1,
+ &menu.main.text.level_name, &main_text_level_name,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_AUTHOR,
+ NULL, -1,
+ &menu.main.text.level_author, &main_text_level_author,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_YEAR,
+ NULL, -1,
+ &menu.main.text.level_year, &main_text_level_year,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_IMPORTED_FROM,
+ NULL, -1,
+ &menu.main.text.level_imported_from, &main_text_level_imported_from,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_IMPORTED_BY,
+ NULL, -1,
+ &menu.main.text.level_imported_by, &main_text_level_imported_by,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_LEVEL_TESTED_BY,
+ NULL, -1,
+ &menu.main.text.level_tested_by, &main_text_level_tested_by,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_TITLE_1,
+ NULL, -1,
+ &menu.main.text.title_1, &main_text_title_1,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_TITLE_2,
+ NULL, -1,
+ &menu.main.text.title_2, &main_text_title_2,
+ NULL, NULL,
+ },
+ {
+ MAIN_CONTROL_TITLE_3,
+ NULL, -1,
+ &menu.main.text.title_3, &main_text_title_3,
+ NULL, NULL,
+ },
+
+ {
+ -1,
+ NULL, -1,
+ NULL, NULL,
+ NULL, NULL,
+ }
+};
+
+
+static int getTitleScreenGraphic(int nr, boolean initial)
+{
+ return (initial ? IMG_TITLESCREEN_INITIAL_1 : IMG_TITLESCREEN_1) + nr;
+}
+
+static struct TitleMessageInfo *getTitleMessageInfo(int nr, boolean initial)
+{
+ return (initial ? &titlemessage_initial[nr] : &titlemessage[nr]);
+}
+
+#if 0
+static int getTitleScreenGameMode(boolean initial)
+{
+ return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
+}
+#endif
+
+static int getTitleMessageGameMode(boolean initial)
+{
+ return (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
+}
+
+#if 0
+static int getTitleScreenBackground(boolean initial)
+{
+ return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
+}
+#endif
+
+#if 0
+static int getTitleMessageBackground(int nr, boolean initial)
+{
+ return (initial ? IMG_BACKGROUND_TITLE_INITIAL : IMG_BACKGROUND_TITLE);
+}
+#endif
+
+static int getTitleBackground(int nr, boolean initial, boolean is_image)
+{
+ int base = (is_image ?
+ (initial ? IMG_BACKGROUND_TITLESCREEN_INITIAL_1 :
+ IMG_BACKGROUND_TITLESCREEN_1) :
+ (initial ? IMG_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
+ IMG_BACKGROUND_TITLEMESSAGE_1));
+ int graphic_global = (initial ? IMG_BACKGROUND_TITLE_INITIAL :
+ IMG_BACKGROUND_TITLE);
+ int graphic_local = base + nr;
+
+ if (graphic_info[graphic_local].bitmap != NULL)
+ return graphic_local;
+
+ if (graphic_info[graphic_global].bitmap != NULL)
+ return graphic_global;
+
+ return IMG_UNDEFINED;
+}
+
+static int getTitleSound(struct TitleControlInfo *tci)
+{
+ boolean is_image = tci->is_image;
+ int initial = tci->initial;
+ int nr = tci->local_nr;
+ int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
+ int base = (is_image ?
+ (initial ? SND_BACKGROUND_TITLESCREEN_INITIAL_1 :
+ SND_BACKGROUND_TITLESCREEN_1) :
+ (initial ? SND_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
+ SND_BACKGROUND_TITLEMESSAGE_1));
+ int sound_global = menu.sound[mode];
+ int sound_local = base + nr;
+
+#if 0
+ printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
+ nr, initial, is_image,
+ sound_global, getSoundListEntry(sound_global)->filename,
+ sound_local, getSoundListEntry(sound_local)->filename);
+#endif
+
+ if (!strEqual(getSoundListEntry(sound_local)->filename, UNDEFINED_FILENAME))
+ return sound_local;
+
+ if (!strEqual(getSoundListEntry(sound_global)->filename, UNDEFINED_FILENAME))
+ return sound_global;
+
+ return SND_UNDEFINED;
+}
+
+static int getTitleMusic(struct TitleControlInfo *tci)
+{
+ boolean is_image = tci->is_image;
+ int initial = tci->initial;
+ int nr = tci->local_nr;
+ int mode = (initial ? GAME_MODE_TITLE_INITIAL : GAME_MODE_TITLE);
+ int base = (is_image ?
+ (initial ? MUS_BACKGROUND_TITLESCREEN_INITIAL_1 :
+ MUS_BACKGROUND_TITLESCREEN_1) :
+ (initial ? MUS_BACKGROUND_TITLEMESSAGE_INITIAL_1 :
+ MUS_BACKGROUND_TITLEMESSAGE_1));
+ int music_global = menu.music[mode];
+ int music_local = base + nr;
+
+#if 0
+ printf("::: %d, %d, %d: %d ['%s'], %d ['%s']\n",
+ nr, initial, is_image,
+ music_global, getMusicListEntry(music_global)->filename,
+ music_local, getMusicListEntry(music_local)->filename);
+#endif
+
+ if (!strEqual(getMusicListEntry(music_local)->filename, UNDEFINED_FILENAME))
+ return music_local;
+
+ if (!strEqual(getMusicListEntry(music_global)->filename, UNDEFINED_FILENAME))
+ return music_global;
+
+ return MUS_UNDEFINED;
+}
+
+static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci)
+{
+ boolean is_image = tci->is_image;
+ int initial = tci->initial;
+ int nr = tci->local_nr;
+ struct TitleFadingInfo ti;
+
+ if (is_image)
+ {
+ int graphic = getTitleScreenGraphic(nr, initial);
+
+ /* initialize fading control values to default title config settings */
+ ti = (initial ? title_initial_default : title_default);
+
+ /* override default settings with image config settings, if defined */
+ if (graphic_info[graphic].fade_mode != FADE_MODE_DEFAULT)
+ ti.fade_mode = graphic_info[graphic].fade_mode;
+ if (graphic_info[graphic].fade_delay > -1)
+ ti.fade_delay = graphic_info[graphic].fade_delay;
+ if (graphic_info[graphic].post_delay > -1)
+ ti.post_delay = graphic_info[graphic].post_delay;
+ if (graphic_info[graphic].auto_delay > -1)
+ ti.auto_delay = graphic_info[graphic].auto_delay;
+ }
+ else
+ {
+ if (initial)
+ {
+ ti.fade_mode = titlemessage_initial[nr].fade_mode;
+ ti.fade_delay = titlemessage_initial[nr].fade_delay;
+ ti.post_delay = titlemessage_initial[nr].post_delay;
+ ti.auto_delay = titlemessage_initial[nr].auto_delay;
+ }
+ else
+ {
+ ti.fade_mode = titlemessage[nr].fade_mode;
+ ti.fade_delay = titlemessage[nr].fade_delay;
+ ti.post_delay = titlemessage[nr].post_delay;
+ ti.auto_delay = titlemessage[nr].auto_delay;
+ }
+ }
+
+#if 0
+ if (ti.anim_mode == ANIM_NONE)
+ ti.fade_delay = ti.post_delay = 0;
+#endif
+
+ return ti;
+}
+
+static int compareTitleControlInfo(const void *object1, const void *object2)
+{
+ const struct TitleControlInfo *tci1 = (struct TitleControlInfo *)object1;
+ const struct TitleControlInfo *tci2 = (struct TitleControlInfo *)object2;
+ int compare_result;
+
+ if (tci1->initial != tci2->initial)
+ compare_result = (tci1->initial ? -1 : +1);
+ else if (tci1->sort_priority != tci2->sort_priority)
+ compare_result = tci1->sort_priority - tci2->sort_priority;
+ else if (tci1->is_image != tci2->is_image)
+ compare_result = (tci1->is_image ? -1 : +1);
+ else
+ compare_result = tci1->local_nr - tci2->local_nr;
+
+ return compare_result;
+}
+
+static void InitializeTitleControlsExt_AddTitleInfo(boolean is_image,
+ boolean initial,
+ int nr, int sort_priority)
+{
+ title_controls[num_title_screens].is_image = is_image;
+ title_controls[num_title_screens].initial = initial;
+ title_controls[num_title_screens].local_nr = nr;
+ title_controls[num_title_screens].sort_priority = sort_priority;
+
+ num_title_screens++;
+}
+
+static void InitializeTitleControls_CheckTitleInfo(boolean initial)
+{
+ int i;
+
+ for (i = 0; i < MAX_NUM_TITLE_IMAGES; i++)
+ {
+ int graphic = getTitleScreenGraphic(i, initial);
+ Bitmap *bitmap = graphic_info[graphic].bitmap;
+ int sort_priority = graphic_info[graphic].sort_priority;
+
+#if 0
+ /* skip images and messages (fonts!) when using forced custom graphics */
+ if (setup.override_level_graphics && !initial)
+ continue;
+#endif
+
+ if (bitmap != NULL)
+ InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority);
+ }
+
+ for (i = 0; i < MAX_NUM_TITLE_MESSAGES; i++)
+ {
+ struct TitleMessageInfo *tmi = getTitleMessageInfo(i, initial);
+ char *filename = getLevelSetTitleMessageFilename(i, initial);
+ int sort_priority = tmi->sort_priority;
+
+#if 0
+ /* skip images and messages (fonts!) when using forced custom graphics */
+ if (setup.override_level_graphics)
+ continue;
+#endif
+
+ if (filename != NULL)
+ InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority);
+ }
+}
+
+static void InitializeTitleControls(boolean show_title_initial)
+{
+ num_title_screens = 0;
+
+#if 1
+ /* 1st step: initialize title screens for game start (only when starting) */
+ if (show_title_initial)
+ InitializeTitleControls_CheckTitleInfo(TRUE);
+#endif
+
+ /* 2nd step: initialize title screens for current level set */
+ InitializeTitleControls_CheckTitleInfo(FALSE);
+
+ /* sort title screens according to sort_priority and title number */
+ qsort(title_controls, num_title_screens, sizeof(struct TitleControlInfo),
+ compareTitleControlInfo);
+}
+
+static boolean visibleMenuPos(struct MenuPosInfo *pos)
+{
+ return (pos != NULL && pos->x != -1 && pos->y != -1);
+}
+
+static boolean visibleTextPos(struct TextPosInfo *pos)
+{
+ return (pos != NULL && pos->x != -1 && pos->y != -1);
+}
+
+static void InitializeMainControls()
+{
+ boolean local_team_mode = (!options.network && setup.team_mode);
+ int i;
+
+ /* set main control text values to dynamically determined values */
+ sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
+
+ strcpy(main_text_first_level, int2str(leveldir_current->first_level,
+ menu.main.text.first_level.size));
+ strcpy(main_text_last_level, int2str(leveldir_current->last_level,
+ menu.main.text.last_level.size));
+ strcpy(main_text_level_number, int2str(level_nr,
+ menu.main.text.level_number.size));
+
+ main_text_level_year = leveldir_current->year;
+ main_text_level_imported_from = leveldir_current->imported_from;
+ main_text_level_imported_by = leveldir_current->imported_by;
+ main_text_level_tested_by = leveldir_current->tested_by;
+
+ /* set main control screen positions to dynamically determined values */
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MainControlInfo *mci = &main_controls[i];
+ int nr = mci->nr;
+ struct MenuPosInfo *pos_button = mci->pos_button;
+ struct TextPosInfo *pos_text = mci->pos_text;
+ struct TextPosInfo *pos_input = mci->pos_input;
+ char *text = (mci->text ? *mci->text : NULL);
+ char *input = (mci->input ? *mci->input : NULL);
+ int button_graphic = mci->button_graphic;
+#if 1
+ int font_text = (pos_text ? pos_text->font : -1);
+ int font_input = (pos_input ? pos_input->font : -1);
+#else
+ int font_text = mci->font_text;
+ int font_input = mci->font_input;
+#endif
+
+ int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
+ int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
+ int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
+ int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
+ int text_chars = (text != NULL ? strlen(text) : 0);
+ int input_chars = (input != NULL ? strlen(input) : 0);
+
+ int button_width =
+ (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
+ int button_height =
+ (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
+ int text_width = font_text_width * text_chars;
+ int text_height = font_text_height;
+ int input_width = font_input_width * input_chars;
+ int input_height = font_input_height;
+
+ if (nr == MAIN_CONTROL_NAME)
+ {
+#if 0
+ if (menu.main.input.name.x == -1)
+ menu.main.input.name.x = menu.main.text.name.x + text_width;
+ if (menu.main.input.name.y == -1)
+ menu.main.input.name.y = menu.main.text.name.y;
+#endif
+
+#if 1
+ menu.main.input.name.width = input_width;
+ menu.main.input.name.height = input_height;
+#else
+ menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
+ menu.main.input.name.height = font_input_height;
+#endif
+ }
+
+ if (pos_button != NULL) /* (x/y may be -1/-1 here) */
+ {
+ if (pos_button->width == 0)
+ pos_button->width = button_width;
+ if (pos_button->height == 0)
+ pos_button->height = button_height;
+ }
+
+ if (pos_text != NULL) /* (x/y may be -1/-1 here) */
+ {
+ /* calculate width for non-clickable text -- needed for text alignment */
+ boolean calculate_text_width = (pos_button == NULL && text != NULL);
+
+ if (visibleMenuPos(pos_button))
+ {
+ if (pos_text->x == -1)
+ pos_text->x = pos_button->x + pos_button->width;
+ if (pos_text->y == -1)
+ pos_text->y = pos_button->y;
+ }
+
+ if (pos_text->width == -1 || calculate_text_width)
+ pos_text->width = text_width;
+ if (pos_text->height == -1)
+ pos_text->height = text_height;
+ }
+
+ if (pos_input != NULL) /* (x/y may be -1/-1 here) */
+ {
+ if (visibleTextPos(pos_text))
+ {
+ if (pos_input->x == -1)
+ pos_input->x = pos_text->x + pos_text->width;
+ if (pos_input->y == -1)
+ pos_input->y = pos_text->y;
+ }
+
+ if (pos_input->width == -1)
+ pos_input->width = input_width;
+ if (pos_input->height == -1)
+ pos_input->height = input_height;
+ }
+ }
+}
+
+static void DrawCursorAndText_Main_Ext(int nr, boolean active_text,
+ boolean active_input)
+{
+ int i;
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MainControlInfo *mci = &main_controls[i];
+
+ if (mci->nr == nr || nr == -1)
+ {
+ struct MenuPosInfo *pos_button = mci->pos_button;
+ struct TextPosInfo *pos_text = mci->pos_text;
+ struct TextPosInfo *pos_input = mci->pos_input;
+ char *text = (mci->text ? *mci->text : NULL);
+ char *input = (mci->input ? *mci->input : NULL);
+ int button_graphic = mci->button_graphic;
+#if 1
+ int font_text = (pos_text ? pos_text->font : -1);
+ int font_input = (pos_input ? pos_input->font : -1);
+#else
+ int font_text = mci->font_text;
+ int font_input = mci->font_input;
+#endif
+
+ if (active_text)
+ {
+ button_graphic = BUTTON_ACTIVE(button_graphic);
+ font_text = FONT_ACTIVE(font_text);
+ }
+
+ if (active_input)
+ {
+ font_input = FONT_ACTIVE(font_input);
+ }
+
+ if (visibleMenuPos(pos_button))
+ {
+ struct MenuPosInfo *pos = pos_button;
+ int x = mSX + pos->x;
+ int y = mSY + pos->y;
+
+ DrawBackgroundForGraphic(x, y, pos->width, pos->height, button_graphic);
+ DrawGraphicThruMaskExt(drawto, x, y, button_graphic, 0);
+ }
+
+ if (visibleTextPos(pos_text) && text != NULL)
+ {
+ struct TextPosInfo *pos = pos_text;
+ int x = mSX + ALIGNED_TEXT_XPOS(pos);
+ int y = mSY + ALIGNED_TEXT_YPOS(pos);
+
+#if 1
+ /* (check why/if this is needed) */
+ DrawBackgroundForFont(x, y, pos->width, pos->height, font_text);
+#endif
+ DrawText(x, y, text, font_text);
+ }
+
+ if (visibleTextPos(pos_input) && input != NULL)
+ {
+ struct TextPosInfo *pos = pos_input;
+ int x = mSX + ALIGNED_TEXT_XPOS(pos);
+ int y = mSY + ALIGNED_TEXT_YPOS(pos);
+
+#if 1
+ /* (check why/if this is needed) */
+ DrawBackgroundForFont(x, y, pos->width, pos->height, font_input);
+#endif
+ DrawText(x, y, input, font_input);
+ }
+ }
+ }
+}
+
+static void DrawCursorAndText_Main(int nr, boolean active_text)
+{
+ DrawCursorAndText_Main_Ext(nr, active_text, FALSE);
+}
+
+#if 0
+static void DrawCursorAndText_Main_Input(int nr, boolean active_text)
+{
+ DrawCursorAndText_Main_Ext(nr, active_text, TRUE);
+}
+#endif
+
+static struct MainControlInfo *getMainControlInfo(int nr)
+{
+ int i;