- ClearField();
-
- if (setup_mode == SETUP_MODE_MAIN)
- {
- setup_info = setup_info_main;
- title_string = "Setup";
- }
- else if (setup_mode == SETUP_MODE_GAME)
- {
- setup_info = setup_info_game;
- title_string = "Setup Game";
- }
- else if (setup_mode == SETUP_MODE_EDITOR)
- {
- setup_info = setup_info_editor;
- title_string = "Setup Editor";
- }
- else if (setup_mode == SETUP_MODE_GRAPHICS)
- {
- setup_info = setup_info_graphics;
- title_string = "Setup Graphics";
- }
- else if (setup_mode == SETUP_MODE_SOUND)
- {
- setup_info = setup_info_sound;
- title_string = "Setup Sound";
- }
- else if (setup_mode == SETUP_MODE_ARTWORK)
- {
- setup_info = setup_info_artwork;
- title_string = "Custom Artwork";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS)
- {
- setup_info = setup_info_shortcuts;
- title_string = "Setup Shortcuts";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS_1)
- {
- setup_info = setup_info_shortcuts_1;
- title_string = "Setup Shortcuts";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS_2)
- {
- setup_info = setup_info_shortcuts_2;
- title_string = "Setup Shortcuts";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS_3)
- {
- setup_info = setup_info_shortcuts_3;
- title_string = "Setup Shortcuts";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS_4)
- {
- setup_info = setup_info_shortcuts_4;
- title_string = "Setup Shortcuts";
- }
- else if (setup_mode == SETUP_MODE_SHORTCUTS_5)
- {
- setup_info = setup_info_shortcuts_5;
- title_string = "Setup Shortcuts";
- }
-
- DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string);
-
-#if 1
-
- num_setup_info = 0;
- for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
- num_setup_info++;
-
- max_setup_info = 0;
- for (i = 0; setup_info[i].type != 0; i++)
- max_setup_info++;
-
-#if 0
- drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN);
-#endif
-
-#else
-
- num_setup_info = 0;
-#if 1
- for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++)
-#else
- for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++)
-#endif
- {
- void *value_ptr = setup_info[i].value;
-
- /* set some entries to "unchangeable" according to other variables */
- if ((value_ptr == &setup.sound_simple && !audio.sound_available) ||
- (value_ptr == &setup.sound_loops && !audio.loops_available) ||
- (value_ptr == &setup.sound_music && !audio.music_available) ||
- (value_ptr == &setup.fullscreen && !video.fullscreen_available) ||
- (value_ptr == &screen_mode_text && !video.fullscreen_available) ||
- (value_ptr == &window_size_text && !video.window_scaling_available) ||
- (value_ptr == &scaling_type_text && !video.window_scaling_available))
- setup_info[i].type |= TYPE_GHOSTED;
-
- if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST))
- initCursor(i, IMG_MENU_BUTTON_ENTER_MENU);
- else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST))
- initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
- else if (setup_info[i].type & ~TYPE_SKIP_ENTRY)
- initCursor(i, IMG_MENU_BUTTON);
-
- DrawCursorAndText_Setup(i, FALSE);
-
- if (setup_info[i].type & TYPE_VALUE)
- drawSetupValue(i);
-
- num_setup_info++;
- }
-#endif
-
-#if 0
- DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4,
- "Joysticks deactivated in setup menu");
-#endif
-
-#if 1
- HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
-#endif
-
-#if 1
- MapScreenGadgets(max_setup_info);
-#endif
-
- if (redraw_all)
- redraw_mask = REDRAW_ALL;
-
-#if 1
- FadeIn(redraw_mask);
-#else
- FadeIn(REDRAW_FIELD);
-#endif
-
- InitAnimation();
-#if 0
- HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE);
-#endif
-}
-
-void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
-{
- static int choice_store[MAX_SETUP_MODES];
- static int first_entry_store[MAX_SETUP_MODES];
- int choice = choice_store[setup_mode]; /* starts with 0 */
- int first_entry = first_entry_store[setup_mode]; /* starts with 0 */
- int x = 0;
-#if 1
- int y = choice - first_entry;
- int y_old = y;
-#else
- int y = choice;
-#endif
- boolean position_set_by_scrollbar = (dx == 999);
-#if 1
- int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
- int num_page_entries;
-
- num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN);
-#endif
-
- if (button == MB_MENU_INITIALIZE)
- {
- /* advance to first valid menu entry */
- while (choice < num_setup_info &&
- setup_info[choice].type & TYPE_SKIP_ENTRY)
- choice++;
-#if 0
- choice_store[setup_mode] = choice;
-#endif
-
-#if 1
- if (position_set_by_scrollbar)
- first_entry = first_entry_store[setup_mode] = dy;
- else
- AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
- NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
-
- drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
-#endif
-
-#if 1
- if (choice < first_entry)
- choice = first_entry;
- else if (choice > first_entry + num_page_entries - 1)
- choice = first_entry + num_page_entries - 1;
-
- choice_store[setup_mode] = choice;
-
- DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
-#else
- DrawCursorAndText_Setup(choice, -1, TRUE);
-#endif
-
- return;
- }
- else if (button == MB_MENU_LEAVE)
- {
- int i;
-
- PlaySound(SND_MENU_ITEM_SELECTING);
-
- for (i = 0; setup_info[i].type != 0; i++)
- {
- if (setup_info[i].type & TYPE_LEAVE_MENU)
- {
- void (*menu_callback_function)(void) = setup_info[i].value;
-
- FadeSetLeaveMenu();
-
- menu_callback_function();
-
- break; /* absolutely needed because function changes 'setup_info'! */
- }
- }
-
- return;
- }
-
- if (mx || my) /* mouse input */
- {
- x = (mx - mSX) / 32;
- y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
- }
-#if 1
- else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */
-#else
- else if (dx || dy) /* keyboard input */
-#endif
- {
- /* move cursor instead of scrolling when already at start/end of list */
- if (dy == -1 * SCROLL_LINE && first_entry == 0)
- dy = -1;
- else if (dy == +1 * SCROLL_LINE &&
- first_entry + num_page_entries == max_setup_info)
- dy = 1;
-
- /* handle scrolling screen one line or page */
- if (y + dy < 0 ||
- y + dy > num_page_entries - 1)
- {
- boolean redraw = FALSE;
-
- if (ABS(dy) == SCROLL_PAGE)
- step = num_page_entries - 1;
-
- if (dy < 0 && first_entry > 0)
- {
- /* scroll page/line up */
-
- first_entry -= step;
- if (first_entry < 0)
- first_entry = 0;
-
- redraw = TRUE;
- }
- else if (dy > 0 && first_entry + num_page_entries < max_setup_info)
- {
- /* scroll page/line down */
-
- first_entry += step;
- if (first_entry + num_page_entries > max_setup_info)
- first_entry = MAX(0, max_setup_info - num_page_entries);
-
- redraw = TRUE;
- }
-
- if (redraw)
- {
- choice += first_entry - first_entry_store[setup_mode];
-
- first_entry_store[setup_mode] = first_entry;
-
- if (choice < first_entry)
- choice = first_entry;
- else if (choice > first_entry + num_page_entries - 1)
- choice = first_entry + num_page_entries - 1;
-
- choice_store[setup_mode] = choice;
-
- drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
-
- DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
-
- AdjustScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, max_setup_info,
- NUM_MENU_ENTRIES_ON_SCREEN, first_entry);
- }
-
- return;
- }
-
- if (dx)
- {
- int menu_navigation_type = (dx < 0 ? TYPE_LEAVE : TYPE_ENTER);
-
- if (setup_info[choice].type & menu_navigation_type ||
- setup_info[choice].type & TYPE_BOOLEAN_STYLE ||
- setup_info[choice].type & TYPE_YES_NO_AUTO)
- button = MB_MENU_CHOICE;
- }
-#if 1
- else if (dy)
- y += dy;
-#else
- else if (dy)
- y = choice + dy;
-#endif
-
- /* jump to next non-empty menu entry (up or down) */
- while (y > 0 && y < num_setup_info - 1 &&
- setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
- y += dy;
-
- if (!IN_VIS_FIELD(x, y))
- {
- first_entry += y - y_old;
-
- if (first_entry >= 0 &&
- first_entry + num_page_entries <= max_setup_info)
- {
- first_entry_store[setup_mode] = first_entry;
-
- if (choice < first_entry)
- choice = first_entry;
- else if (choice > first_entry + num_page_entries - 1)
- choice = first_entry + num_page_entries - 1;