Maelstrom: Load UI on demand, since it's fairly fast

https://github.com/libsdl-org/Maelstrom/commit/66332e6632c3e7f96577770f47b6c55b08de5144

From 66332e6632c3e7f96577770f47b6c55b08de5144 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 23 Oct 2011 10:20:50 -0400
Subject: [PATCH] Load UI on demand, since it's fairly fast

---
 UI/UI.lst               |  2 --
 init.cpp                |  7 ------
 screenlib/UIManager.cpp | 53 +++++------------------------------------
 screenlib/UIManager.h   |  3 +--
 4 files changed, 7 insertions(+), 58 deletions(-)
 delete mode 100644 UI/UI.lst

diff --git a/UI/UI.lst b/UI/UI.lst
deleted file mode 100644
index 4e69efcd..00000000
--- a/UI/UI.lst
+++ /dev/null
@@ -1,2 +0,0 @@
-# List of panels to load at startup
-loading
diff --git a/init.cpp b/init.cpp
index bfe4a4b3..ff77bcae 100644
--- a/init.cpp
+++ b/init.cpp
@@ -741,7 +741,6 @@ int DoInitializations(Uint32 window_flags, Uint32 render_flags)
 
 	/* Do the Ambrosia Splash screen */
 	screen->FadeOut();
-	ui->LoadPanel(PANEL_SPLASH);
 	ui->ShowPanel(PANEL_SPLASH);
 	ui->Draw();
 
@@ -753,12 +752,6 @@ int DoInitializations(Uint32 window_flags, Uint32 render_flags)
 	if ( LoadCICNS() < 0 )
 		return(-1);
 
-	/* -- Load the rest of the UI panels */
-	if (!ui->LoadPanels()) {
-		error("Couldn't load panels: %s\n", ui->Error());
-		return(-1);
-	}
-
 	/* -- Create the stars array */
 	InitStars();
 
diff --git a/screenlib/UIManager.cpp b/screenlib/UIManager.cpp
index e794856c..ceee020f 100644
--- a/screenlib/UIManager.cpp
+++ b/screenlib/UIManager.cpp
@@ -20,8 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <physfs.h>
-
 #include "SDL_FrameBuf.h"
 #include "UIManager.h"
 #include "UIPanel.h"
@@ -69,55 +67,13 @@ static const char *GetLine(char *&text)
 	return line;
 }
 
-bool
-UIManager::LoadPanels()
-{
-	char file[1024];
-	PHYSFS_File *fp;
-	PHYSFS_sint64 size;
-	char *buffer, *spot;
-	const char *line;
-
-	sprintf(file, "%s/UI.lst", m_loadPath);
-	fp = PHYSFS_openRead(file);
-	if (!fp) {
-		SetError("Couldn't open %s: %s", file, PHYSFS_getLastError());
-		return false;
-	}
-
-	size = PHYSFS_fileLength(fp);
-	buffer = new char[size+1];
-	if (PHYSFS_readBytes(fp, buffer, size) != size) {
-		SetError("Couldn't read from %s: %s", file, PHYSFS_getLastError());
-		PHYSFS_close(fp);
-		delete[] buffer;
-		return false;
-	}
-	buffer[size] = '\0';
-	PHYSFS_close(fp);
-
-	spot = buffer;
-	while ((line = GetLine(spot)) != NULL) {
-		if (*line == '#') {
-			continue;
-		}
-		if (!LoadPanel(line)) {
-			delete[] buffer;
-			return false;
-		}
-	}
-
-	delete[] buffer;
-	return true;
-}
-
 UIPanel *
 UIManager::LoadPanel(const char *name)
 {
 	UIPanel *panel;
 
-	panel = GetPanel(name);
-	if (!name) {
+	panel = GetPanel(name, false);
+	if (!panel) {
 		char file[1024];
 
 		sprintf(file, "%s/%s.xml", m_loadPath, name);
@@ -132,13 +88,16 @@ UIManager::LoadPanel(const char *name)
 }
 
 UIPanel *
-UIManager::GetPanel(const char *name)
+UIManager::GetPanel(const char *name, bool allowLoad)
 {
 	for (unsigned i = 0; i < m_panels.length(); ++i) {
 		if (strcmp(name, m_panels[i]->GetName()) == 0) {
 			return m_panels[i];
 		}
 	}
+	if (allowLoad) {
+		return LoadPanel(name);
+	}
 	return NULL;
 }
 
diff --git a/screenlib/UIManager.h b/screenlib/UIManager.h
index 76591797..8a7cc2dc 100644
--- a/screenlib/UIManager.h
+++ b/screenlib/UIManager.h
@@ -47,9 +47,8 @@ class UIManager : public UIArea
 	}
 
 	void SetLoadPath(const char *path);
-	bool LoadPanels();
 	UIPanel *LoadPanel(const char *name);
-	UIPanel *GetPanel(const char *name);
+	UIPanel *GetPanel(const char *name, bool allowLoad = true);
 	UIPanel *GetCurrentPanel();
 
 	/* These are called by the UIPanel class */