+ setup.game_frame_delay = atoi(game_speed_current->identifier);
+
+ /* needed for displaying game speed text instead of identifier */
+ game_speed_text = game_speed_current->name;
+}
+
+static void execSetupGame_setScrollDelays()
+{
+ if (scroll_delays == NULL)
+ {
+ int i;
+
+ for (i = 0; scroll_delays_list[i].value != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = scroll_delays_list[i].value;
+ char *text = scroll_delays_list[i].text;
+
+ ti->node_top = &scroll_delays;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Scaling Type");
+
+ pushTreeInfo(&scroll_delays, ti);
+ }
+
+ /* sort scaling type values to start with lowest scaling type value */
+ sortTreeInfo(&scroll_delays);
+
+ /* set current scaling type value to configured scaling type value */
+ scroll_delay_current =
+ getTreeInfoFromIdentifier(scroll_delays,i_to_a(setup.scroll_delay_value));
+
+ /* if that fails, set current scaling type to reliable default value */
+ if (scroll_delay_current == NULL)
+ scroll_delay_current =
+ getTreeInfoFromIdentifier(scroll_delays, i_to_a(STD_SCROLL_DELAY));
+
+ /* if that also fails, set current scaling type to first available value */
+ if (scroll_delay_current == NULL)
+ scroll_delay_current = scroll_delays;
+ }
+
+ setup.scroll_delay_value = atoi(scroll_delay_current->identifier);
+
+ /* needed for displaying scaling type text instead of identifier */
+ scroll_delay_text = scroll_delay_current->name;
+}
+
+static void execSetupGame()
+{
+ execSetupGame_setGameSpeeds();
+ execSetupGame_setScrollDelays();
+
+ setup_mode = SETUP_MODE_GAME;
+
+ DrawSetupScreen();
+}
+
+static void execSetupChooseGameSpeed()
+{
+ setup_mode = SETUP_MODE_CHOOSE_GAME_SPEED;
+
+ DrawSetupScreen();
+}
+
+static void execSetupChooseScrollDelay()
+{
+ setup_mode = SETUP_MODE_CHOOSE_SCROLL_DELAY;
+
+ DrawSetupScreen();
+}
+
+static void execSetupEditor()
+{
+ setup_mode = SETUP_MODE_EDITOR;
+
+ DrawSetupScreen();
+}
+
+static void execSetupGraphics_setWindowSizes(boolean update_list)
+{
+ if (window_sizes != NULL && update_list)
+ {
+ freeTreeInfo(window_sizes);
+
+ window_sizes = NULL;
+ }
+
+ if (window_sizes == NULL)
+ {
+ boolean current_window_size_found = FALSE;
+ int i;
+
+ for (i = 0; window_sizes_list[i].value != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = window_sizes_list[i].value;
+ char *text = window_sizes_list[i].text;
+
+ ti->node_top = &window_sizes;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Window Scaling");
+
+ pushTreeInfo(&window_sizes, ti);
+
+ if (value == setup.window_scaling_percent)
+ current_window_size_found = TRUE;
+ }
+
+ if (!current_window_size_found)
+ {
+ // add entry for non-preset window scaling value
+
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = setup.window_scaling_percent;
+
+ ti->node_top = &window_sizes;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%d %% (Current)", value);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Window Scaling");
+
+ pushTreeInfo(&window_sizes, ti);
+ }
+
+ /* sort window size values to start with lowest window size value */
+ sortTreeInfo(&window_sizes);
+
+ /* set current window size value to configured window size value */
+ window_size_current =
+ getTreeInfoFromIdentifier(window_sizes,
+ i_to_a(setup.window_scaling_percent));
+
+ /* if that fails, set current window size to reliable default value */
+ if (window_size_current == NULL)
+ window_size_current =
+ getTreeInfoFromIdentifier(window_sizes,
+ i_to_a(STD_WINDOW_SCALING_PERCENT));
+
+ /* if that also fails, set current window size to first available value */
+ if (window_size_current == NULL)
+ window_size_current = window_sizes;
+ }
+
+ setup.window_scaling_percent = atoi(window_size_current->identifier);
+
+ /* needed for displaying window size text instead of identifier */
+ window_size_text = window_size_current->name;
+}
+
+static void execSetupGraphics_setScalingTypes()
+{
+ if (scaling_types == NULL)
+ {
+ int i;
+
+ for (i = 0; scaling_types_list[i].value != NULL; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ char *value = scaling_types_list[i].value;
+ char *text = scaling_types_list[i].text;
+
+ ti->node_top = &scaling_types;
+ ti->sort_priority = i;
+
+ sprintf(identifier, "%s", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Anti-Aliasing");
+
+ pushTreeInfo(&scaling_types, ti);
+ }
+
+ /* sort scaling type values to start with lowest scaling type value */
+ sortTreeInfo(&scaling_types);
+
+ /* set current scaling type value to configured scaling type value */
+ scaling_type_current =
+ getTreeInfoFromIdentifier(scaling_types, setup.window_scaling_quality);
+
+ /* if that fails, set current scaling type to reliable default value */
+ if (scaling_type_current == NULL)
+ scaling_type_current =
+ getTreeInfoFromIdentifier(scaling_types, SCALING_QUALITY_DEFAULT);
+
+ /* if that also fails, set current scaling type to first available value */
+ if (scaling_type_current == NULL)
+ scaling_type_current = scaling_types;
+ }
+
+ setup.window_scaling_quality = scaling_type_current->identifier;
+
+ /* needed for displaying scaling type text instead of identifier */
+ scaling_type_text = scaling_type_current->name;
+}
+
+static void execSetupGraphics_setScreenModes()
+{
+ // if (screen_modes == NULL && video.fullscreen_available)
+ if (screen_modes == NULL && video.fullscreen_modes != NULL)
+ {
+ int i;
+
+ for (i = 0; video.fullscreen_modes[i].width != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int x = video.fullscreen_modes[i].width;
+ int y = video.fullscreen_modes[i].height;
+ int xx, yy;
+
+ get_aspect_ratio_from_screen_mode(&video.fullscreen_modes[i], &xx, &yy);
+
+ ti->node_top = &screen_modes;
+ ti->sort_priority = x * 10000 + y;
+
+ sprintf(identifier, "%dx%d", x, y);
+ sprintf(name, "%d x %d [%d:%d]", x, y, xx, yy);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Fullscreen Mode");
+
+ pushTreeInfo(&screen_modes, ti);
+ }
+
+ /* sort fullscreen modes to start with lowest available screen resolution */
+ sortTreeInfo(&screen_modes);
+
+ /* set current screen mode for fullscreen mode to configured setup value */
+ screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
+ setup.fullscreen_mode);
+
+ /* if that fails, set current screen mode to reliable default value */
+ if (screen_mode_current == NULL)
+ screen_mode_current = getTreeInfoFromIdentifier(screen_modes,
+ DEFAULT_FULLSCREEN_MODE);
+
+ /* if that also fails, set current screen mode to first available mode */
+ if (screen_mode_current == NULL)
+ screen_mode_current = screen_modes;
+
+ if (screen_mode_current == NULL)
+ video.fullscreen_available = FALSE;
+ }
+
+ // if (video.fullscreen_available)
+ if (screen_mode_current != NULL)
+ {
+ setup.fullscreen_mode = screen_mode_current->identifier;
+
+ /* needed for displaying screen mode name instead of identifier */
+ screen_mode_text = screen_mode_current->name;
+ }
+}
+
+static void execSetupGraphics()
+{
+ if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE)
+ {
+ // update "setup.window_scaling_percent" from list selection
+ execSetupGraphics_setWindowSizes(FALSE);
+ }
+ else
+ {
+ // update list selection from "setup.window_scaling_percent"
+ execSetupGraphics_setWindowSizes(TRUE);
+ }
+
+ execSetupGraphics_setScalingTypes();
+ execSetupGraphics_setScreenModes();
+
+ setup_mode = SETUP_MODE_GRAPHICS;
+
+ DrawSetupScreen();
+
+#if defined(TARGET_SDL2)
+ // window scaling may have changed at this point
+ ToggleFullscreenOrChangeWindowScalingIfNeeded();
+
+ // window scaling quality may have changed at this point
+ if (!strEqual(setup.window_scaling_quality, video.window_scaling_quality))
+ SDLSetWindowScalingQuality(setup.window_scaling_quality);
+#endif
+}
+
+#if !defined(PLATFORM_ANDROID)
+#if defined(TARGET_SDL2)
+static void execSetupChooseWindowSize()
+{
+ setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE;
+
+ DrawSetupScreen();
+}
+
+static void execSetupChooseScalingType()
+{
+ setup_mode = SETUP_MODE_CHOOSE_SCALING_TYPE;
+
+ DrawSetupScreen();
+}
+#else
+static void execSetupChooseScreenMode()
+{
+ if (!video.fullscreen_available)
+ return;
+
+ setup_mode = SETUP_MODE_CHOOSE_SCREEN_MODE;
+
+ DrawSetupScreen();
+}
+#endif
+#endif
+
+static void execSetupChooseVolumeSimple()
+{
+ setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
+
+ DrawSetupScreen();
+}
+
+static void execSetupChooseVolumeLoops()
+{
+ setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
+
+ DrawSetupScreen();
+}
+
+static void execSetupChooseVolumeMusic()
+{
+ setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
+
+ DrawSetupScreen();
+}
+
+static void execSetupSound()
+{
+ if (volumes_simple == NULL)
+ {
+ boolean current_volume_simple_found = FALSE;
+ int i;
+
+ for (i = 0; volumes_list[i].value != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = volumes_list[i].value;
+ char *text = volumes_list[i].text;
+
+ ti->node_top = &volumes_simple;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Sound Volume");
+
+ pushTreeInfo(&volumes_simple, ti);
+
+ if (value == setup.volume_simple)
+ current_volume_simple_found = TRUE;
+ }
+
+ if (!current_volume_simple_found)
+ {
+ // add entry for non-preset volume value
+
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = setup.volume_simple;
+
+ ti->node_top = &volumes_simple;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%d %% (Current)", value);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Sound Volume");
+
+ pushTreeInfo(&volumes_simple, ti);
+ }
+
+ /* sort volume values to start with lowest volume value */
+ sortTreeInfo(&volumes_simple);
+
+ /* set current volume value to configured volume value */
+ volume_simple_current =
+ getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
+
+ /* if that fails, set current volume to reliable default value */
+ if (volume_simple_current == NULL)
+ volume_simple_current =
+ getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
+
+ /* if that also fails, set current volume to first available value */
+ if (volume_simple_current == NULL)
+ volume_simple_current = volumes_simple;
+ }
+
+ if (volumes_loops == NULL)
+ {
+ boolean current_volume_loops_found = FALSE;
+ int i;
+
+ for (i = 0; volumes_list[i].value != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = volumes_list[i].value;
+ char *text = volumes_list[i].text;
+
+ ti->node_top = &volumes_loops;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Loops Volume");
+
+ pushTreeInfo(&volumes_loops, ti);
+
+ if (value == setup.volume_loops)
+ current_volume_loops_found = TRUE;
+ }
+
+ if (!current_volume_loops_found)
+ {
+ // add entry for non-preset volume value
+
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = setup.volume_loops;
+
+ ti->node_top = &volumes_loops;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%d %% (Current)", value);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Loops Volume");
+
+ pushTreeInfo(&volumes_loops, ti);
+ }
+
+ /* sort volume values to start with lowest volume value */
+ sortTreeInfo(&volumes_loops);
+
+ /* set current volume value to configured volume value */
+ volume_loops_current =
+ getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
+
+ /* if that fails, set current volume to reliable default value */
+ if (volume_loops_current == NULL)
+ volume_loops_current =
+ getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
+
+ /* if that also fails, set current volume to first available value */
+ if (volume_loops_current == NULL)
+ volume_loops_current = volumes_loops;
+ }
+
+ if (volumes_music == NULL)
+ {
+ boolean current_volume_music_found = FALSE;
+ int i;
+
+ for (i = 0; volumes_list[i].value != -1; i++)
+ {
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = volumes_list[i].value;
+ char *text = volumes_list[i].text;
+
+ ti->node_top = &volumes_music;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%s", text);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Music Volume");
+
+ pushTreeInfo(&volumes_music, ti);
+
+ if (value == setup.volume_music)
+ current_volume_music_found = TRUE;
+ }
+
+ if (!current_volume_music_found)
+ {
+ // add entry for non-preset volume value
+
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+ char identifier[32], name[32];
+ int value = setup.volume_music;
+
+ ti->node_top = &volumes_music;
+ ti->sort_priority = value;
+
+ sprintf(identifier, "%d", value);
+ sprintf(name, "%d %% (Current)", value);
+
+ setString(&ti->identifier, identifier);
+ setString(&ti->name, name);
+ setString(&ti->name_sorting, name);
+ setString(&ti->infotext, "Music Volume");
+
+ pushTreeInfo(&volumes_music, ti);
+ }
+
+ /* sort volume values to start with lowest volume value */
+ sortTreeInfo(&volumes_music);
+
+ /* set current volume value to configured volume value */
+ volume_music_current =
+ getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
+
+ /* if that fails, set current volume to reliable default value */
+ if (volume_music_current == NULL)
+ volume_music_current =
+ getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
+
+ /* if that also fails, set current volume to first available value */
+ if (volume_music_current == NULL)
+ volume_music_current = volumes_music;
+ }
+
+ setup.volume_simple = atoi(volume_simple_current->identifier);
+ setup.volume_loops = atoi(volume_loops_current->identifier);
+ setup.volume_music = atoi(volume_music_current->identifier);