From 9cf7caccd61b849694dc49e397422cbc717a083b Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Fri, 17 Oct 2003 17:46:48 +0000
Subject: [PATCH] Allow more than one title screen

---
 src/include/stratagus.h     |  2 +-
 src/stratagus/stratagus.cpp | 97 +++++++++++++++++++------------------
 src/ui/script_ui.cpp        | 29 +++++------
 src/video/movie.cpp         | 21 ++++++--
 4 files changed, 84 insertions(+), 65 deletions(-)

diff --git a/src/include/stratagus.h b/src/include/stratagus.h
index d07f810a6..c4ad9e743 100644
--- a/src/include/stratagus.h
+++ b/src/include/stratagus.h
@@ -450,7 +450,7 @@ extern int SlowFrameCounter;
     */
 #define MyRand()	rand()
 
-extern char* TitleScreen;		/// File for title screen
+extern char** TitleScreen;		/// File for title screen
 extern char* GameName;			/// Name of the game (wc2,wc1)
 extern char* MenuBackground;		/// File for menu background
 extern char* MenuBackgroundWithTitle;	/// File for menu with title
diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp
index 8c16f8256..ddddbf00a 100644
--- a/src/stratagus/stratagus.cpp
+++ b/src/stratagus/stratagus.cpp
@@ -234,7 +234,7 @@ extern SCM CclUnits(void);
 --	Variables
 ----------------------------------------------------------------------------*/
 
-global char* TitleScreen;		/// Titlescreen to show at startup
+global char** TitleScreen;		/// Titlescreen to show at startup
 global char* MenuBackground;		/// File for menu background
 global char* MenuBackgroundWithTitle;	/// File for menu with title
 global char* TitleMusic;		/// File for title music
@@ -451,7 +451,15 @@ local int WaitMouseY;			/// Mouse Y position
 local void WaitCallbackKey(unsigned dummy __attribute__((unused)))
 {
     DebugLevel3Fn("Pressed %8x %8x\n" _C_ MouseButtons _C_ dummy);
-    WaitNoEvent=0;
+    WaitNoEvent = 0;
+}
+
+/**
+**	Callback for input.
+*/
+local void WaitCallbackKey1(unsigned dummy __attribute__((unused)))
+{
+    DebugLevel3Fn("Released %8x %8x\n" _C_ MouseButtons _C_ dummy);
 }
 
 /**
@@ -461,7 +469,7 @@ local void WaitCallbackKey2(unsigned dummy1 __attribute__((unused)),
     unsigned dummy2 __attribute__((unused)))
 {
     DebugLevel3Fn("Pressed %8x %8x %8x\n" _C_ MouseButtons _C_ dummy1 _C_ dummy2);
-    WaitNoEvent=0;
+    WaitNoEvent = 0;
 }
 
 /**
@@ -469,9 +477,18 @@ local void WaitCallbackKey2(unsigned dummy1 __attribute__((unused)),
 */
 local void WaitCallbackKey3(unsigned dummy1 __attribute__((unused)),
     unsigned dummy2 __attribute__((unused)))
+{
+    DebugLevel3Fn("Released %8x %8x %8x\n" _C_ MouseButtons _C_ dummy1 _C_ dummy2);
+}
+
+/**
+**	Callback for input.
+*/
+local void WaitCallbackKey4(unsigned dummy1 __attribute__((unused)),
+    unsigned dummy2 __attribute__((unused)))
 {
     DebugLevel3Fn("Repeated %8x %8x %8x\n" _C_ MouseButtons _C_ dummy1 _C_ dummy2);
-    WaitNoEvent=0;
+    WaitNoEvent = 0;
 }
 
 /**
@@ -856,7 +873,7 @@ local void VideoEffect0(int frame,
 }
 #endif
 
-#ifdef DEBUG
+#ifdef DEBUG_DRAWFONTS
 /**
 **	Draw the fonts, for screen shots.
 */
@@ -911,65 +928,52 @@ local void DebugDrawFonts(void)
 local void WaitForInput(int timeout)
 {
     EventCallback callbacks;
-#if defined(linux) && !defined(DEBUG)
-    char* s;
-    char ddate[72 + 1];
-    FILE* ddfile;
-#endif
 
     SetVideoSync();
 
     callbacks.ButtonPressed = WaitCallbackKey;
-    callbacks.ButtonReleased = WaitCallbackKey;
+    callbacks.ButtonReleased = WaitCallbackKey1;
     callbacks.MouseMoved = WaitCallbackMouse;
     callbacks.MouseExit = WaitCallbackExit;
     callbacks.KeyPressed = WaitCallbackKey2;
-    callbacks.KeyReleased = WaitCallbackKey2;
-    callbacks.KeyRepeated = WaitCallbackKey3;
+    callbacks.KeyReleased = WaitCallbackKey3;
+    callbacks.KeyRepeated = WaitCallbackKey4;
     callbacks.NetworkEvent = NetworkEvent;
     callbacks.SoundReady = WriteSound;
 
     //
     //	FIXME: more work needed, scrolling credits, animations, ...
-#ifdef DEBUG
     WaitNoEvent = 1;
+#ifdef DEBUG_DRAWFONTS
     while (WaitNoEvent) {
+	static int init = 0;
+	if (!init) {
+	    SetDefaultTextColors(FontYellow, FontWhite);
+	    LoadFonts();
+	    init = 1;
+	}
 	DebugDrawFonts();
 	WaitEventsOneFrame(&callbacks);
     }
 #else
-    VideoLockScreen();
-    VideoDrawTextCentered(VideoWidth / 2, 5, LargeFont, "Press SPACE to continue.");
-#ifdef linux
-    ddate[0] = '\0';
-    ddfile = popen("`which ddate`", "r");
-    fgets(ddate, 72, ddfile);
-    pclose(ddfile);
-    if ((s = strrchr(ddate, '\n'))) {
-	*s = '\0';
-    }
-    VideoDrawTextCentered(VideoWidth / 2, 20, LargeFont, ddate);
-#endif
-    VideoUnlockScreen();
-    Invalidate();
-    RealizeVideoMemory();
-
-    WaitNoEvent = 1;
     timeout *= CYCLES_PER_SECOND;
     while (timeout-- && WaitNoEvent) {
-	VideoEffect0(timeout, &callbacks);
+	// FIXME: make this configurable
+	if (0) {
+	    VideoEffect0(timeout, &callbacks);
+	}
 	WaitEventsOneFrame(&callbacks);
     }
-    VideoEffect0(-1, &callbacks);
+    if (0) {
+	VideoEffect0(-1, &callbacks);
+    }
 #endif
 
     VideoLockScreen();
-    VideoDrawTextCentered(VideoWidth / 2, 5, LargeFont,
-	"----------------------------");
+    VideoClearScreen();
     VideoUnlockScreen();
     Invalidate();
     RealizeVideoMemory();
-
 }
 
 /**
@@ -1251,13 +1255,13 @@ Use it at your own risk.\n\n");
     //
     InitVideo();			// setup video display
 #ifdef WITH_SOUND
-    if (!SoundOff && InitSound()) {			// setup sound card
+    if (!SoundOff && InitSound()) {	// setup sound card
 	SoundOff = 1;
 	SoundFildes = -1;
     }
 #endif
 
-#ifndef DEBUG				// For debug its better not to have:
+#ifndef DEBUG				// For debug it's better not to have:
     srand(time(NULL));			// Random counter = random each start
 #endif
 
@@ -1266,23 +1270,22 @@ Use it at your own risk.\n\n");
     //
     //	Show title screen.
     //
-    i = 1;
     SetClipping(0, 0, VideoWidth - 1, VideoHeight - 1);
     if (TitleScreen) {
-	if ((i = PlayMovie(TitleScreen,
-		PlayMovieZoomScreen | PlayMovieKeepAspect))) {
-	    DisplayPicture(TitleScreen);
-	    Invalidate();
+	for (i = 0; TitleScreen[i]; ++i) {
+	    if (PlayMovie(TitleScreen[i],
+		    PlayMovieZoomScreen | PlayMovieKeepAspect)) {
+		DisplayPicture(TitleScreen[i]);
+		Invalidate();
+		// FIXME: make the time configurable
+		WaitForInput(20);
+	    }
 	}
     }
 
     InitUnitsMemory();		// Units memory management
     PreMenuSetup();		// Load everything needed for menus
 
-    if (i) {
-	WaitForInput(20);	// Show game intro
-    }
-
     MenuLoop(MapName, &TheMap);	// Enter the menu loop
 
     return 0;
diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp
index cb2cc1c0b..3ea136017 100644
--- a/src/ui/script_ui.cpp
+++ b/src/ui/script_ui.cpp
@@ -283,25 +283,26 @@ local SCM CclSetVideoFullscreen(SCM fullscreen)
 **
 **	@param title	SCM title. (nil reports only)
 **
-**	@return		Old title screen.
+**	@return		None
 */
-local SCM CclSetTitleScreen(SCM title)
+local SCM CclSetTitleScreen(SCM list)
 {
-    SCM old;
+    int i;
 
-    old = NIL;
     if (TitleScreen) {
-	old = gh_str02scm(TitleScreen);
-    }
-    if (!gh_null_p(title)) {
-	if (TitleScreen) {
-	    free(TitleScreen);
-	    TitleScreen = NULL;
+	for (i = 0; TitleScreen[i]; ++i) {
+	    free(TitleScreen[i]);
 	}
-
-	TitleScreen = gh_scm2newstr(title, NULL);
     }
-    return old;
+    if (!gh_null_p(list)) {
+	i = 0;
+	TitleScreen = calloc(gh_length(list) + 1, sizeof(*TitleScreen));
+	while (!gh_null_p(list)) {
+	    TitleScreen[i++] = gh_scm2newstr(gh_car(list), NULL);
+	    list = gh_cdr(list);
+	}
+    }
+    return SCM_UNSPECIFIED;
 }
 
 /**
@@ -3240,7 +3241,7 @@ global void UserInterfaceCclRegister(void)
     gh_new_procedure2_0("set-video-resolution!", CclSetVideoResolution);
     gh_new_procedure1_0("set-video-fullscreen!", CclSetVideoFullscreen);
 
-    gh_new_procedure1_0("set-title-screen!", CclSetTitleScreen);
+    gh_new_procedureN("set-title-screen!", CclSetTitleScreen);
     gh_new_procedure1_0("set-menu-background!", CclSetMenuBackground);
     gh_new_procedure1_0("set-menu-background-with-title!",
 	CclSetMenuBackgroundWithTitle);
diff --git a/src/video/movie.cpp b/src/video/movie.cpp
index 4153e8678..52dde27ac 100644
--- a/src/video/movie.cpp
+++ b/src/video/movie.cpp
@@ -163,6 +163,13 @@ local void MovieCallbackKey(unsigned dummy __attribute__((unused)))
     MovieKeyPressed = 0;
 }
 
+/**
+**	Callback for input.
+*/
+local void MovieCallbackKey1(unsigned dummy __attribute__((unused)))
+{
+}
+
 /**
 **	Callback for input.
 */
@@ -177,6 +184,14 @@ local void MovieCallbackKey2(unsigned dummy1 __attribute__((unused)),
 */
 local void MovieCallbackKey3(unsigned dummy1 __attribute__((unused)),
 	unsigned dummy2 __attribute__((unused)))
+{
+}
+
+/**
+**	Callback for input.
+*/
+local void MovieCallbackKey4(unsigned dummy1 __attribute__((unused)),
+	unsigned dummy2 __attribute__((unused)))
 {
     MovieKeyPressed = 0;
 }
@@ -251,12 +266,12 @@ global int PlayMovie(const char* name, int flags)
 #endif
 
     callbacks.ButtonPressed = MovieCallbackKey;
-    callbacks.ButtonReleased = MovieCallbackKey;
+    callbacks.ButtonReleased = MovieCallbackKey1;
     callbacks.MouseMoved = MovieCallbackMouse;
     callbacks.MouseExit = MovieCallbackExit;
     callbacks.KeyPressed = MovieCallbackKey2;
-    callbacks.KeyReleased = MovieCallbackKey2;
-    callbacks.KeyRepeated = MovieCallbackKey3;
+    callbacks.KeyReleased = MovieCallbackKey3;
+    callbacks.KeyRepeated = MovieCallbackKey4;
     callbacks.NetworkEvent = NetworkEvent;
     callbacks.SoundReady = WriteSound;