added setup file option to toggle setup menu option to upload all tapes
[rocksndiamonds.git] / src / screens.c
index 23e0b113c01b0bc4f52424330a6dad50889ba5f5..553b24109c939556ad4be8ddfca81ab8bac02e3e 100644 (file)
@@ -282,6 +282,8 @@ static void MapScreenTreeGadgets(TreeInfo *);
 
 static void UpdateScreenMenuGadgets(int, boolean);
 
+static boolean OfferUploadTapes(void);
+
 static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS];
 
 static int info_mode = INFO_MODE_MAIN;
@@ -6651,6 +6653,11 @@ static void execGadgetNetworkServer(void)
   ClickOnGadget(gi, MB_LEFTBUTTON);
 }
 
+static void execOfferUploadTapes(void)
+{
+  OfferUploadTapes();
+}
+
 static void ToggleNetworkModeIfNeeded(void)
 {
   int font_title = FONT_TITLE_1;
@@ -6870,6 +6877,7 @@ static struct TokenInfo setup_info_game[] =
   { TYPE_STRING,       &network_server_text,   ""                      },
   { TYPE_SWITCH,       &setup.api_server,      "Use Highscore Server:" },
   { TYPE_SWITCH,       &setup.only_show_local_scores, "Only Show Local Scores:" },
+  { TYPE_ENTER_LIST,   execOfferUploadTapes,   "Upload All Tapes to Server" },
   { TYPE_SWITCH,       &setup.multiple_users,  "Multiple Users/Teams:" },
   { TYPE_YES_NO,       &setup.input_on_focus,  "Only Move Focussed Player:" },
   { TYPE_SWITCH,       &setup.time_limit,      "Time Limit:"           },
@@ -9034,10 +9042,10 @@ void HandleGameActions(void)
   if (game_status != GAME_MODE_PLAYING)
     return;
 
-  GameActions();       // main game loop
+  GameActions();               // main game loop
 
   if (tape.auto_play && !tape.playing)
-    AutoPlayTapes();   // continue automatically playing next tape
+    AutoPlayTapesContinue();   // continue automatically playing next tape
 }
 
 
@@ -9828,3 +9836,83 @@ void DrawScreenAfterAddingSet(char *tree_subdir_new, int tree_type)
     }
   }
 }
+
+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("Upload all your tapes to the high score server now?", REQ_ASK))
+    return FALSE;
+
+  int num_tapes_uploaded = UploadTapes();
+  char message[100];
+
+  sprintf(message, "%d tapes uploaded!", num_tapes_uploaded);
+
+  Request(message, REQ_CONFIRM);
+
+  // after all tapes have been uploaded, remove entry from setup menu
+  setup.provide_uploading_tapes = FALSE;
+  setHideSetupEntry(execOfferUploadTapes);
+
+  SaveSetup();
+
+  return (num_tapes_uploaded > 0);
+}
+
+void CheckUploadTapes(void)
+{
+  if (!setup.provide_uploading_tapes)
+    setHideSetupEntry(execOfferUploadTapes);
+
+  if (!setup.ask_for_uploading_tapes)
+    return;
+
+  if (directoryExists(getTapeDir(NULL)))
+  {
+    boolean tapes_uploaded = OfferUploadTapes();
+
+    if (!tapes_uploaded)
+      Request("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;
+    setHideSetupEntry(execOfferUploadTapes);
+  }
+
+  // after asking for uploading all tapes once, do not ask again
+  setup.ask_for_uploading_tapes = FALSE;
+
+  SaveSetup();
+}