Maelstrom: Converted the zap scores dialog over to XML

https://github.com/libsdl-org/Maelstrom/commit/d0ac0cfb4ed5fa64456e438c194fe0ea48c75adc

From d0ac0cfb4ed5fa64456e438c194fe0ea48c75adc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 29 Oct 2011 02:39:28 -0400
Subject: [PATCH] Converted the zap scores dialog over to XML

---
 Maelstrom_Globals.h        |  1 +
 UI/zap.xml                 | 15 +++++++++
 main.cpp                   | 27 +++++++++++----
 scores.cpp                 | 69 ++++++--------------------------------
 scores.h                   |  2 +-
 screenlib/SDL_FrameBuf.cpp |  2 +-
 6 files changed, 48 insertions(+), 68 deletions(-)
 create mode 100644 UI/zap.xml

diff --git a/Maelstrom_Globals.h b/Maelstrom_Globals.h
index 6e0d81ff..92c50ab5 100644
--- a/Maelstrom_Globals.h
+++ b/Maelstrom_Globals.h
@@ -109,6 +109,7 @@ extern Bool	gNetScores;
 #define PANEL_GAMEOVER	"gameover"
 #define PANEL_ABOUT	"about_story"
 #define DIALOG_CONTROLS	"controls"
+#define DIALOG_ZAP	"zap"
 #define DIALOG_DAWN	"dawn"
 
 // Sound resource definitions...
diff --git a/UI/zap.xml b/UI/zap.xml
new file mode 100644
index 00000000..41e5353a
--- /dev/null
+++ b/UI/zap.xml
@@ -0,0 +1,15 @@
+<Dialog>
+	<Size w="273" h="103"/>
+	<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" x="183" y="93"/>
+	<Elements>
+		<Title id="102">
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" x="4" y="4"/>
+		</Icon>
+		<DialogButton name="clearButton" text="Clear" closeDialog="true">
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" x="99" y="74"/>
+		</DialogButton>
+		<DialogButton text="Cancel" default="true" closeDialog="true">
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPRIGHT" anchor="clearButton"x="13"/>
+		</DialogButton>
+	</Elements>
+</Dialog>
diff --git a/main.cpp b/main.cpp
index bd627798..acd94fdf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -89,15 +89,25 @@ static void SetSoundLevel(int volume)
 	/* -- Draw the new sound level */
 	gUpdateBuffer = true;
 }
-static void RunZapScores(void)
+static void SetupZapScores(void)
 {
-	if ( ZapHighScores() ) {
-		/* Fade the screen and redisplay scores */
-		screen->Fade();
-		Delay(SOUND_DELAY);
-		sound->PlaySound(gExplosionSound, 5);
-		gUpdateBuffer = true;
+	UIPanel *panel;
+	UIElementButton *button;
+
+	panel = ui->GetPanel(DIALOG_ZAP);
+	if (!panel) {
+		return;
 	}
+
+	button = panel->GetElement<UIElementButton>("clearButton");
+	if (button) {
+		button->SetClickCallback(ZapHighScores);
+	}
+}
+static void RunZapScores(void)
+{
+	SetupZapScores();
+	ui->ShowPanel(DIALOG_ZAP);
 }
 static void RunToggleFullscreen(void)
 {
@@ -328,6 +338,9 @@ int main(int argc, char *argv[])
 
 		ui->Draw();
 
+		/* -- In case we were faded out */
+		screen->FadeIn();
+
 		/* -- Get events */
 		while ( screen->PollEvent(&event) ) {
 			if ( ui->HandleEvent(event) )
diff --git a/scores.cpp b/scores.cpp
index 126d60dc..89ca8460 100644
--- a/scores.cpp
+++ b/scores.cpp
@@ -21,9 +21,6 @@
 /* Everyone can write to scores file if defined to 0 */
 #define SCORES_PERMMASK		0
 
-#define CLR_DIALOG_WIDTH	281
-#define CLR_DIALOG_HEIGHT	111
-
 Bool gNetScores = 0;
 Scores hScores[NUM_SCORES];
 
@@ -102,63 +99,17 @@ void PrintHighScores(void)
 	}
 }
 
-static int do_clear;
-
-static int Clear_callback(void) {
-	do_clear = 1;
-	return(1);
-}
-static int Cancel_callback(void) {
-	do_clear = 0;
-	return(1);
-}
-
-int ZapHighScores(void)
+void ZapHighScores(void)
 {
-	MFont *chicago;
-	Maclike_Dialog *dialog;
-	int X, Y;
-	SDL_Texture *splash;
-	Mac_Button *clear;
-	Mac_Button *cancel;
-
-	/* Set up all the components of the dialog box */
-#ifdef CENTER_DIALOG
-	X=(SCREEN_WIDTH-CLR_DIALOG_WIDTH)/2;
-	Y=(SCREEN_HEIGHT-CLR_DIALOG_HEIGHT)/2;
-#else	/* The way it is on the original Maelstrom */
-	X=179;
-	Y=89;
-#endif
-	chicago = fonts[CHICAGO_12];
-	if ( (splash = Load_Title(screen, 102)) == NULL ) {
-		error("Can't load score zapping splash!\n");
-		return(0);
-	}
-	dialog = new Maclike_Dialog(X, Y, CLR_DIALOG_WIDTH, CLR_DIALOG_HEIGHT,
-								screen);
-	dialog->Add_Image(splash, 4, 4);
-	do_clear = 0;
-	clear = new Mac_Button(99, 74, BUTTON_WIDTH, BUTTON_HEIGHT,
-				"Clear", chicago, fontserv, Clear_callback);
-	dialog->Add_Dialog(clear);
-	cancel = new Mac_DefaultButton(99+BUTTON_WIDTH+14, 74, 
-				BUTTON_WIDTH, BUTTON_HEIGHT,
-				"Cancel", chicago, fontserv, Cancel_callback);
-	dialog->Add_Dialog(cancel);
-
-	/* Run the dialog box */
-	dialog->Run();
-
-	/* Clean up and return */
-	screen->FreeImage(splash);
-	delete dialog;
-	if ( do_clear ) {
-		memset(hScores, 0, sizeof(hScores));
-		SaveScores();
-		gLastHigh = -1;
-	}
-	return(do_clear);
+	memset(hScores, 0, sizeof(hScores));
+	SaveScores();
+	gLastHigh = -1;
+
+	/* Fade the screen and redisplay scores */
+	screen->FadeOut();
+	Delay(SOUND_DELAY);
+	sound->PlaySound(gExplosionSound, 5);
+	gUpdateBuffer = true;
 }
 
 
diff --git a/scores.h b/scores.h
index 4126260e..49d27df3 100644
--- a/scores.h
+++ b/scores.h
@@ -2,7 +2,7 @@
 // Functions from scores.cc
 extern void	LoadScores(void);
 extern void	SaveScores(void);
-extern int	ZapHighScores(void);
+extern void	ZapHighScores(void);
 extern int	GetStartLevel(void);
 extern void	PrintHighScores(void);
 
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 9526d4a2..522a478f 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -131,7 +131,7 @@ void
 FrameBuf:: Fade(void)
 {
 // Temporary for development
-return;
+//return;
 	const int max = 32;
 	Uint16 ramp[256];