+
+void HandleScreenGadgetKeys(Key key)
+{
+ if (key == setup.shortcut.tape_play)
+ HandleScreenGadgets(screen_gadget[SCREEN_CTRL_ID_PLAY_TAPE]);
+}
+
+void DumpScreenIdentifiers(void)
+{
+ int i;
+
+ Print("Active screen elements on current screen:\n");
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MainControlInfo *mci = &main_controls[i];
+
+ if (mci->button_graphic != -1)
+ {
+ char *token = getTokenFromImageID(mci->button_graphic);
+
+ Print("- '%s'\n", token);
+ }
+ }
+
+ Print("Done.\n");
+}
+
+boolean DoScreenAction(int image_id)
+{
+ int i;
+
+ if (game_status != GAME_MODE_MAIN)
+ return FALSE;
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ struct MainControlInfo *mci = &main_controls[i];
+ struct MenuPosInfo *pos = mci->pos_button;
+
+ if (mci->button_graphic == image_id)
+ {
+ int x = mSX + pos->x;
+ int y = mSY + pos->y;
+
+ HandleMainMenu(x, y, 0, 0, MB_MENU_CHOICE);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
+{
+ // get tree info node of newly added level or artwork set
+ TreeInfo *tree_node_first = TREE_FIRST_NODE(tree_type);
+ TreeInfo *tree_node_new = getTreeInfoFromIdentifier(tree_node_first,
+ tree_subdir_new);
+ if (tree_node_new == NULL) // should not happen
+ return;
+
+ // if request dialog is active, do nothing
+ if (game.request_active)
+ return;
+
+ if (game_status == GAME_MODE_MAIN &&
+ tree_type == TREE_TYPE_LEVEL_DIR)
+ {
+ // when adding new level set in main menu, select it as current level set
+
+ // change current level set to newly added level set from zip file
+ leveldir_current = tree_node_new;
+
+ // change current level number to first level of newly added level set
+ level_nr = leveldir_current->first_level;
+
+ // redraw screen to reflect changed level set
+ DrawMainMenu();
+
+ // save this level set and level number as last selected level set
+ SaveLevelSetup_LastSeries();
+ SaveLevelSetup_SeriesInfo();
+ }
+ else if (game_status == GAME_MODE_LEVELS &&
+ tree_type == TREE_TYPE_LEVEL_DIR)
+ {
+ // when adding new level set in level set menu, set cursor and update screen
+
+ leveldir_current = tree_node_new;
+
+ DrawChooseTree(&leveldir_current);
+ }
+ else if (game_status == GAME_MODE_SETUP)
+ {
+ // when adding new artwork set in setup menu, set cursor and update screen
+
+ if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS &&
+ tree_type == TREE_TYPE_GRAPHICS_DIR)
+ {
+ artwork.gfx_current = tree_node_new;
+
+ DrawChooseTree(&artwork.gfx_current);
+ }
+ else if (setup_mode == SETUP_MODE_CHOOSE_SOUNDS &&
+ tree_type == TREE_TYPE_SOUNDS_DIR)
+ {
+ artwork.snd_current = tree_node_new;
+
+ DrawChooseTree(&artwork.snd_current);
+ }
+ else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC &&
+ tree_type == TREE_TYPE_MUSIC_DIR)
+ {
+ artwork.mus_current = tree_node_new;
+
+ DrawChooseTree(&artwork.mus_current);
+ }
+ }
+}
+
+static int UploadTapes(void)
+{
+ SetGameStatus(GAME_MODE_LOADING);
+
+ FadeSetEnterScreen();
+ FadeOut(REDRAW_ALL);
+
+ ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+ FadeIn(REDRAW_ALL);
+
+ DrawInitTextHead("Uploading tapes");
+
+ global.autoplay_mode = AUTOPLAY_MODE_UPLOAD;
+ global.autoplay_leveldir = "ALL";
+ global.autoplay_all = TRUE;
+
+ int num_tapes_uploaded = AutoPlayTapes();
+
+ global.autoplay_mode = AUTOPLAY_MODE_NONE;
+ global.autoplay_leveldir = NULL;
+ global.autoplay_all = FALSE;
+
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+
+ return num_tapes_uploaded;
+}
+
+static boolean OfferUploadTapes(void)
+{
+ if (!Request(setup.has_remaining_tapes ?
+ "Upload missing tapes to the high score server now?" :
+ "Upload all your tapes to the high score server now?", REQ_ASK))
+ return FALSE;
+
+ // when uploading tapes, make sure that high score server is enabled
+ runtime.use_api_server = setup.use_api_server = TRUE;
+
+ int num_tapes_uploaded = UploadTapes();
+ char message[100];
+
+ if (num_tapes_uploaded < 0)
+ {
+ num_tapes_uploaded = -num_tapes_uploaded - 1;
+
+ if (num_tapes_uploaded == 0)
+ sprintf(message, "Upload failed! No tapes uploaded!");
+ else if (num_tapes_uploaded == 1)
+ sprintf(message, "Upload failed! Only 1 tape uploaded!");
+ else
+ sprintf(message, "Upload failed! Only %d tapes uploaded!",
+ num_tapes_uploaded);
+
+ Request(message, REQ_CONFIRM);
+
+ // if uploading tapes failed, add tape upload entry to setup menu
+ setup.provide_uploading_tapes = TRUE;
+ setup.has_remaining_tapes = TRUE;
+
+ SaveSetup_ServerSetup();
+
+ return FALSE;
+ }
+
+ if (num_tapes_uploaded == 0)
+ sprintf(message, "No tapes uploaded!");
+ else if (num_tapes_uploaded == 1)
+ sprintf(message, "1 tape uploaded!");
+ else
+ sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
+
+ Request(message, REQ_CONFIRM);
+
+ if (num_tapes_uploaded > 0)
+ Request("New scores will be visible after a few minutes!", REQ_CONFIRM);
+
+ // after all tapes have been uploaded, remove entry from setup menu
+ setup.provide_uploading_tapes = FALSE;
+ setup.has_remaining_tapes = FALSE;
+
+ SaveSetup_ServerSetup();
+
+ return TRUE;
+}
+
+static void CheckUploadTapes(void)
+{
+ if (!setup.ask_for_uploading_tapes)
+ return;
+
+ // after asking for uploading tapes, do not ask again
+ setup.ask_for_uploading_tapes = FALSE;
+ setup.ask_for_remaining_tapes = FALSE;
+
+ if (directoryExists(getTapeDir(NULL)))
+ {
+ boolean tapes_uploaded = OfferUploadTapes();
+
+ if (!tapes_uploaded)
+ {
+ Request(setup.has_remaining_tapes ?
+ "You can upload missing tapes from the setup menu later!" :
+ "You can upload your tapes from the setup menu later!",
+ REQ_CONFIRM);
+ }
+ }
+ else
+ {
+ // if tapes directory does not exist yet, never offer uploading all tapes
+ setup.provide_uploading_tapes = FALSE;
+ }
+
+ SaveSetup_ServerSetup();
+}
+
+static void UpgradePlayerUUID(void)
+{
+ ApiResetUUIDAsThread(getUUID());
+}
+
+static void CheckUpgradePlayerUUID(void)
+{
+ if (setup.player_version > 1)
+ return;
+
+ UpgradePlayerUUID();
+}
+
+void CheckApiServerTasks(void)
+{
+ // check if the player's UUID has to be upgraded
+ CheckUpgradePlayerUUID();
+
+ // check if there are any tapes to be uploaded
+ CheckUploadTapes();
+}