Add cloud menu background by Krisi, configurable with the menu_clouds option.
authorShadowNinja <noreply@gmail.com>
Tue, 5 Mar 2013 22:23:03 +0000 (17:23 -0500)
committerkwolekr <kwolekr@minetest.net>
Thu, 14 Mar 2013 01:18:40 +0000 (21:18 -0400)
Also add a menuheader, menusplash, menufooter_clouds, and allow HD menu footers.
And finally don't git-ignore textures/base/.

.gitignore
minetest.conf.example
src/clouds.cpp
src/clouds.h
src/defaultsettings.cpp
src/guiMainMenu.cpp
src/main.cpp
textures/base/pack/logo.png [new file with mode: 0644]
textures/base/pack/menufooter.png [new file with mode: 0644]
textures/base/pack/menuheader.png [new file with mode: 0644]
textures/base/pack/menulogo.png [deleted file]

index 803d8cb23cecb9ca371fd1d7d0b6c8cff8d6ff9b..1ebd43e0d913b1a46290def8ab41d7a7550ce8f7 100644 (file)
@@ -12,7 +12,8 @@ tags
 /games/*
 !/games/minimal/
 /cache/
-/textures/
+/textures/*
+!/textures/base/
 /sounds/
 /mods/*
 !/mods/minetest/
index 1f2a764f28003bb3a4965e55535c3195a9843ed1..daca1616d81bf3fdcacdb7dd2dc5be16d8839231 100644 (file)
 #farmesh_distance = 40
 # Enable/disable clouds
 #enable_clouds = true
+# Use a cloud animation for the main menu background
+#menu_clouds = true
 # Path for screenshots
 #screenshot_path = .
 # Amount of view bobbing (0 = no view bobbing, 1.0 = normal, 2.0 = double)
index 9f0bc06d8fc22a187ebd5e736f9aad51dcd80c80..55ec8965ad6683b8b146f4ec7e907702c790d66c 100644 (file)
@@ -29,7 +29,8 @@ Clouds::Clouds(
                scene::ISceneNode* parent,
                scene::ISceneManager* mgr,
                s32 id,
-               u32 seed
+               u32 seed,
+               s16 cloudheight
 ):
        scene::ISceneNode(parent, mgr, id),
        m_seed(seed),
@@ -45,7 +46,8 @@ Clouds::Clouds(
        //m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
        m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
 
-       m_cloud_y = BS * g_settings->getS16("cloud_height");
+       m_cloud_y = BS * (cloudheight ? cloudheight :
+                               g_settings->getS16("cloud_height"));
 
        m_box = core::aabbox3d<f32>(-BS*1000000,m_cloud_y-BS,-BS*1000000,
                        BS*1000000,m_cloud_y+BS,BS*1000000);
index 72923c2c5e9e19e3f0967039c4a984bbd2f31c03..8f8b19faf77c63bb58a0348f8a22e7bfeb8f384f 100644 (file)
@@ -30,7 +30,8 @@ public:
                        scene::ISceneNode* parent,
                        scene::ISceneManager* mgr,
                        s32 id,
-                       u32 seed
+                       u32 seed,
+                       s16 cloudheight=0
        );
 
        ~Clouds();
index a8954be724c204f54d362dc4bcdfeef90ceadc48..3ec0ad9fcca9f6fa69f2bd1e78d5abbea6941fb4 100644 (file)
@@ -109,6 +109,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("view_bobbing_amount", "1.0");
        settings->setDefault("enable_3d_clouds", "true");
        settings->setDefault("cloud_height", "120");
+       settings->setDefault("menu_clouds", "true");
        settings->setDefault("opaque_water", "false");
        settings->setDefault("console_color", "(0,0,0)");
        settings->setDefault("console_alpha", "200");
index c2e68579e9fcf7c3ff7eaf48731ac1d944487146..4accbaa27ae49718ddef4473f309e601273d3508 100644 (file)
@@ -209,7 +209,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        changeCtype("");
 
        // Version
-       //if(m_data->selected_tab != TAB_CREDITS)
        {
                core::rect<s32> rect(0, 0, size.X, 40);
                rect += v2s32(4, 0);
@@ -219,7 +218,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        }
 
        //v2s32 center(size.X/2, size.Y/2);
-       v2s32 c800(size.X/2-400, size.Y/2-300);
+       v2s32 c800(size.X/2-400, size.Y/2-270);
        
        m_topleft_client = c800 + v2s32(90, 70+50+30);
        m_size_client = v2s32(620, 270);
@@ -237,7 +236,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
        m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
        
        // Tabs
-#if 1
        {
                core::rect<s32> rect(0, 0, m_size_client.X, 30);
                rect += m_topleft_client + v2s32(0, -30);
@@ -250,7 +248,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
                e->addTab(wgettext("Credits"));
                e->setActiveTab(m_data->selected_tab);
        }
-#endif
        
        if(m_data->selected_tab == TAB_SINGLEPLAYER)
        {
@@ -786,15 +783,15 @@ void GUIMainMenu::drawMenu()
                        driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
                }
                video::ITexture *logotexture =
-                               driver->getTexture(getTexturePath("menulogo.png").c_str());
+                               driver->getTexture(getTexturePath("logo.png").c_str());
                if(logotexture)
                {
                        v2s32 logosize(logotexture->getOriginalSize().Width,
                                        logotexture->getOriginalSize().Height);
-                       logosize *= 2;
+
                        core::rect<s32> rect(0,0,logosize.X,logosize.Y);
                        rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
-                       rect += v2s32(130, 50);
+                       rect += v2s32(500, 30);
                        driver->draw2DImage(logotexture, rect,
                                core::rect<s32>(core::position2d<s32>(0,0),
                                core::dimension2di(logotexture->getSize())),
index 696468049bb36b0d842aea6eef25fc4582952273..73be969adff29aafdbd408b9a521a7003a0b56eb 100644 (file)
@@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_extrabloated.h"
 #include "debug.h"
 #include "test.h"
+#include "clouds.h"
 #include "server.h"
 #include "constants.h"
 #include "porting.h"
@@ -596,50 +597,120 @@ private:
        bool rightreleased;
 };
 
-void drawMenuBackground(video::IVideoDriver* driver)
-{
+//Draw the tiled menu background
+void drawMenuBackground(video::IVideoDriver* driver) {
        core::dimension2d<u32> screensize = driver->getScreenSize();
+
+       std::string path = getTexturePath("menubg.png");
+       if (path[0]) {
+               video::ITexture *bgtexture =
+                       driver->getTexture(path.c_str());
+
+               if (bgtexture) {
+                       s32 scaledsize = 128;
                
-       video::ITexture *bgtexture =
-                       driver->getTexture(getTexturePath("menubg.png").c_str());
-       if(bgtexture)
-       {
-               s32 scaledsize = 128;
-               
-               // The important difference between destsize and screensize is
-               // that destsize is rounded to whole scaled pixels.
-               // These formulas use component-wise multiplication and division of v2u32.
-               v2u32 texturesize = bgtexture->getSize();
-               v2u32 sourcesize = texturesize * screensize / scaledsize + v2u32(1,1);
-               v2u32 destsize = scaledsize * sourcesize / texturesize;
+                       // The important difference between destsize and screensize is
+                       // that destsize is rounded to whole scaled pixels.
+                       // These formulas use component-wise multiplication and division of v2u32.
+                       v2u32 texturesize = bgtexture->getSize();
+                       v2u32 sourcesize = texturesize * screensize / scaledsize + v2u32(1,1);
+                       v2u32 destsize = scaledsize * sourcesize / texturesize;
                
-               // Default texture wrapping mode in Irrlicht is ETC_REPEAT.
-               driver->draw2DImage(bgtexture,
-                       core::rect<s32>(0, 0, destsize.X, destsize.Y),
-                       core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
-                       NULL, NULL, true);
+                       // Default texture wrapping mode in Irrlicht is ETC_REPEAT.
+                       driver->draw2DImage(bgtexture,
+                               core::rect<s32>(0, 0, destsize.X, destsize.Y),
+                               core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
+                               NULL, NULL, true);
+               }
        }
-       
-       video::ITexture *logotexture =
-                       driver->getTexture(getTexturePath("menulogo.png").c_str());
-       if(logotexture)
-       {
-               v2s32 logosize(logotexture->getOriginalSize().Width,
-                               logotexture->getOriginalSize().Height);
-               logosize *= 4;
-
-               video::SColor bgcolor(255,50,50,50);
-               core::rect<s32> bgrect(0, screensize.Height-logosize.Y-20,
-                               screensize.Width, screensize.Height);
-               driver->draw2DRectangle(bgcolor, bgrect, NULL);
-
-               core::rect<s32> rect(0,0,logosize.X,logosize.Y);
-               rect += v2s32(screensize.Width/2,screensize.Height-10-logosize.Y);
-               rect -= v2s32(logosize.X/2, 0);
-               driver->draw2DImage(logotexture, rect,
-                       core::rect<s32>(core::position2d<s32>(0,0),
-                       core::dimension2di(logotexture->getSize())),
-                       NULL, NULL, true);
+}
+
+//Draw the footer at the bottom of the window
+void drawMenuFooter(video::IVideoDriver* driver, bool clouds) {
+       core::dimension2d<u32> screensize = driver->getScreenSize();
+       std::string path = getTexturePath(clouds ?
+                                               "menufooter_clouds.png" : "menufooter.png");
+       if (path[0]) {
+               video::ITexture *footertexture =
+                       driver->getTexture(path.c_str());
+
+               if (footertexture) {
+                       f32 mult = (((f32)screensize.Width)) /
+                               ((f32)footertexture->getOriginalSize().Width);
+
+                       v2s32 footersize(((f32)footertexture->getOriginalSize().Width) * mult,
+                                       ((f32)footertexture->getOriginalSize().Height) * mult);
+
+                       // Don't draw the footer if there isn't enough room
+                       s32 free_space = (((s32)screensize.Height)-320)/2;
+                       if (free_space > footersize.Y) {
+                               core::rect<s32> rect(0,0,footersize.X,footersize.Y);
+                               rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y);
+                               rect -= v2s32(footersize.X/2, 0);
+
+                               driver->draw2DImage(footertexture, rect,
+                                       core::rect<s32>(core::position2d<s32>(0,0),
+                                       core::dimension2di(footertexture->getSize())),
+                                       NULL, NULL, true);
+                       }
+               }
+       }
+}
+
+// Draw the Header over the main menu
+void drawMenuHeader(video::IVideoDriver* driver) {
+       core::dimension2d<u32> screensize = driver->getScreenSize();
+
+       std::string path = getTexturePath("menuheader.png");
+       if (path[0]) {
+               video::ITexture *splashtexture =
+               driver->getTexture(path.c_str());
+
+               if(splashtexture) {
+                       //v2s32 splashsize((splashtexture->getOriginalSize().Width*100)/
+                       //      splashtexture->getOriginalSize().Height, 80);
+
+                       f32 mult = (((f32)screensize.Width / 2)) /
+                               ((f32)splashtexture->getOriginalSize().Width);
+
+                       v2s32 splashsize(((f32)splashtexture->getOriginalSize().Width) * mult,
+                                       ((f32)splashtexture->getOriginalSize().Height) * mult);
+
+                       // Don't draw the header is there isn't enough room
+                       s32 free_space = (((s32)screensize.Height)-320)/2;
+                       if (free_space > splashsize.Y) {
+                               core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y);
+                               splashrect += v2s32((screensize.Width/2)-(splashsize.X/2),
+                                       ((free_space/2)-splashsize.Y/2)+10);
+
+                               video::SColor bgcolor(255,50,50,50);
+
+                               driver->draw2DImage(splashtexture, splashrect,
+                                       core::rect<s32>(core::position2d<s32>(0,0),
+                                       core::dimension2di(splashtexture->getSize())),
+                                       NULL, NULL, true);
+                       }
+               }
+       }
+}
+
+// Draw the Splash over the clouds and under the main menu
+void drawMenuSplash(video::IVideoDriver* driver) {
+       core::dimension2d<u32> screensize = driver->getScreenSize();
+       if (getTexturePath("menusplash.png") != "") {
+               video::ITexture *splashtexture =
+                       driver->getTexture(getTexturePath("menusplash.png").c_str());
+
+               if(splashtexture) {
+                       core::rect<s32> splashrect(0, 0, screensize.Width, screensize.Height);
+
+                       video::SColor bgcolor(255,50,50,50);
+
+                       driver->draw2DImage(splashtexture, splashrect,
+                               core::rect<s32>(core::position2d<s32>(0,0),
+                               core::dimension2di(splashtexture->getSize())),
+                               NULL, NULL, true);
+               }
        }
 }
 
@@ -1540,6 +1611,22 @@ int main(int argc, char *argv[])
                                                                &g_menumgr, &menudata, g_gamecallback);
                                        menu->allowFocusRemoval(true);
 
+                                       // Clouds for the main menu
+                                       bool cloud_menu_background = false;
+                                       Clouds *clouds = NULL;
+                                       if (g_settings->getBool("menu_clouds")) {
+                                               cloud_menu_background = true;
+                                               clouds = new Clouds(smgr->getRootSceneNode(),
+                                                                                       smgr, -1, rand(), 100);
+                                               clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
+
+                                               // A camera to see the clouds
+                                               scene::ICameraSceneNode* camera;
+                                               camera = smgr->addCameraSceneNode(0,
+                                                                       v3f(0,0,0), v3f(0, 60, 100));
+                                               camera->setFarValue(10000);
+                                       }
+
                                        if(error_message != L"")
                                        {
                                                verbosestream<<"error_message = "
@@ -1552,6 +1639,9 @@ int main(int argc, char *argv[])
                                                error_message = L"";
                                        }
 
+                                       // Time is in milliseconds, for clouds
+                                       u32 lasttime = device->getTimer()->getTime();
+
                                        infostream<<"Created main menu"<<std::endl;
 
                                        while(device->run() && kill == false)
@@ -1559,23 +1649,50 @@ int main(int argc, char *argv[])
                                                if(menu->getStatus() == true)
                                                        break;
 
-                                               //driver->beginScene(true, true, video::SColor(255,0,0,0));
-                                               driver->beginScene(true, true, video::SColor(255,128,128,128));
+                                               // Time calc for the clouds
+                                               f32 dtime; // in seconds
+                                               if (cloud_menu_background) {
+                                                       u32 time = device->getTimer()->getTime();
+                                                       if(time > lasttime)
+                                                               dtime = (time - lasttime) / 1000.0;
+                                                       else
+                                                               dtime = 0;
+                                                       lasttime = time;
+                                               }
 
-                                               drawMenuBackground(driver);
+                                               //driver->beginScene(true, true, video::SColor(255,0,0,0));
+                                               driver->beginScene(true, true, video::SColor(255,140,186,250));
+
+                                               if (cloud_menu_background) {
+                                                       // *3 otherwise the clouds would move very slowly
+                                                       clouds->step(dtime*3); 
+                                                       clouds->render();
+                                                       smgr->drawAll();
+                                                       drawMenuSplash(driver);
+                                                       drawMenuFooter(driver, true);
+                                                       drawMenuHeader(driver);
+                                               } else {
+                                                       drawMenuBackground(driver);
+                                                       drawMenuFooter(driver, false);
+                                               }
 
                                                guienv->drawAll();
-                                               
+
                                                driver->endScene();
                                                
                                                // On some computers framerate doesn't seem to be
                                                // automatically limited
-                                               sleep_ms(25);
+                                               if (!cloud_menu_background)
+                                                       sleep_ms(25);
                                        }
                                        
                                        infostream<<"Dropping main menu"<<std::endl;
 
                                        menu->drop();
+                                       if (cloud_menu_background) {
+                                               clouds->drop();
+                                               smgr->clear();
+                                       }
                                }
 
                                playername = wide_to_narrow(menudata.name);
diff --git a/textures/base/pack/logo.png b/textures/base/pack/logo.png
new file mode 100644 (file)
index 0000000..f341e88
Binary files /dev/null and b/textures/base/pack/logo.png differ
diff --git a/textures/base/pack/menufooter.png b/textures/base/pack/menufooter.png
new file mode 100644 (file)
index 0000000..fd43184
Binary files /dev/null and b/textures/base/pack/menufooter.png differ
diff --git a/textures/base/pack/menuheader.png b/textures/base/pack/menuheader.png
new file mode 100644 (file)
index 0000000..66fd6de
Binary files /dev/null and b/textures/base/pack/menuheader.png differ
diff --git a/textures/base/pack/menulogo.png b/textures/base/pack/menulogo.png
deleted file mode 100644 (file)
index 578c9db..0000000
Binary files a/textures/base/pack/menulogo.png and /dev/null differ